CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
46  template <class OtherPoint>
47  explicit Basic3DVector(const OtherPoint& p) : theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
48 
49 #ifdef USE_SSEVECT
50  // constructor from Vec4
51  template <typename U>
52  Basic3DVector(mathSSE::Vec4<U> const& iv) : theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
53 #endif
54 #ifdef USE_EXTVECT
55  // constructor from Vec4
56  template <typename U>
57  Basic3DVector(Vec4<U> const& iv) : theX(iv[0]), theY(iv[1]), theZ(iv[2]), theW(0) {}
58 #endif
59 
61  Basic3DVector(const T& x, const T& y, const T& z) : theX(x), theY(y), theZ(z), theW(0) {}
62 
67  template <typename U>
68  Basic3DVector(const Geom::Theta<U>& theta, const Geom::Phi<U>& phi, const T& r) {
69  Polar p(theta.value(), phi.value(), r);
70  theX = p.x();
71  theY = p.y();
72  theZ = p.z();
73  }
74 
76  T x() const { return theX; }
77 
79  T y() const { return theY; }
80 
82  T z() const { return theZ; }
83 
85 
86  // equality
87  bool operator==(const Basic3DVector& rh) const { return x() == rh.x() && y() == rh.y() && z() == rh.z(); }
88 
90  T mag2() const { return x() * x() + y() * y() + z() * z(); }
91 
93  T mag() const { return std::sqrt(mag2()); }
94 
96  T perp2() const { return x() * x() + y() * y(); }
97 
99  T perp() const { return std::sqrt(perp2()); }
100 
102  T transverse() const { return perp(); }
103 
108  T barePhi() const { return std::atan2(y(), x()); }
109  Geom::Phi<T> phi() const { return Geom::Phi<T>(barePhi()); }
115  T bareTheta() const { return std::atan2(perp(), z()); }
116  Geom::Theta<T> theta() const { return Geom::Theta<T>(std::atan2(perp(), z())); }
117 
122  // T eta() const { return -log( tan( theta()/2.));}
123  T eta() const { return detailsBasic3DVector::eta(x(), y(), z()); } // correct
128  Basic3DVector unit() const {
129  T my_mag = mag2();
130  if (my_mag == 0)
131  return *this;
132  my_mag = T(1) / std::sqrt(my_mag);
134  return ret *= my_mag;
135  }
139  template <class U>
141  theX += p.x();
142  theY += p.y();
143  theZ += p.z();
144  return *this;
145  }
146 
149  template <class U>
151  theX -= p.x();
152  theY -= p.y();
153  theZ -= p.z();
154  return *this;
155  }
156 
158  Basic3DVector operator-() const { return Basic3DVector(-x(), -y(), -z()); }
159 
162  theX *= t;
163  theY *= t;
164  theZ *= t;
165  return *this;
166  }
167 
170  t = T(1) / t;
171  theX *= t;
172  theY *= t;
173  theZ *= t;
174  return *this;
175  }
176 
178  T dot(const Basic3DVector& v) const { return x() * v.x() + y() * v.y() + z() * v.z(); }
179 
185  template <class U>
187  return x() * v.x() + y() * v.y() + z() * v.z();
188  }
189 
192  return Basic3DVector(y() * v.z() - v.y() * z(), z() * v.x() - v.z() * x(), x() * v.y() - v.x() * y());
193  }
194 
200  template <class U>
203  y() * v.z() - v.y() * z(), z() * v.x() - v.z() * x(), x() * v.y() - v.x() * y());
204  }
205 
206 private:
211 }
212 #ifndef __CINT__
213 __attribute__((aligned(16)))
214 #endif
215 ;
216 
219  typedef Basic3DVector<long double> RT;
220  return RT(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
221 }
223  typedef Basic3DVector<long double> RT;
224  return RT(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
225 }
226 
227 template <class U>
229  const Basic3DVector<U>& b) {
231  return RT(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
232 }
233 
234 template <class U>
236  const Basic3DVector<long double>& b) {
238  return RT(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
239 }
240 
241 template <class U>
243  const Basic3DVector<U>& b) {
245  return RT(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
246 }
247 
248 template <class U>
250  const Basic3DVector<long double>& b) {
252  return RT(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
253 }
254 
256 // template <>
257 inline long double operator*(const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
258  return v1.dot(v2);
259 }
260 
262 template <class U>
264  const Basic3DVector<U>& v2) {
265  return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
266 }
267 
268 template <class U>
270  const Basic3DVector<long double>& v2) {
271  return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
272 }
273 
277 //template <>
279  return Basic3DVector<long double>(v.x() * t, v.y() * t, v.z() * t);
280 }
281 
283 // template <>
285  return Basic3DVector<long double>(v.x() * t, v.y() * t, v.z() * t);
286 }
287 
288 template <typename S>
290  return static_cast<long double>(t) * v;
291 }
292 
293 template <typename S>
295  return static_cast<long double>(t) * v;
296 }
297 
301 template <typename S>
303  long double t = 1 / s;
304  return v * t;
305 }
306 
308 
309 #ifdef __clang__
310 #pragma clang diagnostic pop
311 #endif
312 
313 #endif // GeometryVector_Basic3DVectorLD_h
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &v) const
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
tuple ret
prodAgent to be discontinued
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
int32_t *__restrict__ iv
Geom::Phi< T > phi() const
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or &quot;cross&quot; product, with a vector of same type.
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
T perp2() const
Squared magnitude of transverse component.
Geom::Spherical2Cartesian< T > Spherical
Geom::Theta< T > theta() const
T barePhi() const
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
T x() const
Cartesian x coordinate.
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
T1 value() const
Explicit access to value in case implicit conversion not OK.
Definition: Phi.h:75
Geom::Phi< T > phi() const
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
Basic3DVector & operator+=(const Basic3DVector< U > &p)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Basic2DVector< T > xy() const
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
bool operator==(const Basic3DVector &rh) const
T z() const
Cartesian z coordinate.
T sqrt(T t)
Definition: SSEVec.h:19
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
float __attribute__((vector_size(8))) cms_float32x2_t
Definition: ExtVec.h:12
Basic3DVector< T > MathVector
Basic3DVector(const OtherPoint &p)
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &v) const
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:64
T perp() const
Magnitude of transverse component.
Basic3DVector & operator-=(const Basic3DVector< U > &p)
Basic3DVector< long double > Basic3DVectorLD
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T1 operator/(const Phi< T1, Range > &a, const Phi< T1, Range > &b)
Division.
Definition: Phi.h:176
T value() const
Explicit access to value in case implicit conversion not OK.
Definition: Theta.h:24
T perp() const
Magnitude of transverse component.
Basic3DVector(const Basic2DVector< T > &p)
constructor from 2D vector (X and Y from 2D vector, z set to zero)
double b
Definition: hdecay.h:118
T perp2() const
Squared magnitude of transverse component.
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Basic3DVector(const T &x, const T &y, const T &z)
construct from cartesian coordinates
double a
Definition: hdecay.h:119
T transverse() const
Another name for perp()
T y() const
Cartesian y coordinate.
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
T z() const
Cartesian z coordinate.
Geom::Cylindrical2Cartesian< T > Cylindrical
Basic3DVector unit() const
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 mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)