thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
Transverse.h
1 // -*- C++ -*-
2 //
3 // Transverse.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 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_Transverse_H
10 #define ThePEG_Transverse_H
11 // This is the declaration of the Transverse class.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "ThePEG/Vectors/Lorentz5Vector.h"
15 #include "Transverse.fh"
16 
17 namespace ThePEG {
18 
29 template <typename Value>
30 class Transverse: public pair<Value,Value> {
31 
32 public:
33 
35  using Value2 = decltype(sqr(std::declval<Value>()));
36 
38  using BasePair = pair<Value,Value>;
39 
40 public:
41 
47  Transverse() : BasePair(Value(), Value()) {}
48 
52  Transverse(const BasePair & p) : BasePair(p) {}
53 
57  Transverse(Value x, Value y) : BasePair(x, y) {}
58 
62  Transverse(const ThreeVector<Value> & p) : BasePair(p.x(), p.y()) {}
63 
67  Transverse(const LorentzVector<Value> & p) : BasePair(p.x(), p.y()) {}
68 
72  Transverse(const Lorentz5Vector<Value> & p) : BasePair(p.x(), p.y()) {}
74 
80  const Transverse & operator=(const BasePair & p) {
81  BasePair::operator=(p);
82  return *this;
83  }
84 
89  BasePair::operator=(BasePair(p.x(), p.y()));
90  return *this;
91  }
92 
97  BasePair::operator=(BasePair(p.x(), p.y()));
98  return *this;
99  }
100 
105  BasePair::operator=(BasePair(p.x(), p.y()));
106  return *this;
107  }
108 
110 
116  Transverse operator-() const { return Transverse(-x(), -y()); }
117 
121  Transverse operator-(const Transverse & pt) const {
122  return Transverse(x() - pt.x(), y() - pt.y());
123  }
124 
129  BasePair::first -= pt.x();
130  BasePair::second -= pt.y();
131  return *this;
132  }
133 
138  return Transverse(x() + pt.x(), y() + pt.y());
139  }
140 
145  BasePair::first += pt.x();
146  BasePair::second += pt.y();
147  return *this;
148  }
149 
153  inline Transverse & operator*=(double a) {
154  BasePair::first *= a;
155  BasePair::second *= a;
156  return *this;
157  }
158 
162  inline Transverse & operator/=(double a) {
163  BasePair::first /= a;
164  BasePair::second /= a;
165  return *this;
166  }
168 
174  Value x() const { return BasePair::first; }
175 
179  Value y() const { return BasePair::second; }
180 
184  Value2 pt2() const { return sqr(x()) + sqr(y()); }
185 
189  Value pt() const { return sqrt(pt2()); }
190 
194  double phi() const { return atan2(y(), x()); }
196 
197 };
198 
200 template <typename OStream, typename T, typename UT>
201 void ounitstream(OStream & os, const Transverse<T> & p, UT & u) {
202  os << ounit(p.x(), u) << ounit(p.y(), u);
203 }
204 
206 template <typename IStream, typename T, typename UT>
207 void iunitstream(IStream & is, Transverse<T> & p, UT & u) {
208  T x, y;
209  is >> iunit(x, u) >> iunit(y, u);
210  p = Transverse<T>(x, y);
211 }
212 
214 template <typename Value>
215 inline Transverse<Value>
216 operator*(Transverse<Value> a, double b) {
217  return a *= b;
218 }
219 
221 template <typename Value>
222 inline Transverse<Value>
223 operator*(double b, Transverse<Value> a) {
224  return a *= b;
225 }
226 
228 template <typename ValueA, typename ValueB>
229 inline auto operator*(ValueB a, const Transverse<ValueA> & v)
230 -> Transverse<decltype(a*v.x())>
231 {
232  return {a*v.x(), a*v.y()};
233 }
234 
236 template <typename ValueA, typename ValueB>
237 inline auto operator*(const Transverse<ValueA> & v, ValueB a)
238 -> Transverse<decltype(a*v.x())>
239 {
240  return {a*v.x(), a*v.y()};
241 }
242 
244 template <typename Value>
245 inline Transverse<double>
246 operator/(const Transverse<Value> & v, Value a) {
247  return {v.x()/a, v.y()/a};
248 }
249 
251 template <typename ValueA, typename ValueB>
252 inline auto operator/(const Transverse<ValueA> & v, ValueB b)
253 -> Transverse<decltype(v.x()/b)>
254 {
255  return {v.x()/b, v.y()/b};
256 }
257 
258 }
259 
260 #endif /* ThePEG_Transverse_H */
A 4-component Lorentz vector.
Definition: LorentzVector.h:35
Transverse & operator/=(double a)
Divide-assign with a scalar.
Definition: Transverse.h:162
const Transverse & operator=(const BasePair &p)
Assignment from underlying representation.
Definition: Transverse.h:80
Transverse(const BasePair &p)
Constructor from underlying representation.
Definition: Transverse.h:52
decltype(sqr(std::declval< Energy >())) Value2
Template argument typedef.
Definition: Transverse.h:35
void ounitstream(OStream &os, const vector< T, Alloc > &v, UT &u)
Ouput a vector of objects with the specified unit.
Definition: Containers.h:275
A 3-component vector.
Definition: ThreeVector.h:34
constexpr auto sqr(const T &x) -> decltype(x *x)
The square function should really have been included in the standard C++ library. ...
Definition: ThePEG.h:117
Transverse()
Default constructor.
Definition: Transverse.h:47
Transverse & operator+=(const Transverse &pt)
Assign-add.
Definition: Transverse.h:144
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Transverse & operator-=(const Transverse &pt)
Assign-subtract.
Definition: Transverse.h:128
This is the main config header file for ThePEG.
Transverse(const LorentzVector< Value > &p)
Constructor taking the transverse parts of a LorentzVector.
Definition: Transverse.h:67
const Transverse & operator=(const LorentzVector< Value > &p)
Assignment taking the transverse parts of a LorentzVector.
Definition: Transverse.h:96
double phi() const
The azimuth angle.
Definition: Transverse.h:194
void iunitstream(IStream &is, vector< T, Alloc > &v, UT &u)
Input a vector of objects with the specified unit.
Definition: Containers.h:289
Transverse operator-(const Transverse &pt) const
Binary minus.
Definition: Transverse.h:121
Transverse(const ThreeVector< Value > &p)
Constructor taking the transverse parts of a ThreeVector.
Definition: Transverse.h:62
Value x() const
The x-component.
Definition: Transverse.h:174
Transverse operator-() const
Unary minus.
Definition: Transverse.h:116
OUnit< T, UT > ounit(const T &t, const UT &ut)
Helper function creating a OUnit object given an object and a unit.
Definition: UnitIO.h:84
Transverse(Value x, Value y)
Constructor from x and y components.
Definition: Transverse.h:57
Value y() const
The y-component.
Definition: Transverse.h:179
Transverse represents the transverse components of a LorentzVector.
Definition: Transverse.h:30
const Transverse & operator=(const ThreeVector< Value > &p)
Assignment taking the transverse parts of a ThreeVector.
Definition: Transverse.h:88
Value x() const
Component access.
Value pt() const
The magnitude.
Definition: Transverse.h:189
Transverse(const Lorentz5Vector< Value > &p)
Constructor taking the transverse parts of a Lorentz5Vector.
Definition: Transverse.h:72
The Lorentz5Vector inherits from the LorentzVector class.
Transverse operator+(const Transverse &pt) const
Addition.
Definition: Transverse.h:137
pair< Energy, Energy > BasePair
Template argument typedef.
Definition: Transverse.h:38
Value2 pt2() const
The magnitude squared.
Definition: Transverse.h:184
Transverse & operator*=(double a)
Multiply-assign with a scalar.
Definition: Transverse.h:153
const Transverse & operator=(const Lorentz5Vector< Value > &p)
Assignment taking the transverse parts of a Lorentz5Vector.
Definition: Transverse.h:104
IUnit< T, UT > iunit(T &t, const UT &ut)
Helper function creating a IUnit object given an object and a unit.
Definition: UnitIO.h:91