Re: How draw histo from directory

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue May 26 1998 - 18:36:44 MEST


Tadeusz,
You have several problems in your macro. See comments inside.

Rene Brun

Tadeusz Pytlos wrote:
> 
> Dear Rooters,
> The TBrowser is a very nice device, but I need to draw a histogram
> from directory in the formal way. I failed trying it in this way
> 
> ....
>    TFile *hfile=new TFile("prob.root");
>    top->cd();
>    plane6->cd();
>    page = new TCanvas("page","Probability",0,0,500,700);
>    page->SetFillColor(10);
>    page->Divide(1,1);
> 
>    Int_t kpad,ans;
>    char padname[20];
> 
>    kpad=0;
> //   sprintf(padname,"page_%d",kpad+1);
> //   TPad *pad = (TPad*)page->GetPrimitive(padname);
> //   pad->cd();
     Note that you do not need all these statements. You can directly do
   page->cd(1);  // now gPad points to the current pad

>    pad->SetGrid();
>    pad->SetLogy();
>    pad->GetFrame()->SetFillColor(42);
>    pad->GetFrame()->SetBorderMode(-1);
>    pad->GetFrame()->SetBorderSize(5);
>    pad->Draw();
> 
>    char hname[20];
>    TH1 *h;
> 
>    sprintf(hname,"h%d",kpad+12);
>    h=(TH1F*)hfile.Get(hname);

You should check here against h=NULL. Very likely hname as encoded
in your sprintf does not exist in the file. CINT correctly generates
the diagnostic below.

>    h.SetLineWidth(2);
>    h.SetLineStyle(1);
>    h.SetLineColor(1);
>    h.SetXTitle("k");
>    h.SetYTitle("N");
>    h.SetMinimum(1e-1);
>    h.Draw();
> ....
> }
> The error was just
> 
> Processing prob1.C...
> Error: illegal pointer to class object h 0x0 321
> FILE:/home/pytlos/usr/kret/stat33/./prob1.C LINE:90
> NULL
> *** Interpreter error recovered ***
> 
> How modify my macro?
> *********************
> 
> Next thing. What wrong with f.pwd()? Example below.

A statement like f.pwd() prints the name of the directory f,
not the name of of subdirectory in f where you may be.
If you want to print the name of your current directory, do
  gDirectory->pwd();


> 
> root [0] TFile *f=new TFile("prob.root")
> root [1] f.ls()
> TFile**         prob.root
>  TFile*         prob.root
>   KEY: TDirectory       top;1   top
> root [2] f.pwd()
> prob.root:/
> root [3] .pwd
> Current directory: prob.root:/
> Current style:     Default
> root [4] top.cd()
> root [5] f.ls()
> TFile**         prob.root
>  TFile*         prob.root
>   TDirectory*           top     top
>    KEY: TDirectory      plane6;1        plane6
>   KEY: TDirectory       top;1   top
> root [6] f.pwd()
> prob.root:/
> root [7] .pwd
> Current directory: prob.root:/top
> Current style:     Default
> root [8] plane6.cd()
> root [9] f.ls()
> TFile**         prob.root
>  TFile*         prob.root
>   TDirectory*           top     top
>    TDirectory*          plane6  plane6
>    ......
>     KEY: TH1S   h12;1   h12
>    KEY: TDirectory      plane6;1        plane6
>   KEY: TDirectory       top;1   top
> root [10] f.pwd()
> prob.root:/
> root [11] .pwd
> Current directory: prob.root:/top/plane6
> Current style:     Default
> root [12]
> 
> Thank in advance,
>               Tadeusz
> 
> --
> Tadeusz Pytlos
> mailto:pytlos@fizwe5.fic.uni.lodz.pl
> Lodz, Poland



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