# How to calculate Efficiency error?

**URL:** <https://root-forum.cern.ch/t/how-to-calculate-efficiency-error/38425>\
**Category:** Newbie\
**Created:** [March 16, 2020, 9:53am UTC](https://root-forum.cern.ch/t/how-to-calculate-efficiency-error/38425 "2020-03-16T09:53:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![meu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meu/32/20557_2.png) [@meu](https://root-forum.cern.ch/u/meu)\
**Post date:** [March 16, 2020, 9:53am UTC](https://root-forum.cern.ch/t/how-to-calculate-efficiency-error/38425/1 "2020-03-16T09:53:00Z")

</div>

Hi, everyone

I use one detector like Scintillator, Aerogel Cherenkov counter.

When I get the total number of events N and the observed number of passed events k with cut condition, I can define efficiency.

efficiency=k/N

But I don’t know how to calculate Efficiency error.

I think TEfficiency method can calculate this, but I found method using two histogram.

If I have three data set (cut, N, k) instead of histgram.

How do I use TEfficiency and get efficincy error?

Please help me.

---

<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:** [March 16, 2020, 2:16pm UTC](https://root-forum.cern.ch/t/how-to-calculate-efficiency-error/38425/2 "2020-03-16T14:16:25Z")

</div>

Hi,

You can call directly the TEfficiency static functions such as `ClopperPearson` for the frequentist method, where you pass the number of passed (k) and the total number (N) and it returns the upper or lower level of the interval.  
See [https://root.cern.ch/doc/master/classTEfficiency.html#ae80c3189bac22b7ad15f57a1476ef75b](https://root.cern.ch/doc/master/classTEfficiency.html#ae80c3189bac22b7ad15f57a1476ef75b)

For the description of the different method see the general TEfficiency documentation

Lorenzo

---

<div class="post-metadata">

**Author:** ![meu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meu/32/20557_2.png) [@meu](https://root-forum.cern.ch/u/meu)\
**Post date:** [March 16, 2020, 9:41pm UTC](https://root-forum.cern.ch/t/how-to-calculate-efficiency-error/38425/3 "2020-03-16T21:41:47Z")

</div>

Thank you.

Your answer helped me.  
I have two questions about link you sent.

**First**  
I tried TEfficinency::ClopperPearson as fallows

```auto
cout << TEfficiency::ClopperPearson(100, 100, 95, true) << endl;

```

This return 1.  
I think “true” option means upper bounary and efficiency=100/100=1.  
So, **This means the upper limit (error?) of efficiency is 1+1=2 ?.**  
I think upper boundary is zero if efficiency =0. I can’t understand this result.

**Second**  
I can’t understand “P(x ≧ passed; total)=(1-level)/2” in document you sent.  
Where does “(1-level)/2” term come from?

This is my lack of knowledge about statistics.  
Please teach me if possible…

---

<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:** [March 17, 2020, 7:57am UTC](https://root-forum.cern.ch/t/how-to-calculate-efficiency-error/38425/4 "2020-03-17T07:57:51Z")

</div>

Hi,

The function it returns the upper value of the efficiency. In case the central value ( npassed/ntotal) is very close to 1, the upper interval value is then 1 as expected.  
The upper/lower error value (computed at 68% confidence level ) are as following:

```auto
double efficiency = double(k)/N; 
double lower_error = efficiency - TEfficiency::ClopperPearson(N, k, 0.683, false);
double upper_error = TEfficiency::ClopperPearson(N, k, 0.683, true) - efficiency; 

```

For the second question, `P(x ≧ passed; total)=(1-level)/2` comes from the definition of the upper interval. The probability to get a value outside the confidence interval is `1.-condidence_level`.  
Then if you consider only the upper interval and by definition you want equal probability on the lower/upper side, then you divide by a factor 2.

Lorenzo

---

<div class="post-metadata">

**Author:** ![meu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meu/32/20557_2.png) [@meu](https://root-forum.cern.ch/u/meu)\
**Post date:** [March 17, 2020, 12:53pm UTC](https://root-forum.cern.ch/t/how-to-calculate-efficiency-error/38425/5 "2020-03-17T12:53:31Z")

</div>

Thank you for your answer.  
I forgot to change the third argument. I treated it as percentage notation.  
And I misunderstood the meaning of upper/lower boundary.

And thank you for your second answer.  
I study your answer as a reference.

Thank you very much.
