|
| 1 | +// -*- C++ -*- |
| 2 | +// |
| 3 | +// HepMCHelper_HepMC.h is a part of ThePEG - A multi-purpose Monte Carlo event generator |
| 4 | +// Copyright (C) 2002-2019 The Herwig Collaboration |
| 5 | +// |
| 6 | +// ThePEG is licenced under version 3 of the GPL, see COPYING for details. |
| 7 | +// Please respect the MCnet academic guidelines, see GUIDELINES for details. |
| 8 | +// |
| 9 | +// |
| 10 | +// This is a helper header to implement HepMC conversions |
| 11 | +// |
| 12 | +#include "GeneratorInterface/Herwig7Interface/interface/HepMC3Traits.h" |
| 13 | +#include "HepMC3/GenEvent.h" |
| 14 | +#include "HepMC3/GenVertex.h" |
| 15 | +#include "HepMC3/GenParticle.h" |
| 16 | +#include "HepMC3/Version.h" |
| 17 | +#include "HepMC3/WriterAscii.h" |
| 18 | +#include "HepMC3/WriterHEPEVT.h" |
| 19 | +#include "HepMC3/WriterAsciiHepMC2.h" |
| 20 | +#ifdef HAVE_HEPMC3_WRITERROOT_H |
| 21 | +#include "HepMC3/WriterRoot.h" |
| 22 | +#endif |
| 23 | +#ifdef HAVE_HEPMC3_WRITERROOTTREE_H |
| 24 | +#include "HepMC3/WriterRootTree.h" |
| 25 | +#endif |
| 26 | +#include <string> |
| 27 | +namespace HepMC3 { |
| 28 | + using Polarization = std::pair<double, double>; |
| 29 | +} |
| 30 | +namespace ThePEG { |
| 31 | + /** |
| 32 | + * Struct for HepMC conversion |
| 33 | + */ |
| 34 | + // This is version 3! |
| 35 | + template <> |
| 36 | + struct HepMCTraits<HepMC3::GenEvent> : public HepMCTraitsBase<HepMC3::GenEvent, |
| 37 | + HepMC3::GenParticle, |
| 38 | + HepMC3::GenParticlePtr, |
| 39 | + HepMC3::GenVertex, |
| 40 | + HepMC3::GenVertexPtr, |
| 41 | + HepMC3::Polarization, |
| 42 | + HepMC3::GenPdfInfo> { |
| 43 | + /** Create an event object with number \a evno and \a weight. */ |
| 44 | + static EventT *newEvent(long evno, double weight, const map<string, double> &optionalWeights) { |
| 45 | + EventT *e = new EventT(HepMC3::Units::GEV, HepMC3::Units::MM); |
| 46 | + e->set_event_number(evno); |
| 47 | + e->set_event_number(evno); |
| 48 | + //std::vector<std::string> wnames; |
| 49 | + std::vector<double> wvalues; |
| 50 | + |
| 51 | + //wnames.push_back("Default"); |
| 52 | + wvalues.push_back(weight); |
| 53 | + for (map<string, double>::const_iterator w = optionalWeights.begin(); w != optionalWeights.end(); ++w) { |
| 54 | + //wnames.push_back(w->first); |
| 55 | + wvalues.push_back(w->second); |
| 56 | + } |
| 57 | + //e->run_info()->set_weight_names(wnames); |
| 58 | + e->weights() = wvalues; |
| 59 | + return e; |
| 60 | + } |
| 61 | + |
| 62 | + /** Create a new vertex. */ |
| 63 | + static VertexPtrT newVertex() { return std::make_shared<VertexT>(VertexT()); } |
| 64 | + |
| 65 | + /** Set the \a scale, \f$\alpha_S\f$ (\a aS) and \f$\alpha_{EM}\f$ |
| 66 | + (\a aEM) for the event \a e. The scale will be scaled with \a |
| 67 | + unit before given to the GenEvent. */ |
| 68 | + static void setScaleAndAlphas(EventT &e, Energy2 scale, double aS, double aEM, Energy unit) { |
| 69 | + e.add_attribute("event_scale", std::make_shared<HepMC3::DoubleAttribute>(sqrt(scale) / unit)); |
| 70 | + e.add_attribute("mpi", |
| 71 | + std::make_shared<HepMC3::IntAttribute>(-1)); //Please fix it later, once ThePEG authors respond |
| 72 | + e.add_attribute("signal_process_id", |
| 73 | + std::make_shared<HepMC3::IntAttribute>(0)); //Please fix it later, once ThePEG authors respond |
| 74 | + e.add_attribute("alphaQCD", std::make_shared<HepMC3::DoubleAttribute>(aS)); |
| 75 | + e.add_attribute("alphaQED", std::make_shared<HepMC3::DoubleAttribute>(aEM)); |
| 76 | + } |
| 77 | + |
| 78 | + /** Set the colour line (with index \a indx) to \a coline for |
| 79 | + particle \a p. */ |
| 80 | + static void setColourLine(ParticleT &p, int indx, int coline) { |
| 81 | + p.add_attribute("flow" + std::to_string(indx), std::make_shared<HepMC3::IntAttribute>(coline)); |
| 82 | + } |
| 83 | + |
| 84 | + /** Add an incoming particle, \a p, to the vertex, \a v. */ |
| 85 | + static void addIncoming(VertexT &v, ParticlePtrT p) { v.add_particle_in(p); } |
| 86 | + |
| 87 | + /** Add an outgoing particle, \a p, to the vertex, \a v. */ |
| 88 | + static void addOutgoing(VertexT &v, ParticlePtrT p) { v.add_particle_out(p); } |
| 89 | + |
| 90 | + /** Set the primary vertex, \a v, for the event \a e. */ |
| 91 | + static void setSignalProcessVertex(EventT &e, VertexPtrT v) { |
| 92 | + e.add_vertex(v); |
| 93 | + e.add_attribute("signal_process_vertex", std::make_shared<HepMC3::IntAttribute>(v->id())); |
| 94 | + } |
| 95 | + |
| 96 | + /** Set a vertex, \a v, for the event \a e. */ |
| 97 | + static void addVertex(EventT &e, VertexPtrT v) { e.add_vertex(v); } |
| 98 | + |
| 99 | + /** Set the beam particles for the event.*/ |
| 100 | + static void setBeamParticles(EventT &e, ParticlePtrT p1, ParticlePtrT p2) { |
| 101 | + //e.set_beam_particles(p1,p2); |
| 102 | + p1->set_status(4); |
| 103 | + p2->set_status(4); |
| 104 | + e.set_beam_particles(p1, p2); |
| 105 | + } |
| 106 | + |
| 107 | + /** Create a new particle object with momentum \a p, PDG number \a |
| 108 | + id and status code \a status. The momentum will be scaled with |
| 109 | + \a unit which according to the HepMC documentation should be |
| 110 | + GeV. */ |
| 111 | + static ParticlePtrT newParticle(const Lorentz5Momentum &p, long id, int status, Energy unit) { |
| 112 | + // Note that according to the documentation the momentum is stored in a |
| 113 | + // HepLorentzVector in GeV (event though the CLHEP standard is MeV). |
| 114 | + HepMC3::FourVector p_scalar(p.x() / unit, p.y() / unit, p.z() / unit, p.e() / unit); |
| 115 | + ParticlePtrT genp = std::make_shared<ParticleT>(ParticleT(p_scalar, id, status)); |
| 116 | + genp->set_generated_mass(p.mass() / unit); |
| 117 | + return genp; |
| 118 | + } |
| 119 | + |
| 120 | + /** Set the polarization directions, \a the and \a phi, for particle |
| 121 | + \a p. */ |
| 122 | + static void setPolarization(ParticleT &genp, double the, double phi) { |
| 123 | + genp.add_attribute("theta", std::make_shared<HepMC3::DoubleAttribute>(the)); |
| 124 | + genp.add_attribute("phi", std::make_shared<HepMC3::DoubleAttribute>(phi)); |
| 125 | + } |
| 126 | + |
| 127 | + /** Set the position \a p for the vertex, \a v. The length will be |
| 128 | + scaled with \a unit which normally should be millimeters. */ |
| 129 | + static void setPosition(VertexT &v, const LorentzPoint &p, Length unit) { |
| 130 | + HepMC3::FourVector v_scaled(p.x() / unit, p.y() / unit, p.z() / unit, p.e() / unit); |
| 131 | + v.set_position(v_scaled); |
| 132 | + } |
| 133 | + }; |
| 134 | +} // namespace ThePEG |
0 commit comments