Class member functions in TTree::Draw

Hello, fellow rooters,

There are some older forum posts on this topic, but all the responses contain phrases like “at this time”, so I figure I’ll ask if anything’s changed.

I have a class which has a vector of Channel objects, each of which has a vector of Pulse objects. The Channel class has a member function which converts indices on the sampling digitizer to times, SampleToTime(int samp).

What I would like to do is call

tree->Draw("channels[].SampleToTime(channels[].pulses[].start_index)")

However, this results in obtaining the indices, as if I had called

tree->Draw("channels[].pulses[].start_index")

(Am I doing something wrong here? It seems to me that that should generate an error or at least a warning, not just silently ignore the function.)

But this would be a complicated loop, so maybe it is still not possible to define this behavior. What I thought should work, based on the TTree::Draw documentation, is

tree->Draw("channels[0].SampleToTime(channels[0].pulses[0].start_index)"
But this doesn’t work either; again the surrounding function is simply ignored. In this case there is no looping, and the argument to the function is numeric, which seems analagous to “event.GetTrack(fMax).GetPx()” mentioned in TTree::Draw. Does this not work when the class is contained in a vector?

Thanks,
~Ben[/code]

Hi,

Unfortunately, this documentation bit is inaccurate and has been removed. As you guessed the fundamental problem is one of semantic in case the argument is array and other array are used in the expression, then it is unclear whether the indices for the argument should vary with the other indices and be an inner loop.

I update the documentation to accurately describe this and I will look into whether it is possible to add a better error message (note that in my attempt to reproduce this problem, I never encountered the case where it silently ignore the outer function instead I got several error message saying that the content of the argument was not known).

Cheers,
Philippe.

That’s what I was afraid of.

Thanks!

Hi,

As an alternative you can use the TTree::Draw technique where you pass a file name (containing a user function) where you will be able to call any function you want (as the expense of having to implement the looping over the array inside each TTree entry). See the section ‘Drawing a user function accessing the TTree data directly’ in the TTree::Draw documentation or the TTree::MakeProxy documentation

Cheers,
Philippe.