Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.12/07
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
tdf004_cutFlowReport.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tdataframe
3 /// This tutorial shows how to get information about the efficiency of the filters
4 /// applied
5 ///
6 /// \macro_code
7 ///
8 /// \date December 2016
9 /// \author Danilo Piparo
10 
11 using FourVector = ROOT::Math::XYZTVector;
12 using FourVectors = std::vector<FourVector>;
13 using CylFourVector = ROOT::Math::RhoEtaPhiVector;
14 
15 // A simple helper function to fill a test tree: this makes the example
16 // stand-alone.
17 void fill_tree(const char *treeName, const char *fileName)
18 {
20  int i(0);
21  d.Define("b1", [&i]() { return (double)i; })
22  .Define("b2",
23  [&i]() {
24  auto j = i * i;
25  ++i;
26  return j;
27  })
28  .Snapshot(treeName, fileName);
29 }
30 
32 {
33 
34  // We prepare an input tree to run on
35  auto fileName = "tdf004_cutFlowReport.root";
36  auto treeName = "myTree";
37  fill_tree(treeName, fileName);
38 
39  // We read the tree from the file and create a TDataFrame
40  ROOT::Experimental::TDataFrame d(treeName, fileName, {"b1", "b2"});
41 
42  // ## Define cuts and create the report
43  // Here we define two simple cuts
44  auto cut1 = [](double b1) { return b1 > 25.; };
45  auto cut2 = [](int b2) { return 0 == b2 % 2; };
46 
47  // An optional string parameter name can be passed to the Filter method to create a named filter.
48  // Named filters work as usual, but also keep track of how many entries they accept and reject.
49  auto filtered1 = d.Filter(cut1, {"b1"}, "Cut1");
50  auto filtered2 = d.Filter(cut2, {"b2"}, "Cut2");
51 
52  auto augmented1 = filtered2.Define("b3", [](double b1, int b2) { return b1 / b2; });
53  auto cut3 = [](double x) { return x < .5; };
54  auto filtered3 = augmented1.Filter(cut3, {"b3"}, "Cut3");
55 
56  // Statistics are retrieved through a call to the Report method:
57  // when Report is called on the main TDataFrame object, it prints stats for all named filters declared up to that
58  // point
59  // when called on a stored chain state (i.e. a chain/graph node), it prints stats for all named filters in the
60  // section
61  // of the chain between the main TDataFrame and that node (included).
62  // Stats are printed in the same order as named filters have been added to the graph, and refer to the latest
63  // event-loop that has been run using the relevant TDataFrame.
64  std::cout << "Cut3 stats:" << std::endl;
65  filtered3.Report();
66  std::cout << "All stats:" << std::endl;
67  d.Report();
68 }
DisplacementVector3D< CylindricalEta3D< double >, DefaultCoordinateSystemTag > RhoEtaPhiVector
3D Vector based on the eta based cylindrical coordinates rho, eta, phi in double precision.
Definition: Vector3Dfwd.h:50
Double_t x[n]
Definition: legend1.C:17
LorentzVector< PxPyPzE4D< double > > XYZTVector
LorentzVector based on x,y,x,t (or px,py,pz,E) coordinates in double precision with metric (-...
Definition: Vector4Dfwd.h:33
TInterface< TDFDetail::TFilter< F, Proxied > > Filter(F f, const ColumnNames_t &columns={}, std::string_view name="")
Append a filter to the call graph.
ROOT&#39;s TDataFrame offers a high level interface for analyses of data stored in TTrees.
Definition: TDataFrame.hxx:39