# Normalize each bin of THStack histogram?

**URL:** <https://root-forum.cern.ch/t/normalize-each-bin-of-thstack-histogram/39073>\
**Category:** ROOT\
**Created:** [April 24, 2020, 2:52pm UTC](https://root-forum.cern.ch/t/normalize-each-bin-of-thstack-histogram/39073 "2020-04-24T14:52:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alkass](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@Alkass](https://root-forum.cern.ch/u/Alkass)\
**Post date:** [April 24, 2020, 2:52pm UTC](https://root-forum.cern.ch/t/normalize-each-bin-of-thstack-histogram/39073/1 "2020-04-24T14:52:27Z")

</div>

Hello

It may sound naive, but is there a ROOT method to normalize each bin of a THStack, ie something that would look like the pic I attach ?

[Screen Shot 2020-04-24 at 16.47.19.pdf](https://root-forum.cern.ch/uploads/short-url/kaA7D0fgfMEJzWEslkn77GMooey.pdf) (57.3 KB)

---

<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:** [April 24, 2020, 3:02pm UTC](https://root-forum.cern.ch/t/normalize-each-bin-of-thstack-histogram/39073/2 "2020-04-24T15:02:41Z")

</div>

There is a discussion about this on the forum. Here:

> [@Normalize THSatck](https://root-forum.cern.ch/t/normalize-thsatck/21807):
>
> Dear expert, I want to normalize a THStack such that the integral is equal to 1. For the TH1 I used to do: h-\>Scale(1/h-\>Integral(“width”)); but the the Scale() or even Integral() are not a member of THStack. Is there a smart way to do that? Regards

It might help you.

---

<div class="post-metadata">

**Author:** ![Alkass](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@Alkass](https://root-forum.cern.ch/u/Alkass)\
**Post date:** [April 24, 2020, 4:06pm UTC](https://root-forum.cern.ch/t/normalize-each-bin-of-thstack-histogram/39073/3 "2020-04-24T16:06:19Z")

</div>

So effectively, you add to the THStack each histo once you normalize it and presumably that should give a THStack which should be normalized to (1/N) where N=amount of histograms.

The problem with this, is that THStack does not have a scale funtion, so it is not possible to normalize the sumed histo the way I want it, i.e. basically to normalize each one of the bins to 1…

---

<div class="post-metadata">

**Author:** ![RongkunWang](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rongkunwang/32/36036_2.png) [@RongkunWang](https://root-forum.cern.ch/u/RongkunWang)\
**Post date:** [April 26, 2020, 7:12pm UTC](https://root-forum.cern.ch/t/normalize-each-bin-of-thstack-histogram/39073/4 "2020-04-26T19:12:55Z")

</div>

You have to add all histograms up, and use that to normalize, not use each single histogram’s area to normalize. You could always have one loop before hand to calculate this integral up “manually”, and scale for each input.

---

<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:** [May 10, 2020, 7:12pm UTC](https://root-forum.cern.ch/t/normalize-each-bin-of-thstack-histogram/39073/5 "2020-05-10T19:12:59Z")

</div>

Closed on May 10, 2020, 7:12pm UTC

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