Root files with multiple TTrees


My problem is more a tad more detailed than below, but I give a simplified version of what it all boils down to. I didn’t create the ROOT files in question, but have to deal with them somehow.

Lets say I have a set of ROOT files containing 2 TTrees, lets call them treeA and treeB. Both TTrees have a branch with the same name. Lets call the branch name b.

Now, If the branch names were a and b, this would be no problem. I would create a class with data members a and b, then in my constructor I would have something like:

TTree* tree;
TChain* chainA = new TChain(“treeA”);chainA->Add(file);
TChain* chainB = new TChain(“treeB”);chainB->Add(file);
tree = chainA;

and everything would work well. This normally works fine for me. Having 2 data members with the name b obviously causes compilation errors. As I would normally make TTrees treeA and treeB friends, there is an ambiguity over which TTree to use when accessing branch b.

How should I go about accessing branch b in both treeA and treeB in a consistent way that ensures no cross over of data or any other screw ups?

Thanks for your time

Hi John,

If you are customizing the MakeClass/MakeSelector/TSelector that you are using, you can simply rename the data member that points to the alternate branch. And in the calls setting the address make sure to specify treeA.b or treeB.b.