CMS 3D CMS Logo

Basic3DVectorLD.h
Go to the documentation of this file.
1 #ifndef GeometryVector_Basic3DVectorLD_h
2 #define GeometryVector_Basic3DVectorLD_h
3 
4 #ifdef __clang__
5 #pragma clang diagnostic push
6 #pragma clang diagnostic ignored "-Wunused-private-field"
7 #endif
8 
9 #include "extBasic3DVector.h"
10 // long double specialization
11 template <>
12 class Basic3DVector<long double> {
13 public:
14  typedef long double T;
15  typedef T ScalarType;
18  typedef Spherical Polar; // synonym
19 
21 
26  Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
27 
29  Basic3DVector(const Basic3DVector& p) : theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
30 
32  template <class U>
33  Basic3DVector(const Basic3DVector<U>& p) : theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
34 
36  Basic3DVector(const Basic2DVector<T>& p) : theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
37 
39  Basic3DVector& operator=(const Basic3DVector&) = default;
40 
49  template <class OtherPoint>
50  explicit Basic3DVector(const OtherPoint& p) : theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
51 
52 #ifdef USE_SSEVECT
53  // constructor from Vec4
54  template <typename U>
55  Basic3DVector(mathSSE::Vec4<U> const& iv) : theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
56 #endif
57 #ifdef USE_EXTVECT
58  // constructor from Vec4
59  template <typename U>
60  Basic3DVector(Vec4<U> const& iv) : theX(iv[0]), theY(iv[1]), theZ(iv[2]), theW(0) {}
61 #endif
62 
64  Basic3DVector(const T& x, const T& y, const T& z) : theX(x), theY(y), theZ(z), theW(0) {}
65 
70  template <typename U>
71  Basic3DVector(const Geom::Theta<U>& theta, const Geom::Phi<U>& phi, const T& r) {
72  Polar p(theta.value(), phi.value(), r);
73  theX = p.x();
74  theY = p.y();
75  theZ = p.z();
76  }
77 
79  T x() const { return theX; }
80 
82  T y() const { return theY; }
83 
85  T z() const { return theZ; }
86 
88 
89  // equality
90  bool operator==(const Basic3DVector& rh) const { return x() == rh.x() && y() == rh.y() && z() == rh.z(); }
91 
93  T mag2() const { return x() * x() + y() * y() + z() * z(); }
94 
96  T mag() const { return std::sqrt(mag2()); }
97 
99  T perp2() const { return x() * x() + y() * y(); }
100 
102  T perp() const { return std::sqrt(perp2()); }
103 
105  T transverse() const { return perp(); }
106 
111  T barePhi() const { return std::atan2(y(), x()); }
112  Geom::Phi<T> phi() const { return Geom::Phi<T>(barePhi()); }
118  T bareTheta() const { return std::atan2(perp(), z()); }
119  Geom::Theta<T> theta() const { return Geom::Theta<T>(std::atan2(perp(), z())); }
120 
125  // T eta() const { return -log( tan( theta()/2.));}
126  T eta() const { return detailsBasic3DVector::eta(x(), y(), z()); } // correct
131  Basic3DVector unit() const {
132  T my_mag = mag2();
133  if (my_mag == 0)
134  return *this;
135  my_mag = T(1) / std::sqrt(my_mag);
137  return ret *= my_mag;
138  }
142  template <class U>
144  theX += p.x();
145  theY += p.y();
146  theZ += p.z();
147  return *this;
148  }
149 
152  template <class U>
154  theX -= p.x();
155  theY -= p.y();
156  theZ -= p.z();
157  return *this;
158  }
159 
161  Basic3DVector operator-() const { return Basic3DVector(-x(), -y(), -z()); }
162 
165  theX *= t;
166  theY *= t;
167  theZ *= t;
168  return *this;
169  }
170 
173  t = T(1) / t;
174  theX *= t;
175  theY *= t;
176  theZ *= t;
177  return *this;
178  }
179 
181  T dot(const Basic3DVector& v) const { return x() * v.x() + y() * v.y() + z() * v.z(); }
182 
188  template <class U>
190  return x() * v.x() + y() * v.y() + z() * v.z();
191  }
192 
195  return Basic3DVector(y() * v.z() - v.y() * z(), z() * v.x() - v.z() * x(), x() * v.y() - v.x() * y());
196  }
197 
203  template <class U>
206  y() * v.z() - v.y() * z(), z() * v.x() - v.z() * x(), x() * v.y() - v.x() * y());
207  }
208 
209 private:
214 }
215 #ifndef __CINT__
216 __attribute__((aligned(16)))
217 #endif
218 ;
219 
222  typedef Basic3DVector<long double> RT;
223  return RT(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
224 }
226  typedef Basic3DVector<long double> RT;
227  return RT(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
228 }
229 
230 template <class U>
232  const Basic3DVector<U>& b) {
234  return RT(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
235 }
236 
237 template <class U>
239  const Basic3DVector<long double>& b) {
241  return RT(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
242 }
243 
244 template <class U>
246  const Basic3DVector<U>& b) {
248  return RT(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
249 }
250 
251 template <class U>
253  const Basic3DVector<long double>& b) {
255  return RT(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
256 }
257 
259 // template <>
260 inline long double operator*(const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
261  return v1.dot(v2);
262 }
263 
265 template <class U>
267  const Basic3DVector<U>& v2) {
268  return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
269 }
270 
271 template <class U>
273  const Basic3DVector<long double>& v2) {
274  return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
275 }
276 
280 //template <>
282  return Basic3DVector<long double>(v.x() * t, v.y() * t, v.z() * t);
283 }
284 
286 // template <>
288  return Basic3DVector<long double>(v.x() * t, v.y() * t, v.z() * t);
289 }
290 
291 template <typename S>
293  return static_cast<long double>(t) * v;
294 }
295 
296 template <typename S>
298  return static_cast<long double>(t) * v;
299 }
300 
304 template <typename S>
306  long double t = 1 / s;
307  return v * t;
308 }
309 
311 
312 #ifdef __clang__
313 #pragma clang diagnostic pop
314 #endif
315 
316 #endif // GeometryVector_Basic3DVectorLD_h
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &v) const
bool operator==(const Basic3DVector &rh) const
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
long double operator*(const Basic3DVector< long double > &v1, const Basic3DVector< long double > &v2)
scalar product of vectors of same precision
T perp2() const
Squared magnitude of transverse component.
T perp2() const
Squared magnitude of transverse component.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
ret
prodAgent to be discontinued
Geom::Spherical2Cartesian< T > Spherical
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
Basic3DVector & operator+=(const Basic3DVector< U > &p)
T y() const
Cartesian y coordinate.
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Geom::Theta< T > theta() const
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Geom::Phi< T > phi() const
T sqrt(T t)
Definition: SSEVec.h:19
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
T perp() const
Magnitude of transverse component.
Basic3DVector< T > MathVector
T z() const
Cartesian z coordinate.
class Basic3DVector< long double > __attribute__((aligned(16)))
T transverse() const
Another name for perp()
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:60
Basic3DVector & operator-=(const Basic3DVector< U > &p)
Basic3DVector< long double > Basic3DVectorLD
T eta() const
T perp() const
Magnitude of transverse component.
Basic3DVector unit() const
T z() const
Cartesian z coordinate.
Basic3DVector(const Basic2DVector< T > &p)
constructor from 2D vector (X and Y from 2D vector, z set to zero)
double b
Definition: hdecay.h:120
Basic2DVector< T > xy() const
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Basic3DVector(const T &x, const T &y, const T &z)
construct from cartesian coordinates
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
double a
Definition: hdecay.h:121
Basic3DVector< long double > operator+(const Basic3DVector< long double > &a, const Basic3DVector< long double > &b)
vector sum and subtraction of vectors of possibly different precision
Geom::Phi< T > phi() const
Geom::Cylindrical2Cartesian< T > Cylindrical
long double T
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: Phi.h:52
T x() const
Cartesian x coordinate.
Basic3DVector & operator=(const Basic3DVector &)=default
Assignment operator.
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &v) const