Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // HepMCHelper_HepMC.h is a part of ThePEG - A multi-purpose Monte Carlo event generator
0004 // Copyright (C) 2002-2019 The Herwig Collaboration
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 //
0010 // This is a helper header to implement HepMC conversions
0011 //
0012 #include "ThePEG/Vectors/HepMCTraits.h"
0013 #ifdef  HAVE_HEPMC3
0014 #include "HepMC3/GenEvent.h"
0015 #include "HepMC3/GenVertex.h"
0016 #include "HepMC3/GenParticle.h"
0017 #include "HepMC3/Version.h"   
0018 #include "HepMC3/WriterAscii.h"
0019 #include "HepMC3/WriterHEPEVT.h"
0020 #include "HepMC3/WriterAsciiHepMC2.h"
0021 #ifdef HAVE_HEPMC3_WRITERROOT_H
0022 #include "HepMC3/WriterRoot.h"
0023 #endif
0024 #ifdef HAVE_HEPMC3_WRITERROOTTREE_H
0025 #include "HepMC3/WriterRootTree.h"
0026 #endif
0027 namespace HepMC3 {
0028 using PdfInfo=GenPdfInfo;
0029 using Polarization=std::pair<double,double>;
0030 }
0031 namespace HepMC=HepMC3;
0032 #else
0033 #include "HepMC/GenEvent.h"
0034 #include "HepMC/GenVertex.h"
0035 #include "HepMC/GenParticle.h"
0036 #include "HepMC/Version.h"
0037 #include "HepMC/IO_BaseClass.h"
0038 #include "HepMC/IO_GenEvent.h"
0039 #include "HepMC/IO_AsciiParticles.h"
0040 namespace HepMC {
0041 #undef GenParticlePtr
0042 #undef GenVertexPtr
0043 typedef GenParticle * GenParticlePtr;
0044 typedef GenVertex * GenVertexPtr;
0045 }
0046 #endif
0047 namespace ThePEG {
0048 /**
0049  * Struct for HepMC conversion
0050  */
0051 #ifndef HAVE_HEPMC3
0052 template<> 
0053 struct HepMCTraits<HepMC::GenEvent> 
0054   : public HepMCTraitsBase<HepMC::GenEvent,
0055                HepMC::GenParticle,
0056                HepMC::GenParticle *,
0057                HepMC::GenVertex,
0058                HepMC::GenVertex *,
0059                HepMC::Polarization,
0060                HepMC::PdfInfo>
0061 {
0062 #else
0063   // This is version 3!
0064 template<> 
0065 struct HepMCTraits<HepMC::GenEvent> 
0066   : public HepMCTraitsBase<HepMC::GenEvent,
0067                HepMC::GenParticle,
0068                HepMC::GenParticlePtr,
0069                HepMC::GenVertex,
0070                HepMC::GenVertexPtr,
0071                HepMC::Polarization,
0072                HepMC::PdfInfo>
0073 {
0074 
0075   /** Create an event object with number \a evno and \a weight. */
0076   static EventT * newEvent(long evno, double weight,
0077                const map<string,double>& optionalWeights) {
0078     EventT * e = new EventT(HepMC::Units::GEV, HepMC::Units::MM);
0079     e->set_event_number(evno);
0080     e->set_event_number(evno);
0081     //std::vector<std::string> wnames;
0082     std::vector<double> wvalues;
0083     
0084     //wnames.push_back("Default");
0085     wvalues.push_back(weight);
0086     for ( map<string,double>::const_iterator w = optionalWeights.begin();
0087       w != optionalWeights.end(); ++w ) {
0088     //wnames.push_back(w->first);
0089     wvalues.push_back(w->second);
0090     }
0091     //e->run_info()->set_weight_names(wnames);
0092     e->weights()=wvalues;    
0093   return e;
0094   }
0095 
0096   /** Create a new vertex. */
0097   static VertexPtrT newVertex() {
0098     return std::make_shared<VertexT>(VertexT());
0099   }
0100 
0101   /** Set the \a scale, \f$\alpha_S\f$ (\a aS) and \f$\alpha_{EM}\f$
0102       (\a aEM) for the event \a e. The scale will be scaled with \a
0103       unit before given to the GenEvent. */
0104   static void setScaleAndAlphas(EventT & e, Energy2 scale,
0105                 double aS,  double aEM, Energy unit) {
0106     e.add_attribute("event_scale",std::make_shared<HepMC::DoubleAttribute>(sqrt(scale)/unit));
0107     e.add_attribute("mpi",std::make_shared<HepMC::IntAttribute>(-1));//Please fix it later, once ThePEG authors respond
0108     e.add_attribute("signal_process_id",std::make_shared<HepMC::IntAttribute>(0));//Please fix it later, once ThePEG authors respond
0109     e.add_attribute("alphaQCD",std::make_shared<HepMC::DoubleAttribute>(aS));
0110     e.add_attribute("alphaQED",std::make_shared<HepMC::DoubleAttribute>(aEM));
0111   }
0112 
0113   /** Set the colour line (with index \a indx) to \a coline for
0114       particle \a p. */
0115   static void setColourLine(ParticleT & p, int indx, int coline) {
0116    p.add_attribute("flow"+std::to_string(indx),std::make_shared<HepMC::IntAttribute>(coline));
0117   }
0118 
0119   /** Add an incoming particle, \a p, to the vertex, \a v. */
0120   static void addIncoming(VertexT & v, ParticlePtrT p) {
0121     v.add_particle_in(p);
0122   }
0123 
0124   /** Add an outgoing particle, \a p, to the vertex, \a v. */
0125   static void addOutgoing(VertexT & v, ParticlePtrT p) {
0126     v.add_particle_out(p);
0127   }
0128 
0129   /** Set the primary vertex, \a v, for the event \a e. */
0130   static void setSignalProcessVertex(EventT & e, VertexPtrT v) {
0131     e.add_vertex(v);
0132     e.add_attribute("signal_process_vertex",
0133                     std::make_shared<HepMC::IntAttribute>(v->id()));
0134   }
0135 
0136   /** Set a vertex, \a v, for the event \a e. */
0137   static void addVertex(EventT & e, VertexPtrT v) {
0138     e.add_vertex(v);
0139   }
0140 
0141   /** Set the beam particles for the event.*/
0142   static void setBeamParticles(EventT & e, ParticlePtrT p1, ParticlePtrT p2) {
0143     //    e.set_beam_particles(p1,p2);
0144     p1->set_status(4);
0145     p2->set_status(4);
0146     e.set_beam_particles(p1, p2);
0147   }
0148 
0149   /** Create a new particle object with momentum \a p, PDG number \a
0150       id and status code \a status. The momentum will be scaled with
0151       \a unit which according to the HepMC documentation should be
0152       GeV. */
0153   static ParticlePtrT newParticle(const Lorentz5Momentum & p,
0154                                     long id, int status, Energy unit) {
0155     // Note that according to the documentation the momentum is stored in a
0156     // HepLorentzVector in GeV (event though the CLHEP standard is MeV).
0157     HepMC::FourVector p_scalar(p.x()/unit, p.y()/unit, p.z()/unit, p.e()/unit);
0158     ParticlePtrT genp = std::make_shared<ParticleT>(ParticleT(p_scalar, id, status));
0159     genp->set_generated_mass(p.mass()/unit);
0160     return genp;
0161   }
0162 
0163   /** Set the polarization directions, \a the and \a phi, for particle
0164       \a p. */
0165   static void setPolarization(ParticleT & genp, double the, double phi) {
0166     genp.add_attribute("theta",std::make_shared<HepMC::DoubleAttribute>(the));
0167     genp.add_attribute("phi",std::make_shared<HepMC::DoubleAttribute>(phi));
0168    }
0169 
0170   /** Set the position \a p for the vertex, \a v. The length will be
0171       scaled with \a unit which normally should be millimeters. */
0172   static void setPosition(VertexT & v, const LorentzPoint & p, Length unit) {
0173     HepMC::FourVector v_scaled(p.x()/unit, p.y()/unit, p.z()/unit, p.e()/unit);
0174     v.set_position(v_scaled);
0175   }
0176 
0177 #endif
0178 
0179 };
0180 }