TStack Y axis problem

Hello,

I’ve written a code to compare data and background using “HStack”,

[code]void BG_Macro() {

TFile* fgg = new TFile(“file:background_gg2zz_13TeV_.root”);
TFile* fzz = new TFile(“file:background_qqbar2zz_13TeV_.root”);
TFile* fdata1 = new TFile(“file:data_500GeV_13TeV_.root”);

TH1D h_gg = (TH1D)fgg->Get(“myHisto1”);
TH1D h_zz = (TH1D)fzz->Get(“myHisto1”);
TH1D h_data1 = (TH1D)fdata1->Get(“myHisto1”);

TCanvas *c1 = new TCanvas(“c1”, “c1”, 0, 0, 700, 500);
c1->cd();
gPad->SetLogy();
THStack *hs = new THStack(“hs”, NULL);
hs->Add(h_gg);
hs->Add(h_zz);
hs->Draw();
h_data1->Draw(“same”);
}
[/code]

but I can’t change the Y axis range, and I don’t know what is the problem

Hi,

the solution is to use the methods SetMaximum and SetMinimum of the THStack. A mock of your case:

  auto h_gg = new TH1F("hgg","",64,-4,4);
  auto h_zz = new TH1F("hzz","",64,-4,4);
  auto h_data1 = new TH1F("hdata1","",64,-4,4);

  for (auto&& h : {h_gg,h_zz,h_data1}) h->FillRandom("gaus");

  auto c1 = new TCanvas("c1", "c1", 0, 0, 700, 500);
  c1->cd();
  c1->SetLogy();
  auto hs =  new THStack("hs", NULL);
  hs->Add(h_gg);
  hs->Add(h_zz);
  hs->Draw();
  h_data1->Draw("same");
  hs->SetMaximum(100);
  hs->SetMinimum(10);

Cheers,
Danilo

Thank You so much, that solved my problem :slight_smile: