Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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