I have a code that was build on a skeleton of makeClass using a ROOT file with a single Tree.
Recently the ROOT files has been expanded with the addition of an additional Tree. I’d like to be able to access both Trees from my current code. The way I understand this, it is possible to do this using the AddFriend() method. Everything “seems” to be working fine until I try to access the second tree variables. Although no warning or crash occurs the variable values are not correct but instead have their initialisation values (=0). This implies that their values are not picked up by SetBranchAddress() etc… Here’s a summary of what I am doing:
Chain* primaryChain = new TChain(“TDirectoryName1/TreeName1”);
TChain* friendChain = new TChain(“TDirectoryName2/TreeName2”);
What am I missing?
I have simplified the problem by starting from scratch with makeClass and a single ROOT file.
A minimum working example is found here  with all files included.
If I remember correctly, to get this to work you need two MakeClass skeleton. One for each of the friend …
i think i saw a post where it is mentioned that you create two makeClass and then copy/paste by hand. If you look at the code this is exactly what I did. In particular, the branch addresses of the second Tree are added by hand to the first makeClass. Then I add the friendship between the two trees. Is that correct?
Disable the reading of objects (i.e. the std::vectors).
can you please be more specific. That line (L 393 in TreeReaderReco.h) is already there. So if you I must disable it, i just tested it and the result is the same. i.e. the “friend” tree branches are not read but instead have their initialised values. Unless I misunderstood something?
I meant to say that this line should be removed if you want to read any data stored in a vector.
i.e. the “friend” tree branches are not read but instead have their initialised values.
Are you saying that for the branch in the main tree that are vector the data is read correctly?
As I said above, I have put a minimal working code on lxplus.
So when you loop over the tree (.x run.cc) I print branches values from both trees. Those from the primary tree have correct values and those from the friends tree have their initialised values => their values are not read correctly (or at all). Commenting out
make no difference.
Can you access the code i have put on lxplus? I can also attach it here if it is preferred.
Thanks for the help
Those from the primary tree have correct values and those from the friends tree have their initialised values
This is because SetMakeClass is not set on the friend TTree. I.e. adding to the constructor:
might make the simple value appear correctly (but it might also make reading the vector not work properly).
Either way, I recommend that you consider using the TTreeReader-based TSelector created by v6’s TTree::MakeSelector rather than MakeClass.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.