Ploting many 2Dhisto in the same canva

Hi everyone,
I am struggling with a problem that must be quite simple, but unfortunately I don’t know why it doesn’t work. In fact I have a root file which contains 5 histograms that is attached below and I would like to draw them in the same canva in order to do a global fit after that, so I try this:

TFile* f = new TFile("file2.root");
TH1F *h3 = (TH1F*)f->Get("h3");
TH1F *h4 = (TH1F*)f->Get("h4");
TH1F *h5 = (TH1F*)f->Get("h5");
TH1F *h6 = (TH1F*)f->Get("h6");
TH1F *h7 = (TH1F*)f->Get("h7");

Unless getting what I expected I will have only one histo displayed and the stat pad of all the histograms are displayed too. So I would appreciate if someone could help please.
file2.root (20.9 KB)

{ gStyle->SetOptStat(0); gROOT->ForceStyle(kTRUE); // gStyle->SetErrorX(0.0); // 0.5 ... or ... 0.0 TCanvas *c = new TCanvas("c", "c"); c->Divide(1, 2); TFile *f = TFile::Open("file2.root"); // f->ls(); THStack *hs = new THStack("hs", "[hs] of all regions combined"); TProfile *h3; f->GetObject("h3", h3); if (h3) hs->Add(h3); TProfile *h4; f->GetObject("h4", h4); if (h4) hs->Add(h4); TProfile *h5; f->GetObject("h5", h5); if (h5) hs->Add(h5); TProfile *h6; f->GetObject("h6", h6); if (h6) hs->Add(h6); TProfile *h7; f->GetObject("h7", h7); if (h7) hs->Add(h7); c->cd(1); hs->Draw("NOSTACK"); TMultiGraph *mg = new TMultiGraph("mg", "[mg] all regions combined"); // TGraphErrors ... or ... TGraphAsymmErrors if (h3) mg->Add(new TGraphErrors(h3)); if (h4) mg->Add(new TGraphErrors(h4)); if (h5) mg->Add(new TGraphErrors(h5)); if (h6) mg->Add(new TGraphErrors(h6)); if (h7) mg->Add(new TGraphErrors(h7)); if (mg->GetListOfGraphs()) { c->cd(2); mg->Draw("APZ"); // mg->Fit( ... whatever you like ... ); } c->cd(0); }

Thanks Pepe now it looks good :slight_smile:

Hi Pepe,
With the baby code you wrote it works but it doesn’t fit saying that no member named Fit in THStack. I read in root talk someone who had the same error in 2007 and there was an answer of this problem saying that it should be implemented in one months. But it seems it haven’t not yet done!!
is there anyway to do it?

I think that the “in one months” time period estimation from 2007 is still valid. It’s just that this particular very special “month” has not begun yet. I guess it’s one of these “months” which belong “ad Kalendas Graecas”.

See my modified macro, in my previous post here, to get an idea what you could easily try.

yeah Pepe you are right :slight_smile: I gonna test your last script thanks again