How to deal with THStack?

Hi,

I try to use THStack class to deal with several TH1F but I don’t understand some points…

when I first draw a TH1F and then want to plot the THStack in the same pad, THStack isn’t drawn (whereas single TH1F is). I do :
hd->Draw(“e1p”); //TH1F* hd
hstack->Draw(“samenostack”); // THStack* hstack

when I modify the range of all the TH1F composing the THStack, modification isn’t taken into account when drawing THStack. I do :
hd->SetAxisRange(4, 30); (for all TH1F composing THStack)
hstack->Draw(“nostack”)
If I plot a single TH1F, modification is taken into account.

So I’d appreciate if anyone could help me understanding what I do wrong.

Thanks,

Vincent

Here is an example hopefully answering your first question:

{
  TCanvas *c1 = new TCanvas("c1","c1",800,600);
                                                                                
  TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
  h1->FillRandom("gaus",10000);
                                                                                
  TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
  h2->FillRandom("gaus",20000);
                                                                                
  TH1F *h3 = new TH1F("h3","Histo 3",100,-5,5);
  h3->FillRandom("gaus",5000);
                                                                                
  h1->SetFillStyle(3004);
  h1->SetFillColor(1);
  h2->SetFillStyle(3005);
  h2->SetFillColor(1);
  h3->SetFillStyle(3006);
  h3->SetFillColor(1);
                                                                                
  THStack *hs = new THStack("hs","A stack of histograms");
  hs->Add(h1);
  hs->Add(h2);
                                                                                
  hs->Draw("nostack");
  h3->Draw("e1 same");
}

Hi,

thanks for your reply but my problem was to draw first a reference histogram and then the THStack and it seems I can’t use “same” option to draw THStack.
Nevertheless, I managed to do what I needed using THStack::GetXaxis()::SetLimits(xmin, xmax)

thanks again for your reply,

Vincent