CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oldBasic3DVector.h
Go to the documentation of this file.
1 #ifndef GeometryVector_oldBasic3DVector_h
2 #define GeometryVector_oldBasic3DVector_h
3 #if defined(__CINT__) && !defined(__REFLEX__)
4 #define __REFLEX__
5 #endif
11 #ifndef __REFLEX__
13 #endif
14 #include <iosfwd>
15 #include <cmath>
16 
17 namespace detailsBasic3DVector {
18  inline float __attribute__((always_inline)) __attribute__ ((pure))
19  eta(float x, float y, float z) { float t(z/std::sqrt(x*x+y*y)); return ::asinhf(t);}
20  inline double __attribute__((always_inline)) __attribute__ ((pure))
21  eta(double x, double y, double z) { double t(z/std::sqrt(x*x+y*y)); return ::asinh(t);}
22  inline long double __attribute__((always_inline)) __attribute__ ((pure))
23  eta(long double x, long double y, long double z) { long double t(z/std::sqrt(x*x+y*y)); return ::asinhl(t);}
24 }
25 
26 
27 template < typename T>
28 class Basic3DVector {
29 public:
31 
32 
33  typedef T ScalarType;
36  typedef Spherical Polar; // synonym
37 
42  Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
43 
46  theX(p.x()), theY(p.y()), theZ(p.z()), theW(p.w()) {}
47 
49  template <class U>
51  theX(p.x()), theY(p.y()), theZ(p.z()), theW(p.w()) {}
52 
55  theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
56 
65  template <class OtherPoint>
66  explicit Basic3DVector( const OtherPoint& p) :
67  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
68 
69 
70 #ifndef __REFLEX__
71  // constructor from Vec4
72  template<typename U>
74  theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
75 #endif
76 
77 #ifndef __REFLEX__
78  Basic3DVector( const T& x, const T& y, const T& z, const T& w=0) :
80  theX(x), theY(y), theZ(z), theW(w) {}
81 #else
82  Basic3DVector( const T& x, const T& y, const T& z) :
84  theX(x), theY(y), theZ(z), theW(0) {}
85  Basic3DVector( const T& x, const T& y, const T& z, const T& w) :
86  theX(x), theY(y), theZ(z), theW(w) {}
87 #endif
88 
89 
90 
95  template <typename U>
97  const Geom::Phi<U>& phi, const T& r) {
98  Polar p( theta.value(), phi.value(), r);
99  theX = p.x(); theY = p.y(); theZ = p.z();
100  }
101 
103  T x() const { return theX;}
104 
106  T y() const { return theY;}
107 
109  T z() const { return theZ;}
110 
111  T w() const { return theW;}
112 
113 
115 
116 
117  // equality
118  bool operator==(const Basic3DVector& rh) const {
119  return x()==rh.x() && y()==rh.y() && z()==rh.z();
120  }
121 
123  T mag2() const { return x()*x() + y()*y()+z()*z();}
124 
126  T mag() const { return std::sqrt( mag2());}
127 
129  T perp2() const { return x()*x() + y()*y();}
130 
132  T perp() const { return std::sqrt( perp2());}
133 
135  T transverse() const { return perp();}
136 
141  T barePhi() const {return std::atan2(y(),x());}
142  Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
143 
148  T bareTheta() const {return std::atan2(perp(),z());}
149  Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
150 
155  // T eta() const { return -log( tan( theta()/2.));}
156  T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct
157 
161  Basic3DVector unit() const {
162  T my_mag = mag2();
163  if (my_mag==0) return *this;
164  my_mag = T(1)/std::sqrt(my_mag);
165  return *this * my_mag;
166  }
167 
170  template <class U>
172  theX += p.x();
173  theY += p.y();
174  theZ += p.z();
175  theW += p.w();
176  return *this;
177  }
178 
181  template <class U>
183  theX -= p.x();
184  theY -= p.y();
185  theZ -= p.z();
186  theW -= p.w();
187  return *this;
188  }
191  Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
192 
195  theX *= t;
196  theY *= t;
197  theZ *= t;
198  theW *= t;;
199  return *this;
200  }
204  t = T(1)/t;
205  theX *= t;
206  theY *= t;
207  theZ *= t;
208  theW *= t;;
209  return *this;
210  }
211 
213  T dot( const Basic3DVector& v) const {
214  return x()*v.x() + y()*v.y() + z()*v.z();
215  }
216 
222  template <class U>
223  typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const {
224  return x()*v.x() + y()*v.y() + z()*v.z();
225  }
226 
228  Basic3DVector cross( const Basic3DVector& v) const {
229  return Basic3DVector( y()*v.z() - v.y()*z(),
230  z()*v.x() - v.z()*x(),
231  x()*v.y() - v.x()*y());
232  }
233 
234 
240  template <class U>
242  cross( const Basic3DVector<U>& v) const {
243  return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(),
244  z()*v.x() - v.z()*x(),
245  x()*v.y() - v.x()*y());
246  }
247 
248 private:
253 }
254 #ifndef __CINT__
255 __attribute__ ((aligned (16)))
256 #endif
257 ;
259 
260 namespace geometryDetails {
261  std::ostream & print3D(std::ostream& s, double x, double y, double z);
262 }
263 
265 template <class T>
266 inline std::ostream & operator<<( std::ostream& s, const Basic3DVector<T>& v) {
267  return geometryDetails::print3D(s, v.x(),v.y(), v.z());
268 }
269 
272 template <class T, class U>
276  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z(), a.w()+b.w());
277 }
278 
279 template <class T, class U>
283  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z(), a.w()-b.w());
284 }
285 
287 template <class T>
288 inline T operator*( const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
289  return v1.dot(v2);
290 }
293 template <class T, class U>
295  const Basic3DVector<U>& v2) {
296  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
297 }
298 
302 template <class T>
304  return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t, v.w()*t);
305 }
308 template <class T>
310  return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t, v.w()*t);
311 }
312 
313 template <class T, typename S>
315  return static_cast<T>(t)*v;
316 }
318 template <class T, typename S>
320  return static_cast<T>(t)*v;
321 }
322 
323 
327 template <class T, typename S>
329  T t = T(1)/s;
330  return v*t;
331 }
332 
333 
337 
339 #endif // GeometryVector_Basic3DVector_h
340 
341 
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &v) const
Basic2DVector< T > xy() const
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &v) const
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
T perp2() const
Squared magnitude of transverse component.
Geom::Theta< T > theta() const
T barePhi() const
Basic3DVector unit() const
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
bool operator==(const Basic3DVector &rh) const
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Geom::Phi< T > phi() const
T eta() const
double double double z
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Basic3DVector(mathSSE::Vec4< U > const &iv)
Basic3DVector< float > Basic3DVectorF
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
float float float z float t(z/std::sqrt(x *x+y *y))
T z() const
Cartesian z coordinate.
T sqrt(T t)
Definition: SSEVec.h:46
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Basic3DVector & operator+=(const Basic3DVector< U > &p)
mathSSE::Vec4< T > v
Basic3DVector< T > MathVector
T perp() const
Magnitude of transverse component.
Basic3DVector< double > Basic3DVectorD
Basic3DVector & operator-=(const Basic3DVector< U > &p)
Basic3DVector< long double > Basic3DVectorLD
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
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
Basic3DVector(const Basic2DVector< T > &p)
constructor from 2D vector (X and Y from 2D vector, z set to zero)
Geom::Spherical2Cartesian< T > Spherical
double b
Definition: hdecay.h:120
Geom::Cylindrical2Cartesian< T > Cylindrical
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
float __attribute__((always_inline)) __attribute__((pure)) eta(float x
double a
Definition: hdecay.h:121
T transverse() const
Another name for perp()
T bareTheta() 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)
Definition: DDAxes.h:10
std::ostream & print3D(std::ostream &s, double x, double y, double z)
Definition: print.cc:5
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
long double T
Basic3DVector(const OtherPoint &p)
Definition: Phi.h:20
class Geom::Polar2Cartesian __attribute__
mathSSE::Vec4< T > v
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T dot(const Basic3DVector &rh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.