Belle II Software development
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 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() [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 77 of file B2Vector3.h.

77 :
78 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 81 of file B2Vector3.h.

81: 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 84 of file B2Vector3.h.

84: 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 408 of file B2Vector3.h.

409 {
410 m_coordinates[0] = std::abs(m_coordinates[0]);
411 m_coordinates[1] = std::abs(m_coordinates[1]);
412 m_coordinates[2] = std::abs(m_coordinates[2]);
413 }

◆ Angle()

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

The angle w.r.t.

another B2Vector3.

Definition at line 304 of file B2Vector3.h.

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

◆ CosTheta()

template<typename DataType>
DataType CosTheta ( ) const
inline

Cosine of the polar angle.

Definition at line 157 of file B2Vector3.h.

157{ 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 298 of file B2Vector3.h.

299 {
300 return B2Vector3<DataType>(Y() * p.Z() - p.Y() * Z(), Z() * p.X() - p.Z() * X(), X() * p.Y() - p.X() * Y());
301 }

◆ DeltaPhi()

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

returns phi in the interval [-PI,PI)

Definition at line 230 of file B2Vector3.h.

230{ 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 247 of file B2Vector3.h.

248 {
249 const double deta = Eta() - v.Eta();
250 const double dphi = DeltaPhi(v);
251 return std::hypot(deta, dphi);
252 }

◆ Dot()

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

Scalar product.

Definition at line 292 of file B2Vector3.h.

293 {
294 return X() * p.X() + Y() * p.Y() + Z() * p.Z();
295 }

◆ DrEtaPhi()

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

return DrEtaPhi with respect to input-vector

Definition at line 255 of file B2Vector3.h.

256 {
257 return DeltaR(v);
258 }

◆ Eta()

template<typename DataType>
DataType Eta ( ) const
inline

Returns the pseudo-rapidity.

Definition at line 333 of file B2Vector3.h.

333{ return PseudoRapidity(); }

◆ Mag()

template<typename DataType>
DataType Mag ( ) const
inline

The magnitude (rho in spherical coordinate system).

Definition at line 161 of file B2Vector3.h.

161{ 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 159 of file B2Vector3.h.

159{ 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 234 of file B2Vector3.h.

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

◆ operator ROOT::Math::XYZVector()

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

type conversion in ROOT::Math::XYZVector

Definition at line 105 of file B2Vector3.h.

105{ return GetXYZVector(); }

◆ operator TVector3()

template<typename DataType>
operator TVector3 ( ) const
inline

type conversion in TVector3

Definition at line 103 of file B2Vector3.h.

103{ return GetTVector3(); }

◆ operator!=() [1/3]

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

Comparison != with a B2Vector3.

Definition at line 114 of file B2Vector3.h.

114{ 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 118 of file B2Vector3.h.

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

◆ operator!=() [3/3]

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

Comparison != with a TVector3.

Definition at line 116 of file B2Vector3.h.

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

◆ operator()() [1/2]

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

member access without boundary check

Definition at line 91 of file B2Vector3.h.

91{ return m_coordinates[i]; }

◆ operator()() [2/2]

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

member access without boundary check

Definition at line 87 of file B2Vector3.h.

87{ 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 149 of file B2Vector3.h.

149{ 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 139 of file B2Vector3.h.

140 {
141 return B2Vector3<DataType>(a * X(), a * Y(), a * Z());
142 }

◆ operator+()

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

Addition of 3-vectors.

Definition at line 129 of file B2Vector3.h.

130 {
131 return B2Vector3<DataType>(X() + b.X(), Y() + b.Y(), Z() + b.Z());
132 }

◆ operator-() [1/2]

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

unary minus

Definition at line 127 of file B2Vector3.h.

127{ 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 134 of file B2Vector3.h.

135 {
136 return B2Vector3<DataType>(X() - b.X(), Y() - b.Y(), Z() - b.Z());
137 }

◆ operator/()

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

Scaling of 3-vectors with a real number.

Definition at line 144 of file B2Vector3.h.

145 {
146 return B2Vector3<DataType>(X() / a, Y() / a, Z() / a);
147 }

◆ operator==() [1/3]

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

Comparison for equality with a B2Vector3.

Definition at line 108 of file B2Vector3.h.

108{ 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 112 of file B2Vector3.h.

112{ 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 110 of file B2Vector3.h.

110{ 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 93 of file B2Vector3.h.

93{ return m_coordinates[i]; }

◆ operator[]() [2/2]

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

member access without boundary check

Definition at line 89 of file B2Vector3.h.

89{ return m_coordinates[i]; }

◆ Orthogonal()

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

Vector orthogonal to this one.

Definition at line 279 of file B2Vector3.h.

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

◆ Perp() [1/2]

template<typename DataType>
DataType Perp ( ) const
inline

The transverse component (R in cylindrical coordinate system).

Definition at line 202 of file B2Vector3.h.

202{ 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 228 of file B2Vector3.h.

228{ 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 198 of file B2Vector3.h.

198{ 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 215 of file B2Vector3.h.

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

◆ Phi()

template<typename DataType>
DataType Phi ( ) const
inline

The azimuth angle.

returns phi from -pi to pi

Definition at line 153 of file B2Vector3.h.

153{ 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 513 of file B2Vector3.h.

514 {
515 //print vector parameters
516 Print(PrintString().c_str());
517 }

◆ 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 487 of file B2Vector3.h.

488 {
489 return name() + " " + PrintStringXYZ(precision) + " " + PrintStringCyl(precision);
490 }

◆ PrintStringCyl()

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

create a string containing vector in spherical coordinates

Definition at line 503 of file B2Vector3.h.

504 {
505 std::ostringstream output;
506 output << "(rho, theta, phi)=("
507 << std::fixed << std::setprecision(precision)
508 << Mag() << "," << Theta() * 180. / M_PI << "," << Phi() * 180. / M_PI << ")";
509 return output.str();
510 }

◆ PrintStringXYZ()

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

create a string containing vector in cartesian coordinates

Definition at line 493 of file B2Vector3.h.

494 {
495 std::ostringstream output;
496 output << "(x,y,z)=("
497 << std::fixed << std::setprecision(precision)
498 << X() << "," << Y() << "," << Z() << ")";
499 return output.str();
500 }

◆ 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 321 of file B2Vector3.h.

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

◆ Pt() [1/2]

template<typename DataType>
DataType Pt ( ) const
inline

The transverse component (R in cylindrical coordinate system).

Definition at line 200 of file B2Vector3.h.

200{ 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 226 of file B2Vector3.h.

226{ return Perp(axis); }

◆ Px()

template<typename DataType>
DataType Px ( ) const
inline

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

Definition at line 443 of file B2Vector3.h.

443{ return x(); }

◆ Py()

template<typename DataType>
DataType Py ( ) const
inline

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

Definition at line 445 of file B2Vector3.h.

445{ return y(); }

◆ Pz()

template<typename DataType>
DataType Pz ( ) const
inline

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

Definition at line 447 of file B2Vector3.h.

447{ 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 401 of file B2Vector3.h.

402 {
403 B2Vector3<DataType> n = v.Unit();
404 *this = (n * (n.Dot(*this)) + cos(alpha) * ((n.Cross(*this)).Cross(n)) + sin(alpha) * (n.Cross(*this)));
405 }

◆ RotateUz()

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

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

Definition at line 372 of file B2Vector3.h.

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

◆ RotateX()

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

Rotates the B2Vector3 around the x-axis.

Definition at line 337 of file B2Vector3.h.

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

◆ RotateY()

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

Rotates the B2Vector3 around the y-axis.

Definition at line 349 of file B2Vector3.h.

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

◆ RotateZ()

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

Rotates the B2Vector3 around the z-axis.

Definition at line 361 of file B2Vector3.h.

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

◆ SetMag()

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

Set magnitude keeping theta and phi constant.

Definition at line 184 of file B2Vector3.h.

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

◆ SetMagThetaPhi()

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

setter with mag, theta, phi

Definition at line 261 of file B2Vector3.h.

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

◆ SetPerp()

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

Set the transverse component keeping phi and z constant.

Definition at line 205 of file B2Vector3.h.

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

◆ SetPhi()

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

Set phi keeping mag and theta constant.

Definition at line 164 of file B2Vector3.h.

165 {
166 const double perp = Perp();
167 SetX(perp * cos((double)phi));
168 SetY(perp * sin((double)phi));
169 }

◆ SetTheta()

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

Set theta keeping mag and phi constant.

Definition at line 172 of file B2Vector3.h.

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

◆ SetX()

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

set X/1st-coordinate

Definition at line 463 of file B2Vector3.h.

463{ 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 470 of file B2Vector3.h.

471 {
472 SetX(x); SetY(y); SetZ(z);
473 }

◆ SetY()

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

set Y/2nd-coordinate

Definition at line 465 of file B2Vector3.h.

465{ m_coordinates[1] = y; }

◆ SetZ()

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

set Z/3rd-coordinate

Definition at line 467 of file B2Vector3.h.

467{ 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 416 of file B2Vector3.h.

417 {
418 Abs();
419 m_coordinates[0] = std::sqrt(m_coordinates[0]);
420 m_coordinates[1] = std::sqrt(m_coordinates[1]);
421 m_coordinates[2] = std::sqrt(m_coordinates[2]);
422 }

◆ Theta()

template<typename DataType>
DataType Theta ( ) const
inline

The polar angle.

Definition at line 155 of file B2Vector3.h.

155{ 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 271 of file B2Vector3.h.

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

◆ X()

template<typename DataType>
DataType X ( ) const
inline

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

Definition at line 435 of file B2Vector3.h.

435{ return x(); }

◆ x()

template<typename DataType>
DataType x ( ) const
inline

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

Definition at line 427 of file B2Vector3.h.

427{ return m_coordinates[0]; }

◆ Y()

template<typename DataType>
DataType Y ( ) const
inline

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

Definition at line 437 of file B2Vector3.h.

437{ return y(); }

◆ y()

template<typename DataType>
DataType y ( ) const
inline

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

Definition at line 429 of file B2Vector3.h.

429{ return m_coordinates[1]; }

◆ Z()

template<typename DataType>
DataType Z ( ) const
inline

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

Definition at line 439 of file B2Vector3.h.

439{ return z(); }

◆ z()

template<typename DataType>
DataType z ( ) const
inline

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

Definition at line 431 of file B2Vector3.h.

431{ 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: