thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
HepMCTraits.h
1 // -*- C++ -*-
2 //
3 // HepMCTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2017 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 #include "HepMC/GenEvent.h"
13 
14 namespace HepMC {
15 
16 class GenEvent;
17 class GenParticle;
18 class GenVertex;
19 class Polarization;
20 class PdfInfo;
21 
22 }
23 
24 namespace ThePEG {
25 
42 template <typename HepMCEventT, typename HepMCParticleT,
43  typename HepMCVertexT, typename HepMCPolarizationT,
44  typename HepMCPdfInfoT>
45 
47 
49  typedef HepMCParticleT ParticleT;
50 
52  typedef HepMCEventT EventT;
53 
55  typedef HepMCVertexT VertexT;
56 
58  typedef HepMCPolarizationT PolarizationT;
59 
61  typedef HepMCPdfInfoT PdfInfoT;
62 
64  static EventT * newEvent(long evno, double weight,
65  const map<string,double>& optionalWeights) {
66  EventT * e = new EventT();
67  e->set_event_number(evno);
68 #ifdef HEPMC_HAS_NAMED_WEIGHTS
69  e->weights()["Default"] = weight;
70 #else
71  e->weights().push_back(weight);
72 #endif
73  for ( map<string,double>::const_iterator w = optionalWeights.begin();
74  w != optionalWeights.end(); ++w ) {
75 #ifdef HEPMC_HAS_NAMED_WEIGHTS
76  e->weights()[w->first] = w->second;
77 #else
78  e->weights().push_back(w->second);
79 #endif
80  }
81  return e;
82  }
83 
85  static void resetEvent(EventT * e, long evno, double weight,
86  const map<string,double>& optionalWeights) {
87  e->set_event_number(evno);
88  e->weights().clear();
89 #ifdef HEPMC_HAS_NAMED_WEIGHTS
90  e->weights()["Default"] = weight;
91 #else
92  e->weights().push_back(weight);
93 #endif
94  for ( map<string,double>::const_iterator w = optionalWeights.begin();
95  w != optionalWeights.end(); ++w ) {
96 #ifdef HEPMC_HAS_NAMED_WEIGHTS
97  e->weights()[w->first] = w->second;
98 #else
99  e->weights().push_back(w->second);
100 #endif
101  }
102  }
103 
107  static bool hasUnits() {
108 #ifdef HEPMC_HAS_UNITS
109  return true;
110 #else
111  return false;
112 #endif
113  }
114 
119 #ifndef HEPMC_HAS_UNITS
120  return GeV;
121 #else
122  return HepMC::Units::default_momentum_unit() == HepMC::Units::GEV? GeV: MeV;
123 #endif
124  }
125 
130 #ifndef HEPMC_HAS_UNITS
131  return millimeter;
132 #else
133  return HepMC::Units::default_length_unit() == HepMC::Units::MM?
134  millimeter: 10.0*millimeter;
135 #endif
136  }
137 
142  static Energy momentumUnit(const EventT & e) {
143 #ifdef HEPMC_HAS_UNITS
144  return e.momentum_unit() == HepMC::Units::MEV? MeV: GeV;
145 #else
146  return GeV;
147 #endif
148  }
149 
154  static Length lengthUnit(const EventT & e) {
155 #ifdef HEPMC_HAS_UNITS
156  return e.length_unit() == HepMC::Units::CM? centimeter: millimeter;
157 #else
158  return millimeter;
159 #endif
160  }
161 
166 #ifdef HEPMC_HAS_UNITS
167  static void setUnits(EventT & e, Energy momu, Length lenu) {
168  e.use_units(momu == MeV? HepMC::Units::MEV: HepMC::Units::GEV,
169  lenu == centimeter? HepMC::Units::CM: HepMC::Units::MM);
170  }
171 #else
172  static void setUnits(EventT &, Energy, Length) {}
173 #endif
174 
175 
179  static void setScaleAndAlphas(EventT & e, Energy2 scale,
180  double aS, double aEM, Energy unit) {
181  e.set_event_scale(sqrt(scale)/unit);
182  e.set_alphaQCD(aS);
183  e.set_alphaQED(aEM);
184  }
185 
187  static void setSignalProcessVertex(EventT & e, VertexT * v) {
188  e.set_signal_process_vertex(v);
189  }
190 
192  static void addVertex(EventT & e, VertexT * v) {
193  e.add_vertex(v);
194  }
195 
200  static ParticleT * newParticle(const Lorentz5Momentum & p,
201  long id, int status, Energy unit) {
202  // Note that according to the documentation the momentum is stored in a
203  // HepLorentzVector in GeV (event though the CLHEP standard is MeV).
204  LorentzVector<double> p_scalar = p/unit;
205  ParticleT * genp = new ParticleT(p_scalar, id, status);
206  genp->setGeneratedMass(p.mass()/unit);
207  return genp;
208  }
209 
212  static void setPolarization(ParticleT & genp, double the, double phi) {
213  genp.set_polarization(PolarizationT(the, phi));
214  }
215 
218  static void setColourLine(ParticleT & p, int indx, int coline) {
219  p.set_flow(indx, coline);
220  }
221 
223  static VertexT * newVertex() {
224  return new VertexT();
225  }
226 
228  static void addIncoming(VertexT & v, ParticleT * p) {
229  v.add_particle_in(p);
230  }
231 
233  static void addOutgoing(VertexT & v, ParticleT * p) {
234  v.add_particle_out(p);
235  }
236 
239  static void setPosition(VertexT & v, const LorentzPoint & p, Length unit) {
240  LorentzVector<double> p_scaled = p/unit;
241  v.set_position(p_scaled);
242  }
243 
245  static void setBeamParticles(EventT & e, ParticleT * p1, ParticleT * p2) {
246  e.set_beam_particles(p1,p2);
247  p1->set_status(4);
248  p2->set_status(4);
249  }
250 
252 #ifdef HEPMC_HAS_PDF_INFO
253  static void setPdfInfo(EventT & e, int id1, int id2, double x1, double x2,
254  double scale, double xf1, double xf2) {
255  e.set_pdf_info(PdfInfoT(id1, id2, x1, x2, scale, xf1, xf2));
256  }
257 #else
258  static void setPdfInfo(EventT &, int, int, double, double,
259  double, double, double) {}
260 #endif
261 
263 #ifdef HEPMC_HAS_CROSS_SECTION
264  static void setCrossSection(EventT & ev, double xs, double xserr) {
265  HepMC::GenCrossSection x;
266  x.set_cross_section(xs, xserr);
267  ev.set_cross_section(x);
268  }
269 #else
270  static void setCrossSection(EventT &, double, double) {}
271 #endif
272 
273 };
274 
288 template <typename HepMCEventT>
289 struct HepMCTraits {};
290 }
291 
292 #endif
293 
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:85
static Length defaultLengthUnit()
Return the length unit used in the installed version of HepMC.
Definition: HepMCTraits.h:129
static void setPosition(VertexT &v, const LorentzPoint &p, Length unit)
Set the position p for the vertex, v.
Definition: HepMCTraits.h:239
A 4-component Lorentz vector.
Definition: LorentzVector.h:35
static VertexT * newVertex()
Create a new vertex.
Definition: HepMCTraits.h:223
static void setPdfInfo(EventT &, int, int, double, double, double, double, double)
Set the PDF info for the event.
Definition: HepMCTraits.h:258
HepMCVertexT VertexT
Typedef of the vertex class.
Definition: HepMCTraits.h:55
static ParticleT * 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:200
static EventT * newEvent(long evno, double weight, const map< string, double > &optionalWeights)
Create an event object with number evno and weight.
Definition: HepMCTraits.h:64
static void addOutgoing(VertexT &v, ParticleT *p)
Add an outgoing particle, p, to the vertex, v.
Definition: HepMCTraits.h:233
static bool hasUnits()
Return true if this version of HepMC accept user-defined units.
Definition: HepMCTraits.h:107
static Energy defaultEnergyUnit()
Return the energy unit used in the installed version of HepMC.
Definition: HepMCTraits.h:118
HepMCPolarizationT PolarizationT
Typedef of the polarization class.
Definition: HepMCTraits.h:58
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
HepMCParticleT ParticleT
Typedef of the particle class.
Definition: HepMCTraits.h:49
HepMCPdfInfoT PdfInfoT
Typedef of the PdfInfo class.
Definition: HepMCTraits.h:61
static Length lengthUnit(const EventT &e)
Return the length unit used by a given GenEvent object.
Definition: HepMCTraits.h:154
static void setCrossSection(EventT &, double, double)
Set the cross section info for the event.
Definition: HepMCTraits.h:270
static void addVertex(EventT &e, VertexT *v)
Set a vertex, v, for the event e.
Definition: HepMCTraits.h:192
static void addIncoming(VertexT &v, ParticleT *p)
Add an incoming particle, p, to the vertex, v.
Definition: HepMCTraits.h:228
Value mass() const
Mass/invariant length component.
HepMCTraitsBase is a convenient base class for specializing the HepMCTraits class to deal with differ...
Definition: HepMCTraits.h:46
static Energy momentumUnit(const EventT &e)
Return the momentum unit used by a given GenEvent object.
Definition: HepMCTraits.h:142
HepMCEventT EventT
Typedef of the event class.
Definition: HepMCTraits.h:52
The HepMCTraits class is used to deal with different flavours of HepMC in the HepMCConverter class...
Definition: HepMCTraits.h:289
static void setSignalProcessVertex(EventT &e, VertexT *v)
Set the primary vertex, v, for the event e.
Definition: HepMCTraits.h:187
static void setBeamParticles(EventT &e, ParticleT *p1, ParticleT *p2)
Set the beam particles for the event.
Definition: HepMCTraits.h:245
static void setPolarization(ParticleT &genp, double the, double phi)
Set the polarization directions, the and phi, for particle p.
Definition: HepMCTraits.h:212
static void setColourLine(ParticleT &p, int indx, int coline)
Set the colour line (with index indx) to coline for particle p.
Definition: HepMCTraits.h:218
static void setUnits(EventT &, Energy, Length)
Set the units to be used by the given GenEvent object.
Definition: HepMCTraits.h:172
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:179