Loading [MathJax]/extensions/tex2jax.js
ROOT
6.12/07
Reference Guide
ROOT Home Page
Main Page
Tutorials
User's Classes
+
Namespaces
Namespace List
+
Namespace Members
+
All
<
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Functions
<
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
u
w
x
+
Enumerations
a
e
f
g
m
p
t
w
y
+
Enumerator
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
w
+
All Classes
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
y
+
Enumerations
a
b
c
d
e
f
g
h
i
l
m
o
p
r
s
w
y
+
Enumerator
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
+
Properties
f
+
Related Functions
:
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Files
File List
+
File Members
+
All
1
2
3
4
5
6
7
8
9
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
+
Enumerations
c
e
f
i
l
m
p
r
u
x
+
Enumerator
a
c
d
e
f
g
h
i
k
l
n
o
p
r
s
v
w
+
Macros
1
2
3
4
5
6
7
8
9
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
tutorials
dataframe
tdf012_DefinesAndFiltersAsStrings.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_tdataframe
3
/// \notebook -nodraw
4
///
5
/// This tutorial illustrates how to save some typing when using TDataFrame
6
/// by invoking functions that perform jit-compiling at runtime.
7
///
8
/// \macro_code
9
///
10
/// \date October 2017
11
/// \author Guilherme Amadio
12
13
#include "
ROOT/TDataFrame.hxx
"
14
15
void
tdf012_DefinesAndFiltersAsStrings
()
16
{
17
// We will inefficiently calculate an approximation of pi by generating
18
// some data and doing very simple filtering and analysis on it
19
20
// We start by creating an empty dataframe where we will insert 10 million
21
// random points in a square of side 2.0 (that is, with an inscribed circle
22
// of radius 1.0)
23
24
size_t
npoints = 10000000;
25
ROOT::Experimental::TDataFrame
tdf(npoints);
26
27
// Define what we want inside the dataframe. We do not need to define p as an array,
28
// but we do it here to demonstrate how to use jitting with TDataFrame
29
30
// NOTE: Although it's possible to use "for (auto&& x : p)" below, it will
31
// shadow the name of the data column "x", and may cause compilation failures
32
// if the local variable and the data column are of different types or the
33
// local x variable is declared in the global scope of the lambda function
34
35
auto
pidf = tdf.Define(
"x"
,
"gRandom->Uniform(-1.0, 1.0)"
)
36
.Define(
"y"
,
"gRandom->Uniform(-1.0, 1.0)"
)
37
.Define(
"p"
,
"std::array<double, 2> v{x, y}; return v;"
)
38
.Define(
"r"
,
"double r2 = 0.0; for (auto&& x : p) r2 += x*x; return sqrt(r2);"
);
39
40
// Now we have a dataframe with columns x, y, p (which is a point based on x
41
// and y), and the radius r = sqrt(x*x + y*y). In order to approximate pi, we
42
// need to know how many of our data points fall inside the unit circle compared
43
// with the total number of points. The ratio of the areas is
44
//
45
// A_circle / A_square = pi r*r / l * l, where r = 1.0, and l = 2.0
46
//
47
// Therefore, we can approximate pi with 4 times the number of points inside the
48
// unit circle over the total number of points in our dataframe:
49
50
auto
incircle
= *(pidf.Filter(
"r <= 1.0"
).Count());
51
52
double
pi_approx = 4.0 *
incircle
/ npoints;
53
54
std::cout <<
"pi is approximately equal to "
<< pi_approx << std::endl;
55
}
incircle
REAL incircle(struct mesh *m, struct behavior *b, vertex pa, vertex pb, vertex pc, vertex pd)
Definition:
triangle.c:5863
tdf012_DefinesAndFiltersAsStrings
Definition:
tdf012_DefinesAndFiltersAsStrings.py:1
ROOT::Experimental::TDataFrame
ROOT's TDataFrame offers a high level interface for analyses of data stored in TTrees.
Definition:
TDataFrame.hxx:39
TDataFrame.hxx