Event.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_Event_HH
00003 #define RIVET_Event_HH
00004 
00005 #include "Rivet/Rivet.hh"
00006 #include "Rivet/Projection.hh"
00007 
00008 namespace Rivet {
00009 
00010 
00011   /// Rivet wrapper for HepMC event and Projection references.
00012   ///
00013   /// Event is a concrete class representing an generated event in
00014   /// Rivet. It is constructed given a HepMC::GenEvent, a pointer to
00015   /// which is kept by the Event object throughout its lifetime. The user
00016   /// must therefore make sure that the corresponding HepMC::GenEvent
00017   /// will persist at least as long as the Event object.
00018   ///
00019   /// In addition to the HepMC::GenEvent object the Event also keeps
00020   /// track of all Projections object which have been applied to the
00021   /// Event so far.
00022   class Event {
00023   public:
00024 
00025     /// @name Standard constructors and destructors.
00026     //@{
00027 
00028     /// The default constructor.
00029     Event(const GenEvent& ge);
00030 
00031     /// The copy constructor.
00032     Event(const Event& e);
00033 
00034     /// The destructor
00035     ~Event();
00036 
00037     //@}
00038 
00039 
00040   public:
00041 
00042     /// Return the generated event obtained from an external event generator.
00043     const GenEvent& genEvent() const;
00044 
00045     /// The weight associated with the event.
00046     double weight() const {
00047       return _weight;
00048     }
00049 
00050 
00051   public:
00052 
00053     /// Add a projection \a p to this Event. If an equivalent Projection
00054     /// has been applied before, the Projection::project(const Event &)
00055     /// of \a p is not called and a reference to the previous equivalent
00056     /// projection is returned. If no previous Projection was found, the
00057     /// Projection::project(const Event &) of \a p is called and a
00058     /// reference to p is returned.
00059     template <typename PROJ>
00060     const PROJ& applyProjection(PROJ& p) const {
00061       const Projection* cpp(&p);
00062       std::set<const Projection*>::const_iterator old = _projections.find(cpp);
00063       if (old != _projections.end()) {
00064         const Projection& pRef = **old;
00065         return pcast<PROJ>(pRef);
00066       }
00067       // Add the projection via the Projection base class (only
00068       // possible because Event is a friend of Projection)
00069       Projection* pp = const_cast<Projection*>(cpp);
00070       pp->project(*this);
00071       _projections.insert(pp);
00072       return p;
00073     }
00074 
00075 
00076     template <typename PROJ>
00077     const PROJ& applyProjection(PROJ* pp) const {
00078       if (!pp) throw Error("Event::applyProjection(PROJ*): Projection pointer is null.");
00079       return applyProjection(*pp);
00080     }
00081 
00082 
00083   private:
00084     void _geNormAlignment();
00085 
00086 
00087     /// @brief The generated event, obtained from an external generator.
00088     /// Note that it is only externally accessible via a const reference.
00089     GenEvent const& _genEvent;
00090 
00091     GenEvent* _modGenEvent;
00092 
00093     /// The set of Projection objects applied so far.
00094     mutable std::set<ConstProjectionPtr> _projections;
00095 
00096     /// @brief The generation weight associated with the event.
00097     /// Usually 1.0. Only copied from the HepMC event once, at construction time.
00098     double _weight;
00099 
00100   };
00101 
00102 
00103 }
00104 
00105 #endif