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