Chains with same name hide friend branches?

Hello fellow rooters,

I’ve had a tedious few days trying to understand an odd behavior with TChains being unable to find branches of friends that have the same name. I wonder if this is expected behavior, or am I trying to do something odd?

The attached macros illustrate the problem. I have lots of trees with the same name but different branches, and I want to make a chain for each branch, then the chains together. In chainfriends.C, all my chains share the same name (“cuts”), and files are added by filename only ( Add("*.root")). When I run it (on either 5.28 or 5.32), I get

root [1] chainfriends()
xeven: 9 yeven: 11 zeven: 9
Error in <TTreeFormula::Compile>:  Bad numerical expression : "yeven"
xeven: 9 yeven: 20 zeven: 9

I’ve confirmed with my real setup that all but the first and last trees in the set are hidden.

If instead I give all the chains different names, then add files via Add("*.root/cuts"), it seems to work OK:

root [1] chainfriends()
xeven: 9 yeven: 11 zeven: 9
xeven: 9 yeven: 11 zeven: 9

Is this a bug, or intentional behavior? Also, is there a better workaround than the one I’ve found? The reason I ask the latter questions is that IRL I have trees for each detector, and many have long branch names. So if I want to draw something for a specific detector, I end up with the somewhat absurd string like “detectorN.reallyReallyLongBranchName.reallyReallyLongBranchName”. A minor annoyance, all things considered…

Many thanks,
chainfriends_works.C (1.8 KB)
chainfriends.C (1.79 KB)