rivet is hosted by Hepforge, IPPP Durham
ConstLossyFinalState.hh
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_ConstLossyFinalState_HH
00003 #define RIVET_ConstLossyFinalState_HH
00004 
00005 #include "Rivet/Tools/Logging.hh"
00006 #include "Rivet/Rivet.hh"
00007 #include "Rivet/Particle.hh"
00008 #include "Rivet/Event.hh"
00009 #include "Rivet/Projection.hh"
00010 #include "Rivet/Projections/FinalState.hh"
00011 #include "Rivet/Projections/LossyFinalState.hh"
00012 
00013 namespace Rivet {
00014 
00015 
00016   /// Functor used to implement constant random lossiness.
00017   class ConstRandomFilter {
00018   public:
00019 
00020     ConstRandomFilter(double lossFraction)
00021       : _lossFraction(lossFraction)
00022     {
00023       assert(_lossFraction >= 0);
00024     }
00025 
00026     // If operator() returns true, particle is deleted ("lost")
00027     bool operator()(const Particle&) {
00028       /// @todo Use a better RNG
00029       return (rand()/static_cast<double>(RAND_MAX) < _lossFraction);
00030     }
00031 
00032     int compare(const ConstRandomFilter& other) const {
00033       return cmp(_lossFraction, other._lossFraction);
00034     }
00035 
00036   private:
00037 
00038     double _lossFraction;
00039 
00040   };
00041 
00042 
00043 
00044   /// @brief Randomly lose a constant fraction of particles.
00045   class ConstLossyFinalState : public LossyFinalState<ConstRandomFilter> {
00046   public:
00047 
00048     /// @name Constructors
00049     //@{
00050 
00051     /// Constructor from a FinalState.
00052     ConstLossyFinalState(const FinalState& fsp, double lossfraction)
00053       : LossyFinalState<ConstRandomFilter>(fsp, ConstRandomFilter(lossfraction))
00054     {
00055       setName("ConstLossyFinalState");
00056     }
00057 
00058     /// Stand-alone constructor. Initialises the base FinalState projection.
00059     ConstLossyFinalState(double lossfraction,
00060                          double mineta = -MAXRAPIDITY,
00061                          double maxeta = MAXRAPIDITY,
00062                          double minpt = 0.0)
00063       : LossyFinalState<ConstRandomFilter>(ConstRandomFilter(lossfraction), mineta, maxeta, minpt)
00064     {
00065       setName("ConstLossyFinalState");
00066     }
00067 
00068     /// Clone on the heap.
00069     virtual const Projection* clone() const {
00070       return new ConstLossyFinalState(*this);
00071     }
00072 
00073     //@}
00074 
00075   };
00076 
00077 
00078 }
00079 
00080 #endif