6 {
7
8
9 TFile* infile = new TFile(filename);
10
11
12 TMultiGraph*
gr =
new TMultiGraph(
"gr",
";#beta#gamma;dE/dx");
13 TMultiGraph* gr_res = new TMultiGraph("gr_res",";dE/dx;#sigma");
14 TMultiGraph* grp = new TMultiGraph("grp",";Momentum;dE/dx");
15 TMultiGraph* grp_res = new TMultiGraph("grp_res",";Momentum;#sigma");
16
17
18 TMultiGraph* grchi = new TMultiGraph("grchi",";#beta#gamma;#chi mean");
19 TMultiGraph* grsigma = new TMultiGraph("grsigma",";#beta#gamma;#sigma");
20 TMultiGraph* grchip = new TMultiGraph("grchip",";Momentum;#chi mean");
21 TMultiGraph* grsigmap = new TMultiGraph("grsigmap",";Momentum;#sigma");
22
23 const int npart = 5;
24 TGraphErrors particle_dedx[npart];
25 TGraph particle_res[npart];
26 TGraphErrors particle_dedxp[npart];
27 TGraph particle_resp[npart];
28 TGraph newchi[npart];
29 TGraph newsigma[npart];
30 TGraph newchip[npart];
31 TGraph newsigmap[npart];
32
33
34
35
36
38 for( int i = 0; i < particles.size(); ++i ){
39 TString particle = particles[i];
40
41 if( particle ==
"pion" )
mass = Widget::mpion;
42 else if( particle ==
"kaon" )
mass = Widget::mkaon;
43 else if( particle ==
"proton" )
mass = Widget::mproton;
44 else if( particle ==
"muon" )
mass = Widget::mmuon;
45 else if( particle ==
"electron" )
mass = Widget::melectron;
46 if(
mass == 0.0 ) exit(1);
47
48 TTree* hadron = (TTree*)infile->Get(particle);
49
50 std::cout << "HadronCalibration: reading " << particle << " in file " << filename << std::endl;
51
52 double dedx_pub;
53 double dedx;
55
56 double dedxerr;
57 double dedx_res;
58
59 double sin_avg;
60 double chi;
61 double chi_pub;
63 double sigma_pub;
64
65 hadron->SetBranchAddress("dedx",&dedx);
66 hadron->SetBranchAddress("dedx_pub",&dedx_pub);
67 hadron->SetBranchAddress(
"bg_avg",&
bg);
68 hadron->SetBranchAddress("error",&dedxerr);
69 hadron->SetBranchAddress("dedxres_avg",&dedx_res);
70
71 hadron->SetBranchAddress("sinth_avg",&sin_avg);
72 hadron->SetBranchAddress("chi",&chi);
73 hadron->SetBranchAddress("chi_pub",&chi_pub);
74 hadron->SetBranchAddress(
"sigma",&
sigma);
75 hadron->SetBranchAddress("sigma_pub",&sigma_pub);
76
77 for( int j = 0; j < hadron->GetEntries(); ++j ){
78 hadron->GetEvent(j);
79
80 particle_dedx[i].SetPoint(j,
bg,dedx);
81 particle_dedx[i].SetPointError(j,0,dedxerr);
82 particle_res[i].SetPoint(j,dedx,dedx_res);
83
84 particle_dedxp[i].SetPoint(j,
bg*
mass,dedx);
85 particle_dedxp[i].SetPointError(j,0,dedxerr);
86 particle_resp[i].SetPoint(j,
bg*
mass,dedx_res);
87
88 newchi[i].SetPoint(j,
bg,chi);
89 newsigma[i].SetPoint(j,
bg,
sigma);
90 newchip[i].SetPoint(j,
bg*
mass,chi);
92 }
93
94 newchi[i].SetMarkerStyle(4);
95 newchi[i].SetMarkerColor(i+1);
96 if( i == 4 ) newchi[i].SetMarkerColor(i+2);
97 newchip[i].SetMarkerStyle(4);
98 newchip[i].SetMarkerColor(i+1);
99 if( i == 4 ) newchip[i].SetMarkerColor(i+2);
100
101 newsigma[i].SetMarkerStyle(4);
102 newsigma[i].SetMarkerColor(i+1);
103 if( i == 4 ) newsigma[i].SetMarkerColor(i+2);
104 newsigmap[i].SetMarkerStyle(4);
105 newsigmap[i].SetMarkerColor(i+1);
106 if( i == 4 ) newsigmap[i].SetMarkerColor(i+2);
107
108 particle_dedx[i].SetMarkerStyle(4);
109 particle_dedx[i].SetMarkerColor(i+1);
110 if( i == 4 ) particle_dedx[i].SetMarkerColor(i+2);
111 particle_dedxp[i].SetMarkerStyle(4);
112 particle_dedxp[i].SetMarkerColor(i+1);
113 if( i == 4 ) particle_dedxp[i].SetMarkerColor(i+2);
114
115 particle_res[i].SetMarkerStyle(4);
116 particle_res[i].SetMarkerColor(i+1);
117 if( i == 4 ) particle_res[i].SetMarkerColor(i+2);
118 particle_resp[i].SetMarkerStyle(4);
119 particle_resp[i].SetMarkerColor(i+1);
120 if( i == 4 ) particle_resp[i].SetMarkerColor(i+2);
121
122 gr->Add(&particle_dedx[i]);
123 gr_res->Add(&particle_res[i]);
124 grp->Add(&particle_dedxp[i]);
125 grp_res->Add(&particle_resp[i]);
126 grchi->Add(&newchi[i]);
127 grsigma->Add(&newsigma[i]);
128 grchip->Add(&newchip[i]);
129 grsigmap->Add(&newsigmap[i]);
130 }
131
132
133
134
135
136
139
140 double bgmin1 = 0.1, bgmax1 = 5;
141 double bgmin2 = 4, bgmax2 = 12;
142 double bgmin3 = 8, bgmax3 = 2000;
143
144 TF1* fdedx1 = new TF1("fdedx1",gc,bgmin1,bgmax1,9,"WidgetCurve");
145 fdedx1->SetParameter(0,1);
146 for( int i = 1; i < 9; ++i ){
147 fdedx1->SetParameter(i,gpar.getCurvePars(i-1));
148 }
149
150 fdedx1->FixParameter(4,1);
151
152 TF1* fdedx2 = new TF1("fdedx2",gc,bgmin2,bgmax2,5,"WidgetCurve");
153 fdedx2->SetParameter(0,2);
154 for( int i = 1; i < 5; ++i ){
155 fdedx2->SetParameter(i,gpar.getCurvePars(7+i));
156 }
157
158 TF1* fdedx3 = new TF1("fdedx3",gc,bgmin3,bgmax3,5,"WidgetCurve");
159 fdedx3->SetParameter(0,3);
160 for( int i = 1; i < 5; ++i ){
161 fdedx3->SetParameter(i,gpar.getCurvePars(11+i));
162 }
163
164 TF1* fdedx4 = new TF1("fdedx4","1",100,100000);
165
166 TCanvas* bandcan = new TCanvas("bandcan","dE/dx",820,750);
167 grp->Draw("APE");
168 bandcan->SaveAs("plots/dedxbands.eps");
169 delete bandcan;
170
171 TCanvas* logbandcan = new TCanvas("logbandcan","dE/dx",820,750);
172 logbandcan->cd()->SetLogy();
173 grp->Draw("APE");
174 logbandcan->SaveAs("plots/dedxbands_log.eps");
175 delete logbandcan;
176
177 TCanvas* bgcurvecan = new TCanvas("bgcurvecan","dE/dx",820,750);
178 bgcurvecan->cd()->SetLogy();
179 bgcurvecan->cd()->SetLogx();
181
182 int stat1 =
gr->Fit(
"fdedx1",
"",
"",bgmin1,bgmax1);
183 for( int i = 0; i < 50; ++i ){
184 if( stat1 == 0 ) break;
185 stat1 =
gr->Fit(
"fdedx1",
"",
"",bgmin1,bgmax1);
186 }
187 int stat2 =
gr->Fit(
"fdedx2",
"",
"",bgmin2,bgmax2);
188 for( int i = 0; i < 50; ++i ){
189 if( stat2 == 0 ) break;
190 stat2 =
gr->Fit(
"fdedx2",
"",
"",bgmin2,bgmax2);
191 }
192 int stat3 =
gr->Fit(
"fdedx3",
"",
"",bgmin3,bgmax3);
193 for( int i = 0; i < 50; ++i ){
194 if( stat3 == 0 ) break;
195 stat3 =
gr->Fit(
"fdedx3",
"",
"",bgmin3,bgmax3);
196 }
197
198
199 if( stat1 != 0 ) std::cout << "WARNING: BG FIT 1 FAILED..." << std::endl;
200 for( int i = 1; i < 9; ++i ){
201 gpar.setCurvePars(i-1,fdedx1->GetParameter(i));
202 }
203 if( stat2 != 0 ) std::cout << "WARNING: BG FIT 2 FAILED..." << std::endl;
204 for( int i = 1; i < 5; ++i ){
205 gpar.setCurvePars(7+i,fdedx2->GetParameter(i));
206 }
207 if( stat3 != 0 ) std::cout << "WARNING: BG FIT 3 FAILED..." << std::endl;
208 for( int i = 1; i < 5; ++i ){
209 gpar.setCurvePars(11+i,fdedx3->GetParameter(i));
210 }
211
212 fdedx1->SetLineColor(kBlack);
213 fdedx1->Draw("same");
214 fdedx2->SetLineColor(kBlue);
215 fdedx2->Draw("same");
216 fdedx3->SetLineColor(kRed);
217 fdedx3->Draw("same");
218 fdedx4->SetLineColor(kGray);
219 fdedx4->Draw("same");
220
221 TLegend* tleg = new TLegend(0.4,0.6,0.6,0.8);
222 for( int i = 0; i < 5; ++i ){
223 tleg->AddEntry(&particle_dedx[i],particles[i],"p");
224 }
225 tleg->Draw("same");
226
227 bgcurvecan->SaveAs("plots/bgcurve.eps");
228 delete bgcurvecan;
229
230
231
232
233
234
235 double A = 4.5,
B = 10;
236
237 TMultiGraph* fit_res = new TMultiGraph("fit_res",";#beta#gamma;Residual");
238 TGraph particle_residual[npart];
239 int respoint = 1;
240 double rmin = 1.0, rmax = 1.0;
241 for( int i = 0; i < npart; ++i ){
242 for( int j = 0; j < particle_dedx[i].GetN(); ++j ){
244 particle_dedx[i].GetPoint(j,x,
y);
245 if(
y == 0 )
continue;
246 if( x < A )
247 fit = fdedx1->Eval(x);
248 else if( x < B )
249 fit = fdedx2->Eval(x);
250 else
251 fit = fdedx3->Eval(x);
252
253
254 if( npart == 4 ) fit = 1.0;
255
256 particle_residual[i].SetPoint(respoint++,x,fit/
y);
257 if( fit/
y < rmin ) rmin = fit/
y;
258 else if( fit/
y > rmax ) rmax = fit/
y;
259 }
260
261 particle_residual[i].SetMarkerStyle(4);
262 particle_residual[i].SetMarkerColor(i+1);
263 if( i == 4 ) particle_residual[i].SetMarkerColor(i+2);
264 fit_res->Add(&particle_residual[i]);
265 }
266 fit_res->SetMinimum(rmin*0.98);
267 fit_res->SetMaximum(rmax*1.02);
268
269 TCanvas* bgrescan = new TCanvas("bgrescan","dE/dx",820,750);
270 bgrescan->cd()->SetLogx();
271 fit_res->GetXaxis()->SetRange(0.05,5000);
272 fit_res->Draw("AP");
273 tleg->Draw("same");
274
275 bgrescan->SaveAs("plots/bgresidual.eps");
276 delete bgrescan;
277
278
279
280
281
282
283 TF1* sigvsdedx = new TF1("sigvsdedx","[0]+[1]*x",0.0,10.0);
284 sigvsdedx->SetParameter(0,gpar.getDedxPars(0));
285 sigvsdedx->SetParameter(1,gpar.getDedxPars(1));
286
287 TCanvas* sigcan = new TCanvas("sigcan","dE/dx",820,750);
288 sigcan->cd();
289 gr_res->Draw("APE");
290 tleg->Draw("same");
291
292 int status = gr_res->Fit("sigvsdedx","qm","",0.0,4.0);
293 for( int i = 0; i < 10; ++i ){
294 if( status == 0 ) break;
295 status = gr_res->Fit("sigvsdedx","q","",0.0,4.0);
296 }
297 sigcan->SaveAs("plots/sigmavsdedx.eps");
298 delete sigcan;
299
300 if( status != 0 ) std::cout << "WARNING: SIGMA VS DEDX FIT FAILED..." << std::endl;
301 gpar.setDedxPars(0,sigvsdedx->GetParameter(0));
302 gpar.setDedxPars(1,sigvsdedx->GetParameter(1));
303
304
305 gpar.printParameters("parameters.bgcurve.fit");
306
307 sigvsdedx->Draw("same");
308 tleg->Draw("same");
309
310
311
312
313
314
315 TLine* line0 = new TLine(0,0,10000,0);
316 line0->SetLineStyle(kDashed);
317 line0->SetLineColor(kRed);
318 TLine* line1 = new TLine(0,1,10000,1);
319 line1->SetLineStyle(kDashed);
320 line1->SetLineColor(kRed);
321
322 TCanvas* cbgcan = new TCanvas("cbgcan","Mean #chi vs. #beta#gamma");
323 grchi->SetMinimum(-0.5);
324 grchi->SetMaximum(+0.5);
325 grchi->Draw("AP");
326 line0->Draw("same");
327 tleg->Draw("same");
328 cbgcan->SaveAs("plots/chimeanVSbetagamma.eps");
329
330 grchi->GetXaxis()->SetLimits(0,25);
331 grchi->Draw("AP");
332 line0->Draw("same");
333 tleg->Draw("same");
334 cbgcan->SaveAs("plots/chimeanVSbetagamma_zoom.eps");
335
336
337
338 grsigma->SetMinimum(0.5);
339 grsigma->SetMaximum(1.5);
340 grsigma->Draw("AP");
341 line1->Draw("same");
342 tleg->Draw("same");
343 cbgcan->SaveAs("plots/sigmaVSbetagamma.eps");
344
345 grsigma->GetXaxis()->SetLimits(0,25);
346 grsigma->Draw("AP");
347 line1->Draw("same");
348 tleg->Draw("same");
349 cbgcan->SaveAs("plots/sigmaVSbetagamma_zoom.eps");
350
351 TCanvas* cpcan = new TCanvas("cpcan","Mean #chi vs. momentum");
352 grchip->SetMinimum(-0.5);
353 grchip->SetMaximum(+0.5);
354 grchip->Draw("AP");
355 line0->Draw("same");
356 tleg->Draw("same");
357 cpcan->SaveAs("plots/chimeanVSmomentum.eps");
358
359 grsigmap->SetMinimum(0.5);
360 grsigmap->SetMaximum(1.5);
361 grsigmap->Draw("AP");
362 line1->Draw("same");
363 tleg->Draw("same");
364 cpcan->SaveAs("plots/sigmaVSmomentum.eps");
365
366 delete cbgcan;
367 delete cpcan;
368 delete line0;
369 delete line1;
371 delete gr_res;
372 delete grp;
373 delete grp_res;
374 delete grchi;
375 delete grsigma;
376 delete grchip;
377 delete grsigmap;
378}