CMS 3D CMS Logo

sseBasic3DVector.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)) 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>
30 class Basic3DVector {
31 public:
32  typedef T ScalarType;
37  typedef Spherical Polar; // synonym
38 
44 
46  Basic3DVector(const Basic3DVector& p) : v(p.v) {}
47 
49  template <class U>
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(p.x(), p.y(), p.z()) {}
65 
66  // constructor from Vec4
67  template <class U>
69 
71  Basic3DVector(const T& x, const T& y, const T& z, const T& w = 0) : v(x, y, z, w) {}
72 
77  template <typename U>
78  Basic3DVector(const Geom::Theta<U>& theta, const Geom::Phi<U>& phi, const T& r) {
79  Polar p(theta.value(), phi.value(), r);
80  v.o.theX = p.x();
81  v.o.theY = p.y();
82  v.o.theZ = p.z();
83  }
84 
85  MathVector const& mathVector() const { return v; }
86  MathVector& mathVector() { return v; }
87 
88  T operator[](int i) const { return v[i]; }
89  T& operator[](int i) { return v[i]; }
90 
92  T x() const { return v.o.theX; }
93 
95  T y() const { return v.o.theY; }
96 
98  T z() const { return v.o.theZ; }
99 
100  T w() const { return v.o.theW; }
101 
102  Basic2DVector<T> xy() const { return v.xy(); }
103 
104  // equality
105  bool operator==(const Basic3DVector& rh) const { return v == rh.v; }
106 
108  T mag2() const { return ::dot(v, v); }
109 
111  T mag() const { return std::sqrt(mag2()); }
112 
114  T perp2() const { return ::dotxy(v, v); }
115 
117  T perp() const { return std::sqrt(perp2()); }
118 
120  T transverse() const { return perp(); }
121 
126  T barePhi() const { return std::atan2(y(), x()); }
127  Geom::Phi<T> phi() const { return Geom::Phi<T>(barePhi()); }
128 
133  T bareTheta() const { return std::atan2(perp(), z()); }
134  Geom::Theta<T> theta() const { return Geom::Theta<T>(std::atan2(perp(), z())); }
135 
140  // T eta() const { return -log( tan( theta()/2.));}
141  T eta() const { return detailsBasic3DVector::eta(x(), y(), z()); } // correct
142 
146  Basic3DVector unit() const {
147  T my_mag = mag2();
148  return (0 != my_mag) ? (*this) * (T(1) / std::sqrt(my_mag)) : *this;
149  }
150 
153  template <class U>
155  v = v + p.v;
156  return *this;
157  }
158 
161  template <class U>
163  v = v - p.v;
164  return *this;
165  }
166 
168  Basic3DVector operator-() const { return Basic3DVector(-v); }
169 
172  v = t * v;
173  return *this;
174  }
175 
178  //t = T(1)/t;
179  v = v / t;
180  return *this;
181  }
182 
184  T dot(const Basic3DVector& rh) const { return ::dot(v, rh.v); }
185 
191  template <class U>
195  }
196 
199 
205  template <class U>
209  }
210 
211 public:
213 } __attribute__((aligned(16)));
214 
215 namespace geometryDetails {
216  std::ostream& print3D(std::ostream& s, double x, double y, double z);
217 }
218 
220 template <class T>
221 inline std::ostream& operator<<(std::ostream& s, const Basic3DVector<T>& v) {
222  return geometryDetails::print3D(s, v.x(), v.y(), v.z());
223 }
224 
226 template <class T>
228  return a.v + b.v;
229 }
230 template <class T>
232  return a.v - b.v;
233 }
234 
235 template <class T, class U>
237  const Basic3DVector<U>& b) {
239  return RT(a).v + RT(b).v;
240 }
241 
242 template <class T, class U>
244  const Basic3DVector<U>& b) {
246  return RT(a).v - RT(b).v;
247 }
248 
250 template <class T>
251 inline T operator*(const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
252  return v1.dot(v2);
253 }
254 
256 template <class T, class U>
258  return v1.dot(v2);
259 }
260 
264 template <class T>
266  return v.v * t;
267 }
268 
270 template <class T>
272  return v.v * t;
273 }
274 
275 template <class T, typename S>
277  return static_cast<T>(t) * v;
278 }
279 
280 template <class T, typename S>
282  return static_cast<T>(t) * v;
283 }
284 
288 template <class T>
290  return v.v / t;
291 }
292 
293 template <class T, typename S>
295  // T t = S(1)/s; return v*t;
296  T t = s;
297  return v / t;
298 }
299 
302 
303 // add long double specialization
304 #include "Basic3DVectorLD.h"
305 
306 #endif // GeometryVector_Basic3DVector_h
Phi.h
Basic3DVector::v
mathSSE::Vec4< T > v
Definition: sseBasic3DVector.h:212
Basic3DVector::theta
Geom::Theta< T > theta() const
Definition: extBasic3DVector.h:139
Basic3DVector::Basic3DVector
Basic3DVector(const OtherPoint &p)
Definition: sseBasic3DVector.h:64
mps_fire.i
i
Definition: mps_fire.py:428
Basic3DVector::transverse
T transverse() const
Another name for perp()
Definition: sseBasic3DVector.h:120
Basic3DVector::xy
Basic2DVector< T > xy() const
Definition: sseBasic3DVector.h:102
Basic3DVector::Basic3DVector
Basic3DVector(const Geom::Theta< U > &theta, const Geom::Phi< U > &phi, const T &r)
Definition: sseBasic3DVector.h:78
__attribute__
class Basic3DVector __attribute__((aligned(16)))
Basic3DVector::operator/=
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
Definition: sseBasic3DVector.h:177
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
operator<<
std::ostream & operator<<(std::ostream &s, const Basic3DVector< T > &v)
simple text output to standard streams
Definition: sseBasic3DVector.h:221
SSEVec.h
Basic3DVector::cross
Basic3DVector< typename PreciseFloatType< T, U >::Type > cross(const Basic3DVector< U > &lh) const
Definition: sseBasic3DVector.h:206
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
Geom::Theta
Definition: Theta.h:12
Basic3DVector::perp2
T perp2() const
Squared magnitude of transverse component.
Definition: sseBasic3DVector.h:114
CoordinateSets.h
Geom::Spherical2Cartesian
Definition: CoordinateSets.h:58
Basic3DVector::ScalarType
T ScalarType
Definition: sseBasic3DVector.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: sseBasic3DVector.h:71
operator-
Basic3DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: sseBasic3DVector.h:290
Basic3DVector::mathVector
MathVector & mathVector()
Definition: sseBasic3DVector.h:86
Basic3DVector::eta
T eta() const
Definition: sseBasic3DVector.h:141
Basic3DVector::mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: sseBasic3DVector.h:111
Basic3DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: sseBasic3DVector.h:108
Basic3DVectorF
Basic3DVector< float > Basic3DVectorF
Definition: sseBasic3DVector.h:300
Basic3DVector::VectorType
mathSSE::Vec4< T > VectorType
Definition: sseBasic3DVector.h:33
Basic3DVector::Basic3DVector
Basic3DVector(const Basic3DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: sseBasic3DVector.h:46
Basic3DVector::Polar
Spherical Polar
Definition: sseBasic3DVector.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
Basic3DVector::MathVector
mathSSE::Vec4< T > MathVector
Definition: sseBasic3DVector.h:34
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: sseBasic3DVector.h:88
eta
T eta() const
Definition: sseBasic3DVector.h:263
Basic3DVectorLD.h
Basic3DVector::cross
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
Definition: sseBasic3DVector.h:198
Basic3DVector::operator*=
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Definition: sseBasic3DVector.h:171
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: sseBasic3DVector.h:184
b
double b
Definition: hdecay.h:118
Basic3DVector::operator==
bool operator==(const Basic3DVector &rh) const
Definition: sseBasic3DVector.h:105
Basic2DVector
Definition: extBasic2DVector.h:15
a
double a
Definition: hdecay.h:119
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cross
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
Definition: sseBasic3DVector.h:320
operator/
Basic3DVector< T > operator/(const Basic3DVector< T > &v, T t)
Definition: sseBasic3DVector.h:289
Basic3DVector::barePhi
T barePhi() const
Definition: sseBasic3DVector.h:126
mathSSE::Vec4
Definition: SSEVec.h:115
Basic3DVector::operator[]
T & operator[](int i)
Definition: sseBasic3DVector.h:89
Basic3DVector::Basic3DVector
Basic3DVector(mathSSE::Vec4< U > const &iv)
Definition: sseBasic3DVector.h:68
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: sseBasic3DVector.h:162
PreciseFloatType::Type
double Type
Definition: PreciseFloatType.h:24
geometryDetails
Definition: extTkRotation.h:21
Basic3DVector::v
Vec4< T > v
Definition: extBasic3DVector.h:217
alignCSCRings.r
r
Definition: alignCSCRings.py:93
Basic3DVector::dot
PreciseFloatType< T, U >::Type dot(const Basic3DVector< U > &lh) const
Definition: sseBasic3DVector.h:192
Basic3DVector::Basic3DVector
Basic3DVector(const Basic3DVector< U > &p)
Copy constructor and implicit conversion from Basic3DVector of different precision.
Definition: sseBasic3DVector.h:50
operator*
T operator*(const Basic3DVector< T > &v1, const Basic3DVector< T > &v2)
scalar product of vectors of same precision
Definition: sseBasic3DVector.h:251
Basic2DVector.h
T
long double T
Definition: Basic3DVectorLD.h:48
v
mathSSE::Vec4< T > v
Definition: sseBasic3DVector.h:334
Basic3DVector::Spherical
Geom::Spherical2Cartesian< T > Spherical
Definition: sseBasic3DVector.h:36
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
operator+
Basic3DVector< T > operator+(const Basic3DVector< T > &a, const Basic3DVector< T > &b)
vector sum and subtraction of vectors of possibly different precision
Definition: sseBasic3DVector.h:227
Basic3DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic3DVector.h:94
S
Definition: CSCDBL1TPParametersExtended.h:16
Basic3DVector::mathVector
MathVector const & mathVector() const
Definition: sseBasic3DVector.h:85
Basic3DVectorD
Basic3DVector< double > Basic3DVectorD
Definition: sseBasic3DVector.h:301
Basic3DVector::Cylindrical
Geom::Cylindrical2Cartesian< T > Cylindrical
Definition: sseBasic3DVector.h:35
Basic3DVector::perp
T perp() const
Magnitude of transverse component.
Definition: sseBasic3DVector.h:117
dot
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: sseBasic3DVector.h:306
Basic3DVector::Basic3DVector
Basic3DVector()
Definition: sseBasic3DVector.h:43
Basic3DVector::bareTheta
T bareTheta() const
Definition: sseBasic3DVector.h:133
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
Basic3DVector::z
T z() const
Cartesian z coordinate.
Definition: extBasic3DVector.h:100
Basic3DVector::unit
Basic3DVector unit() const
Definition: sseBasic3DVector.h:146
Basic3DVector::phi
Geom::Phi< T > phi() const
Definition: extBasic3DVector.h:132
Basic3DVector< align::Scalar >::MathVector
Vec4< align::Scalar > 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: sseBasic3DVector.h:53
Basic3DVector
Definition: extBasic3DVector.h:30
detailsBasic3DVector
Definition: extBasic3DVector.h:13