Cuts.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_Cuts_HH
00003 #define RIVET_Cuts_HH
00004 
00005 #include "Rivet/Rivet.hh"
00006 #include "Rivet/Cuts.fhh"
00007 #include <iostream>
00008 
00009 
00010 namespace Rivet {
00011 
00012   /// A Cuts object contains information which can be passed from the
00013   /// different Projection and Analysis objects in Rivet to the
00014   /// outside world. The main purpose of the Cut objects is
00015   /// to allow applications which use Rivet to determine whether or
00016   /// not a given analysis "makes sense" on the provided events. An
00017   /// Analysis' Cuts object should be the combination of Cuts
00018   /// from its projections, plus the additional constraints (experiment
00019   /// conditions and cuts) specific to that analysis.
00020   class Cuts {
00021     
00022   public:
00023 
00024     /// @name Standard constructors, destructors and assignment.
00025     //@{
00026     /// The default constructor.
00027     inline Cuts() { }
00028     //@}
00029 
00030   public:
00031 
00032     /// Define this cut by a quantity to be constrained and the comparison type of the constraint.
00033     Cuts& addCut(const string& quantity, const Comparison& comparison, const double value);
00034 
00035 
00036     /// Combine with another set of Cuts, using addCut iternally.
00037     inline Cuts& addCuts(const Cuts& other) {
00038       for (const_iterator cut = other.begin(); cut != other.end(); ++cut) {
00039         addCut(cut->first, MORE_EQ, cut->second.higherthan());
00040         addCut(cut->first, LESS_EQ, cut->second.lowerthan());
00041       }
00042       return *this;
00043     }
00044 
00045     /// Set the value of this cut, bypassing the combination mechanism.
00046     // inline Cuts& setCut(const string& quantity, const BinaryCut& bincut) {
00047     //   _cuts[quantity] = bincut;
00048     //   return *this;
00049     // }
00050 
00051     /// Make sure that the cuts are internally consistent. Returns no
00052     /// value, but an exception will be thrown if there is an inconsistency.
00053     bool checkConsistency() const;
00054 
00055     /// Print the parameters to the given \a stream.
00056     ostream& print(ostream& stream) const;
00057 
00058 
00059   public:
00060     /// A minimal wrapper class to define >=, <= cut pairs.
00061     class BinaryCut {
00062     public:
00063       /// Default constructor.
00064       BinaryCut() {
00065         _raw = pair<double, double>(numeric_limits<double>::max(), -numeric_limits<double>::max());
00066       }
00067 
00068       /// Valued constructor.
00069       BinaryCut(double lowerthan, double higherthan) {
00070         _raw = pair<double, double>(lowerthan, higherthan);
00071       }
00072 
00073       /// @name Accessing the low and high cut values
00074       //@{
00075       inline double& lowerthan() { return _raw.first; }
00076       inline double& higherthan() { return _raw.second; }
00077       inline const double& lowerthan() const { return _raw.first; }
00078       inline const double& higherthan() const { return _raw.second; }
00079       //@}
00080 
00081     private:
00082       pair<double, double> _raw;
00083     };
00084 
00085     /// Typedef for a named collection of binary cut objects.
00086     typedef map<string, BinaryCut> NamedBinaryCuts;
00087 
00088 
00089   public:
00090 
00091     /// @name Non-const iterators over the cuts
00092     //@{
00093     typedef NamedBinaryCuts::iterator iterator;
00094     inline iterator begin() { return _cuts.begin(); }
00095     inline iterator end() { return _cuts.end(); }
00096     inline iterator find(const string& quantity) { return _cuts.find(quantity); }
00097     //@}
00098 
00099     /// @name Non-const iterators over the cuts
00100     //@{
00101     typedef NamedBinaryCuts::const_iterator const_iterator;
00102     inline const const_iterator begin() const { return _cuts.begin(); }
00103     inline const const_iterator end() const { return _cuts.end(); }
00104     inline const const_iterator find(const string& quantity) const { return _cuts.find(quantity); }
00105     //@}
00106 
00107 
00108   private:
00109     NamedBinaryCuts _cuts;
00110 
00111   };
00112 
00113 
00114   /// Allow Cuts to be passed to an ostream.
00115   inline ostream& operator<<(ostream& os, const Cuts& cuts) {
00116     return cuts.print(os);
00117   }
00118 
00119 }
00120 
00121 #endif