TLatex::GetXsize()

Hi,

I have a problem with getting the right size for a label which I want to draw. The goal is to create the label and then move it to the right position taking account for the size of the label.

So I started to write a script:

[code]TLatex * test_function (TH2D * img) {

img->Draw(“colz”);

TLatex * label = new TLatex ( 10, 10, “asdf” );

cout << "GetXsize() = " << label->GetXsize() << endl;

return label;
}[/code]

and when I call the function, the following happens:

root [2] label = test_function(data_histo) Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 GetXsize() = 0.066092 (class TLatex*)0x30d5cc0 root [3] label->GetXsize() (Double_t)1.04260059024860382e+02

I am confused, I don’t understand the return value of GetXsize(): in the documentation it says, GetXsize() would return the size in pad coordinates. However, there is only one pad involved here, why do I get two different results? And moreover, the result in the script is obviously wrong - 0.07 would be invisible…

Can anyone help here? Thanks a lot in advance!

Seems to me it works fine. I have drawn a text on hpxpy from hsimple.C.
Then grow it interactively. And I get:

root [0] hpxpy->Draw("colz")
root [1] TLatex * label = new TLatex ( 2, -3, "asdf" );
root [2] label->GetXsize()
(Double_t)6.46551733772303017e-01
root [3] label->Draw()
root [4] label->GetXsize()
(Double_t)6.46551733772303017e-01

..... enlarge the text with the mouse

root [5] label->GetXsize()
(Double_t)2.25574716005003539e+00

Yes, that works for me, too.

I found the solution (thanks for the hint with hsimple.C): in order to get the coordinates right one has to call

canvas->Modified(); canvas->Update();

AFTER drawing the graph/hisogram and BEFORE defining the TLatex. Then the coordinate system works. Interactive mode seems to do it automatically while scripts obviously don’t… goot to know!