Scaling histograms before stacking them with option "nostackb" removes the bins width and colors

Hello,
I am stacking 3 non-normalized histograms and assign each of them colors. The result is what I am looking for; visible bins with the respective color. Now, whenever I try to scale each histograms before integrating them to the THStack, the resulting plot loses the color and also plots crosses instead of bins. In other words, there are no more rectangular bins but only crosses with the same blue across every histograms. What do I don’t understand about this behaviour?

Here is some code to generate the results:
`
TH1F h1(“H”, “Bleu”, bin_width, bin_min, bin_max), h2(“H”, “Green”, bin_width, bin_min, bin_max),
h3(“H”, “Red”, bin_width, bin_min, bin_max);

// Fill the histograms

// Scaling (this step is problematic when I introduce it, the plot is different and
// there are not color differences (every crosses are the same blue across all histograms)
h1.Scale(1/h1.Integral());
h2.Scale(1/h2.Integral());
h3.Scale(1/h3.Integral());

// Assign color
h1.SetFillColor(kBlue);
h2.SetFillColor(kGreen);
h3.SetFillColor(kRed);

THStack hs(“hs”,“Bleu”);
hs->Add(h1);
hs->Add(h2)
hs->Add(h3);

hs->Draw(“nostackb”);

Thank you in advance for your help.
`

ROOT Version: 6.26/06
Platform: Windows 10
Compiler: MSVC 17

@couet can you have a look? Thanks!

A simple “fix” … after “histo.Scale(...);” execute “histo.Sumw2(0);”`

1 Like

… or add the histograms in the stack with the option “HIST”.

and BTW, Welcome to the ROOT forum :wink:

Or draw the stack with the option “hist”:

hs->Draw("nostackb, hist");

But using “hist” when adding them to hs, you can control each one:

hs->Add(h1,"hist");
hs->Add(h2);   // if you don't want lines/bars for this one
hs->Add(h3,"hist");
hs->Draw("nostackb");
1 Like

Thank you, it also works like this. But I think the preferred solution is when adding the “hist” to the Add method of THStack.

1 Like

Thank you for the answer and for this handy library.