Large Error bars in TEffciency

Hello,

I am using TEfficiency to calculte the efficiency, with option “TEfficiency::kFNormal”
I am getting large error bars and I wonder if there’s a way to reduce those error bars ? see the plot below

Hi,
Are you sure you are using the normal approximation ? It seems the error bars are asymmetric and this should not be the case for normal.

If you are using the default Clopper_Pearson it is true in some low statistics case the error bars are not small. You can use try also to use one of the other options available.

Lorenzo

I tried the default option, but seems it doesn’t support weighted histograms, so I tried KFNormal,
the code I used is below

void teff(){

TFile *f1 = new TFile("100GeV_signal_pu_NN.root", "READ");
TString f2 = "";
TH1F *h1 = (TH1F*)f1->Get("loose");
TH1F *h3 = (TH1F*)f1->Get("medium");
TH1F *h4 = (TH1F*)f1->Get("tight");

TH1F *h2 = (TH1F*)f1->Get("signal_truth");

TCanvas* c1 = new TCanvas("example","",600,400);

TH1F *hpass_l = new TH1F("hpass_l", "hpass_loosevseta", 10, 2., 4.5);
TH1F *hpass_m = new TH1F("hpass_m", "hpass_mediumvseta", 10, 2., 4.5);
TH1F *hpass_t = new TH1F("hpass_t", "hpass_tightvseta", 10, 2., 4.5);

TH1F *htot = new TH1F("htot", "htotvseta", 10, 2., 4.5);

for (Int_t i = 1; i <= h1->GetNbinsX(); i++){
    hpass_l->Fill(h1->GetBinCenter(i), h1->GetBinContent(i));
  
    hpass_l->ResetStats();
}   
for (Int_t i = 1; i <= h3->GetNbinsX(); i++){
    hpass_m->Fill(h3->GetBinCenter(i), h3->GetBinContent(i));
   
    hpass_m->ResetStats();
}  
for (Int_t i = 1; i <= h4->GetNbinsX(); i++){
    hpass_t->Fill(h4->GetBinCenter(i), h4->GetBinContent(i));
   
    hpass_t->ResetStats();
}  
for (Int_t i = 1; i <= h2->GetNbinsX(); i++){
    htot->Fill(h2->GetBinCenter(i), h2->GetBinContent(i));
    
    htot->ResetStats();
} 

TEfficiency *eff_l= new TEfficiency(*hpass_l, *htot);
eff_l->SetStatisticOption(TEfficiency::kFNormal);

TEfficiency *eff_m= new TEfficiency(*hpass_m, *htot);
eff_m->SetStatisticOption(TEfficiency::kFNormal);

TEfficiency *eff_t= new TEfficiency(*hpass_t, *htot);
eff_t->SetStatisticOption(TEfficiency::kFNormal);

std::cout<<" Loose Efficiency  "<<eff_l->GetEfficiency(1)<<" Loose Eff Error down  "<<eff_l->GetEfficiencyErrorLow(1)<<"  Loose Eff Error up  "<<eff_l->GetEfficiencyErrorUp(1)<<std::endl;
std::cout<<" Medium Efficiency "<<eff_m->GetEfficiency(1)<<" Meduim Eff Error down "<<eff_m->GetEfficiencyErrorLow(1)<<"  Medium Eff Error up "<<eff_m->GetEfficiencyErrorUp(1)<<std::endl;
std::cout<<" Tight Efficiency  "<<eff_t->GetEfficiency(1)<<" Tight Eff Error down  "<<eff_t->GetEfficiencyErrorLow(1)<<" Tight Eff Error up  "<<eff_t->GetEfficiencyErrorUp(1)<<std::endl;

eff_l->Draw("AP");
eff_m->Draw("same");
eff_t->Draw("same");

eff_l->SetLineColor(kBlue);
eff_l->SetLineWidth(3);
eff_m->SetLineColor(kGreen);
eff_m->SetLineWidth(3);
eff_t->SetLineColor(kRed);
eff_t->SetLineWidth(3);


TLegend* legend1 = new TLegend(0.8,0.75,0.9,0.9);
legend1->SetBorderSize(0);  // no borde
legend1->SetBorderSize(0);  // simple border, but no drop shadow
legend1->SetFillColor(0);   // Legend1 background should be white
legend1->SetTextSize(0.03); // Increase entry font size!
legend1->SetFillStyle(0);
legend1->AddEntry(eff_l, "Loose",  "l");
legend1->AddEntry(eff_m, "Medium",  "l");
legend1->AddEntry(eff_t, "Tight",  "l");
legend1->Draw("same");
c1->Print("eff.png");

}

Hi,

I think huge error bars are the result of how you fill your histograms. In the loop over all bins you simply fill this bin with whatever was in this bin in a different histogram. This way the statistical uncertainty on the content of every bin is 100%. Why? Why not simply forget about hpass_l, hpass_m, and hpass_t and feed your primary histograms h1, h3, and h4 to the TEfficiency objects?

Hi
Thanks a lot for your suggestion, It works, But it didn’t give me error bars along y-axis ??(see plot below)

Hi,
can you maybe show the updated code and your input .root files? I guess the uncertainties are just so small they are basically invisible (unless you made some additional changes in the code). If you’d rather not show the .root files, maybe just let us know the statistics in these h1, h2, h3, and h4?

here is the root file

just do
TEfficiency *eff_l = new TEfficiency(*loose, *signal_truth);
eff_l->SetStatisticOption(TEfficiency::kFCP);
eff_l->Draw();

Right, the bin contents of both loose and signal_truth are large enough to yield a virtually invisible uncertainty.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.