# TEfficiency or Divide(..."B") for SF files

**URL:** <https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762>\
**Category:** Newbie\
**Tags:** python\
**Created:** [September 9, 2021, 2:22pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762 "2021-09-09T14:22:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrobac](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/50afbb/32.png) [@adrobac](https://root-forum.cern.ch/u/adrobac)\
**Post date:** [September 9, 2021, 2:22pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/1 "2021-09-09T14:22:17Z")

</div>

Hi there,

I’m making efficiency scale factors (SF), where the SF is the ratio of the data efficiency to the simulated efficiency, and I need to calculate the overall stat uncertainty on these SFs. The workflow (in pseudocode) right now is

data\_efficiency\_TH2 = data\_matches\_TH2.Divide(data\_total\_TH2)  
mc\_efficiency\_TH2 = mc\_matches\_TH2.Divide(mc\_total\_TH2)  
SF\_TH2 = data.efficiency\_TH2.Divide(mc\_efficiency\_TH2)

My understanding, though, is that just using this Divide() function doesn’t properly do binomial error, and that I should either use Divide(hist1, hist2, 1, 1, “B”) or create TEfficiency objects and use those (though I am unfamiliar with TEfficiency and am not sure how to access the bin error once the objects are created). It’s unclear to me from looking at previous forums which is the recommended approach. Any suggestions?

Thanks!

* * *

ROOT version: 6.22.00

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [September 9, 2021, 10:47pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/2 "2021-09-09T22:47:26Z")

</div>

Hi @adrobac; I am sure @couet can help you with this.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 10, 2021, 7:01am UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/3 "2021-09-10T07:01:08Z")

</div>

I think @moneta will know better than me.

---

<div class="post-metadata">

**Author:** ![adrobac](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/50afbb/32.png) [@adrobac](https://root-forum.cern.ch/u/adrobac)\
**Post date:** [September 16, 2021, 3:39pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/4 "2021-09-16T15:39:56Z")

</div>

Thanks @jalopezg and @couet for your replies. I’m just replying as well to refresh this question in the topics list.

---

<div class="post-metadata">

**Author:** ![adrobac](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/50afbb/32.png) [@adrobac](https://root-forum.cern.ch/u/adrobac)\
**Post date:** [September 23, 2021, 1:29pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/5 "2021-09-23T13:29:35Z")

</div>

@moneta ? Sorry to bother you again, but I could really use some help with this.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [September 23, 2021, 2:23pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/6 "2021-09-23T14:23:07Z")

</div>

Hi,  
For proper error estimation on the efficiency you should use the TEfficiency class passing the total and pass histograms. The class will compute correctly the errors in the efficiency providing different statistical methods for doing it. It includes also the case of `TH1::Divide(.."B")` .  
See the reference documentation of [TEfficiency](https://root.cern.ch/doc/master/classTEfficiency.html). There should be there enough information to learn on how to use the class.  
Apologies for the late reply.

Lorenzo

---

<div class="post-metadata">

**Author:** ![adrobac](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/50afbb/32.png) [@adrobac](https://root-forum.cern.ch/u/adrobac)\
**Post date:** [September 23, 2021, 3:37pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/7 "2021-09-23T15:37:12Z")

</div>

Thank you for the reply @moneta! I think I understand what I should do now, but I just wanted to confirm that the default options are sufficient:

First, if I do  
dataHist = TEfficiency(dataMatchHists,dataProbeHist).GetCopyTotalHisto(),  
and likewise for MC, I get TH2’s with properly-calculated binominal errors.

Then, for the SF, which is Data eff / MC eff, I believe that since they are uncorrelated errors I can simply take the hists from above and do  
SFHist = dataHist.Divide(MCHist),  
which will propagate the data and MC hist errors in quadrature.

Is this the correct way to go about things, to your understanding?

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [September 23, 2021, 4:36pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/8 "2021-09-23T16:36:22Z")

</div>

Hi,

To get the properly calculated binomial errors, you need to use directly the TEfficiency class…  
You can draw it or get their bin content and errors calling  
`TEfficiency::GetEfficiency(bin)` and `TEfficiency::GetEfficiencyErrorLow(bin)`, `TEfficiency::GetEfficiencyErrorUp(bin)`.  
After having drawn it (calling `TEfficiency::Draw()`) , you can get the corresponding Graph (for the 1D case), by calling `TEfficiency::GetPaintedGraph()` and `TEfficiency::GetPaintedHistogram()` for the 2-d case as yours.

For uncorrelated histograms you can call `TH1::Divide`, but if you want proper Poisson errors ratio error, you can use (for 1D case only), `TGraphAsymmErrors::Divide(h1,h2, "pois")`, see [ROOT: TGraphAsymmErrors Class Reference](https://root.cern.ch/doc/master/classTGraphAsymmErrors.html#a37a202762b286cf4c7f5d34046be8c0b)

---

<div class="post-metadata">

**Author:** ![adrobac](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/50afbb/32.png) [@adrobac](https://root-forum.cern.ch/u/adrobac)\
**Post date:** [September 24, 2021, 3:35pm UTC](https://root-forum.cern.ch/t/tefficiency-or-divide-b-for-sf-files/46762/9 "2021-09-24T15:35:15Z")

</div>

I think this is all that I need; thank you for the help!
