TEfficiency::TEfficiency(const TH1& passed,const TH1& total)

Dear Root users/developers,

I have installed the 5.27.06 root (binary) version for mac, and would like to use the class TEfficiency.
I tried the example “Filling with events” given in root.cern.ch/root/html/TEfficiency.html and get the same graph. However I don’t manage to get a graph with the constructor TEfficiency(const TH1& passed, const TH1& total), using two existing histograms as input.
I defined a very simple test routine :

{
TEfficiency* pEff = 0;

TH1D h_pass = new TH1D(“h_pass”,“pass”,10,0,10);
TH1D h_tot = new TH1D(“h_tot”,“tot”,10,0,10);
for (int i=1;i<11;i++)
{
h_pass->SetBinContent(i,0.5
i);
h_tot->SetBinContent(i,2
i);
h_pass->SetBinError(i,0.05i);
h_tot->SetBinError(i,0.1
i);
}
h_tot->Draw();
h_pass->Draw(“same”);
TFile* pFile = new TFile(“myfile.root”,“recreate”);
if(TEfficiency::CheckConsistency(h_pass,h_tot))
{
pEff = new TEfficiency(h_pass,h_tot);
pEff->Write();
pEff->Draw(“AP”);
}

}
But get the following error message :
Error: Function CheckConsistency(h_pass,h_tot) is not defined in current scope testEff.C:16:
*** Interpreter error recovered ***

If I comment the CheckConsistency Line and replace pEff = new TEfficiency(h_pass,h_tot) by pEff = new TEfficiency::TEfficiency(h_pass,h_tot) I still get an error:

Error: Symbol h_pass,h_tot is not defined in current scope testEff.C:18:
*** Interpreter error recovered ***

Does anybody has an example of how to use the TEfficiency class with two existing histograms?

Thanks,

Pauline

Hi,

First of all your code contains some C++ errors, the function TEfficiency(const TH1& passed, const TH1& total) requires you to pass const reference and you pass pointers (the same for TEfficiency::CheckConsistency ).
In addition, TEfficiency works for for histogram representing counts, thus with integer content and with errors equal to the square root of the content. You instead are filling with floating values and errors not equal to the square root of the content.
Here is your corrected macro as an example:

{
TEfficiency* pEff = 0;

TH1D *h_pass = new TH1D("h_pass","pass",10,0,10);
TH1D *h_tot = new TH1D("h_tot","tot",10,0,10);
for (int i=1;i<11;i++)
{
h_pass->SetBinContent(i,i);
h_tot->SetBinContent(i,2*i);
// no need to set the errors (they are automatically = sqrt(content) 
}
h_tot->Draw();
h_pass->Draw("same");
TFile* pFile = new TFile("myfile.root","recreate");
if(TEfficiency::CheckConsistency(*h_pass,*h_tot))
{
pEff = new TEfficiency(*h_pass,*h_tot);
pEff->Write();
pEff->Draw("AP");
}
}

Best Regards

Lorenzo

Thank you Lorenzo,

I am concerned by the error per bin associated to the two already existing histograms and thus to the TEfficiency one. I am filling the histograms with weighted events and I would like to use the error per bin estimated with Sumw2(). If I force the errors to be estimated with Sumw2() and therefore different from the sqrt(content), the check Consistency of TEfficiency failed. Is there a way to use TEfficiency with weighted events?

Cheers,

Pauline

Hello Pauline,
currently TEfficiency does not support the use case to be built from two histograms with different weights for each event. There is a solution, which should work in the case of only Bayesian statistics, but it is not yet implemented in the class.
What is supported right now is the combination of different efficiency classes with weighted sample of events,
see root.cern.ch/root/htmldoc/TEfficiency.html#cm

Best Regards

Lorenzo