Logo ROOT  
Reference Guide
df012_DefinesAndFiltersAsStrings Namespace Reference

Variables

 df = ROOT.RDataFrame(npoints)
 incircle = pidf.Filter("r <= 1.0").Count().GetValue()
 Now we have a dataframe with columns x, y, p (which is a point based on x and y), and the radius r = sqrt(x*x + y*y).
int npoints = 10000000
 We will inefficiently calculate an approximation of pi by generating some data and doing very simple filtering and analysis on it.
float pi_approx = 4.0 * incircle / npoints
 pidf
 Define what data we want inside the dataframe.

Variable Documentation

◆ df

df012_DefinesAndFiltersAsStrings.df = ROOT.RDataFrame(npoints)

Definition at line 25 of file df012_DefinesAndFiltersAsStrings.py.

◆ incircle

df012_DefinesAndFiltersAsStrings.incircle = pidf.Filter("r <= 1.0").Count().GetValue()

Now we have a dataframe with columns x, y, p (which is a point based on x and y), and the radius r = sqrt(x*x + y*y).

In order to approximate pi, we need to know how many of our data points fall inside the circle of radius one compared with the total number of points. The ratio of the areas is

A_circle / A_square = pi r*r / l * l, where r = 1.0, and l = 2.0

Therefore, we can approximate pi with four times the number of points inside the unit circle over the total number of points:

Definition at line 45 of file df012_DefinesAndFiltersAsStrings.py.

◆ npoints

int df012_DefinesAndFiltersAsStrings.npoints = 10000000

We will inefficiently calculate an approximation of pi by generating some data and doing very simple filtering and analysis on it.

We start by creating an empty dataframe where we will insert 10 million random points in a square of side 2.0 (that is, with an inscribed unit circle).

Definition at line 24 of file df012_DefinesAndFiltersAsStrings.py.

◆ pi_approx

float df012_DefinesAndFiltersAsStrings.pi_approx = 4.0 * incircle / npoints

Definition at line 47 of file df012_DefinesAndFiltersAsStrings.py.

◆ pidf

df012_DefinesAndFiltersAsStrings.pidf
Initial value:
1= df.Define("x", "gRandom->Uniform(-1.0, 1.0)") \
2 .Define("y", "gRandom->Uniform(-1.0, 1.0)") \
3 .Define("p", "std::array<double, 2> v{x, y}; return v;") \
4 .Define("r", "double r2 = 0.0; for (auto&& w : p) r2 += w*w; return sqrt(r2);")

Define what data we want inside the dataframe.

We do not need to define p as an array, but we do it here to demonstrate how to use jitting with RDataFrame.

Definition at line 30 of file df012_DefinesAndFiltersAsStrings.py.