CMS 3D CMS Logo

oldBasic3DVector.h
Go to the documentation of this file.
1 #ifndef GeometryVector_oldBasic3DVector_h
2 #define GeometryVector_oldBasic3DVector_h
3 #if ( defined(__CLING__) || defined(__CINT__) ) && !defined(__REFLEX__)
4 #define __REFLEX__
5 #endif
11 #ifndef __REFLEX__
13 #endif
14 #include <iosfwd>
15 #include <cmath>
16 
17 
18 namespace detailsBasic3DVector {
19  inline float __attribute__((always_inline)) __attribute__ ((pure))
20  eta(float x, float y, float z) { float t(z/std::sqrt(x*x+y*y)); return ::asinhf(t);}
21  inline double __attribute__((always_inline)) __attribute__ ((pure))
22  eta(double x, double y, double z) { double t(z/std::sqrt(x*x+y*y)); return ::asinh(t);}
23  inline long double __attribute__((always_inline)) __attribute__ ((pure))
24  eta(long double x, long double y, long double z) { long double t(z/std::sqrt(x*x+y*y)); return ::asinhl(t);}
25 }
26 
27 
28 template < typename T>
29 class Basic3DVector {
30 public:
32 
33 
34  typedef T ScalarType;
37  typedef Spherical Polar; // synonym
38 
43  Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
44 
47  theX(p.x()), theY(p.y()), theZ(p.z()), theW(p.w()) {}
48 
50  template <class U>
52  theX(p.x()), theY(p.y()), theZ(p.z()), theW(p.w()) {}
53 
56  theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
57 
66  template <class OtherPoint>
67  explicit Basic3DVector( const OtherPoint& p) :
68  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
69 
70 
71 #if defined(USE_EXTVECT)
72  template<typename U>
73  Basic3DVector(Vec4<U> const& iv) :
74  theX(iv[0]), theY(iv[1]), theZ(iv[2]), theW(0) {}
75 #elif defined(USE_SSEVECT)
76  // constructor from Vec4
77  template<typename U>
78  Basic3DVector(mathSSE::Vec4<U> const& iv) :
79  theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
80 #endif
81 
82 #ifndef __REFLEX__
83  Basic3DVector( const T& x, const T& y, const T& z, const T& w=0) :
85  theX(x), theY(y), theZ(z), theW(w) {}
86 #else
87  Basic3DVector( const T& x, const T& y, const T& z) :
89  theX(x), theY(y), theZ(z), theW(0) {}
90  Basic3DVector( const T& x, const T& y, const T& z, const T& w) :
91  theX(x), theY(y), theZ(z), theW(w) {}
92 #endif
93 
94 
95 
100  template <typename U>
102  const Geom::Phi<U>& phi, const T& r) {
103  Polar p( theta.value(), phi.value(), r);
104  theX = p.x(); theY = p.y(); theZ = p.z();
105  }
106 
107 
108  T operator[](int i) const { return *((&theX)+i) ;}
109  T & operator[](int i) { return *((&theX)+i);}
110 
111 
112 
114  T x() const { return theX;}
115 
117  T y() const { return theY;}
118 
120  T z() const { return theZ;}
121 
122  T w() const { return theW;}
123 
124 
126 
127 
128  // equality
129  bool operator==(const Basic3DVector& rh) const {
130  return x()==rh.x() && y()==rh.y() && z()==rh.z();
131  }
132 
134  T mag2() const { return x()*x() + y()*y()+z()*z();}
135 
137  T mag() const { return std::sqrt( mag2());}
138 
140  T perp2() const { return x()*x() + y()*y();}
141 
143  T perp() const { return std::sqrt( perp2());}
144 
146  T transverse() const { return perp();}
147 
152  T barePhi() const {return std::atan2(y(),x());}
153  Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
154 
159  T bareTheta() const {return std::atan2(perp(),z());}
160  Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
161 
166  // T eta() const { return -log( tan( theta()/2.));}
167  T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct
168 
172  Basic3DVector unit() const {
173  T my_mag = mag2();
174  if (my_mag==0) return *this;
175  my_mag = T(1)/std::sqrt(my_mag);
176  return *this * my_mag;
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  }
189 
192  template <class U>
194  theX -= p.x();
195  theY -= p.y();
196  theZ -= p.z();
197  theW -= p.w();
198  return *this;
199  }
200 
202  Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
203 
206  theX *= t;
207  theY *= t;
208  theZ *= t;
209  theW *= t;;
210  return *this;
211  }
212 
215  t = T(1)/t;
216  theX *= t;
217  theY *= t;
218  theZ *= t;
219  theW *= t;;
220  return *this;
221  }
222 
224  T dot( const Basic3DVector& v) const {
225  return x()*v.x() + y()*v.y() + z()*v.z();
226  }
227 
233  template <class U>
235  return x()*v.x() + y()*v.y() + z()*v.z();
236  }
237 
240  return Basic3DVector( y()*v.z() - v.y()*z(),
241  z()*v.x() - v.z()*x(),
242  x()*v.y() - v.x()*y());
243  }
244 
245 
251  template <class U>
253  cross( const Basic3DVector<U>& v) const {
254  return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(),
255  z()*v.x() - v.z()*x(),
256  x()*v.y() - v.x()*y());
257  }
258 
259 private:
264 }
265 #ifndef __CINT__
266 __attribute__ ((aligned (16)))
267 #endif
268 ;
269 
270 
271 namespace geometryDetails {
272  std::ostream & print3D(std::ostream& s, double x, double y, double z);
273 }
274 
276 template <class T>
277 inline std::ostream & operator<<( std::ostream& s, const Basic3DVector<T>& v) {
278  return geometryDetails::print3D(s, v.x(),v.y(), v.z());
279 }
280 
281 
283 template <class T, class U>
287  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z(), a.w()+b.w());
288 }
289 
290 template <class T, class U>
294  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z(), a.w()-b.w());
295 }
296 
298 template <class T>
299 inline T operator*( const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
300  return v1.dot(v2);
301 }
302 
304 template <class T, class U>
306  const Basic3DVector<U>& v2) {
307  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
308 }
309 
313 template <class T>
315  return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t, v.w()*t);
316 }
317 
319 template <class T>
321  return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t, v.w()*t);
322 }
323 
324 template <class T, typename S>
326  return static_cast<T>(t)*v;
327 }
328 
329 template <class T, typename S>
331  return static_cast<T>(t)*v;
332 }
333 
334 
338 template <class T, typename S>
340  T t = T(1)/s;
341  return v*t;
342 }
343 
344 
348 
349 
350 #endif // GeometryVector_Basic3DVector_h
351 
352 
Phi.h
Basic3DVector::theta
Geom::Theta< T > theta() const
Definition: extBasic3DVector.h:139
Basic3DVector::Basic3DVector
Basic3DVector(const OtherPoint &p)
Definition: oldBasic3DVector.h:67
mps_fire.i
i
Definition: mps_fire.py:428
Basic3DVector::transverse
T transverse() const
Another name for perp()
Definition: oldBasic3DVector.h:146
Basic3DVector::xy
Basic2DVector< T > xy() const
Definition: oldBasic3DVector.h:125
Basic3DVector::Basic3DVector
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
Definition: oldBasic3DVector.h:101
SIMDVec.h
Basic3DVector::operator/=
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Definition: extBasic3DVector.h:182
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
operator+
Basic3DVector< typename PreciseFloatType< T, U >::Type > operator+(const Basic3DVector< T > &a, const Basic3DVector< U > &b)
vector sum and subtraction of vectors of possibly different precision
Definition: oldBasic3DVector.h:285
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Geom::Theta
Definition: Theta.h:12
Basic3DVector::perp2
T perp2() const
Squared magnitude of transverse component.
Definition: oldBasic3DVector.h:140
CoordinateSets.h
Geom::Spherical2Cartesian
Definition: CoordinateSets.h:58
Vec4
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:64
operator<<
std::ostream & operator<<(std::ostream &s, const Basic3DVector< T > &v)
simple text output to standard streams
Definition: oldBasic3DVector.h:277
Basic3DVector::ScalarType
T ScalarType
Definition: oldBasic3DVector.h:34
Basic3DVector::theZ
T theZ
Definition: oldBasic3DVector.h:262
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Basic3DVector::eta
T eta() const
Definition: oldBasic3DVector.h:167
Basic3DVector::mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: oldBasic3DVector.h:137
Basic3DVector::theY
T theY
Definition: oldBasic3DVector.h:261
Basic3DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: oldBasic3DVector.h:134
operator*
T operator*(const Basic3DVector< T > &v1, const Basic3DVector< T > &v2)
scalar product of vectors of same precision
Definition: oldBasic3DVector.h:299
Basic3DVector< long double >
Definition: Basic3DVectorLD.h:12
Basic3DVector::dot
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &v) const
Definition: oldBasic3DVector.h:234
eta
T eta() const
Definition: oldBasic3DVector.h:308
Basic3DVector::theX
T theX
Definition: oldBasic3DVector.h:260
Basic3DVector::Basic3DVector
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: oldBasic3DVector.h:46
Basic3DVector::Polar
Spherical Polar
Definition: oldBasic3DVector.h:37
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Basic3DVector::w
T w() const
Definition: extBasic3DVector.h:102
Basic3DVector::cross
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &v) const
Definition: oldBasic3DVector.h:253
Basic3DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic3DVector.h:97
Basic3DVector::dot
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Definition: oldBasic3DVector.h:224
PreciseFloatType.h
detailsBasic3DVector::__attribute__
float __attribute__((always_inline)) __attribute__((pure)) eta(float x
geometryDetails::print3D
std::ostream & print3D(std::ostream &s, double x, double y, double z)
Definition: print.cc:5
Basic3DVector::operator[]
T operator[](int i) const
Definition: oldBasic3DVector.h:108
Basic3DVector::operator*=
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Definition: extBasic3DVector.h:176
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Geom::Cylindrical2Cartesian
Definition: CoordinateSets.h:34
Basic3DVector::dot
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: extBasic3DVector.h:189
b
double b
Definition: hdecay.h:118
Basic3DVector::operator==
bool operator==(const Basic3DVector &rh) const
Definition: oldBasic3DVector.h:129
Basic3DVector::MathVector
Basic3DVector< T > MathVector
Definition: oldBasic3DVector.h:31
__attribute__
class Basic3DVector __attribute__((aligned(16)))
operator/
Basic3DVector< T > operator/(const Basic3DVector< T > &v, S s)
Definition: oldBasic3DVector.h:339
Basic2DVector
Definition: extBasic2DVector.h:15
Basic3DVectorD
Basic3DVector< double > Basic3DVectorD
Definition: oldBasic3DVector.h:346
a
double a
Definition: hdecay.h:119
Basic3DVector::barePhi
T barePhi() const
Definition: oldBasic3DVector.h:152
Basic3DVector::cross
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Definition: oldBasic3DVector.h:239
mathSSE::Vec4
Definition: SSEVec.h:115
Basic3DVector::operator[]
T & operator[](int i)
Definition: oldBasic3DVector.h:109
Basic3DVector::theW
T theW
Definition: oldBasic3DVector.h:263
Basic3DVector::operator+=
Basic3DVector & operator+=(const Basic3DVector< U > &p)
Definition: extBasic3DVector.h:159
Theta.h
Geom::Phi
Definition: Phi.h:52
Basic3DVector::operator-
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: oldBasic3DVector.h:202
Basic3DVector::operator-=
Basic3DVector & operator-=(const Basic3DVector< U > &p)
Definition: extBasic3DVector.h:167
PreciseFloatType::Type
double Type
Definition: PreciseFloatType.h:24
geometryDetails
Definition: extTkRotation.h:21
Basic3DVector::v
Vec4< T > v
Definition: extBasic3DVector.h:217
Basic3DVectorLD
Basic3DVector< long double > Basic3DVectorLD
Definition: oldBasic3DVector.h:347
alignCSCRings.r
r
Definition: alignCSCRings.py:93
Basic3DVector::Basic3DVector
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
Definition: oldBasic3DVector.h:51
Basic2DVector.h
T
long double T
Definition: Basic3DVectorLD.h:48
Basic3DVector::Spherical
Geom::Spherical2Cartesian< T > Spherical
Definition: oldBasic3DVector.h:36
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
Basic3DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic3DVector.h:94
S
Definition: CSCDBL1TPParametersExtended.h:16
Basic3DVector::Cylindrical
Geom::Cylindrical2Cartesian< T > Cylindrical
Definition: oldBasic3DVector.h:35
Basic3DVector::perp
T perp() const
Magnitude of transverse component.
Definition: oldBasic3DVector.h:143
Basic3DVector::Basic3DVector
Basic3DVector()
Definition: oldBasic3DVector.h:43
Basic3DVector::bareTheta
T bareTheta() const
Definition: oldBasic3DVector.h:159
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
Basic3DVector::z
T z() const
Cartesian z coordinate.
Definition: extBasic3DVector.h:100
Basic3DVector::unit
Basic3DVector unit() const
Definition: extBasic3DVector.h:151
Basic3DVector::phi
Geom::Phi< T > phi() const
Definition: extBasic3DVector.h:132
Basic3DVector::Basic3DVector
Basic3DVector(const Basic2DVector< T > &p)
constructor from 2D vector (X and Y from 2D vector, z set to zero)
Definition: oldBasic3DVector.h:55
operator-
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: oldBasic3DVector.h:343
Basic3DVector
Definition: extBasic3DVector.h:30
Basic3DVectorF
Basic3DVector< float > Basic3DVectorF
Definition: oldBasic3DVector.h:345
detailsBasic3DVector
Definition: extBasic3DVector.h:13