LossyFinalState.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_LossyFinalState_HH
00003 #define RIVET_LossyFinalState_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 
00012 namespace Rivet {
00013 
00014 
00015   /// Randomly lose a fraction of the particles from the supplied final state projection.
00016   /// @todo This needs an overhaul to make the base projections work properly. Slicing + inheritance again.
00017   class LossyFinalState : public FinalState {
00018 
00019   public:
00020  
00021     /// @name Constructors
00022     //@{
00023 
00024     /// Constructor from FinalState.
00025     LossyFinalState(const FinalState& fsp, double lossfraction)
00026       : _lossFraction(lossfraction)
00027     {
00028       setName("LossyFinalState");
00029       addProjection(fsp, "FS");
00030       assert(_lossFraction >= 0);
00031     }
00032  
00033     /// Stand-alone constructor. Initialises the base FinalState projection.
00034     LossyFinalState(double lossfraction,
00035                     double mineta = -MAXRAPIDITY,
00036                     double maxeta = MAXRAPIDITY,
00037                     double minpt = 0.0)
00038       : _lossFraction(lossfraction)
00039     {
00040       setName("LossyFinalState");
00041       addProjection(FinalState(mineta, maxeta, minpt), "FS");
00042       assert(_lossFraction >= 0);
00043     }
00044 
00045     /// Clone on the heap.
00046     virtual const Projection* clone() const {
00047       return new LossyFinalState(*this);
00048     }
00049 
00050     //@}
00051 
00052   protected:
00053  
00054     /// Apply the projection on the supplied event.
00055     void project(const Event& e);
00056  
00057     /// Compare projections.
00058     int compare(const Projection& p) const;
00059 
00060   private:
00061 
00062     /// Inner functor used to implement the random lossiness.
00063     struct RandomFilter {
00064       RandomFilter(double lossFraction) : _lossFraction(lossFraction) {}
00065       bool operator()(const Particle& p) {
00066         /// @todo Use a better RNG
00067         return (rand()/static_cast<double>(RAND_MAX) < _lossFraction);
00068       }
00069       double _lossFraction;
00070     };
00071 
00072     /// Fraction of particles to lose.
00073     const double _lossFraction;
00074  
00075   };
00076 
00077 
00078 }
00079 
00080 
00081 #endif