Add brach to ntuple & evaluate function given by string

Hello Rooters,

I have a ntuple with two branches, let’s name them “AOP1” and “AOP2”, and I want to add to this same ntuple a third branch with entries given by a function of AOP1 and AOP2. The function defined by a string.

I would like to know if there is any of these two options availabe in ROOT:

  1. to evaluate a function (defined by a string) with arguments given by the branches (e.g.: “AOP1+AOP2*AOP2”) and insert the output to the original ntuple as a new branch.

  2. the method TTree::Draw(), allows me to calculate the function using the TCut in the selection argument, but I can’t get the result for each entry, but rather for each bin (not useful). Is it possible to get the output of the evaluation of its function for each entry?

Many thanks in advance,
H.

Hi,

to add a branch to a TTree you need to create a new TTree, create the branch in there, and declare the new TTree a friend of the old one (see TTree::AddFriend).

TTree::Draw()'s output is (in general) a histogram. You could simply create a selector (see TTree::MakeSelector()) and run it using TTree::Process() to create and fill the new branch.

Cheers, Axel.

Hi,

Note that after using TTree::Draw some of the raw result of the calculation are available via tree->GetV1() (and tree->GetV2()). Namely the last 'tree->GetEstimate()" values can be found in this array. To get all the values use tree->SetEstimate(tree->GetEntries()).

Cheers,
Philippe.

Thank you both.