[ROOT] Function as an NTuple/Tree Variable

From: Roger Moore (rwmoore@fnal.gov)
Date: Fri Aug 16 2002 - 23:27:42 MEST


Something I have been trying to do in ROOT without any success is to write
an independent function and have it pretend to be a variable of a Tree or
NTuple in ROOT. Much like you used to be able to write a F77 method in PAW
and have it behave as a NTuple variable.

What I essentially want to be able to type on the command line is:

	mytree->Draw("myfunc");

where 'myfunc' is function of the type:

	double myfunc(TTree *)

I know that I could use MakeClass (for NTuples) or the base classes for a
ROOT Tree and add a method to the class. However this makes it extremely
hard to cope with updates to the code since I have to redit the class
header file to include every method prototype. It is also a big mess since
when analysing data I will write very many such functions, most of which I
probably don't care about at any one time, and so the header file fills up
with unused prototypes that I don't want to delete just in case I do want
to revisit an old method.

Failing something like this then is it at least possible, when using
trees, to make ROOT read the data as a derived class? For example if I
have a TTree with a Branch containing 'Muon' objects can I make ROOT read
those in a 'MyMuon' objects where 'MyMuon' inherits from 'Muon'?

In this way I could put my methods into 'MyMuon' and still invoke them
from the Draw command. That way when a new version of 'Muon' is released I
simply recompile my code.

I've tried to work around this problem with function pointers but the C++
interpreter doesn't like these. I've also wondered if, since the Draw
command must use the class dictionary to look up members, whether it is
possible to add a method after the fact by adding it to the dictionary
directly but this seems sufficiently hard (and may be impossible) that I
haven't tried it yet.

Any help would be appreciated,

Roger



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:04 MET