Projection.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_Projection_HH
00003 #define RIVET_Projection_HH
00004 
00005 #include "Rivet/Rivet.hh"
00006 #include "Rivet/Projection.fhh"
00007 #include "Rivet/ProjectionApplier.hh"
00008 #include "Rivet/ProjectionHandler.hh"
00009 #include "Rivet/Constraints.hh"
00010 #include "Rivet/ParticleName.hh"
00011 #include "Rivet/Event.fhh"
00012 #include "Rivet/Tools/Logging.hh"
00013 #include "Rivet/Cmp.fhh"
00014 
00015 
00016 namespace Rivet {
00017 
00018   /// Projection is the base class of all Projections to be used by
00019   /// Rivet. A Projection object can be assigned to an Event object and
00020   /// will then define a processed part of the information available in
00021   /// the Event, which then can be used by other Projection objects
00022   /// and/or Analysis objects.
00023   ///
00024   /// The main virtual functions to be overridden by concrete sub-classes
00025   /// are project(const Event &) and compare(const Projection &).
00026   class Projection : public ProjectionApplier {
00027  
00028   public:
00029  
00030     /// Event is a friend.
00031     friend class Event;
00032  
00033     /// The Cmp specialization for Projection is a friend.
00034     friend class Cmp<Projection>;
00035  
00036   public:
00037  
00038     /// @name Standard constructors and destructors.
00039     //@{
00040     /// The default constructor.
00041     Projection();
00042 
00043     /// Clone on the heap.
00044     virtual const Projection* clone() const = 0;
00045  
00046     /// The destructor.
00047     virtual ~Projection();
00048     //@}
00049  
00050 
00051   public:
00052  
00053     /// Take the information available in the Event and make the
00054     /// calculations necessary to obtain the projection. Note that this
00055     /// function must never be called except inside the
00056     /// Event::applyProjection(Projection *) function.
00057     virtual void project(const Event& e) = 0;
00058 
00059 
00060   protected:
00061 
00062     /// This function is used to define a unique ordering between
00063     /// different Projection objects of the same class. If this is
00064     /// considered to be equivalent to the Projector object, \a p, in the
00065     /// argument the function should return 0. If this object should be
00066     /// ordered before \a p a negative value should be returned,
00067     /// otherwise a positive value should be returned. This function must
00068     /// never be called explicitly, but should only be called from the
00069     /// operator<(const Projection &). When implementing the function in
00070     /// concrete sub-classes, it is then guaranteed that the Projection
00071     /// object \a p in the argument is of the same class as the sub-class
00072     /// and can be safely dynamically casted to that class.
00073     ///
00074     /// When implementing this function in a sub-class, the immediate
00075     /// base class version of the function should be called first. If the
00076     /// base class function returns a non-zero value, that value should
00077     /// be returned immediately. Only if zero is returned should this
00078     /// function check the member variables of the sub-class to determine
00079     /// whether this should be ordered before or after \a p, or if it is
00080     /// equivalent with \a p.
00081     virtual int compare(const Projection& p) const = 0;
00082  
00083   public:
00084 
00085     /// Determine whether this object should be ordered before the object
00086     /// \a p given as argument. If \a p is of a different class than
00087     /// this, the before() function of the corresponding type_info
00088     /// objects is used. Otherwise, if the objects are of the same class,
00089     /// the virtual compare(const Projection &) will be returned.
00090     bool before(const Projection& p) const;
00091  
00092     /// Return the BeamConstraints for this projection, not including
00093     /// recursion. Derived classes should ensure that all contained projections
00094     /// are registered in the @a _projections set for the beam constraint
00095     /// chaining to work.
00096     virtual const std::set<BeamPair> beamPairs() const;
00097 
00098     /// Get the name of the projection.
00099     virtual std::string name() const {
00100       return _name;
00101     }
00102 
00103 
00104     /// Add a colliding beam pair.
00105     Projection& addBeamPair(const ParticleName& beam1, const ParticleName& beam2) {
00106       _beamPairs.insert(BeamPair(beam1, beam2));
00107       return *this;
00108     }
00109  
00110  
00111     /// Get a Log object based on the getName() property of the calling projection object.
00112     Log& getLog() const {
00113       string logname = "Rivet.Projection." + name();
00114       return Log::getLog(logname);
00115     }
00116 
00117     /// Used by derived classes to set their name.
00118     void setName(const std::string& name) {
00119       _name = name;
00120     }
00121 
00122   protected:
00123 
00124     /// Shortcut to make a named Cmp<Projection> comparison with the @c *this
00125     /// object automatically passed as one of the parent projections.
00126     Cmp<Projection> mkNamedPCmp(const Projection& otherparent, const std::string& pname) const;
00127 
00128 
00129     /// Shortcut to make a named Cmp<Projection> comparison with the @c *this
00130     /// object automatically passed as one of the parent projections.
00131     Cmp<Projection> mkPCmp(const Projection& otherparent, const std::string& pname) const;
00132 
00133 
00134   private:
00135 
00136     /// Name variable is used by the base class messages to identify
00137     /// which derived class is being handled.
00138     string _name;
00139 
00140     /// Beam-type constraint.
00141     set<BeamPair> _beamPairs;
00142  
00143   };
00144 
00145 
00146 }
00147 
00148 
00149 /// Define "less" operator for Projection* containers in terms of the Projection::before virtual method.
00150 inline bool std::less<const Rivet::Projection *>::operator()(const Rivet::Projection* x,
00151                                                              const Rivet::Projection* y) const {
00152   return x->before(*y);
00153 }
00154 
00155 
00156 // Definition of the comparison objects and functions
00157 #include "Rivet/Cmp.hh"
00158 
00159 
00160 #endif