Skip to content

Commit 0e1856e

Browse files
authored
Merge pull request #47834 from mkirsano/herwig7addhepmc3_1
Add plugins that create HepMC3 products to Herwig7Interface
2 parents 1e0aa33 + 8feaed5 commit 0e1856e

File tree

10 files changed

+1456
-0
lines changed

10 files changed

+1456
-0
lines changed

GeneratorInterface/Herwig7Interface/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<use name="GeneratorInterface/Core"/>
22
<use name="boost"/>
33
<use name="hepmc"/>
4+
<use name="hepmc3"/>
45
<use name="thepeg"/>
56
<use name="herwig7"/>
67
<export>
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
// -*- C++ -*-
2+
//
3+
// HepMCConverter.h is a part of ThePEG - Toolkit for HEP Event Generation
4+
// Copyright (C) 1999-2019 Leif Lonnblad
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+
#ifndef ThePEG_HepMC3Converter_H
10+
#define ThePEG_HepMC3Converter_H
11+
// This is the declaration of the HepMCConverter class.
12+
13+
#include "ThePEG/Config/ThePEG.h"
14+
#include "ThePEG/EventRecord/Event.h"
15+
#include "GeneratorInterface/Herwig7Interface/interface/HepMC3Traits.h"
16+
17+
namespace ThePEG {
18+
19+
template <typename HepMCEventT, typename Traits = HepMCTraits<HepMCEventT> >
20+
class HepMCConverter {
21+
public:
22+
struct HepMCConverterException : public Exception {};
23+
24+
struct Vertex {
25+
/** Particles going in to the vertex. */
26+
tcParticleSet in;
27+
/** Particles going out of the vertex. */
28+
tcParticleSet out;
29+
};
30+
31+
/** Forward typedefs from Traits class. */
32+
typedef typename Traits::ParticleT GenParticle;
33+
/** Forward typedefs from Traits class. */
34+
typedef typename Traits::ParticlePtrT GenParticlePtrT;
35+
/** Forward typedefs from Traits class. */
36+
typedef typename Traits::EventT GenEvent;
37+
/** Forward typedefs from Traits class. */
38+
typedef typename Traits::VertexT GenVertex;
39+
/** Forward typedefs from Traits class. */
40+
typedef typename Traits::VertexPtrT GenVertexPtrT;
41+
/** Forward typedefs from Traits class. */
42+
typedef typename Traits::PdfInfoT PdfInfo;
43+
/** Map ThePEG particles to HepMC particles. */
44+
typedef map<tcPPtr, GenParticlePtrT> ParticleMap;
45+
/** Map ThePEG colour lines to HepMC colour indices. */
46+
typedef map<tcColinePtr, long> FlowMap;
47+
/** Map ThePEG particles to vertices. */
48+
typedef map<tcPPtr, Vertex *> VertexMap;
49+
/** Map vertices to GenVertex */
50+
typedef map<const Vertex *, GenVertexPtrT> GenVertexMap;
51+
52+
public:
53+
/**
54+
* Convert a ThePEG::Event to a HepMC::GenEvent. The caller is
55+
* responsible for deleting the constructed GenEvent object. If \a
56+
* nocopies is true, only final copies of particles connected with
57+
* Particle::previous() and Particle::next() will be entered in the
58+
* HepMC::GenEvent. In the GenEvent object, the energy/momentum
59+
* variables will be in units of \a eunit and lengths variables in
60+
* units of \a lunit.
61+
*/
62+
static GenEvent *convert(const Event &ev,
63+
bool nocopies = false,
64+
Energy eunit = Traits::defaultEnergyUnit(),
65+
Length lunit = Traits::defaultLengthUnit());
66+
67+
/**
68+
* Convert a ThePEG::Event to a HepMC::GenEvent. The caller supplies
69+
* a GenEvent object, \a gev, which will be filled. If \a nocopies
70+
* is true, only final copies of particles connected with
71+
* Particle::previous() and Particle::next() will be entered in the
72+
* HepMC::GenEvent. In the GenEvent object, the energy/momentum
73+
* variables will be in units of \a eunit and lengths variables in
74+
* units of \a lunit.
75+
*/
76+
static void convert(const Event &ev, GenEvent &gev, bool nocopies, Energy eunit, Length lunit);
77+
78+
/**
79+
* Convert a ThePEG::Event to a HepMC::GenEvent. The caller supplies
80+
* a GenEvent object, \a gev, which will be filled. If \a nocopies
81+
* is true, only final copies of particles connected with
82+
* Particle::previous() and Particle::next() will be entered in the
83+
* HepMC::GenEvent. In the GenEvent object, the energy/momentum
84+
* variables will be in units of \a eunit and lengths variables in
85+
* units of \a lunit.
86+
*/
87+
static void convert(const Event &ev, GenEvent &gev, bool nocopies = false);
88+
89+
private:
90+
/**
91+
* The proper constructors are private. The class is only
92+
* instantiated within the convert method.
93+
*/
94+
HepMCConverter(const Event &ev, bool nocopies, Energy eunit, Length lunit);
95+
96+
/**
97+
* The proper constructors are private. The class is only
98+
* instantiated within the convert method.
99+
*/
100+
HepMCConverter(const Event &ev, GenEvent &gev, bool nocopies, Energy eunit, Length lunit);
101+
102+
/**
103+
* Common init function used by the constructors.
104+
*/
105+
void init(const Event &ev, bool nocopies);
106+
107+
/**
108+
* Default constructor is unimplemented and private and should never be used.
109+
*/
110+
HepMCConverter() = delete;
111+
112+
/**
113+
* Copy constructor is unimplemented and private and should never be used.
114+
*/
115+
HepMCConverter(const HepMCConverter &) = delete;
116+
117+
/**
118+
* Assignment is unimplemented and private and should never be used.
119+
*/
120+
HepMCConverter &operator=(const HepMCConverter &) = delete;
121+
122+
private:
123+
/**
124+
* Create a GenParticle from a ThePEG Particle.
125+
*/
126+
GenParticlePtrT createParticle(tcPPtr p) const;
127+
128+
/**
129+
* Join the decay vertex of the parent with the decay vertex of the
130+
* child.
131+
*/
132+
void join(tcPPtr parent, tcPPtr child);
133+
134+
/**
135+
* Create a GenVertex from a temporary Vertex.
136+
*/
137+
GenVertexPtrT createVertex(Vertex *v);
138+
139+
/**
140+
* Create and set a PdfInfo object for the event
141+
*/
142+
void setPdfInfo(const Event &e);
143+
144+
private:
145+
/**
146+
* The constructed GenEvent.
147+
*/
148+
GenEvent *geneve;
149+
150+
/**
151+
* The translation table between the ThePEG particles and the
152+
* GenParticles.
153+
*/
154+
ParticleMap pmap;
155+
156+
/**
157+
* The translation table between ThePEG ColourLine objects and HepMC
158+
* Flow indices.
159+
*/
160+
FlowMap flowmap;
161+
162+
/**
163+
* All temporary vertices created.
164+
*/
165+
vector<Vertex> vertices;
166+
167+
/**
168+
* The mapping of particles to their production vertices.
169+
*/
170+
VertexMap prov;
171+
172+
/**
173+
* The mapping of particles to their decy vertices.
174+
*/
175+
VertexMap decv;
176+
177+
/**
178+
* The mapping between temporary vertices and the created GenVertex Objects.
179+
*/
180+
GenVertexMap vmap;
181+
182+
/**
183+
* The energy unit to be used in the GenEvent.
184+
*/
185+
Energy energyUnit;
186+
187+
/**
188+
* The length unit to be used in the GenEvent.
189+
*/
190+
Length lengthUnit;
191+
};
192+
193+
} // namespace ThePEG
194+
195+
#include "ThePEG/Vectors/HepMCConverter.tcc"
196+
197+
#endif /* ThePEG_HepMCConverter_H */
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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

Comments
 (0)