ThePEG  1.8.0
HepMCTraits.h
1 // -*- C++ -*-
2 //
3 // HepMCTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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  e->weights().push_back(weight);
69  for ( map<string,double>::const_iterator w = optionalWeights.begin();
70  w != optionalWeights.end(); ++w ) {
71 #ifdef HEPMC_HAS_NAMED_WEIGHTS
72  e->weights()[w->first] = w->second;
73 #else
74  e->weights().push_back(w->second);
75 #endif
76  }
77  return e;
78  }
79 
81  static void resetEvent(EventT * e, long evno, double weight,
82  const map<string,double>& optionalWeights) {
83  e->set_event_number(evno);
84  e->weights().clear();
85  e->weights().push_back(weight);
86  for ( map<string,double>::const_iterator w = optionalWeights.begin();
87  w != optionalWeights.end(); ++w ) {
88 #ifdef HEPMC_HAS_NAMED_WEIGHTS
89  e->weights()[w->first] = w->second;
90 #else
91  e->weights().push_back(w->second);
92 #endif
93  }
94  }
95 
99  static bool hasUnits() {
100 #ifdef HEPMC_HAS_UNITS
101  return true;
102 #else
103  return false;
104 #endif
105  }
106 
111 #ifndef HEPMC_HAS_UNITS
112  return GeV;
113 #else
114  return HepMC::Units::default_momentum_unit() == HepMC::Units::GEV? GeV: MeV;
115 #endif
116  }
117 
122 #ifndef HEPMC_HAS_UNITS
123  return millimeter;
124 #else
125  return HepMC::Units::default_length_unit() == HepMC::Units::MM?
126  millimeter: 10.0*millimeter;
127 #endif
128  }
129 
134  static Energy momentumUnit(const EventT & e) {
135 #ifdef HEPMC_HAS_UNITS
136  return e.momentum_unit() == HepMC::Units::MEV? MeV: GeV;
137 #else
138  return GeV;
139 #endif
140  }
141 
146  static Length lengthUnit(const EventT & e) {
147 #ifdef HEPMC_HAS_UNITS
148  return e.length_unit() == HepMC::Units::CM? centimeter: millimeter;
149 #else
150  return millimeter;
151 #endif
152  }
153 
158 #ifdef HEPMC_HAS_UNITS
159  static void setUnits(EventT & e, Energy momu, Length lenu) {
160  e.use_units(momu == MeV? HepMC::Units::MEV: HepMC::Units::GEV,
161  lenu == centimeter? HepMC::Units::CM: HepMC::Units::MM);
162  }
163 #else
164  static void setUnits(EventT &, Energy, Length) {}
165 #endif
166 
167 
171  static void setScaleAndAlphas(EventT & e, Energy2 scale,
172  double aS, double aEM, Energy unit) {
173  e.set_event_scale(sqrt(scale)/unit);
174  e.set_alphaQCD(aS);
175  e.set_alphaQED(aEM);
176  }
177 
179  static void setSignalProcessVertex(EventT & e, VertexT * v) {
180  e.set_signal_process_vertex(v);
181  }
182 
184  static void addVertex(EventT & e, VertexT * v) {
185  e.add_vertex(v);
186  }
187 
192  static ParticleT * newParticle(const Lorentz5Momentum & p,
193  long id, int status, Energy unit) {
194  // Note that according to the documentation the momentum is stored in a
195  // HepLorentzVector in GeV (event though the CLHEP standard is MeV).
196  LorentzVector<double> p_scalar = p/unit;
197  ParticleT * genp = new ParticleT(p_scalar, id, status);
198  genp->setGeneratedMass(p.mass()/unit);
199  return genp;
200  }
201 
204  static void setPolarization(ParticleT & genp, double the, double phi) {
205  genp.set_polarization(PolarizationT(the, phi));
206  }
207 
210  static void setColourLine(ParticleT & p, int indx, int coline) {
211  p.set_flow(indx, coline);
212  }
213 
215  static VertexT * newVertex() {
216  return new VertexT();
217  }
218 
220  static void addIncoming(VertexT & v, ParticleT * p) {
221  v.add_particle_in(p);
222  }
223 
225  static void addOutgoing(VertexT & v, ParticleT * p) {
226  v.add_particle_out(p);
227  }
228 
231  static void setPosition(VertexT & v, const LorentzPoint & p, Length unit) {
232  LorentzVector<double> p_scaled = p/unit;
233  v.set_position(p_scaled);
234  }
235 
237  static void setBeamParticles(EventT & e, ParticleT * p1, ParticleT * p2) {
238  e.set_beam_particles(p1,p2);
239  p1->set_status(4);
240  p2->set_status(4);
241  }
242 
244 #ifdef HEPMC_HAS_PDF_INFO
245  static void setPdfInfo(EventT & e, int id1, int id2, double x1, double x2,
246  double scale, double xf1, double xf2) {
247  e.set_pdf_info(PdfInfoT(id1, id2, x1, x2, scale, xf1, xf2));
248  }
249 #else
250  static void setPdfInfo(EventT &, int, int, double, double,
251  double, double, double) {}
252 #endif
253 
255 #ifdef HEPMC_HAS_CROSS_SECTION
256  static void setCrossSection(EventT & ev, double xs, double xserr) {
257  HepMC::GenCrossSection x;
258  x.set_cross_section(xs, xserr);
259  ev.set_cross_section(x);
260  }
261 #else
262  static void setCrossSection(EventT &, double, double) {}
263 #endif
264 
265 };
266 
280 template <typename HepMCEventT>
281 struct HepMCTraits {};
282 }
283 
284 #endif
285 
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:81
static Length defaultLengthUnit()
Return the length unit used in the installed version of HepMC.
Definition: HepMCTraits.h:121
static void setPosition(VertexT &v, const LorentzPoint &p, Length unit)
Set the position p for the vertex, v.
Definition: HepMCTraits.h:231
A 4-component Lorentz vector.
Definition: LorentzVector.h:35
static VertexT * newVertex()
Create a new vertex.
Definition: HepMCTraits.h:215
static void setPdfInfo(EventT &, int, int, double, double, double, double, double)
Set the PDF info for the event.
Definition: HepMCTraits.h:250
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:192
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:225
static bool hasUnits()
Return true if this version of HepMC accept user-defined units.
Definition: HepMCTraits.h:99
static Energy defaultEnergyUnit()
Return the energy unit used in the installed version of HepMC.
Definition: HepMCTraits.h:110
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:146
QTY< 0, 1, 0 >::Type Energy
Energy.
Definition: Unitsystem.h:34
static void setCrossSection(EventT &, double, double)
Set the cross section info for the event.
Definition: HepMCTraits.h:262
static void addVertex(EventT &e, VertexT *v)
Set a vertex, v, for the event e.
Definition: HepMCTraits.h:184
static void addIncoming(VertexT &v, ParticleT *p)
Add an incoming particle, p, to the vertex, v.
Definition: HepMCTraits.h:220
QTY< 1, 0, 0 >::Type Length
Length.
Definition: Unitsystem.h:40
HepMCTraitsBase is a convenient base class for specializing the HepMCTraits class to deal with differ...
Definition: HepMCTraits.h:46
Value mass() const
Mass/invariant length component.
static Energy momentumUnit(const EventT &e)
Return the momentum unit used by a given GenEvent object.
Definition: HepMCTraits.h:134
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:281
static void setSignalProcessVertex(EventT &e, VertexT *v)
Set the primary vertex, v, for the event e.
Definition: HepMCTraits.h:179
static void setBeamParticles(EventT &e, ParticleT *p1, ParticleT *p2)
Set the beam particles for the event.
Definition: HepMCTraits.h:237
static void setPolarization(ParticleT &genp, double the, double phi)
Set the polarization directions, the and phi, for particle p.
Definition: HepMCTraits.h:204
static void setColourLine(ParticleT &p, int indx, int coline)
Set the colour line (with index indx) to coline for particle p.
Definition: HepMCTraits.h:210
static void setUnits(EventT &, Energy, Length)
Set the units to be used by the given GenEvent object.
Definition: HepMCTraits.h:164
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:171