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 template < typename T>
18 class Basic3DVector {
19 public:
20 
21  typedef T ScalarType;
24  typedef Spherical Polar; // synonym
25 
30  Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
31 
34  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
35 
37  template <class U>
39  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
40 
43  theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
44 
53  template <class OtherPoint>
54  explicit Basic3DVector( const OtherPoint& p) :
55  theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
56 
57 
58 #ifndef __REFLEX__
59  // constructor from Vec4
60  template<typename U>
62  theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
63 #endif
64 
66  Basic3DVector( const T& x, const T& y, const T& z) :
67  theX(x), theY(y), theZ(z), theW(0) {}
68 
73  template <typename U>
75  const Geom::Phi<U>& phi, const T& r) {
76  Polar p( theta.value(), phi.value(), r);
77  theX = p.x(); theY = p.y(); theZ = p.z();
78  }
79 
81  T x() const { return theX;}
82 
84  T y() const { return theY;}
85 
87  T z() const { return theZ;}
88 
90 
91 
92  // equality
93  bool operator==(const Basic3DVector& rh) const {
94  return x()==rh.x() && y()==rh.y() && z()==rh.z();
95  }
96 
98  T mag2() const { return x()*x() + y()*y()+z()*z();}
99 
101  T mag() const { return std::sqrt( mag2());}
102 
104  T perp2() const { return x()*x() + y()*y();}
105 
107  T perp() const { return std::sqrt( perp2());}
108 
110  T transverse() const { return perp();}
111 
116  T barePhi() const {return std::atan2(y(),x());}
117  Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
118 
123  T bareTheta() const {return std::atan2(perp(),z());}
124  Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
125 
130  // T eta() const { return -log( tan( theta()/2.));}
131  T eta() const { T x(z()/perp()); return std::log(x+std::sqrt(x*x+T(1)));} // faster
132 
136  Basic3DVector unit() const {
137  T my_mag = mag2();
138  if (my_mag==0) return *this;
139  my_mag = T(1)/std::sqrt(my_mag);
140  return *this * my_mag;
141  }
142 
145  template <class U>
147  theX += p.x();
148  theY += p.y();
149  theZ += p.z();
150  return *this;
151  }
152 
155  template <class U>
157  theX -= p.x();
158  theY -= p.y();
159  theZ -= p.z();
160  return *this;
161  }
162 
164  Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
165 
168  theX *= t;
169  theY *= t;
170  theZ *= t;
171  return *this;
172  }
173 
176  t = T(1)/t;
177  theX *= t;
178  theY *= t;
179  theZ *= t;
180  return *this;
181  }
182 
184  T dot( const Basic3DVector& v) const {
185  return x()*v.x() + y()*v.y() + z()*v.z();
186  }
187 
193  template <class U>
195  return x()*v.x() + y()*v.y() + z()*v.z();
196  }
197 
200  return Basic3DVector( y()*v.z() - v.y()*z(),
201  z()*v.x() - v.z()*x(),
202  x()*v.y() - v.x()*y());
203  }
204 
205 
211  template <class U>
213  cross( const Basic3DVector<U>& v) const {
214  return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(),
215  z()*v.x() - v.z()*x(),
216  x()*v.y() - v.x()*y());
217  }
218 
219 private:
220  T theX;
221  T theY;
222  T theZ;
223  T theW;
224 }
225 #ifndef __CINT__
226 __attribute__ ((aligned (16)))
227 #endif
228 ;
230 
231 namespace geometryDetails {
232  std::ostream & print3D(std::ostream& s, double x, double y, double z);
233 }
234 
236 template <class T>
237 inline std::ostream & operator<<( std::ostream& s, const Basic3DVector<T>& v) {
238  return geometryDetails::print3D(s, v.x(),v.y(), v.z());
239 }
240 
243 template <class T, class U>
247  return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
248 }
249 
250 template <class T, class U>
254  return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
255 }
256 
258 template <class T>
259 inline T operator*( const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
260  return v1.dot(v2);
261 }
262 
264 template <class T, class U>
266  const Basic3DVector<U>& v2) {
267  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
268 }
269 
273 template <class T>
275  return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t);
276 }
277 
279 template <class T>
281  return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t);
282 }
284 template <class T, typename S>
286  return static_cast<T>(t)*v;
287 }
289 template <class T, typename S>
291  return static_cast<T>(t)*v;
292 }
293 
294 
298 template <class T, typename S>
300  T t = T(1)/s;
301  return v*t;
302 }
304 
307 
308 
309 #endif // GeometryVector_Basic3DVector_h
310 
311 
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())
class Geom::OnePiRange __attribute__
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
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)
Definition: DDAxes.h:10
T z() const
Cartesian z coordinate.
T sqrt(T t)
Definition: SSEVec.h:28
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Basic3DVector & operator+=(const Basic3DVector< U > &p)
mathSSE::Vec4< T > v
Basic2DVector< T > operator/(const Basic2DVector< T > &v, const Scalar &s)
T perp() const
Magnitude of transverse component.
Basic3DVector< double > Basic3DVectorD
Basic3DVector & operator-=(const Basic3DVector< U > &p)
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)
Log< T >::type log(const T &t)
Definition: Log.h:22
Geom::Spherical2Cartesian< T > Spherical
Basic3DVector(const T &x, const T &y, const T &z)
construct from cartesian coordinates
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.
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)
string s
Definition: asciidump.py:422
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())
Basic3DVector(const OtherPoint &p)
Definition: Phi.h:20
mathSSE::Vec4< T > v
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)