9 TFile* infile =
new TFile(filename);
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");
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");
24 TGraphErrors particle_dedx[npart];
25 TGraph particle_res[npart];
26 TGraphErrors particle_dedxp[npart];
27 TGraph particle_resp[npart];
29 TGraph newsigma[npart];
30 TGraph newchip[npart];
31 TGraph newsigmap[npart];
38 for(
int i = 0; i < particles.size(); ++i ){
39 TString particle = particles[i];
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);
48 TTree* hadron = (TTree*)infile->Get(particle);
50 std::cout <<
"HadronCalibration: reading " << particle <<
" in file " << filename << std::endl;
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);
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);
77 for(
int j = 0; j < hadron->GetEntries(); ++j ){
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);
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);
88 newchi[i].SetPoint(j,
bg,chi);
89 newsigma[i].SetPoint(j,
bg,
sigma);
90 newchip[i].SetPoint(j,
bg*
mass,chi);
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);
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);
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);
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);
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]);
140 double bgmin1 = 0.1, bgmax1 = 5;
141 double bgmin2 = 4, bgmax2 = 12;
142 double bgmin3 = 8, bgmax3 = 2000;
144 TF1* fdedx1 =
new TF1(
"fdedx1",gc,bgmin1,bgmax1,9,
"WidgetCurve");
145 fdedx1->SetParameter(0,1);
146 for(
int i = 1; i < 9; ++i ){
150 fdedx1->FixParameter(4,1);
152 TF1* fdedx2 =
new TF1(
"fdedx2",gc,bgmin2,bgmax2,5,
"WidgetCurve");
153 fdedx2->SetParameter(0,2);
154 for(
int i = 1; i < 5; ++i ){
158 TF1* fdedx3 =
new TF1(
"fdedx3",gc,bgmin3,bgmax3,5,
"WidgetCurve");
159 fdedx3->SetParameter(0,3);
160 for(
int i = 1; i < 5; ++i ){
164 TF1* fdedx4 =
new TF1(
"fdedx4",
"1",100,100000);
166 TCanvas* bandcan =
new TCanvas(
"bandcan",
"dE/dx",820,750);
168 bandcan->SaveAs(
"plots/dedxbands.eps");
171 TCanvas* logbandcan =
new TCanvas(
"logbandcan",
"dE/dx",820,750);
172 logbandcan->cd()->SetLogy();
174 logbandcan->SaveAs(
"plots/dedxbands_log.eps");
177 TCanvas* bgcurvecan =
new TCanvas(
"bgcurvecan",
"dE/dx",820,750);
178 bgcurvecan->cd()->SetLogy();
179 bgcurvecan->cd()->SetLogx();
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);
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);
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);
199 if( stat1 != 0 ) std::cout <<
"WARNING: BG FIT 1 FAILED..." << std::endl;
200 for(
int i = 1; i < 9; ++i ){
203 if( stat2 != 0 ) std::cout <<
"WARNING: BG FIT 2 FAILED..." << std::endl;
204 for(
int i = 1; i < 5; ++i ){
207 if( stat3 != 0 ) std::cout <<
"WARNING: BG FIT 3 FAILED..." << std::endl;
208 for(
int i = 1; i < 5; ++i ){
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");
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");
227 bgcurvecan->SaveAs(
"plots/bgcurve.eps");
235 double A = 4.5, B = 10;
237 TMultiGraph* fit_res =
new TMultiGraph(
"fit_res",
";#beta#gamma;Residual");
238 TGraph particle_residual[npart];
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;
247 fit = fdedx1->Eval(
x);
249 fit = fdedx2->Eval(
x);
251 fit = fdedx3->Eval(
x);
254 if( npart == 4 ) fit = 1.0;
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;
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]);
266 fit_res->SetMinimum(rmin*0.98);
267 fit_res->SetMaximum(rmax*1.02);
269 TCanvas* bgrescan =
new TCanvas(
"bgrescan",
"dE/dx",820,750);
270 bgrescan->cd()->SetLogx();
271 fit_res->GetXaxis()->SetRange(0.05,5000);
275 bgrescan->SaveAs(
"plots/bgresidual.eps");
283 TF1* sigvsdedx =
new TF1(
"sigvsdedx",
"[0]+[1]*x",0.0,10.0);
287 TCanvas* sigcan =
new TCanvas(
"sigcan",
"dE/dx",820,750);
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);
297 sigcan->SaveAs(
"plots/sigmavsdedx.eps");
300 if( status != 0 ) std::cout <<
"WARNING: SIGMA VS DEDX FIT FAILED..." << std::endl;
307 sigvsdedx->Draw(
"same");
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);
322 TCanvas* cbgcan =
new TCanvas(
"cbgcan",
"Mean #chi vs. #beta#gamma");
323 grchi->SetMinimum(-0.5);
324 grchi->SetMaximum(+0.5);
328 cbgcan->SaveAs(
"plots/chimeanVSbetagamma.eps");
330 grchi->GetXaxis()->SetLimits(0,25);
334 cbgcan->SaveAs(
"plots/chimeanVSbetagamma_zoom.eps");
338 grsigma->SetMinimum(0.5);
339 grsigma->SetMaximum(1.5);
343 cbgcan->SaveAs(
"plots/sigmaVSbetagamma.eps");
345 grsigma->GetXaxis()->SetLimits(0,25);
349 cbgcan->SaveAs(
"plots/sigmaVSbetagamma_zoom.eps");
351 TCanvas* cpcan =
new TCanvas(
"cpcan",
"Mean #chi vs. momentum");
352 grchip->SetMinimum(-0.5);
353 grchip->SetMaximum(+0.5);
357 cpcan->SaveAs(
"plots/chimeanVSmomentum.eps");
359 grsigmap->SetMinimum(0.5);
360 grsigmap->SetMaximum(1.5);
361 grsigmap->Draw(
"AP");
364 cpcan->SaveAs(
"plots/sigmaVSmomentum.eps");
384 TFile* infile =
new TFile(filename);
387 TMultiGraph* gr =
new TMultiGraph(
"gr",
";#beta#gamma;dE/dx");
388 TMultiGraph* gr_res =
new TMultiGraph(
"gr_res",
";dE/dx;#sigma");
389 TMultiGraph* grp =
new TMultiGraph(
"grp",
";Momentum;dE/dx");
390 TMultiGraph* grp_res =
new TMultiGraph(
"grp_res",
";Momentum;#sigma");
393 TMultiGraph* grchi =
new TMultiGraph(
"grchi",
";#beta#gamma;#chi mean");
394 TMultiGraph* grsigma =
new TMultiGraph(
"grsigma",
";#beta#gamma;#sigma");
395 TMultiGraph* grchip =
new TMultiGraph(
"grchip",
";Momentum;#chi mean");
396 TMultiGraph* grsigmap =
new TMultiGraph(
"grsigmap",
";Momentum;#sigma");
399 TGraphErrors particle_dedx[npart];
400 TGraph particle_res[npart];
401 TGraphErrors particle_dedxp[npart];
402 TGraph particle_resp[npart];
403 TGraph newchi[npart];
404 TGraph newsigma[npart];
405 TGraph newchip[npart];
406 TGraph newsigmap[npart];
413 for(
int i = 0; i < particles.size(); ++i ){
414 TString particle = particles[i];
416 if( particle ==
"pion" )
mass = Widget::mpion;
417 else if( particle ==
"kaon" )
mass = Widget::mkaon;
418 else if( particle ==
"proton" )
mass = Widget::mproton;
419 else if( particle ==
"muon" )
mass = Widget::mmuon;
420 else if( particle ==
"electron" )
mass = Widget::melectron;
421 if(
mass == 0.0 ) exit(1);
423 TTree* hadron = (TTree*)infile->Get(particle);
425 std::cout <<
"HadronCalibration: reading " << particle <<
" in file " << filename << std::endl;
440 hadron->SetBranchAddress(
"dedx",&dedx);
441 hadron->SetBranchAddress(
"dedx_pub",&dedx_pub);
442 hadron->SetBranchAddress(
"bg_avg",&
bg);
443 hadron->SetBranchAddress(
"error",&dedxerr);
444 hadron->SetBranchAddress(
"dedxres_avg",&dedx_res);
446 hadron->SetBranchAddress(
"sinth_avg",&sin_avg);
447 hadron->SetBranchAddress(
"chi",&chi);
448 hadron->SetBranchAddress(
"chi_pub",&chi_pub);
449 hadron->SetBranchAddress(
"sigma",&
sigma);
450 hadron->SetBranchAddress(
"sigma_pub",&sigma_pub);
452 for(
int j = 0; j < hadron->GetEntries(); ++j ){
455 particle_dedx[i].SetPoint(j,
bg,dedx);
456 particle_dedx[i].SetPointError(j,0,dedxerr);
457 particle_res[i].SetPoint(j,dedx,dedx_res);
459 particle_dedxp[i].SetPoint(j,
bg*
mass,dedx);
460 particle_dedxp[i].SetPointError(j,0,dedxerr);
461 particle_resp[i].SetPoint(j,
bg*
mass,dedx_res);
463 newchi[i].SetPoint(j,
bg,chi);
464 newsigma[i].SetPoint(j,
bg,
sigma);
465 newchip[i].SetPoint(j,
bg*
mass,chi);
469 newchi[i].SetMarkerStyle(4);
470 newchi[i].SetMarkerColor(i+1);
471 if( i == 4 ) newchi[i].SetMarkerColor(i+2);
472 newchip[i].SetMarkerStyle(4);
473 newchip[i].SetMarkerColor(i+1);
474 if( i == 4 ) newchip[i].SetMarkerColor(i+2);
476 newsigma[i].SetMarkerStyle(4);
477 newsigma[i].SetMarkerColor(i+1);
478 if( i == 4 ) newsigma[i].SetMarkerColor(i+2);
479 newsigmap[i].SetMarkerStyle(4);
480 newsigmap[i].SetMarkerColor(i+1);
481 if( i == 4 ) newsigmap[i].SetMarkerColor(i+2);
483 particle_dedx[i].SetMarkerStyle(4);
484 particle_dedx[i].SetMarkerColor(i+1);
485 if( i == 4 ) particle_dedx[i].SetMarkerColor(i+2);
486 particle_dedxp[i].SetMarkerStyle(4);
487 particle_dedxp[i].SetMarkerColor(i+1);
488 if( i == 4 ) particle_dedxp[i].SetMarkerColor(i+2);
490 particle_res[i].SetMarkerStyle(4);
491 particle_res[i].SetMarkerColor(i+1);
492 if( i == 4 ) particle_res[i].SetMarkerColor(i+2);
493 particle_resp[i].SetMarkerStyle(4);
494 particle_resp[i].SetMarkerColor(i+1);
495 if( i == 4 ) particle_resp[i].SetMarkerColor(i+2);
497 gr->Add(&particle_dedx[i]);
498 gr_res->Add(&particle_res[i]);
499 grp->Add(&particle_dedxp[i]);
500 grp_res->Add(&particle_resp[i]);
501 grchi->Add(&newchi[i]);
502 grsigma->Add(&newsigma[i]);
503 grchip->Add(&newchip[i]);
504 grsigmap->Add(&newsigmap[i]);
507 TCanvas* bandcan =
new TCanvas(
"bandcan",
"dE/dx",820,750);
509 bandcan->SaveAs(
"plots/dedxbands.eps");
512 TCanvas* logbandcan =
new TCanvas(
"logbandcan",
"dE/dx",820,750);
513 logbandcan->cd()->SetLogy();
515 logbandcan->SaveAs(
"plots/dedxbands_log.eps");
518 TCanvas* bgcurvecan =
new TCanvas(
"bgcurvecan",
"dE/dx",820,750);
519 bgcurvecan->cd()->SetLogy();
520 bgcurvecan->cd()->SetLogx();
527 TLine* line0 =
new TLine(0,0,10000,0);
528 line0->SetLineStyle(kDashed);
529 line0->SetLineColor(kRed);
530 TLine* line1 =
new TLine(0,1,10000,1);
531 line1->SetLineStyle(kDashed);
532 line1->SetLineColor(kRed);
534 TCanvas* cbgcan =
new TCanvas(
"cbgcan",
"Mean #chi vs. #beta#gamma");
535 grchi->SetMinimum(-0.5);
536 grchi->SetMaximum(+0.5);
539 TLegend* tleg =
new TLegend(0.4,0.6,0.6,0.8);
540 for(
int i = 0; i < 5; ++i ){
541 tleg->AddEntry(&particle_dedx[i],particles[i],
"p");
544 cbgcan->SaveAs(
"plots/chimeanVSbetagamma.eps");
546 grchi->GetXaxis()->SetLimits(0,25);
550 cbgcan->SaveAs(
"plots/chimeanVSbetagamma_zoom.eps");
554 grsigma->SetMinimum(0.5);
555 grsigma->SetMaximum(1.5);
559 cbgcan->SaveAs(
"plots/sigmaVSbetagamma.eps");
561 grsigma->GetXaxis()->SetLimits(0,25);
565 cbgcan->SaveAs(
"plots/sigmaVSbetagamma_zoom.eps");
567 TCanvas* cpcan =
new TCanvas(
"cpcan",
"Mean #chi vs. momentum");
568 grchip->SetMinimum(-0.5);
569 grchip->SetMaximum(+0.5);
573 cpcan->SaveAs(
"plots/chimeanVSmomentum.eps");
575 grsigmap->SetMinimum(0.5);
576 grsigmap->SetMaximum(1.5);
577 grsigmap->Draw(
"AP");
580 cpcan->SaveAs(
"plots/sigmaVSmomentum.eps");
582 TFile* outfile =
new TFile(
"dedxbands.root",
"RECREATE");
611 TFile* infile =
new TFile(filename);
612 TTree* hadron = (TTree*)infile->Get(
"track");
614 std::cout <<
"HadronCalibration: reading in file " << filename << std::endl;
636 hadron->SetBranchAddress(
"dedx", &dedxpub);
637 hadron->SetBranchAddress(
"dedxsat", &dedx);
638 hadron->SetBranchAddress(
"pF", &p);
639 hadron->SetBranchAddress(
"costh", &costh);
640 hadron->SetBranchAddress(
"db", &db);
641 hadron->SetBranchAddress(
"dz", &dz);
642 hadron->SetBranchAddress(
"chiPi", &chiPi);
643 hadron->SetBranchAddress(
"eopst", &eop);
646 hadron->SetBranchAddress(
"numGoodHits", &b3nhit);
648 hadron->SetBranchAddress(
"lNHitsUsed", &b2nhit);
651 const int m_nhitbins = 20;
652 const double m_uppernhit = 32.5, m_lowernhit = 5.5;
654 double nhitstep = (m_uppernhit-m_lowernhit)/m_nhitbins;
657 TH1F* hdedx_nhit[m_nhitbins];
658 TH1F* hdedx_nhit_pub[m_nhitbins];
661 for(
int i = 0; i < m_nhitbins; ++i ){
662 char histname[100],histname2[100],histname3[100],histname4[100],histname5[100],histname6[100];
663 sprintf(histname,
"dedx_nhit_%d",i);
664 sprintf(histname4,
"dedxpub_nhit_%d",i);
666 hdedx_nhit[i] =
new TH1F(histname,histname,200,-1,1);
667 hdedx_nhit_pub[i] =
new TH1F(histname4,histname4,200,-1,1);
671 double sumnhit[m_nhitbins];
672 double sumbg[m_nhitbins];
673 double sumsin[m_nhitbins];
674 int sumsize[m_nhitbins];
675 for(
int i = 0; i < m_nhitbins; ++i ){
686 std::ifstream parfile(
"sat-pars.txt");
687 if( !parfile.fail() ){
688 for(
int i = 0; i < 5; ++i ){
689 parfile >> hadpar[i];
701 for(
unsigned int index = 0; index < hadron->GetEntries(); ++index ){
702 hadron->GetEvent(index);
704 bg = fabs(p)/Widget::mpion;
708 nhit = std::floor(b3nhit);
712 if( dedx <= 0 || nhit <= m_lowernhit || nhit >= m_uppernhit )
715 int nhitBin = (int)((nhit-m_lowernhit)/(m_uppernhit-m_lowernhit) * m_nhitbins);
717 double dedx_new = dedx;
718 if( !mcflag ) dedx_new = m_hadsat.
D2I(costh,m_hadsat.
I2D(costh,1.0)*dedx);
721 double chi_new = (dedx_new-dedx_cur)/dedx_res;
724 int i = (int) ( (fabs(nhit)-m_lowernhit)/nhitstep );
725 hdedx_nhit[i]->Fill((dedx_new-dedx_cur)/res_cor);
726 hdedx_nhit_pub[i]->Fill((dedx_new-dedx_cur)/res_cor);
728 if( fabs(nhit-(m_lowernhit+0.5*nhitstep+nhitBin*nhitstep)) < 0.5*nhitstep ){
729 sumnhit[nhitBin] += nhit;
730 sumbg[nhitBin] +=
bg;
731 sumsin[nhitBin] += sqrt(1-costh*costh);
732 sumsize[nhitBin] += 1;
743 TTree* nhitTree =
new TTree(
"sigmavsnhit",
"dE/dx means and errors");
753 nhitTree->Branch(
"dedx",&nhitdedx,
"dedx/D");
754 nhitTree->Branch(
"width",&nhitsigma,
"width/D");
755 nhitTree->Branch(
"dedx_pub",&nhitdedxpub,
"dedx_pub/D");
756 nhitTree->Branch(
"sigma_pub",&nhitsigmapub,
"sigma_pub/D");
757 nhitTree->Branch(
"nhit_avg",&nhitavg,
"nhit_avg/D");
758 nhitTree->Branch(
"bg_avg",&nhitbgavg,
"bg_avg/D");
759 nhitTree->Branch(
"sin_avg",&nhitsinavg,
"sin_avg/D");
761 double nhits[m_nhitbins], nhitserr[m_nhitbins], nhitres[m_nhitbins], nhitreserr[m_nhitbins];
764 double avg_sigma = 0.0;
765 for(
int i = 0; i < m_nhitbins; ++i ){
768 nhitavg = sumnhit[i]/sumsize[i];
769 nhitbgavg = sumbg[i]/sumsize[i];
770 nhitsinavg = sumsin[i]/sumsize[i];
773 int fs = hdedx_nhit[i]->Fit(
"gaus",
"ql");
774 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
775 double mean = hdedx_nhit[i]->GetFunction(
"gaus")->GetParameter(1);
776 double width = hdedx_nhit[i]->GetFunction(
"gaus")->GetParameter(2);
777 fs = hdedx_nhit[i]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
778 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
780 nhitdedx = hdedx_nhit[i]->GetFunction(
"gaus")->GetParameter(1);
781 nhitsigma = hdedx_nhit[i]->GetFunction(
"gaus")->GetParameter(2);
785 fs = hdedx_nhit_pub[i]->Fit(
"gaus",
"ql");
786 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
787 mean = hdedx_nhit_pub[i]->GetFunction(
"gaus")->GetParameter(1);
788 width = hdedx_nhit_pub[i]->GetFunction(
"gaus")->GetParameter(2);
789 fs = hdedx_nhit_pub[i]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
790 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
792 nhitdedxpub = hdedx_nhit_pub[i]->GetFunction(
"gaus")->GetParameter(1);
793 nhitsigmapub = hdedx_nhit_pub[i]->GetFunction(
"gaus")->GetParameter(2);
799 nhitres[i] = nhitsigma;
800 nhitreserr[i] = hdedx_nhit[i]->GetFunction(
"gaus")->GetParError(2);
802 avg_sigma += nhitres[i];
808 avg_sigma = avg_sigma/m_nhitbins;
809 for(
int i = 0; i < m_nhitbins; ++i ){
810 nhitres[i] = nhitres[i]/avg_sigma;
811 nhitreserr[i] = nhitreserr[i]/avg_sigma;
815 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp",900,900);
817 std::stringstream psname; psname <<
"plots/sigmavsnhit_fits.ps[";
818 ctmp->Print(psname.str().c_str());
819 psname.str(
""); psname <<
"plots/sigmavsnhit_fits.ps";
820 for(
int i = 0 ; i < m_nhitbins; ++i ){
822 hdedx_nhit[i]->Draw();
824 ctmp->Print(psname.str().c_str());
826 psname.str(
""); psname <<
"plots/sigmavsnhit_fits.ps]";
827 ctmp->Print(psname.str().c_str());
836 TCanvas* sigvsnhitcan =
new TCanvas(
"sigvsnhitcan",
"#sigma vs. nHit",600,600);
838 TGraphErrors* gr =
new TGraphErrors(m_nhitbins,
nhits,nhitres,nhitserr,nhitreserr);
839 gr->SetMarkerStyle(8);
840 gr->SetMarkerSize(0.3);
841 gr->SetTitle(
";nHit;#sigma");
858 double nhitmin = 2, nhitmax = 50;
859 TF1* fsigma =
new TF1(
"fsigma",gs,nhitmin,nhitmax,6,
"WidgetSigma");
860 fsigma->SetParameter(0,2);
861 for(
int i = 1; i < 6; ++i ){
866 int status = gr->Fit(
"fsigma",
"qm",
"",nhitmin,nhitmax);
867 for(
int i = 0; i < 10; ++i ){
868 if( status == 0 )
break;
869 status = gr->Fit(
"fsigma",
"q",
"",nhitmin,nhitmax);
872 if( status != 0 ) std::cout <<
"WARNING: SIGMA VS NHIT FIT FAILED..." << std::endl;
873 for(
int j = 1; j < 6; ++j ){
877 fsigma->Draw(
"same");
878 sigvsnhitcan->SaveAs(
"plots/sigmavsnhit.eps");
888 TFile* infile =
new TFile(filename);
889 TTree* hadron = (TTree*)infile->Get(
"track");
891 std::cout <<
"HadronCalibration: reading in file " << filename << std::endl;
913 hadron->SetBranchAddress(
"dedx", &dedxpub);
914 hadron->SetBranchAddress(
"dedxsat", &dedx);
915 hadron->SetBranchAddress(
"pF", &p);
916 hadron->SetBranchAddress(
"costh", &costh);
917 hadron->SetBranchAddress(
"db", &db);
918 hadron->SetBranchAddress(
"dz", &dz);
919 hadron->SetBranchAddress(
"chiPi", &chiPi);
920 hadron->SetBranchAddress(
"eopst", &eop);
923 hadron->SetBranchAddress(
"numGoodHits", &b3nhit);
925 hadron->SetBranchAddress(
"lNHitsUsed", &b2nhit);
928 const int m_sinbins = 20;
929 const double m_uppersin = 1.0, m_lowersin = 0.36;
931 double sinstep = (m_uppersin-m_lowersin)/m_sinbins;
934 TH1F* hdedx_sin[m_sinbins];
935 TH1F* hdedx_sin_pub[m_sinbins];
938 for(
int i = 0; i < m_sinbins; ++i ){
939 char histname[100],histname2[100],histname3[100],histname4[100],histname5[100],histname6[100];
940 sprintf(histname,
"dedx_sin_%d",i);
941 sprintf(histname4,
"dedxpub_sin_%d",i);
943 hdedx_sin[i] =
new TH1F(histname,histname,200,-1,1);
944 hdedx_sin_pub[i] =
new TH1F(histname4,histname4,200,-1,1);
948 double sumnhit[m_sinbins];
949 double sumbg[m_sinbins];
950 double sumsin[m_sinbins];
951 int sumsize[m_sinbins];
952 for(
int i = 0; i < m_sinbins; ++i ){
963 std::ifstream parfile(
"sat-pars.txt");
964 if( !parfile.fail() ){
965 for(
int i = 0; i < 5; ++i ){
966 parfile >> hadpar[i];
978 for(
unsigned int index = 0; index < hadron->GetEntries(); ++index ){
979 hadron->GetEvent(index);
981 if( costh != costh )
continue;
983 bg = fabs(p)/Widget::mpion;
984 double sin = sqrt(1-costh*costh);
988 nhit = std::floor(b3nhit);
992 if( dedx <= 0 || nhit <= 0 || nhit >= 100 ||
sin > m_uppersin ||
sin < m_lowersin )
995 int sinBin = (int)((
sin-m_lowersin)/(m_uppersin-m_lowersin) * m_sinbins);
997 double dedx_new = dedx;
998 if( !mcflag ) dedx_new = m_hadsat.
D2I(costh,m_hadsat.
I2D(costh,1.0)*dedx);
1000 double dedx_res = gpar.
sigmaPrediction(dedx,nhit,sqrt(1-costh*costh));
1001 double chi_new = (dedx_new-dedx_cur)/dedx_res;
1004 int i = (int) ( (
sin-m_lowersin)/sinstep );
1005 hdedx_sin[i]->Fill((dedx_new-dedx_cur)/res_cor);
1006 hdedx_sin_pub[i]->Fill((dedx_new-dedx_cur)/res_cor);
1008 if( fabs(
sin-(m_lowersin+0.5*sinstep+sinBin*sinstep)) < 0.5*sinstep ){
1009 sumnhit[sinBin] += nhit;
1010 sumbg[sinBin] +=
bg;
1011 sumsin[sinBin] += sqrt(1-costh*costh);
1012 sumsize[sinBin] += 1;
1023 TTree* sinTree =
new TTree(
"sigmavssin",
"dE/dx means and errors");
1033 sinTree->Branch(
"dedx",&sindedx,
"dedx/D");
1034 sinTree->Branch(
"width",&sinsigma,
"width/D");
1035 sinTree->Branch(
"dedx_pub",&sindedxpub,
"dedx_pub/D");
1036 sinTree->Branch(
"sigma_pub",&sinsigmapub,
"sigma_pub/D");
1037 sinTree->Branch(
"nhit_avg",&sinnhitavg,
"nhit_avg/D");
1038 sinTree->Branch(
"bg_avg",&sinbgavg,
"bg_avg/D");
1039 sinTree->Branch(
"sin_avg",&sinavg,
"sin_avg/D");
1041 double sins[m_sinbins], sinserr[m_sinbins], sinres[m_sinbins], sinreserr[m_sinbins];
1044 double avg_sigma = 0.0;
1045 for(
int i = 0; i < m_sinbins; ++i ){
1048 sinnhitavg = sumnhit[i]/sumsize[i];
1049 sinbgavg = sumbg[i]/sumsize[i];
1050 sinavg = sumsin[i]/sumsize[i];
1054 int fs = hdedx_sin[i]->Fit(
"gaus",
"ql");
1055 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
1056 double mean = hdedx_sin[i]->GetFunction(
"gaus")->GetParameter(1);
1057 double width = hdedx_sin[i]->GetFunction(
"gaus")->GetParameter(2);
1058 fs = hdedx_sin[i]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
1059 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
1061 sindedx = hdedx_sin[i]->GetFunction(
"gaus")->GetParameter(1);
1062 sinsigma = hdedx_sin[i]->GetFunction(
"gaus")->GetParameter(2);
1066 fs = hdedx_sin_pub[i]->Fit(
"gaus",
"ql");
1067 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
1068 mean = hdedx_sin_pub[i]->GetFunction(
"gaus")->GetParameter(1);
1069 width = hdedx_sin_pub[i]->GetFunction(
"gaus")->GetParameter(2);
1070 fs = hdedx_sin_pub[i]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
1071 if( fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " << fs << std::endl;
1073 sindedxpub = hdedx_sin_pub[i]->GetFunction(
"gaus")->GetParameter(1);
1074 sinsigmapub = hdedx_sin_pub[i]->GetFunction(
"gaus")->GetParameter(2);
1080 sinres[i] = sinsigma;
1081 sinreserr[i] = hdedx_sin[i]->GetFunction(
"gaus")->GetParError(2);
1083 avg_sigma += sinres[i];
1089 avg_sigma = avg_sigma/m_sinbins;
1090 for(
int i = 0; i < m_sinbins; ++i ){
1091 sinres[i] = sinres[i]/avg_sigma;
1092 sinreserr[i] = sinreserr[i]/avg_sigma;
1096 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp",900,900);
1098 std::stringstream psname; psname <<
"plots/sigmavssin_fits.ps[";
1099 ctmp->Print(psname.str().c_str());
1100 psname.str(
""); psname <<
"plots/sigmavssin_fits.ps";
1101 for(
int i = 0 ; i < m_sinbins; ++i ){
1103 hdedx_sin[i]->Draw();
1105 ctmp->Print(psname.str().c_str());
1107 psname.str(
""); psname <<
"plots/sigmavssin_fits.ps]";
1108 ctmp->Print(psname.str().c_str());
1117 TCanvas* sigvssincan =
new TCanvas(
"sigvssincan",
"#sigma vs. sin(#theta)",600,600);
1119 TGraphErrors* gr =
new TGraphErrors(m_sinbins,sins,sinres,sinserr,sinreserr);
1120 gr->SetMarkerStyle(8);
1121 gr->SetMarkerSize(0.3);
1122 gr->SetTitle(
";sin(#theta);#sigma");
1127 TF1* fsigma =
new TF1(
"fsigma",gs,m_lowersin,m_uppersin,6,
"WidgetSigma");
1128 fsigma->SetParameter(0,2);
1129 for(
int i = 1; i < 6; ++i ){
1130 fsigma->SetParameter(i,gpar.
getSinPars(i-1));
1134 int status = gr->Fit(
"fsigma",
"q",
"",m_lowersin,m_uppersin);
1135 for(
int i = 0; i < 10; ++i ){
1136 if( status == 0 )
break;
1137 status = gr->Fit(
"fsigma",
"q",
"",m_lowersin,m_uppersin);
1140 if( status != 0 ) std::cout <<
"WARNING: SIGMA VS SIN FIT FAILED..." << std::endl;
1141 for(
int j = 1; j < 6; ++j ){
1142 gpar.
setSinPars(j-1,fsigma->GetParameter(j));
1145 fsigma->Draw(
"same");
1146 sigvssincan->SaveAs(
"plots/sigmavssin.eps");
1159 TFile* pifile =
new TFile(filenames[0]);
1160 TFile* kfile =
new TFile(filenames[1]);
1161 TTree*
pion = (TTree*)pifile->Get(
"track");
1162 TTree*
kaon = (TTree*)kfile->Get(
"track");
1164 std::cout <<
"HadronCalibration: reading in file " << filenames[0] << std::endl;
1186 pion->SetBranchAddress(
"dedx", &dedxpub);
1187 pion->SetBranchAddress(
"dedxsat", &dedx);
1188 pion->SetBranchAddress(
"pF", &p);
1189 pion->SetBranchAddress(
"costh", &costh);
1190 pion->SetBranchAddress(
"db", &db);
1191 pion->SetBranchAddress(
"dz", &dz);
1192 pion->SetBranchAddress(
"chiPi", &chiPi);
1193 pion->SetBranchAddress(
"eopst", &eop);
1196 pion->SetBranchAddress(
"numGoodHits", &b3nhit);
1197 else if( type == 1 )
1198 pion->SetBranchAddress(
"lNHitsUsed", &b2nhit);
1202 kaon->SetBranchAddress(
"dedx", &dedxpub);
1203 kaon->SetBranchAddress(
"dedxsat", &dedx);
1204 kaon->SetBranchAddress(
"pF", &p);
1205 kaon->SetBranchAddress(
"costh", &costh);
1206 kaon->SetBranchAddress(
"db", &db);
1207 kaon->SetBranchAddress(
"dz", &dz);
1208 kaon->SetBranchAddress(
"chiPi", &chiPi);
1209 kaon->SetBranchAddress(
"eopst", &eop);
1212 kaon->SetBranchAddress(
"numGoodHits", &b3nhit);
1213 else if( type == 1 )
1214 kaon->SetBranchAddress(
"lNHitsUsed", &b2nhit);
1217 const int m_nhitbins = 20;
1218 const double m_uppernhit = 32.5, m_lowernhit = 5.5;
1220 double nhitstep = (m_uppernhit-m_lowernhit)/m_nhitbins;
1226 std::ifstream parfile(
"sat-pars.txt");
1227 if( !parfile.fail() ){
1228 for(
int i = 0; i < 5; ++i ){
1229 parfile >> hadpar[i];
1235 std::cout <<
"WARNING: NO SATUARTION PARAMETERS!!!" << std::endl;
1239 const int nbins = 20;
1240 TFile* outfile =
new TFile(saveas,
"RECREATE");
1242 TH1F* pinumer =
new TH1F(
"pinumer",
"",
nbins,0,2);
1243 TH1F* pidenom =
new TH1F(
"pidenom",
"",
nbins,0,2);
1245 TH2F* pihdedx =
new TH2F(
"pihdedx",
"",100,0,2,100,0,4);
1246 TH2F* pipredpi =
new TH2F(
"pipredpi",
"",100,0,2,100,0,4);
1247 TH2F* pipredk =
new TH2F(
"pipredk",
"",100,0,2,100,0,4);
1249 TH2F* pichivp =
new TH2F(
"pichivp",
"",100,0,2,100,-10,10);
1251 TH1F* knumer =
new TH1F(
"knumer",
"",
nbins,0,2);
1252 TH1F* kdenom =
new TH1F(
"kdenom",
"",
nbins,0,2);
1254 TH2F* khdedx =
new TH2F(
"khdedx",
"",100,0,2,100,0,4);
1255 TH2F* kpredpi =
new TH2F(
"kpredpi",
"",100,0,2,100,0,4);
1256 TH2F* kpredk =
new TH2F(
"kpredk",
"",100,0,2,100,0,4);
1258 TH2F* kchivp =
new TH2F(
"kchivp",
"",100,0,2,100,-10,10);
1265 for(
unsigned int index = 0; index <
pion->GetEntries(); ++index ){
1266 pion->GetEvent(index);
1270 nhit = std::floor(b3nhit);
1271 else if( type == 1 )
1274 if( dedx <= 0 || nhit <= m_lowernhit || nhit >= m_uppernhit )
1277 double dedx_new = dedx;
1278 if( !mcflag ) dedx_new = m_hadsat.
D2I(costh,m_hadsat.
I2D(costh,1.0)*dedx);
1279 double dedx_res = gpar.
sigmaPrediction(dedx,nhit,sqrt(1-costh*costh));
1281 pihdedx->Fill(fabs(p),dedx_new);
1283 double pibg = fabs(p)/Widget::mpion;
1285 double chi_new_pi = (dedx_new-dedx_cur_pi)/dedx_res;
1287 pipredpi->Fill(fabs(p),dedx_cur_pi);
1289 double kbg = fabs(p)/Widget::mkaon;
1291 double chi_new_k = (dedx_new-dedx_cur_k)/dedx_res;
1293 pipredk->Fill(fabs(p),dedx_cur_k);
1295 pichivp->Fill(fabs(p),(chi_new_k*chi_new_k-chi_new_pi*chi_new_pi));
1297 pidenom->Fill(fabs(p));
1298 if( chi_new_k*chi_new_k > chi_new_pi*chi_new_pi ) pinumer->Fill(fabs(p));
1303 for(
unsigned int index = 0; index <
kaon->GetEntries(); ++index ){
1304 kaon->GetEvent(index);
1308 nhit = std::floor(b3nhit);
1309 else if( type == 1 )
1312 if( dedx <= 0 || nhit <= m_lowernhit || nhit >= m_uppernhit )
1314 if( fabs(p) < 0.5 and dedx < 1 )
continue;
1316 double dedx_new = dedx;
1317 if( !mcflag ) dedx_new = m_hadsat.
D2I(costh,m_hadsat.
I2D(costh,1.0)*dedx);
1318 double dedx_res = gpar.
sigmaPrediction(dedx,nhit,sqrt(1-costh*costh));
1320 khdedx->Fill(fabs(p),dedx_new);
1322 double pibg = fabs(p)/Widget::mpion;
1324 double chi_new_pi = (dedx_new-dedx_cur_pi)/dedx_res;
1326 kpredpi->Fill(fabs(p),dedx_cur_pi);
1328 double kbg = fabs(p)/Widget::mkaon;
1330 double chi_new_k = (dedx_new-dedx_cur_k)/dedx_res;
1332 kpredk->Fill(fabs(p),dedx_cur_k);
1334 kchivp->Fill(fabs(p),(chi_new_k*chi_new_k-chi_new_pi*chi_new_pi));
1336 kdenom->Fill(fabs(p));
1337 if( chi_new_k*chi_new_k < chi_new_pi*chi_new_pi ) knumer->Fill(fabs(p));
1340 TEfficiency* piteff =
new TEfficiency(*pinumer,*pidenom);
1341 TEfficiency* kteff =
new TEfficiency(*knumer,*kdenom);
double sin(const BesAngle a)
void fitSigmaVsSin(TString filename, std::string paramfile, int mcFlag, int type)
void plotEfficiency(TString filenames[5], TString saveas, std::string paramfile, int mcFlag, int type)
void plotBGCurve(std::vector< TString > particles, TString filename, std::string paramfile)
void fitBGCurve(std::vector< TString > particles, TString filename, std::string paramfile)
void fitSigmaVsNHit(TString filename, std::string paramfile, int mcFlag, int type)
double I2D(double cosTheta, double I, double alpha, double gamma, double delta, double power, double ratio) const
double D2I(double cosTheta, double D, double alpha, double gamma, double delta, double power, double ratio) const
void setParameters(double par[])
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)