Selecting variable pads not working; minimal example reprodu

Dear ROOT experts,

Using root 5.12/00a (same however in root 5.14/00) I have the next problem:

I divide a canvas in a variable number of pads. Then in a loop I want to select a certain pad, but this does not work, the main canvas stays selected with the result that all histograms are drawn in the main canvas, totally neglecting my wish for pads.

Does anyone know a solution to this problem?

Many thanks in advance,

Ytsen.

PS. Example below reproduces the problem. The desired output would be a canvas, split in 10 pads (vertically allocated) and all histos cosths0 to cosths9 in the respective pads …

{

gROOT->Reset();

const Int_t binsTHETA = 10;

TH1F hncosths[binsTHETA];

for (Int_t i = 0; i < binsTHETA; ++i) {
TString scosths;
scosths.Form(“hcosths%i”, i);
hncosths[i] = TH1F(scosths, scosths, 10, -1, 1);
};

TCanvas cArray(“cArray”,“cArray”,0,0,1000, 800);
cArray.Divide(1, binsTHETA);
for (Int_t i = 0; i < binsTHETA; ++i) {
cArray.cd(i);
hncosths[i].DrawClone();
};

};

Hi Ytsen,
you forgot update current pad. for (Int_t i = 0; i < binsTHETA; ++i) { cArray.cd(i); // i+1 !!! gPad->Update(); hncosths[i].DrawClone(); }
Jan

Thanks! Because of your reply I found what really was wrong. The cd(i) started with i = 0 and that somehow messed it all up.

It works great with:

TCanvas cArray(“cArray”,“cArray”,0,0,1000, 800);
cArray.Divide(1, binsTHETA);
for (Int_t i = 0; i < binsTHETA; ++i) {
cArray.cd(i+1);
hncosths[i].DrawClone();
};

(Note the “i+1” as argument in TPad::cd()!).

Cheers,

Ytsen.