I am trying to load an external function that I can then use in TTree::Draw. If I use primitive types, this works fine, but when I try to do this with a PtEtaPhiMVector, I get the error:
Error in <TTreeFormula::Compile>: Bad numerical expression
The way I’m loading the macro seems to be fine, e.g.:
gROOT.ProcessLine(".L external_functions_C.so")
And I can use externally defined functions that use and return primitive types but I don’t seem to be able to use any of the LorentzVector classes. Does anyone have any idea how I can do this? A basic example of a function I’ve tried is:
Hi @jhowarth ,
not a direct answer to your question (sorry, for that I think we need @pcanal ) but RDataFrame has no problem handling arbitrary C++ types and your code above would be:
auto h = df.Define("pt_vec", "return Map(l_vec, [](PtEtaPhiMVector &l) { return l.Pt(); }")
.Histo1D("pt_vec")
where arrays are read as RVec objects so we can use Map here to transform an array of PtEtaPhiMVectors into an array of floats.
More verbose, but also more versatile (and adding ROOT::EnableImplicitMT() in front automatically runs the query on multiple threads).
Thanks for the suggestion, but this would mean migrating a very large amount of code from TTree::Project setup to an RDataFrame setup. Which we would like to do eventually, but in the short term it’s not viable.
But thanks anyway for pointing out a longer-term solution!