Rev 291 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
291 | f9daq | 1 | #include "TROOT.h" |
2 | #include "TFile.h" |
||
3 | #include "TBenchmark.h" |
||
4 | #include "TH1F.h" |
||
5 | #include "TH2F.h" |
||
6 | gROOT->Reset(); |
||
7 | |||
8 | #include "TCanvas.h" |
||
9 | #include "TStyle.h" |
||
10 | #include "TPad.h" |
||
11 | #include "TF1.h" |
||
12 | #include "TGraph.h" |
||
13 | #include "TSpectrum.h" |
||
14 | |||
15 | #include "DrootHelper.cpp" |
||
16 | |||
17 | |||
18 | #define NCH 2 |
||
19 | |||
20 | //------------------------------------------------------------------------------------- |
||
21 | |||
22 | void SetGS() { |
||
23 | const UInt_t Number = 2; |
||
24 | Double_t Red[Number] = {0.00, 1.00}; |
||
25 | Double_t Green[Number] = {0.00, 1.00}; |
||
26 | Double_t Blue[Number] = {0.00, 1.00}; |
||
27 | Double_t Stops[Number] = {0.00, 1.00}; |
||
28 | |||
29 | Int_t nb=50; |
||
30 | TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, nb); |
||
31 | } |
||
32 | |||
33 | |||
34 | //------------------------------------------------------------------------------------- |
||
35 | Double_t ConstantStep(Double_t x) |
||
36 | { |
||
37 | if(x<=0) return 0.; |
||
38 | else return 1.; |
||
39 | } |
||
40 | |||
41 | // ======================================================================================================= |
||
42 | |||
43 | void plotCorTDC(TH1F *hp1d, char *hTitle, double fitmin, double fitmax, double drawmin, double drawmax) |
||
44 | { |
||
45 | char sbuff[256]; |
||
46 | |||
47 | TLegend *leg1 = new TLegend(0.57,0.76,0.88,0.88); |
||
48 | leg1->SetFillColor(0); |
||
49 | leg1->SetBorderSize(1); |
||
50 | leg1->SetTextSize(0.05); |
||
51 | leg1->SetTextAlign(22); |
||
52 | |||
53 | //gStyle->SetOptFit(111); |
||
54 | sprintf(sbuff, "%s;Time[ns];", hTitle); |
||
55 | hp1d->SetTitle(sbuff); |
||
56 | //~ hp1d->GetXaxis()->SetRangeUser(2*fitmin, 2*fitmax); |
||
57 | hp1d->GetXaxis()->SetRangeUser(drawmin, drawmax); |
||
58 | //~ hcTDC->DrawClone(); |
||
59 | |||
60 | //~ TF1 *fs = new TF1("fs","pol0(0) + gaus(1)"); |
||
61 | |||
62 | TF1 *fs = new TF1("fs","gaus(0) + ([3]*exp((x)/[4]) + [5]) * (0.5+0.5*TMath::Erf((x-[6])/[7]))"); |
||
63 | fs->SetParName(0, "G_Const"); fs->SetParName(1, "G_Mean"); fs->SetParName(2, "G_Sigma"); |
||
64 | fs->SetParName(3, "Exp_p0"); fs->SetParName(4, "Exp_p1"); fs->SetParName(5, "Exp_p2"); |
||
65 | fs->SetParName(6, "Erf_p0"); fs->SetParName(7, "Erf_p1"); |
||
66 | //~ |
||
67 | TF1 *fg1 = new TF1("fg1", "gaus(0)"); fg1->SetNpx(400); |
||
68 | TF1 *fe1 = new TF1("fe1", "[0]*exp((x)/[1]) + [2]"); |
||
69 | TF1 *ferf1 = new TF1("ferf1", "[0]*(0.5+0.5*TMath::Erf((x-[1])/[2]))"); |
||
70 | TF1 *fe1erf = new TF1("fe1erf", "([0]*exp((x)/[1]) + [2]) * (0.5+0.5*TMath::Erf((x-[3])/[4]))"); fe1erf->SetNpx(400); |
||
71 | |||
72 | double fitampl = hp1d->GetMaximum(); |
||
73 | double fitcenter = hp1d->GetBinCenter(hp1d->GetMaximumBin()); |
||
74 | |||
75 | fs->SetNpx(400); |
||
76 | fs->SetParameters(fitampl, fitcenter, 0.01, 1e2, -0.1, 1e1, 0, 0.05); |
||
77 | |||
78 | // G + Er + Ex |
||
79 | //fs->SetParLimits( 1, -0.1, 0.1); |
||
80 | //fs->SetParLimits( 2, 0.018, 0.5); |
||
81 | fs->SetParLimits( 4, -0.3, 0); |
||
82 | //fs->SetParLimits( 6, -1e-1, 1e-1); |
||
83 | fs->SetParLimits( 7, 0.04, 0.6); |
||
84 | |||
85 | //~ // G |
||
86 | //~ fs->SetParameters(fitampl/100., fitampl, fitcenter, 0.01); |
||
87 | |||
88 | hp1d->Fit(fs,"Q","",fitmin, fitmax); |
||
89 | |||
90 | //~ printf("Chi / NDF = %lf/%lf\n", fs->GetChisquare(), fs->GetNDF()); |
||
91 | |||
92 | fg1->SetParameters(fs->GetParameter(0), fs->GetParameter(1), fs->GetParameter(2)); |
||
93 | //~ fe1->SetParameters(fs->GetParameter(3), fs->GetParameter(4), fs->GetParameter(5)); |
||
94 | //~ ferf1->SetParameters(1e4, fs->GetParameter(6), fs->GetParameter(7)); |
||
95 | fe1erf->SetParameters(fs->GetParameter(3), fs->GetParameter(4), fs->GetParameter(5), fs->GetParameter(6), fs->GetParameter(7)); |
||
96 | |||
97 | fg1->SetLineColor(kRed); fg1->SetLineWidth(1); fg1->SetLineStyle(1); fg1->SetRange(fitmin, fitmax); fg1->DrawCopy("SAME"); |
||
98 | //~ fe1->SetLineColor(kBlue); fe1->SetLineWidth(1); fe1->SetLineStyle(1); fe1->SetRange(fitmin, fitmax); fe1->DrawCopy("SAME"); |
||
99 | //~ ferf1->SetLineColor(kYellow); ferf1->SetLineWidth(1);ferf1->SetLineStyle(1);ferf1->SetRange(fitmin, fitmax);ferf1->DrawCopy("SAME"); |
||
100 | fe1erf->SetLineColor(kBlue); fe1erf->SetLineWidth(1);fe1erf->SetLineStyle(1);fe1erf->SetRange(fitmin, fitmax);fe1erf->DrawCopy("SAME"); |
||
101 | |||
102 | double HalfMax = fitampl/2.0; |
||
103 | double MinHalfMax = fs->GetX(HalfMax, -0.5, fitcenter); |
||
104 | double MaxHalfMax = fs->GetX(HalfMax, fitcenter, 1.5); |
||
105 | double FWHM = MaxHalfMax - MinHalfMax; |
||
106 | double sigmaFWHM = fs->GetParameter(2); |
||
107 | printf("Corrected %s resolution FWHM = %.1lf [ps]\n", hTitle, FWHM*1000); |
||
108 | //~ fprintf(fp,"%lf ", FWHM*1000); |
||
109 | |||
110 | sprintf(sbuff, "FWHM = %.0lf ps", FWHM*1000); |
||
111 | leg1->AddEntry((TF1*)fs->Clone(),sbuff, "L"); |
||
112 | leg1->Draw(); |
||
113 | } |
||
114 | |||
115 | // ======================================================================================================= |
||
116 | |||
299 | f9daq | 117 | void plots2(char *fname="480", char *plopt="d", int chich=0, double fitcenter = 1190., double fitw = 70., double comhi_range_hi = 2100., int batch_q=0) |
291 | f9daq | 118 | { |
119 | char sbuff[256]; |
||
120 | |||
121 | char *fitopt="crystal1"; |
||
122 | double inmin=-10; |
||
123 | double inmax=10; |
||
124 | double Ecut_lo = 450.; |
||
125 | double Ecut_hi = 625.; |
||
126 | |||
127 | |||
128 | int printeps = 0; |
||
129 | int printgif=-1, double fitlo=1.0, double fithi=1.0; |
||
130 | int ch=0; |
||
131 | char fullname[256]; |
||
132 | |||
133 | //get ROOT file with histograms |
||
134 | char fnameroot[1024]; |
||
135 | TFile * rootfile; |
||
136 | TDirectory *dir; |
||
137 | |||
138 | sprintf(fnameroot, "root/%s.root", fname); |
||
139 | rootfile = (TFile *) gROOT->FindObject(fname); |
||
140 | if(rootfile==NULL) rootfile = new TFile(fnameroot); |
||
141 | if(rootfile==NULL) { |
||
142 | printf("Cannot open root file %s!!!\n",fnameroot); |
||
143 | return; |
||
144 | } |
||
145 | dir = (TDirectory*) rootfile; |
||
146 | |||
147 | DrSetDrawStyle(); |
||
148 | |||
149 | TCanvas *c[64]; |
||
150 | int cc=-1; |
||
151 | char hname[256], htitle[256]; |
||
152 | TH1F *hp1d, *hp1dcut; TH2F *hp2d; |
||
153 | |||
154 | TLegend *leg[64]; |
||
155 | int legi = -1; |
||
156 | TH1F *legentry[64]; |
||
157 | int legentryi = -1; |
||
158 | |||
159 | TGraph *graph[16]; |
||
160 | int igraph=-1; |
||
161 | |||
162 | int colarr[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, kOrange, 10,11,12,13,14,15,16,17,18,19}; |
||
163 | int legsty[] = {1,7,2,3,9,6,9,5,6}; |
||
164 | |||
165 | TF1 *fg = new TF1("fg", "gaus"); fg->SetNpx(300); |
||
166 | |||
167 | TF1 *fgg = new TF1("fgg", "gaus(0)+gaus(3)"); fg->SetNpx(300); |
||
168 | fgg->SetParName(0,"G1_Const"); fgg->SetParName(3,"G2_Const"); |
||
169 | fgg->SetParName(1,"G1_Mean" ); fgg->SetParName(4,"G2_Mean" ); |
||
170 | fgg->SetParName(2,"G1_Sigma"); fgg->SetParName(5,"G2_Sigma"); |
||
171 | |||
172 | TF1 *fg3 = new TF1("fg3", "gaus(0)+gaus(3)+gaus(6)"); fg3->SetNpx(300); |
||
173 | fg3->SetParName(0,"G1_Const"); fg3->SetParName(3,"G2_Const"); fg3->SetParName(6,"G3_Const"); |
||
174 | fg3->SetParName(1,"G1_Mean" ); fg3->SetParName(4,"G2_Mean" ); fg3->SetParName(7,"G3_Mean" ); |
||
175 | fg3->SetParName(2,"G1_Sigma"); fg3->SetParName(5,"G2_Sigma"); fg3->SetParName(8,"G3_Sigma"); |
||
176 | |||
177 | TF1 *fg4 = new TF1("fg4", "gaus(0)+gaus(3)+gaus(6)+gaus(9)"); fg4->SetNpx(300); |
||
178 | fg4->SetParName(0,"G1_Const"); fg4->SetParName(3,"G2_Const"); fg4->SetParName(6,"G3_Const"); fg4->SetParName(9,"G4_Const"); |
||
179 | fg4->SetParName(1,"G1_Mean" ); fg4->SetParName(4,"G2_Mean" ); fg4->SetParName(7,"G3_Mean" ); fg4->SetParName(10,"G4_Mean" ); |
||
180 | fg4->SetParName(2,"G1_Sigma"); fg4->SetParName(5,"G2_Sigma"); fg4->SetParName(8,"G3_Sigma"); fg4->SetParName(11,"G4_Sigma"); |
||
181 | |||
182 | TF1 *fg5 = new TF1("fg5", "gaus(0)+gaus(3)+gaus(6)+gaus(9)+gaus(12)"); fg5->SetNpx(300); |
||
183 | fg5->SetParName(0,"G1_Const"); fg5->SetParName(3,"G2_Const"); fg5->SetParName(6,"G3_Const"); fg5->SetParName(9,"G4_Const"); fg5->SetParName(12,"G5_Const"); |
||
184 | fg5->SetParName(1,"G1_Mean" ); fg5->SetParName(4,"G2_Mean" ); fg5->SetParName(7,"G3_Mean" ); fg5->SetParName(10,"G4_Mean" ); fg5->SetParName(13,"G5_Mean" ); |
||
185 | fg5->SetParName(2,"G1_Sigma"); fg5->SetParName(5,"G2_Sigma"); fg5->SetParName(8,"G3_Sigma"); fg5->SetParName(11,"G4_Sigma"); fg5->SetParName(14,"G5_Sigma"); |
||
186 | |||
187 | // ------------------------------------------------------------------- |
||
188 | |||
189 | if( strchr(plopt, 'a') != NULL ) { |
||
190 | |||
191 | //~ gStyle->SetOptStat(1111); |
||
192 | gStyle->SetOptStat(0); |
||
193 | gStyle->SetOptFit(0); |
||
194 | |||
299 | f9daq | 195 | c[++cc] = new TCanvas("a", "a", 0, 0, 1600, 900); |
291 | f9daq | 196 | c[cc]->Divide(2,2); |
197 | |||
299 | f9daq | 198 | int draw_cuts = 0; |
199 | int chmap[] = {0,1,2,31}; |
||
200 | |||
201 | for(int ich = 0;ich<4;ich++) { |
||
202 | (c[cc]->cd(ich+1))->SetLogy(1); |
||
203 | sprintf(hname, "hadc%d", chmap[ich]); |
||
291 | f9daq | 204 | hp1d = DrTH1F(dir, hname, ""); |
299 | f9daq | 205 | sprintf(htitle, "ADC%d;ADC;Count", chmap[ich]); hp1d->SetTitle(htitle); |
206 | //~ hp1d->GetXaxis()->SetRangeUser(0,2000); |
||
291 | f9daq | 207 | //~ hp1d->GetYaxis()->SetRangeUser(0.9,hp1d->GetMaximum()*1.1); |
208 | hp1d->SetLineColor(kBlack); |
||
209 | hp1d->DrawClone(); |
||
210 | |||
211 | if(draw_cuts) { |
||
299 | f9daq | 212 | sprintf(hname, "hadc_cut%d", chmap[ich]); |
291 | f9daq | 213 | hp1dcut = DrTH1F(dir, hname, ""); |
214 | hp1dcut->SetLineColor(kRed); |
||
215 | hp1dcut->DrawClone("SAME"); |
||
216 | } |
||
299 | f9daq | 217 | } |
291 | f9daq | 218 | |
299 | f9daq | 219 | sprintf(fullname, "gif/%s_a.gif", fname); c[cc]->SaveAs(fullname); |
291 | f9daq | 220 | } |
221 | |||
222 | // ------------------------------------------------------------------- |
||
223 | |||
299 | f9daq | 224 | if( strchr(plopt, 't') != NULL ) { |
291 | f9daq | 225 | |
226 | gStyle->SetOptStat(1111); |
||
299 | f9daq | 227 | //~ gStyle->SetOptStat(0); |
291 | f9daq | 228 | gStyle->SetOptFit(0); |
229 | |||
299 | f9daq | 230 | c[++cc] = new TCanvas("t", "t", 0, 0, 1600, 900); |
231 | c[cc]->Divide(2,2); |
||
291 | f9daq | 232 | |
299 | f9daq | 233 | int draw_cuts = 0; |
234 | int chmap[] = {0,1,2,31}; |
||
235 | |||
236 | for(int ich = 0;ich<4;ich++) { |
||
237 | (c[cc]->cd(ich+1))->SetLogy(1); |
||
238 | sprintf(hname, "htdc%d", chmap[ich]); |
||
291 | f9daq | 239 | hp1d = DrTH1F(dir, hname, ""); |
299 | f9daq | 240 | sprintf(htitle, "TDC%d - TRIGGER;Time [ns];Count", chmap[ich]); hp1d->SetTitle(htitle); |
241 | hp1d->GetXaxis()->SetRangeUser(-50,50); |
||
291 | f9daq | 242 | //~ hp1d->GetYaxis()->SetRangeUser(0.9,hp1d->GetMaximum()*1.1); |
299 | f9daq | 243 | hp1d->SetLineColor(kBlack); |
291 | f9daq | 244 | hp1d->DrawClone(); |
245 | |||
246 | if(draw_cuts) { |
||
299 | f9daq | 247 | sprintf(hname, "htdc_cut%d", chmap[ich]); |
291 | f9daq | 248 | hp1dcut = DrTH1F(dir, hname, ""); |
249 | hp1dcut->SetLineColor(kRed); |
||
250 | hp1dcut->DrawClone("SAME"); |
||
251 | } |
||
299 | f9daq | 252 | } |
291 | f9daq | 253 | |
299 | f9daq | 254 | sprintf(fullname, "gif/%s_t.gif", fname); c[cc]->SaveAs(fullname); |
291 | f9daq | 255 | } |
299 | f9daq | 256 | |
291 | f9daq | 257 | // ------------------------------------------------------------------- |
258 | |||
299 | f9daq | 259 | if( strchr(plopt, 'f') != NULL ) { |
291 | f9daq | 260 | |
299 | f9daq | 261 | gStyle->SetOptStat(1111); |
262 | //~ gStyle->SetOptStat(0); |
||
263 | gStyle->SetOptFit(0); |
||
291 | f9daq | 264 | |
299 | f9daq | 265 | c[++cc] = new TCanvas("f", "f", 0, 0, 1600, 900); |
266 | c[cc]->Divide(2,2); |
||
291 | f9daq | 267 | |
268 | int draw_cuts = 0; |
||
299 | f9daq | 269 | int chmap[] = {0,1,2,31}; |
291 | f9daq | 270 | |
299 | f9daq | 271 | for(int ich = 0;ich<4;ich++) { |
272 | (c[cc]->cd(ich+1))->SetLogy(1); |
||
273 | sprintf(hname, "hctdc%d", chmap[ich]); |
||
291 | f9daq | 274 | hp1d = DrTH1F(dir, hname, ""); |
299 | f9daq | 275 | sprintf(htitle, "corTDC%d - TRIGGER;Time [ns];Count", chmap[ich]); hp1d->SetTitle(htitle); |
276 | hp1d->GetXaxis()->SetRangeUser(-30,30); |
||
277 | //~ hp1d->GetYaxis()->SetRangeUser(0.9,hp1d->GetMaximum()*1.1); |
||
291 | f9daq | 278 | hp1d->SetLineColor(kBlack); |
299 | f9daq | 279 | hp1d->DrawClone(); |
291 | f9daq | 280 | |
281 | if(draw_cuts) { |
||
299 | f9daq | 282 | sprintf(hname, "hctdc_cut%d", chmap[ich]); |
291 | f9daq | 283 | hp1dcut = DrTH1F(dir, hname, ""); |
284 | hp1dcut->SetLineColor(kRed); |
||
285 | hp1dcut->DrawClone("SAME"); |
||
286 | } |
||
299 | f9daq | 287 | } |
288 | |||
289 | sprintf(fullname, "gif/%s_f.gif", fname); c[cc]->SaveAs(fullname); |
||
291 | f9daq | 290 | } |
291 | |||
292 | // ------------------------------------------------------------------- |
||
293 | |||
294 | if( strchr(plopt, 'c') != NULL ) { |
||
295 | |||
299 | f9daq | 296 | //gStyle->SetOptStat(1111); |
297 | gStyle->SetOptStat(0); |
||
298 | gStyle->SetOptFit(0); |
||
291 | f9daq | 299 | |
299 | f9daq | 300 | c[++cc] = new TCanvas("c", "c", 0, 0, 1600, 900); |
301 | c[cc]->Divide(2,2); |
||
291 | f9daq | 302 | |
299 | f9daq | 303 | int draw_cuts = 0; |
304 | int chmap[] = {0,1,2,31}; |
||
305 | |||
306 | for(int ich = 0;ich<4;ich++) { |
||
307 | (c[cc]->cd(ich+1))->SetLogz(1); |
||
308 | sprintf(hname, "hcor%d", chmap[ich]); |
||
291 | f9daq | 309 | hp2d = DrTH2F(dir, hname, ""); |
299 | f9daq | 310 | sprintf(htitle, "TDC%d - TRIGGER;ADC;Time [ns];Count", chmap[ich]); hp2d->SetTitle(htitle); |
311 | hp2d->GetXaxis()->SetRangeUser(0,2048); |
||
291 | f9daq | 312 | hp2d->DrawClone("COLZ"); |
299 | f9daq | 313 | } |
314 | |||
315 | sprintf(fullname, "gif/%s_c.gif", fname); c[cc]->SaveAs(fullname); |
||
291 | f9daq | 316 | } |
299 | f9daq | 317 | //~ // ------------------------------------------------------------------- |
291 | f9daq | 318 | |
299 | f9daq | 319 | //~ if( strchr(plopt, 'c') != NULL ) { |
291 | f9daq | 320 | |
321 | gStyle->SetOptStat(1111); |
||
299 | f9daq | 322 | //~ gStyle->SetOptStat(0); |
291 | f9daq | 323 | //~ gStyle->SetOptFit(0); |
324 | |||
299 | f9daq | 325 | //~ c[++cc] = new TCanvas("c", "c", 0, 0, 1600, 900); |
291 | f9daq | 326 | |
299 | f9daq | 327 | //~ int draw_cuts = 0; |
291 | f9daq | 328 | |
299 | f9daq | 329 | //~ int ich = chich; |
330 | //~ (c[cc]->cd(1))->SetLogz(1); |
||
331 | //~ sprintf(hname, "hcor%d", ich); |
||
332 | //~ hp2d = DrTH2F(dir, hname, ""); |
||
333 | //~ sprintf(htitle, "TDC%d - TRIGGER;ADC;Time [ns];Count", ich); hp2d->SetTitle(htitle); |
||
334 | //~ hp2d->GetXaxis()->SetRangeUser(512,2048); |
||
335 | //~ hp2d->GetYaxis()->SetRangeUser(-10,20); |
||
336 | //~ hp2d->DrawClone("COLZ"); |
||
291 | f9daq | 337 | |
338 | |||
299 | f9daq | 339 | //~ sprintf(fullname, "gif/%s_c.gif", fname); c[cc]->SaveAs(fullname); |
340 | //~ } |
||
341 | |||
291 | f9daq | 342 | // ------------------------------------------------------------------- |
343 | } |