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