Hi,
I am trying to make a RDataFrame from a user-defined function that computes 3 different values and has an input variable from a dataframe. Then I want to Define
the values computed in the user-defined function in 3 different columns of the same dataframe but I don’t want to call this function 3 times for each column since that is very inefficient:
// User-defined function
void MyFunct(Double_t x, Double_t &a, Double_t &b, Double_t &c //, ... has more than the parameters a, b, c to be compute ) {
// needs x from a dataframe column and computes a, b, c
}
-------------------------------------
void genKM15(){
Double_t a, b,c ;
ROOT::RDataFrame df(1000);
auto df_1 = df.Define("x", []() { return gRandom->Uniform(1., 4); })
.Define("a", [&](double x) { MyFunct(x, a, b, c); return a; }, {"x"})
.Define("b", [&](double x) { MyFunct(x, a, b, c); return b; }, {"x"})
.Define("c", [&](double x) { MyFunct(x, a, b, c); return c; }, {"x"});
}
Is there a better way to do this with RDataFrames where I only call MyFunc just once for every row and save the values of a, b, c in the dataframe without having to call MyFunc 3 times for each row?
Thank you!
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided