Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
df016_vecOps.C
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_code
10/// \macro_image
11///
12/// \date February 2018
13/// \author Danilo Piparo (CERN)
14
16using namespace ROOT::VecOps;
17
18int df016_vecOps()
19{
20 // We re-create a set of points in a square.
21 // This is a technical detail, just to create a dataset to play with!
22 auto unifGen = [](double) { return gRandom->Uniform(-1.0, 1.0); };
23 auto vGen = [&](int len) {
24 RVec<double> v(len);
25 std::transform(v.begin(), v.end(), v.begin(), unifGen);
26 return v;
27 };
28 RDataFrame d(1024);
29 auto d0 = d.Define("len", []() { return (int)gRandom->Uniform(0, 16); })
30 .Define("x", vGen, {"len"})
31 .Define("y", vGen, {"len"});
32
33 // Now we have in hands d, a RDataFrame with two columns, x and y, which
34 // hold collections of coordinates. The size of these collections vary.
35 // Let's now define radii out of x and y. We'll do it treating the collections
36 // stored in the columns without looping on the individual elements.
37 auto d1 = d0.Define("r", "sqrt(x*x + y*y)");
38
39 // Now we want to plot 2 quarters of a ring with radii .5 and 1
40 // Note how the cuts are performed on RVecs, comparing them with integers and
41 // among themselves
42 auto ring_h = d1.Define("rInFig", "r > .4 && r < .8 && x*y < 0")
43 .Define("yFig", "y[rInFig]")
44 .Define("xFig", "x[rInFig]")
45 .Histo2D({"fig", "Two quarters of a ring", 64, -1, 1, 64, -1, 1}, "xFig", "yFig");
46
47 auto cring = new TCanvas();
48 ring_h->DrawCopy("Colz");
49
50 return 0;
51}
double
#define d(i)
Definition RSha256.hxx:102
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
A "std::vector"-like collection of values implementing handy operation to analyse them.
Definition RVec.hxx:296
The Canvas class.
Definition TCanvas.h:23
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition TRandom.cxx:672