Logo ROOT  
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 df = ROOT.RDataFrame(50)
17 df.Define("b1", "(double) rdfentry_")\
18 .Define("b2", "(int) rdfentry_ * rdfentry_").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.
27d = ROOT.RDataFrame(treeName, fileName)
28
29# ## Define cuts and create the report
30# An optional string parameter name can be passed to the Filter method to create a named filter.
31# Named filters work as usual, but also keep track of how many entries they accept and reject.
32filtered1 = d.Filter('b1 > 25', 'Cut1')
33filtered2 = d.Filter('0 == b2 % 2', 'Cut2')
34
35augmented1 = filtered2.Define('b3', 'b1 / b2')
36filtered3 = augmented1.Filter('b3 < .5','Cut3')
37
38# Statistics are retrieved through a call to the Report method:
39# when Report is called on the main RDataFrame object, it retrieves stats for
40# all named filters declared up to that point. When called on a stored chain
41# state (i.e. a chain/graph node), it retrieves stats for all named filters in
42# the section of the chain between the main RDataFrame and that node (included).
43# Stats are printed in the same order as named filters have been added to the
44# graph, and refer to the latest event-loop that has been run using the relevant
45# RDataFrame.
46print('Cut3 stats:')
47filtered3.Report()
48print('All stats:')
49allCutsReport = d.Report()
50allCutsReport.Print()
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42