CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 // long double specialization
10 template <>
11 class Basic3DVector<long double> {
12 public:
13 
14 
15  typedef long double T;
16  typedef T ScalarType;
19  typedef Spherical Polar; // synonym
20 
22 
27  Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
28 
31  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
32 
34  template <class U>
36  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
37 
40  theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
41 
50  template <class OtherPoint>
51  explicit Basic3DVector( const OtherPoint& p) :
52  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
53 
54 
55 #ifdef USE_SSEVECT
56  // constructor from Vec4
57  template<typename U>
59  theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
60 #endif
61 #ifdef USE_EXTVECT
62  // constructor from Vec4
63  template<typename U>
64  Basic3DVector(Vec4<U> const& iv) :
65  theX(iv[0]), theY(iv[1]), theZ(iv[2]), theW(0) {}
66 #endif
67 
68 
70  Basic3DVector( const T& x, const T& y, const T& z) :
71  theX(x), theY(y), theZ(z), theW(0) {}
72 
77  template <typename U>
79  const Geom::Phi<U>& phi, const T& r) {
80  Polar p( theta.value(), phi.value(), r);
81  theX = p.x(); theY = p.y(); theZ = p.z();
82  }
83 
85  T x() const { return theX;}
86 
88  T y() const { return theY;}
89 
91  T z() const { return theZ;}
92 
94 
95 
96  // equality
97  bool operator==(const Basic3DVector& rh) const {
98  return x()==rh.x() && y()==rh.y() && z()==rh.z();
99  }
100 
102  T mag2() const { return x()*x() + y()*y()+z()*z();}
103 
105  T mag() const { return std::sqrt( mag2());}
106 
108  T perp2() const { return x()*x() + y()*y();}
109 
111  T perp() const { return std::sqrt( perp2());}
114  T transverse() const { return perp();}
115 
120  T barePhi() const {return std::atan2(y(),x());}
121  Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
122 
127  T bareTheta() const {return std::atan2(perp(),z());}
128  Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
129 
134  // T eta() const { return -log( tan( theta()/2.));}
135  T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct
136 
137 
141  Basic3DVector unit() const {
142  T my_mag = mag2();
143  if (my_mag==0) return *this;
144  my_mag = T(1)/std::sqrt(my_mag);
145  Basic3DVector ret(*this);
146  return ret*=my_mag;
147  }
148 
151  template <class U>
153  theX += p.x();
154  theY += p.y();
155  theZ += p.z();
156  return *this;
157  }
158 
161  template <class U>
163  theX -= p.x();
164  theY -= p.y();
165  theZ -= p.z();
166  return *this;
167  }
168 
170  Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
171 
174  theX *= t;
175  theY *= t;
176  theZ *= t;
177  return *this;
178  }
179 
182  t = T(1)/t;
183  theX *= t;
184  theY *= t;
185  theZ *= t;
186  return *this;
187  }
188 
190  T dot( const Basic3DVector& v) const {
191  return x()*v.x() + y()*v.y() + z()*v.z();
192  }
193 
199  template <class U>
201  return x()*v.x() + y()*v.y() + z()*v.z();
202  }
203 
206  return Basic3DVector( y()*v.z() - v.y()*z(),
207  z()*v.x() - v.z()*x(),
208  x()*v.y() - v.x()*y());
209  }
210 
211 
217  template <class U>
219  cross( const Basic3DVector<U>& v) const {
220  return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(),
221  z()*v.x() - v.z()*x(),
222  x()*v.y() - v.x()*y());
223  }
224 
225 private:
230 }
231 #ifndef __CINT__
232 __attribute__ ((aligned (16)))
233 #endif
234 ;
235 
236 
240  typedef Basic3DVector<long double> RT;
241  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
242 }
245  typedef Basic3DVector<long double> RT;
246  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
247 }
248 
249 
250 
251 template <class U>
255  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
256 }
257 
258 template <class U>
262  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
263 }
264 
265 
266 template <class U>
270  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
271 }
272 
273 template <class U>
277  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
278 }
279 
281 // template <>
282 inline long double operator*( const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
283  return v1.dot(v2);
284 }
285 
287 template <class U>
289  const Basic3DVector<U>& v2) {
290  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
291 }
292 
293 template <class U>
295  const Basic3DVector<long double>& v2 ) {
296  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
297 }
298 
299 
303 //template <>
305  return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
306 }
307 
309 // template <>
311  return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
312 }
313 
314 template <typename S>
316  return static_cast<long double>(t)*v;
317 }
318 
319 template <typename S>
321  return static_cast<long double>(t)*v;
322 }
323 
324 
328 template <typename S>
330  long double t = 1/s;
331  return v*t;
332 }
333 
334 
336 
337 #ifdef __clang__
338 #pragma clang diagnostic pop
339 #endif
340 
341 #endif // GeometryVector_Basic3DVectorLD_h
342 
343 
344 
tuple ret
prodAgent to be discontinued
Basic2DVector< T > xy() const
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:74
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.
Geom::Phi< T > phi() const
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
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)
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
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.
float __attribute__((vector_size(8))) float32x2_t
Definition: ExtVec.h:12
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.
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
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
T bareTheta() const
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 operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
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:20
Geom::Theta< T > theta() const
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)