Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:32

0001 // -*- C++ -*-
0002 //
0003 // HepMCConverter.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef ThePEG_HepMCConverter_H
0010 #define ThePEG_HepMCConverter_H
0011 // This is the declaration of the HepMCConverter class.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 #include "ThePEG/EventRecord/Event.h"
0015 #include "HepMCTraits.h"
0016 
0017 namespace ThePEG {
0018 
0019 
0020 /**
0021  * The HepMCConverter defines only one public static function which
0022  * converts a ThePEG::Event object to a
0023  * <code>HepMC::GenEvent</code>. All mother-daughter relationships and
0024  * colour information is preserved.
0025  *
0026  * @see Event
0027  * @see Particle
0028  *
0029  * @author Leif Lönnblad
0030  */
0031 template <typename HepMCEventT, typename Traits = HepMCTraits<HepMCEventT> >
0032 class HepMCConverter  {
0033 
0034 public:
0035 
0036   /** @cond EXCEPTIONCLASSES */
0037   /** Exception class for HepMCConverter. */
0038   struct HepMCConverterException: public Exception {};
0039   /** @endcond */
0040 
0041   /**
0042    * Help class to represent a temporary vertex which can be
0043    * converted to a GenVertex.
0044    */
0045   struct Vertex {
0046     /** Particles going in to the vertex. */
0047     tcParticleSet in;
0048     /** Particles going out of the vertex. */
0049     tcParticleSet out;
0050   };
0051 
0052   /** Forward typedefs from Traits class. */
0053   typedef typename Traits::ParticleT GenParticle;
0054   /** Forward typedefs from Traits class. */
0055   typedef typename Traits::ParticlePtrT GenParticlePtrT;
0056   /** Forward typedefs from Traits class. */
0057   typedef typename Traits::EventT GenEvent;
0058   /** Forward typedefs from Traits class. */
0059   typedef typename Traits::VertexT GenVertex;
0060   /** Forward typedefs from Traits class. */
0061   typedef typename Traits::VertexPtrT GenVertexPtrT;
0062   /** Forward typedefs from Traits class. */
0063   typedef typename Traits::PdfInfoT PdfInfo;
0064   /** Map ThePEG particles to HepMC particles. */
0065   typedef map<tcPPtr,GenParticlePtrT> ParticleMap;
0066   /** Map ThePEG colour lines to HepMC colour indices. */
0067   typedef map<tcColinePtr,long> FlowMap;
0068   /** Map ThePEG particles to vertices. */
0069   typedef map<tcPPtr,Vertex*> VertexMap;
0070   /** Map vertices to GenVertex */
0071   typedef map<const Vertex *, GenVertexPtrT> GenVertexMap;
0072 
0073 public:
0074 
0075   /**
0076    * Convert a ThePEG::Event to a HepMC::GenEvent. The caller is
0077    * responsible for deleting the constructed GenEvent object. If \a
0078    * nocopies is true, only final copies of particles connected with
0079    * Particle::previous() and Particle::next() will be entered in the
0080    * HepMC::GenEvent. In the GenEvent object, the energy/momentum
0081    * variables will be in units of \a eunit and lengths variables in
0082    * units of \a lunit.
0083    */
0084   static GenEvent * convert(const Event & ev, bool nocopies = false,
0085                 Energy eunit = Traits::defaultEnergyUnit(),
0086                 Length lunit = Traits::defaultLengthUnit());
0087 
0088   /**
0089    * Convert a ThePEG::Event to a HepMC::GenEvent. The caller supplies
0090    * a GenEvent object, \a gev, which will be filled. If \a nocopies
0091    * is true, only final copies of particles connected with
0092    * Particle::previous() and Particle::next() will be entered in the
0093    * HepMC::GenEvent. In the GenEvent object, the energy/momentum
0094    * variables will be in units of \a eunit and lengths variables in
0095    * units of \a lunit.
0096    */
0097   static void
0098   convert(const Event & ev, GenEvent & gev, bool nocopies,
0099       Energy eunit, Length lunit);
0100 
0101   /**
0102    * Convert a ThePEG::Event to a HepMC::GenEvent. The caller supplies
0103    * a GenEvent object, \a gev, which will be filled. If \a nocopies
0104    * is true, only final copies of particles connected with
0105    * Particle::previous() and Particle::next() will be entered in the
0106    * HepMC::GenEvent. In the GenEvent object, the energy/momentum
0107    * variables will be in units of \a eunit and lengths variables in
0108    * units of \a lunit.
0109    */
0110   static void
0111   convert(const Event & ev, GenEvent & gev, bool nocopies = false);
0112 
0113 private:
0114 
0115   /**
0116    * The proper constructors are private. The class is only
0117    * instantiated within the convert method.
0118    */
0119   HepMCConverter(const Event & ev, bool nocopies, Energy eunit, Length lunit);
0120 
0121   /**
0122    * The proper constructors are private. The class is only
0123    * instantiated within the convert method.
0124    */
0125   HepMCConverter(const Event & ev, GenEvent & gev, bool nocopies,
0126          Energy eunit, Length lunit);
0127 
0128   /**
0129    * Common init function used by the constructors.
0130    */
0131   void init(const Event & ev, bool nocopies);
0132 
0133   /**
0134    * Default constructor is unimplemented and private and should never be used.
0135    */
0136   HepMCConverter();
0137 
0138   /**
0139    * Copy constructor is unimplemented and private and should never be used.
0140    */
0141   HepMCConverter(const HepMCConverter &);
0142 
0143   /**
0144    * Assignment is unimplemented and private and should never be used.
0145    */
0146   HepMCConverter & operator=(const HepMCConverter &) = delete;
0147 
0148 private:
0149 
0150   /**
0151    * Create a GenParticle from a ThePEG Particle.
0152    */
0153   GenParticlePtrT createParticle(tcPPtr p) const;
0154 
0155   /**
0156    * Join the decay vertex of the parent with the decay vertex of the
0157    * child.
0158    */
0159   void join(tcPPtr parent, tcPPtr child);
0160 
0161   /**
0162    * Create a GenVertex from a temporary Vertex.
0163    */
0164   GenVertexPtrT createVertex(Vertex * v); 
0165 
0166   /**
0167    * Create and set a PdfInfo object for the event
0168    */
0169   void setPdfInfo(const Event & e);
0170 
0171 private:
0172 
0173   /**
0174    * The constructed GenEvent.
0175    */
0176   GenEvent * geneve;
0177 
0178   /**
0179    * The translation table between the ThePEG particles and the
0180    * GenParticles.
0181    */
0182   ParticleMap pmap;
0183 
0184   /**
0185    * The translation table between ThePEG ColourLine objects and HepMC
0186    * Flow indices.
0187    */
0188   FlowMap flowmap;
0189 
0190   /**
0191    * All temporary vertices created.
0192    */
0193   vector<Vertex> vertices;
0194 
0195   /**
0196    * The mapping of particles to their production vertices.
0197    */
0198   VertexMap prov;
0199 
0200   /**
0201    * The mapping of particles to their decy vertices.
0202    */
0203   VertexMap decv;
0204 
0205   /**
0206    * The mapping between temporary vertices and the created GenVertex Objects.
0207    */
0208   GenVertexMap vmap;
0209 
0210   /**
0211    * The energy unit to be used in the GenEvent.
0212    */
0213   Energy energyUnit;
0214 
0215   /**
0216    * The length unit to be used in the GenEvent.
0217    */
0218   Length lengthUnit;
0219 
0220 };
0221 
0222 }
0223 
0224 #include "HepMCConverter.tcc"
0225 
0226 #endif /* ThePEG_HepMCConverter_H */