CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
extBasic3DVector.h
Go to the documentation of this file.
1 #ifndef GeometryVector_newBasic3DVector_h
2 #define GeometryVector_newBasic3DVector_h
3 
10 #include <iosfwd>
11 #include <cmath>
12 
13 namespace detailsBasic3DVector {
14  inline float __attribute__((always_inline)) __attribute__ ((pure))
15  eta(float x, float y, float z) { float t(z/std::sqrt(x*x+y*y)); return ::asinhf(t);}
16  inline double __attribute__((always_inline)) __attribute__ ((pure))
17  eta(double x, double y, double z) { double t(z/std::sqrt(x*x+y*y)); return ::asinh(t);}
18  inline long double __attribute__((always_inline)) __attribute__ ((pure))
19  eta(long double x, long double y, long double z) { long double t(z/std::sqrt(x*x+y*y)); return ::asinhl(t);}
20 }
21 
22 
23 template < typename T>
25 public:
26 
27  typedef T ScalarType;
32  typedef Spherical Polar; // synonym
33 
38  Basic3DVector() : v{0,0,0,0} {}
39 
42  v(p.v) {}
43 
45  template <class U>
47  v{T(p.v[0]),T(p.v[1]),T(p.v[2]),T(p.v[3])} {}
48 
49 
52  v{p.x(),p.y(),0} {}
53 
54 
63  template <class OtherPoint>
64  explicit Basic3DVector( const OtherPoint& p) :
65  v{T(p.x()),T(p.y()),T(p.z())} {}
66 
67 
68  // constructor from Vec4
70  v(iv) {}
71 
72  template<class U>
73  Basic3DVector(Vec4<U> const& iv) :
74  v{T(iv[0]),T(iv[1]),T(iv[2]),T(iv[3])} {}
75 
77  Basic3DVector( const T& x, const T& y, const T& z, const T&w=0) :
78  v{x,y,z,w}{}
79 
84  template <typename U>
86  const Geom::Phi<U>& phi, const T& r) {
87  Polar p( theta.value(), phi.value(), r);
88  v[0] = p.x(); v[1] = p.y(); v[2] = p.z();
89  }
90 
91  MathVector const & mathVector() const { return v;}
92  MathVector & mathVector() { return v;}
93 
94  T operator[](int i) const { return v[i];}
95  T & operator[](int i) { return v[i];}
96 
97 
99  T x() const { return v[0];}
100 
102  T y() const { return v[1];}
103 
105  T z() const { return v[2];}
106 
107  T w() const { return v[3];}
108 
110 
111  // equality
112  bool operator==(const Basic3DVector& rh) const {
113  auto res = v==rh.v;
114  return res[0]&res[1]&res[2]&res[3];
115  }
116 
118  T mag2() const { return ::dot(v,v);}
119 
121  T mag() const { return std::sqrt( mag2());}
122 
124  T perp2() const { return ::dot2(v,v);}
125 
127  T perp() const { return std::sqrt( perp2());}
128 
130  T transverse() const { return perp();}
131 
136  T barePhi() const {return std::atan2(y(),x());}
137  Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
138 
143  T bareTheta() const {return std::atan2(perp(),z());}
144  Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
145 
150  // T eta() const { return -log( tan( theta()/2.));}
151  T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct
152 
156  Basic3DVector unit() const {
157  T my_mag = mag2();
158  return (0!=my_mag) ? (*this)*(T(1)/std::sqrt(my_mag)) : *this;
159  }
160 
163  template <class U>
165  v = v + p.v;
166  return *this;
167  }
171  template <class U>
173  v = v - p.v;
174  return *this;
175  }
178  Basic3DVector operator-() const { return Basic3DVector(-v);}
182  v = t*v;
183  return *this;
184  }
185 
188  //t = T(1)/t;
189  v = v/t;
190  return *this;
191  }
192 
194  T dot( const Basic3DVector& rh) const {
195  return ::dot(v,rh.v);
196  }
197 
203  template <class U>
207  }
208 
212  }
213 
214 
220  template <class U>
222  cross( const Basic3DVector<U>& lh) const {
225  }
226 
227 public:
229 } __attribute__ ((aligned (16)));
230 
231 
232 namespace geometryDetails {
233  std::ostream & print3D(std::ostream& s, double x, double y, double z);
234 }
235 
237 template <class T>
238 inline std::ostream & operator<<( std::ostream& s, const Basic3DVector<T>& v) {
239  return geometryDetails::print3D(s, v.x(),v.y(), v.z());
240 }
241 
242 
244 template <class T>
247  return a.v+b.v;
248 }
249 template <class T>
252  return a.v-b.v;
253 }
254 
255 template <class T, class U>
259  return RT(a).v+RT(b).v;
260 }
261 
262 template <class T, class U>
266  return RT(a).v-RT(b).v;
267 }
270 template <class T>
271 inline T operator*( const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
272  return v1.dot(v2);
273 }
276 template <class T, class U>
278  const Basic3DVector<U>& v2) {
279  return v1.dot(v2);
280 }
285 template <class T>
287  return v.v*t;
288 }
291 template <class T>
293  return v.v*t;
294 }
295 
296 
297 
298 template <class T, typename S>
300  return static_cast<T>(t)*v;
301 }
303 template <class T, typename S>
305  return static_cast<T>(t)*v;
306 }
307 
308 
312 template <class T>
314  return v.v/t;
315 }
317 template <class T, typename S>
319  // T t = S(1)/s; return v*t;
320  T t = s;
321  return v/t;
322 }
323 
324 
327 
328 
329 // add long double specialization
330 #include "Basic3DVectorLD.h"
331 
332 #endif // GeometryVector_Basic3DVector_h
333 
334 
Basic3DVector(MathVector const &iv)
int i
Definition: DBlmapReader.cc:9
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())
T & operator[](int i)
Basic3DVector(const T &x, const T &y, const T &z, const T &w=0)
construct from cartesian coordinates
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:23
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
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or &quot;cross&quot; product, with a vector of same type.
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &lh) const
bool operator==(const Basic3DVector &rh) const
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Vec4< T > MathVector
Vec cross3(Vec x, Vec y)
Definition: ExtVec.h:55
Geom::Phi< T > phi() const
bool int lh
Definition: SIMDVec.h:19
T eta() const
float float float z
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
T z() const
Cartesian z coordinate.
auto dot2(V1 x, V2 y) -> typenamestd::remove_reference< decltype(x[0])>::type
Definition: ExtVec.h:111
T sqrt(T t)
Definition: SSEVec.h:48
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Basic3DVector & operator+=(const Basic3DVector< U > &p)
MathVector const & mathVector() const
T perp() const
Magnitude of transverse component.
Basic3DVector & operator-=(const Basic3DVector< U > &p)
T y() const
Cartesian y coordinate.
T operator[](int i) const
Basic3DVector(Vec4< U > const &iv)
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)
Basic3DVector< double > Basic3DVectorD
float __attribute__((vector_size(8))) float32x2_t
Definition: ExtVec.h:6
Geom::Spherical2Cartesian< T > Spherical
double b
Definition: hdecay.h:120
Vec4< T > VectorType
MathVector & mathVector()
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
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< float > Basic3DVectorF
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
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &lh) const
T x() const
Cartesian x coordinate.
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.