THStack for lego plots?

I would like to stack lego plots to make the faint source I am looking at stand out on top of the background from other nearby sources.

I tried using THStack to do this

root [2] c->Draw(“b:l>>all(50,0,30,50,-10,10)”,lb);
: created default TCanvas with name c1
root [3] c->Draw(“b:l>>ls(50,0,30,50,-10,10)”,lb&&“mc_src_id==1”);
root [5] THStack* hs = new THStack(“hs”,“stacks”);
root [6] hs->Add(all);
root [7] ls->SetFillColor(kRed);
root [8] hs.Draw(“lego”);
root [9] hs.Draw(“lego”);
root [10] hs->Add(ls);
root [11] hs.Draw(“lego”);

I’ve attached the lego plot. Is there something I missed?

Thanks,

Richard

The lego plot is badly drawn and the ls histogram does not get coloured - I don’t know how to set the colour

I do not completly understand what you would like to achieve. Can you send a small running example showing what you are doing, and what you think is going wrong ?

Hi Olivier,

Do you mean to send the input data file and the definition of the source cuts? But in words, I wanted the faint source to sit on top of the background and be coloured differently. Of course this works great in the manual for 1-d plots.

The only missing code is the opening of the file and the definition of the source and background cuts. 175 events survive the source cut. But notice that the lego plot looks weird - that is exactly how it appeared in the canvas - no stretching effects etc in display.

Richard

Hi Richard,

I do not understand how you can get this plot with the few lines you sent. You draw many times “hs” … there is some red involved … I see no red … so that’s why I ask for a small running example which reproduces your problem … I do not want all your data … just a small running example

My bad. Lines 8 & 9 should have been erased. I had forgotten to add the source plot. Then did so and remade the plot with both plots stacked. Sorry!

Richard

Ok … so please send me something running I can work on. So I will be able to help you more efficiently.

This reproduces the same plot I sent before:

root [0] .x openLS5039-10.C
root [1] .x LScut.C
root [2] THStack* hs = new THStack(“hs”,“stacks”);
root [3] c->Draw(“b:l>>ls(50,0,30,50,-10,10)”,lb&&“mc_src_id==1”);
: created default TCanvas with name c1
root [4] c->Draw(“b:l>>all(50,0,30,50,-10,10)”,lb);
root [5] hs->Add(all);
root [6] hs->Add(ls);
root [7] hs->Draw(“lego”);

where openLS just opens the data file and LScut defines the source region cut lb.

Richard

Richard,

Nowhere you set the colors for your histograms.
Could you send teh THstack object in a ROOT file and post it
TFile f(“stack.root”,“recreate”);
hs->Write();

and post stack.root

Rene

Sigh. The price for doing this during collaboration meeting talks :slight_smile:

root [0] .x openLS5039-10.C
root [1] .x LScut.C
root [2] THStack* hs = new THStack(“hs”,“stacks”);
root [3] c->Draw(“b:l>>ls(50,0,30,50,-10,10)”,lb&&“mc_src_id==1”);
: created default TCanvas with name c1
root [4] c->Draw(“b:l>>all(50,0,30,50,-10,10)”,lb);
root [5] hs->Add(all);
root [6] hs->Add(ls);
root [7] ls->SetFillColor(kRed);
root [8] hs->Draw(“lego”);
root [9] TFile h(“stack.root”,“RECREATE”);
root [10] hs->Write();
root [11] h->Close();
stack.root (5.38 KB)

Ok I tried your example.
I think you should just set a color for the histogram “all” and the stack will look ok.

Richard,

You should set a FillColor for your histogram "all"
For example try
all->SetFillColor(7);

and then Draw your stack with option “lego1” instead of just “lego”

Rene

That did it! Thanks, Rene and Olivier!

Richard