Logo ROOT   6.14/05
Reference Guide
df016_vecOps.C
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 using ROOT::RDataFrame;
13 using namespace ROOT::VecOps;
14 
15 int df016_vecOps()
16 {
17  // We re-create a set of points in a square.
18  // This is a technical detail, just to create a dataset to play with!
19  auto unifGen = [](double) { return gRandom->Uniform(-1.0, 1.0); };
20  auto vGen = [&](int len) {
21  RVec<double> v(len);
22  std::transform(v.begin(), v.end(), v.begin(), unifGen);
23  return v;
24  };
25  RDataFrame d(1024);
26  auto d0 = d.Define("len", []() { return (int)gRandom->Uniform(0, 16); })
27  .Define("x", vGen, {"len"})
28  .Define("y", vGen, {"len"});
29 
30  // Now we have in hands d, a RDataFrame with two columns, x and y, which
31  // hold collections of coordinates. The size of these collections vary.
32  // Let's now define radii out of x and y. We'll do it treating the collections
33  // stored in the columns without looping on the individual elements.
34  auto d1 = d0.Define("r", "sqrt(x*x + y*y)");
35 
36  // Now we want to plot 2 quarters of a ring with radii .5 and 1
37  // Note how the cuts are performed on RVecs, comparing them with integers and
38  // among themselves
39  auto ring_h = d1.Define("rInFig", "r > .4 && r < .8 && x*y < 0")
40  .Define("yFig", "y[rInFig]")
41  .Define("xFig", "x[rInFig]")
42  .Histo2D({"fig", "Two quarters of a ring", 64, -1, 1, 64, -1, 1}, "xFig", "yFig");
43 
44  TCanvas cring;
45  ring_h->Draw("Colz");
46  cring.Print("df016_vecOps.png");
47 
48  return 0;
49 }
A "std::vector"-like collection of values implementing handy operation to analyse them...
Definition: RVec.hxx:146
SVector< double, 2 > v
Definition: Dict.h:5
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
Definition: TPad.cxx:4617
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
The Canvas class.
Definition: TCanvas.h:31
#define d(i)
Definition: RSha256.hxx:102
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:627
virtual void Draw(Option_t *option="")
Draw a canvas.
Definition: TCanvas.cxx:826