Referencing the previous/neighbouring event in RDataFrame::Define

I wonder if it is possible today?

Very similar question:

was a while ago for patch 6.16. And for Filter, not Define.

It would be nice to have:

improt ROOT

df = ROOT.RDataFrame(10)\
        .Define("squares", "rdfentry_*rdfentry_")\
        .Define("prev_squares", "squares_of the previous event")\
        .Define("odds", "squares - prev_squares")

Was there any progress on that?

If I ran the proposed answer in that post, or the answer from this post:

I get the error:

  ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter,void> ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter,void>::Define(basic_string_view<char,char_traits<char> > name, basic_string_view<char,char_traits<char> > expression) =>
    TypeError: takes at most 2 arguments (3 given)
  Failed to instantiate "Define(std::string,std::string,std::initializer_list<std::string>)"


Hello @FoxWise ,

there is nothing ad-hoc in RDF to access previous or neighboring events. In general you need a stateful filter, similar to the stateful Define that you linked. For thread-safety you can have per-thread storage (df.GetNSlots() tells you how many threads you’ll have and the rdfslot_ column can be used to index into per-thread storage, e.g. a vector).

As per the error, it looks like you are passing a string as a second argument and a list of columns as third argument. The third argument is only needed if as second argument you pass a function or functor, not a string.

I hope this helps!

So, then it is impossible to call the method with 3 arguments from pyROOT?

As I did define functor, but inside

gInterpriter.Declare(''' . . . ''')

It is totally possible, e.g. this should work:

import ROOT

struct Functor {
    double operator()(double x) { return x*x; }

f = ROOT.Functor()
m = ROOT.RDataFrame(10)\
        .Define("x", "3.")\
        .Define("xsq", f, ["x"])\
1 Like

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