Re: getting values from a TTree

From: Roger Mason <rmason_at_esd.mun.ca>
Date: Sat, 4 Oct 2008 11:01:14 -0230


Hi Philippe,

Philippe Canal <pcanal_at_fnal.gov> writes:

>> I'm trying to read values (energy) from a branch of a TTree into an
>> array ( e[i] = (Double_t*)*b_energy->GetEntry(i); ) in the code below:

[snip]

> Why? You are already getting the value via the variable 'energy'. So
> I am guessing
> you simply meant:
>
> e[i] = energy;

Thank you! I stole the code from one of the TTree tutorials and _thought_ I understood it, but evidently I did not.

> PS. e[i] = (Double_t*)...; is a syntax error since you declare e to
> be an array
> of double and hence this is assigning a pointer to a double to
> variable of type double
> (i.e. 2 incompatible types).

> PPS. GetEntry returns the number bytes read from the TTree and _not_
> the value of
> the data. So if you actually tried *(Double_t*)...GetEntry(), you are
> then dereferencing
> essentially a random pointer
>
> PPPS. Rather than (which does indeed work)
>
> TFile *f = new TFile("Ca2Mn46d.topaz.20080506.160756.root");
> TTree *tr = (TTree*)f->Get("t");
> TBranch *b_energy = tr->GetBranch("energy");
> b_energy->SetAddress(&energy);
>
> I recommend:
>
> TFile *f = new TFile("Ca2Mn46d.topaz.20080506.160756.root");
> if (!f || f->IsZombie()) return;
> TTree *tr; f->GetObject("t",tr);
> if (!tr) return;
> TBranch *b_energy;
> tr->SetBranchAddress("energy",&energy,b_energy);

Again, thank you. It has been several months since I wrote any C++ and evidently my skills have not improved in the interrim.

Best wishes,
Roger Received on Sat Oct 04 2008 - 15:37:08 CEST

This archive was generated by hypermail 2.2.0 : Mon Oct 06 2008 - 11:50:02 CEST