# Dividing Histograms - Output seems wrong

**URL:** <https://root-forum.cern.ch/t/dividing-histograms-output-seems-wrong/42342>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [November 17, 2020, 6:53pm UTC](https://root-forum.cern.ch/t/dividing-histograms-output-seems-wrong/42342 "2020-11-17T18:53:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfrancis](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jfrancis](https://root-forum.cern.ch/u/jfrancis)\
**Post date:** [November 17, 2020, 6:53pm UTC](https://root-forum.cern.ch/t/dividing-histograms-output-seems-wrong/42342/1 "2020-11-17T18:53:23Z")

</div>

I’m trying to divide two histograms, “top” by “bottom”, to produce a third histogram, “Forward-Backward Asymmetry…”. However, checking individual bins shows a discrepancy between the third histogram and what the division output should be. For example, in the images provided, dividing bin 8 in “top” by bin 8 in “bottom” should result in about 0.15, however, the value of bin 8 in “Forward…” is about 0.6. Furthermore, this only seems to be an issue when inputting particle event data, and not Monte Carlo simulations.

I have included some of my code below.

bottom-\>Add(h\_lep\_cos\_decang\_pos,h\_lep\_cos\_decang\_neg);  
flip-\>Add(h\_lep\_cos\_decang\_neg,-1);  
top-\>Add(h\_lep\_cos\_decang\_pos,flip);  
TH1F _clone = (TH1F_)top-\>Clone(“clone”);  
top-\>Divide(bottom);  
h\_lep\_cos\_w-\>Add(top);

h\_lep\_cos\_decang\_pos and h\_lep\_cos\_decang\_neg are both TH1F\* objects. Am I perhaps misunderstanding the Add/Divide functions, or is there an error in the code that I am missing?

Edit: Posted the running code  
[Analysis.C](https://root-forum.cern.ch/uploads/short-url/xT38uNmURc7gYiBNuyUtH29PAeV.C) (7.0 KB) [Analysis.h](https://root-forum.cern.ch/uploads/short-url/2HpgW7qdIVjoMi4k12cJbdo0sFg.h) (575 Bytes) [CLoop.C](https://root-forum.cern.ch/uploads/short-url/n7kruLAcXJ9kiykQnORT9u3c4OA.C) (2.6 KB) [CLoop.h](https://root-forum.cern.ch/uploads/short-url/fSnGCBeIpkB6MHugfm7SBHLyGt2.h) (17.4 KB)

 ![2lep_1_1.5_120_140_asymmetry](https://root-forum.cern.ch/uploads/default/original/3X/1/6/16887378149643994849eefed7fb468bf690d244.png)  
 ![2lep_1_1.5_120_140_bottom](https://root-forum.cern.ch/uploads/default/original/3X/c/a/ca03e3354305d76b84fd505683952767dbf3af16.png)  
 ![2lep_1_1.5_120_140_top](https://root-forum.cern.ch/uploads/default/original/3X/7/2/72941366b1033a2f061e1e1b1122b6ea3a148b2f.png)

---

<div class="post-metadata">

**Author:** ![jfrancis](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jfrancis](https://root-forum.cern.ch/u/jfrancis)\
**Post date:** [November 17, 2020, 6:57pm UTC](https://root-forum.cern.ch/t/dividing-histograms-output-seems-wrong/42342/2 "2020-11-17T18:57:02Z")

</div>

There is a mistake in the code. There should be an asterisk after each of the TH1Fs.

---

<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:** [November 18, 2020, 9:37am UTC](https://root-forum.cern.ch/t/dividing-histograms-output-seems-wrong/42342/3 "2020-11-18T09:37:48Z")

</div>

Please post the running code and attach to the post or included in pre-formatted text

---

<div class="post-metadata">

**Author:** ![jfrancis](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jfrancis](https://root-forum.cern.ch/u/jfrancis)\
**Post date:** [November 18, 2020, 2:31pm UTC](https://root-forum.cern.ch/t/dividing-histograms-output-seems-wrong/42342/4 "2020-11-18T14:31:19Z")

</div>

I have attached it to the post, please let me know if you have trouble accessing the files.
