I want to calculate the 2D flight distance sv_dxy using sv_x and sv_y.
import ROOT
from ROOT import RDataFrame
ROOT.gInterpreter.Declare("""
#include <cmath>
float compute_svDxy(float svX, float svY) {
return std::sqrt(svX*svX + svY*svY);
}
""")
dfq = RDataFrame("demo/tree", "QCD_Output_All.root")
dfg = RDataFrame("demo/tree", "BulkGrav_Output_All.root")
dfq = dfq.Define("svDxy_q", "compute_svDxy(svX, svY)")
dfg = dfg.Define("svDxy_g", "compute_svDxy(svX, svY)")
dfq.Snapshot("demo/tree", "QCD_Output_With_svDxy.root")
dfg.Snapshot("demo/tree", "BulkGrav_Output_With_svDxy.root")
My error is,
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[32], line 14
11 dfq = RDataFrame("demo/tree", "QCD_Output_All.root")
12 dfg = RDataFrame("demo/tree", "BulkGrav_Output_All.root")
---> 14 dfq = dfq.Define("svDxy_q", "compute_svDxy(svX, svY)")
15 dfg = dfg.Define("svDxy_g", "compute_svDxy(svX, svY)")
17 dfq.Snapshot("demo/tree", "QCD_Output_With_svDxy.root")
File ~/miniconda3/envs/root_env/lib/python3.10/site-packages/ROOT/_pythonization/_rdf_pyz.py:372, in _PyDefine(rdf, col_name, callable_or_str, cols, extra_args)
369 raise TypeError(f"First argument of Define must be a valid string for the new column name. {type(col_name).__name__} is not a string.")
371 if isinstance(callable_or_str, str): # If string argument is passed. Invoke the Original Define.
--> 372 return rdf._OriginalDefine(col_name, callable_or_str)
374 if not callable(callable_or_str): # The 2st argument is either a string or a python callable.
375 raise TypeError(f"The second argument of a Define operation should be a callable. {type(callable_or_str).__name__} object is not callable.")
ValueError: Template method resolution failed:
ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void>::Define(basic_string_view<char,char_traits<char> > name, basic_string_view<char,char_traits<char> > expression) =>
ValueError: nullptr result where temporary expected
cling JIT session error: Failed to materialize symbols: { (main, { _ZN4ROOT3RDF10RInterfaceINS_6Detail3RDF12RLoopManagerEvE6DefineESt17basic_string_viewIcSt11char_traitsIcEES9_ }) }