ROOT   Reference Guide
df016_vecOps.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_dataframe
3 /// \notebook -draw
4 /// \brief 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
14
15 using ROOT::RDataFrame;
16 using namespace ROOT::VecOps;
17
18 int 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 }
df016_vecOps
Definition: df016_vecOps.py:1
TRandom::Uniform
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:635
ROOT::RDataFrame
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42
v
@ v
Definition: rootcling_impl.cxx:3635
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
double
double
Definition: Converters.cxx:921
TCanvas
Definition: TCanvas.h:23
d
#define d(i)
Definition: RSha256.hxx:120
ROOT::VecOps
Definition: RVec.hxx:53
ROOT::VecOps::RVec< double >