Help: direct access to contents of a TTree?

dear ROOT-experts

I’m a newbye and need some help.

I have a data file data1.root which include a TTree

root [0] TFile *myfroot = new TFile(“data1.root”, “READ”);
root [1] TTree mytree2 = (TTree)myfroot->Get(“liveTime”);

I can print the content with a Scan() and see the tree has 201 rows.

root [2] mytree2->Scan();


  • Row * Instance * run * dummy1 * live * dummy2 * dummy3 *

  •    0 *        0 *         1 *        28 *       916 *         1 *         0 *
    
  •    0 *        1 *         1 *        28 *       916 *         2 *         0 *
    

[…]

I’d like to loop over the rows and put the contents of the branch “live”
(5th column in the table above) into a double.

something like

for (int n=1; nGetEntries(); n++)
{
double x=mytree2->SomeMagicHere(“live”,n);
}

I appreciate if someone could please help?

thanks, eric

Hi Eric,

If you know the type of data ‘live’ (in the code below I will assuming it is a double), you can use: double x; mytree2->SetBranchAddress("live",&x); for (int n=0; n<mytree2->GetEntries(); n++) { mytree2->GetEntry(n); // x now has the correct value. }I strongly recommend that you re-read the User’s Chapter on TTree for more details and the many alternative. In particular you may want to investigate how to use TTree::MakeSelector to simply your task.

Cheers,
Philippe.

thanks ! this works fine. yes, I will follow your suggestion and read the chapter you’re mentioning.

cheers, e cm