# TGraphAsymmErrors::Divide skips bins

**URL:** <https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314>\
**Category:** ROOT\
**Tags:** feature\
**Created:** [March 23, 2022, 12:19am UTC](https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314 "2022-03-23T00:19:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfontana](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/6bbea6/32.png) [@bfontana](https://root-forum.cern.ch/u/bfontana)\
**Post date:** [March 23, 2022, 12:19am UTC](https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314/1 "2022-03-23T00:19:57Z")

</div>

As described in [TGraphAsymmErrors](https://root.cern.ch/doc/master/classTGraphAsymmErrors.html#a37a202762b286cf4c7f5d34046be8c0b)::Divide method:

> If the denominator becomes 0 or pass \> total, the corresponding bin is skipped.

While an efficiency does not indeed make sense when the denominator is zero, silently skipping those bins is extremely error-prone. Why not raising an exception (thinking about `PyROOT`) or at least returning a flag?

* * *

_ROOT Version:_ 6.22/09  
_Platform:_ CentOS 7 (Core)  
_Compiler:_ GCC 9.3.0

* * *

---

<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:** [March 23, 2022, 9:17am UTC](https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314/2 "2022-03-23T09:17:49Z")

</div>

Hi @bfontana,

These changes, if performed, must be carefully documented as it might break user code that was previously “working”. That said, @moneta or @couet might provide more useful information on 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:** [March 23, 2022, 9:31am UTC](https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314/3 "2022-03-23T09:31:04Z")

</div>

The help says:

_If the denominator becomes 0 or pass \> total, the corresponding bin is skipped._

It is true that, in the code, the protections against dividing by 0 are done without printing a waning. My guess is that too many warnings might be generated if a such message is printed. Documenting a bit more precisely might help. We can also have a logic which print the warning only once. I let @moneta decide what is the best.

---

<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 23, 2022, 9:46am UTC](https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314/4 "2022-03-23T09:46:08Z")

</div>

Hi,  
I agree with could have the logic to print such a warning the first time the denominator histogram has a bin with zero content. Having an exception as said before will likely break too much existing code. It can be quite common to have empty bins in the histograms.

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![bfontana](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/6bbea6/32.png) [@bfontana](https://root-forum.cern.ch/u/bfontana)\
**Post date:** [March 23, 2022, 10:32am UTC](https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314/6 "2022-03-23T10:32:15Z")

</div>

Another possibility: one could add an enumerator with the following options:

1. (default) whenever the denominator is zero or pass \> total a warning is printed (no backward-compatibility issues)
2. an exception is raised
3. the bins that satisfy the above conditions are set to zero and no exception is raised

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 6, 2022, 10:33am UTC](https://root-forum.cern.ch/t/tgraphasymmerrors-divide-skips-bins/49314/7 "2022-04-06T10:33:10Z")

</div>

Closed on April 6, 2022, 10:33am UTC

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