The Row corresponds to event number. I have converted this root file into a rdf object and i want to filter this rdf. I wanted to go to each event, assuming it has atleast two entries, and filter the two entries with higher and next higher Jet.energy in the dataframe itself. Here how can we filter entries within an event? This i wanted to do for each event in a loop.
Additionally How do we define a new column of Lorentz vector’s containing components as Jet.energy, Jet.momentum.x, Jet.momentum.y and Jet.momentum.z?
About your first question, I understand you want to define a new column that contains a collection with the two leading jets - please correct me if this is not accurate.
Assuming your Jet column is a STL vector, you can achieve that with a Define:
Not the leading two jets, the one with highest value of Jet.energy and next higher value. For each event, i only want to keep these corresponding rows in the dataframe.
“Leading jets” is a common term used for the ones with a highest Pt indeed. This is the way in which particles (and jets) collections are ordered in most data models. If you want to get the ones with the highest energy, or use any other criteria, it is just a matter of sorting (std::sort + predicate?) the vector according to it before extracting the two leading components according to such criterion.
Ok. The root file seems to be sorted based on pT value.
Actually i want filtering of events here firstly. Above command is defining a new column.
I wanted to filter these leading jets rows on each event. This would give me for each event, only two entries that corresponds to leading jets. Also i want to ignore the events with only 1 entry. So this would give me a new df with 2 entries per event.
After this, i wanted to define a new column of Lorentz vectors to this df.
RDataFrame works in a declarative way: nothing is modified in place, but rather new columns are created.
If you wish to skip events with one jet only, the way to go is to define a filter upfront. Always assuming LeadingJets is a std::vector:
Thanks it worked. Can you explain what the command myvec() doing here? Also i wanted to look at newly formed columns by displaying it. How this can be done?
auto myvec(Jet) is creating a new variable myvec with the syntax of a copy constructor, with a type inferred from Jet (that we know is a vector - I still do not know T, but I can let the compiler figure it out for me with the auto keyword).
For what concerns the VecOps::Construct, it’s a variadic template invoking the constructor of T using elements of the vectors provided, one by one. If you are curious about the implementation details, you can always navigate to it via Doxygen!
Cheers and thanks for the interesting follow-up questions!