Selectors/proxies within TTreeFormula or TTree::Draw


This is a query to the root experts seeking advice on how to implement the functionality I would like…

I want to be able to implement complex selections and variables in a similar way to the way proxies and selectors work. But then I want to be able to use these complex selections in regular draw statements - or come up with an equivalent.

At the very basic level, I want to be able to specify the variable(s) to draw, the histogram to “Fill” them to, and the entry selection to apply.

So I want to be able to do something which would look like:


where myVariable.cxx could contain code to evaluate a number using the values from the ttree for the instance (so could be multiple instances in an entry, a-la looping over vectors) as selected by the mySelection.cxx code.

I think in essence, I am looking for a way to create “dynamic branches” for tchains and ttrees, which work seamlessly with the existing Draw and Process methods and associated infrastructures. Perhaps the best way to have this would be to be able to add these dynamics branches like you would a regular branch, e.g…

tree->Draw(....variables and cuts that use myDynamicBranch...)

Where myBranchCode.cxx would be able to use the values from other branches to generate a value for itself. Ideally it could use the values of other dynamic branches, but then you’d need some way to protect against circular dependency. You’d want the dynamic branch to be a function of the entry number as well as the instance number (so if you decided to do a Draw with a branch that was a vector or array, for example, then your dynamic branch could be evaluated for each specific instance in the vector).

Before I sit down and try to implement this, I would be interested to know if anything close to this is already available in ROOT. I’ve struggled to find it, but the complexities of TTreeFormula and so on might mean something like this is already almost possible!?? I think a complete solution would involve quite a lot of work, so in the meantime I’m thinking about implementing some code that basically creates a friend tree/chain with the results stored in them - so that values aren’t dynamically created at runtime, they are just loaded from a file. But I think this might be the most straightforward way given the current ROOT features available.

As I say, if an expert has any interesting views on this sort of thing, I’d be very interested to hear them!



Hi Will,

One of the existing feature that resemble what you propose is the TTree Aliases which allows to record shortcuts for complex TTreeFormula expressions. You can combine this aliases and a set of free-standing function to get pretty close to what you want.


Hi Phillipe,

Thanks for the reply. Unfortunately it looks like free-standing functions (static functions which I then aclic compile) do not work when processing the TTree as a TChain in proof mode. Any way around this?