Logo ROOT   6.14/05
Reference Guide
df004_cutFlowReport.py
Go to the documentation of this file.
1 ## \file
2 ## \ingroup tutorial_dataframe
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.RDataFrame(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 = 'df004_cutFlowReport_py.root'
20 treeName = 'myTree'
21 fill_tree(treeName, fileName)
22 
23 # We read the tree from the file and create a RDataFrame, a class that
24 # allows us to interact with the data contained in the tree.
25 RDF = ROOT.ROOT.RDataFrame
26 d = RDF(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 RDataFrame object, it retrieves stats for
39 # all named filters declared up to that point. When called on a stored chain
40 # state (i.e. a chain/graph node), it retrieves stats for all named filters in
41 # the section of the chain between the main RDataFrame and that node (included).
42 # Stats are printed in the same order as named filters have been added to the
43 # graph, and refer to the latest event-loop that has been run using the relevant
44 # RDataFrame.
45 print('Cut3 stats:')
46 filtered3.Report()
47 print('All stats:')
48 allCutsReport = d.Report()
49 allCutsReport.Print()