Hello,
I am trying to plot multiple (~20) histograms with the same name, from the same .root file, onto one plot.
In my case, I have .root file, with ~20 histograms, each of the same name (myhist;1 myhist;2 myhist;3…)
and all the same title (myhist).
Here is [some parts pseudo-]code of what I am doing:
TFile *f=new TFile("myfile.root");
TCanvas *c1=new TCanvas("c1","c1",800,800);
bool setupComplete(false);
for (int i(1);i<=20;++i){
TH1F* h;
h = (TH1F*) f->Get("myhist;i"); //pseudocode, I call a little function which returns the char* properly e.g. "myhist;1"
if (!h){
std::cout<<"Error: histogram not found"<<std::endl;
continue;
}
if (!setupComplete) { h->Draw(); setupComplete=true; }
else h->Draw("SAME");
}
So I want to draw all of these histograms on the same plot, adding one at a time. All the histograms have the same # of entries, same binning, same boundaries. What I get back I have attached as canvas.png, obviously not what I was going for.
I have tried similar loops where the histograms all have different names (myhist1;1 myhist2;1 myhist3;1) and that seems to work fine, so I think the problem is with the shared name.
I can also print out info from the histogram, statistical quantities like the mean, etc., so it appears to be reading the histograms from the file perfectly fine.
If I print out the value of h (the address in memory), it is always the same for all the histograms. I am not sure how to interpret this…
Any help would be greatly appreciated. Thank you.