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 #include "HepMC/GenEvent.h"
00008 #include "Event.fhh"
00009 
00010 
00011 namespace Rivet {
00012 
00013   /// Forward typedef from HepMC.
00014   typedef HepMC::GenEvent GenEvent;
00015   
00016   /// Forward typedef from HepMC.
00017   typedef HepMC::GenVertex GenVertex;
00018 
00019 
00020   /// Event is a concrete class representing an generated event in
00021   /// Rivet. It is constructed given a HepMC::GenEvent, a pointer to
00022   /// which is kept by the Event object throughout its lifetime. The user
00023   /// must therefore make sure that the corresponding HepMC::GenEvent
00024   /// will persist at least as long as the Event object.
00025   ///
00026   /// In addition to the HepMC::GenEvent object the Event also keeps
00027   /// track of all Projections object which have been applied to the
00028   /// Event so far.
00029   class Event {
00030 
00031   public:
00032 
00033     /// @name Standard constructors and destructors.
00034     //@{
00035     /// The default constructor.
00036     inline Event(const GenEvent & geneve)
00037       : theGenEvent(&geneve), theWeight(1.0) {
00038       if ( geneve.weights().size() ) theWeight = geneve.weights()[0];
00039     }
00040 
00041     /// The copy constructor.
00042     inline Event(const Event& x)  
00043       : theGenEvent(x.theGenEvent), theWeight(x.theWeight) 
00044     { }
00045 
00046     /// The destructor.
00047     virtual ~Event() { }
00048     //@}
00049 
00050   public:
00051 
00052     /// Return the generated event obtained from an external event generator.
00053     inline const GenEvent& genEvent() const { return *theGenEvent; }
00054 
00055     /// Add a projection \a p to this Event. If an equivalent Projection
00056     /// has been applied before, the Projection::project(const Event &)
00057     /// of \a p is not called and a reference to the previous equivalent
00058     /// projection is returned. If no previous Projection was found, the
00059     /// Projection::project(const Event &) of \a p is called and a
00060     /// reference to p is returned.
00061     template <typename PROJ>
00062     inline const PROJ& applyProjection(PROJ& p) const {
00063       std::set<const Projection*>::const_iterator old = theProjections.find(&p);
00064       if ( old != theProjections.end() ) {
00065         return *( dynamic_cast<const PROJ*>(*old) );
00066       }
00067       // Add the projection via the Projection base class (only 
00068       // possible because Event is a friend of Projection)
00069       Projection* pp = &p;
00070       pp->project(*this);
00071       theProjections.insert(pp);
00072       return p;
00073     }
00074 
00075     /// The weight associated with the event.
00076     inline double weight() const { return theWeight; }
00077 
00078   private:
00079 
00080     /// A pointer to the generated event obtained from an external generator.
00081     const GenEvent* theGenEvent;
00082 
00083     /// The set of Projection objects applied so far.
00084     mutable std::set<const Projection*> theProjections;
00085 
00086     /// The weight associated with the event.
00087     double theWeight;
00088 
00089   private:
00090 
00091     /// The assignment operator is private and must never be called.
00092     /// In fact, it should not even be implemented.
00093     Event& operator=(const Event&);
00094 
00095   };
00096   
00097 }
00098 
00099 #endif