Multiple Canvas


TCanvas *c2 = new TCanvas("c2","c2",400,100,520,400); TCanvas *c3 = new TCanvas("c3","c3",350,150,520,400); TCanvas *c4 = new TCanvas("c4","c4",300,200,520,400);

I define many canvas like above and put TH1F into them like below;

[code] TFile *aHOa = new TFile(“RootFile.root”);

TH1F aH1 = (TH1F)aHOa->Get(“Jets”);
TH1F aH2 = (TH1F)aHOa->Get(“JetEnergy”);
TH1F aH3 = (TH1F)aHOa->Get(“JetPt”);


Actually, what I have done is more complicated than this one. So I want to use arrays or something like that to write my macro shorter.

What is the shortest way to define many canvas and put all the plots in a root file into them one by one ?

Thanks a lot


Maybe the last sentence is not clear enough . All my problem is ;

For example, I have 10 histograms in a root file. I want to plot all of them in different canvases by using a macro. Now I do this job by defining ten different canvas. But I think there must be a way to define n canvas (n: natural number) even I couldn’t find yet.

Thanks in advance


You can do something like;

{ const Int_t nhist=10; char *hnames[nhist] = {"Jets","JetsEnergy",...}; TFile *aHOa = new TFile("RootFile.root"); TH1 *hist[nhist]; TCanvas *c[nhist]; for (Int_t i=0;i<nhist;i++) { hist[i] = (TH1*)aH0a->Get(names[i]); c[i] = new TCanvas(Form("c%d",i)); hist[i]->Draw(); } }


Hi Rene,

It is really very short. Thanks a lot !