Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Namespaces
tdf004_cutFlowReport.py File Reference

Namespaces

 tdf004_cutFlowReport
 

Detailed Description

This tutorial shows how to get information about the efficiency of the filters applied.

1 
2 import ROOT
3 
4 fill_tree_code ='''
5 using FourVector = ROOT::Math::XYZTVector;
6 using FourVectors = std::vector<FourVector>;
7 using CylFourVector = ROOT::Math::RhoEtaPhiVector;
8 void fill_tree(const char *filename, const char *treeName)
9 {
10  TFile f(filename, "RECREATE");
11  TTree t(treeName, treeName);
12  double b1;
13  int b2;
14  t.Branch("b1", &b1);
15  t.Branch("b2", &b2);
16  for (int i = 0; i < 50; ++i) {
17  b1 = i;
18  b2 = i * i;
19  t.Fill();
20  }
21  t.Write();
22  f.Close();
23  return;
24 }
25 '''
26 
27 # We prepare an input tree to run on
28 fileName = 'tdf004_cutFlowReport_py.root'
29 treeName = 'myTree'
30 ROOT.gInterpreter.Declare(fill_tree_code)
31 ROOT.fill_tree(fileName, treeName)
32 
33 # We read the tree from the file and create a TDataFrame, a class that
34 # allows us to interact with the data contained in the tree.
35 TDF = ROOT.ROOT.Experimental.TDataFrame
36 d = TDF(treeName, fileName)
37 
38 # ## Define cuts and create the report
39 # An optional string parameter name can be passed to the Filter method to create a named filter.
40 # Named filters work as usual, but also keep track of how many entries they accept and reject.
41 filtered1 = d.Filter('b1 > 25', 'Cut1')
42 filtered2 = d.Filter('0 == b2 % 2', 'Cut2')
43 
44 augmented1 = filtered2.Define('b3', 'b1 / b2')
45 filtered3 = augmented1.Filter('b3 < .5','Cut3')
46 
47 # Statistics are retrieved through a call to the Report method:
48 # when Report is called on the main TDataFrame object, it prints stats for all named filters declared up to that
49 # point when called on a stored chain state (i.e. a chain/graph node), it prints stats for all named filters in the
50 # section of the chain between the main TDataFrame and that node (included).
51 # Stats are printed in the same order as named filters have been added to the graph, and refer to the latest
52 # event-loop that has been run using the relevant TDataFrame.
53 print('Cut3 stats:')
54 filtered3.Report()
55 print('All stats:')
56 d.Report()
Date
May 2017
Author
Danilo Piparo

Definition in file tdf004_cutFlowReport.py.