Re: [ROOT] Two new-user questions regarding tutorial h1draw.C

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri May 19 2000 - 11:10:19 MEST


Hi Charlie,

Charlie Maguire wrote:
> 
> Dear all,
> 
>         A couple of new-user questions regarding the
> introductory tutorial h1draw.C.
> 
>         First, I change the following third pad lines
> 
>    hpx->Draw("e1p");
>    label3 = new TPaveLabel(2,600,3.5,650,"option e1p");
>    label3->SetFillColor(42);
>    //
>    // The following illustrates how to add comments using a PaveText.
> 
> to add a simple text
> 
>    hpx->Draw("e1p");
>    label3 = new TPaveLabel(2,600,3.5,650,"option e1p");
>    label3->SetFillColor(42);
>    TText *text = new TText(2.,300.,"Test");
>    text->Draw();
>    label3->Draw();
>    //
>    // The following illustrates how to add comments using a PaveText.
> 
> This works fine.  However, if I use the mouse to click on SetLogy, then
> the added text disappears.  The same thing happens directly on a canvas.
> This all came up when I tried to add text on semi-log plots, after having
> been able to add text easily enough on linear-linear plots.

The low level primitives such as TText, TPolyLine, markers are drawn in the
current user coordinate system. They do not know about log scales. Only high
level
primitives such as TGraph, TH1 are able to switch on the same picture
between lin/log scales. For objects like text, paves, you can draw in
the Normalized Device Coordinate system NDC [0,1] to be totally independent
of the user coordinates range and/OR system.
If you have a TText object t, you can call t.SetNDC() and create this object
or draw it(via DrawText) with coordinates in the range [0,1].

> 
>         Second question.  If I add a "void h1draw()" line to the original
> version of h1draw.C, and then give the command ".x h1draw.C" all works
> fine for the top 2 plots, but the data points in the bottom plot
> flash by instantaneously and disappear.  Only the text remains.  As it
> happens, I am used to adding defaulted parameters in the macro call,
> and would like to know the explanation of the different results.
>

This question was already answered. It is a C++ scoping question.
If a macro is unnamed {...}, then all variables/objects created in the macro
are still visible after executing the macro, like if you had typed each
statement
at the command line.
 In case of a named macro, the normal C++ scoping rules apply. Objects on the
stack
will be automatically deleted. For example if you had something like:
   TH1F h1("h1",.....
   h1.Draw();
the histogram in the pad will disappear when the macro has executed.
If you had instead objects in the heap, like
   TH1F *h1 = new TH1F("h1",...
   h1->Draw();
the object h1 will still be in the pad.

Rene Brun
>         I am running ROOT2.23/12 on an SGI/IRIX6.5 .  The same behavior
> also occurs running the same ROOT version on an RH6.1 platform.
> 
> Thanks,
> Charlie Maguire



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:25 MET