Rev 37 | Rev 47 | 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 | |||
36 | f9daq | 68 | TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC"); |
35 | f9daq | 69 | TCanvas* canvas2 = new TCanvas("canvas2","canvas2",800,800); |
70 | canvas2->cd(); |
||
36 | f9daq | 71 | //h_correctedTDC->Draw("colz"); |
72 | |||
73 | TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz"); |
||
74 | h_correctedTDC->SetTitle("; t [ns]; Channel"); |
||
35 | f9daq | 75 | h_correctedTDC->Draw("colz"); |
36 | f9daq | 76 | TCanvas* canvas3 = new TCanvas("canvas3","canvas3",800,800); |
35 | f9daq | 77 | canvas2->cd(2); |
40 | f9daq | 78 | TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64); |
79 | h_allTDCbins->Draw(); |
||
80 | /* |
||
35 | f9daq | 81 | int binY = map[chX][chY]; |
82 | TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1); |
||
40 | f9daq | 83 | channelY->SetStats(0); |
35 | f9daq | 84 | |
85 | char title[256]; |
||
86 | sprintf(title,"Channel %d;t [ns];Events", binY); |
||
87 | channelY->SetTitle(title); |
||
88 | channelY->GetYaxis()->SetTitleOffset(1.7); |
||
40 | f9daq | 89 | TAxis* xAxis = h_correctedTDC->GetXaxis(); |
90 | int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1); |
||
91 | channelY->GetXaxis()->SetRangeUser(-range, range); |
||
35 | f9daq | 92 | channelY->Draw(); |
40 | f9daq | 93 | |
35 | f9daq | 94 | TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight); |
95 | TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8); |
||
96 | f_gaus1->SetParNames("Linear","Norm","#mu","#sigma"); |
||
97 | f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2"); |
||
98 | Int_t n = channelY->GetMaximum(); |
||
99 | Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin()); |
||
100 | |||
101 | f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0); |
||
102 | channelY->Fit(f_gaus1,"0"); |
||
103 | channelY->Fit(f_gaus1,"r"); |
||
104 | */ |
||
105 | //Fit in range +- 3 sigma |
||
106 | //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3), |
||
107 | // f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3)); |
||
108 | |||
109 | |||
110 | //f_gaus2->SetParameters(-1, n, mean-0.1, 0.01, |
||
111 | // n, mean+0.1, 0.1); |
||
112 | //channelY->Fit(f_gaus2,"0"); |
||
113 | //channelY->Fit(f_gaus2,"rl"); |
||
114 | // set range to +- 3 sigma |
||
115 | //channelY->Fit(f_gaus,"lr","",f_gaus->GetParameter(2)-3*f_gaus->GetParameter(3), |
||
116 | // f_gaus->GetParameter(2)+3*f_gaus->GetParameter(3)); |
||
117 | |||
118 | return (0); |
||
119 | } |