Logo ROOT   6.14/05
Reference Guide
df005_fillAnyObject.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_dataframe
3 /// \notebook -nodraw
4 /// This tutorial shows how to fill any object the class of which exposes a
5 /// `Fill` method.
6 /// \macro_code
7 ///
8 /// \date March 2017
9 /// \author Danilo Piparo
10 
11 // A simple helper function to fill a test tree: this makes the example
12 // stand-alone.
13 void fill_tree(const char *treeName, const char *fileName)
14 {
15  ROOT::RDataFrame d(100);
16  auto i = 0.;
17  d.Define("b1", [&i]() { return i; })
18  .Define("b2",
19  [&i]() {
20  float j = i * i;
21  ++i;
22  return j;
23  })
24  .Snapshot(treeName, fileName);
25 }
26 
27 int df005_fillAnyObject()
28 {
29 
30  // We prepare an input tree to run on
31  auto fileName = "df005_fillAnyObject.root";
32  auto treeName = "myTree";
33  fill_tree(treeName, fileName);
34 
35  // We read the tree from the file and create a RDataFrame.
36  ROOT::RDataFrame d(treeName, fileName);
37 
38  // ## Filling any object
39  // We now fill some objects which are instances of classes which expose a
40  // `Fill` method with some input arguments.
41  auto th1d = d.Fill<double>(TH1D("th1d", "th1d", 64, 0, 128), {"b1"});
42  auto th1i = d.Fill<float>(TH1I("th1i", "th1i", 64, 0, 128), {"b2"});
43  auto th2d = d.Fill<double, float>(TH2D("th2d", "th2d", 64, 0, 128, 64, 0, 1024), {"b1", "b2"});
44 
45  auto c1 = new TCanvas();
46  th1d->DrawClone();
47 
48  auto c2 = new TCanvas();
49  th1i->DrawClone();
50 
51  auto c3 = new TCanvas();
52  th2d->DrawClone("COLZ");
53 
54  return 0;
55 }
THist< 1, int, THistStatContent > TH1I
Definition: THist.hxx:287
return c1
Definition: legend1.C:41
ROOT&#39;s RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV&#39;s and other data formats.
Definition: RDataFrame.hxx:42
The Canvas class.
Definition: TCanvas.h:31
#define d(i)
Definition: RSha256.hxx:102
return c2
Definition: legend2.C:14
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:290
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:284
return c3
Definition: legend3.C:15