RDataFrame : limit actions on N first entries of vector<float>


I’m analysing a TTree with many vector stored per event.
I would like to perform actions (standard things like defining new variables, histogramming) using only the 1st or N first entries in the vectors.

I can do something like :
d.Define("vectorA0", "vectorA[0]").Histo1D("vectorA0")

However, this means I would have to add such a Define for all my vectorX variables which I’m interested. This starts to be inconvenient when I have more than ~10 of them.

Is there another way to impose a global limitation on what entry in the vector to use ?
Also what if I want to do the same histograms, but with only the N first entry (typically 2 or 3) ?

Thanks for any hints !


_ROOT Version: 6.16
Platform: Not Provided
Compiler: Not Provided

Hi @pad,
there is no RDF-native way to restrict all vectors to only the first or the first N entries.
You will have to Define the quantities that you want to use to fill histograms.

But you can just use a for loop to do this for all your variables:

const auto cols = {"A", "B", "C"};
ROOT::RDF::RNode df_with_defines = df;
for (const std::string &col : cols)
   df_with_defines = df.Define(col + "0", col + "[0]");

Hope this helps!

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