rivet is hosted by Hepforge, IPPP Durham
Cutflow Struct Reference

A tracker of numbers & fractions of events passing sequential cuts. More...

#include <Cutflow.hh>

List of all members.

Public Member Functions

 Cutflow ()
 Default constructor.
 Cutflow (const string &cfname, const vector< string > &cutnames)
 Proper constructor.
void fillinit ()
 Fill the pre-cut counter.
bool fill (size_t icut, bool cutresult)
 Fill the {icut}'th post-cut counter.
bool fill (const vector< bool > &cutresults)
 Fill all cut-state counters from an Ncut-element results vector.
bool filltail (const vector< bool > &cutresults)
 Fill the N trailing post-cut counters, when supplied with an N-element results vector.
string str () const
 Create a string representation.
void print (ostream &os) const
 Print string representation to a stream.

Public Attributes

string name
size_t ncuts
vector< string > cuts
vector< int > counts

Detailed Description

A tracker of numbers & fractions of events passing sequential cuts.

Definition at line 10 of file Cutflow.hh.


Constructor & Destructor Documentation

Cutflow ( ) [inline]

Default constructor.

Does nothing! Just to allow storage in STL containers and use as a member variable without using the init list

Definition at line 15 of file Cutflow.hh.

{}
Cutflow ( const string &  cfname,
const vector< string > &  cutnames 
) [inline]

Proper constructor.

Definition at line 18 of file Cutflow.hh.

      : name(cfname), ncuts(cutnames.size()), cuts(cutnames), counts(ncuts+1, 0)
    {  }

Member Function Documentation

bool fill ( size_t  icut,
bool  cutresult 
) [inline]

Fill the {icut}'th post-cut counter.

Note:
Returns the cut result to allow 'side-effect' cut-flow filling in an if-statement

Definition at line 30 of file Cutflow.hh.

                                           {
      if (cutresult) counts[icut+1] += 1;
      return cutresult;
    }
bool fill ( const vector< bool > &  cutresults) [inline]

Fill all cut-state counters from an Ncut-element results vector.

This function is to be used to fill all of an event's pre- and post-cut state counters at once, including the incoming event counter. It must not be mixed with calls to the fill(size_t, bool) and fillinit() methods, or double-counting will occur.

Note:
Returns the overall cut result to allow 'side-effect' cut-flow filling in an if-statement

Definition at line 43 of file Cutflow.hh.

                                              {
      if (cutresults.size() != ncuts)
        throw RangeError("Number of filled cut results needs to match the Cutflow construction");
      counts[0] += 1;
      for (size_t i = 0; i < ncuts; ++i) {
        if (cutresults[i]) counts[i+1] += 1; else break;
      }
      return all(cutresults);
    }
void fillinit ( ) [inline]

Fill the pre-cut counter.

Definition at line 23 of file Cutflow.hh.

                    {
      counts[0] += 1;
    }
bool filltail ( const vector< bool > &  cutresults) [inline]

Fill the N trailing post-cut counters, when supplied with an N-element results vector.

The cutresults vector represents the boolean results of the last N cuts. This function allows mixing of cut-flow filling with higher-level analyze() function escapes such as the vetoEvent directive. The initial state (state 0) is not incremented.

Note:
Returns the overall cut result to allow 'side-effect' cut-flow filling in an if-statement

Definition at line 60 of file Cutflow.hh.

                                                  {
      if (cutresults.size() > ncuts)
        throw RangeError("Number of filled cut results needs to match the Cutflow construction");
      const size_t offset = counts.size() - cutresults.size();
      for (size_t i = 0; i < cutresults.size(); ++i) {
        if (cutresults[i]) counts[offset+i] += 1; else break;
      }
      return all(cutresults);
    }
void print ( ostream &  os) const [inline]

Print string representation to a stream.

Definition at line 89 of file Cutflow.hh.

                                  {
      os << str() << flush;
    }
string str ( ) const [inline]

Create a string representation.

Definition at line 71 of file Cutflow.hh.

                       {
      stringstream ss;
      ss << name << " cut-flow:";
      size_t maxlen = 0;
      for (const string& t : cuts) maxlen = max(t.length(), maxlen);
      for (size_t i = 0; i <= ncuts; ++i) {
        const int pcttot = (counts[0] == 0) ? -1 : int(100*counts[i]/double(counts[0]));
        const int pctinc = (i == 0 || counts[i-1] == 0) ? -1 : int(100*counts[i]/double(counts[i-1]));
        ss << "\n" << setw(maxlen+5) << left
           << (i == 0 ? "" : "Pass "+cuts[i-1]) << "   " << right
           << setw(toString(counts[0]).length()) << toString(counts[i]) << "    "
           << setw(4) << (pcttot < 0 ? "- " : toString(pcttot)+"%") << "    "
           << setw(4) << (pctinc < 0 ? "- " : toString(pctinc)+"%");
      }
      return ss.str();
    }

Member Data Documentation

vector<int> counts

Definition at line 96 of file Cutflow.hh.

vector<string> cuts

Definition at line 95 of file Cutflow.hh.

string name

Definition at line 93 of file Cutflow.hh.

size_t ncuts

Definition at line 94 of file Cutflow.hh.


The documentation for this struct was generated from the following file: