Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RCutFlowReport.cxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo CERN 02/2018
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
12#include "TString.h" // Printf
13
14#include <algorithm>
15#include <iostream>
16#include <sstream>
17#include <stdexcept>
18
19namespace ROOT {
20
21namespace RDF {
22
23void RCutFlowReport::Print() const
24{
25 auto print = AsString();
26 std::cout << print;
27}
28
29std::string RCutFlowReport::AsString() const
30{
31 std::stringstream stringRepresentation;
32
33 const auto allEntries = fCutInfos.empty() ? 0ULL : fCutInfos.begin()->GetAll();
34 for (auto &&ci : fCutInfos) {
35 const auto &name = ci.GetName();
36 const auto pass = ci.GetPass();
37 const auto all = ci.GetAll();
38 const auto eff = ci.GetEff();
39 const auto cumulativeEff = 100.f * double(pass) / double(allEntries);
40
41 std::string stringtodisplay = Form("%-20s: pass=%-10lld all=%-10lld -- eff=%3.2f %% cumulative eff=%3.2f %%",
42 name.c_str(), pass, all, eff, cumulativeEff);
43
45
47 }
48 return stringRepresentation.str();
49}
50
51const TCutInfo &RCutFlowReport::operator[](std::string_view cutName)
52{
53 if (cutName.empty()) {
54 throw std::runtime_error("Cannot look for an unnamed cut.");
55 }
56 auto pred = [&cutName](const TCutInfo &ci) { return ci.GetName() == cutName; };
57 const auto ciItEnd = fCutInfos.end();
58 const auto it = std::find_if(fCutInfos.begin(), ciItEnd, pred);
59 if (ciItEnd == it) {
60 std::string err = "Cannot find a cut called \"";
61 err += cutName;
62 err += "\". Available named cuts are: \n";
63 for (auto &&ci : fCutInfos) {
64 err += " - " + ci.GetName() + "\n";
65 }
66 throw std::runtime_error(err);
67 }
68 return *it;
69}
70
71} // End NS RDF
72
73} // End NS ROOT
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
std::vector< TCutInfo > fCutInfos
std::string AsString() const
const_iterator begin() const
const_iterator end() const