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 
10 // long double specialization
11 template <>
12 class Basic3DVector<long double> {
13 public:
14 
15 
16  typedef long double T;
17  typedef T ScalarType;
20  typedef Spherical Polar; // synonym
21 
23 
28  Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
29 
32  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
33 
35  template <class U>
37  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
38 
41  theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
42 
51  template <class OtherPoint>
52  explicit Basic3DVector( const OtherPoint& p) :
53  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
54 
55 
56 #ifdef USE_SSEVECT
57  // constructor from Vec4
58  template<typename U>
59  Basic3DVector(mathSSE::Vec4<U> const& iv) :
60  theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
61 #endif
62 #ifdef USE_EXTVECT
63  // constructor from Vec4
64  template<typename U>
65  Basic3DVector(Vec4<U> const& iv) :
66  theX(iv[0]), theY(iv[1]), theZ(iv[2]), theW(0) {}
67 #endif
68 
69 
71  Basic3DVector( const T& x, const T& y, const T& z) :
72  theX(x), theY(y), theZ(z), theW(0) {}
73 
78  template <typename U>
80  const Geom::Phi<U>& phi, const T& r) {
81  Polar p( theta.value(), phi.value(), r);
82  theX = p.x(); theY = p.y(); theZ = p.z();
83  }
84 
86  T x() const { return theX;}
87 
89  T y() const { return theY;}
90 
92  T z() const { return theZ;}
93 
95 
96 
97  // equality
98  bool operator==(const Basic3DVector& rh) const {
99  return x()==rh.x() && y()==rh.y() && z()==rh.z();
100  }
101 
103  T mag2() const { return x()*x() + y()*y()+z()*z();}
104 
106  T mag() const { return std::sqrt( mag2());}
107 
109  T perp2() const { return x()*x() + y()*y();}
110 
112  T perp() const { return std::sqrt( perp2());}
113 
115  T transverse() const { return perp();}
116 
121  T barePhi() const {return std::atan2(y(),x());}
122  Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
123 
128  T bareTheta() const {return std::atan2(perp(),z());}
129  Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
130 
135  // T eta() const { return -log( tan( theta()/2.));}
136  T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct
137 
138 
142  Basic3DVector unit() const {
143  T my_mag = mag2();
144  if (my_mag==0) return *this;
145  my_mag = T(1)/std::sqrt(my_mag);
146  Basic3DVector ret(*this);
147  return ret*=my_mag;
148  }
149 
152  template <class U>
154  theX += p.x();
155  theY += p.y();
156  theZ += p.z();
157  return *this;
158  }
162  template <class U>
164  theX -= p.x();
165  theY -= p.y();
166  theZ -= p.z();
167  return *this;
168  }
169 
171  Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
175  theX *= t;
176  theY *= t;
177  theZ *= t;
178  return *this;
179  }
180 
183  t = T(1)/t;
184  theX *= t;
185  theY *= t;
186  theZ *= t;
187  return *this;
188  }
189 
191  T dot( const Basic3DVector& v) const {
192  return x()*v.x() + y()*v.y() + z()*v.z();
193  }
194 
200  template <class U>
201  typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const {
202  return x()*v.x() + y()*v.y() + z()*v.z();
203  }
204 
206  Basic3DVector cross( const Basic3DVector& v) const {
207  return Basic3DVector( y()*v.z() - v.y()*z(),
208  z()*v.x() - v.z()*x(),
209  x()*v.y() - v.x()*y());
210  }
211 
212 
218  template <class U>
220  cross( const Basic3DVector<U>& v) const {
222  z()*v.x() - v.z()*x(),
223  x()*v.y() - v.x()*y());
224  }
225 
226 private:
227  T theX;
228  T theY;
229  T theZ;
230  T theW;
231 }
232 #ifndef __CINT__
233 __attribute__ ((aligned (16)))
234 #endif
235 ;
236 
237 
242  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
243 }
246  typedef Basic3DVector<long double> RT;
247  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
248 }
249 
250 
252 template <class U>
256  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
257 }
258 
259 template <class U>
263  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
264 }
265 
266 
267 template <class U>
271  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
272 }
273 
274 template <class U>
278  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
279 }
282 // template <>
283 inline long double operator*( const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
284  return v1.dot(v2);
285 }
286 
288 template <class U>
290  const Basic3DVector<U>& v2) {
291  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
292 }
293 
294 template <class U>
296  const Basic3DVector<long double>& v2 ) {
297  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
298 }
299 
300 
304 //template <>
306  return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
307 }
308 
310 // template <>
312  return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
313 }
314 
315 template <typename S>
317  return static_cast<long double>(t)*v;
318 }
319 
320 template <typename S>
322  return static_cast<long double>(t)*v;
323 }
324 
325 
329 template <typename S>
331  long double t = 1/s;
332  return v*t;
333 }
334 
335 
337 
338 #ifdef __clang__
339 #pragma clang diagnostic pop
340 #endif
341 
342 #endif // GeometryVector_Basic3DVectorLD_h
343 
344 
345 
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
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:62
Geom::Phi< T > phi() const
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
T perp2() const
Squared magnitude of transverse component.
Geom::Spherical2Cartesian< T > Spherical
Geom::Theta< T > theta() const
T barePhi() const
Basic3DVector unit() const
T x() const
Cartesian x coordinate.
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Geom::Phi< T > phi() const
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
T eta() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
T transverse() const
Another name for perp()
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Basic2DVector< T > xy() const
bool operator==(const Basic3DVector &rh) const
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
T z() const
Cartesian z coordinate.
T sqrt(T t)
Definition: SSEVec.h:18
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Basic3DVector< T > MathVector
Basic3DVector & operator+=(const Basic3DVector< U > &p)
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &v) const
class Basic3DVector< long double > __attribute__((aligned(16)))
Basic3DVector(const OtherPoint &p)
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)
T value() const
Explicit access to value in case implicit conversion not OK.
Definition: Theta.h:25
T value() const
Explicit access to value in case implicit conversion not OK.
Definition: Phi.h:38
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:120
T perp2() const
Squared magnitude of transverse component.
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &v) const
Basic3DVector(const T &x, const T &y, const T &z)
construct from cartesian coordinates
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
T y() const
Cartesian y coordinate.
T z() const
Cartesian z coordinate.
Geom::Cylindrical2Cartesian< T > Cylindrical
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
long double T
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: Phi.h:20
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)