1 #ifndef RIVET_Cutflow_HH 2 #define RIVET_Cutflow_HH 4 #include "Rivet/Tools/Utils.hh" 18 Cutflow(
const string& cfname,
const vector<string>& cutnames)
19 : name(cfname), ncuts(cutnames.size()), cuts(cutnames), counts(ncuts+1, 0)
24 counts.front() += weight;
30 bool fill(
size_t icut,
bool cutresult=
true,
double weight=1.) {
31 if (cutresult) counts.at(icut) += weight;
41 bool fill(
size_t icut,
double weight) {
42 return fill(icut,
true, weight);
53 bool fill(
const vector<bool>& cutresults,
double weight=1.) {
54 if (cutresults.size() != ncuts)
55 throw RangeError(
"Number of filled cut results needs to match the Cutflow construction");
57 for (
size_t i = 0; i < ncuts; ++i) {
58 if (cutresults[i]) counts.at(i+1) += weight;
else break;
60 return all(cutresults);
74 bool filltail(
const vector<bool>& cutresults,
double weight=1.) {
75 if (cutresults.size() > ncuts)
76 throw RangeError(
"Number of filled cut results needs to match the Cutflow construction");
77 const size_t offset = counts.size() - cutresults.size();
78 for (
size_t i = 0; i < cutresults.size(); ++i) {
79 if (cutresults[i]) counts.at(offset+i) += weight;
else break;
81 return all(cutresults);
86 for (
double& x : counts) x *= factor;
91 scale(norm/counts.at(icut));
97 ss << fixed << setprecision(1) << counts.front();
98 const size_t count0len = ss.str().length();
100 ss << name <<
" cut-flow:\n";
101 size_t maxnamelen = 0;
102 for (
const string& t : cuts)
103 maxnamelen =
max(t.length(), maxnamelen);
104 ss << setw(maxnamelen+5) <<
"" <<
" " 105 << setw(count0len) << right <<
"Count" <<
" " 106 << setw(6) << right <<
"A_cumu" <<
" " 107 << setw(6) << right <<
"A_incr";
108 for (
size_t i = 0; i <= ncuts; ++i) {
109 const int pcttot = (counts.front() == 0) ? -1 : round(100*counts.at(i)/double(counts.front()));
110 const int pctinc = (i == 0 || counts.at(i-1) == 0) ? -1 : round(100*counts.at(i)/double(counts.at(i-1)));
112 ss2 << fixed << setprecision(1) << counts.at(i);
113 const string countstr = ss2.str(); ss2.str(
"");
114 ss2 << fixed << setprecision(3) << pcttot <<
"%";
115 const string pcttotstr = ss2.str(); ss2.str(
"");
116 ss2 << fixed << setprecision(3) << pctinc <<
"%";
117 const string pctincstr = ss2.str();
119 << setw(maxnamelen+5) << left << (i == 0 ?
"" :
"Pass "+cuts.at(i-1)) <<
" " 120 << setw(count0len) << right << countstr <<
" " 121 << setw(6) << right << (pcttot < 0 ?
"- " : pcttotstr) <<
" " 122 << setw(6) << right << (pctinc < 0 ?
"- " : pctincstr);
129 os <<
str() << flush;
135 vector<double> counts;
141 inline ostream& operator << (ostream& os,
const Cutflow& cf) {
142 return os << cf.
str();
154 Cutflows(
const vector<Cutflow>& cutflows) : cfs(cutflows) { }
162 void addCutflow(
const string& cfname,
const vector<string>& cutnames) {
163 cfs.push_back(
Cutflow(cfname, cutnames));
167 Cutflow& operator [] (
size_t i) {
return cfs[i]; }
169 const Cutflow& operator [] (
size_t i)
const {
return cfs[i]; }
174 if (cf.name == name)
return cf;
175 throw UserError(
"Requested cut-flow name '" + name +
"' does not exist");
178 const Cutflow& operator [] (
const string& name)
const {
180 if (cf.name == name)
return cf;
181 throw UserError(
"Requested cut-flow name '" + name +
"' does not exist");
186 for (
Cutflow& cf : cfs) cf.fillinit(weight);
190 bool fill(
size_t icut,
bool cutresult=
true,
double weight=1.) {
191 for (
Cutflow& cf : cfs) cf.fill(icut, cutresult, weight);
201 bool fill(
size_t icut,
double weight) {
202 return fill(icut,
true, weight);
211 for (
Cutflow& cf : cfs) cf.scale(factor);
217 for (
Cutflow& cf : cfs) cf.normalize(norm, icut);
230 os <<
str() << flush;
238 inline ostream& operator << (ostream& os,
const Cutflows& cfs) {
239 return os << cfs.
str();
Definition: ALICE_2010_I880049.cc:13
bool fill(size_t icut, bool cutresult=true, double weight=1.)
Fill the {icut}'th post-cut counter, starting at icut=1 for first cut, with the same result for all {...
Definition: Cutflow.hh:190
void normalize(double norm, size_t icut=0)
Scale the cutflow weights so that the weight count after cut icut is norm.
Definition: Cutflow.hh:90
void scale(double factor)
Scale the cutflow weights by the given factor.
Definition: Cutflow.hh:85
bool fill(size_t icut, double weight)
Fill the {icut}'th post-cut counter, starting at icut=1 for first cut, with the same result for all {...
Definition: Cutflow.hh:201
void fillinit(double weight=1.)
Fill the pre-cuts state counter for all contained {Cutflow}s.
Definition: Cutflow.hh:185
Error specialisation for where the problem is between the chair and the computer. ...
Definition: Exceptions.hh:55
void print(ostream &os) const
Print string representation to a stream.
Definition: Cutflow.hh:229
Cutflows()
Do-nothing default constructor.
Definition: Cutflow.hh:151
string str() const
Create a string representation.
Definition: Cutflow.hh:221
string str() const
Create a string representation.
Definition: Cutflow.hh:95
Cutflow(const string &cfname, const vector< string > &cutnames)
Proper constructor.
Definition: Cutflow.hh:18
Cutflows(const vector< Cutflow > &cutflows)
Populating constructor.
Definition: Cutflow.hh:154
bool filltail(const vector< bool > &cutresults, double weight=1.)
Fill the N trailing post-cut counters, when supplied with an N-element results vector.
Definition: Cutflow.hh:74
Cutflow()
Default constructor.
Definition: Cutflow.hh:15
void print(ostream &os) const
Print string representation to a stream.
Definition: Cutflow.hh:128
void scale(double factor)
Scale the contained {Cutflow}s by the given factor.
Definition: Cutflow.hh:210
bool fill(size_t icut, bool cutresult=true, double weight=1.)
Fill the {icut}'th post-cut counter, starting at icut=1 for first cut.
Definition: Cutflow.hh:30
bool all(const CONTAINER &c)
Return true if x is true for all x in container c, otherwise false.
Definition: Utils.hh:301
double max(const vector< double > &in, double errval=DBL_NAN)
Find the maximum value in the vector.
Definition: Utils.hh:465
void addCutflow(const string &cfname, const vector< string > &cutnames)
Append a newly constructed Cutflow to the list.
Definition: Cutflow.hh:162
void addCutflow(const Cutflow &cf)
Append a provided Cutflow to the list.
Definition: Cutflow.hh:157
A tracker of numbers & fractions of events passing sequential cuts.
Definition: Cutflow.hh:10
bool fill(size_t icut, double weight)
Fill the {icut}'th post-cut counter, starting at icut=1 for first cut (cutvalue=true overload) ...
Definition: Cutflow.hh:41
A container for several Cutflow objects, with some convenient batch access.
Definition: Cutflow.hh:148
bool fill(const vector< bool > &cutresults, double weight=1.)
Fill all cut-state counters from an Ncut-element results vector.
Definition: Cutflow.hh:53
void fillinit(double weight=1.)
Fill the pre-cut counter.
Definition: Cutflow.hh:23
Error for e.g. use of invalid bin ranges.
Definition: Exceptions.hh:22
void normalize(double norm, size_t icut=0)
Definition: Cutflow.hh:216