Subversion Repositories f9daq

Rev

Rev 40 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
35 f9daq 1
#include "TROOT.h"
2
#include "TFile.h"
3
#include "TBenchmark.h"
4
#include "TH1F.h"
5
#include "TH2F.h"
37 f9daq 6
#include "TH3F.h"
35 f9daq 7
#include "TCanvas.h"
8
#include "TStyle.h"
9
#include "TPad.h"
10
#include "TF1.h"
11
#include "TGraph.h"
12
#include "TSpectrum.h"
13
#include "stdio.h"
14
 
37 f9daq 15
//#include "include/RTUtil.h"
35 f9daq 16
 
17
int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=-16, double rangeRight=16, bool debug = false)
18
{
19
  //const int c_nChannels = 64;
20
  //const double c_xOffset = 2.2; // mm
21
  //const double c_yOffset = 2.3;
22
 
23
  int map[8][8]={{32,34,53,55,40,42,61,63},
24
                 {48,50,37,39,56,58,45,47},
25
                 {33,35,52,54,41,43,60,62},
26
                 {49,51,36,38,57,59,44,46},
27
                 {17,19,4,6,25,27,12,14},
28
                 {1,3,20,22,9,11,28,30},
29
                 {16,18,5,7,24,26,13,15},
30
                 {0,2,21,23,8,10,29,31}
31
                };
32
 
33
  char fnameroot[256];
34
  TFile* rootfile;
35
	sprintf(fnameroot, "root/%s.root", filename);
36
	rootfile = (TFile *) gROOT->FindObject(filename);
37
	if(rootfile==NULL) rootfile = new TFile(fnameroot);
38
	if(rootfile==NULL) {
39
	  printf("Cannot open root file %s!!!\n",fnameroot);
40
	  return(0);
41
	}
42
 
43
	// set draw style
44
	gStyle->SetPalette(1, 0);
45
 
46
	gStyle->SetPaperSize(TStyle::kA4);
47
	gStyle->SetStatBorderSize(1);
48
	gStyle->SetFrameBorderMode(0);
49
	gStyle->SetFrameFillColor(0);
50
	gStyle->SetCanvasBorderMode(0);
51
	gStyle->SetPadBorderMode(0);
52
	gStyle->SetPadColor(0);
53
	gStyle->SetCanvasColor(0);
54
	gStyle->SetStatColor(0);
55
	gStyle->SetOptFit(11);
37 f9daq 56
	gStyle->SetOptStat("ne");
57
	gStyle->SetPadTopMargin(0.15);
58
	gStyle->SetPadBottomMargin(0.15);
35 f9daq 59
	gStyle->SetPadRightMargin(0.15);
37 f9daq 60
	gStyle->SetPadLeftMargin(0.15);
35 f9daq 61
	//gStyle->SetTitleYOffset(1.4);
62
 
63
    TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000);
64
    TH2F* htdc = (TH2F*) rootfile->Get("htdc");
65
    canvas1->cd();
66
    htdc->Draw("colz");
67
 
47 f9daq 68
    //TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC");
69
    TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC");
35 f9daq 70
    TCanvas* canvas2 = new TCanvas("canvas2","canvas2",800,800);
71
    canvas2->cd();
47 f9daq 72
    h_correctedTDC->Draw("colz");
36 f9daq 73
 
47 f9daq 74
    /*
36 f9daq 75
    TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz");
76
    h_correctedTDC->SetTitle("; t [ns]; Channel");
35 f9daq 77
    h_correctedTDC->Draw("colz");
36 f9daq 78
    TCanvas* canvas3 = new TCanvas("canvas3","canvas3",800,800);
35 f9daq 79
    canvas2->cd(2);
40 f9daq 80
    TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64);
81
    h_allTDCbins->Draw();
47 f9daq 82
    */
40 f9daq 83
    /*
35 f9daq 84
    int binY = map[chX][chY];
85
    TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1);
40 f9daq 86
    channelY->SetStats(0);
35 f9daq 87
 
88
    char title[256];
89
    sprintf(title,"Channel %d;t [ns];Events", binY);
90
    channelY->SetTitle(title);
91
    channelY->GetYaxis()->SetTitleOffset(1.7);
40 f9daq 92
    TAxis* xAxis = h_correctedTDC->GetXaxis();
93
    int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1);
94
    channelY->GetXaxis()->SetRangeUser(-range, range);
35 f9daq 95
    channelY->Draw();
40 f9daq 96
 
35 f9daq 97
    TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight);
98
    TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8);
99
    f_gaus1->SetParNames("Linear","Norm","#mu","#sigma");
100
    f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2");
101
    Int_t n = channelY->GetMaximum();
102
    Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin());
103
 
104
    f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0);
105
    channelY->Fit(f_gaus1,"0");
106
    channelY->Fit(f_gaus1,"r");
107
    */
108
    //Fit in range +- 3 sigma
109
    //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3),
110
      //                            f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3));
111
 
112
 
113
    //f_gaus2->SetParameters(-1, n, mean-0.1, 0.01,
114
      //                         n, mean+0.1, 0.1);
115
    //channelY->Fit(f_gaus2,"0");
116
    //channelY->Fit(f_gaus2,"rl");
117
    // set range to +- 3 sigma
118
    //channelY->Fit(f_gaus,"lr","",f_gaus->GetParameter(2)-3*f_gaus->GetParameter(3),
119
      //                           f_gaus->GetParameter(2)+3*f_gaus->GetParameter(3));
120
 
121
  return (0);
122
  }