Logo ROOT   6.18/05
Reference Guide
df011_ROOTDataSource.py
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 TRootDS. 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
16import ROOT
17
18# A simple helper function to fill a test tree: this makes the example stand-alone.
19def fill_tree(treeName, fileName):
20 tdf = ROOT.ROOT.RDataFrame(10000)
21 tdf.Define("b1", "(int) tdfentry_").Snapshot(treeName, fileName)
22
23
24# We prepare an input tree to run on
25fileName = "df011_rootDataSource_py.root"
26treeName = "myTree"
27fill_tree(treeName, fileName)
28
29# Create the data frame
30MakeRootDataFrame = ROOT.ROOT.RDF.MakeRootDataFrame
31
32d = MakeRootDataFrame(treeName, fileName)
33
34# Now we have a regular RDataFrame: the ingestion of data is delegated to
35# the RDataSource. At this point everything works as before.
36
37h = d.Define("x", "1./(b1 + 1.)").Histo1D(("h_s", "h_s", 128, 0, .6), "x")
38
39# Now we redo the same with a RDF and we draw the two histograms
40c = ROOT.TCanvas()
41c.SetLogy()
42h.DrawClone()
RDataFrame MakeRootDataFrame(std::string_view treeName, std::string_view fileNameGlob)
Definition: RRootDS.cxx:163