Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:57

0001 // -*- C++ -*-
0002 #ifndef RIVET_Projection_HH
0003 #define RIVET_Projection_HH
0004 
0005 #include "Rivet/Projection.fhh"
0006 #include "Rivet/ProjectionApplier.hh"
0007 #include "Rivet/ProjectionHandler.hh"
0008 #include "Rivet/Config/RivetCommon.hh"
0009 #include "Rivet/Tools/Cuts.hh"
0010 // NOTE: Cmp.hh, Event.hh and Particle.hh included at the bottom
0011 
0012 namespace Rivet {
0013 
0014 
0015   // Forward declaration
0016   class Event;
0017 
0018 
0019   /// @brief Base class for all Rivet projections.
0020   ///
0021   /// Projection is the base class of all Projections to be used by
0022   /// Rivet. A Projection object can be assigned to an Event object and
0023   /// will then define a processed part of the information available in
0024   /// the Event, which then can be used by other Projection objects
0025   /// and/or Analysis objects.
0026   ///
0027   /// The main virtual functions to be overridden by concrete sub-classes
0028   /// are project(const Event &) and compare(const Projection &).
0029   class Projection : public ProjectionApplier {
0030   public:
0031 
0032     /// Event is a friend.
0033     friend class Event;
0034 
0035     /// The Cmp specialization for Projection is a friend.
0036     friend class Cmp<Projection>;
0037 
0038 
0039 
0040     /// @name Standard constructors and destructors.
0041     /// @{
0042 
0043     /// The default constructor.
0044     Projection();
0045 
0046     /// Clone on the heap.
0047     virtual unique_ptr<Projection> clone() const = 0;
0048 
0049     /// Virtual destructor for safe inheritability.
0050     virtual ~Projection() = default;
0051 
0052     /// Suppress copy assignment.
0053     virtual Projection& operator = (const Projection&) = delete;
0054 
0055     /// Explicit (but not careful!) copy construction (required for clone()).
0056     Projection(const Projection&) = default;
0057 
0058     /// @}
0059 
0060 
0061     /// Get the name of the projection.
0062     virtual std::string name() const {
0063       return _name;
0064     }
0065 
0066     /// Get the state of the projetion.
0067     bool valid() const {
0068       return _isValid;
0069     }
0070 
0071     /// Get the state of the projetion.
0072     bool failed() const {
0073       return !valid();
0074     }
0075 
0076     /// @name Projection operation and comparison
0077     /// @{
0078 
0079     /// Take the information available in the Event and make the
0080     /// calculations necessary to obtain the projection. Note that this
0081     /// function must never be called except inside the
0082     /// Event::applyProjection(Projection *) function.
0083     virtual void project(const Event& e) = 0;
0084 
0085     /// This function is used to define a unique ordering between
0086     /// different Projection objects of the same class. If this is
0087     /// considered to be equivalent to the Projector object, \a p, in the
0088     /// argument the function should return 0. If this object should be
0089     /// ordered before \a p a negative value should be returned,
0090     /// otherwise a positive value should be returned. This function must
0091     /// never be called explicitly, but should only be called from the
0092     /// operator<(const Projection &). When implementing the function in
0093     /// concrete sub-classes, it is then guaranteed that the Projection
0094     /// object \a p in the argument is of the same class as the sub-class
0095     /// and can be safely dynamically casted to that class.
0096     ///
0097     /// When implementing this function in a sub-class, the immediate
0098     /// base class version of the function should be called first. If the
0099     /// base class function returns a non-zero value, that value should
0100     /// be returned immediately. Only if zero is returned should this
0101     /// function check the member variables of the sub-class to determine
0102     /// whether this should be ordered before or after \a p, or if it is
0103     /// equivalent with \a p.
0104     virtual CmpState compare(const Projection& p) const = 0;
0105 
0106     /// Determine whether this object should be ordered before the object
0107     /// \a p given as argument. If \a p is of a different class than
0108     /// this, the before() function of the corresponding type_info
0109     /// objects is used. Otherwise, if the objects are of the same class,
0110     /// the virtual compare(const Projection &) will be returned.
0111     bool before(const Projection& p) const;
0112 
0113     /// @}
0114 
0115 
0116 
0117     // /// @name Beam configuration
0118     // /// @todo Does it really make sense to restrict Projections to particular beam configs? Do we use this in practice?
0119     // /// @{
0120 
0121     // /// Return the allowed beam pairs on which this projection can operate, not
0122     // /// including recursion. Derived classes should ensure that all contained
0123     // /// projections are registered in the @a _projections set for the beam
0124     // /// constraint chaining to work.
0125     // /// @todo Remove the beam constraints system from projections.
0126     // virtual const std::set<PdgIdPair> beamPairs() const;
0127 
0128 
0129     // /// Add a colliding beam pair.
0130     // /// @todo This deserves a better name!
0131     // Projection& addPdgIdPair(PdgId beam1, PdgId beam2) {
0132     //   _beamPairs.insert(PdgIdPair(beam1, beam2));
0133     //   return *this;
0134     // }
0135 
0136     // /// @}
0137 
0138 
0139   protected:
0140 
0141     /// Get a Log object based on the getName() property of the calling projection object.
0142     Log& getLog() const {
0143       string logname = "Rivet.Projection." + name();
0144       return Log::getLog(logname);
0145     }
0146 
0147     /// Used by derived classes to set their name.
0148     void setName(const std::string& name) {
0149       _name = name;
0150     }
0151     
0152     /// Set the projection in an unvalid state.
0153     void fail() {
0154       _isValid = false;
0155     }
0156 
0157     /// Shortcut to make a named Cmp<Projection> comparison with the @c *this
0158     /// object automatically passed as one of the parent projections.
0159     Cmp<Projection> mkNamedPCmp(const Projection& otherparent, const std::string& pname) const;
0160 
0161     /// Shortcut to make a named Cmp<Projection> comparison with the @c *this
0162     /// object automatically passed as one of the parent projections.
0163     ///
0164     /// @note Alias for mkNamedPCmp
0165     Cmp<Projection> mkPCmp(const Projection& otherparent, const std::string& pname) const;
0166 
0167 
0168   private:
0169 
0170     /// Name variable is used by the base class messages to identify
0171     /// which derived class is being handled.
0172     string _name;
0173 
0174     /// Flag to tell if this projection is in a valid state.
0175     bool _isValid;
0176 
0177   };
0178 
0179 
0180 }
0181 
0182 
0183 /// Define "less" operator for Projection* containers in terms of the Projection::before virtual method.
0184 inline bool std::less<const Rivet::Projection *>::operator()(const Rivet::Projection* x,
0185                                                              const Rivet::Projection* y) const {
0186   return x->before(*y);
0187 }
0188 
0189 
0190 #endif
0191 
0192 
0193 #include "Rivet/Event.hh"
0194 #include "Rivet/Particle.hh"
0195 #include "Rivet/Tools/Cmp.hh"
0196 
0197 
0198 /// @def RIVET_DEFAULT_PROJ_CLONE
0199 /// Preprocessor define to prettify the manky constructor with name string argument
0200 #define RIVET_DEFAULT_PROJ_CLONE(clsname) \
0201   virtual unique_ptr<Projection> clone() const { return unique_ptr<Projection>(new clsname(*this)); }