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

72 :
73 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 75 of file B2Vector3.h.

75 :
76 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 79 of file B2Vector3.h.

79: 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 82 of file B2Vector3.h.

82: 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 406 of file B2Vector3.h.

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

◆ Angle()

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

The angle w.r.t.

another B2Vector3.

Definition at line 302 of file B2Vector3.h.

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

◆ CosTheta()

template<typename DataType>
DataType CosTheta ( ) const
inline

Cosine of the polar angle.

Definition at line 155 of file B2Vector3.h.

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

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

◆ DeltaPhi()

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

returns phi in the interval [-PI,PI)

Definition at line 228 of file B2Vector3.h.

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

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

◆ Dot()

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

Scalar product.

Definition at line 290 of file B2Vector3.h.

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

◆ DrEtaPhi()

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

return DrEtaPhi with respect to input-vector

Definition at line 253 of file B2Vector3.h.

254 {
255 return DeltaR(v);
256 }

◆ Eta()

template<typename DataType>
DataType Eta ( ) const
inline

Returns the pseudo-rapidity.

Definition at line 331 of file B2Vector3.h.

331{ return PseudoRapidity(); }

◆ Mag()

template<typename DataType>
DataType Mag ( ) const
inline

The magnitude (rho in spherical coordinate system).

Definition at line 159 of file B2Vector3.h.

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

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

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

◆ operator ROOT::Math::XYZVector()

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

type conversion in ROOT::Math::XYZVector

Definition at line 103 of file B2Vector3.h.

103{ return GetXYZVector(); }

◆ operator TVector3()

template<typename DataType>
operator TVector3 ( ) const
inline

type conversion in TVector3

Definition at line 101 of file B2Vector3.h.

101{ return GetTVector3(); }

◆ operator!=() [1/3]

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

Comparison != with a B2Vector3.

Definition at line 112 of file B2Vector3.h.

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

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

◆ operator!=() [3/3]

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

Comparison != with a TVector3.

Definition at line 114 of file B2Vector3.h.

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

◆ operator()() [1/2]

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

member access without boundary check

Definition at line 89 of file B2Vector3.h.

89{ return m_coordinates[i]; }

◆ operator()() [2/2]

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

member access without boundary check

Definition at line 85 of file B2Vector3.h.

85{ 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 147 of file B2Vector3.h.

147{ 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 137 of file B2Vector3.h.

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

◆ operator+()

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

Addition of 3-vectors.

Definition at line 127 of file B2Vector3.h.

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

◆ operator-() [1/2]

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

unary minus

Definition at line 125 of file B2Vector3.h.

125{ 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 132 of file B2Vector3.h.

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

◆ operator/()

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

Scaling of 3-vectors with a real number.

Definition at line 142 of file B2Vector3.h.

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

◆ operator==() [1/3]

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

Comparison for equality with a B2Vector3.

Definition at line 106 of file B2Vector3.h.

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

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

108{ 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 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]; }

◆ Orthogonal()

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

Vector orthogonal to this one.

Definition at line 277 of file B2Vector3.h.

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

◆ Perp() [1/2]

template<typename DataType>
DataType Perp ( ) const
inline

The transverse component (R in cylindrical coordinate system).

Definition at line 200 of file B2Vector3.h.

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

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

196{ 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 213 of file B2Vector3.h.

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

◆ Phi()

template<typename DataType>
DataType Phi ( ) const
inline

The azimuth angle.

returns phi from -pi to pi

Definition at line 151 of file B2Vector3.h.

151{ 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 507 of file B2Vector3.h.

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

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

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

◆ PrintStringCyl()

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

create a string containing vector in spherical coordinates

Definition at line 497 of file B2Vector3.h.

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

◆ PrintStringXYZ()

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

create a string containing vector in cartesian coordinates

Definition at line 487 of file B2Vector3.h.

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

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

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

◆ Pt() [1/2]

template<typename DataType>
DataType Pt ( ) const
inline

The transverse component (R in cylindrical coordinate system).

Definition at line 198 of file B2Vector3.h.

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

224{ return Perp(axis); }

◆ Px()

template<typename DataType>
DataType Px ( ) const
inline

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

Definition at line 437 of file B2Vector3.h.

437{ return x(); }

◆ Py()

template<typename DataType>
DataType Py ( ) const
inline

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

Definition at line 439 of file B2Vector3.h.

439{ return y(); }

◆ Pz()

template<typename DataType>
DataType Pz ( ) const
inline

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

Definition at line 441 of file B2Vector3.h.

441{ 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 399 of file B2Vector3.h.

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

◆ RotateUz()

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

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

Definition at line 370 of file B2Vector3.h.

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

◆ RotateX()

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

Rotates the B2Vector3 around the x-axis.

Definition at line 335 of file B2Vector3.h.

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

◆ RotateY()

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

Rotates the B2Vector3 around the y-axis.

Definition at line 347 of file B2Vector3.h.

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

◆ RotateZ()

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

Rotates the B2Vector3 around the z-axis.

Definition at line 359 of file B2Vector3.h.

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

◆ SetMag()

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

Set magnitude keeping theta and phi constant.

Definition at line 182 of file B2Vector3.h.

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

◆ SetMagThetaPhi()

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

setter with mag, theta, phi

Definition at line 259 of file B2Vector3.h.

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

◆ SetPerp()

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

Set the transverse component keeping phi and z constant.

Definition at line 203 of file B2Vector3.h.

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

◆ SetPhi()

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

Set phi keeping mag and theta constant.

Definition at line 162 of file B2Vector3.h.

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

◆ SetTheta()

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

Set theta keeping mag and phi constant.

Definition at line 170 of file B2Vector3.h.

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

◆ SetX()

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

set X/1st-coordinate

Definition at line 457 of file B2Vector3.h.

457{ 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 464 of file B2Vector3.h.

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

◆ SetY()

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

set Y/2nd-coordinate

Definition at line 459 of file B2Vector3.h.

459{ m_coordinates[1] = y; }

◆ SetZ()

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

set Z/3rd-coordinate

Definition at line 461 of file B2Vector3.h.

461{ 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 414 of file B2Vector3.h.

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

◆ Theta()

template<typename DataType>
DataType Theta ( ) const
inline

The polar angle.

Definition at line 153 of file B2Vector3.h.

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

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

◆ X()

template<typename DataType>
DataType X ( ) const
inline

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

Definition at line 431 of file B2Vector3.h.

431{ return x(); }

◆ x()

template<typename DataType>
DataType x ( ) const
inline

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

Definition at line 425 of file B2Vector3.h.

425{ return m_coordinates[0]; }

◆ Y()

template<typename DataType>
DataType Y ( ) const
inline

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

Definition at line 433 of file B2Vector3.h.

433{ return y(); }

◆ y()

template<typename DataType>
DataType y ( ) const
inline

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

Definition at line 427 of file B2Vector3.h.

427{ return m_coordinates[1]; }

◆ Z()

template<typename DataType>
DataType Z ( ) const
inline

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

Definition at line 435 of file B2Vector3.h.

435{ return z(); }

◆ z()

template<typename DataType>
DataType z ( ) const
inline

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

Definition at line 429 of file B2Vector3.h.

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