Printing index corresponding to Max$(structure) using TTree::Scan()

Hello,

Using TTree::Scan(), I would like to be able to print index for a structure or array element satisfying Max$(structure) or Max$(array).

I found this related post, and this reference for commands to use within TTrees under the heading “Special functions and variables”. But neither really appears to provide an idea of what I want to achieve.

To try and explain what I want, I will provide examples of what I have tried. Suppose I have TTree object TreeA and within that object I have a structure structB or array arrB. Here are some of the commands that I have tried:

TreeA.Scan("Iteration$", "max$(structB) == structB");
TreeA.Scan("Iteration$", "max$(structB) == structB && Iteration$");
TreeA.Scan("TMath::LocMax(length(structB), structB)");
TreeA.Scan("TMath::LocMax(N, {structB.object_1, structB.object_2, ..., structB.object_N})");

For the above the structB contains only double values and nothing else. Perhaps there could be a way to cast the entries in the structure into an array to be used? That is what I tried doing in the last example, but the use objects within braces didn’t seem to be recognized as an array by TMath::LocMax() didn’t seem to work.

TreeA.Scan("TMath::LocMax(N, {structB.object_1, structB.object_2, ..., structB.object_N})");

TTree::Scan does not support the {..., ....} syntax to create arrays.

for a structure or array element satisfying Max$(structure) or Max$(array).

Max$ only supports array, not structs.

I don’t think there is an efficient way to implement this in TTree::Scan, however RDataFrame might help.

ROOT::RDataFrame df(treename, filename);
df.Define("maxvalue", "std::max({structB.object_1, structB.object_2, ..., structB.object_N})")
   .Define("indexvalue", "return maxvalue == structB.object_1 ? 1 : maxvalue == structB.object_2 ? 2 : ....;";
...

Cheers,
Philippe.

1 Like

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