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