In a TTree, can I have a branch that points to another internally?

I have a TTree in which I have three branches that each store information about an object of a different type: call them A, B, and C. In each entry of my TTree I can have only two of the objects: I can have (A, B), or (A, C) or (B, C).

I’d like to keep the storage of each object separate (though their branches are identical in content), but add a branch that provides a pointer to the two that are stored in the TTree entry, so that in each branch I can use that branch to access which ever other entry exists in that entry, be it A or B, etc.

Is this possible?

I’m not exactly clear on your goal, but I’d suggest you investigate TTree:SetAlias and Alt$ from TTree::Draw as quoted below.

My understand is that aliases apply to the whole TTree (to all entries equally). I want something that points to a different branch of the tree depending on the particular entry.

My solution now has been to basically make an alias: using an extra variable that describes which branch should be grabbed, I can create an alias that grabs the correct one. But it’s not ideal.

If your object/class inherits from TObject, you can use the TRef ( mechanism in conjunction with TTree::BranchRef (

However using the extra variable might still be simpler to understand/use.

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