How to extend/add user method of a Branch class?

It is very convenient to directly call a branch class’s method when drawing
or scanning a TTree. For example, for the Event class in $ROOTSYS/test/Event.h,
we can use “tree->Draw(event.GetNtrack())” which calls the method “GetNtrack()”.

However, the method to call is independent of the data storage or “Streamer”.
For a large class “Myclass” stored in a TTree, we need to update the methods of
the class constantly in the analysis, while the data member don’t change.
E.g., we may want use “tree->Draw(Myclass.newmethod1())”,
“tree->Draw(Myclass.newmethod2())”… . This means we will keep updating
"Myclass" by adding or modifying it’s methods in the analysis, which is totally
not convenient
.

Is there a way to separate Myclass’s data member and it’s methods? So that
when creating/writing the tree, only the data member is relevant. And then
in later detailed analysis, users can update/modify the methods in other files
and locations.

I guess, one way to implement this in the current structure is to derive a
class called “MyclassImp” from “Myclass” as the branch class:

MyclassImp * myevent = new MyclassImp(); tree->Branch("myevent", &myevent, bufsize,split);

When creating the tree, MyclassImp is empty with no or few methods:

class MyclassImp: public Myclass{ ClassDef(MyclassImp,1) };

And when analysing the tree, user can write a separate MyclassImp with
user-defined methods:

class MyclassImp: public Myclass{ Float_t method1(){...} Float_t method2(){...} ... ClassDef(MyclassImp,1) };
,and load it with “.L MyclassImp.C+” when reading the tree in file,
so that the each user can use “tree->Draw(Myclass.method1()) …” and update it
according to their analysis requirement.

This way is still not very convenient and elegant, and I’m not satisfied.
For each user need to stick to the name “MyclassImp”. Is there a good way in
ROOT to do this?

Hi,

I believe what you’re looking for is a way to post-process a TTree. That’s indeed very common, and the recommended way is to use the TTree::MakeProxy interface. If the analysis code becomes too complex you might have to switch to a TSelector base approach.

Cheers, Axel.