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