9#include <tracking/modules/trackingPerformanceEvaluation/PerformanceEvaluationBaseClass.h>
11#include <framework/logging/Logger.h>
13#include <root/TAxis.h>
17PerformanceEvaluationBaseClass:: PerformanceEvaluationBaseClass()
21PerformanceEvaluationBaseClass::~ PerformanceEvaluationBaseClass()
27 Int_t nbins, Double_t min, Double_t max,
28 const char* xtitle, TList* histoList)
31 TH1F* h =
new TH1F(name, title, nbins, min, max);
33 h->GetXaxis()->SetTitle(xtitle);
42 Int_t nbins, Double_t* bins,
43 const char* xtitle, TList* histoList)
46 TH1F* h =
new TH1F(name, title, nbins, bins);
48 h->GetXaxis()->SetTitle(xtitle);
57 Int_t nbinsX, Double_t minX, Double_t maxX,
59 Int_t nbinsY, Double_t minY, Double_t maxY,
60 const char* titleY, TList* histoList)
63 TH2F* h =
new TH2F(name, title, nbinsX, minX, maxX, nbinsY, minY, maxY);
65 h->GetXaxis()->SetTitle(titleX);
66 h->GetYaxis()->SetTitle(titleY);
75 Int_t nbinsX, Double_t* binsX,
77 Int_t nbinsY, Double_t* binsY,
82 TH2F* h =
new TH2F(name, title, nbinsX, binsX, nbinsY, binsY);
84 h->GetXaxis()->SetTitle(titleX);
85 h->GetYaxis()->SetTitle(titleY);
94 Int_t nbinsX, Double_t minX, Double_t maxX,
96 Int_t nbinsY, Double_t minY, Double_t maxY,
98 Int_t nbinsZ, Double_t minZ, Double_t maxZ,
103 TH3F* h =
new TH3F(name, title, nbinsX, minX, maxX, nbinsY, minY, maxY, nbinsZ, minZ, maxZ);
105 h->GetXaxis()->SetTitle(titleX);
106 h->GetYaxis()->SetTitle(titleY);
107 h->GetZaxis()->SetTitle(titleZ);
116 Int_t nbinsX, Double_t* binsX,
118 Int_t nbinsY, Double_t* binsY,
120 Int_t nbinsZ, Double_t* binsZ,
125 TH3F* h =
new TH3F(name, title, nbinsX, binsX, nbinsY, binsY, nbinsZ, binsZ);
127 h->GetXaxis()->SetTitle(titleX);
128 h->GetYaxis()->SetTitle(titleY);
129 h->GetZaxis()->SetTitle(titleZ);
138 TH1* h, TList* histoList)
141 TH1F* h1 =
dynamic_cast<TH1F*
>(h);
142 TH2F* h2 =
dynamic_cast<TH2F*
>(h);
143 TH3F* h3 =
dynamic_cast<TH3F*
>(h);
148 newh =
new TH1F(*h1);
150 newh =
new TH2F(*h2);
152 newh =
new TH3F(*h3);
154 if (newh ==
nullptr) {
155 B2ERROR(
"In function duplicateHistogram: newh is a nullptr. This shouldn't happen."\
156 "Don't continue creation of duplicate histogram in this case and return nullptr.");
160 newh->SetName(newname);
161 newh->SetTitle(newtitle);
164 histoList->Add(newh);
171 TH1* hNum, TH1* hDen,
bool isEffPlot,
175 TH1F* h1den =
dynamic_cast<TH1F*
>(hDen);
176 TH1F* h1num =
dynamic_cast<TH1F*
>(hNum);
177 TH2F* h2den =
dynamic_cast<TH2F*
>(hDen);
178 TH2F* h2num =
dynamic_cast<TH2F*
>(hNum);
179 TH3F* h3den =
dynamic_cast<TH3F*
>(hDen);
180 TH3F* h3num =
dynamic_cast<TH3F*
>(hNum);
186 hden =
new TH1F(*h1den);
187 hnum =
new TH1F(*h1num);
190 hden =
new TH2F(*h2den);
191 hnum =
new TH2F(*h2num);
194 hden =
new TH3F(*h3den);
195 hnum =
new TH3F(*h3num);
203 the_axis = hden->GetXaxis();
204 the_other1 = hden->GetYaxis();
205 the_other2 = hden->GetZaxis();
206 }
else if (axisRef == 1) {
207 the_axis = hden->GetYaxis();
208 the_other1 = hden->GetXaxis();
209 the_other2 = hden->GetZaxis();
210 }
else if (axisRef == 2) {
211 the_axis = hden->GetZaxis();
212 the_other1 = hden->GetXaxis();
213 the_other2 = hden->GetYaxis();
219 if (the_axis->GetXbins()->GetSize())
220 h =
new TH1F(name, title, the_axis->GetNbins(), (the_axis->GetXbins())->GetArray());
222 h =
new TH1F(name, title, the_axis->GetNbins(), the_axis->GetXmin(), the_axis->GetXmax());
223 h->GetXaxis()->SetTitle(the_axis->GetTitle());
225 h->GetYaxis()->SetRangeUser(0.00001, 1);
229 for (
int the_bin = 1; the_bin < the_axis->GetNbins() + 1; the_bin++) {
234 for (
int other1_bin = 1; other1_bin < the_other1->GetNbins() + 1; other1_bin++)
235 for (
int other2_bin = 1; other2_bin < the_other2->GetNbins() + 1; other2_bin++) {
237 if (axisRef == 0) bin = hden->GetBin(the_bin, other1_bin, other2_bin);
238 else if (axisRef == 1) bin = hden->GetBin(other1_bin, the_bin, other2_bin);
239 else if (axisRef == 2) bin = hden->GetBin(other1_bin, other2_bin, the_bin);
241 if (hden->IsBinUnderflow(bin))
242 B2INFO(
" bin = " << bin <<
"(" << the_bin <<
"," << other1_bin <<
"," << other2_bin <<
"), UNDERFLOW");
243 if (hden->IsBinOverflow(bin))
244 B2INFO(
" bin = " << bin <<
"(" << the_bin <<
"," << other1_bin <<
"," << other2_bin <<
"), OVERFLOW");
246 num += hnum->GetBinContent(bin);
247 den += hden->GetBinContent(bin);
254 eff = (double)num / den;
255 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
259 h->SetBinContent(the_bin, eff);
260 h->SetBinError(the_bin, err);
262 h->SetBinContent(the_bin, 1 - eff);
263 h->SetBinError(the_bin, err);
275 if ((h3_xPerMCParticle ==
nullptr) || (h3_MCParticle ==
nullptr))
279 TH1F* h_ineff_pt =
createHistogramsRatio(
"hineffpt",
"inefficiency VS pt, normalized to MCParticles", h3_xPerMCParticle,
280 h3_MCParticle,
false, 0);
281 histoList->Add(h_ineff_pt);
283 TH1F* h_ineff_theta =
createHistogramsRatio(
"hinefftheta",
"inefficiency VS #theta, normalized to MCParticles",
284 h3_xPerMCParticle, h3_MCParticle,
false, 1);
285 histoList->Add(h_ineff_theta);
287 TH1F* h_ineff_phi =
createHistogramsRatio(
"hineffphi",
"inefficiency VS #phi, normalized to MCParticles", h3_xPerMCParticle,
288 h3_MCParticle,
false, 2);
289 histoList->Add(h_ineff_phi);
295 if ((h3_xPerMCParticle ==
nullptr) || (h3_MCParticle ==
nullptr))
299 TH1F* h_eff_pt =
createHistogramsRatio(
"heffpt",
"efficiency VS pt, normalized to MCParticles", h3_xPerMCParticle,
300 h3_MCParticle,
true, 0);
301 histoList->Add(h_eff_pt);
303 TH1F* h_eff_theta =
createHistogramsRatio(
"hefftheta",
"efficiency VS #theta, normalized to MCParticles", h3_xPerMCParticle,
304 h3_MCParticle,
true, 1);
305 histoList->Add(h_eff_theta);
307 TH1F* h_eff_phi =
createHistogramsRatio(
"heffphi",
"efficiency VS #phi, normalized to MCParticles", h3_xPerMCParticle,
308 h3_MCParticle,
true, 2);
309 histoList->Add(h_eff_phi);
317 if ((h3_X ==
nullptr) || (h3_MCParticlesPerX ==
nullptr))
322 histoList->Add(h_pur_pt);
324 TH1F* h_pur_theta =
createHistogramsRatio(
"hpurtheta",
"purity VS #theta", h3_MCParticlesPerX, h3_X,
true, 1);
325 histoList->Add(h_pur_theta);
327 TH1F* h_pur_phi =
createHistogramsRatio(
"hpurphi",
"purity VS #phi", h3_MCParticlesPerX, h3_X,
true, 2);
328 histoList->Add(h_pur_phi);
333 bool geo_accettance, TList* histoList)
335 if (h1_den ==
nullptr or h1_num ==
nullptr) {
336 B2ERROR(
"One of the input histograms for function effPlot1D is a nullptr, "\
337 "can't create new histograms from this. Returning a nullptr.");
342 std::string trueTitle;
344 if (geo_accettance ==
false) {
345 std::string name1 =
"_noGeoAcc";
346 total = std::string(name) + name1;
347 trueTitle = std::string(title) + name1;
349 std::string name2 =
"_withGeoAcc";
350 total = std::string(name) + name2;
351 trueTitle = std::string(title) + name2;
354 TH1F* h = (TH1F*)
duplicateHistogram(total.c_str(), trueTitle.c_str(), h1_den, histoList);
355 h->GetYaxis()->SetRangeUser(0., 1);
357 for (
int bin = 0; bin < h->GetXaxis()->GetNbins(); bin++) {
358 float num = h1_num->GetBinContent(bin + 1);
359 float den = h1_den->GetBinContent(bin + 1);
364 eff = (double)num / den;
365 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
367 h->SetBinContent(bin + 1, eff);
368 h->SetBinError(bin + 1, err);
379 const char* title, TList* histoList)
381 if (h1_MC ==
nullptr or h1_RecoTrack ==
nullptr or h1_Track ==
nullptr) {
382 B2ERROR(
"One of the input histograms for function effPlot1D is a nullptr, "\
383 "can't create new histograms from this. Returning a nullptr.");
387 std::string name1 =
"_noGeoAcc";
388 std::string name2 =
"_withGeoAcc";
390 std::string total1 = std::string(name) + name1;
391 std::string total2 = std::string(name) + name2;
393 std::string title1 = std::string(title) + name1;
394 std::string title2 = std::string(title) + name2;
398 h[0] = (TH1F*)
duplicateHistogram(total2.c_str(), title2.c_str(), h1_RecoTrack, histoList);
399 h[0]->GetYaxis()->SetRangeUser(0., 1);
401 for (
int bin = 0; bin < h[0]->GetXaxis()->GetNbins(); bin++) {
402 float num = h1_Track->GetBinContent(bin + 1);
403 float den = h1_RecoTrack->GetBinContent(bin + 1);
408 eff = (double)num / den;
409 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
411 h[0]->SetBinContent(bin + 1, eff);
412 h[0]->SetBinError(bin + 1, err);
416 h[1]->GetYaxis()->SetRangeUser(0., 1);
418 for (
int bin = 0; bin < h[1]->GetXaxis()->GetNbins(); bin++) {
419 float num = h1_Track->GetBinContent(bin + 1);
420 float den = h1_MC->GetBinContent(bin + 1);
425 eff = (double)num / den;
426 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
428 h[1]->SetBinContent(bin + 1, eff);
429 h[1]->SetBinError(bin + 1, err);
433 histoList->Add(h[0]);
434 histoList->Add(h[1]);
441 const char* name,
const char* title,
bool geo_accettance, TList* histoList)
443 if (h2_den ==
nullptr or h2_num ==
nullptr) {
444 B2ERROR(
"One of the input histograms for function effPlot1D is a nullptr, "\
445 "can't create new histograms from this. Returning a nullptr.");
449 std::string err_char =
"_error_";
450 std::string addTitle =
"Errors, ";
454 std::string trueTitle;
456 std::string titleErr = addTitle + std::string(title);
458 if (geo_accettance ==
false) {
459 std::string name1 =
"_noGeoAcc";
460 total = std::string(name) + name1;
461 trueTitle = std::string(title) + name1;
462 error = std::string(name) + err_char + std::string(name1);
464 std::string name2 =
"_withGeoAcc";
465 total = std::string(name) + name2;
466 trueTitle = std::string(title) + name2;
467 error = std::string(name) + err_char + std::string(name2);
471 h2[0] = (TH2F*)
duplicateHistogram(total.c_str(), trueTitle.c_str(), h2_den, histoList);
472 h2[1] = (TH2F*)
duplicateHistogram(error.c_str(), titleErr.c_str(), h2_den, histoList);
474 for (
int binX = 0; binX < h2[0]->GetXaxis()->GetNbins(); binX++) {
475 for (
int binY = 0; binY < h2[0]->GetYaxis()->GetNbins(); binY++) {
476 float num = h2_num->GetBinContent(binX + 1, binY + 1);
477 float den = h2_den->GetBinContent(binX + 1, binY + 1);
482 eff = (double)num / den;
483 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
486 h2[0]->SetBinContent(binX + 1, binY + 1, eff);
487 h2[0]->SetBinError(binX + 1, binY + 1, err);
488 h2[1]->SetBinContent(binX + 1, binY + 1, err);
494 histoList->Add(h2[0]);
495 histoList->Add(h2[1]);
503 const char* title, TList* histoList)
505 if (h2_MC ==
nullptr or h2_RecoTrack ==
nullptr or h2_Track ==
nullptr) {
506 B2ERROR(
"One of the input histograms for function effPlot1D is a nullptr, "\
507 "can't create new histograms from this. Returning a nullptr.");
511 std::string name1 =
"_noGeoAcc";
512 std::string name2 =
"_withGeoAcc";
513 std::string err_char =
"_error_";
514 std::string addTitle =
"Errors, ";
516 std::string total1 = std::string(name) + name1;
517 std::string total2 = std::string(name) + name2;
519 std::string title1 = std::string(title) + name1;
520 std::string title2 = std::string(title) + name2;
522 std::string error1 = std::string(name) + err_char + name1;
523 std::string error2 = std::string(name) + err_char + name2;
524 std::string titleErr = addTitle + std::string(title);
528 h2[0] = (TH2F*)
duplicateHistogram(total2.c_str(), title2.c_str(), h2_RecoTrack, histoList);
529 h2[1] = (TH2F*)
duplicateHistogram(error2.c_str(), titleErr.c_str(), h2_RecoTrack, histoList);
531 for (
int binX = 0; binX < h2[0]->GetXaxis()->GetNbins(); binX++) {
532 for (
int binY = 0; binY < h2[0]->GetYaxis()->GetNbins(); binY++) {
533 float num = h2_Track->GetBinContent(binX + 1, binY + 1);
534 float den = h2_RecoTrack->GetBinContent(binX + 1, binY + 1);
540 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
543 h2[0]->SetBinContent(binX + 1, binY + 1, eff);
544 h2[0]->SetBinError(binX + 1, binY + 1, err);
545 h2[1]->SetBinContent(binX + 1, binY + 1, err);
550 h2[3] = (TH2F*)
duplicateHistogram(error1.c_str(), titleErr.c_str(), h2_MC, histoList);
552 for (
int binX = 0; binX < h2[2]->GetXaxis()->GetNbins(); binX++) {
553 for (
int binY = 0; binY < h2[2]->GetYaxis()->GetNbins(); binY++) {
554 float num = h2_Track->GetBinContent(binX + 1, binY + 1);
555 float den = h2_MC->GetBinContent(binX + 1, binY + 1);
561 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
564 h2[2]->SetBinContent(binX + 1, binY + 1, eff);
565 h2[2]->SetBinError(binX + 1, binY + 1, err);
566 h2[3]->SetBinContent(binX + 1, binY + 1, err);
571 histoList->Add(h2[0]);
572 histoList->Add(h2[1]);
573 histoList->Add(h2[2]);
574 histoList->Add(h2[3]);
583 h->GetYaxis()->SetRangeUser(0., 1);
585 for (
int bin = 0; bin < h->GetXaxis()->GetNbins(); bin++) {
586 float num = h1_num->GetBinContent(bin + 1);
587 float den = h1_den->GetBinContent(bin + 1);
592 eff = (double)num / den;
593 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
595 h->SetBinContent(bin + 1, eff);
596 h->SetBinError(bin + 1, err);
606 const char* name,
const char* title, TList* histoList)
608 std::string err_char =
"_err";
609 std::string addTitle =
"Errors, ";
611 std::string error = std::string(name) + err_char;
612 std::string titleErr = addTitle + std::string(title);
616 h2[1] = (TH2F*)
duplicateHistogram(error.c_str(), titleErr.c_str(), h2_den, histoList);
618 for (
int binX = 0; binX < h2[0]->GetXaxis()->GetNbins(); binX++) {
619 for (
int binY = 0; binY < h2[0]->GetYaxis()->GetNbins(); binY++) {
620 float num = h2_num->GetBinContent(binX + 1, binY + 1);
621 float den = h2_den->GetBinContent(binX + 1, binY + 1);
626 eff = (double)num / den;
627 err =
sqrt(eff * (1 - eff)) /
sqrt(den);
629 h2[0]->SetBinContent(binX + 1, binY + 1, eff);
630 h2[0]->SetBinError(binX + 1, binY + 1, err);
631 h2[1]->SetBinContent(binX + 1, binY + 1, err);
636 histoList->Add(h2[0]);
637 histoList->Add(h2[1]);
645 const char* name,
const char* title, TList* histoList)
649 h->GetYaxis()->SetRangeUser(0., 1);
651 for (
int bin = 0; bin < h->GetXaxis()->GetNbins(); bin++) {
652 double dau0 = h1_dau0->GetBinContent(bin);
653 double dau1 = h1_dau1->GetBinContent(bin);
654 double Mother = h1_Mother->GetBinContent(bin);
655 double dau0Err = h1_dau0->GetBinError(bin);
656 double dau1Err = h1_dau1->GetBinError(bin);
657 double MotherErr = h1_Mother->GetBinError(bin);
659 double binCont = 1. * Mother / dau0 / dau1;
660 double binErr = binCont *
sqrt((dau0Err / dau0) * (dau0Err / dau0) + (dau1Err / dau1) * (dau1Err / dau1) * (MotherErr / Mother) *
661 (MotherErr / Mother));
663 h->SetBinContent(bin, binCont);
664 h->SetBinError(bin, binErr);
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.