Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:21

0001 // -*- C++ -*-
0002 //
0003 // ParticleTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef ThePEG_ParticleTraits_H
0010 #define ThePEG_ParticleTraits_H
0011 // This is the declaration of the ParticleTraits class.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 // #include "ParticleTraits.fh"
0015 // #include "ParticleTraits.xh"
0016 
0017 namespace ThePEG {
0018 
0019 template <typename PType>
0020 /**
0021  * ParticleTraits is a templated class defining a general interface to
0022  * any particle class. To make another particle type
0023  * <code>PType</code> available to some general ThePEG routines, the
0024  * ParticleTraits should be specialized to that class implementing
0025  * relevant methods of the general ParticleTraits class
0026  * below. Typically one needs specialisation both for the class itself
0027  * and of pointers to the class.
0028  * 
0029  * @see Particle
0030  * @see Lorentz5Vector
0031  * 
0032  */
0033 struct ParticleTraits: public TraitsType {
0034 
0035   /**
0036    * Return a reference to the particle.
0037    */
0038   static PType & ref(PType & p) {
0039     return p;
0040   }
0041 
0042   /**
0043    * Return the momentum of particle \a p.
0044    */
0045   static LorentzMomentum momentum(const PType & p) {
0046     return p.momentum();
0047   }
0048 
0049   /**
0050    * Return the mass of particle \a p.
0051    */
0052   static Energy mass(const PType & p) {
0053     return p.mass();
0054   }
0055 
0056   /**
0057    * Perform a Lorentz transformation on particle \a p.
0058    */
0059   static void transform(PType & p, const LorentzRotation & r) {
0060     p.transform(r);
0061   }
0062 
0063   /**
0064    * Set the momentum and mass of a particle.
0065    */
0066   static void set5Momentum(PType & p, const Lorentz5Momentum & q) {
0067     p.set5Momentum(q);
0068   }
0069 
0070   /**
0071    * Set the 3-momentum of a particle. The energy is rescaled to
0072    * preserve invariant mass.
0073    */
0074   static void set3Momentum(PType & p, const Momentum3 & q) {
0075     p.set3Momentum(q);
0076   }
0077 
0078   /**
0079    * Return charge of particle \a p in units of e/3.
0080    */
0081   static int iCharge(const PType & p) {
0082     return p.data().iCharge();
0083   }
0084 
0085 };
0086 
0087 /** @cond TRAITSPECIALIZATIONS */
0088 
0089 /** Specialization of ParticleTraits for pointer to Particle. */
0090 template <>
0091 struct ParticleTraits<PPtr>: public TraitsType {
0092 
0093   /**
0094    * Return a reference to the particle.
0095    */
0096   static Particle & ref(tPPtr p) {
0097     return *p;
0098   }
0099 
0100   /**
0101    * Return the momentum of particle \a p.
0102    */
0103   static const LorentzMomentum & momentum(tPPtr p) {
0104     return p->momentum();
0105   }
0106 
0107   /**
0108    * Return the mass of particle \a p.
0109    */
0110   static Energy mass(tPPtr p) {
0111     return p->mass();
0112   }
0113 
0114   /**
0115    * Perform a Lorentz transformation on particle \a p.
0116    */
0117   static void transform(tPPtr p, const LorentzRotation & r) {
0118     p->transform(r);
0119   }
0120 
0121   /**
0122    * Set the momentum and mass of a particle.
0123    */
0124   static void set5Momentum(tPPtr p, const Lorentz5Momentum & q) {
0125     p->set5Momentum(q);
0126   }
0127 
0128   /**
0129    * Set the 3-momentum of a particle. The energy is rescaled to
0130    * preserve invariant mass.
0131    */
0132   static void set3Momentum(tPPtr p, const Momentum3 & q) {
0133     p->set3Momentum(q);
0134   }
0135 
0136   /**
0137    * Return charge of particle \a p in units of e/3.
0138    */
0139   static int iCharge(tPPtr p) {
0140     return p->data().iCharge();
0141   }
0142 };  
0143 
0144 /** Specialization of ParticleTraits for pointer to const Particle. */
0145 template <>
0146 struct ParticleTraits<cPPtr>: public TraitsType {
0147 
0148   /**
0149    * Return a const reference to the particle.
0150    */
0151   static const Particle & ref(tcPPtr p) {
0152     return *p;
0153   }
0154 
0155   /**
0156    * Return the momentum of particle \a p.
0157    */
0158   static const LorentzMomentum & momentum(tcPPtr & p) {
0159     return p->momentum();
0160   }
0161 
0162   /**
0163    * Return the mass of particle \a p.
0164    */
0165   static Energy mass(tcPPtr p) {
0166     return p->mass();
0167   }
0168 
0169   /**
0170    * Return charge of particle \a p in units of e/3.
0171    */
0172   static int iCharge(tcPPtr & p) {
0173     return p->data().iCharge();
0174   }
0175 };  
0176 
0177 /** Specialization of ParticleTraits for transient pointer to Particle. */
0178 template <>
0179 struct ParticleTraits<tPPtr>: public TraitsType {
0180 
0181   /**
0182    * Return a reference to the particle.
0183    */
0184   static Particle & ref(tPPtr p) {
0185     return *p;
0186   }
0187 
0188   /**
0189    * Return the momentum of particle \a p.
0190    */
0191   static const LorentzMomentum & momentum(tPPtr p) {
0192     return p->momentum();
0193   }
0194 
0195   /**
0196    * Return the mass of particle \a p.
0197    */
0198   static Energy mass(tPPtr p) {
0199     return p->mass();
0200   }
0201 
0202   /**
0203    * Perform a Lorentz transformation on particle \a p.
0204    */
0205   static void transform(tPPtr p, const LorentzRotation & r) {
0206     p->transform(r);
0207   }
0208 
0209   /**
0210    * Set the momentum and mass of a particle.
0211    */
0212   static void set5Momentum(tPPtr p, const Lorentz5Momentum & q) {
0213     p->set5Momentum(q);
0214   }
0215 
0216   /**
0217    * Set the 3-momentum of a particle. The energy is rescaled to
0218    * preserve invariant mass.
0219    */
0220   static void set3Momentum(tPPtr p, const Momentum3 & q) {
0221     p->set3Momentum(q);
0222   }
0223 
0224   /**
0225    * Return charge of particle \a p in units of e/3.
0226    */
0227   static int iCharge(tPPtr p) {
0228     return p->data().iCharge();
0229   }
0230 };  
0231 
0232 /** Specialization of ParticleTraits for transient pointer to const Particle. */
0233 template <>
0234 struct ParticleTraits<tcPPtr>: public TraitsType {
0235 
0236   /**
0237    * Return a const reference to the particle.
0238    */
0239   static const Particle & ref(tcPPtr p) {
0240     return *p;
0241   }
0242 
0243   /**
0244    * Return the momentum of particle \a p.
0245    */
0246   static const LorentzMomentum & momentum(tcPPtr p) {
0247     return p->momentum();
0248   }
0249 
0250   /**
0251    * Return the mass of particle \a p.
0252    */
0253   static Energy mass(tcPPtr p) {
0254     return p->mass();
0255   }
0256 
0257   /**
0258    * Return charge of particle \a p in units of e/3.
0259    */
0260   static int iCharge(tcPPtr p) {
0261     return p->data().iCharge();
0262   }
0263 };
0264 
0265 /** Partial specialization of ParticleTraits for bare pointer to anything. */
0266 template <typename T>
0267 struct ParticleTraits<T*>: public TraitsType {
0268 
0269   /**
0270    * Return a reference to the particle.
0271    */
0272   static Particle & ref(T * p) {
0273     return *p;
0274   }
0275 
0276   /**
0277    * Return the momentum of particle \a p.
0278    */
0279   static const LorentzMomentum & momentum(T * p) {
0280     return ParticleTraits<T>::momentum(*p);
0281   }
0282 
0283   /**
0284    * Return the mass of particle \a p.
0285    */
0286   static Energy mass(T * p) {
0287     return ParticleTraits<T>::mass(*p);
0288   }
0289 
0290   /**
0291    * Perform a Lorentz transformation on particle \a p.
0292    */
0293   static void transform(T * p, const LorentzRotation & r) {
0294     ParticleTraits<T>::transform(*p, r);
0295   }
0296 
0297   /**
0298    * Set the momentum and mass of a particle.
0299    */
0300   static void set5Momentum(T * p, const Lorentz5Momentum & q) {
0301     ParticleTraits<T>::set5Momentum(*p, q);
0302   }
0303 
0304   /**
0305    * Set the 3-momentum of a particle. The energy is rescaled to
0306    * preserve invariant mass.
0307    */
0308   static void set3Momentum(T * p, const Momentum3 & q) {
0309     ParticleTraits<T>::set3Momentum(*p, q);
0310   }
0311 
0312   /**
0313    * Return charge of particle \a p in units of e/3.
0314    */
0315   static int iCharge(T * p) {
0316     return ParticleTraits<T>::iCharge(*p);
0317   }
0318 };  
0319 
0320 /** Partial specialization of ParticleTraits for bare pointer to const
0321     anything. */
0322 template <typename T>
0323 struct ParticleTraits<const T *>: public TraitsType {
0324 
0325   /**
0326    * Return a const reference to the particle.
0327    */
0328   static const Particle & ref(const T * p) {
0329     return *p;
0330   }
0331 
0332   /**
0333    * Return the momentum of particle \a p.
0334    */
0335   static const LorentzMomentum & momentum(const T * p) {
0336     return ParticleTraits<T>::momentum(*p);
0337   }
0338 
0339   /**
0340    * Return the mass of particle \a p.
0341    */
0342   static Energy mass(const T * p) {
0343     return ParticleTraits<T>::mass(*p);
0344   }
0345 
0346   /**
0347    * Return charge of particle \a p in units of e/3.
0348    */
0349   static int iCharge(const T * p) {
0350     return ParticleTraits<T>::iCharge(*p);
0351   }
0352 };
0353 
0354 /** Specialization of ParticleTraits for LorentzMomentum. In this way
0355  *  a LorentzMomentum can be used where only the momentum parts of a
0356  *  Particle is required. */
0357 template <>
0358 struct ParticleTraits<LorentzMomentum>: public TraitsType {
0359 
0360   /**
0361    * Return a reference to the LorentzMomentum.
0362    */
0363   static LorentzMomentum & ref(LorentzMomentum & p) {
0364     return p;
0365   }
0366 
0367   /**
0368    * Return the momentum.
0369    */
0370   static const LorentzMomentum & momentum(const LorentzMomentum & p) {
0371     return p;
0372   }
0373 
0374   /**
0375    * Return the mass.
0376    */
0377   static Energy mass(const LorentzMomentum & p) {
0378     return p.m();
0379   }
0380 
0381   /**
0382    * Perform a Lorentz transformation.
0383    */
0384   static void transform(LorentzMomentum & p, const LorentzRotation & r) {
0385     p.transform(r);
0386   }
0387 
0388   /**
0389    * Set the momentum and mass.
0390    */
0391   static void set5Momentum(LorentzMomentum & p, const Lorentz5Momentum & q) {
0392     p = q;
0393   }
0394 
0395   /**
0396    * Set the 3-momentum. The energy is rescaled to
0397    * preserve invariant mass.
0398    */
0399   static void set3Momentum(LorentzMomentum & p, const Momentum3 & q) {
0400     p = LorentzMomentum(q, sqrt(q.mag2() + p.m2()));
0401   }
0402 };  
0403 
0404 /** Specialization of ParticleTraits for Lorentz5Momentum. In this way
0405  *  a Lorentz5Momentum can be used where only the momentum parts of a
0406  *  Particle is required. */
0407 template <>
0408 struct ParticleTraits<Lorentz5Momentum>: public TraitsType {
0409 
0410   /**
0411    * Return a reference to the Lorentz5Momentum.
0412    */
0413   static Lorentz5Momentum & ref(Lorentz5Momentum & p) {
0414     return p;
0415   }
0416 
0417   /**
0418    * Return the momentum.
0419    */
0420   static const LorentzMomentum & momentum(const Lorentz5Momentum & p) {
0421     return p;
0422   }
0423 
0424   /**
0425    * Return the mass.
0426    */
0427   static Energy mass(const Lorentz5Momentum & p) {
0428     return p.mass();
0429   }
0430 
0431   /**
0432    * Perform a Lorentz transformation.
0433    */
0434   static void transform(Lorentz5Momentum & p, const LorentzRotation & r) {
0435     p.transform(r);
0436   }
0437 
0438   /**
0439    * Set the momentum and mass.
0440    */
0441   static void set5Momentum(Lorentz5Momentum & p, const Lorentz5Momentum & q) {
0442     p = q;
0443   }
0444 
0445   /**
0446    * Set the 3-momentum. The energy is rescaled to
0447    * preserve invariant mass.
0448    */
0449   static void set3Momentum(Lorentz5Momentum & p, const Momentum3 & q) {
0450     p = Lorentz5Momentum(p.mass(), q);
0451   }
0452 };  
0453 
0454 /** @endcond */
0455 
0456 /** A helper class to be used in <code>std::</code> algorithms to
0457  *  transform a range of particles. */
0458 struct Transformer {
0459   /** Constructor taking a reference to the Lorentz rotation to be
0460    *  performed. */
0461   Transformer(const LorentzRotation & rin) : r(rin) {}
0462   /** Copy constructor. */
0463   Transformer(const Transformer & t) : r(t.r) {}
0464   /** Perform the rotation on a given particle. */
0465   template <typename PType>
0466   void operator()(const PType & p) {
0467     ParticleTraits<PType>::transform(p, r);
0468   }
0469   /** A reference to the Lorentz rotation to be performed. */
0470   const LorentzRotation & r;
0471 };
0472 
0473 }
0474 
0475 // #include "ParticleTraits.icc"
0476 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
0477 // #include "ParticleTraits.tcc"
0478 #endif
0479 
0480 #endif /* ThePEG_ParticleTraits_H */