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