Logo ROOT  
Reference Guide
df016_vecOps.C File Reference

Detailed Description

View in nbviewer Open in SWAN Process collections in RDataFrame with the help of RVec.

This tutorial shows the potential of the VecOps approach for treating collections stored in datasets, a situation very common in HEP data analysis.

using namespace ROOT::VecOps;
// We re-create a set of points in a square.
// This is a technical detail, just to create a dataset to play with!
auto unifGen = [](double) { return gRandom->Uniform(-1.0, 1.0); };
auto vGen = [&](int len) {
std::transform(v.begin(), v.end(), v.begin(), unifGen);
return v;
RDataFrame d(1024);
auto d0 = d.Define("len", []() { return (int)gRandom->Uniform(0, 16); })
.Define("x", vGen, {"len"})
.Define("y", vGen, {"len"});
// Now we have in hands d, a RDataFrame with two columns, x and y, which
// hold collections of coordinates. The size of these collections vary.
// Let's now define radii out of x and y. We'll do it treating the collections
// stored in the columns without looping on the individual elements.
auto d1 = d0.Define("r", "sqrt(x*x + y*y)");
// Now we want to plot 2 quarters of a ring with radii .5 and 1
// Note how the cuts are performed on RVecs, comparing them with integers and
// among themselves
auto ring_h = d1.Define("rInFig", "r > .4 && r < .8 && x*y < 0")
.Define("yFig", "y[rInFig]")
.Define("xFig", "x[rInFig]")
.Histo2D({"fig", "Two quarters of a ring", 64, -1, 1, 64, -1, 1}, "xFig", "yFig");
auto cring = new TCanvas();
return 0;
February 2018
Danilo Piparo (CERN)

Definition in file df016_vecOps.C.

Definition: df016_vecOps.py:1
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:672
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTree,...
Definition: RDataFrame.hxx:42
@ v
Definition: rootcling_impl.cxx:3664
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
Definition: Converters.cxx:939
The Canvas class.
Definition: TCanvas.h:23
#define d(i)
Definition: RSha256.hxx:102
Definition: TCollectionProxyInfo.h:42
ROOT::VecOps::RVec< double >