58 gErrorIgnoreLevel = kWarning;
63 if( particle ==
"pion" )
mass = Widget::mpion;
64 else if( particle ==
"kaon" )
mass = Widget::mkaon;
65 else if( particle ==
"proton" )
mass = Widget::mproton;
66 else if( particle ==
"muon" )
mass = Widget::mmuon;
67 else if( particle ==
"electron" )
mass = Widget::melectron;
68 if(
mass == 0.0 ) exit(1);
70 TFile* infile =
new TFile(m_filename);
71 TTree* hadron = (TTree*)infile->Get(
"track");
73 std::cout <<
"HadronPrep: reading in file " << m_filename << std::endl;
74 std::cout <<
"\t beta-gamma range: " << m_lowerbg <<
" to " << m_upperbg << std::endl;
75 std::cout <<
"\t cos(theta) range: " << m_lowercos <<
" to " << m_uppercos << std::endl;
97 hadron->SetBranchAddress(
"dedx", &dedxpub);
98 hadron->SetBranchAddress(
"dedxsat", &dedx);
99 hadron->SetBranchAddress(
"pF", &p);
100 hadron->SetBranchAddress(
"costh", &costh);
101 hadron->SetBranchAddress(
"db", &db);
102 hadron->SetBranchAddress(
"dz", &dz);
103 hadron->SetBranchAddress(
"chiPi", &chiPi);
104 hadron->SetBranchAddress(
"eopst", &eop);
107 hadron->SetBranchAddress(
"numGoodHits", &b3nhit);
108 else if( m_type == 1 )
109 hadron->SetBranchAddress(
"lNHitsUsed", &b2nhit);
112 double bgstep = (m_upperbg-m_lowerbg)/m_bgbins;
113 double cosstep = (m_uppercos-m_lowercos)/m_cosbins;
116 TH1F* hdedx_costh[m_bgbins][m_cosbins];
117 TH1F* hdedx_costh_pub[m_bgbins][m_cosbins];
118 TH1F* hchi_costh[m_bgbins][m_cosbins];
119 TH1F* hchi_costh_pub[m_bgbins][m_cosbins];
122 for(
int i = 0; i < m_bgbins; ++i ){
123 for(
int j = 0; j < m_cosbins; ++j ){
124 char histname[100],histname2[100],histname3[100],histname4[100],histname5[100];
125 sprintf(histname,
"dedx_costh_p_%d_cos_%d",i,j);
126 sprintf(histname2,
"chi_costh_p_%d_cos_%d",i,j);
127 sprintf(histname3,
"chipub_costh_p_%d_cos_%d",i,j);
128 sprintf(histname4,
"dedxpub_costh_p_%d_cos_%d",i,j);
129 sprintf(histname5,
"dedxnew_costh_p_%d_cos_%d",i,j);
132 if( particle ==
"electron" ){
133 hdedx_costh[i][j] =
new TH1F(histname,histname,200,0,2);
134 hchi_costh[i][j] =
new TH1F(histname2,histname2,200,-2,2);
135 hchi_costh_pub[i][j] =
new TH1F(histname3,histname3,200,-5,5);
136 hdedx_costh_pub[i][j] =
new TH1F(histname4,histname4,200,0,2);
138 else if( particle ==
"proton" ){
140 hdedx_costh[i][j] =
new TH1F(histname,histname,200,0,6);
141 hchi_costh[i][j] =
new TH1F(histname2,histname2,200,-30,30);
142 hchi_costh_pub[i][j] =
new TH1F(histname3,histname3,200,0,40);
143 hdedx_costh_pub[i][j] =
new TH1F(histname4,histname4,200,0,6);
146 hdedx_costh[i][j] =
new TH1F(histname,histname,200,0,4);
147 hchi_costh[i][j] =
new TH1F(histname2,histname2,200,-5,5);
148 hchi_costh_pub[i][j] =
new TH1F(histname3,histname3,200,-20,20);
149 hdedx_costh_pub[i][j] =
new TH1F(histname4,histname4,200,0,4);
152 hdedx_costh[i][j] =
new TH1F(histname,histname,200,0,2);
153 hchi_costh[i][j] =
new TH1F(histname2,histname2,200,-5,5);
154 hchi_costh_pub[i][j] =
new TH1F(histname3,histname3,200,-5,5);
155 hdedx_costh_pub[i][j] =
new TH1F(histname4,histname4,200,0,2);
159 hdedx_costh[i][j] =
new TH1F(histname,histname,200,0,4);
160 hchi_costh[i][j] =
new TH1F(histname2,histname2,200,-5,5);
161 hchi_costh_pub[i][j] =
new TH1F(histname3,histname3,200,-5,5);
162 hdedx_costh_pub[i][j] =
new TH1F(histname4,histname4,200,0,4);
165 hdedx_costh[i][j] =
new TH1F(histname,histname,200,0,2);
166 hchi_costh[i][j] =
new TH1F(histname2,histname2,200,-5,5);
167 hchi_costh_pub[i][j] =
new TH1F(histname3,histname3,200,-5,5);
168 hdedx_costh_pub[i][j] =
new TH1F(histname4,histname4,200,0,2);
174 double sumcos[m_bgbins][m_cosbins];
175 double sumsin[m_bgbins][m_cosbins];
176 double sumbg[m_bgbins][m_cosbins];
177 double sumressq[m_bgbins][m_cosbins];
178 int sumsize[m_bgbins][m_cosbins];
179 for(
int i = 0; i < m_bgbins; ++i ){
180 for(
int j = 0; j < m_cosbins; ++j ){
190 double means[m_bgbins][m_cosbins];
191 double errors[m_bgbins][m_cosbins];
192 double widths[m_bgbins][m_cosbins];
193 for(
int i = 0; i < m_bgbins; ++i ){
194 for(
int j = 0; j < m_cosbins; ++j ){
211 for(
unsigned int index = 0; index < hadron->GetEntries(); ++index ){
212 hadron->GetEvent(index);
219 nhit = std::floor(b3nhit);
220 else if( m_type == 1 )
224 if( nhit < 0 || nhit > 100 || dedx <= 0 || costh != costh ||
229 if( particle ==
"pion" && eop > 0.75 )
continue;
232 if( particle ==
"proton" && (dedxpub < 0 || dedxpub > 100 || dedxpub < 0.85/fabs(p)) )
234 if( particle ==
"kaon" && dedxpub < 0.4/fabs(p) )
237 int bgBin = (int)((
bg-m_lowerbg)/(m_upperbg-m_lowerbg) * m_bgbins);
238 int cosBin = (int)((costh-m_lowercos)/(m_uppercos-m_lowercos) * m_cosbins);
240 double dedx_pre = dedx;
241 double dedx_new = dedx_pre;
242 if( !m_mcFlag ) dedx_new = m_hadsat.
D2I(costh,m_hadsat.
I2D(costh,1.0)*dedx);
244 double dedx_res = m_gpar.
sigmaPrediction(dedx_cur,nhit,sqrt(1-costh*costh));
246 std::cout <<
"RESOLUTION IS ZERO!!!" << std::endl;
250 double chi_new = (dedx_new-dedx_cur)/dedx_res;
251 if( particle ==
"electron" ) chi_new = (dedx_new-1)/dedx_res;
252 if( correct ) hdedx_costh[bgBin][cosBin]->Fill(dedx_new);
253 else hdedx_costh[bgBin][cosBin]->Fill(dedx_pre);
255 if( correct ) hchi_costh[bgBin][cosBin]->Fill(chi_new);
256 else hchi_costh[bgBin][cosBin]->Fill(chiPi);
258 hdedx_costh_pub[bgBin][cosBin]->Fill(dedxpub);
259 hchi_costh_pub[bgBin][cosBin]->Fill(chiPi);
263 sumcos[bgBin][cosBin] += costh;
264 sumsin[bgBin][cosBin] += sqrt(1-costh*costh);
265 sumbg[bgBin][cosBin] +=
bg;
266 sumressq[bgBin][cosBin] += pow(dedx_res,2);
267 sumsize[bgBin][cosBin] += 1;
278 TTree* satTree =
new TTree(particle,
"dE/dx means and errors");
287 double satdedxres_avg;
296 double satchipubwidth;
299 satTree->Branch(
"bg",&satbg,
"bg/D");
300 satTree->Branch(
"costh",&satcosth,
"costh/D");
301 satTree->Branch(
"dedx",&satdedx,
"dedx/D");
302 satTree->Branch(
"error",&saterror,
"error/D");
303 satTree->Branch(
"bg_avg",&satbg_avg,
"bg_avg/D");
304 satTree->Branch(
"costh_avg",&satcosth_avg,
"costh_avg/D");
305 satTree->Branch(
"sinth_avg",&satsinth_avg,
"sinth_avg/D");
306 satTree->Branch(
"dedxres_avg",&satdedxres_avg,
"dedxres_avg/D");
307 satTree->Branch(
"dedx_pub",&satpubdedx,
"dedx_pub/D");
308 satTree->Branch(
"dedxerr_pub",&satpuberror,
"dedxerr_pub/D");
309 satTree->Branch(
"chi",&satchi,
"chi/D");
310 satTree->Branch(
"chi_pub",&satchipub,
"chi_pub/D");
311 satTree->Branch(
"sigma",&satchiwidth,
"sigma/D");
312 satTree->Branch(
"sigma_pub",&satchipubwidth,
"sigma_pub/D");
313 satTree->Branch(
"ratio",&ratio,
"ratio/D");
316 int fs1=0, fs2=0, fs3=0, fs4=0;
317 double dedxmax = 1.0, dedxmin = 1.0;
318 for(
int i = 0; i < m_bgbins; ++i ){
319 for(
int j = 0; j < m_cosbins; ++j ){
321 std::cout <<
"\t\t" <<
"i= " << i <<
" j= " << j << std::endl;
323 satbg = m_lowerbg+0.5*bgstep+i*bgstep;
324 satcosth = m_lowercos+0.5*cosstep+j*cosstep;
326 satbg_avg = sumbg[i][j]/sumsize[i][j];
327 satcosth_avg = sumcos[i][j]/sumsize[i][j];
328 satsinth_avg = sumsin[i][j]/sumsize[i][j];
329 satdedxres_avg = sumressq[i][j]/sumsize[i][j];
333 fs = hdedx_costh[i][j]->Fit(
"gaus",
"ql");
334 double mean = hdedx_costh[i][j]->GetFunction(
"gaus")->GetParameter(1);
335 double width = hdedx_costh[i][j]->GetFunction(
"gaus")->GetParameter(2);
337 fs = hdedx_costh[i][j]->Fit(
"gaus",
"l",
"",mean-2.5*width,mean+2.5*width);
339 std::cout <<
"\t\t" <<
"MEAN FIT STATUS " <<
fs << std::endl;
343 satdedx = hdedx_costh[i][j]->GetFunction(
"gaus")->GetParameter(1);
344 saterror = hdedx_costh[i][j]->GetFunction(
"gaus")->GetParError(1);
345 means[i][j] = satdedx;
346 errors[i][j] = saterror;
347 widths[i][j] = hdedx_costh[i][j]->GetFunction(
"gaus")->GetParameter(2);
349 if( satdedx > dedxmax ) dedxmax = satdedx;
350 if( satdedx < dedxmin ) dedxmin = satdedx;
353 fs = hdedx_costh_pub[i][j]->Fit(
"gaus",
"ql");
354 mean = hdedx_costh_pub[i][j]->GetFunction(
"gaus")->GetParameter(1);
355 width = hdedx_costh_pub[i][j]->GetFunction(
"gaus")->GetParameter(2);
357 fs = hdedx_costh_pub[i][j]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
359 std::cout <<
"\t\t" <<
"MEAN PUB FIT STATUS " <<
fs << std::endl;
363 satpubdedx = hdedx_costh_pub[i][j]->GetFunction(
"gaus")->GetParameter(1);
364 satpuberror = hdedx_costh_pub[i][j]->GetFunction(
"gaus")->GetParError(1);
365 satpubwidth = hdedx_costh_pub[i][j]->GetFunction(
"gaus")->GetParameter(2);
369 fs = hchi_costh[i][j]->Fit(
"gaus",
"ql");
370 mean = hchi_costh[i][j]->GetFunction(
"gaus")->GetParameter(1);
371 width = hchi_costh[i][j]->GetFunction(
"gaus")->GetParameter(2);
372 fs = hchi_costh[i][j]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
378 satchi = hchi_costh[i][j]->GetFunction(
"gaus")->GetParameter(1);
379 satchierr = hchi_costh[i][j]->GetFunction(
"gaus")->GetParError(1);
380 satchiwidth = hchi_costh[i][j]->GetFunction(
"gaus")->GetParameter(2);
407 if( fs1+fs2+fs3+fs4 != 0 ) std::cout <<
"FIT RESULTS: " << particle << std::endl;
408 if( fs1 != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT FAILS " << fs1 << std::endl;
409 if( fs2 != 0 ) std::cout <<
"\t\t" <<
"MEAN PUB FIT FAILS " << fs2 << std::endl;
410 if( fs3 != 0 ) std::cout <<
"\t\t" <<
"CHI FIT FAILS " << fs3 << std::endl;
411 if( fs4 != 0 ) std::cout <<
"\t\t" <<
"CHI PUB FIT FAILS " << fs4 << std::endl;
413 std::string corname(
"uncorrected");
414 if( correct ==
true ) corname =
"corrected";
417 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp",900,900);
419 std::stringstream psname; psname <<
"plots/dedx_" << particle <<
"_" << corname <<
".ps[";
420 ctmp->Print(psname.str().c_str());
421 psname.str(
""); psname <<
"plots/dedx_" << particle <<
"_" << corname <<
".ps";
422 for(
int i = 0 ; i < m_bgbins; ++i ){
423 for(
int j = 0; j < m_cosbins; ++j ){
425 hdedx_costh[i][j]->Draw();
427 ctmp->Print(psname.str().c_str());
430 psname.str(
""); psname <<
"plots/dedx_" << particle <<
"_" << corname <<
".ps]";
431 ctmp->Print(psname.str().c_str());
436 TCanvas* ctmp2 =
new TCanvas(
"tmp2",
"tmp2",900,900);
438 psname.str(
""); psname <<
"plots/dedx_" << particle <<
"_pub_" << corname <<
".ps[";
439 ctmp2->Print(psname.str().c_str());
440 psname.str(
""); psname <<
"plots/dedx_" << particle <<
"_pub_" << corname <<
".ps";
441 for(
int i = 0 ; i < m_bgbins; ++i ){
442 for(
int j = 0; j < m_cosbins; ++j ){
444 hdedx_costh_pub[i][j]->Draw();
446 ctmp2->Print(psname.str().c_str());
449 psname.str(
""); psname <<
"plots/dedx_" << particle <<
"_pub_" << corname <<
".ps]";
450 ctmp2->Print(psname.str().c_str());
455 TCanvas* ctmp3 =
new TCanvas(
"tmp3",
"tmp3",900,900);
457 psname.str(
""); psname <<
"plots/chi_" << particle <<
"_" << corname <<
".ps[";
458 ctmp3->Print(psname.str().c_str());
459 psname.str(
""); psname <<
"plots/chi_" << particle <<
"_" << corname <<
".ps";
460 for(
int i = 0 ; i < m_bgbins; ++i ){
461 for(
int j = 0; j < m_cosbins; ++j ){
463 hchi_costh[i][j]->Draw();
465 ctmp3->Print(psname.str().c_str());
468 psname.str(
""); psname <<
"plots/chi_" << particle <<
"_" << corname <<
".ps]";
469 ctmp3->Print(psname.str().c_str());
474 TCanvas* ctmp4 =
new TCanvas(
"tmp4",
"tmp4",900,900);
476 psname.str(
""); psname <<
"plots/chi_" << particle <<
"_pub_" << corname <<
".ps[";
477 ctmp4->Print(psname.str().c_str());
478 psname.str(
""); psname <<
"plots/chi_" << particle <<
"_pub_" << corname <<
".ps";
479 for(
int i = 0 ; i < m_bgbins; ++i ){
480 for(
int j = 0; j < m_cosbins; ++j ){
482 hchi_costh_pub[i][j]->Draw();
484 ctmp4->Print(psname.str().c_str());
487 psname.str(
""); psname <<
"plots/chi_" << particle <<
"_pub_" << corname <<
".ps]";
488 ctmp4->Print(psname.str().c_str());
491 double cbcenters[m_cosbins], cberrors[m_cosbins];
492 for(
int j = 0; j < m_cosbins; ++j ){
493 cbcenters[j] = m_lowercos+0.5*cosstep+j*cosstep;
498 TGraphErrors gdedx_costh[m_bgbins];
499 for(
int i = 0; i < m_bgbins; ++i ){
501 satbg = m_lowerbg+0.5*bgstep+i*bgstep;
502 sprintf(graphname,
"dedx_costh_p_%d",i);
503 gdedx_costh[i] = TGraphErrors(m_cosbins,cbcenters,means[i],cberrors,errors[i]);
505 TH1F* base =
new TH1F(
"base",
"dE/dx vs. cos(#theta);cos(#theta);dE/dx",100,0,1.0);
506 base->GetXaxis()->SetTitleOffset(1.5);
507 base->SetMaximum(dedxmax*1.1);
508 base->SetMinimum(dedxmin*0.9);
512 TCanvas* ctmp6 =
new TCanvas(
"tmp6",
"tmp6",900,900);
514 for(
int i = 0 ; i < m_bgbins; ++i ){
515 gdedx_costh[i].SetMarkerSize(0.8);
516 gdedx_costh[i].SetMarkerColor(50+i);
517 gdedx_costh[i].SetLineColor(50+i);
518 gdedx_costh[i].DrawClone(
"same");
520 psname.str(
""); psname <<
"plots/costh_" << particle <<
"_" << corname <<
".eps";
521 ctmp6->SaveAs(psname.str().c_str());
524 std::cout <<
"HadronPrep: saving output to " << outfile->GetName() << std::endl;
531 for(
int i = 0; i < m_bgbins; ++i ){
532 for(
int j = 0; j < m_cosbins; ++j ){
533 delete hdedx_costh[i][j];
534 delete hdedx_costh_pub[i][j];
535 delete hchi_costh[i][j];
536 delete hchi_costh_pub[i][j];
547 gErrorIgnoreLevel = kWarning;
552 if( particle ==
"pion" )
mass = Widget::mpion;
553 else if( particle ==
"kaon" )
mass = Widget::mkaon;
554 else if( particle ==
"proton" )
mass = Widget::mproton;
555 else if( particle ==
"muon" )
mass = Widget::mmuon;
556 else if( particle ==
"electron" )
mass = Widget::melectron;
557 if(
mass == 0.0 ) exit(1);
559 TFile* infile =
new TFile(m_filename);
560 TTree* hadron = (TTree*)infile->Get(
"track");
562 std::cout <<
"HadronPrep: reading in file " << m_filename << std::endl;
563 std::cout <<
"\t beta-gamma range: " << m_lowerbg <<
" to " << m_upperbg << std::endl;
585 hadron->SetBranchAddress(
"dedx", &dedxpub);
586 hadron->SetBranchAddress(
"dedxsat", &dedx);
587 hadron->SetBranchAddress(
"pF", &p);
588 hadron->SetBranchAddress(
"costh", &costh);
589 hadron->SetBranchAddress(
"db", &db);
590 hadron->SetBranchAddress(
"dz", &dz);
591 hadron->SetBranchAddress(
"chiPi", &chiPi);
592 hadron->SetBranchAddress(
"eopst", &eop);
595 hadron->SetBranchAddress(
"numGoodHits", &b3nhit);
596 else if( m_type == 1 )
597 hadron->SetBranchAddress(
"lNHitsUsed", &b2nhit);
600 double bgstep = (m_upperbg-m_lowerbg)/m_bgbins;
603 TH1F* hdedx_bg[m_bgbins];
604 TH1F* hdedx_bg_pub[m_bgbins];
605 TH1F* hchi_bg[m_bgbins];
606 TH1F* hchi_bg_pub[m_bgbins];
607 TH1F* hsigma_bg[m_bgbins];
610 for(
int i = 0; i < m_bgbins; ++i ){
611 char histname[100], histname2[100], histname3[100];
612 char histname4[100], histname5[100], histname6[100];
613 sprintf(histname,
"dedx_bg_%d",i);
614 sprintf(histname2,
"chi_bg_%d",i);
615 sprintf(histname3,
"chipub_bg_%d",i);
616 sprintf(histname4,
"dedxpub_bg_%d",i);
617 sprintf(histname5,
"dedxnew_bg_%d",i);
618 sprintf(histname6,
"sigma_bg_%d",i);
620 if( particle ==
"electron" ){
621 hdedx_bg[i] =
new TH1F(histname,histname,200,0,2);
622 hchi_bg[i] =
new TH1F(histname2,histname2,200,-2,2);
623 hchi_bg_pub[i] =
new TH1F(histname3,histname3,200,-5,5);
624 hdedx_bg_pub[i] =
new TH1F(histname4,histname4,200,0,2);
626 else if( particle ==
"proton" ){
628 hdedx_bg[i] =
new TH1F(histname,histname,200,0,6);
629 hchi_bg[i] =
new TH1F(histname2,histname2,200,-30,30);
630 hchi_bg_pub[i] =
new TH1F(histname3,histname3,200,0,40);
631 hdedx_bg_pub[i] =
new TH1F(histname4,histname4,200,0,6);
634 hdedx_bg[i] =
new TH1F(histname,histname,200,0,4);
635 hchi_bg[i] =
new TH1F(histname2,histname2,200,-5,5);
636 hchi_bg_pub[i] =
new TH1F(histname3,histname3,200,-20,20);
637 hdedx_bg_pub[i] =
new TH1F(histname4,histname4,200,0,4);
640 hdedx_bg[i] =
new TH1F(histname,histname,200,0,2);
641 hchi_bg[i] =
new TH1F(histname2,histname2,200,-5,5);
642 hchi_bg_pub[i] =
new TH1F(histname3,histname3,200,-5,5);
643 hdedx_bg_pub[i] =
new TH1F(histname4,histname4,200,0,2);
647 hdedx_bg[i] =
new TH1F(histname,histname,200,0,4);
648 hchi_bg[i] =
new TH1F(histname2,histname2,200,-5,5);
649 hchi_bg_pub[i] =
new TH1F(histname3,histname3,200,-20,20);
650 hdedx_bg_pub[i] =
new TH1F(histname4,histname4,200,0,4);
653 hdedx_bg[i] =
new TH1F(histname,histname,200,0,2);
654 hchi_bg[i] =
new TH1F(histname2,histname2,200,-5,5);
655 hchi_bg_pub[i] =
new TH1F(histname3,histname3,100,-5,5);
656 hdedx_bg_pub[i] =
new TH1F(histname4,histname4,200,0,2);
658 hsigma_bg[i] =
new TH1F(histname6,histname6,100,-3,3);
662 double sumcos[m_bgbins];
663 double sumsin[m_bgbins];
664 double sumbg[m_bgbins];
665 double sumressq[m_bgbins];
666 int sumsize[m_bgbins];
667 for(
int i = 0; i < m_bgbins; ++i ){
676 double means[m_bgbins];
677 double errors[m_bgbins];
678 double widths[m_bgbins];
679 for(
int i = 0; i < m_bgbins; ++i ){
686 const int cosbins = 20;
687 const double cosstep = 2.0 / cosbins;
688 double cosArray[cosbins], cosArrayErr[cosbins];
689 for(
int i = 0; i < cosbins; ++i ){
690 cosArray[i] = -1 + (i*cosstep + cosstep/2.0);
691 cosArrayErr[i] = 0.0;
694 TH1F* hchi_costh_all[2][cosbins];
695 TH1F* hchi_costh_0[2][cosbins];
696 TH1F* hchi_costh_1[2][cosbins];
697 TH1F* hchi_costh_2[2][cosbins];
699 for(
int i = 0; i < cosbins; ++i ){
700 char histname[100], histname0[100], histname1[100], histname2[100];
701 sprintf(histname,
"chi_costh_pos_%d",i);
702 sprintf(histname0,
"chi_costh0_pos_%d",i);
703 sprintf(histname1,
"chi_costh1_pos_%d",i);
704 sprintf(histname2,
"chi_costh2_pos_%d",i);
706 hchi_costh_all[0][i] =
new TH1F(histname,histname,100,-5,5);
707 hchi_costh_0[0][i] =
new TH1F(histname0,histname0,100,-5,5);
708 hchi_costh_1[0][i] =
new TH1F(histname1,histname1,100,-5,5);
709 hchi_costh_2[0][i] =
new TH1F(histname2,histname2,100,-5,5);
711 sprintf(histname,
"chi_costh_neg_%d",i);
712 sprintf(histname0,
"chi_costh0_neg_%d",i);
713 sprintf(histname1,
"chi_costh1_neg_%d",i);
714 sprintf(histname2,
"chi_costh2_neg_%d",i);
716 hchi_costh_all[1][i] =
new TH1F(histname,histname,100,-5,5);
717 hchi_costh_0[1][i] =
new TH1F(histname0,histname0,100,-5,5);
718 hchi_costh_1[1][i] =
new TH1F(histname1,histname1,100,-5,5);
719 hchi_costh_2[1][i] =
new TH1F(histname2,histname2,100,-5,5);
731 for(
unsigned int index = 0; index < hadron->GetEntries(); ++index ){
732 hadron->GetEvent(index);
734 int charge = (p < 0)? 1 : 0;
739 nhit = std::floor(b3nhit);
740 else if( m_type == 1 )
744 if( nhit < 0 || nhit > 100 || dedx <= 0 || costh != costh ||
749 if( particle ==
"pion" && eop > 0.75 )
continue;
752 if( particle ==
"proton" && (dedxpub < 0 || dedxpub > 100 || dedxpub < 0.85/fabs(p)) )
754 if( particle ==
"kaon" && dedxpub < 0.4/fabs(p) )
757 int bgBin = (int)((
bg-m_lowerbg)/(m_upperbg-m_lowerbg) * m_bgbins);
759 double dedx_pre = dedx;
760 double dedx_new = dedx_pre;
761 if( !m_mcFlag ) dedx_new = m_hadsat.
D2I(costh,m_hadsat.
I2D(costh,1.0)*dedx);
763 double dedx_res = m_gpar.
sigmaPrediction(dedx_cur,nhit,sqrt(1-costh*costh));
765 double chi_new = (dedx_new-dedx_cur)/dedx_res;
766 if( particle ==
"electron" ) chi_new = (dedx_new-1)/dedx_res;
767 double res_cor = m_gpar.
resPrediction(nhit,sqrt(1-costh*costh));
768 int i = (int) ( (fabs(
bg)-m_lowerbg)/bgstep );
769 hsigma_bg[i]->Fill((dedx_new-dedx_cur)/res_cor);
771 if( correct ) hdedx_bg[bgBin]->Fill(dedx_new);
772 else hdedx_bg[bgBin]->Fill(dedx_pre);
773 hdedx_bg_pub[bgBin]->Fill(dedxpub);
774 if( correct ) hchi_bg[bgBin]->Fill(chi_new);
775 hchi_bg_pub[bgBin]->Fill(chiPi);
777 sumcos[bgBin] += costh;
778 sumsin[bgBin] += sqrt(1-costh*costh);
780 sumressq[bgBin] += pow(dedx_res,2);
784 int icos = (int)((costh+1)/cosstep);
785 hchi_costh_all[
charge][icos]->Fill(chi_new);
786 if( bgBin <
int(m_bgbins/3) )
787 hchi_costh_0[
charge][icos]->Fill(chi_new);
788 else if( bgBin < 2*
int(m_bgbins/3) )
789 hchi_costh_1[
charge][icos]->Fill(chi_new);
791 hchi_costh_2[
charge][icos]->Fill(chi_new);
801 TTree* satTree =
new TTree(particle,
"dE/dx means and errors");
810 double satdedxres_avg;
819 double satchipubwidth;
822 satTree->Branch(
"bg",&satbg,
"bg/D");
823 satTree->Branch(
"costh",&satcosth,
"costh/D");
824 satTree->Branch(
"dedx",&satdedx,
"dedx/D");
825 satTree->Branch(
"error",&saterror,
"error/D");
826 satTree->Branch(
"bg_avg",&satbg_avg,
"bg_avg/D");
827 satTree->Branch(
"costh_avg",&satcosth_avg,
"costh_avg/D");
828 satTree->Branch(
"sinth_avg",&satsinth_avg,
"sinth_avg/D");
829 satTree->Branch(
"dedxres_avg",&satdedxres_avg,
"dedxres_avg/D");
830 satTree->Branch(
"dedx_pub",&satpubdedx,
"dedx_pub/D");
831 satTree->Branch(
"dedxerr_pub",&satpuberror,
"dedxerr_pub/D");
832 satTree->Branch(
"chi",&satchi,
"chi/D");
833 satTree->Branch(
"chi_pub",&satchipub,
"chi_pub/D");
834 satTree->Branch(
"sigma",&satchiwidth,
"sigma/D");
835 satTree->Branch(
"sigma_pub",&satchipubwidth,
"sigma_pub/D");
836 satTree->Branch(
"ratio",&ratio,
"ratio/D");
839 for(
int i = 0; i < m_bgbins; ++i ){
842 satbg = m_lowerbg+0.5*bgstep+i*bgstep;
844 satbg_avg = sumbg[i]/sumsize[i];
845 satcosth_avg = sumcos[i]/sumsize[i];
846 satsinth_avg = sumsin[i]/sumsize[i];
849 hsigma_bg[i]->Fit(
"gaus",
"ql");
850 satdedxres_avg = hsigma_bg[i]->GetFunction(
"gaus")->GetParameter(2);
855 fs = hdedx_bg[i]->Fit(
"gaus",
"ql");
856 if(
fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " <<
fs << std::endl;
857 double mean = hdedx_bg[i]->GetFunction(
"gaus")->GetParameter(1);
858 double width = hdedx_bg[i]->GetFunction(
"gaus")->GetParameter(2);
859 fs = hdedx_bg[i]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
860 if(
fs != 0 ) std::cout <<
"\t\t" <<
"MEAN FIT STATUS " <<
fs << std::endl;
862 satdedx = hdedx_bg[i]->GetFunction(
"gaus")->GetParameter(1);
863 saterror = hdedx_bg[i]->GetFunction(
"gaus")->GetParError(1);
865 errors[i] = saterror;
866 widths[i] = hdedx_bg[i]->GetFunction(
"gaus")->GetParameter(2);
870 fs = hdedx_bg_pub[i]->Fit(
"gaus",
"ql");
871 if(
fs != 0 ) std::cout <<
"\t\t" <<
"MEAN PUB FIT STATUS " <<
fs << std::endl;
872 mean = hdedx_bg_pub[i]->GetFunction(
"gaus")->GetParameter(1);
873 width = hdedx_bg_pub[i]->GetFunction(
"gaus")->GetParameter(2);
874 fs = hdedx_bg_pub[i]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
875 if(
fs != 0 ) std::cout <<
"\t\t" <<
"MEAN PUB FIT STATUS " <<
fs << std::endl;
877 satpubdedx = hdedx_bg_pub[i]->GetFunction(
"gaus")->GetParameter(1);
878 satpuberror = hdedx_bg_pub[i]->GetFunction(
"gaus")->GetParError(1);
879 satpubwidth = hdedx_bg_pub[i]->GetFunction(
"gaus")->GetParameter(2);
883 fs = hchi_bg[i]->Fit(
"gaus",
"ql");
884 if(
fs != 0 ) std::cout <<
"\t\t" <<
"CHI FIT STATUS " <<
fs << std::endl;
885 mean = hchi_bg[i]->GetFunction(
"gaus")->GetParameter(1);
886 width = hchi_bg[i]->GetFunction(
"gaus")->GetParameter(2);
887 fs = hchi_bg[i]->Fit(
"gaus",
"ql",
"",mean-2.5*width,mean+2.5*width);
888 if(
fs != 0 ) std::cout <<
"\t\t" <<
"CHI FIT STATUS " <<
fs << std::endl;
890 satchi = hchi_bg[i]->GetFunction(
"gaus")->GetParameter(1);
891 satchierr = hchi_bg[i]->GetFunction(
"gaus")->GetParError(1);
892 satchiwidth = hchi_bg[i]->GetFunction(
"gaus")->GetParameter(2);
916 std::string corname(
"uncorrected");
917 if( correct ==
true ) corname =
"corrected";
920 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp",900,900);
922 std::stringstream psname; psname <<
"plots/dedx_" << particle <<
"_" << corname <<
".ps[";
923 ctmp->Print(psname.str().c_str());
924 psname.str(
""); psname <<
"plots/dedx_" << particle <<
"_" << corname <<
".ps";
925 for(
int i = 0 ; i < m_bgbins; ++i ){
929 ctmp->Print(psname.str().c_str());
931 psname.str(
""); psname <<
"plots/dedx_" << particle <<
"_" << corname <<
".ps]";
932 ctmp->Print(psname.str().c_str());
935 std::cout <<
"HadronPrep: saving output to " << outfile->GetName() << std::endl;
941 std::cout <<
"making validation plots..." << std::endl;
947 double chicos[2][cosbins], sigmacos[2][cosbins];
948 double chicoserr[2][cosbins], sigmacoserr[2][cosbins];
950 double chicos0[2][cosbins], sigmacos0[2][cosbins];
951 double chicos0err[2][cosbins], sigmacos0err[2][cosbins];
953 double chicos1[2][cosbins], sigmacos1[2][cosbins];
954 double chicos1err[2][cosbins], sigmacos1err[2][cosbins];
956 double chicos2[2][cosbins], sigmacos2[2][cosbins];
957 double chicos2err[2][cosbins], sigmacos2err[2][cosbins];
959 for(
int c = 0; c < 2; ++c ){
960 for(
int i = 0; i < cosbins; ++i ){
961 if( hchi_costh_all[c][i]->Integral(1,100) == 0 )
continue;
962 hchi_costh_all[c][i]->Fit(
"gaus",
"ql");
963 chicos[c][i] = hchi_costh_all[c][i]->GetFunction(
"gaus")->GetParameter(1);
964 chicoserr[c][i] = hchi_costh_all[c][i]->GetFunction(
"gaus")->GetParError(1);
965 sigmacos[c][i] = hchi_costh_all[c][i]->GetFunction(
"gaus")->GetParameter(2);
966 sigmacoserr[c][i] = hchi_costh_all[c][i]->GetFunction(
"gaus")->GetParError(2);
968 for(
int i = 0; i < cosbins; ++i ){
969 if( hchi_costh_0[c][i]->Integral(1,100) == 0 )
continue;
970 hchi_costh_0[c][i]->Fit(
"gaus",
"ql");
971 chicos0[c][i] = hchi_costh_0[c][i]->GetFunction(
"gaus")->GetParameter(1);
972 chicos0err[c][i] = hchi_costh_0[c][i]->GetFunction(
"gaus")->GetParError(1);
973 sigmacos0[c][i] = hchi_costh_0[c][i]->GetFunction(
"gaus")->GetParameter(2);
974 sigmacos0err[c][i] = hchi_costh_0[c][i]->GetFunction(
"gaus")->GetParError(2);
976 for(
int i = 0; i < cosbins; ++i ){
977 if( hchi_costh_1[c][i]->Integral(1,100) == 0 )
continue;
978 hchi_costh_1[c][i]->Fit(
"gaus",
"ql");
979 chicos1[c][i] = hchi_costh_1[c][i]->GetFunction(
"gaus")->GetParameter(1);
980 chicos1err[c][i] = hchi_costh_1[c][i]->GetFunction(
"gaus")->GetParError(1);
981 sigmacos1[c][i] = hchi_costh_1[c][i]->GetFunction(
"gaus")->GetParameter(2);
982 sigmacos1err[c][i] = hchi_costh_1[c][i]->GetFunction(
"gaus")->GetParError(2);
984 for(
int i = 0; i < cosbins; ++i ){
985 if( hchi_costh_2[c][i]->Integral(1,100) == 0 )
continue;
986 hchi_costh_2[c][i]->Fit(
"gaus",
"ql");
987 chicos2[c][i] = hchi_costh_2[c][i]->GetFunction(
"gaus")->GetParameter(1);
988 chicos2err[c][i] = hchi_costh_2[c][i]->GetFunction(
"gaus")->GetParError(1);
989 sigmacos2[c][i] = hchi_costh_2[c][i]->GetFunction(
"gaus")->GetParameter(2);
990 sigmacos2err[c][i] = hchi_costh_2[c][i]->GetFunction(
"gaus")->GetParError(2);
995 TCanvas* ctmp2 =
new TCanvas(
"tmp2",
"tmp2",900,900);
997 psname.str(
""); psname <<
"plots/chivscos_fits_" << particle <<
".ps[";
998 ctmp2->Print(psname.str().c_str());
999 psname.str(
""); psname <<
"plots/chivscos_fits_" << particle <<
".ps";
1000 for(
int i = 0 ; i < cosbins; ++i ){
1002 hchi_costh_all[0][i]->Draw();
1003 hchi_costh_all[1][i]->SetMarkerColor(kRed);
1004 hchi_costh_all[1][i]->Draw(
"same");
1006 ctmp2->Print(psname.str().c_str());
1008 psname.str(
""); psname <<
"plots/chivscos_fits_" << particle <<
".ps]";
1009 ctmp2->Print(psname.str().c_str());
1012 TGraphErrors* grchicos =
new TGraphErrors(cosbins,cosArray,chicos[0],cosArrayErr,chicoserr[0]);
1013 TGraphErrors* grchicos0 =
new TGraphErrors(cosbins,cosArray,chicos0[0],cosArrayErr,chicos0err[0]);
1014 TGraphErrors* grchicos1 =
new TGraphErrors(cosbins,cosArray,chicos1[0],cosArrayErr,chicos1err[0]);
1015 TGraphErrors* grchicos2 =
new TGraphErrors(cosbins,cosArray,chicos2[0],cosArrayErr,chicos2err[0]);
1017 TGraphErrors* grchicosn =
new TGraphErrors(cosbins,cosArray,chicos[1],cosArrayErr,chicoserr[1]);
1018 TGraphErrors* grchicos0n =
new TGraphErrors(cosbins,cosArray,chicos0[1],cosArrayErr,chicos0err[1]);
1019 TGraphErrors* grchicos1n =
new TGraphErrors(cosbins,cosArray,chicos1[1],cosArrayErr,chicos1err[1]);
1020 TGraphErrors* grchicos2n =
new TGraphErrors(cosbins,cosArray,chicos2[1],cosArrayErr,chicos2err[1]);
1022 TGraphErrors* grsigmacos =
new TGraphErrors(cosbins,cosArray,sigmacos[0],cosArrayErr,sigmacoserr[0]);
1023 TGraphErrors* grsigmacos0 =
new TGraphErrors(cosbins,cosArray,sigmacos0[0],cosArrayErr,sigmacos0err[0]);
1024 TGraphErrors* grsigmacos1 =
new TGraphErrors(cosbins,cosArray,sigmacos1[0],cosArrayErr,sigmacos1err[0]);
1025 TGraphErrors* grsigmacos2 =
new TGraphErrors(cosbins,cosArray,sigmacos2[0],cosArrayErr,sigmacos2err[0]);
1027 TGraphErrors* grsigmacosn =
new TGraphErrors(cosbins,cosArray,sigmacos[1],cosArrayErr,sigmacoserr[1]);
1028 TGraphErrors* grsigmacos0n =
new TGraphErrors(cosbins,cosArray,sigmacos0[1],cosArrayErr,sigmacos0err[1]);
1029 TGraphErrors* grsigmacos1n =
new TGraphErrors(cosbins,cosArray,sigmacos1[1],cosArrayErr,sigmacos1err[1]);
1030 TGraphErrors* grsigmacos2n =
new TGraphErrors(cosbins,cosArray,sigmacos2[1],cosArrayErr,sigmacos2err[1]);
1032 TLine* line0 =
new TLine(-1,0,1,0);
1033 line0->SetLineStyle(kDashed);
1034 line0->SetLineColor(kRed);
1035 TLine* line1 =
new TLine(-1,1,1,1);
1036 line1->SetLineStyle(kDashed);
1037 line1->SetLineColor(kRed);
1040 if( particle ==
"pion" )
ptype +=
"#pi";
1041 else if( particle ==
"kaon" )
ptype +=
"K";
1042 else if( particle ==
"proton" )
ptype +=
"p";
1043 else if( particle ==
"muon" )
ptype +=
"#mu";
1044 else if( particle ==
"electron" )
ptype +=
"e";
1046 TLegend* lchi =
new TLegend(0.6,0.75,0.8,0.85);
1047 lchi->SetBorderSize(0);
1048 lchi->SetFillColor(0);
1049 lchi->AddEntry(grchicos,
ptype+
"^{+}",
"p");
1050 lchi->AddEntry(grchicosn,
ptype+
"^{-}",
"p");
1051 TCanvas* cchi =
new TCanvas(
"cchi",
"cchi",700,600);
1055 grchicos->Draw(
"AP");
1056 grchicosn->Draw(
"P,same");
1057 line0->Draw(
"same");
1059 cchi->SaveAs(
"plots/chiall"+particle+
".eps");
1063 grchicos0->Draw(
"AP");
1064 grchicos0n->Draw(
"P,same");
1065 line0->Draw(
"same");
1067 cchi->SaveAs(
"plots/chi0"+particle+
".eps");
1071 grchicos1->Draw(
"AP");
1072 grchicos1n->Draw(
"P,same");
1073 line0->Draw(
"same");
1075 cchi->SaveAs(
"plots/chi1"+particle+
".eps");
1079 grchicos2->Draw(
"AP");
1080 grchicos2n->Draw(
"P,same");
1081 line0->Draw(
"same");
1083 cchi->SaveAs(
"plots/chi2"+particle+
".eps");
1087 grsigmacos->Draw(
"AP");
1088 grsigmacosn->Draw(
"P,same");
1089 line1->Draw(
"same");
1091 cchi->SaveAs(
"plots/sigmaall"+particle+
".eps");
1095 grsigmacos0->Draw(
"AP");
1096 grsigmacos0n->Draw(
"P,same");
1097 line1->Draw(
"same");
1099 cchi->SaveAs(
"plots/sigma0"+particle+
".eps");
1103 grsigmacos1->Draw(
"AP");
1104 grsigmacos1n->Draw(
"P,same");
1105 line1->Draw(
"same");
1107 cchi->SaveAs(
"plots/sigma1"+particle+
".eps");
1111 grsigmacos2->Draw(
"AP");
1112 grsigmacos2n->Draw(
"P,same");
1113 line1->Draw(
"same");
1115 cchi->SaveAs(
"plots/sigma2"+particle+
".eps");
1117 for(
int i = 0; i < 2; ++i ){
1118 for(
int j = 0; j < cosbins; ++j ){
1119 delete hchi_costh_all[i][j];
1120 delete hchi_costh_0[i][j];
1121 delete hchi_costh_1[i][j];
1122 delete hchi_costh_2[i][j];
1142 delete grsigmacos0n;
1143 delete grsigmacos1n;
1144 delete grsigmacos2n;