Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
df010_trivialDataSource.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_dataframe
3/// \notebook -draw
4/// Use the "trivial data source", an example data source implementation.
5///
6/// This tutorial illustrates how use the RDataFrame in combination with a
7/// RDataSource. In this case we use a RTrivialDS, which is nothing more
8/// than a simple generator: it does not interface to any existing dataset.
9/// The RTrivialDS has a single column, col0, which has value n for entry n.
10/// The code for RTrivialDS is available at these links (header and source):
11/// - https://github.com/root-project/root/blob/master/tree/dataframe/src/RTrivialDS.cxx
12/// - https://github.com/root-project/root/blob/master/tree/dataframe/inc/ROOT/RTrivialDS.hxx
13///
14/// \macro_code
15///
16/// \date September 2017
17/// \author Danilo Piparo (CERN)
18
20{
21 auto nEvents = 128U;
22 auto d_s = ROOT::RDF::MakeTrivialDataFrame(nEvents);
23
24 /// Now we have a regular RDataFrame: the ingestion of data is delegated to
25 /// the RDataSource. At this point everything works as before.
26 auto h_s = d_s.Define("x", "1./(1. + col0)").Histo1D({"h_s", "h_s", 128, 0, .6}, "x");
27
28 /// Now we redo the same with a RDF from scratch and we draw the two histograms
29 ROOT::RDataFrame d(nEvents);
30
31 /// This lambda redoes what the TTrivialDS provides
32 auto g = []() {
33 static ULong64_t i = 0;
34 return i++;
35 };
36 auto h = d.Define("col0", g).Define("x", "1./(1. + col0)").Histo1D({"h", "h", 128, 0, .6}, "x");
37
38 auto c_s = new TCanvas();
39 c_s->SetLogy();
40 h_s->DrawClone();
41
42 auto c = new TCanvas();
43 c->SetLogy();
44 h->DrawClone();
45
46 return 0;
47}
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
unsigned long long ULong64_t
Definition RtypesCore.h:74
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
The Canvas class.
Definition TCanvas.h:23
RInterface< RDFDetail::RLoopManager, RTrivialDS > MakeTrivialDataFrame()