11 #include <tracking/modules/trackingPerformanceEvaluation/PerformanceEvaluationBaseClass.h>
13 #include <framework/logging/Logger.h>
15 #include <root/TAxis.h>
19 PerformanceEvaluationBaseClass:: PerformanceEvaluationBaseClass()
23 PerformanceEvaluationBaseClass::~ PerformanceEvaluationBaseClass()
29 Int_t nbins, Double_t min, Double_t max,
30 const char* xtitle, TList* histoList)
33 TH1F* h =
new TH1F(name, title, nbins, min, max);
35 h->GetXaxis()->SetTitle(xtitle);
44 Int_t nbins, Double_t* bins,
45 const char* xtitle, TList* histoList)
48 TH1F* h =
new TH1F(name, title, nbins, bins);
50 h->GetXaxis()->SetTitle(xtitle);
59 Int_t nbinsX, Double_t minX, Double_t maxX,
61 Int_t nbinsY, Double_t minY, Double_t maxY,
62 const char* titleY, TList* histoList)
65 TH2F* h =
new TH2F(name, title, nbinsX, minX, maxX, nbinsY, minY, maxY);
67 h->GetXaxis()->SetTitle(titleX);
68 h->GetYaxis()->SetTitle(titleY);
77 Int_t nbinsX, Double_t* binsX,
79 Int_t nbinsY, Double_t* binsY,
84 TH2F* h =
new TH2F(name, title, nbinsX, binsX, nbinsY, binsY);
86 h->GetXaxis()->SetTitle(titleX);
87 h->GetYaxis()->SetTitle(titleY);
96 Int_t nbinsX, Double_t minX, Double_t maxX,
98 Int_t nbinsY, Double_t minY, Double_t maxY,
100 Int_t nbinsZ, Double_t minZ, Double_t maxZ,
105 TH3F* h =
new TH3F(name, title, nbinsX, minX, maxX, nbinsY, minY, maxY, nbinsZ, minZ, maxZ);
107 h->GetXaxis()->SetTitle(titleX);
108 h->GetYaxis()->SetTitle(titleY);
109 h->GetZaxis()->SetTitle(titleZ);
118 Int_t nbinsX, Double_t* binsX,
120 Int_t nbinsY, Double_t* binsY,
122 Int_t nbinsZ, Double_t* binsZ,
127 TH3F* h =
new TH3F(name, title, nbinsX, binsX, nbinsY, binsY, nbinsZ, binsZ);
129 h->GetXaxis()->SetTitle(titleX);
130 h->GetYaxis()->SetTitle(titleY);
131 h->GetZaxis()->SetTitle(titleZ);
140 TH1* h, TList* histoList)
143 TH1F* h1 =
dynamic_cast<TH1F*
>(h);
144 TH2F* h2 =
dynamic_cast<TH2F*
>(h);
145 TH3F* h3 =
dynamic_cast<TH3F*
>(h);
150 newh =
new TH1F(*h1);
152 newh =
new TH2F(*h2);
154 newh =
new TH3F(*h3);
156 newh->SetName(newname);
157 newh->SetTitle(newtitle);
160 histoList->Add(newh);
167 TH1* hNum, TH1* hDen,
bool isEffPlot,
171 TH1F* h1den =
dynamic_cast<TH1F*
>(hDen);
172 TH1F* h1num =
dynamic_cast<TH1F*
>(hNum);
173 TH2F* h2den =
dynamic_cast<TH2F*
>(hDen);
174 TH2F* h2num =
dynamic_cast<TH2F*
>(hNum);
175 TH3F* h3den =
dynamic_cast<TH3F*
>(hDen);
176 TH3F* h3num =
dynamic_cast<TH3F*
>(hNum);
182 hden =
new TH1F(*h1den);
183 hnum =
new TH1F(*h1num);
186 hden =
new TH2F(*h2den);
187 hnum =
new TH2F(*h2num);
190 hden =
new TH3F(*h3den);
191 hnum =
new TH3F(*h3num);
199 the_axis = hden->GetXaxis();
200 the_other1 = hden->GetYaxis();
201 the_other2 = hden->GetZaxis();
202 }
else if (axisRef == 1) {
203 the_axis = hden->GetYaxis();
204 the_other1 = hden->GetXaxis();
205 the_other2 = hden->GetZaxis();
206 }
else if (axisRef == 2) {
207 the_axis = hden->GetZaxis();
208 the_other1 = hden->GetXaxis();
209 the_other2 = hden->GetYaxis();
215 if (the_axis->GetXbins()->GetSize())
216 h =
new TH1F(name, title, the_axis->GetNbins(), (the_axis->GetXbins())->GetArray());
218 h =
new TH1F(name, title, the_axis->GetNbins(), the_axis->GetXmin(), the_axis->GetXmax());
219 h->GetXaxis()->SetTitle(the_axis->GetTitle());
221 h->GetYaxis()->SetRangeUser(0.00001, 1);
226 for (
int the_bin = 1; the_bin < the_axis->GetNbins() + 1; the_bin++) {
231 for (
int other1_bin = 1; other1_bin < the_other1->GetNbins() + 1; other1_bin++)
232 for (
int other2_bin = 1; other2_bin < the_other2->GetNbins() + 1; other2_bin++) {
234 if (axisRef == 0) bin = hden->GetBin(the_bin, other1_bin, other2_bin);
235 else if (axisRef == 1) bin = hden->GetBin(other1_bin, the_bin, other2_bin);
236 else if (axisRef == 2) bin = hden->GetBin(other1_bin, other2_bin, the_bin);
238 if (hden->IsBinUnderflow(bin))
239 B2INFO(
" bin = " << bin <<
"(" << the_bin <<
"," << other1_bin <<
"," << other2_bin <<
"), UNDERFLOW");
240 if (hden->IsBinOverflow(bin))
241 B2INFO(
" bin = " << bin <<
"(" << the_bin <<
"," << other1_bin <<
"," << other2_bin <<
"), OVERFLOW");
243 num += hnum->GetBinContent(bin);
244 den += hden->GetBinContent(bin);
253 eff = (double)num / den;
254 err = sqrt(eff * (1 - eff)) / sqrt(den);
258 h->SetBinContent(the_bin, eff);
259 h->SetBinError(the_bin, err);
261 h->SetBinContent(the_bin, 1 - eff);
262 h->SetBinError(the_bin, err);
274 if ((h3_xPerMCParticle == NULL) || (h3_MCParticle == NULL))
278 TH1F* h_ineff_pt =
createHistogramsRatio(
"hineffpt",
"inefficiency VS pt, normalized to MCParticles", h3_xPerMCParticle,
279 h3_MCParticle,
false, 0);
280 histoList->Add(h_ineff_pt);
282 TH1F* h_ineff_theta =
createHistogramsRatio(
"hinefftheta",
"inefficiency VS #theta, normalized to MCParticles",
283 h3_xPerMCParticle, h3_MCParticle,
false, 1);
284 histoList->Add(h_ineff_theta);
286 TH1F* h_ineff_phi =
createHistogramsRatio(
"hineffphi",
"inefficiency VS #phi, normalized to MCParticles", h3_xPerMCParticle,
287 h3_MCParticle,
false, 2);
288 histoList->Add(h_ineff_phi);
294 if ((h3_xPerMCParticle == NULL) || (h3_MCParticle == NULL))
298 TH1F* h_eff_pt =
createHistogramsRatio(
"heffpt",
"efficiency VS pt, normalized to MCParticles", h3_xPerMCParticle,
299 h3_MCParticle,
true, 0);
300 histoList->Add(h_eff_pt);
302 TH1F* h_eff_theta =
createHistogramsRatio(
"hefftheta",
"efficiency VS #theta, normalized to MCParticles", h3_xPerMCParticle,
303 h3_MCParticle,
true, 1);
304 histoList->Add(h_eff_theta);
306 TH1F* h_eff_phi =
createHistogramsRatio(
"heffphi",
"efficiency VS #phi, normalized to MCParticles", h3_xPerMCParticle,
307 h3_MCParticle,
true, 2);
308 histoList->Add(h_eff_phi);
316 if ((h3_X == NULL) || (h3_MCParticlesPerX == NULL))
321 histoList->Add(h_pur_pt);
323 TH1F* h_pur_theta =
createHistogramsRatio(
"hpurtheta",
"purity VS #theta", h3_MCParticlesPerX, h3_X,
true, 1);
324 histoList->Add(h_pur_theta);
326 TH1F* h_pur_phi =
createHistogramsRatio(
"hpurphi",
"purity VS #phi", h3_MCParticlesPerX, h3_X,
true, 2);
327 histoList->Add(h_pur_phi);
332 bool geo_accettance, TList* histoList)
336 std::string trueTitle;
338 if (geo_accettance ==
false) {
339 std::string name1 =
"_noGeoAcc";
340 total = std::string(name) + name1;
341 trueTitle = std::string(title) + name1;
343 std::string name2 =
"_withGeoAcc";
344 total = std::string(name) + name2;
345 trueTitle = std::string(title) + name2;
348 TH1F* h = (TH1F*)
duplicateHistogram(total.c_str(), trueTitle.c_str(), h1_den, histoList);
349 h->GetYaxis()->SetRangeUser(0., 1);
351 for (
int bin = 0; bin < h->GetXaxis()->GetNbins(); bin++) {
352 float num = h1_num->GetBinContent(bin + 1);
353 float den = h1_den->GetBinContent(bin + 1);
358 eff = (double)num / den;
359 err = sqrt(eff * (1 - eff)) / sqrt(den);
361 h->SetBinContent(bin + 1, eff);
362 h->SetBinError(bin + 1, err);
373 const char* title, TList* histoList)
375 if (h1_Track == NULL) B2INFO(
"h_Track missing");
377 std::string name1 =
"_noGeoAcc";
378 std::string name2 =
"_withGeoAcc";
380 std::string total1 = std::string(name) + name1;
381 std::string total2 = std::string(name) + name2;
383 std::string title1 = std::string(title) + name1;
384 std::string title2 = std::string(title) + name2;
388 h[0] = (TH1F*)
duplicateHistogram(total2.c_str(), title2.c_str(), h1_RecoTrack, histoList);
389 h[0]->GetYaxis()->SetRangeUser(0., 1);
391 for (
int bin = 0; bin < h[0]->GetXaxis()->GetNbins(); bin++) {
392 float num = h1_Track->GetBinContent(bin + 1);
393 float den = h1_RecoTrack->GetBinContent(bin + 1);
398 eff = (double)num / den;
399 err = sqrt(eff * (1 - eff)) / sqrt(den);
401 h[0]->SetBinContent(bin + 1, eff);
402 h[0]->SetBinError(bin + 1, err);
406 h[1]->GetYaxis()->SetRangeUser(0., 1);
408 for (
int bin = 0; bin < h[1]->GetXaxis()->GetNbins(); bin++) {
409 float num = h1_Track->GetBinContent(bin + 1);
410 float den = h1_MC->GetBinContent(bin + 1);
415 eff = (double)num / den;
416 err = sqrt(eff * (1 - eff)) / sqrt(den);
418 h[1]->SetBinContent(bin + 1, eff);
419 h[1]->SetBinError(bin + 1, err);
423 histoList->Add(h[0]);
424 histoList->Add(h[1]);
431 const char* name,
const char* title,
bool geo_accettance, TList* histoList)
433 std::string err_char =
"_error_";
434 std::string addTitle =
"Errors, ";
438 std::string trueTitle;
440 std::string titleErr = addTitle + std::string(title);
442 if (geo_accettance ==
false) {
443 std::string name1 =
"_noGeoAcc";
444 total = std::string(name) + name1;
445 trueTitle = std::string(title) + name1;
446 error = std::string(name) + err_char + std::string(name1);
448 std::string name2 =
"_withGeoAcc";
449 total = std::string(name) + name2;
450 trueTitle = std::string(title) + name2;
451 error = std::string(name) + err_char + std::string(name2);
455 h2[0] = (TH2F*)
duplicateHistogram(total.c_str(), trueTitle.c_str(), h2_den, histoList);
456 h2[1] = (TH2F*)
duplicateHistogram(error.c_str(), titleErr.c_str(), h2_den, histoList);
458 for (
int binX = 0; binX < h2[0]->GetXaxis()->GetNbins(); binX++) {
459 for (
int binY = 0; binY < h2[0]->GetYaxis()->GetNbins(); binY++) {
460 float num = h2_num->GetBinContent(binX + 1, binY + 1);
461 float den = h2_den->GetBinContent(binX + 1, binY + 1);
466 eff = (double)num / den;
467 err = sqrt(eff * (1 - eff)) / sqrt(den);
470 h2[0]->SetBinContent(binX + 1, binY + 1, eff);
471 h2[0]->SetBinError(binX + 1, binY + 1, err);
472 h2[1]->SetBinContent(binX + 1, binY + 1, err);
478 histoList->Add(h2[0]);
479 histoList->Add(h2[1]);
487 const char* title, TList* histoList)
489 if (h2_Track == NULL) B2INFO(
"h_Track missing");
491 std::string name1 =
"_noGeoAcc";
492 std::string name2 =
"_withGeoAcc";
493 std::string err_char =
"_error_";
494 std::string addTitle =
"Errors, ";
496 std::string total1 = std::string(name) + name1;
497 std::string total2 = std::string(name) + name2;
499 std::string title1 = std::string(title) + name1;
500 std::string title2 = std::string(title) + name2;
502 std::string error1 = std::string(name) + err_char + name1;
503 std::string error2 = std::string(name) + err_char + name2;
504 std::string titleErr = addTitle + std::string(title);
508 h2[0] = (TH2F*)
duplicateHistogram(total2.c_str(), title2.c_str(), h2_RecoTrack, histoList);
509 h2[1] = (TH2F*)
duplicateHistogram(error2.c_str(), titleErr.c_str(), h2_RecoTrack, histoList);
511 for (
int binX = 0; binX < h2[0]->GetXaxis()->GetNbins(); binX++) {
512 for (
int binY = 0; binY < h2[0]->GetYaxis()->GetNbins(); binY++) {
513 float num = h2_Track->GetBinContent(binX + 1, binY + 1);
514 float den = h2_RecoTrack->GetBinContent(binX + 1, binY + 1);
520 err = sqrt(eff * (1 - eff)) / sqrt(den);
523 h2[0]->SetBinContent(binX + 1, binY + 1, eff);
524 h2[0]->SetBinError(binX + 1, binY + 1, err);
525 h2[1]->SetBinContent(binX + 1, binY + 1, err);
530 h2[3] = (TH2F*)
duplicateHistogram(error1.c_str(), titleErr.c_str(), h2_MC, histoList);
532 for (
int binX = 0; binX < h2[2]->GetXaxis()->GetNbins(); binX++) {
533 for (
int binY = 0; binY < h2[2]->GetYaxis()->GetNbins(); binY++) {
534 float num = h2_Track->GetBinContent(binX + 1, binY + 1);
535 float den = h2_MC->GetBinContent(binX + 1, binY + 1);
541 err = sqrt(eff * (1 - eff)) / sqrt(den);
544 h2[2]->SetBinContent(binX + 1, binY + 1, eff);
545 h2[2]->SetBinError(binX + 1, binY + 1, err);
546 h2[3]->SetBinContent(binX + 1, binY + 1, err);
551 histoList->Add(h2[0]);
552 histoList->Add(h2[1]);
553 histoList->Add(h2[2]);
554 histoList->Add(h2[3]);
563 h->GetYaxis()->SetRangeUser(0., 1);
565 for (
int bin = 0; bin < h->GetXaxis()->GetNbins(); bin++) {
566 float num = h1_num->GetBinContent(bin + 1);
567 float den = h1_den->GetBinContent(bin + 1);
572 eff = (double)num / den;
573 err = sqrt(eff * (1 - eff)) / sqrt(den);
575 h->SetBinContent(bin + 1, eff);
576 h->SetBinError(bin + 1, err);
586 const char* name,
const char* title, TList* histoList)
588 std::string err_char =
"_err";
589 std::string addTitle =
"Errors, ";
591 std::string error = std::string(name) + err_char;
592 std::string titleErr = addTitle + std::string(title);
596 h2[1] = (TH2F*)
duplicateHistogram(error.c_str(), titleErr.c_str(), h2_den, histoList);
598 for (
int binX = 0; binX < h2[0]->GetXaxis()->GetNbins(); binX++) {
599 for (
int binY = 0; binY < h2[0]->GetYaxis()->GetNbins(); binY++) {
600 float num = h2_num->GetBinContent(binX + 1, binY + 1);
601 float den = h2_den->GetBinContent(binX + 1, binY + 1);
606 eff = (double)num / den;
607 err = sqrt(eff * (1 - eff)) / sqrt(den);
609 h2[0]->SetBinContent(binX + 1, binY + 1, eff);
610 h2[0]->SetBinError(binX + 1, binY + 1, err);
611 h2[1]->SetBinContent(binX + 1, binY + 1, err);
616 histoList->Add(h2[0]);
617 histoList->Add(h2[1]);
625 const char* name,
const char* title, TList* histoList)
629 h->GetYaxis()->SetRangeUser(0., 1);
631 for (
int bin = 0; bin < h->GetXaxis()->GetNbins(); bin++) {
632 double dau0 = h1_dau0->GetBinContent(bin);
633 double dau1 = h1_dau1->GetBinContent(bin);
634 double Mother = h1_Mother->GetBinContent(bin);
635 double dau0Err = h1_dau0->GetBinError(bin);
636 double dau1Err = h1_dau1->GetBinError(bin);
637 double MotherErr = h1_Mother->GetBinError(bin);
639 double binCont = 1. * Mother / dau0 / dau1;
640 double binErr = binCont * sqrt((dau0Err / dau0) * (dau0Err / dau0) + (dau1Err / dau1) * (dau1Err / dau1) * (MotherErr / Mother) *
641 (MotherErr / Mother));
643 h->SetBinContent(bin, binCont);
644 h->SetBinError(bin, binErr);