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 
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()); }
110 
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
124 
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  }
136 
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< long double >::Basic3DVector
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
Definition: Basic3DVectorLD.h:68
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
__attribute__
class Basic3DVector< long double > __attribute__((aligned(16)))
Basic3DVector::theta
Geom::Theta< T > theta() const
Definition: extBasic3DVector.h:139
Basic3DVector< long double >::z
T z() const
Cartesian z coordinate.
Definition: Basic3DVectorLD.h:82
Basic3DVector::transverse
T transverse() const
Another name for perp()
Definition: extBasic3DVector.h:125
Basic3DVector< long double >::cross
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &v) const
Definition: Basic3DVectorLD.h:201
Basic3DVectorLD
Basic3DVector< long double > Basic3DVectorLD
Definition: Basic3DVectorLD.h:307
Basic3DVector< long double >::barePhi
T barePhi() const
Definition: Basic3DVectorLD.h:108
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Geom::Theta
Definition: Theta.h:12
Basic3DVector< long double >::Basic3DVector
Basic3DVector(const OtherPoint &p)
Definition: Basic3DVectorLD.h:47
Basic3DVector< long double >::perp2
T perp2() const
Squared magnitude of transverse component.
Definition: Basic3DVectorLD.h:96
Basic3DVector::perp2
T perp2() const
Squared magnitude of transverse component.
Definition: extBasic3DVector.h:119
Geom::Spherical2Cartesian
Definition: CoordinateSets.h:58
Basic3DVector< long double >::eta
T eta() const
Definition: Basic3DVectorLD.h:123
Vec4
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:64
operator-
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: Basic3DVectorLD.h:192
Basic3DVector< long double >::theX
T theX
Definition: Basic3DVectorLD.h:207
Basic3DVector::theZ
T theZ
Definition: oldBasic3DVector.h:262
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Basic3DVector::theY
T theY
Definition: oldBasic3DVector.h:261
Basic3DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: extBasic3DVector.h:113
eta
T eta() const
Definition: Basic3DVectorLD.h:157
Basic3DVector< long double >::mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:93
Basic3DVector< long double >
Definition: Basic3DVectorLD.h:12
Basic3DVector::theX
T theX
Definition: oldBasic3DVector.h:260
extBasic3DVector.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Basic3DVector< long double >::operator+=
Basic3DVector & operator+=(const Basic3DVector< U > &p)
Definition: Basic3DVectorLD.h:140
Basic3DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic3DVector.h:97
Basic3DVector< long double >::Basic3DVector
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
Definition: Basic3DVectorLD.h:33
operator+
Basic3DVector< long double > operator+(const Basic3DVector< long double > &a, const Basic3DVector< long double > &b)
vector sum and subtraction of vectors of possibly different precision
Definition: Basic3DVectorLD.h:218
Basic3DVector< long double >::theY
T theY
Definition: Basic3DVectorLD.h:208
operator*
long double operator*(const Basic3DVector< long double > &v1, const Basic3DVector< long double > &v2)
scalar product of vectors of same precision
Definition: Basic3DVectorLD.h:257
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Geom::Cylindrical2Cartesian
Definition: CoordinateSets.h:34
Basic3DVector< long double >::Cylindrical
Geom::Cylindrical2Cartesian< T > Cylindrical
Definition: Basic3DVectorLD.h:16
Basic3DVector< long double >::phi
Geom::Phi< T > phi() const
Definition: Basic3DVectorLD.h:109
Basic3DVector< long double >::Basic3DVector
Basic3DVector()
Definition: Basic3DVectorLD.h:26
Basic3DVector< long double >::T
long double T
Definition: Basic3DVectorLD.h:14
b
double b
Definition: hdecay.h:118
Basic3DVector< long double >::theZ
T theZ
Definition: Basic3DVectorLD.h:209
Basic2DVector
Definition: extBasic2DVector.h:15
Basic3DVector< long double >::y
T y() const
Cartesian y coordinate.
Definition: Basic3DVectorLD.h:79
Basic3DVector< long double >::operator*=
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Definition: Basic3DVectorLD.h:161
a
double a
Definition: hdecay.h:119
Basic3DVector< long double >::Polar
Spherical Polar
Definition: Basic3DVectorLD.h:18
Basic3DVector< long double >::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: Basic3DVectorLD.h:90
Basic3DVector< long double >::MathVector
Basic3DVector< T > MathVector
Definition: Basic3DVectorLD.h:20
Basic3DVector::barePhi
T barePhi() const
Definition: extBasic3DVector.h:131
mathSSE::Vec4
Definition: SSEVec.h:115
Basic3DVector< long double >::cross
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Definition: Basic3DVectorLD.h:191
Basic3DVector::theW
T theW
Definition: oldBasic3DVector.h:263
operator/
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Definition: Basic3DVectorLD.h:302
Basic3DVector< long double >::ScalarType
T ScalarType
Definition: Basic3DVectorLD.h:15
Geom::Phi
Definition: Phi.h:52
Basic3DVector< long double >::Spherical
Geom::Spherical2Cartesian< T > Spherical
Definition: Basic3DVectorLD.h:17
Basic3DVector< long double >::dot
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &v) const
Definition: Basic3DVectorLD.h:186
Basic3DVector::operator-=
Basic3DVector & operator-=(const Basic3DVector< U > &p)
Definition: extBasic3DVector.h:167
Basic3DVector< long double >::Basic3DVector
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: Basic3DVectorLD.h:29
Basic3DVector< long double >::operator==
bool operator==(const Basic3DVector &rh) const
Definition: Basic3DVectorLD.h:87
PreciseFloatType::Type
double Type
Definition: PreciseFloatType.h:24
Basic3DVector::v
Vec4< T > v
Definition: extBasic3DVector.h:217
Basic3DVector< long double >::Basic3DVector
Basic3DVector(const T &x, const T &y, const T &z)
construct from cartesian coordinates
Definition: Basic3DVectorLD.h:61
alignCSCRings.r
r
Definition: alignCSCRings.py:93
Basic3DVector< long double >::xy
Basic2DVector< T > xy() const
Definition: Basic3DVectorLD.h:84
T
long double T
Definition: Basic3DVectorLD.h:48
Basic3DVector< long double >::perp
T perp() const
Magnitude of transverse component.
Definition: Basic3DVectorLD.h:99
Basic3DVector< long double >::bareTheta
T bareTheta() const
Definition: Basic3DVectorLD.h:115
Basic3DVector< long double >::dot
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Definition: Basic3DVectorLD.h:178
Basic3DVector< long double >::theW
T theW
Definition: Basic3DVectorLD.h:210
Basic3DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic3DVector.h:94
S
Definition: CSCDBL1TPParametersExtended.h:16
Basic3DVector::perp
T perp() const
Magnitude of transverse component.
Definition: extBasic3DVector.h:122
Basic3DVector< long double >::unit
Basic3DVector unit() const
Definition: Basic3DVectorLD.h:128
Basic3DVector< long double >::Basic3DVector
Basic3DVector(const Basic2DVector< T > &p)
constructor from 2D vector (X and Y from 2D vector, z set to zero)
Definition: Basic3DVectorLD.h:36
Basic3DVector::Basic3DVector
Basic3DVector()
Definition: extBasic3DVector.h:43
Basic3DVector< long double >::x
T x() const
Cartesian x coordinate.
Definition: Basic3DVectorLD.h:76
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
Basic3DVector::z
T z() const
Cartesian z coordinate.
Definition: extBasic3DVector.h:100
Basic3DVector::phi
Geom::Phi< T > phi() const
Definition: extBasic3DVector.h:132
Basic3DVector< long double >::operator-
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: Basic3DVectorLD.h:158
Basic3DVector
Definition: extBasic3DVector.h:30
Basic3DVector< long double >::operator/=
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Definition: Basic3DVectorLD.h:169