Logo ROOT   6.12/06
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Namespaces
tdf011_ROOTDataSource.py File Reference

Namespaces

 tdf011_ROOTDataSource
 

Detailed Description

This tutorial illustrates how use the TDataFrame in combination with a TDataSource.

In this case we use a TRootDS. This data source allows to read a ROOT dataset from a TDataFrame in a different way, not based on the regular TDataFrame code. This allows to perform all sorts of consistency checks and illustrate the usage of the TDataSource in a didactic context.

1 
2 import ROOT
3 
4 # A simple helper function to fill a test tree: this makes the example stand-alone.
5 def fill_tree(treeName, fileName):
6  tdf = ROOT.ROOT.Experimental.TDataFrame(10000)
7  tdf.Define("b1", "(int) tdfentry_").Snapshot(treeName, fileName)
8 
9 
10 # We prepare an input tree to run on
11 fileName = "tdf011_rootDataSource_py.root"
12 treeName = "myTree"
13 fill_tree(treeName, fileName)
14 
15 # Create the data frame
16 MakeRootDataFrame = ROOT.ROOT.Experimental.TDF.MakeRootDataFrame
17 
18 d = MakeRootDataFrame(treeName, fileName)
19 
20 # Now we have a regular TDataFrame: the ingestion of data is delegated to
21 # the TDataSource. At this point everything works as before.
22 
23 h = d.Define("x", "1./(b1 + 1.)").Histo1D(("h_s", "h_s", 128, 0, .6), "x")
24 
25 # Now we redo the same with a TDF and we draw the two histograms
26 c = ROOT.TCanvas()
27 c.SetLogy()
28 h.DrawClone()
Date
September 2017
Author
Danilo Piparo

Definition in file tdf011_ROOTDataSource.py.