Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
16 import ROOT
17 
18 # A simple helper function to fill a test tree: this makes the example stand-alone.
19 def 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
25 fileName = "df011_rootDataSource_py.root"
26 treeName = "myTree"
27 fill_tree(treeName, fileName)
28 
29 # Create the data frame
30 MakeRootDataFrame = ROOT.ROOT.RDF.MakeRootDataFrame
31 
32 d = 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 
37 h = 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
40 c = ROOT.TCanvas()
41 c.SetLogy()
42 h.DrawClone()