RDataFrame dynamically update column

I was wondering if it is possible to dynamically updated a column in rdataframe?

Say I have defined a new column and set all the values in that column to true (or 1 if that is too hard)

df = ROOT.ROOT.RDataFrame(“Events”,“dataTrees.root”)
11presel = True
ROOT.gInterpreter.Declare(‘bool 11presel = bool(TPython::Eval(“11presel”));’)
or
11presel = 1
ROOT.gInterpreter.Declare(‘int 11presel = int(TPython::Eval(“11presel”));’)
whatever is convenient
then:
df.Define(“11_presel”,“11presel”)

Next what I want to do is dynamically update the 11_presel column as I check other conditions for other columns. I am doing this because I want to keep track of an event passing or failing these checks. The pass events will be made into a snapshot dataframe and the fail events will be made into another snapshot dataframe.

Is this possible? Maybe I should be using a lambda function with experimental PyRoot?
Thanks,

Derek


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


Hi,
this question has some overlap with Modifying an existing column in RDataFrame, you might want to check that out.

The short answer is that, in RDF, the way of expressing that 11_presel has a value that depends on the other columns (through the “check of other conditions” that you mention) is to explicitly write that dependency down as the Define expression.

The biggest issue is that besides what happens in the Define expression, you have no hook into the event loop: you can’t do things in-between RDF event processing.

Cheers,
Enrico

Enrico,

Thanks for your reply. If I understand you right, the best way for me to do this is to check all of my conditions and then set the value in the new column as either true or false, all in the Define expression?

The way I think to do this is:

Define(“11_presel”, " (list of checks)")
where list of checks is a list of statements like: pT > 6.0 && eta < 2.0

Does this sound correct? I can think of another way to do this, i.e. c++ lamnda functions, but I don’t know how that might mesh with running this in python.

Thanks,
Derek

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