CMS 3D CMS Logo

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 
14  inline float __attribute__((always_inline)) __attribute__((pure)) eta(float x, float y, float z) {
15  float t(z / std::sqrt(x * x + y * y));
16  return ::asinhf(t);
17  }
18  inline double __attribute__((always_inline)) __attribute__((pure)) eta(double x, double y, double z) {
19  double t(z / std::sqrt(x * x + y * y));
20  return ::asinh(t);
21  }
22  inline long double __attribute__((always_inline)) __attribute__((pure))
23  eta(long double x, long double y, long double z) {
24  long double t(z / std::sqrt(x * x + y * y));
25  return ::asinhl(t);
26  }
27 } // namespace detailsBasic3DVector
28 
29 template <typename T>
31 public:
32  typedef T ScalarType;
37  typedef Spherical Polar; // synonym
38 
43  Basic3DVector() : v{0, 0, 0, 0} {}
44 
46  Basic3DVector(const Basic3DVector& p) : v(p.v) {}
47 
49  template <class U>
50  Basic3DVector(const Basic3DVector<U>& p) : v{T(p.v[0]), T(p.v[1]), T(p.v[2]), T(p.v[3])} {}
51 
53  Basic3DVector(const Basic2DVector<T>& p) : v{p.x(), p.y(), 0} {}
54 
63  template <class OtherPoint>
64  explicit Basic3DVector(const OtherPoint& p) : v{T(p.x()), T(p.y()), T(p.z())} {}
65 
66  // constructor from Vec4
67  Basic3DVector(MathVector const& iv) : v(iv) {}
68 
69  template <class U>
70  Basic3DVector(Vec4<U> const& iv) : v{T(iv[0]), T(iv[1]), T(iv[2]), T(iv[3])} {}
71 
73  Basic3DVector(const T& x, const T& y, const T& z, const T& w = 0) : v{x, y, z, w} {}
74 
79  template <typename U>
80  Basic3DVector(const Geom::Theta<U>& theta, const Geom::Phi<U>& phi, const T& r) {
81  Polar p(theta.value(), phi.value(), r);
82  v[0] = p.x();
83  v[1] = p.y();
84  v[2] = p.z();
85  }
86 
87  MathVector const& mathVector() const { return v; }
88  MathVector& mathVector() { return v; }
89 
90  T operator[](int i) const { return v[i]; }
91  T& operator[](int i) { return v[i]; }
92 
94  T x() const { return v[0]; }
95 
97  T y() const { return v[1]; }
98 
100  T z() const { return v[2]; }
101 
102  T w() const { return v[3]; }
103 
105 
106  // equality
107  bool operator==(const Basic3DVector& rh) const {
108  auto res = v == rh.v;
109  return res[0] & res[1] & res[2] & res[3];
110  }
111 
113  T mag2() const { return ::dot(v, v); }
114 
116  T mag() const { return std::sqrt(mag2()); }
117 
119  T perp2() const { return ::dot2(v, v); }
120 
122  T perp() const { return std::sqrt(perp2()); }
123 
125  T transverse() const { return perp(); }
126 
131  T barePhi() const { return std::atan2(y(), x()); }
132  Geom::Phi<T> phi() const { return Geom::Phi<T>(barePhi()); }
133 
138  T bareTheta() const { return std::atan2(perp(), z()); }
139  Geom::Theta<T> theta() const { return Geom::Theta<T>(std::atan2(perp(), z())); }
140 
145  // T eta() const { return -log( tan( theta()/2.));}
146  T eta() const { return detailsBasic3DVector::eta(x(), y(), z()); } // correct
147 
151  Basic3DVector unit() const {
152  T my_mag = mag2();
153  return (0 != my_mag) ? (*this) * (T(1) / std::sqrt(my_mag)) : *this;
154  }
158  template <class U>
160  v = v + p.v;
161  return *this;
162  }
163 
166  template <class U>
168  v = v - p.v;
169  return *this;
170  }
171 
173  Basic3DVector operator-() const { return Basic3DVector(-v); }
174 
177  v = t * v;
178  return *this;
179  }
180 
183  //t = T(1)/t;
184  v = v / t;
185  return *this;
186  }
189  T dot(const Basic3DVector& rh) const { return ::dot(v, rh.v); }
190 
196  template <class U>
200  }
201 
204 
210  template <class U>
214  }
215 
216 public:
218 } __attribute__((aligned(16)));
219 
220 namespace geometryDetails {
221  std::ostream& print3D(std::ostream& s, double x, double y, double z);
222 }
225 template <class T>
226 inline std::ostream& operator<<(std::ostream& s, const Basic3DVector<T>& v) {
227  return geometryDetails::print3D(s, v.x(), v.y(), v.z());
228 }
229 
231 template <class T>
233  return a.v + b.v;
234 }
235 template <class T>
237  return a.v - b.v;
238 }
240 template <class T, class U>
242  const Basic3DVector<U>& b) {
244  return RT(a).v + RT(b).v;
245 }
246 
247 template <class T, class U>
249  const Basic3DVector<U>& b) {
251  return RT(a).v - RT(b).v;
252 }
253 
255 template <class T>
256 inline T operator*(const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
257  return v1.dot(v2);
258 }
259 
261 template <class T, class U>
263  return v1.dot(v2);
264 }
265 
269 template <class T>
271  return v.v * t;
272 }
273 
275 template <class T>
277  return v.v * t;
278 }
279 
280 template <class T, typename S>
282  return static_cast<T>(t) * v;
283 }
284 
285 template <class T, typename S>
287  return static_cast<T>(t) * v;
288 }
289 
293 template <class T>
295  return v.v / t;
296 }
297 
298 template <class T, typename S>
300  // T t = S(1)/s; return v*t;
301  T t = s;
302  return v / t;
303 }
304 
307 
308 // add long double specialization
309 #include "Basic3DVectorLD.h"
310 
311 #endif // GeometryVector_Basic3DVector_h
Basic3DVector(MathVector const &iv)
Basic3DVector< T > operator+(const Basic3DVector< T > &a, const Basic3DVector< T > &b)
vector sum and subtraction of vectors of possibly different precision
int32_t *__restrict__ iv
T x() const
Cartesian x coordinate.
T & operator[](int i)
T perp2() const
Squared magnitude of transverse component.
Basic3DVector(const T &x, const T &y, const T &z, const T &w=0)
construct from cartesian coordinates
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
class Basic3DVector __attribute__((aligned(16)))
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
bool operator==(const Basic3DVector &rh) const
Basic2DVector< T > xy() const
Vec4< T > MathVector
Vec cross3(Vec x, Vec y)
Definition: ExtVec.h:87
bool int lh
Definition: SIMDVec.h:20
T y() const
Cartesian y coordinate.
T operator[](int i) const
float float float z
Definition: Electron.h:6
Geom::Theta< T > theta() const
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &lh) const
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &lh) const
T bareTheta() const
T sqrt(T t)
Definition: SSEVec.h:19
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
Basic3DVector & operator+=(const Basic3DVector< U > &p)
T transverse() const
Another name for perp()
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:60
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Basic2DVector< T > xy() const
MathVector const & mathVector() const
Basic3DVector< T > operator/(const Basic3DVector< T > &v, T t)
Basic3DVector & operator-=(const Basic3DVector< U > &p)
T operator*(const Basic3DVector< T > &v1, const Basic3DVector< T > &v2)
scalar product of vectors of same precision
Basic3DVector(Vec4< U > const &iv)
T perp() const
Magnitude of transverse component.
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
T z() const
Cartesian z coordinate.
Geom::Spherical2Cartesian< T > Spherical
double b
Definition: hdecay.h:120
Vec4< T > VectorType
MathVector & mathVector()
Geom::Cylindrical2Cartesian< T > Cylindrical
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
float __attribute__((always_inline)) __attribute__((pure)) eta(float x
double a
Definition: hdecay.h:121
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
float x
Basic3DVector unit() const
Basic3DVector< float > Basic3DVectorF
Geom::Phi< T > phi() const
std::ostream & print3D(std::ostream &s, double x, double y, double z)
Definition: print.cc:5
T eta() const
long double T
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Basic3DVector(const OtherPoint &p)
Definition: Phi.h:52
auto dot2(V1 x, V2 y) -> typename std::remove_reference< decltype(x[0])>::type
Definition: ExtVec.h:139
Vec4< T > v