I am moving from root_numpy to RDataFrame and i am having some difficulties in the TTree filtering.
I have a lot of variables in my trees, some of then are event variables and other are track variables, and i need to filter both kind of variables at the same time.
My problem is filtering tracks within an event.
How can i filter track variables, as eta or pt, easily in PyROOT ? For example selecting tracks with pT > 700MeV ?
You can also use RVec in the JITted C++ (see the example in the documentation), I think Track_pt > 700. && Track_pt < X constructs an RVec<bool> that you can use to index any other Track_XYZ (for how to scale to a large number of branches the discussion Is there better way to filter array branches than defining new columns in RDataFrame? is a nice overview of the possibilities and limitations).
If you are using a string to define your cut that you pass as an argument to Filter, there is no difference between Python and C++ (the expression in the string is just in time compiled as C++ code in both cases).
Filter("eta>0") just works if eta is a scalar branch. If eta is an array/vector branch, the right filter would be Filter("All(eta>0)"), since the result of eta>0 would be an RVec<bool> as explained by @pieterdavid - that would filter out the events with all etas <=0. Here’s a tutorial that shows the logical operations you can do: