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

A THStack is a collection of histograms, not a single histogram.

What about summing your histograms and doing the normalisation on the result ?

Dear Couet,

thank you for your answer. Your advice is interesting, but I would like to see the different contribution from the different bkg, and if I sum all the hist in a single histogram, I won’t be able to see the different bkg (in different color for example like in a THStack). Am I wrong?

Regards

Yes you are right.

What about the suggestion given is this old post:

root.cern.ch/root/roottalk/roottalk06/1357.html

Dear Couet,

thank you for the link but I’m not sure what he wants to do here.

- I understood that he want to scale the histo and then add them in a THStack, so at the end I’m not sure how his THStack is normalise.
- Me, I want to:

a) put all the histogram in a THStack, and then normalise the THStack area to 1 (but you said it is not possible).

Or

b) normalise each histo, such that after after I put them in the THStack, the THStack area is 1 (but I’m not sure this makes sense at this point…).

Yes you could do that but have to know to which value each histo should be normalized so the sum will be 1 …

You could also try something like this:

```
// assuming that "MyTHStack" contains TH1F histograms ...
TH1F *h = new TH1F(*((TH1F *)(MyTHStack->GetStack()->Last())));
h->SetNameTitle("h", "my normalized stack");
h->Scale(1./h->Integral("width"));
```

Dear Pepe,

if I normalize independently each TH1 in the stack to 1, and then add them to the stack, the THStack area will not be >1, am I wrong? What I want to do is to add my differents bkg to the THStack and then normalize the THStack area to 1 (or normalize each histo of the hstack such that the THStack area is egal to 1, but I do not want to resolve complex equation…). Do you see a smart way to do that?

Regards

If you just need the “sum histogram”, use my trick (you will get a normalized “copy”).

Otherwise, you will need to scale all “N” contributing histograms independently (for example, in the simplest case, to a value “1./N”).

Dear Pepe,

ok, thank you for your answer.

Regards