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

Namespaces

 tdf004_cutFlowReport
 

Detailed Description

This tutorial shows how to get information about the efficiency of the filters applied.

1 
2 import ROOT
3 
4 def fill_tree(treeName, fileName):
5  tdf = ROOT.ROOT.Experimental.TDataFrame(50)
6  tdf.Define("b1", "(double) tdfentry_")\
7  .Define("b2", "(int) tdfentry_ * tdfentry_").Snapshot(treeName, fileName)
8 
9 # We prepare an input tree to run on
10 fileName = 'tdf004_cutFlowReport_py.root'
11 treeName = 'myTree'
12 fill_tree(treeName, fileName)
13 
14 # We read the tree from the file and create a TDataFrame, a class that
15 # allows us to interact with the data contained in the tree.
16 TDF = ROOT.ROOT.Experimental.TDataFrame
17 d = TDF(treeName, fileName)
18 
19 # ## Define cuts and create the report
20 # An optional string parameter name can be passed to the Filter method to create a named filter.
21 # Named filters work as usual, but also keep track of how many entries they accept and reject.
22 filtered1 = d.Filter('b1 > 25', 'Cut1')
23 filtered2 = d.Filter('0 == b2 % 2', 'Cut2')
24 
25 augmented1 = filtered2.Define('b3', 'b1 / b2')
26 filtered3 = augmented1.Filter('b3 < .5','Cut3')
27 
28 # Statistics are retrieved through a call to the Report method:
29 # when Report is called on the main TDataFrame object, it prints stats for all named filters declared up to that
30 # point when called on a stored chain state (i.e. a chain/graph node), it prints stats for all named filters in the
31 # section of the chain between the main TDataFrame and that node (included).
32 # Stats are printed in the same order as named filters have been added to the graph, and refer to the latest
33 # event-loop that has been run using the relevant TDataFrame.
34 print('Cut3 stats:')
35 filtered3.Report()
36 print('All stats:')
37 d.Report()
Date
May 2017
Author
Danilo Piparo

Definition in file tdf004_cutFlowReport.py.