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