Sum of a RVec<bool> [RDataFrame]

Dear root experts,

I want to make some plots in a no b-tag region of my phase space. I am reading a ‘Jet_btag’ vector from my ntuples, which has the type ‘ROOT::VecOps::RVec’. This vector has a boolean entry for each jet in the event, which is 1 if the jet is btagged and 0 otherwise. So, I would like to sum the elements of this array and filter just the events where this sum is 0. I tried some things like:

df = df.Filter("Jet_btag.Sum() == 0 ", "No b-jet region")

But it looks like there is no such thing for RVec arrays. And i didn’t found anything like in the documentation. I also tried to convert the array to a numpy array, as its done here →

df = df.Filter("nump.sum(numpy.asarray(Jet_btag)) == 0 ", “No b-jet region”)

But i get the error:

input_line_177:2:8: error: use of undeclared identifier 'numpy'

So, there is a way to do this directly inside the df.Filter() ?


Hi @Daumann ,

in the RVec reference guide (ROOT: ROOT::VecOps::RVec< T > Class Template Reference) there is a section titled Reference for RVec helper functions. There you can see all RVec helper functions – there is one called Sum: df = df.Filter("Sum(Jet_btag) == 0 ", "No b-jet region").


1 Like

Worked wonderfully, Thanks @eguiraud!