Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-13 22:49:55

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_HepMC3Converter_H
0010 #define ThePEG_HepMC3Converter_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 "GeneratorInterface/Herwig7Interface/interface/HepMC3Traits.h"
0016 
0017 namespace ThePEG {
0018 
0019   template <typename HepMCEventT, typename Traits = HepMCTraits<HepMCEventT> >
0020   class HepMCConverter {
0021   public:
0022     struct HepMCConverterException : public Exception {};
0023 
0024     struct Vertex {
0025       /** Particles going in to the vertex. */
0026       tcParticleSet in;
0027       /** Particles going out of the vertex. */
0028       tcParticleSet out;
0029     };
0030 
0031     /** Forward typedefs from Traits class. */
0032     typedef typename Traits::ParticleT GenParticle;
0033     /** Forward typedefs from Traits class. */
0034     typedef typename Traits::ParticlePtrT GenParticlePtrT;
0035     /** Forward typedefs from Traits class. */
0036     typedef typename Traits::EventT GenEvent;
0037     /** Forward typedefs from Traits class. */
0038     typedef typename Traits::VertexT GenVertex;
0039     /** Forward typedefs from Traits class. */
0040     typedef typename Traits::VertexPtrT GenVertexPtrT;
0041     /** Forward typedefs from Traits class. */
0042     typedef typename Traits::PdfInfoT PdfInfo;
0043     /** Map ThePEG particles to HepMC particles. */
0044     typedef map<tcPPtr, GenParticlePtrT> ParticleMap;
0045     /** Map ThePEG colour lines to HepMC colour indices. */
0046     typedef map<tcColinePtr, long> FlowMap;
0047     /** Map ThePEG particles to vertices. */
0048     typedef map<tcPPtr, Vertex *> VertexMap;
0049     /** Map vertices to GenVertex */
0050     typedef map<const Vertex *, GenVertexPtrT> GenVertexMap;
0051 
0052   public:
0053     /**
0054      * Convert a ThePEG::Event to a HepMC::GenEvent. The caller is
0055      * responsible for deleting the constructed GenEvent object. If \a
0056      * nocopies is true, only final copies of particles connected with
0057      * Particle::previous() and Particle::next() will be entered in the
0058      * HepMC::GenEvent. In the GenEvent object, the energy/momentum
0059      * variables will be in units of \a eunit and lengths variables in
0060      * units of \a lunit.
0061      */
0062     static GenEvent *convert(const Event &ev,
0063                              bool nocopies = false,
0064                              Energy eunit = Traits::defaultEnergyUnit(),
0065                              Length lunit = Traits::defaultLengthUnit());
0066 
0067     /**
0068      * Convert a ThePEG::Event to a HepMC::GenEvent. The caller supplies
0069      * a GenEvent object, \a gev, which will be filled. If \a nocopies
0070      * is true, only final copies of particles connected with
0071      * Particle::previous() and Particle::next() will be entered in the
0072      * HepMC::GenEvent. In the GenEvent object, the energy/momentum
0073      * variables will be in units of \a eunit and lengths variables in
0074      * units of \a lunit.
0075      */
0076     static void convert(const Event &ev, GenEvent &gev, bool nocopies, Energy eunit, Length lunit);
0077 
0078     /**
0079      * Convert a ThePEG::Event to a HepMC::GenEvent. The caller supplies
0080      * a GenEvent object, \a gev, which will be filled. If \a nocopies
0081      * is true, only final copies of particles connected with
0082      * Particle::previous() and Particle::next() will be entered in the
0083      * HepMC::GenEvent. In the GenEvent object, the energy/momentum
0084      * variables will be in units of \a eunit and lengths variables in
0085      * units of \a lunit.
0086      */
0087     static void convert(const Event &ev, GenEvent &gev, bool nocopies = false);
0088 
0089   private:
0090     /**
0091      * The proper constructors are private. The class is only
0092      * instantiated within the convert method.
0093      */
0094     HepMCConverter(const Event &ev, bool nocopies, Energy eunit, Length lunit);
0095 
0096     /**
0097      * The proper constructors are private. The class is only
0098      * instantiated within the convert method.
0099      */
0100     HepMCConverter(const Event &ev, GenEvent &gev, bool nocopies, Energy eunit, Length lunit);
0101 
0102     /**
0103      * Common init function used by the constructors.
0104      */
0105     void init(const Event &ev, bool nocopies);
0106 
0107     /**
0108      * Default constructor is unimplemented and private and should never be used.
0109      */
0110     HepMCConverter() = delete;
0111 
0112     /**
0113      * Copy constructor is unimplemented and private and should never be used.
0114      */
0115     HepMCConverter(const HepMCConverter &) = delete;
0116 
0117     /**
0118      * Assignment is unimplemented and private and should never be used.
0119      */
0120     HepMCConverter &operator=(const HepMCConverter &) = delete;
0121 
0122   private:
0123     /**
0124      * Create a GenParticle from a ThePEG Particle.
0125      */
0126     GenParticlePtrT createParticle(tcPPtr p) const;
0127 
0128     /**
0129      * Join the decay vertex of the parent with the decay vertex of the
0130      * child.
0131      */
0132     void join(tcPPtr parent, tcPPtr child);
0133 
0134     /**
0135      * Create a GenVertex from a temporary Vertex.
0136      */
0137     GenVertexPtrT createVertex(Vertex *v);
0138 
0139     /**
0140      * Create and set a PdfInfo object for the event
0141      */
0142     void setPdfInfo(const Event &e);
0143 
0144   private:
0145     /**
0146      * The constructed GenEvent.
0147      */
0148     GenEvent *geneve;
0149 
0150     /**
0151      * The translation table between the ThePEG particles and the
0152      * GenParticles.
0153      */
0154     ParticleMap pmap;
0155 
0156     /**
0157      * The translation table between ThePEG ColourLine objects and HepMC
0158      * Flow indices.
0159      */
0160     FlowMap flowmap;
0161 
0162     /**
0163      * All temporary vertices created.
0164      */
0165     vector<Vertex> vertices;
0166 
0167     /**
0168      * The mapping of particles to their production vertices.
0169      */
0170     VertexMap prov;
0171 
0172     /**
0173      * The mapping of particles to their decy vertices.
0174      */
0175     VertexMap decv;
0176 
0177     /**
0178      * The mapping between temporary vertices and the created GenVertex Objects.
0179      */
0180     GenVertexMap vmap;
0181 
0182     /**
0183      * The energy unit to be used in the GenEvent.
0184      */
0185     Energy energyUnit;
0186 
0187     /**
0188      * The length unit to be used in the GenEvent.
0189      */
0190     Length lengthUnit;
0191   };
0192 
0193 }  // namespace ThePEG
0194 
0195 #include "ThePEG/Vectors/HepMCConverter.tcc"
0196 
0197 #endif /* ThePEG_HepMCConverter_H */