thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
HepMCTraits.h
1// -*- C++ -*-
2//
3// HepMCTraits.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_HepMCTraits_H
10#define ThePEG_HepMCTraits_H
11
12#ifdef HAVE_HEPMC3
13#include "HepMC3/GenEvent.h"
14namespace HepMC3 {
15class GenEvent;
16class GenParticle;
17class GenVertex;
18class GenPdfInfo;
19}
20namespace HepMC3 {
21using PdfInfo=GenPdfInfo;
22using Polarization=std::pair<double,double>;
23}
24namespace HepMC=HepMC3;
25#else
26#include "HepMC/GenEvent.h"
27namespace HepMC {
28
29class GenEvent;
30class GenParticle;
31class GenVertex;
32class Polarization;
33#ifndef HEPMC_GENPDFINFO_H
34class PdfInfo;
35#endif
36}
37#endif
38
39
40namespace ThePEG {
41
58template <typename HepMCEventT,
59 typename HepMCParticleT, typename HepMCParticlePtrT,
60 typename HepMCVertexT, typename HepMCVertexPtrT,
61 typename HepMCPolarizationT, typename HepMCPdfInfoT>
62
64
66 typedef HepMCParticleT ParticleT;
67
69 typedef HepMCEventT EventT;
70
72 typedef HepMCVertexT VertexT;
73
75 typedef HepMCPolarizationT PolarizationT;
76
78 typedef HepMCPdfInfoT PdfInfoT;
79
81 typedef HepMCParticlePtrT ParticlePtrT;
82
84 typedef HepMCVertexPtrT VertexPtrT;
85
87 static EventT * newEvent(long evno, double weight,
88 const map<string,double>& optionalWeights) {
89 EventT * e = new EventT();
90 e->set_event_number(evno);
91 std::vector<std::string> wnames;
92 std::vector<double> wvalues;
93
94 wnames.push_back("Default");
95 wvalues.push_back(weight);
96 for ( map<string,double>::const_iterator w = optionalWeights.begin();
97 w != optionalWeights.end(); ++w ) {
98 wnames.push_back(w->first);
99 wvalues.push_back(w->second);
100 }
101
102
103#ifdef HAVE_HEPMC3
104 e->run_info()->set_weight_names(wnames);
105 e->weights()=wvalues;
106
107#else
108#ifdef HEPMC_HAS_NAMED_WEIGHTS
109 for (size_t i=0;i<wnames.size();i++) e->weights()[wnames[i]] = wvalues[i];
110#else
111 e->weights()=wvalues;
112#endif
113#endif
114
115
116
117 return e;
118 }
119
121 static void resetEvent(EventT * e, long evno, double weight,
122 const map<string,double>& optionalWeights) {
123 e->set_event_number(evno);
124 e->weights().clear();
125 std::vector<std::string> wnames;
126 std::vector<double> wvalues;
127
128 wnames.push_back("Default");
129 wvalues.push_back(weight);
130 for ( map<string,double>::const_iterator w = optionalWeights.begin();
131 w != optionalWeights.end(); ++w ) {
132 wnames.push_back(w->first);
133 wvalues.push_back(w->second);
134 }
135
136
137#ifdef HAVE_HEPMC3
138 e->run_info()->set_weight_names(wnames);
139 e->weights()=wvalues;
140
141#else
142#ifdef HEPMC_HAS_NAMED_WEIGHTS
143 for (size_t i=0;i<wnames.size();i++) e->weights()[wnames[i]] = wvalues[i];
144#else
145 e->weights()=wvalues;
146#endif
147#endif
148 }
149
153 static bool hasUnits() {
154#ifdef HEPMC_HAS_UNITS
155 return true;
156#else
157 return false;
158#endif
159 }
160
165#ifndef HEPMC_HAS_UNITS
166 return GeV;
167#else
168 return HepMC::Units::default_momentum_unit() == HepMC::Units::GEV? GeV: MeV;
169#endif
170 }
171
176#ifndef HEPMC_HAS_UNITS
177 return millimeter;
178#else
179 return HepMC::Units::default_length_unit() == HepMC::Units::MM?
180 millimeter: 10.0*millimeter;
181#endif
182 }
183
188 static Energy momentumUnit(const EventT & e) {
189#ifdef HEPMC_HAS_UNITS
190 return e.momentum_unit() == HepMC::Units::MEV? MeV: GeV;
191#else
192 return GeV;
193#endif
194 }
195
200 static Length lengthUnit(const EventT & e) {
201#ifdef HEPMC_HAS_UNITS
202 return e.length_unit() == HepMC::Units::CM? centimeter: millimeter;
203#else
204 return millimeter;
205#endif
206 }
207
212#ifdef HEPMC_HAS_UNITS
213 static void setUnits(EventT & e, Energy momu, Length lenu) {
214 e.use_units(momu == MeV? HepMC::Units::MEV: HepMC::Units::GEV,
215 lenu == centimeter? HepMC::Units::CM: HepMC::Units::MM);
216 }
217#else
218 static void setUnits(EventT &, Energy, Length) {}
219#endif
220
221
225 static void setScaleAndAlphas(EventT & e, Energy2 scale,
226 double aS, double aEM, Energy unit) {
227 e.set_event_scale(sqrt(scale)/unit);
228 e.set_alphaQCD(aS);
229 e.set_alphaQED(aEM);
230 }
231
234 e.set_signal_process_vertex(v);
235 }
236
238 static void addVertex(EventT & e, VertexPtrT v) {
239 e.add_vertex(v);
240 }
241
247 long id, int status, Energy unit) {
248 // Note that according to the documentation the momentum is stored in a
249 // HepLorentzVector in GeV (event though the CLHEP standard is MeV).
250 LorentzVector<double> p_scalar = p/unit;
251 ParticlePtrT genp =
252 new ParticleT(p_scalar, id, status);
253 genp->setGeneratedMass(p.mass()/unit);
254 return genp;
255 }
256
259 static void setPolarization(ParticleT & genp, double the, double phi) {
260 genp.set_polarization(PolarizationT(the, phi));
261 }
262
265 static void setColourLine(ParticleT & p, int indx, int coline) {
266 p.set_flow(indx, coline);
267 }
268
271 return new VertexT();
272 }
273
275 static void addIncoming(VertexT & v, ParticlePtrT p) {
276 v.add_particle_in(p);
277 }
278
280 static void addOutgoing(VertexT & v, ParticlePtrT p) {
281 v.add_particle_out(p);
282 }
283
286 static void setPosition(VertexT & v, const LorentzPoint & p, Length unit) {
287 LorentzVector<double> p_scaled = p/unit;
288 v.set_position(p_scaled);
289 }
290
293 e.set_beam_particles(p1,p2);
294 p1->set_status(4);
295 p2->set_status(4);
296 }
297
299#ifdef HEPMC_HAS_PDF_INFO
300 static void setPdfInfo(EventT & e, int id1, int id2, double x1, double x2,
301 double scale, double xf1, double xf2) {
302#ifdef HAVE_HEPMC3
303
304 HepMC::GenPdfInfoPtr pdfinfo = std::make_shared<HepMC::GenPdfInfo>();
305 pdfinfo->set(id1, id2, x1, x2, scale, xf1, xf2);
306 e.set_pdf_info(pdfinfo);
307#else
308 e.set_pdf_info(PdfInfoT(id1, id2, x1, x2, scale, xf1, xf2));
309#endif
310 }
311#else
312 static void setPdfInfo(EventT &, int, int, double, double,
313 double, double, double) {}
314#endif
315
317#ifdef HAVE_HEPMC3
318
319 static void setCrossSection(EventT & ev, double xs, double xserr) {
320 std::shared_ptr<HepMC::GenCrossSection> x = std::make_shared<HepMC::GenCrossSection>();
321 x->set_cross_section(xs,xserr);
322 ev.set_cross_section(x);
323 }
324
325#else
326
327 #ifdef HEPMC_HAS_CROSS_SECTION
328
329 static void setCrossSection(EventT & ev, double xs, double xserr) {
330 HepMC::GenCrossSection x;
331 x.set_cross_section(xs, xserr);
332 ev.set_cross_section(x);
333 }
334
335 #else
336
337 static void setCrossSection(EventT &, double, double) {}
338
339 #endif
340
341#endif
342
343};
344
358template <typename HepMCEventT>
359struct HepMCTraits {};
360}
361
362#endif
Value mass() const
Mass/invariant length component.
A 4-component Lorentz vector.
Definition: LorentzVector.h:44
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
HepMCTraitsBase is a convenient base class for specializing the HepMCTraits class to deal with differ...
Definition: HepMCTraits.h:63
static void setCrossSection(EventT &, double, double)
Set the cross section info for the event.
Definition: HepMCTraits.h:337
static void setSignalProcessVertex(EventT &e, VertexPtrT v)
Set the primary vertex, v, for the event e.
Definition: HepMCTraits.h:233
static ParticlePtrT newParticle(const Lorentz5Momentum &p, long id, int status, Energy unit)
Create a new particle object with momentum p, PDG number id and status code status.
Definition: HepMCTraits.h:246
static EventT * newEvent(long evno, double weight, const map< string, double > &optionalWeights)
Create an event object with number evno and weight.
Definition: HepMCTraits.h:87
HepMCPolarizationT PolarizationT
Typedef of the polarization class.
Definition: HepMCTraits.h:75
HepMCEventT EventT
Typedef of the event class.
Definition: HepMCTraits.h:69
HepMCParticlePtrT ParticlePtrT
Typedef of a particle pointer.
Definition: HepMCTraits.h:81
static bool hasUnits()
Return true if this version of HepMC accept user-defined units.
Definition: HepMCTraits.h:153
HepMCPdfInfoT PdfInfoT
Typedef of the PdfInfo class.
Definition: HepMCTraits.h:78
static void addVertex(EventT &e, VertexPtrT v)
Set a vertex, v, for the event e.
Definition: HepMCTraits.h:238
static void setScaleAndAlphas(EventT &e, Energy2 scale, double aS, double aEM, Energy unit)
Set the scale, (aS) and (aEM) for the event e.
Definition: HepMCTraits.h:225
HepMCVertexPtrT VertexPtrT
Typedef of a vertex pointer.
Definition: HepMCTraits.h:84
static void addIncoming(VertexT &v, ParticlePtrT p)
Add an incoming particle, p, to the vertex, v.
Definition: HepMCTraits.h:275
static void resetEvent(EventT *e, long evno, double weight, const map< string, double > &optionalWeights)
Reset event weight and number of a re-used GenEvent.
Definition: HepMCTraits.h:121
static void setPolarization(ParticleT &genp, double the, double phi)
Set the polarization directions, the and phi, for particle p.
Definition: HepMCTraits.h:259
static Length defaultLengthUnit()
Return the length unit used in the installed version of HepMC.
Definition: HepMCTraits.h:175
HepMCParticleT ParticleT
Typedef of the particle class.
Definition: HepMCTraits.h:66
static void setBeamParticles(EventT &e, ParticlePtrT p1, ParticlePtrT p2)
Set the beam particles for the event.
Definition: HepMCTraits.h:292
static Energy momentumUnit(const EventT &e)
Return the momentum unit used by a given GenEvent object.
Definition: HepMCTraits.h:188
static void setColourLine(ParticleT &p, int indx, int coline)
Set the colour line (with index indx) to coline for particle p.
Definition: HepMCTraits.h:265
static Length lengthUnit(const EventT &e)
Return the length unit used by a given GenEvent object.
Definition: HepMCTraits.h:200
static void setPosition(VertexT &v, const LorentzPoint &p, Length unit)
Set the position p for the vertex, v.
Definition: HepMCTraits.h:286
static void setUnits(EventT &, Energy, Length)
Set the units to be used by the given GenEvent object.
Definition: HepMCTraits.h:218
static void setPdfInfo(EventT &, int, int, double, double, double, double, double)
Set the PDF info for the event.
Definition: HepMCTraits.h:312
static VertexPtrT newVertex()
Create a new vertex.
Definition: HepMCTraits.h:270
static Energy defaultEnergyUnit()
Return the energy unit used in the installed version of HepMC.
Definition: HepMCTraits.h:164
HepMCVertexT VertexT
Typedef of the vertex class.
Definition: HepMCTraits.h:72
static void addOutgoing(VertexT &v, ParticlePtrT p)
Add an outgoing particle, p, to the vertex, v.
Definition: HepMCTraits.h:280
The HepMCTraits class is used to deal with different flavours of HepMC in the HepMCConverter class.
Definition: HepMCTraits.h:359