23 tdf = ROOT.ROOT.RDataFrame(npoints)
28 pidf = tdf.Define(
"x",
"gRandom->Uniform(-1.0, 1.0)") \
29 .Define(
"y",
"gRandom->Uniform(-1.0, 1.0)") \
30 .Define(
"p",
"std::array<double, 2> v{x, y}; return v;") \
31 .Define(
"r", "double r2 = 0.0; for (auto&& w : p) r2 += w*w; return sqrt(r2);")
43 incircle = pidf.Filter(
"r <= 1.0").Count().GetValue()
45 pi_approx = 4.0 * incircle / npoints
47 print(
"pi is approximately equal to %g" % (pi_approx))