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