In such case, do I need to unset branches as in classical analysis âSetBranchStatus(false)â or is is automatically the case when I do something like
No, RDataFrame does this automatically. It only reads the branches that you are actively asking for. Your solution of doing a double event loop looks very reasonable!
What is the best way to reproduce something like this using dataframes ?
You do it in two steps:
Define
the columns that you want to histogram, e.g. like in this tutorial df107. Check the function WithDataframe
. It takes a vector of values, and also returns a vector of values. So you can write a loop over all combinations like you did above, and return all the results. This is the example from the tutorial that loops through a collection of inputs, and returns a collection of outputs:
auto CalcPt = [](RVecD &px, RVecD &py, RVecD &E) {
RVecD v;
for (auto i=0U;i < px.size(); ++i) {
if (E[i] > 100) {
v.emplace_back(sqrt(px[i]*px[i] + py[i]*py[i]));
}
}
return v;
};
f.Define("pt", CalcPt, {"px", "py", "E"});
You can do the same, writing all the left-hand values, and in a second define you write all the right-hand values.
And this is a helper from ROOT:VecOps that can give you all indices that you want, so you donât have to compute them yourself:
https://root.cern/doc/master/group__vecops.html#ga134d68284fca51f3460c8c3c508ad351
auto v_3 = Combinations(v, 3);
(ROOT::VecOps::RVec<ROOT::VecOps::RVec<unsigned long> > &) { { 0, 0, 0, 1 }, { 1, 1, 2, 2 }, { 2, 3, 3, 3 } }
- With the columns âGammaE_iâ and âGammaE_jâ defined, you can simply histogram them. Have a look at the documentation here. You will see that it can histogram both single values, but also collections of those, so you can directly histogram what you defined in step 1.
If you want to do both the combinations (i,j) and (j,i), I recommend to make two histograms, one for (i,j) and one for (j,i), and when done you add those histograms.
There is an alternative to write this all manually as a custom RDataFrame action:
https://root.cern/doc/master/df018__customActions_8C.html
You have to watch out a bit to make it threadsafe if you want to run the RDF multithreaded. If you are comfortable with that, the custom action is a viable option.
Otherwise, define the steps as above, and the multithreading will work out of the box.