How to use AddFriend with user-defined-class in a TTree

Hello ROOTers,

I have been using TTree in a simple way with basic types in all branches. Using the method TTree:AddFriend is obvious here. Now I need to store user-defined classes, similar to the Event class (your example), including TClonesArray of some sub-classes. I have the tree created, everything works OK.

Let’s assume, that someone else wants to create new branches to this tree. He can not, because it’s read-only. So he want’s to create a friend tree. How to define the structure, if the branch should contain new information on each track (referring to the Event example)?

What is probably possible, is to load the complete entry to the class in the original tree and save it in a new tree using an extended class (including the new information). Or is there any other way to do it using AddFriend method? Could one use another class in the friend tree representing the same structure (tracks etc)? Is there some example showing how to use AddFriend with classes?

Thank you!


You could create a TrackExtender class containing the extra information (and only the extra information) and stored those objects in a TClonesArray in the friend tree.

Alternatively, you could store the ExtendedTrack object (i.e containing the old and new information) in a TClonesArray in the friend tree (resulting of course in duplication of information).


PS. For some example of tree friends see $ROOTSYS/tutorials/tree