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