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