Hi,
thank you for creating a post that’s smaller in scope than this, I’m not sure how to help there.
Unfortunately you can’t mix RDataFrame column definitions and standard C++, it just can’t work within the C++ (or python) programming language.
So if you want to use a quantity as an argument to a C++ function, it needs to be a C++ variable. If you want to use a quantity within RDataFrame, you can Define it.
You can use RDataFrame’s Take method to extract all values of a given RDF column into a regular std::vector. But it’s usually more efficient to do all operations you need within RDataFrame, and extract just the histograms or the final quantities you need.
Hope this clarifies things a bit.
The ROOT tutorials have a few examples of full analyses done with RDF that you can check out.
Cheers,
Enrico
@eguiraud This does help as I am working through it more; I believe I understand your reply.
What I have a question about is the Define in RDataFrame. If I am eventually calculating the invariant mass (which I am using the tutorial’s code to do so) by using:
auto df_mass = df_muon_mass.Define("Dimuon_mass", InvariantMass<float>, {"Muon.PT", "Muon.Eta", "Muon.Phi", "muon_mass"});
how can I define muon_mass if I do not have that branch in my tree. I tried many different was to define it. After writing,
auto df_muon_mass = df.Define("muon_mass", ROOT::RVec<float>, {"49254", "0.1"});
where 49254 is the collection size and 0.1 is the value I want to give the muon mass. I am also defining it to be an RVec so that I can calculate the invariant mass. My other branch values (Muon.PT,etc which are already present in my tree) are floats.
I keep getting this error:
Processing invariantmass.C...
In file included from input_line_8:1:
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/invariantmass.C:109:64: error: expected '(' for function-style cast or type construction
auto df_muon_mass = df.Define("muon_mass", ROOT::RVec<float>, {"49254", "0.1"});
How can I write my Define correctly so that the Invariant mass will be calculated?
The problem with that code is two-fold: firstly, C++ constructors are a bit special and you can’t use them as factory functions: ROOT::RVec<float> is not a function that returns a ROOT::RVec<float>, hence the compilation error. Secondly, Define requires valid column names as last argument, you cannot just pass any argument to the function as in df.Define("muon_mass", ROOT::RVec<float>, {"49254", "0.1"});.