Re: [ROOT] Execution of macro.

From: Pasha Murat (630)840-8237@169G ((630)840-8237@169G)
Date: Sat Apr 14 2001 - 00:59:15 MEST


hi Maurik, your histogram, defined as a local variable inside the function,
gets deleted when the execution leaves this function. You can do

	TH2F* Grid = new TH2F ...

instead... -best, Pasha

Maurik Holtrop wrote:
> 
> Dear Root,
> 
> I am slightly puzzled by a little macro. When I execute the lines one by one
> from the command line, all is well, when I wrap them in a macro, load it,
> and execute them as a function, I don't get the axes of the (empty) 2D
> histogram. See code below. What is wrong here?
> 
> It seems that when the histogram is defined as TH2F Grid(...) it does not
> work, while TH2F *Grid=new TH2F(...) does.
> While you may argue the second is better, the first should work. It does
> when typed into the commandline one by one.
> 
> Cheers,
> 
>     Maurik
> 
> --------------- Do_It.C -----------------------
> void Do_It(void){
> 
>   TCanvas *c1 = new TCanvas("c1","E2 Target Momentum Loss",10,10,700,750);
>   c1->SetFillColor(42);
>   c1->SetGridx();
>   c1->SetGridy();
>   c1->GetFrame()->SetFillColor(21);
>   c1->GetFrame()->SetBorderSize(12);
> 
>   TPad *pad = new TPad("pad","E2CellsGraph",0.03,0.03,0.97,0.97,21);
> 
>   pad->Draw();
>   pad->cd();
> 
>   // OK:  TH2F *Grid=new TH2F("Grid","Comparison of Momentum Loss Curves for
> E2 Targets",100,0.,4.,100,0.0,12.);
> 
>   TH2F Grid("Grid","Comparison of Momentum Loss Curves for E2
> Targets",100,0.,4.,100,0.0,12.);
> 
>   gStyle->SetOptStat(0);
> 
>   pad->SetGridx();
>   pad->SetGridy();
>   // OK: Grid->Draw();
>   Grid.Draw();
>   pad->Modified();
> 
>   Int_t n1 = 10;
>   Float_t x1[]  = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
>   Float_t y1[]  = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
>   Float_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
>   Float_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
>   gr1 = new TGraphErrors(n1,x1,y1,ex1,ey1);
>   gr1->SetMarkerColor(kBlue);
>   gr1->SetMarkerStyle(21);
>   gr1->Draw("LP");
>   pad->Modified();
> }



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:41 MET