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  }
155 
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  }
187 
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 }
223 
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 }
239 
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
Phi.h
Basic3DVector::theta
Geom::Theta< T > theta() const
Definition: extBasic3DVector.h:139
Basic3DVector::Basic3DVector
Basic3DVector(const OtherPoint &p)
Definition: extBasic3DVector.h:64
mps_fire.i
i
Definition: mps_fire.py:428
Basic3DVector::transverse
T transverse() const
Another name for perp()
Definition: extBasic3DVector.h:125
Basic3DVector::xy
Basic2DVector< T > xy() const
Definition: extBasic3DVector.h:104
Basic3DVector::Basic3DVector
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
Definition: extBasic3DVector.h:80
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
Basic3DVector::cross
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &lh) const
Definition: extBasic3DVector.h:211
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: extBasic3DVector.h:119
CoordinateSets.h
Geom::Spherical2Cartesian
Definition: CoordinateSets.h:58
Vec4
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:64
Basic3DVector::ScalarType
T ScalarType
Definition: extBasic3DVector.h:32
mathSSE::lh
bool int lh
Definition: SIMDVec.h:20
Basic3DVector::Basic3DVector
Basic3DVector(const T &x, const T &y, const T &z, const T &w=0)
construct from cartesian coordinates
Definition: extBasic3DVector.h:73
Basic3DVector::mathVector
MathVector & mathVector()
Definition: extBasic3DVector.h:88
Basic3DVector::eta
T eta() const
Definition: extBasic3DVector.h:146
Basic3DVector::mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: extBasic3DVector.h:116
Basic3DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: extBasic3DVector.h:113
operator*
T operator*(const Basic3DVector< T > &v1, const Basic3DVector< T > &v2)
scalar product of vectors of same precision
Definition: extBasic3DVector.h:256
Basic3DVector::Basic3DVector
Basic3DVector(MathVector const &iv)
Definition: extBasic3DVector.h:67
Basic3DVector::Basic3DVector
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: extBasic3DVector.h:46
Basic3DVector::Basic3DVector
Basic3DVector(Vec4< U > const &iv)
Definition: extBasic3DVector.h:70
Basic3DVector::Polar
Spherical Polar
Definition: extBasic3DVector.h:37
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Basic3DVector::w
T w() const
Definition: extBasic3DVector.h:102
Basic3DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic3DVector.h:97
operator+
Basic3DVector< T > operator+(const Basic3DVector< T > &a, const Basic3DVector< T > &b)
vector sum and subtraction of vectors of possibly different precision
Definition: extBasic3DVector.h:232
__attribute__
class Basic3DVector __attribute__((aligned(16)))
ExtVec.h
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: extBasic3DVector.h:90
Basic3DVectorLD.h
Basic3DVector::cross
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
Definition: extBasic3DVector.h:203
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
xy
Basic2DVector< T > xy() const
Definition: extBasic3DVector.h:236
dot
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: extBasic3DVector.h:321
Basic3DVector::VectorType
Vec4< T > VectorType
Definition: extBasic3DVector.h:33
b
double b
Definition: hdecay.h:118
Basic3DVector::operator==
bool operator==(const Basic3DVector &rh) const
Definition: extBasic3DVector.h:107
Basic2DVector
Definition: extBasic2DVector.h:15
a
double a
Definition: hdecay.h:119
Basic3DVector::barePhi
T barePhi() const
Definition: extBasic3DVector.h:131
Basic3DVector::operator[]
T & operator[](int i)
Definition: extBasic3DVector.h:91
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: extBasic3DVector.h:173
Basic3DVector::operator-=
Basic3DVector & operator-=(const Basic3DVector< U > &p)
Definition: extBasic3DVector.h:167
Basic3DVectorF
Basic3DVector< float > Basic3DVectorF
Definition: extBasic3DVector.h:305
PreciseFloatType::Type
double Type
Definition: PreciseFloatType.h:24
geometryDetails
Definition: extTkRotation.h:21
res
Definition: Electron.h:6
Basic3DVector::v
Vec4< T > v
Definition: extBasic3DVector.h:217
operator-
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: extBasic3DVector.h:305
alignCSCRings.r
r
Definition: alignCSCRings.py:93
Basic3DVector::dot
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &lh) const
Definition: extBasic3DVector.h:197
Basic3DVector::Basic3DVector
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
Definition: extBasic3DVector.h:50
Basic2DVector.h
T
long double T
Definition: Basic3DVectorLD.h:48
operator/
Basic3DVector< T > operator/(const Basic3DVector< T > &v, T t)
Definition: extBasic3DVector.h:294
Basic3DVector::Spherical
Geom::Spherical2Cartesian< T > Spherical
Definition: extBasic3DVector.h:36
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
dot2
auto dot2(V1 x, V2 y) -> typename std::remove_reference< decltype(x[0])>::type
Definition: ExtVec.h:143
Basic3DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic3DVector.h:94
S
Definition: CSCDBL1TPParametersExtended.h:16
Basic3DVector::mathVector
MathVector const & mathVector() const
Definition: extBasic3DVector.h:87
Basic3DVector::Cylindrical
Geom::Cylindrical2Cartesian< T > Cylindrical
Definition: extBasic3DVector.h:35
Basic3DVector::perp
T perp() const
Magnitude of transverse component.
Definition: extBasic3DVector.h:122
eta
T eta() const
Definition: extBasic3DVector.h:278
v
Vec4< T > v
Definition: extBasic3DVector.h:349
cross3
Vec cross3(Vec x, Vec y)
Definition: ExtVec.h:91
Basic3DVector::Basic3DVector
Basic3DVector()
Definition: extBasic3DVector.h:43
Basic3DVector::bareTheta
T bareTheta() const
Definition: extBasic3DVector.h:138
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
operator<<
std::ostream & operator<<(std::ostream &s, const Basic3DVector< T > &v)
simple text output to standard streams
Definition: extBasic3DVector.h:226
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::MathVector
Vec4< T > MathVector
Definition: extBasic3DVector.h:34
Basic3DVector::Basic3DVector
Basic3DVector(const Basic2DVector< T > &p)
constructor from 2D vector (X and Y from 2D vector, z set to zero)
Definition: extBasic3DVector.h:53
Basic3DVector
Definition: extBasic3DVector.h:30
detailsBasic3DVector
Definition: extBasic3DVector.h:13
Basic3DVectorD
Basic3DVector< double > Basic3DVectorD
Definition: extBasic3DVector.h:306