Logo ROOT  
Reference Guide
df016_vecOps.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_dataframe
3## \notebook -draw
4## This tutorial shows the potential of the VecOps approach for treating collections
5## stored in datasets, a situation very common in HEP data analysis.
6##
7## \macro_image
8## \macro_code
9##
10## \date February 2018
11## \author Danilo Piparo
12
13import ROOT
14
15df = ROOT.RDataFrame(1024)
16coordDefineCode = '''ROOT::VecOps::RVec<double> {0}(len);
17 std::transform({0}.begin(), {0}.end(), {0}.begin(), [](double){{return gRandom->Uniform(-1.0, 1.0);}});
18 return {0};'''
19d = df.Define("len", "gRandom->Uniform(0, 16)")\
20 .Define("x", coordDefineCode.format("x"))\
21 .Define("y", coordDefineCode.format("y"))
22
23# Now we have in hands d, a RDataFrame with two columns, x and y, which
24# hold collections of coordinates. The size of these collections vary.
25# Let's now define radii out of x and y. We'll do it treating the collections
26# stored in the columns without looping on the individual elements.
27d1 = d.Define("r", "sqrt(x*x + y*y)")
28
29# Now we want to plot 2 quarters of a ring with radii .5 and 1
30# Note how the cuts are performed on RVecs, comparing them with integers and
31# among themselves
32ring_h = d1.Define("rInFig", "r > .4 && r < .8 && x*y < 0")\
33 .Define("yFig", "y[rInFig]")\
34 .Define("xFig", "x[rInFig]")\
35 .Histo2D(("fig", "Two quarters of a ring", 64, -1, 1, 64, -1, 1), "xFig", "yFig")
36
37cring = ROOT.TCanvas()
38ring_h.Draw("Colz")
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42