Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.12/07
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
tdf011_ROOTDataSource.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tdataframe
3 /// \notebook
4 /// This tutorial illustrates how use the TDataFrame in combination with a
5 /// TDataSource. In this case we use a TRootDS. This data source allows to read
6 /// a ROOT dataset from a TDataFrame in a different way, not based on the
7 /// regular TDataFrame code. This allows to perform all sorts of consistency
8 /// checks and illustrate the usage of the TDataSource 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 {
18  auto i = 0.;
19  d.Define("b1", [&i]() { return i++; }).Snapshot(treeName, fileName);
20 }
21 
23 using TRootDS = ROOT::Experimental::TDF::TRootDS;
24 
26 {
27  auto fileName = "tdf011_ROOTDataSources.root";
28  auto treeName = "myTree";
29  fill_tree(treeName, fileName);
30 
31  auto d_s = ROOT::Experimental::TDF::MakeRootDataFrame(treeName, fileName);
32 
33  /// Now we have a regular TDataFrame: the ingestion of data is delegated to
34  /// the TDataSource. 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 TDF and we draw the two histograms
38  ROOT::Experimental::TDataFrame 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 }
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad...
Definition: TObject.cxx:219
TH1 * h
Definition: legend2.C:5
TDataSource defines an API that TDataFrame can use to read arbitrary data formats.
Definition: TDataSource.hxx:51
The Canvas class.
Definition: TCanvas.h:31
TDataFrame MakeRootDataFrame(std::string_view treeName, std::string_view fileNameGlob)
Definition: TRootDS.cxx:153
ROOT's TDataFrame offers a high level interface for analyses of data stored in TTrees.
Definition: TDataFrame.hxx:39