FoxWise
December 10, 2022, 12:43pm
1
I wonder if it is possible today?
Very similar question:
ROOT Version: 6.16.00
Platform: CentOS 7
Compiler: GCC 7.3.0
Dear experts,
I am currently trying to figure out the correct syntax for using the previous event in the filter for RDataFrame.
In our use case, the events are ordered in time and it is essential to check the previous event in order to satisfy an analysis cut, e.g.
passes = myDF.Filter("x < 1.0 && x[previous event] > 0.5")
Does such functionality exist?
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:
Hi @Samuel1 ,
sorry for the high latency, I was off last week.
The most tricky part about processing entries with a sliding window is multi-threading – each entry will process a bunch of entries at a time, and the first and last entries in the bunch will not have a previous/next entry so you’ll miss some statistics.
If you are happy with single-thread processing, or you don’t mind losing some of the pairs of consecutive entries, you can use a stateful functor + RDataFrame, something like (hav…
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>)"
cheers,
Bohdan
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!
Enrico
FoxWise
December 12, 2022, 10:02pm
3
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
ROOT.gInterpreter.Declare("""
struct Functor {
double operator()(double x) { return x*x; }
};
""")
f = ROOT.Functor()
m = ROOT.RDataFrame(10)\
.Define("x", "3.")\
.Define("xsq", f, ["x"])\
.Mean("xsq")
print(m.GetValue())
1 Like
system
Closed
December 27, 2022, 9:27am
5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.