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 
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