Access TLeaf in a TBranch using TChain

Hello,

I need to access some TLeafD in a TBranch of a TTree, but using TChain, not single files.
The attached macro works if I use a single file as argument, but not if I use multiple files. Using a chain of files, I can access the values in the branch “t”, but not those in the leaf “x” belonging to the branch “position”.

Thanks for any input.

Cheers,
Francesca

leaf_test.C (588 Bytes)

Attach the output of tree->Print();

Hi,

@pcanal Attached the print out. I attached also another macro with proper names of branches, tree, leafs (in the previous one I simplified them).

Thanks,
Francesca

The leaf_test2.C (810 Bytes)
print_leaf_test.txt (5.9 KB)

Try to modify your loop over all entries (not sure if it is enough, @pcanal would need to confirm):

Long64_t nentries = chain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0; // not really needed
for (Long64_t jentry = 0; jentry < nentries; jentry++) {
  Long64_t ientry = chain->LoadTree(jentry);
  if (ientry < 0) break; // no new entries (or opening the file failed)
  if (ientry == 0) { // the first entry from the (next) file
    // ... set all addresses of branches and leaves here ...
  }
  nb = chain->GetEntry(jentry); nbytes += nb;
  // ... analyze this entry here ...
}

Thanks a lot @Wile_E_Coyote, it worked.

Attached the revised version of the macro.

leaf_test3.C (1.1 KB)

You unnecessarily call “GetEntry” twice.
Before exiting the function, you should: delete chain;

@fra_root, @Wile_E_Coyote is correct. Every time the TChain switch from one file to another the underlying TTree object and all its branch and leafs are deleted. Only the address register via SetBranchAddress are carried from one file to the other. Any addresses set directly to the TBranch or TLeaf object needs to be set again at the beginning of each file.

1 Like

Thanks @pcanal @Wile_E_Coyote, I fixed it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.