Belle II Software light-2406-ragdoll
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

typedef DataType value_type

storage type of the vector

Definition at line 50 of file B2Vector3.h.

Constructor & Destructor Documentation

◆ B2Vector3() [1/12]

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)} {};
DataType m_coordinates[3]
Make sure that we only have floating point vectors.
Definition: B2Vector3.h:47

◆ B2Vector3() [2/12]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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()

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()

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 }
DataType Mag2() const
The magnitude squared (rho^2 in spherical coordinate system).
Definition: B2Vector3.h:157
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
Definition: B2Vector3.h:290

◆ CosTheta()

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; }
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:435
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition: B2Vector3.h:159

◆ Cross()

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 }
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:431
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:433

◆ DeltaPhi()

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()); }
DataType Phi() const
The azimuth angle.
Definition: B2Vector3.h:151
static DataType Mpi_pi(DataType angle)
returns given angle in the interval [-PI,PI)
Definition: B2Vector3.h:232

◆ DeltaR()

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 }
DataType Eta() const
Returns the pseudo-rapidity.
Definition: B2Vector3.h:331
DataType DeltaPhi(const B2Vector3< DataType > &v) const
returns phi in the interval [-PI,PI)
Definition: B2Vector3.h:228

◆ Dot()

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()

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 }
DataType DeltaR(const B2Vector3< DataType > &v) const
return deltaR with respect to input-vector
Definition: B2Vector3.h:245

◆ Eta()

DataType Eta ( ) const
inline

Returns the pseudo-rapidity.

Definition at line 331 of file B2Vector3.h.

331{ return PseudoRapidity(); }
DataType PseudoRapidity() const
Returns the pseudo-rapidity, i.e.
Definition: B2Vector3.h:319

◆ Mag()

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()); }
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
Definition: B2Vector3.h:200

◆ Mag2()

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()

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 }
static std::string name()
Returns the name of the B2Vector.
Definition: B2Vector3.h:767

◆ operator ROOT::Math::XYZVector()

operator ROOT::Math::XYZVector ( ) const
inline

type conversion in ROOT::Math::XYZVector

Definition at line 103 of file B2Vector3.h.

103{ return GetXYZVector(); }
ROOT::Math::XYZVector GetXYZVector() const
returns a XYZVector containing the same coordinates
Definition: B2Vector3.h:738

◆ operator TVector3()

operator TVector3 ( ) const
inline

type conversion in TVector3

Definition at line 101 of file B2Vector3.h.

101{ return GetTVector3(); }
TVector3 GetTVector3() const
returns a TVector3 containing the same coordinates
Definition: B2Vector3.h:725

◆ operator!=() [1/3]

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]

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]

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]

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]

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]

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]

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+()

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]

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]

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/()

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]

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]

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]

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]

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]

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()

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 }
B2Vector3(void)
empty Constructor sets everything to 0
Definition: B2Vector3.h:53

◆ Perp() [1/2]

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]

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)); }
DataType Perp2() const
The transverse component squared (R^2 in cylindrical coordinate system).
Definition: B2Vector3.h:196

◆ Perp2() [1/2]

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]

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()

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()

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 }
std::string PrintString(unsigned precision=4) const
create a string containing vector in cartesian and spherical coordinates
Definition: B2Vector3.h:481
void Print()
just for backward compatibility, should not be used with new code
Definition: B2Vector3.h:507

◆ PrintString()

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 }
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
Definition: B2Vector3.h:487
std::string PrintStringCyl(unsigned precision=4) const
create a string containing vector in spherical coordinates
Definition: B2Vector3.h:497

◆ PrintStringCyl()

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 }
DataType Theta() const
The polar angle.
Definition: B2Vector3.h:153

◆ PrintStringXYZ()

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()

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 }
DataType CosTheta() const
Cosine of the polar angle.
Definition: B2Vector3.h:155

◆ Pt() [1/2]

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]

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()

DataType Px ( ) const
inline

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

Definition at line 437 of file B2Vector3.h.

437{ return x(); }
DataType x() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:425

◆ Py()

DataType Py ( ) const
inline

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

Definition at line 439 of file B2Vector3.h.

439{ return y(); }
DataType y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:427

◆ Pz()

DataType Pz ( ) const
inline

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

Definition at line 441 of file B2Vector3.h.

441{ return z(); }
DataType z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:429

◆ Rotate()

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 }
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
Definition: B2Vector3.h:296

◆ RotateUz()

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.) {
388 }
389 }

◆ RotateX()

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()

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()

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()

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 }
void SetX(DataType x)
set X/1st-coordinate
Definition: B2Vector3.h:457
void SetZ(DataType z)
set Z/3rd-coordinate
Definition: B2Vector3.h:461
void SetY(DataType y)
set Y/2nd-coordinate
Definition: B2Vector3.h:459

◆ SetMagThetaPhi()

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()

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()

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()

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()

void SetX ( DataType  x)
inline

set X/1st-coordinate

Definition at line 457 of file B2Vector3.h.

457{ m_coordinates[0] = x; }

◆ SetXYZ()

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()

void SetY ( DataType  y)
inline

set Y/2nd-coordinate

Definition at line 459 of file B2Vector3.h.

459{ m_coordinates[1] = y; }

◆ SetZ()

void SetZ ( DataType  z)
inline

set Z/3rd-coordinate

Definition at line 461 of file B2Vector3.h.

461{ m_coordinates[2] = z; }

◆ Sqrt()

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 }
void Abs()
calculates the absolute value of the coordinates element-wise
Definition: B2Vector3.h:406

◆ Theta()

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()

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()

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

◆ X()

DataType X ( ) const
inline

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

Definition at line 431 of file B2Vector3.h.

431{ return x(); }

◆ y()

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

◆ Y()

DataType Y ( ) const
inline

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

Definition at line 433 of file B2Vector3.h.

433{ return y(); }

◆ z()

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

◆ Z()

DataType Z ( ) const
inline

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

Definition at line 435 of file B2Vector3.h.

435{ return z(); }

Member Data Documentation

◆ m_coordinates

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.


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