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