Re: Problem drawing multipads in macro

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Oct 06 1997 - 08:21:09 MEST


David Nitz wrote:
> 
> I'm trying to draw 4 histograms on one canvas in a macro.  The code
> for the macro follows:
> 
> int fom_tag_logr_cuts()
> {
>   gROOT->Reset();
>   TFile f("runfiles/set3.root");
>   c1 = new TCanvas("c1","Figure of Merit Analysis",200,10,800,600);
>   pad1 = new TPad("pad1","Best Tag Cut Before FIR ",0.03,0.52,0.48,0.97,21);
>   pad2 = new TPad("pad2","Best LogR Cut Before FIR ",0.52,0.52,0.97,0.97,21);
>   pad3 = new TPad("pad3","Best Tag Cut After FIR ",0.03,0.03,0.48,0.48,21);
>   pad4 = new TPad("pad4","Best LogR Cut After FIR ",0.52,0.03,0.97,0.48,21);
>   pad1->Draw();
>   pad2->Draw();
>   pad3->Draw();
>   pad4->Draw();
> 
>   pad1->cd();
>   h19.Draw("lego2");
> 
>   pad2->cd();
>   h20.Draw("lego2");
> 
>   pad3->cd();
>   h20019.Draw("lego2");
> 
>   pad4->cd();
>   h20020.Draw("lego2");
> 
>   c1->Update();
>   return 0;
> }
> 
> What happens is that the pads are drawn, the histograms appear briefly
> with their titles, then the histograms disappear, leaving me with blank
> pads, except for the histogram titles, which remain.  I running  root
> v1.02/00 on HP-UX 10.20.
> 

In your macro above replace the statement
   TFile f(...
by
   TFile *f = new TFile(...

What happens with your macro is the following.
When you leave the scope of your function, all objects created in this
function are automatically deleted. The TFile destructor is called.
All objects supported by the TFile object f are also deleted
(histograms).
If you go via TFile *f = new TFile, only the pointer f is deleted
when you leave the scope, not the object pointed by f.
Another way to make your macro working would be to delete the first
statement int fom_tag_logr_cuts. In this case, all objects and variables
created in the macro will be in the global scope and still accessible
when the macro has executed.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:21 MET