Is there any way to use TEfficiency with weighted histograms?

While creating the object TEfficiency, the option “w” can not be specified so that it fails.

Could ROOT add the option to the constructor of TEfficiency? Otherwise the option “w” in the CheckConsistency is useless since even if two histograms passed CheckConsistency, the object could not be created.

The code and output are shown below:

root [0] TH1F *A=new TH1F("a","a",10,0,10)
root [1] TH1F *B=new TH1F("b","b",10,0,10)
root [2] A->Fill(0.5,0.5)
root [3] B->Fill(0.5,1)
root [4] TEfficiency *t= new TEfficiency(*A,*B)
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)
root [9] TEfficiency::CheckConsistency(*A,*B)
Error in <TROOT::TEfficiency::CheckConsistency>: passed TEfficiency objects do not have consistent bin contents
(Bool_t)0
root [10] TEfficiency::CheckConsistency(*A,*B,"w")
(Bool_t)1

Currently there is no support for using TEfficiency with weighted histograms. We are planning to do it in one of the next ROOT release. However, you can try to use TGraphAsymmErrors::Divide. The Bayesian statistical methods and the normal approximation should work in case of weighted histograms. For the other statistical methods there is currently no support for weighted events.

Hi,
I would like to have an update on this topic.
I am evaluating an efficiency with weighted histograms, using the Clopper-Pearson interval, so I am wondering if is possible to use the Divide method with weights involved.
Thank you for your help, and apologies if the question sounds silly to you.

TEfficiency supports now weighted histograms but only for the Bayesian methods and for a likelihood based one, not for Clopper-Pearson, which can work only for histogram filled with integer values.

The TEfficiency constructor tells me the histograms I am working with are weighted, and is able to create a TEfficiency object but automatically sets the statistical option to kFNormal due to these weights. I would like to use kFWilson.

From what I understand, the histograms have been weighted but the number of entries for each bin is still integer-valued.

Is there anyway to circumvent the fact that the histograms’ entries are weighted, even if the weight is integral? Could I create a new TH1 and fill it with the events from the original histograms such that the number of entries is the same and integral but where TEfficiency doesn’t recognize it as “having weights”?

From what I understand, the Wilson score method needs integral values for pass and total (the normal approximation interval does not), so I don’t think there’s a fundamental issue here.

Alternatively, could I use TGraphAsymmErrors to circumvent this issue? Is there any difference in using TEfficiency and TGraphAsymmErrors with respect to dividing pass over total and then finding asymmetric errors with whatever method?

TEfficiency checks if the total sum of weights is equal to the total sum of the weight square. If an histogram represents counts, it has been filled always with weights equal to 1. If this is not the case the statistics is different and we can use only the normal assumption. If you are sure your histogram represent counts then you can force the histogram to be un-weighted by calling
TH1::Sumw2(false)

TGraphAsymmErrors has the same functionality as TEfficiency for binomial errors, but in addition can compute the error also in case of the poisson ratio, i.e. when the numerator and denominator are uncorrelated.

Thank you for the advice so far. I use histo->Sumw2(false) on both pass and total histograms used to make both TEfficiency objects. For the first TEfficiency object I construct and plot, it works and I get no kFNormal error. For the second object I get

which appears when using the Draw method.

There is possibly a bug here, since the error bars of this second distribution actually do change, and in this case get smaller. In my situation, the error bars seem to shrink when invoking kFWilson as opposed to (automatically defaulting to?) kFNormal.

I’m not sure whether this is a bug or whether the Draw error message is correct. I don’t understand why using Sumw2(false) and kFWilson would work for one TEfficiency object but not the other.