Variable number of input columns in Define

Hi all,

I have several branches in a tree all of the same type double, representing energy deposited across multiple detectors, and wish to use RDataFrame to create a new column that’s just the sum of all the entries in that row. I know how to use Define to do this for a fixed number of columns:

auto df2 = df1.Define(“sumColumn”, DoSum, {“column1”, “column2”, etc…});

However, the number of columns in the each file is different depending on the number of detectors, and so I’ve been struggling to implement this sum for a variable number of columns that I can apply to any file.

Does anyone have input on how to do this? I have tried to read up on variadic functions (I am still a bit novice with C++), but haven’t found anything that works with RDataFrame. Any thoughts would be greatly appreciated!

Hi @nicconflo,

I believe this won’t work out of the box, see a similar issue here, but indeed you can play around with the variadic functions, Declare it to the interpreter and then use it in the Define call, see a similar example here.

Cheers,
Marta

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