I have two histograms have both 1 bin. I would like to calculate the efficiency using Tefficiency class but got an issue (below)
I’m calculating the efficiency like that :
TEfficiency *eff = new TEfficiency(*hpass,*htot)
where the total number of events in each is
hpass====>5939
htot ======>35943
Info in TROOT::TEfficiency::CheckEntries: Histograms are not consistent: passed bin content > total bin content
Error in TROOT::TEfficiency::CheckConsistency: passed TEfficiency objects do not have consistent bin contents
Error in <TEfficiency::TEfficiency(const TH1&,const TH1&)>: histograms are not consistent -> results are useless
Warning in <TEfficiency::TEfficiency(const TH1&,const TH1&)>: using two empty TH1D(‘h1’,‘h1’,10,0,10)
can you please share your code? I can’t seem to reproduce the issue: the following works perfectly fine for me, printing out “Efficiency of that only bin is 0.165234” :
TH1F* hpass = new TH1F("hpass", ";#eta;Number of particles", 1, 2.5, 4.5);
hpass->Fill(3., 5939);
TH1F* htot = new TH1F("htot", ";#eta;Number of particles", 1, 2.5, 4.5);
htot->Fill(3., 35943);
TEfficiency *eff = new TEfficiency(*hpass,*htot);
printf("Efficiency of that only bin is %f\n", eff->GetEfficiency(1));
I just the total number shown in a table not the distribution ? I already made distributions in 20 bins but had problem getting the total efficiency and its error ? I heard it’s not practical to get the total efficiency by doing the mean of efficiency in each bin.
this the reason that lead me to do
I don’t know if you have any suggestion
Your problem is that the content of the underflow bin of the hpass histogram (3950 for loose_trk_misID, 3653 for medium_trk_misID, and 3305 for tight_trk_misID) is larger than the content of the underflow bin of the htot histogram (zero). The documentation clearly states that
pass.GetBinContent(i) has to be <= total.GetBinContent(i) for each bin i
I think you should modify your selection code. With the correct code you shouldn’t have the content of the underflow bin of the pass histogram greater than the content of the same bin of the total histogram.
On the other hand, you could simply manually nullify the underflow bin in the pass histogram. Provided, of course, that you aren’t interested in it. And the issue will disappear.
hpass->SetBinContent(0, 0.); // set the content of bin #0 to 0.0
as in
std::unique_ptr<TFile> file{TFile::Open("~yelghaza/public/100GeV_signal_pu_NN.root")};
if (!file || file->IsZombie())
{
printf("ERROR: can't open input file, bailing out...\n");
return;
}
std::unique_ptr<TH1> hpass(static_cast<TH1*>(file->Get("loose_trk_misID")));
if (!hpass)
{
printf("ERROR: can't fetch the \"loose_trk_misIDfrom\" histogram from the input file, bailing out...\n");
return;
}
std::unique_ptr<TH1> htot(static_cast<TH1*>(file->Get("signal_truth")));
if (!htot)
{
printf("ERROR: can't fetch the \"signal_truth\" histogram from the input file, bailing out...\n");
return;
}
hpass->SetBinContent(0, 0.);
TEfficiency *eff = new TEfficiency(*hpass, *htot);
printf("Efficiency of the only visible bin is %f\n", eff->GetEfficiency(1));
return;