ROOT
master
Reference Guide
Loading...
Searching...
No Matches
df016_vecOps.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_dataframe
3
## \notebook -draw
4
## Process collections in RDataFrame with the help of RVec.
5
##
6
## This tutorial shows the potential of the VecOps approach for treating collections
7
## stored in datasets, a situation very common in HEP data analysis.
8
##
9
## \macro_image
10
## \macro_code
11
##
12
## \date February 2018
13
## \author Danilo Piparo (CERN)
14
15
import
ROOT
16
17
df =
ROOT.RDataFrame
(1024)
18
coordDefineCode =
'''ROOT::RVecD {0}(len);
19
std::transform({0}.begin(), {0}.end(), {0}.begin(), [](double){{return gRandom->Uniform(-1.0, 1.0);}});
20
return {0};'''
21
d =
df.Define
(
"len"
,
"gRandom->Uniform(0, 16)"
)\
22
.Define(
"x"
,
coordDefineCode.format
(
"x"
))\
23
.Define(
"y"
,
coordDefineCode.format
(
"y"
))
24
25
# Now we have in our hands d, a RDataFrame with two columns, x and y, which
26
# hold collections of coordinates. The sizes of these collections vary.
27
# Let's now define radii radii from the x and y coordinates. We'll do it treating
28
# the collections stored in the columns without looping on the individual elements.
29
d1 =
d.Define
(
"r"
,
"sqrt(x*x + y*y)"
)
30
31
# Now we want to plot 2 quarters of a ring with radii .5 and 1.
32
# Note how the cuts are performed on RVecs, comparing them with integers and
33
# among themselves.
34
ring_h =
d1.Define
(
"rInFig"
,
"r > .5 && r < 1 && x*y < 0"
)\
35
.Define(
"yFig"
,
"y[rInFig]"
)\
36
.Define(
"xFig"
,
"x[rInFig]"
)\
37
.Histo2D((
"fig"
,
"Two quarters of a ring"
, 64, -1.1, 1.1, 64, -1.1, 1.1),
"xFig"
,
"yFig"
)
38
39
cring =
ROOT.TCanvas
()
40
ring_h.Draw
(
"Colz"
)
41
cring.SaveAs
(
"df016_ring.png"
)
42
43
print(
"Saved figure to df016_ring.png"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::RDataFrame
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Definition
RDataFrame.hxx:41
tutorials
analysis
dataframe
df016_vecOps.py
ROOT master - Reference Guide Generated on Thu Jan 30 2025 12:41:56 (GVA Time) using Doxygen 1.10.0