Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
df011_ROOTDataSource.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_dataframe
3 /// \notebook -draw
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 /// \macro_image
12 ///
13 /// \date September 2017
14 /// \author Danilo Piparo
15 
16 void fill_tree(const char *treeName, const char *fileName)
17 {
18  ROOT::RDataFrame d(10000);
19  auto i = 0.;
20  d.Define("b1", [&i]() { return i++; }).Snapshot(treeName, fileName);
21 }
22 
23 using TDS = ROOT::RDF::RDataSource;
24 
25 int df011_ROOTDataSource()
26 {
27  auto fileName = "df011_ROOTDataSources.root";
28  auto treeName = "myTree";
29  fill_tree(treeName, fileName);
30 
31  auto d_s = ROOT::RDF::MakeRootDataFrame(treeName, fileName);
32 
33  /// Now we have a regular RDataFrame: the ingestion of data is delegated to
34  /// the RDataSource. At this point everything works as before.
35  auto h_s = d_s.Define("x", "1./(b1 + 1.)").Histo1D({"h_s", "h_s", 128, 0, .6}, "x");
36 
37  /// Now we redo the same with a RDF and we draw the two histograms
38  ROOT::RDataFrame d(treeName, fileName);
39  auto h = d.Define("x", "1./(b1 + 1.)").Histo1D({"h", "h", 128, 0, .6}, "x");
40 
41  auto c_s = new TCanvas();
42  c_s->SetLogy();
43  h_s->DrawClone();
44 
45  auto c = new TCanvas();
46  c->SetLogy();
47  h->DrawClone();
48 
49  return 0;
50 }