Write THStack with weights

Hi everyone,

I’m trying to create a stack of histograms and save it in a file, but I want to stack histograms with weight.

If I fill hist using (e.g.):


And then I stack them in a THStack object, there are no problem. If i fill them using something like:


And I try to stuck them, the histo are not colored. I found similar problem, and you solved using:


And I see that it works. What if I want to save it in a file? I tried to use Write(“hist”), but it doesn’t work and I cannot find another way… Can you help me?


Can you provide a minimal reproducer of the problem?

G Ganis

I have a vector of signal, that I’ll call:

vector<TH1F*> hist_signal;

I have two kind of backgrounds, for semplicity:

TH1F *back1;
TH1F *back2;

I wrote several long routine in which i Fill this histograms with the method above:


And the same for the others, and the signal.
Now I want to write a function that creates a vector of stack, and write that vector on a file. I’m using something like:

vector<THStack*> hist_stack;
TFile out_stack("stack_vector.root","recreate");        

    for(unsigned int i=0;i<hist_stack->size();i++) {

The results is a non-colored stack in which I can’t recognize signal from background. If I don’t use method Fill(x,weight), but only Fill(x) I obtain the usual colored stack.
I found that if I want to see the stack with color (using Fill(x,w)) I have to use Draw(“hist”), but I want to Write on file, because this is a long vector.
Until now I create a canvas with Draw and save it in a file, but it’s not a very usefull solution. There is a way to save on file colored THStack filled with Fill(x,w)?
Thank you

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