thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
ParticleTraits.h
1 // -*- C++ -*-
2 //
3 // ParticleTraits.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_ParticleTraits_H
10 #define ThePEG_ParticleTraits_H
11 // This is the declaration of the ParticleTraits class.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 // #include "ParticleTraits.fh"
15 // #include "ParticleTraits.xh"
16 
17 namespace ThePEG {
18 
19 template <typename PType>
33 struct ParticleTraits: public TraitsType {
34 
38  static PType & ref(PType & p) {
39  return p;
40  }
41 
45  static LorentzMomentum momentum(const PType & p) {
46  return p.momentum();
47  }
48 
52  static Energy mass(const PType & p) {
53  return p.mass();
54  }
55 
59  static void transform(PType & p, const LorentzRotation & r) {
60  p.transform(r);
61  }
62 
66  static void set5Momentum(PType & p, const Lorentz5Momentum & q) {
67  p.set5Momentum(q);
68  }
69 
74  static void set3Momentum(PType & p, const Momentum3 & q) {
75  p.set3Momentum(q);
76  }
77 
81  static int iCharge(const PType & p) {
82  return p.data().iCharge();
83  }
84 
85 };
86 
90 template <>
91 struct ParticleTraits<PPtr>: public TraitsType {
92 
96  static Particle & ref(tPPtr p) {
97  return *p;
98  }
99 
103  static const LorentzMomentum & momentum(tPPtr p) {
104  return p->momentum();
105  }
106 
110  static Energy mass(tPPtr p) {
111  return p->mass();
112  }
113 
117  static void transform(tPPtr p, const LorentzRotation & r) {
118  p->transform(r);
119  }
120 
124  static void set5Momentum(tPPtr p, const Lorentz5Momentum & q) {
125  p->set5Momentum(q);
126  }
127 
132  static void set3Momentum(tPPtr p, const Momentum3 & q) {
133  p->set3Momentum(q);
134  }
135 
139  static int iCharge(tPPtr p) {
140  return p->data().iCharge();
141  }
142 };
143 
145 template <>
146 struct ParticleTraits<cPPtr>: public TraitsType {
147 
151  static const Particle & ref(tcPPtr p) {
152  return *p;
153  }
154 
158  static const LorentzMomentum & momentum(tcPPtr & p) {
159  return p->momentum();
160  }
161 
165  static Energy mass(tcPPtr p) {
166  return p->mass();
167  }
168 
172  static int iCharge(tcPPtr & p) {
173  return p->data().iCharge();
174  }
175 };
176 
178 template <>
179 struct ParticleTraits<tPPtr>: public TraitsType {
180 
184  static Particle & ref(tPPtr p) {
185  return *p;
186  }
187 
191  static const LorentzMomentum & momentum(tPPtr p) {
192  return p->momentum();
193  }
194 
198  static Energy mass(tPPtr p) {
199  return p->mass();
200  }
201 
205  static void transform(tPPtr p, const LorentzRotation & r) {
206  p->transform(r);
207  }
208 
212  static void set5Momentum(tPPtr p, const Lorentz5Momentum & q) {
213  p->set5Momentum(q);
214  }
215 
220  static void set3Momentum(tPPtr p, const Momentum3 & q) {
221  p->set3Momentum(q);
222  }
223 
227  static int iCharge(tPPtr p) {
228  return p->data().iCharge();
229  }
230 };
231 
233 template <>
234 struct ParticleTraits<tcPPtr>: public TraitsType {
235 
239  static const Particle & ref(tcPPtr p) {
240  return *p;
241  }
242 
246  static const LorentzMomentum & momentum(tcPPtr p) {
247  return p->momentum();
248  }
249 
253  static Energy mass(tcPPtr p) {
254  return p->mass();
255  }
256 
260  static int iCharge(tcPPtr p) {
261  return p->data().iCharge();
262  }
263 };
264 
266 template <typename T>
267 struct ParticleTraits<T*>: public TraitsType {
268 
272  static Particle & ref(T * p) {
273  return *p;
274  }
275 
279  static const LorentzMomentum & momentum(T * p) {
280  return ParticleTraits<T>::momentum(*p);
281  }
282 
286  static Energy mass(T * p) {
287  return ParticleTraits<T>::mass(*p);
288  }
289 
293  static void transform(T * p, const LorentzRotation & r) {
295  }
296 
300  static void set5Momentum(T * p, const Lorentz5Momentum & q) {
302  }
303 
308  static void set3Momentum(T * p, const Momentum3 & q) {
310  }
311 
315  static int iCharge(T * p) {
316  return ParticleTraits<T>::iCharge(*p);
317  }
318 };
319 
322 template <typename T>
323 struct ParticleTraits<const T *>: public TraitsType {
324 
328  static const Particle & ref(const T * p) {
329  return *p;
330  }
331 
335  static const LorentzMomentum & momentum(const T * p) {
336  return ParticleTraits<T>::momentum(*p);
337  }
338 
342  static Energy mass(const T * p) {
343  return ParticleTraits<T>::mass(*p);
344  }
345 
349  static int iCharge(const T * p) {
350  return ParticleTraits<T>::iCharge(*p);
351  }
352 };
353 
357 template <>
358 struct ParticleTraits<LorentzMomentum>: public TraitsType {
359 
363  static LorentzMomentum & ref(LorentzMomentum & p) {
364  return p;
365  }
366 
370  static const LorentzMomentum & momentum(const LorentzMomentum & p) {
371  return p;
372  }
373 
377  static Energy mass(const LorentzMomentum & p) {
378  return p.m();
379  }
380 
384  static void transform(LorentzMomentum & p, const LorentzRotation & r) {
385  p.transform(r);
386  }
387 
391  static void set5Momentum(LorentzMomentum & p, const Lorentz5Momentum & q) {
392  p = q;
393  }
394 
399  static void set3Momentum(LorentzMomentum & p, const Momentum3 & q) {
400  p = LorentzMomentum(q, sqrt(q.mag2() + p.m2()));
401  }
402 };
403 
407 template <>
408 struct ParticleTraits<Lorentz5Momentum>: public TraitsType {
409 
413  static Lorentz5Momentum & ref(Lorentz5Momentum & p) {
414  return p;
415  }
416 
420  static const LorentzMomentum & momentum(const Lorentz5Momentum & p) {
421  return p;
422  }
423 
427  static Energy mass(const Lorentz5Momentum & p) {
428  return p.mass();
429  }
430 
434  static void transform(Lorentz5Momentum & p, const LorentzRotation & r) {
435  p.transform(r);
436  }
437 
441  static void set5Momentum(Lorentz5Momentum & p, const Lorentz5Momentum & q) {
442  p = q;
443  }
444 
449  static void set3Momentum(Lorentz5Momentum & p, const Momentum3 & q) {
450  p = Lorentz5Momentum(p.mass(), q);
451  }
452 };
453 
458 struct Transformer {
461  Transformer(const LorentzRotation & rin) : r(rin) {}
463  Transformer(const Transformer & t) : r(t.r) {}
465  template <typename PType>
466  void operator()(const PType & p) {
468  }
471 };
472 
473 }
474 
475 // #include "ParticleTraits.icc"
476 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
477 // #include "ParticleTraits.tcc"
478 #endif
479 
480 #endif /* ThePEG_ParticleTraits_H */
static Energy mass(const PType &p)
Return the mass of particle p.
static PType & ref(PType &p)
Return a reference to the particle.
The Particle class is used to describe an instance of a particle.
Definition: Particle.h:83
Value m() const
Magnitude (signed) .
static void transform(PType &p, const LorentzRotation &r)
Perform a Lorentz transformation on particle p.
static void set3Momentum(PType &p, const Momentum3 &q)
Set the 3-momentum of a particle.
A helper class to be used in std:: algorithms to transform a range of particles.
TraitsType is an empty, non-polymorphic, base class.
Definition: ThePEG.h:94
static int iCharge(const PType &p)
Return charge of particle p in units of e/3.
const LorentzRotation & r
A reference to the Lorentz rotation to be performed.
A 3-component vector.
Definition: ThreeVector.h:34
Value2 mag2() const
Squared magnitude .
Definition: ThreeVector.h:73
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
The LorentzRotation class combine a SpinOneLorentzRotation and a spin SpinHalfLorentzRotation to prov...
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Transformer(const LorentzRotation &rin)
Constructor taking a reference to the Lorentz rotation to be performed.
Transformer(const Transformer &t)
Copy constructor.
This is the main config header file for ThePEG.
Value mass() const
Mass/invariant length component.
static void set5Momentum(PType &p, const Lorentz5Momentum &q)
Set the momentum and mass of a particle.
Lorentz5Vector & transform(const LorentzRotation &r)
Perform a Lorentz transformation.
static LorentzMomentum momentum(const PType &p)
Return the momentum of particle p.
void operator()(const PType &p)
Perform the rotation on a given particle.
Value2 m2() const
Squared magnitude .
ParticleTraits is a templated class defining a general interface to any particle class.
LorentzVector< Value > & transform(const SpinOneLorentzRotation &m)
Rotate the vector. Resets .