TPave::GetX1NDC() returns ridiculous values

Hi all,

Can anyone suggest how to resolve the following:

root [6] TLegend* leg = new TLegend(0.52,0.19,0.88,0.49);
root [7] leg->GetX1NDC()
(const Double_t)2.12199579047120667e-314 <---- Huh??

I am using Root 5.28.00, x86_64.

Thanks!

Alex

I believe you have to first “leg->Draw();” it (i.e. “physically” create it), before you ask about it’s X[12]NDC or Y[12]NDC coordinates.

Hmmm, this seems to work fine in the interpreter. But when I try to define a plotting function, where each call produces a canvas and draws a set of histograms and legend onto it, I get the same silly values as before.

Any other ideas?

Thanks,

Alex

I believe you have to force it to become “physically” drawn. Try:
TLegend* leg = new TLegend(0.52,0.19,0.88,0.49);
leg->Draw();
gPad->Modified(); // or "MyCanvas->Modified();"
gPad->Update(); // or "MyCanvas->Update();"
leg->GetX1NDC()

gPad->Update();
is enough

Yep, that did it.

Thanks again!

Alex

I tend to write:
gPad->Modified(); gPad->Update();
or most often:
MyCanvas->Modified(); MyCanvas->Update();
Could you, please, tell me when can I safely skip the call to “Modified” and when is it necessary?

You can find the answer to your question on slide #29 of this doc:
http://caeinfo.in2p3.fr/root/Formation/en/ROOT_for_beginners_Day2.pdf

Thanks for your reply.
The simple and easy answer offered by this presentation is exactly why I am often using the pair “Modified” + “Update” (in my scripts).
However, from praxis I know that in many cases neither call is needed (even in a script or compiled code) - the changes that I make to objects displayed in a canvas are “automatically” made visible, too.
So, I’m trying to collect more precise informations concerning this issue.