Combining root canvases

I’ve produced a histogram which I’ve fitted with slightly different functions. Each version has been saved as a separate .root file, that is the canvas was saved via File menu and “Save As”. So each canvas originally had the same name (as it was created with the same macro), and the histogram fitted had the same name.

I now want to display each of the fits in different pads on a single canvas. I’ve written the following macro based on an example found in Locate like command and amended the essai2.C code.

{ TFile f1("Pictures/FitMethods/singleG_expo02.root"); TH1D *h1=f1.Get("singlefit"); TFile f2("Pictures/FitMethods/singleN_expo02.root"); TH1D *h2=f2.Get("singlefit"); TCanvas *can = new TCanvas("DataAccess", "DataAccess"); can->Divide(1,2); can->cd(1); h1->Draw(); can->cd(2); h2->Draw(); }

This results in the f2 histogram, h2, being drawn in the “singlefit” canvas and a blank canvas, DataAccess. Presumably h1 has been drawn and then overwritten by h2. How can I extract the respective histograms, h1 and h2, from their .root file and redraw them in separate pads. Note, I intend to expand this out to read in a histogram from 12 files.


Thank you. The solution was:

[code]{
TFile f1(“Pictures/FitMethods/singleG_expoW.root”,“read”);
//f1->ls();
TCanvas c1 = (TCanvas)f1.Get(“singlefit”);
//c1->GetListOfPrimitives()->ls();
TH1F h1=(TH1F)c1->FindObject(“h_singleG”);
TFile f2(“Pictures/FitMethods/singleG_expo.root”);
TCanvas c2 = (TCanvas)f2.Get(“singlefit”);
TH1F h2=(TH1F)c2->FindObject(“h_singleG”);

TCanvas *can = new TCanvas(“DataAccess”, “DataAccess”);
can->Divide(1,2);
can->cd(1);
can->Draw();
h1->Draw();
can->cd(2);
h2->Draw();
}[/code]