Thank you for the reply!
I’m trying your two ways, but something is going wrong.
px, py are double
The first way:
using namespace std;
#include <iostream>
#include <string>
void Analys(){
ROOT::Experimental::TDataFrame d("Particle","crmc_eposlhc_416075184_p_C_800.root");
auto dd = d.Define("pt", "sqrt(px*px + py*py)");
auto hpt = dd.Histo1D({"hpt", "pt distribution", 100, 0, 4}, "pt");
[...]
}
Error:
input_line_51:3:15: error: invalid operands to binary expression ('std::array_view<double>' and 'std::array_view<double>')
return sqrt(px*px + py*py)
/opt/root6/include/TTime.h:85:14: note: candidate function not viable: no known conversion from 'std::array_view<double>' to 'const TTime' for 1st argument
inline TTime operator*(const TTime &t1, const TTime &t2)
/opt/root6/include/TVectorT.h:250:19: note: candidate template ignored: could not match 'TVectorT' against 'array_view'
TVectorT<Element> operator* (const TVectorT <Element> &source, Element val) { return val * source; }
^
terminate called after throwing an instance of 'std::runtime_error'
what(): Cannot interpret the following expression:
sqrt(px*px + py*py)
Make sure it is valid C++.
The Second way:
float -> double
using namespace std;
#include <iostream>
#include <string>
void Analys(){
ROOT::Experimental::TDataFrame d("Particle","crmc_eposlhc_416075184_p_C_800.root");
auto dd = d.Define("pt", [](double px, double py) {return sqrt(px*px + py*py);}, {"px", "py"});
auto hpt = dd.Histo1D({"hpt", "pt distribution", 100, 0, 4}, "pt");
[...]
}
The second way I get graphic, but I Think pt
not is calculated:
file: crmc_eposlhc_416075184_p_C_800.root
TTree Particle particles produced (entries=1000)
nPart "nPart/I" TBranch
pdgid "pdgid[nPart]/I" TBranch
status "status[nPart]/I" TBranch
px "px[nPart]/D" TBranch
py "py[nPart]/D" TBranch
pz "pz[nPart]/D" TBranch
E "E[nPart]/D" TBranch
m "m[nPart]/D" TBranch
Cheers, Andre