Re: [ROOT] TNtuple reading

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Aug 07 2001 - 09:40:57 MEST


Hi Tommaso,

Variables in a TNtuple are of type Float_t not Double_t.
You have two other problems in your script
 - never use gROOT->Reset() in a named macro
 - the loop index starts at 0, not 1

You have 3 ways (at least) to check the content of your ntuple.
 - using teh browser, double click on your variable "p"
 - use nf->Show(ki) to dump the values of entry ki
 - use nf->Scan();

Rene Brun

Tommaso Chiarusi wrote:
> 
> Hello rooters,
> 
> According to the userguide, I wrote the following:
> Note:
> 1. "vario.root" is the root file in which I have stored my ntuple.
> 2. "front" is the name of my ntuple (in "vario.root" there are many
> other ntuples!).
> 3. "p" is the variable that I want to plot. ("p" is either the name of
> the TLeaf inside the ntuple "front" and of the variable the histogram I
> fill with)
> 
> The problem I get is that I actually do NOT Get the Entry value, but
> something like 5.30784e-315!!!!!
> 
> Thank you very much!
> 
> void plot()
> {
> gROOT->Reset();
> 
>  TFile *f = new TFile("vario.root");
>  TNtuple *nf = (TNtuple*)f->Get("front");
> 
> 
>  Int_t entries = (Int_t)nf->GetEntries();
>  cout<<"Number of Entries: "<<entries<< endl;
> 
> 
>  Double_t p=0;
>  nf->SetBranchAddress("p",&p);
> 
>  TH1F *htp = new TH1F("htp","p",100,0,10);
> 
> for (Int_t ki=1;ki<entries;ki++)
> {
>   nf->GetEntry(ki);
>   htp->Fill(p);
> }
> 
> TCanvas *c1 = new TCanvas("c1", "c1",515,210,540,376);
> c1->Draw();
> htp->Draw();
> 
> //
> }
> 
> Tommaso



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