Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Transverse.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_Transverse_H
0010 #define ThePEG_Transverse_H
0011 // This is the declaration of the Transverse class.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 #include "ThePEG/Vectors/Lorentz5Vector.h"
0015 #include "Transverse.fh"
0016 
0017 namespace ThePEG {
0018 
0019 /**
0020  * Transverse represents the transverse components of a
0021  * LorentzVector. It inherits from
0022  * <code>std::pair<Value,Value></code> and can be used
0023  * anywhere such a pair is called for. It can also be created directly
0024  * from a <code>ThreeVector</code>, <code>LorentzVector</code> and
0025  * <code>Lorentz5Momentum</code>.
0026  *
0027  * @see Lorentz5Vector
0028  */
0029 template <typename Value>
0030 class Transverse: public pair<Value,Value> {
0031 
0032 public:
0033 
0034   /** Template argument typedef. */
0035   using Value2 = decltype(sqr(std::declval<Value>()));
0036 
0037   /** Template argument typedef. */
0038   using BasePair = pair<Value,Value>;
0039 
0040 public:
0041 
0042   /** @name Constructors. */
0043   //@{
0044   /**
0045    * Default constructor.
0046    */
0047   Transverse() : BasePair(Value(), Value()) {}
0048 
0049   /**
0050    * Constructor from underlying representation.
0051    */
0052   Transverse(const BasePair & p) : BasePair(p) {}
0053 
0054   /**
0055    * Constructor from x and y components.
0056    */
0057   Transverse(Value x, Value y) : BasePair(x, y) {}
0058 
0059   /**
0060    * Constructor taking the transverse parts of a ThreeVector.
0061    */
0062   Transverse(const ThreeVector<Value> & p) : BasePair(p.x(), p.y()) {}
0063 
0064   /**
0065    * Constructor taking the transverse parts of a LorentzVector.
0066    */
0067   Transverse(const LorentzVector<Value> & p) : BasePair(p.x(), p.y()) {}
0068 
0069   /**
0070    * Constructor taking the transverse parts of a Lorentz5Vector.
0071    */
0072   Transverse(const Lorentz5Vector<Value> & p) : BasePair(p.x(), p.y()) {}
0073   //@}
0074 
0075   /** @name Assignment operators. */
0076   //@{
0077   /**
0078    * Assignment from underlying representation.
0079    */
0080   const Transverse & operator=(const BasePair & p) {
0081     BasePair::operator=(p);
0082     return *this;
0083   }
0084 
0085   /**
0086    * Assignment taking the transverse parts of a ThreeVector.
0087    */
0088   const Transverse & operator=(const ThreeVector<Value> & p) {
0089     BasePair::operator=(BasePair(p.x(), p.y()));
0090     return *this;
0091   }
0092 
0093   /**
0094    * Assignment taking the transverse parts of a LorentzVector.
0095    */
0096   const Transverse & operator=(const LorentzVector<Value> & p) {
0097     BasePair::operator=(BasePair(p.x(), p.y()));
0098     return *this;
0099   }
0100 
0101   /**
0102    * Assignment taking the transverse parts of a Lorentz5Vector.
0103    */
0104   const Transverse & operator=(const Lorentz5Vector<Value> & p) { 
0105     BasePair::operator=(BasePair(p.x(), p.y()));
0106     return *this;
0107   }
0108 
0109   //@}
0110 
0111   /** @name Arithmetric operations */
0112   //@{
0113   /**
0114    * Unary minus.
0115    */
0116   Transverse operator-() const { return Transverse(-x(), -y()); }
0117 
0118   /**
0119    * Binary minus.
0120    */
0121   Transverse operator-(const Transverse & pt) const { 
0122     return Transverse(x() - pt.x(), y() - pt.y()); 
0123   }
0124 
0125   /**
0126    * Assign-subtract.
0127    */
0128   Transverse & operator-=(const Transverse & pt) {
0129     BasePair::first -= pt.x();
0130     BasePair::second -= pt.y();
0131     return *this;
0132   }
0133 
0134   /**
0135    * Addition.
0136    */
0137   Transverse operator+(const Transverse & pt) const {
0138     return Transverse(x() + pt.x(), y() + pt.y());
0139   }
0140 
0141   /**
0142    * Assign-add.
0143    */
0144   Transverse & operator+=(const Transverse & pt) {
0145     BasePair::first += pt.x();
0146     BasePair::second += pt.y();
0147     return *this;
0148   }
0149 
0150   /**
0151    * Multiply-assign with a scalar.
0152    */
0153   inline Transverse & operator*=(double a) {
0154     BasePair::first *= a;
0155     BasePair::second *= a;
0156     return *this;
0157   }
0158 
0159   /**
0160    * Divide-assign with a scalar.
0161    */
0162   inline Transverse & operator/=(double a) {
0163     BasePair::first /= a;
0164     BasePair::second /= a;
0165     return *this;
0166   }
0167   //@}
0168 
0169   /** @name Access coordinates. */
0170   //@{
0171   /**
0172    * The x-component.
0173    */
0174   Value x() const { return BasePair::first; }
0175 
0176   /**
0177    * The y-component.
0178    */
0179   Value y() const { return BasePair::second; }
0180 
0181   /**
0182    * The magnitude squared.
0183    */
0184   Value2 pt2() const { return sqr(x()) + sqr(y()); }
0185 
0186   /**
0187    * The magnitude.
0188    */
0189   Value pt() const { return sqrt(pt2()); }
0190 
0191   /**
0192    * The azimuth angle.
0193    */
0194   double phi() const { return atan2(y(), x()); }
0195   //@}
0196 
0197 };
0198 
0199 /** Output a Transverse with units to a stream. */
0200 template <typename OStream, typename T, typename UT>
0201 void ounitstream(OStream & os, const Transverse<T> & p, UT & u) {
0202   os << ounit(p.x(), u) << ounit(p.y(), u);
0203 }
0204 
0205 /** Input a Transverse with units from a stream. */
0206 template <typename IStream, typename T, typename UT>
0207 void iunitstream(IStream & is, Transverse<T> & p, UT & u) {
0208   T x, y;
0209   is >> iunit(x, u) >> iunit(y, u);
0210   p = Transverse<T>(x, y);
0211 }
0212 
0213 /** Multiply a Transverse with a number. */
0214 template <typename Value>
0215 inline Transverse<Value>
0216 operator*(Transverse<Value> a, double b) {
0217   return a *= b;
0218 }
0219 
0220 /** Multiply a number with a Transverse. */
0221 template <typename Value>
0222 inline Transverse<Value>
0223 operator*(double b, Transverse<Value> a) {
0224   return a *= b;
0225 }
0226 
0227 /** Multiply a (unitful) number with a Transverse. */
0228 template <typename ValueA, typename ValueB>
0229 inline auto operator*(ValueB a, const Transverse<ValueA> & v) 
0230 -> Transverse<decltype(a*v.x())>
0231 {
0232   return {a*v.x(), a*v.y()};
0233 }
0234 
0235 /** Multiply a Transverse with a (unitful) number. */
0236 template <typename ValueA, typename ValueB>
0237 inline auto operator*(const Transverse<ValueA> & v, ValueB a) 
0238 -> Transverse<decltype(a*v.x())>
0239 {
0240   return {a*v.x(), a*v.y()};
0241 }
0242 
0243 /** Divide a Transverse by a number. */
0244 template <typename Value>
0245 inline Transverse<double>
0246 operator/(const Transverse<Value> & v, Value a) {
0247   return {v.x()/a, v.y()/a};
0248 }
0249 
0250 /** Divide a Transverse by a (unitful) number. */
0251 template <typename ValueA, typename ValueB>
0252 inline auto operator/(const Transverse<ValueA> & v, ValueB b) 
0253 -> Transverse<decltype(v.x()/b)>
0254 {
0255   return {v.x()/b, v.y()/b};
0256 }
0257 
0258 }
0259 
0260 #endif /* ThePEG_Transverse_H */