Execution in wrong order

Hello,
I used the following code from the ROOTPrimer.pdf introduction in the interactive interpreter. [http://root.cern.ch/root/htmldoc/guides/primer/ROOTPrimer.pdf]

TH2F bidi_h("bidi_h","2D Histo;Gaussian Vals;Exp. Vals",
30,-5,5, // X axis
30,0,10); // Y axis

TRandom3 rgen;

for (int i=0;i<500000;i++) {bidi_h.Fill(rgen.Gaus(0,2),10-rgen.Exp(4),.1);}

auto c=new TCanvas("Canvas","Canvas",800,800);
c->Divide(2,2);
c->cd(1);bidi_h.DrawClone("Cont1");

The output of this is not as expected.
The “bidi_h.DrawClone(“Cont1”);” seems to be executed before the “c->Divide(2,2);” although the Divide is entered one line before. Alternatively it is possible that “c->cd(1);” could be executed after “bidi_h.DrawClone(“Cont1”);”.

This strange behavior doesn’t occur if I use:

c->cd(1);
bidi_h.DrawClone(“Cont1”);

instead of:

c->cd(1);bidi_h.DrawClone(“Cont1”);

This strange behavior also doesn’t occur if I use “Draw” instead of “DrawClone”.

Why does ROOT behave this way? Why seems the line before being executed after the next line?

Hi,

Which ROOT version? which platform? which compiler?

Cheers, Bertrand.

OK, I can reproduce the issue. Our graphics expert, @couet, will take care of it once he gets back. For the time being, just keep it on two lines:

c->cd(1);
bidi_h.DrawClone(“Cont1”);

Cheers, Bertrand.

ROOT 6.10/02
Built for macosx64

using the interactive interpreter

Actually I see it even with the commands on 2 lines. I will check. Using Draw instead is fine …

In the Cocoa case the Selected Pad behaves is set whereas it is not in the X11 one. If you really need to use DrawClone a workaround would be:

{
   auto h2 = new TH2F("h2","2D Histo;Gaussian Vals;Exp. Vals", 30,-5,5, 30,0,10);
   TRandom3 rgen;
   for (int i=0;i<500000;i++) h2->Fill(rgen.Gaus(0,2),10-rgen.Exp(4),.1);
   auto c=new TCanvas("Canvas","Canvas",800,800);
   c->Divide(2,2);
   gROOT->SetSelectedPad(c->cd(1));
   h2->DrawClone("Cont1");
}

That’s not satisfactory but I found no obvious (not having side effects) fix until now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.