Logo ROOT   6.14/05
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_code
8 ##
9 ## \date February 2018
10 ## \author Danilo Piparo
11 
12 import ROOT
13 
14 tdf = ROOT.RDataFrame(1024)
15 coordDefineCode = '''ROOT::VecOps::RVec<double> {0}(len);
16  std::transform({0}.begin(), {0}.end(), {0}.begin(), [](double){{return gRandom->Uniform(-1.0, 1.0);}});
17  return {0};'''
18 d = tdf.Define("len", "gRandom->Uniform(0, 16)")\
19  .Define("x", coordDefineCode.format("x"))\
20  .Define("y", coordDefineCode.format("y"))
21 
22 # Now we have in hands d, a RDataFrame with two columns, x and y, which
23 # hold collections of coordinates. The size of these collections vary.
24 # Let's now define radii out of x and y. We'll do it treating the collections
25 # stored in the columns without looping on the individual elements.
26 d1 = d.Define("r", "sqrt(x*x + y*y)")
27 
28 # Now we want to plot 2 quarters of a ring with radii .5 and 1
29 # Note how the cuts are performed on RVecs, comparing them with integers and
30 # among themselves
31 ring_h = d1.Define("rInFig", "r > .4 && r < .8 && x*y < 0")\
32  .Define("yFig", "y[rInFig]")\
33  .Define("xFig", "x[rInFig]")\
34  .Histo2D(("fig", "Two quarters of a ring", 64, -1, 1, 64, -1, 1), "xFig", "yFig")
35 
36 cring = ROOT.TCanvas()
37 ring_h.Draw("Colz")
38 cring.Print("df016_vecOps_py.png")
ROOT&#39;s RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV&#39;s and other data formats.
Definition: RDataFrame.hxx:42