Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
df004_cutFlowReport.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_dataframe
3## \notebook
4## 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 (CERN)
14
15import ROOT
16
17def 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
23fileName = 'df004_cutFlowReport_py.root'
24treeName = 'myTree'
25fill_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.
29d = 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.
34filtered1 = d.Filter('b1 > 25', 'Cut1')
35filtered2 = d.Filter('0 == b2 % 2', 'Cut2')
36
37augmented1 = filtered2.Define('b3', 'b1 / b2')
38filtered3 = 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.
48print('Cut3 stats:')
49filtered3.Report()
50print('All stats:')
51allCutsReport = d.Report()
52allCutsReport.Print()
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...