Belle II Software light-2607-kasei
B2Vector3< DataType > Class Template Reference

A fast and root compatible alternative to TVector3. More...

#include <B2Vector3.h>

Public Types

typedef DataType value_type
 storage type of the vector
 

Public Member Functions

 B2Vector3 (void)
 empty Constructor sets everything to 0
 
 B2Vector3 (const DataType xVal, const DataType yVal, const DataType zVal)
 Constructor expecting 3 coordinates.
 
 B2Vector3 (const DataType(&coords)[3])
 Constructor using a reference.
 
 B2Vector3 (const DataType(*coords)[3])
 Constructor using a pointer.
 
 B2Vector3 (const TVector3 &tVec3)
 Constructor expecting a TVector3.
 
 B2Vector3 (const TVector3 *tVec3)
 Constructor expecting a pointer to a TVector3.
 
 B2Vector3 (const B2Vector3< DataType > &b2Vec3)
 Constructor expecting a B2Vector3 of same type.
 
 B2Vector3 (const B2Vector3< DataType > *b2Vec3)
 Constructor expecting a pointer to a B2Vector3.
 
template<typename OtherType>
 B2Vector3 (const B2Vector3< OtherType > &b2Vec3)
 Constructor expecting a B2Vector3 of different type.
 
template<typename OtherType>
 B2Vector3 (const B2Vector3< OtherType > *b2Vec3)
 Constructor expecting a pointer to a B2Vector3 of different type.
 
 B2Vector3 (const ROOT::Math::XYZVector &xyzVec)
 Constructor expecting a XYZVector.
 
 B2Vector3 (const ROOT::Math::XYZVector *xyzVec)
 Constructor expecting a pointer to a XYZVector.
 
DataType operator() (unsigned i) const
 member access without boundary check
 
DataType operator[] (unsigned i) const
 member access without boundary check
 
DataType & operator() (unsigned i)
 member access without boundary check
 
DataType & operator[] (unsigned i)
 member access without boundary check
 
B2Vector3< DataType > & operator= (const B2Vector3< DataType > &b)
 Assignment via B2Vector3.
 
B2Vector3< DataType > & operator= (const TVector3 &b)
 Assignment via TVector3.
 
B2Vector3< DataType > & operator= (const ROOT::Math::XYZVector &b)
 Assignment via XYZVector.
 
 operator TVector3 () const
 type conversion in TVector3
 
 operator ROOT::Math::XYZVector () const
 type conversion in ROOT::Math::XYZVector
 
bool operator== (const B2Vector3< DataType > &b) const
 Comparison for equality with a B2Vector3.
 
bool operator== (const TVector3 &b) const
 Comparison for equality with a TVector3.
 
bool operator== (const ROOT::Math::XYZVector &b) const
 Comparison for equality with a XYZVector.
 
bool operator!= (const B2Vector3< DataType > &b) const
 Comparison != with a B2Vector3.
 
bool operator!= (const TVector3 &b) const
 Comparison != with a TVector3.
 
bool operator!= (const ROOT::Math::XYZVector &b) const
 Comparison != with a XYZVector.
 
B2Vector3< DataType > & operator+= (const B2Vector3< DataType > &b)
 addition
 
B2Vector3< DataType > & operator-= (const B2Vector3< DataType > &b)
 subtraction
 
B2Vector3< DataType > & operator*= (DataType a)
 scaling with real numbers
 
B2Vector3< DataType > operator- () const
 unary minus
 
B2Vector3< DataType > operator+ (const B2Vector3< DataType > &b) const
 Addition of 3-vectors.
 
B2Vector3< DataType > operator- (const B2Vector3< DataType > &b) const
 Subtraction of 3-vectors.
 
B2Vector3< DataType > operator* (DataType a) const
 Scaling of 3-vectors with a real number.
 
B2Vector3< DataType > operator/ (DataType a) const
 Scaling of 3-vectors with a real number.
 
DataType operator* (const B2Vector3< DataType > &b) const
 Scalar product of 3-vectors.
 
DataType Phi () const
 The azimuth angle.
 
DataType Theta () const
 The polar angle.
 
DataType CosTheta () const
 Cosine of the polar angle.
 
DataType Mag2 () const
 The magnitude squared (rho^2 in spherical coordinate system).
 
DataType Mag () const
 The magnitude (rho in spherical coordinate system).
 
void SetPhi (DataType phi)
 Set phi keeping mag and theta constant.
 
void SetTheta (DataType theta)
 Set theta keeping mag and phi constant.
 
void SetMag (DataType mag)
 Set magnitude keeping theta and phi constant.
 
DataType Perp2 () const
 The transverse component squared (R^2 in cylindrical coordinate system).
 
DataType Pt () const
 The transverse component (R in cylindrical coordinate system).
 
DataType Perp () const
 The transverse component (R in cylindrical coordinate system).
 
void SetPerp (DataType r)
 Set the transverse component keeping phi and z constant.
 
DataType Perp2 (const B2Vector3< DataType > &axis) const
 The transverse component w.r.t.
 
DataType Pt (const B2Vector3< DataType > &axis) const
 The transverse component w.r.t.
 
DataType Perp (const B2Vector3< DataType > &axis) const
 The transverse component w.r.t.
 
DataType DeltaPhi (const B2Vector3< DataType > &v) const
 returns phi in the interval [-PI,PI)
 
DataType DeltaR (const B2Vector3< DataType > &v) const
 return deltaR with respect to input-vector
 
DataType DrEtaPhi (const B2Vector3< DataType > &v) const
 return DrEtaPhi with respect to input-vector
 
void SetMagThetaPhi (DataType mag, DataType theta, DataType phi)
 setter with mag, theta, phi
 
B2Vector3< DataType > Unit () const
 Unit vector parallel to this.
 
B2Vector3< DataType > Orthogonal () const
 Vector orthogonal to this one.
 
DataType Dot (const B2Vector3< DataType > &p) const
 Scalar product.
 
B2Vector3< DataType > Cross (const B2Vector3< DataType > &p) const
 Cross product.
 
DataType Angle (const B2Vector3< DataType > &q) const
 The angle w.r.t.
 
DataType PseudoRapidity () const
 Returns the pseudo-rapidity, i.e.
 
DataType Eta () const
 Returns the pseudo-rapidity.
 
void RotateX (DataType angle)
 Rotates the B2Vector3 around the x-axis.
 
void RotateY (DataType angle)
 Rotates the B2Vector3 around the y-axis.
 
void RotateZ (DataType angle)
 Rotates the B2Vector3 around the z-axis.
 
void RotateUz (const B2Vector3< DataType > &NewUzVector)
 Rotates reference frame from Uz to newUz (unit vector).
 
void Rotate (DataType alpha, const B2Vector3< DataType > &v)
 Rotation around an arbitrary axis v with angle alpha.
 
void Abs ()
 calculates the absolute value of the coordinates element-wise
 
void Sqrt ()
 calculates the square root of the absolute values of the coordinates element-wise
 
DataType at (unsigned i) const
 safe member access (with boundary check!)
 
DataType x () const
 access variable X (= .at(0) without boundary check)
 
DataType y () const
 access variable Y (= .at(1) without boundary check)
 
DataType z () const
 access variable Z (= .at(2) without boundary check)
 
DataType X () const
 access variable X (= .at(0) without boundary check)
 
DataType Y () const
 access variable Y (= .at(1) without boundary check)
 
DataType Z () const
 access variable Z (= .at(2) without boundary check)
 
DataType Px () const
 access variable X (= .at(0) without boundary check)
 
DataType Py () const
 access variable Y (= .at(1) without boundary check)
 
DataType Pz () const
 access variable Z (= .at(2) without boundary check)
 
void GetXYZ (Double_t *carray) const
 directly copies coordinates to an array of double
 
void GetXYZ (Float_t *carray) const
 directly copies coordinates to an array of float
 
void GetXYZ (TVector3 *tVec) const
 directly copies coordinates to a TVector3
 
void GetXYZ (ROOT::Math::XYZVector *xyzVec) const
 directly copies coordinates to a XYZVector
 
TVector3 GetTVector3 () const
 returns a TVector3 containing the same coordinates
 
ROOT::Math::XYZVector GetXYZVector () const
 returns a XYZVector containing the same coordinates
 
void SetX (DataType x)
 set X/1st-coordinate
 
void SetY (DataType y)
 set Y/2nd-coordinate
 
void SetZ (DataType z)
 set Z/3rd-coordinate
 
void SetXYZ (DataType x, DataType y, DataType z)
 set all coordinates using data type
 
void SetXYZ (const TVector3 &tVec)
 set all coordinates using a reference to TVector3
 
void SetXYZ (const TVector3 *tVec)
 set all coordinates using a pointer to TVector3
 
void SetXYZ (const ROOT::Math::XYZVector &xyzVec)
 set all coordinates using a reference to XYZVector
 
void SetXYZ (const ROOT::Math::XYZVector *xyzVec)
 set all coordinates using a pointer to XYZVector
 
std::string PrintString (unsigned precision=4) const
 create a string containing vector in cartesian and spherical coordinates
 
std::string PrintStringXYZ (unsigned precision=4) const
 create a string containing vector in cartesian coordinates
 
std::string PrintStringCyl (unsigned precision=4) const
 create a string containing vector in spherical coordinates
 
void Print ()
 just for backward compatibility, should not be used with new code
 

Static Public Member Functions

static DataType Mpi_pi (DataType angle)
 returns given angle in the interval [-PI,PI)
 
static std::string name ()
 Returns the name of the B2Vector.
 

Protected Attributes

DataType m_coordinates [3] {}
 Make sure that we only have floating point vectors.
 

Detailed Description

template<typename DataType>
class Belle2::B2Vector3< DataType >

A fast and root compatible alternative to TVector3.

Goals:

  • vectorizable
  • root compatible
  • fixed size
  • featureset comparable to TVector3 (long term goal)
  • interface/member functions compatible to TVector3

DataType: shall be the data type one wants to store in the B2Vector (e.g. double)

Definition at line 42 of file B2Vector3.h.

Member Typedef Documentation

◆ value_type

template<typename DataType>
typedef DataType value_type

storage type of the vector

Definition at line 50 of file B2Vector3.h.

Constructor & Destructor Documentation

◆ B2Vector3() [1/12]

template<typename DataType>
B2Vector3 ( void )
inline

empty Constructor sets everything to 0

Definition at line 53 of file B2Vector3.h.

53: m_coordinates {static_cast<DataType>(0), static_cast<DataType>(0), static_cast<DataType>(0)} {};

◆ B2Vector3() [2/12]

template<typename DataType>
B2Vector3 ( const DataType xVal,
const DataType yVal,
const DataType zVal )
inline

Constructor expecting 3 coordinates.

Definition at line 55 of file B2Vector3.h.

55: m_coordinates {xVal, yVal, zVal} {};

◆ B2Vector3() [3/12]

template<typename DataType>
B2Vector3 ( const DataType(&) coords[3])
inlineexplicit

Constructor using a reference.

Definition at line 57 of file B2Vector3.h.

57: m_coordinates {coords[0], coords[1], coords[2]} {};

◆ B2Vector3() [4/12]

template<typename DataType>
B2Vector3 ( const DataType(*) coords[3])
inlineexplicit

Constructor using a pointer.

Definition at line 59 of file B2Vector3.h.

59: m_coordinates {(*coords)[0], (*coords)[1], (*coords)[2]} {};

◆ B2Vector3() [5/12]

template<typename DataType>
B2Vector3 ( const TVector3 & tVec3)
inline

Constructor expecting a TVector3.

Definition at line 62 of file B2Vector3.h.

62: m_coordinates {static_cast<DataType>(tVec3.X()), static_cast<DataType>(tVec3.Y()), static_cast<DataType>(tVec3.Z())} {};

◆ B2Vector3() [6/12]

template<typename DataType>
B2Vector3 ( const TVector3 * tVec3)
inline

Constructor expecting a pointer to a TVector3.

Definition at line 65 of file B2Vector3.h.

65: m_coordinates {static_cast<DataType>(tVec3->X()), static_cast<DataType>(tVec3->Y()), static_cast<DataType>(tVec3->Z())} {};

◆ B2Vector3() [7/12]

template<typename DataType>
B2Vector3 ( const B2Vector3< DataType > & b2Vec3)
inlineexplicit

Constructor expecting a B2Vector3 of same type.

Definition at line 67 of file B2Vector3.h.

67: m_coordinates {b2Vec3.X(), b2Vec3.Y(), b2Vec3.Z()} {};

◆ B2Vector3() [8/12]

template<typename DataType>
B2Vector3 ( const B2Vector3< DataType > * b2Vec3)
inlineexplicit

Constructor expecting a pointer to a B2Vector3.

Definition at line 69 of file B2Vector3.h.

69: m_coordinates {b2Vec3->X(), b2Vec3->Y(), b2Vec3->Z()} {};

◆ B2Vector3() [9/12]

template<typename DataType>
template<typename OtherType>
B2Vector3 ( const B2Vector3< OtherType > & b2Vec3)
inline

Constructor expecting a B2Vector3 of different type.

Definition at line 71 of file B2Vector3.h.

71 :
72 m_coordinates {static_cast<DataType>(b2Vec3.X()), static_cast<DataType>(b2Vec3.Y()), static_cast<DataType>(b2Vec3.Z())} {};

◆ B2Vector3() [10/12]

template<typename DataType>
template<typename OtherType>
B2Vector3 ( const B2Vector3< OtherType > * b2Vec3)
inlineexplicit

Constructor expecting a pointer to a B2Vector3 of different type.

Definition at line 74 of file B2Vector3.h.

74 :
75 m_coordinates {static_cast<DataType>(b2Vec3->X()), static_cast<DataType>(b2Vec3->Y()), static_cast<DataType>(b2Vec3->Z())} {};

◆ B2Vector3() [11/12]

template<typename DataType>
B2Vector3 ( const ROOT::Math::XYZVector & xyzVec)
inline

Constructor expecting a XYZVector.

Definition at line 78 of file B2Vector3.h.

78: m_coordinates {static_cast<DataType>(xyzVec.X()), static_cast<DataType>(xyzVec.Y()), static_cast<DataType>(xyzVec.Z())} {};

◆ B2Vector3() [12/12]

template<typename DataType>
B2Vector3 ( const ROOT::Math::XYZVector * xyzVec)
inline

Constructor expecting a pointer to a XYZVector.

Definition at line 81 of file B2Vector3.h.

81: m_coordinates {static_cast<DataType>(xyzVec->X()), static_cast<DataType>(xyzVec->Y()), static_cast<DataType>(xyzVec->Z())} {};

Member Function Documentation

◆ Abs()

template<typename DataType>
void Abs ( )
inline

calculates the absolute value of the coordinates element-wise

Definition at line 405 of file B2Vector3.h.

406 {
407 m_coordinates[0] = std::abs(m_coordinates[0]);
408 m_coordinates[1] = std::abs(m_coordinates[1]);
409 m_coordinates[2] = std::abs(m_coordinates[2]);
410 }

◆ Angle()

template<typename DataType>
DataType Angle ( const B2Vector3< DataType > & q) const
inline

The angle w.r.t.

another B2Vector3.

Definition at line 301 of file B2Vector3.h.

302 {
303 const double ptot2 = Mag2() * q.Mag2();
304 if (ptot2 <= 0) {
305 return 0.0;
306 } else {
307 double arg = Dot(q) / std::sqrt(ptot2);
308 if (arg > 1.0) arg = 1.0;
309 if (arg < -1.0) arg = -1.0;
310 return std::acos(arg);
311 }
312 }

◆ CosTheta()

template<typename DataType>
DataType CosTheta ( ) const
inline

Cosine of the polar angle.

Definition at line 154 of file B2Vector3.h.

154{ const double pTot = Mag(); return pTot == 0 ? 1 : Z() / pTot; }

◆ Cross()

template<typename DataType>
B2Vector3< DataType > Cross ( const B2Vector3< DataType > & p) const
inline

Cross product.

Definition at line 295 of file B2Vector3.h.

296 {
297 return B2Vector3<DataType>(Y() * p.Z() - p.Y() * Z(), Z() * p.X() - p.Z() * X(), X() * p.Y() - p.X() * Y());
298 }

◆ DeltaPhi()

template<typename DataType>
DataType DeltaPhi ( const B2Vector3< DataType > & v) const
inline

returns phi in the interval [-PI,PI)

Definition at line 227 of file B2Vector3.h.

227{ return Mpi_pi(Phi() - v.Phi()); }

◆ DeltaR()

template<typename DataType>
DataType DeltaR ( const B2Vector3< DataType > & v) const
inline

return deltaR with respect to input-vector

Definition at line 244 of file B2Vector3.h.

245 {
246 const double deta = Eta() - v.Eta();
247 const double dphi = DeltaPhi(v);
248 return std::hypot(deta, dphi);
249 }

◆ Dot()

template<typename DataType>
DataType Dot ( const B2Vector3< DataType > & p) const
inline

Scalar product.

Definition at line 289 of file B2Vector3.h.

290 {
291 return X() * p.X() + Y() * p.Y() + Z() * p.Z();
292 }

◆ DrEtaPhi()

template<typename DataType>
DataType DrEtaPhi ( const B2Vector3< DataType > & v) const
inline

return DrEtaPhi with respect to input-vector

Definition at line 252 of file B2Vector3.h.

253 {
254 return DeltaR(v);
255 }

◆ Eta()

template<typename DataType>
DataType Eta ( ) const
inline

Returns the pseudo-rapidity.

Definition at line 330 of file B2Vector3.h.

330{ return PseudoRapidity(); }

◆ Mag()

template<typename DataType>
DataType Mag ( ) const
inline

The magnitude (rho in spherical coordinate system).

Definition at line 158 of file B2Vector3.h.

158{ return std::hypot((double)Perp(), (double)Z()); }

◆ Mag2()

template<typename DataType>
DataType Mag2 ( ) const
inline

The magnitude squared (rho^2 in spherical coordinate system).

Definition at line 156 of file B2Vector3.h.

156{ return X() * X() + Y() * Y() + Z() * Z(); }

◆ Mpi_pi()

template<typename DataType>
static DataType Mpi_pi ( DataType angle)
inlinestatic

returns given angle in the interval [-PI,PI)

Definition at line 231 of file B2Vector3.h.

232 {
233 if (std::isnan(angle)) {
234 B2ERROR(name() << "::Mpi_pi: function called with NaN");
235 return angle;
236 }
237 angle = std::remainder(angle, 2 * M_PI);
238 //for compatibility with ROOT we flip the sign for exactly pi
239 if (angle == M_PI) angle = -M_PI;
240 return angle;
241 }

◆ operator ROOT::Math::XYZVector()

template<typename DataType>
operator ROOT::Math::XYZVector ( ) const
inline

type conversion in ROOT::Math::XYZVector

Definition at line 102 of file B2Vector3.h.

102{ return GetXYZVector(); }

◆ operator TVector3()

template<typename DataType>
operator TVector3 ( ) const
inline

type conversion in TVector3

Definition at line 100 of file B2Vector3.h.

100{ return GetTVector3(); }

◆ operator!=() [1/3]

template<typename DataType>
bool operator!= ( const B2Vector3< DataType > & b) const
inline

Comparison != with a B2Vector3.

Definition at line 111 of file B2Vector3.h.

111{ return !(*this == b); }

◆ operator!=() [2/3]

template<typename DataType>
bool operator!= ( const ROOT::Math::XYZVector & b) const
inline

Comparison != with a XYZVector.

Definition at line 115 of file B2Vector3.h.

115{ return !(*this == b); }

◆ operator!=() [3/3]

template<typename DataType>
bool operator!= ( const TVector3 & b) const
inline

Comparison != with a TVector3.

Definition at line 113 of file B2Vector3.h.

113{ return !(*this == b); }

◆ operator()() [1/2]

template<typename DataType>
DataType & operator() ( unsigned i)
inline

member access without boundary check

Definition at line 88 of file B2Vector3.h.

88{ return m_coordinates[i]; }

◆ operator()() [2/2]

template<typename DataType>
DataType operator() ( unsigned i) const
inline

member access without boundary check

Definition at line 84 of file B2Vector3.h.

84{ return m_coordinates[i]; }

◆ operator*() [1/2]

template<typename DataType>
DataType operator* ( const B2Vector3< DataType > & b) const
inline

Scalar product of 3-vectors.

Definition at line 146 of file B2Vector3.h.

146{ return Dot(b); }

◆ operator*() [2/2]

template<typename DataType>
B2Vector3< DataType > operator* ( DataType a) const
inline

Scaling of 3-vectors with a real number.

Definition at line 136 of file B2Vector3.h.

137 {
138 return B2Vector3<DataType>(a * X(), a * Y(), a * Z());
139 }

◆ operator+()

template<typename DataType>
B2Vector3< DataType > operator+ ( const B2Vector3< DataType > & b) const
inline

Addition of 3-vectors.

Definition at line 126 of file B2Vector3.h.

127 {
128 return B2Vector3<DataType>(X() + b.X(), Y() + b.Y(), Z() + b.Z());
129 }

◆ operator-() [1/2]

template<typename DataType>
B2Vector3< DataType > operator- ( ) const
inline

unary minus

Definition at line 124 of file B2Vector3.h.

124{ return B2Vector3<DataType>(-X(), -Y(), -Z()); }

◆ operator-() [2/2]

template<typename DataType>
B2Vector3< DataType > operator- ( const B2Vector3< DataType > & b) const
inline

Subtraction of 3-vectors.

Definition at line 131 of file B2Vector3.h.

132 {
133 return B2Vector3<DataType>(X() - b.X(), Y() - b.Y(), Z() - b.Z());
134 }

◆ operator/()

template<typename DataType>
B2Vector3< DataType > operator/ ( DataType a) const
inline

Scaling of 3-vectors with a real number.

Definition at line 141 of file B2Vector3.h.

142 {
143 return B2Vector3<DataType>(X() / a, Y() / a, Z() / a);
144 }

◆ operator==() [1/3]

template<typename DataType>
bool operator== ( const B2Vector3< DataType > & b) const
inline

Comparison for equality with a B2Vector3.

Definition at line 105 of file B2Vector3.h.

105{ return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }

◆ operator==() [2/3]

template<typename DataType>
bool operator== ( const ROOT::Math::XYZVector & b) const
inline

Comparison for equality with a XYZVector.

Definition at line 109 of file B2Vector3.h.

109{ return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }

◆ operator==() [3/3]

template<typename DataType>
bool operator== ( const TVector3 & b) const
inline

Comparison for equality with a TVector3.

Definition at line 107 of file B2Vector3.h.

107{ return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }

◆ operator[]() [1/2]

template<typename DataType>
DataType & operator[] ( unsigned i)
inline

member access without boundary check

Definition at line 90 of file B2Vector3.h.

90{ return m_coordinates[i]; }

◆ operator[]() [2/2]

template<typename DataType>
DataType operator[] ( unsigned i) const
inline

member access without boundary check

Definition at line 86 of file B2Vector3.h.

86{ return m_coordinates[i]; }

◆ Orthogonal()

template<typename DataType>
B2Vector3< DataType > Orthogonal ( ) const
inline

Vector orthogonal to this one.

Definition at line 276 of file B2Vector3.h.

277 {
278 const double xVal = std::abs((double)X());
279 const double yVal = std::abs((double)Y());
280 const double zVal = std::abs((double)Z());
281 if (xVal < yVal) {
282 return xVal < zVal ? B2Vector3<DataType>(0, Z(), -Y()) : B2Vector3<DataType>(Y(), -X(), 0);
283 } else {
284 return yVal < zVal ? B2Vector3<DataType>(-Z(), 0, X()) : B2Vector3<DataType>(Y(), -X(), 0);
285 }
286 }

◆ Perp() [1/2]

template<typename DataType>
DataType Perp ( ) const
inline

The transverse component (R in cylindrical coordinate system).

Definition at line 199 of file B2Vector3.h.

199{ return std::hypot((double)X(), (double)Y()); }

◆ Perp() [2/2]

template<typename DataType>
DataType Perp ( const B2Vector3< DataType > & axis) const
inline

The transverse component w.r.t.

given axis.

Definition at line 225 of file B2Vector3.h.

225{ return std::sqrt(Perp2(axis)); }

◆ Perp2() [1/2]

template<typename DataType>
DataType Perp2 ( ) const
inline

The transverse component squared (R^2 in cylindrical coordinate system).

Definition at line 195 of file B2Vector3.h.

195{ return X() * X() + Y() * Y(); }

◆ Perp2() [2/2]

template<typename DataType>
DataType Perp2 ( const B2Vector3< DataType > & axis) const
inline

The transverse component w.r.t.

given axis squared.

Definition at line 212 of file B2Vector3.h.

213 {
214 const double tot = axis.Mag2();
215 const double ss = Dot(axis);
216 double per = Mag2();
217 if (tot > 0.0) per -= ss * ss / tot;
218 if (per < 0) per = 0;
219 return per;
220 }

◆ Phi()

template<typename DataType>
DataType Phi ( ) const
inline

The azimuth angle.

returns phi from -pi to pi

Definition at line 150 of file B2Vector3.h.

150{ return X() == 0 && Y() == 0 ? 0 : atan2(Y(), X()); }

◆ Print()

template<typename DataType>
void Print ( )
inline

just for backward compatibility, should not be used with new code

Definition at line 506 of file B2Vector3.h.

507 {
508 //print vector parameters
509 Print(PrintString().c_str());
510 }

◆ PrintString()

template<typename DataType>
std::string PrintString ( unsigned precision = 4) const
inline

create a string containing vector in cartesian and spherical coordinates

Definition at line 480 of file B2Vector3.h.

481 {
482 return name() + " " + PrintStringXYZ(precision) + " " + PrintStringCyl(precision);
483 }

◆ PrintStringCyl()

template<typename DataType>
std::string PrintStringCyl ( unsigned precision = 4) const
inline

create a string containing vector in spherical coordinates

Definition at line 496 of file B2Vector3.h.

497 {
498 std::ostringstream output;
499 output << "(rho, theta, phi)=("
500 << std::fixed << std::setprecision(precision)
501 << Mag() << "," << Theta() * 180. / M_PI << "," << Phi() * 180. / M_PI << ")";
502 return output.str();
503 }

◆ PrintStringXYZ()

template<typename DataType>
std::string PrintStringXYZ ( unsigned precision = 4) const
inline

create a string containing vector in cartesian coordinates

Definition at line 486 of file B2Vector3.h.

487 {
488 std::ostringstream output;
489 output << "(x,y,z)=("
490 << std::fixed << std::setprecision(precision)
491 << X() << "," << Y() << "," << Z() << ")";
492 return output.str();
493 }

◆ PseudoRapidity()

template<typename DataType>
DataType PseudoRapidity ( ) const
inline

Returns the pseudo-rapidity, i.e.

-ln(tan(theta/2)).

for the sake of keeping compatibility to TVector3, the hardcoded values are not replaced by something more intelligent

Definition at line 318 of file B2Vector3.h.

319 {
320 const double cosTheta = CosTheta();
321 if (std::abs(cosTheta) < 1) return -0.5 * std::log((1.0 - cosTheta) / (1.0 + cosTheta));
322 if (Z() == 0) return 0;
323 //B2WARNING(name() << "::PseudoRapidity: transverse momentum = 0! return +/- 10e10");
324 if (Z() > 0) return 10e10;
325 else return -10e10;
326 }

◆ Pt() [1/2]

template<typename DataType>
DataType Pt ( ) const
inline

The transverse component (R in cylindrical coordinate system).

Definition at line 197 of file B2Vector3.h.

197{ return Perp(); }

◆ Pt() [2/2]

template<typename DataType>
DataType Pt ( const B2Vector3< DataType > & axis) const
inline

The transverse component w.r.t.

given axis.

Definition at line 223 of file B2Vector3.h.

223{ return Perp(axis); }

◆ Px()

template<typename DataType>
DataType Px ( ) const
inline

access variable X (= .at(0) without boundary check)

Definition at line 436 of file B2Vector3.h.

436{ return x(); }

◆ Py()

template<typename DataType>
DataType Py ( ) const
inline

access variable Y (= .at(1) without boundary check)

Definition at line 438 of file B2Vector3.h.

438{ return y(); }

◆ Pz()

template<typename DataType>
DataType Pz ( ) const
inline

access variable Z (= .at(2) without boundary check)

Definition at line 440 of file B2Vector3.h.

440{ return z(); }

◆ Rotate()

template<typename DataType>
void Rotate ( DataType alpha,
const B2Vector3< DataType > & v )
inline

Rotation around an arbitrary axis v with angle alpha.

With n = (n1, n2, n3)^T being the unit vector of v, the rotation matrix R(n, alpha) with ca = cos(alpha) and sa = sin(alpha) reads / n1^2*(1-ca)+ca n1*n2*(1-ca)-n3*sa n1*n3*(1-ca)+n2*sa \ R(n, alpha) = | n2*n1*(1-ca)+n3*sa n2^2*(1-ca)+ca n2*n3*(1-ca)-n1*sa | \ n3*n1*(1-ca)-n2*sa n3*n2*(1-ca)+n1*sa n3^2*(1-ca)+ca / . Using this rotation matrix, the full rotation of a vector b (= this) around the axis v by angle alpha can be written as R(n, alpha)*b = n(n*b) + cos(alpha) * (n x b) x n + sin(alpha) * (n x b).

Definition at line 398 of file B2Vector3.h.

399 {
400 B2Vector3<DataType> n = v.Unit();
401 *this = (n * (n.Dot(*this)) + cos(alpha) * ((n.Cross(*this)).Cross(n)) + sin(alpha) * (n.Cross(*this)));
402 }

◆ RotateUz()

template<typename DataType>
void RotateUz ( const B2Vector3< DataType > & NewUzVector)
inline

Rotates reference frame from Uz to newUz (unit vector).

Definition at line 369 of file B2Vector3.h.

370 {
371 // NewUzVector must be normalized !
372
373 const double u1 = NewUzVector.X();
374 const double u2 = NewUzVector.Y();
375 const double u3 = NewUzVector.Z();
376 double up = u1 * u1 + u2 * u2;
377
378 if (up) {
379 up = std::sqrt(up);
380 DataType px = X(), py = Y(), pz = Z();
381 m_coordinates[0] = (u1 * u3 * px - u2 * py + u1 * up * pz) / up;
382 m_coordinates[1] = (u2 * u3 * px + u1 * py + u2 * up * pz) / up;
383 m_coordinates[2] = (u3 * u3 * px - px + u3 * up * pz) / up;
384 } else if (u3 < 0.) {
385 m_coordinates[0] = -m_coordinates[0];
386 m_coordinates[2] = -m_coordinates[2];
387 }
388 }

◆ RotateX()

template<typename DataType>
void RotateX ( DataType angle)
inline

Rotates the B2Vector3 around the x-axis.

Definition at line 334 of file B2Vector3.h.

335 {
336 //rotate vector around X
337 const double s = std::sin((double)angle);
338 const double c = std::cos((double)angle);
339 const double yOld = Y();
340 m_coordinates[1] = c * yOld - s * Z();
341 m_coordinates[2] = s * yOld + c * Z();
342 }

◆ RotateY()

template<typename DataType>
void RotateY ( DataType angle)
inline

Rotates the B2Vector3 around the y-axis.

Definition at line 346 of file B2Vector3.h.

347 {
348 //rotate vector around Y
349 const double s = std::sin((double)angle);
350 const double c = std::cos((double)angle);
351 const double zOld = Z();
352 m_coordinates[0] = s * zOld + c * X();
353 m_coordinates[2] = c * zOld - s * X();
354 }

◆ RotateZ()

template<typename DataType>
void RotateZ ( DataType angle)
inline

Rotates the B2Vector3 around the z-axis.

Definition at line 358 of file B2Vector3.h.

359 {
360 //rotate vector around Z
361 const double s = std::sin((double)angle);
362 const double c = std::cos((double)angle);
363 const double xOld = X();
364 m_coordinates[0] = c * xOld - s * Y();
365 m_coordinates[1] = s * xOld + c * Y();
366 }

◆ SetMag()

template<typename DataType>
void SetMag ( DataType mag)
inline

Set magnitude keeping theta and phi constant.

Definition at line 181 of file B2Vector3.h.

182 {
183 double factor = Mag();
184 if (factor == 0) {
185 B2WARNING(name() << "::SetMag: zero vector can't be stretched");
186 } else {
187 factor = mag / factor;
188 SetX(X()*factor);
189 SetY(Y()*factor);
190 SetZ(Z()*factor);
191 }
192 }

◆ SetMagThetaPhi()

template<typename DataType>
void SetMagThetaPhi ( DataType mag,
DataType theta,
DataType phi )
inline

setter with mag, theta, phi

Definition at line 258 of file B2Vector3.h.

259 {
260 const double amag = std::abs(mag);
261 const double sinTheta = std::sin((double)theta);
262 m_coordinates[0] = amag * sinTheta * std::cos((double)phi);
263 m_coordinates[1] = amag * sinTheta * std::sin((double)phi);
264 m_coordinates[2] = amag * std::cos((double)theta);
265 }

◆ SetPerp()

template<typename DataType>
void SetPerp ( DataType r)
inline

Set the transverse component keeping phi and z constant.

Definition at line 202 of file B2Vector3.h.

203 {
204 const double p = Perp();
205 if (p != 0.0) {
206 m_coordinates[0] *= r / p;
207 m_coordinates[1] *= r / p;
208 }
209 }

◆ SetPhi()

template<typename DataType>
void SetPhi ( DataType phi)
inline

Set phi keeping mag and theta constant.

Definition at line 161 of file B2Vector3.h.

162 {
163 const double perp = Perp();
164 SetX(perp * cos((double)phi));
165 SetY(perp * sin((double)phi));
166 }

◆ SetTheta()

template<typename DataType>
void SetTheta ( DataType theta)
inline

Set theta keeping mag and phi constant.

Definition at line 169 of file B2Vector3.h.

170 {
171 const double ma = Mag();
172 const double ph = Phi();
173 const double ctheta = std::cos((double) theta);
174 const double stheta = std::sin((double) theta);
175 SetX(ma * stheta * std::cos(ph));
176 SetY(ma * stheta * std::cos(ph));
177 SetZ(ma * ctheta);
178 }

◆ SetX()

template<typename DataType>
void SetX ( DataType x)
inline

set X/1st-coordinate

Definition at line 456 of file B2Vector3.h.

456{ m_coordinates[0] = x; }

◆ SetXYZ()

template<typename DataType>
void SetXYZ ( DataType x,
DataType y,
DataType z )
inline

set all coordinates using data type

Definition at line 463 of file B2Vector3.h.

464 {
465 SetX(x); SetY(y); SetZ(z);
466 }

◆ SetY()

template<typename DataType>
void SetY ( DataType y)
inline

set Y/2nd-coordinate

Definition at line 458 of file B2Vector3.h.

458{ m_coordinates[1] = y; }

◆ SetZ()

template<typename DataType>
void SetZ ( DataType z)
inline

set Z/3rd-coordinate

Definition at line 460 of file B2Vector3.h.

460{ m_coordinates[2] = z; }

◆ Sqrt()

template<typename DataType>
void Sqrt ( )
inline

calculates the square root of the absolute values of the coordinates element-wise

Definition at line 413 of file B2Vector3.h.

414 {
415 Abs();
416 m_coordinates[0] = std::sqrt(m_coordinates[0]);
417 m_coordinates[1] = std::sqrt(m_coordinates[1]);
418 m_coordinates[2] = std::sqrt(m_coordinates[2]);
419 }

◆ Theta()

template<typename DataType>
DataType Theta ( ) const
inline

The polar angle.

Definition at line 152 of file B2Vector3.h.

152{ return X() == 0 && Y() == 0 && Z() == 0 ? 0 : atan2(Perp(), Z()); }

◆ Unit()

template<typename DataType>
B2Vector3< DataType > Unit ( ) const
inline

Unit vector parallel to this.

Definition at line 268 of file B2Vector3.h.

269 {
270 const double tot = Mag2();
271 B2Vector3<DataType> p(X(), Y(), Z());
272 return tot > 0.0 ? p *= (1.0 / std::sqrt(tot)) : p;
273 }

◆ X()

template<typename DataType>
DataType X ( ) const
inline

access variable X (= .at(0) without boundary check)

Definition at line 430 of file B2Vector3.h.

430{ return x(); }

◆ x()

template<typename DataType>
DataType x ( ) const
inline

access variable X (= .at(0) without boundary check)

Definition at line 424 of file B2Vector3.h.

424{ return m_coordinates[0]; }

◆ Y()

template<typename DataType>
DataType Y ( ) const
inline

access variable Y (= .at(1) without boundary check)

Definition at line 432 of file B2Vector3.h.

432{ return y(); }

◆ y()

template<typename DataType>
DataType y ( ) const
inline

access variable Y (= .at(1) without boundary check)

Definition at line 426 of file B2Vector3.h.

426{ return m_coordinates[1]; }

◆ Z()

template<typename DataType>
DataType Z ( ) const
inline

access variable Z (= .at(2) without boundary check)

Definition at line 434 of file B2Vector3.h.

434{ return z(); }

◆ z()

template<typename DataType>
DataType z ( ) const
inline

access variable Z (= .at(2) without boundary check)

Definition at line 428 of file B2Vector3.h.

428{ return m_coordinates[2]; }

Member Data Documentation

◆ m_coordinates

template<typename DataType>
DataType m_coordinates[3] {}
protected

Make sure that we only have floating point vectors.

contains the coordinates in given data type

Definition at line 47 of file B2Vector3.h.

47{};

The documentation for this class was generated from the following file: