TTree.Draw with a function taking as argument a TTree Branch

Dear ROOT experts,

I recently encountered an issue related to tree.Draw() and I’m wondering if this has to do with some kind of intrinsic limitations of the Draw method itself, or if perhaps I’m simply doing something wrong. Unfortunately I wasn’t able to find any example online which describes exactly what I would like to do.
Attached you find a minimal example that reproduces the problem.
I have a tree with two branches (“a” and “b”), which are actually two classes (named “A” and “B” respectively).
What I would like to do, is to feed the Draw method with a function, defined in the class B, which takes as argument elements of type A. In the example, it is something similar to what “function2” and (especially) “function3” are trying to do, without much success.
I execute the macro compiling it with ACliC, using ROOT 5.34/10 on a machine running Scientific Linux 6.6

Thanks in advance for any help or feedback,
Fabio
test.C (1.06 KB)

Hi,

This version of TTree::Draw can only pass numerical argument to function. To call a function passing an object you will need to use the syntax of TTree::Draw that takes a script as input. See the MakeProxy section in root.cern.ch/root/html/TTree.html#TTree:Draw@2.

Cheers,
Philippe

Hi Philippe,

I was not aware of this use of TTree::Draw(). I played around a bit and it works great, at least on the reduced example that I posted.
Thanks a lot for pointing me to this solution!

Cheers,
Fabio

Ciao,

but with my ‘ntuples’ I can do something like this:

ch->Draw(Form("1.0/(pmyParticle(0)->pmyTrTrackPlus()->GetRigidity(%d)) >> innrigidity2", kinn2), npart && pp && trp, "same", nev2beproc);

where in the Tree I saved a ‘myEvent’ class that has pointers to subclasses… I do this in ACliC (but the Fabio’s example is not working neither compiled with .L+) and all the classes are inside a compiled shared library…

Thanks,
Matteo

Hi Matteo,

Fabio’s original example is not supported (calling function from TTree::Draw while passing them an object as a parameter).

Cheers,
Philippe.

Yes I tried it.

I don’t understand why, instead, mine is working… Is quite similar…

Thanks,
Matteo

Hi Matteo,

As far as I can tell in your example the functions are only called with numerical values (which is supported).

Cheers,
Philippe.

Ahhh!

Now I understood! I could use all the ‘nesting’ I want (A->GetPointerToClassB()->GetPointerToClassC()…) and this is supperted.
What are not supported are the class methods accepting wathever is NOT a number.

Sorry previously I didn’t get completely!

Thanks,
Matteo