Logo ROOT   6.14/05
Reference Guide
df011_ROOTDataSource.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_dataframe
3 /// \notebook
4 /// This tutorial illustrates how use the RDataFrame in combination with a
5 /// RDataSource. In this case we use a RRootDS. This data source allows to read
6 /// a ROOT dataset from a RDataFrame in a different way, not based on the
7 /// regular RDataFrame code. This allows to perform all sorts of consistency
8 /// checks and illustrate the usage of the RDataSource in a didactic context.
9 ///
10 /// \macro_code
11 ///
12 /// \date September 2017
13 /// \author Danilo Piparo
14 
15 void fill_tree(const char *treeName, const char *fileName)
16 {
17  ROOT::RDataFrame d(10000);
18  auto i = 0.;
19  d.Define("b1", [&i]() { return i++; }).Snapshot(treeName, fileName);
20 }
21 
22 using TDS = ROOT::RDF::RDataSource;
23 
25 {
26  auto fileName = "df011_ROOTDataSources.root";
27  auto treeName = "myTree";
28  fill_tree(treeName, fileName);
29 
30  auto d_s = ROOT::RDF::MakeRootDataFrame(treeName, fileName);
31 
32  /// Now we have a regular RDataFrame: the ingestion of data is delegated to
33  /// the RDataSource. At this point everything works as before.
34  auto h_s = d_s.Define("x", "1./(b1 + 1.)").Histo1D({"h_s", "h_s", 128, 0, .6}, "x");
35 
36  /// Now we redo the same with a RDF and we draw the two histograms
37  ROOT::RDataFrame d(treeName, fileName);
38  auto h = d.Define("x", "1./(b1 + 1.)").Histo1D({"h", "h", 128, 0, .6}, "x");
39 
40  auto c_s = new TCanvas();
41  c_s->SetLogy();
42  h_s->DrawClone();
43 
44  auto c = new TCanvas();
45  c->SetLogy();
46  h->DrawClone();
47 
48  return 0;
49 }
RDataFrame MakeRootDataFrame(std::string_view treeName, std::string_view fileNameGlob)
Definition: RRootDS.cxx:157
#define h(i)
Definition: RSha256.hxx:106
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV's and other data formats.
Definition: RDataFrame.hxx:42
The Canvas class.
Definition: TCanvas.h:31
#define d(i)
Definition: RSha256.hxx:102
#define c(i)
Definition: RSha256.hxx:101
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
Definition: RDataSource.hxx:91