This tutorial illustrates how to use jit-compiling features of RDataFrame to define data using C++ code in a Python script
import ROOT
npoints = 10000000
tdf = ROOT.ROOT.RDataFrame(npoints)
pidf = tdf.Define("x", "gRandom->Uniform(-1.0, 1.0)") \
.Define("y", "gRandom->Uniform(-1.0, 1.0)") \
.Define("p", "std::array<double, 2> v{x, y}; return v;") \
.Define("r", "double r2 = 0.0; for (auto&& w : p) r2 += w*w; return sqrt(r2);")
incircle = pidf.Filter("r <= 1.0").Count().GetValue()
pi_approx = 4.0 * incircle / npoints
print("pi is approximately equal to %g" % (pi_approx))
pi is approximately equal to 3.14146
- Date
- October 2017
- Author
- Guilherme Amadio
Definition in file df012_DefinesAndFiltersAsStrings.py.