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 
5 // long double specialization
6 template <>
7 class Basic3DVector<long double> {
8 public:
9 
10 
11  typedef long double T;
12  typedef T ScalarType;
15  typedef Spherical Polar; // synonym
16 
18 
23  Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
24 
27  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
28 
30  template <class U>
32  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
33 
36  theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
37 
46  template <class OtherPoint>
47  explicit Basic3DVector( const OtherPoint& p) :
48  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
49 
50 
51 #ifndef __REFLEX__
52  // constructor from Vec4
53  template<typename U>
55  theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
56 #endif
57 
59  Basic3DVector( const T& x, const T& y, const T& z) :
60  theX(x), theY(y), theZ(z), theW(0) {}
61 
66  template <typename U>
68  const Geom::Phi<U>& phi, const T& r) {
69  Polar p( theta.value(), phi.value(), r);
70  theX = p.x(); theY = p.y(); theZ = p.z();
71  }
72 
74  T x() const { return theX;}
75 
77  T y() const { return theY;}
78 
80  T z() const { return theZ;}
81 
83 
84 
85  // equality
86  bool operator==(const Basic3DVector& rh) const {
87  return x()==rh.x() && y()==rh.y() && z()==rh.z();
88  }
89 
91  T mag2() const { return x()*x() + y()*y()+z()*z();}
92 
94  T mag() const { return std::sqrt( mag2());}
95 
97  T perp2() const { return x()*x() + y()*y();}
98 
100  T perp() const { return std::sqrt( perp2());}
101 
103  T transverse() const { return perp();}
104 
109  T barePhi() const {return std::atan2(y(),x());}
110  Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
111 
116  T bareTheta() const {return std::atan2(perp(),z());}
117  Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
118 
123  // T eta() const { return -log( tan( theta()/2.));}
124  T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct
126 
130  Basic3DVector unit() const {
131  T my_mag = mag2();
132  if (my_mag==0) return *this;
133  my_mag = T(1)/std::sqrt(my_mag);
135  return ret*=my_mag;
136  }
137 
140  template <class U>
142  theX += p.x();
143  theY += p.y();
144  theZ += p.z();
145  return *this;
146  }
147 
150  template <class U>
152  theX -= p.x();
153  theY -= p.y();
154  theZ -= p.z();
155  return *this;
156  }
159  Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
160 
163  theX *= t;
164  theY *= t;
165  theZ *= t;
166  return *this;
167  }
168 
171  t = T(1)/t;
172  theX *= t;
173  theY *= t;
174  theZ *= t;
175  return *this;
176  }
177 
179  T dot( const Basic3DVector& v) const {
180  return x()*v.x() + y()*v.y() + z()*v.z();
181  }
182 
188  template <class U>
190  return x()*v.x() + y()*v.y() + z()*v.z();
191  }
192 
195  return Basic3DVector( y()*v.z() - v.y()*z(),
196  z()*v.x() - v.z()*x(),
197  x()*v.y() - v.x()*y());
198  }
200 
206  template <class U>
208  cross( const Basic3DVector<U>& v) const {
209  return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(),
210  z()*v.x() - v.z()*x(),
211  x()*v.y() - v.x()*y());
212  }
213 
214 private:
219 }
220 #ifndef __CINT__
221 __attribute__ ((aligned (16)))
222 #endif
223 ;
224 
225 
229  typedef Basic3DVector<long double> RT;
230  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
231 }
234  typedef Basic3DVector<long double> RT;
235  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
236 }
238 
239 
240 template <class U>
244  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
245 }
246 
247 template <class U>
251  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
252 }
253 
254 
255 template <class U>
259  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
260 }
261 
262 template <class U>
266  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
267 }
268 
270 // template <>
271 inline long double operator*( const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
272  return v1.dot(v2);
273 }
274 
276 template <class U>
278  const Basic3DVector<U>& v2) {
279  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
280 }
281 
282 template <class U>
284  const Basic3DVector<long double>& v2 ) {
285  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
286 }
287 
288 
292 //template <>
294  return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
295 }
296 
298 // template <>
300  return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
301 }
302 
303 template <typename S>
305  return static_cast<long double>(t)*v;
306 }
307 
308 template <typename S>
310  return static_cast<long double>(t)*v;
311 }
312 
313 
317 template <typename S>
319  long double t = 1/s;
320  return v*t;
321 }
322 
323 
325 
326 
327 #endif // GeometryVector_Basic3DVectorLD_h
328 
329 
330 
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
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
Basic3DVector unit() 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 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
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
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:46
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
mathSSE::Vec4< T > v
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.
double a
Definition: hdecay.h:121
T y() const
Cartesian y coordinate.
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
T z() const
Cartesian z coordinate.
Geom::Cylindrical2Cartesian< T > Cylindrical
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
class Geom::Polar2Cartesian __attribute__
Basic3DVector(mathSSE::Vec4< U > const &iv)
Geom::Theta< T > theta() const
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.