Is there a generic way to know components of the TTreeFormula?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Dear Experts,

Is there a generic way to know the (minimal) list of branches/leaves in the TTree that are needed for evaluation of TTreeFormula expression ?

Thank you very much in advance for any useful hints.

Did you try to search the forum? I found several possible related questions, like:

Otherwise @pcanal might give some hints

Dear @bellenot
Thank you. I’ve searched for the topic before. These items are discussing a bit different problem for different needs, and none of them allows to get list of used branched/leaves.

OK, so let’s see if @pcanal can help

Buried in one of those post:

The information you are asking about is […] available via TTreeFormula::GetLeaf which takes an integer from 0 to TTreeFormula::GetNcodes.

Out of curiosity (and because there might be a simpler solution), why do you need/want the list of branches used by a TTreeFormula?

Hi Philippe @pcanal
Thanl you very much. I’ll make a try tomorrow.
(btw - from descriptio of methods this action is not very obviou. Probably it is worth to extend
a bit documentation strings here

My task is rather simple. In my project I often has a tree with very large number of branches
and I often want to prefilter it filter out unnesessary entries and and use only reduced num,ber of variables, but using only “a bit loose” selection criteria, postpoinng the final filtering to the last step. Since initial number of variables is eally huge, and finally I need only O(10) varibales + several varaibles used for “loose versions” of selection criteria, such operation allows me to reduce data very efficiently, and to prepare very compact tree with only interesintng variables and manageable number of entries.

For that purpose, I recommend you check out the Snapshot feature of RDataFrame (the successor to TTree::Draw and TTreeFormula.

hi Philippe @pcanal
It is exactly way I am using, but for this I need to know the list of branches I want to keep :-).
And thats why I am asking how to get branches from TTreeFormula
Thank you!

So the following will retrieve a list of top level branch used in the TTreeFormula (with potentially repeats if the same branch is used multiple time directly (or indirectly as a parent):

TTreeFormula *tf = .....
std::vector<TBranch*> used;
for(int i = 0; i < tf->GetNcodes(); ++i) {
   TLeaf *leaf = tf->GetLeaf(i);
   TBranch *parent = leaf->GetBranch()->GetMother();
   used.push_back(parent);
}

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.