12#include <framework/logging/Logger.h>
15#include <Math/Vector3D.h>
41 template<
typename DataType>
45 static_assert(std::is_floating_point<DataType>::value,
"B2Vector3 only works with floating point types");
62 B2Vector3(
const TVector3& tVec3):
m_coordinates {static_cast<DataType>(tVec3.
X()), static_cast<DataType>(tVec3.
Y()), static_cast<DataType>(tVec3.
Z())} {};
65 B2Vector3(
const TVector3* tVec3):
m_coordinates {static_cast<DataType>(tVec3->
X()), static_cast<DataType>(tVec3->
Y()), static_cast<DataType>(tVec3->
Z())} {};
75 m_coordinates {static_cast<DataType>(b2Vec3.
X()), static_cast<DataType>(b2Vec3.
Y()), static_cast<DataType>(b2Vec3.
Z())} {};
78 m_coordinates {static_cast<DataType>(b2Vec3->
X()), static_cast<DataType>(b2Vec3->
Y()), static_cast<DataType>(b2Vec3->
Z())} {};
81 B2Vector3(
const ROOT::Math::XYZVector& xyzVec):
m_coordinates {static_cast<DataType>(xyzVec.
X()), static_cast<DataType>(xyzVec.
Y()), static_cast<DataType>(xyzVec.
Z())} {};
84 B2Vector3(
const ROOT::Math::XYZVector* xyzVec):
m_coordinates {static_cast<DataType>(xyzVec->
X()), static_cast<DataType>(xyzVec->
Y()), static_cast<DataType>(xyzVec->
Z())} {};
110 bool operator == (
const TVector3& b)
const {
return X() == b.X() &&
Y() == b.Y() &&
Z() == b.Z(); }
112 bool operator == (
const ROOT::Math::XYZVector& b)
const {
return X() == b.X() &&
Y() == b.Y() &&
Z() == b.Z(); }
116 bool operator != (
const TVector3& b)
const {
return !(*
this == b); }
118 bool operator != (
const ROOT::Math::XYZVector& b)
const {
return !(*
this == b); }
153 DataType
Phi()
const {
return X() == 0 &&
Y() == 0 ? 0 : atan2(
Y(),
X()); }
155 DataType
Theta()
const {
return X() == 0 &&
Y() == 0 &&
Z() == 0 ? 0 : atan2(
Perp(),
Z()); }
157 DataType
CosTheta()
const {
const double pTot =
Mag();
return pTot == 0 ? 1 :
Z() / pTot; }
159 DataType
Mag2()
const {
return X() *
X() +
Y() *
Y() +
Z() *
Z(); }
161 DataType
Mag()
const {
return std::hypot((
double)
Perp(), (
double)
Z()); }
166 const double perp =
Perp();
167 SetX(perp * cos((
double)phi));
168 SetY(perp * sin((
double)phi));
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));
186 double factor =
Mag();
188 B2WARNING(
name() <<
"::SetMag: zero vector can't be stretched");
190 factor = mag / factor;
198 DataType
Perp2()
const {
return X() *
X() +
Y() *
Y(); }
202 DataType
Perp()
const {
return std::hypot((
double)
X(), (
double)
Y()); }
207 const double p =
Perp();
217 const double tot = axis.Mag2();
218 const double ss =
Dot(axis);
220 if (tot > 0.0) per -= ss * ss / tot;
221 if (per < 0) per = 0;
236 if (std::isnan(angle)) {
237 B2ERROR(
name() <<
"::Mpi_pi: function called with NaN");
240 angle = std::remainder(angle, 2 * M_PI);
242 if (angle == M_PI) angle = -M_PI;
249 const double deta =
Eta() - v.Eta();
251 return std::hypot(deta, dphi);
263 const double amag = std::abs(mag);
264 const double sinTheta = std::sin((
double)theta);
273 const double tot =
Mag2();
275 return tot > 0.0 ? p *= (1.0 / std::sqrt(tot)) : p;
281 const double xVal = std::abs((
double)
X());
282 const double yVal = std::abs((
double)
Y());
283 const double zVal = std::abs((
double)
Z());
294 return X() * p.X() +
Y() * p.Y() +
Z() * p.Z();
306 const double ptot2 =
static_cast<double>(
Mag2()) * q.Mag2();
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);
324 if (std::abs(cosTheta) < 1)
return -0.5 * std::log((1.0 - cosTheta) / (1.0 + cosTheta));
325 if (
Z() == 0)
return 0;
327 if (
Z() > 0)
return 10e10;
340 const double s = std::sin((
double)angle);
341 const double c = std::cos((
double)angle);
342 const double yOld =
Y();
352 const double s = std::sin((
double)angle);
353 const double c = std::cos((
double)angle);
354 const double zOld =
Z();
364 const double s = std::sin((
double)angle);
365 const double c = std::cos((
double)angle);
366 const double xOld =
X();
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;
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;
387 }
else if (u3 < 0.) {
404 *
this = (n * (n.Dot(*
this)) + cos(alpha) * ((n.Cross(*
this)).Cross(n)) + sin(alpha) * (n.Cross(*
this)));
425 DataType
at(
unsigned i)
const;
435 DataType
X()
const {
return x(); }
437 DataType
Y()
const {
return y(); }
439 DataType
Z()
const {
return z(); }
443 DataType
Px()
const {
return x(); }
445 DataType
Py()
const {
return y(); }
447 DataType
Pz()
const {
return z(); }
456 void GetXYZ(ROOT::Math::XYZVector* xyzVec)
const;
479 void SetXYZ(
const ROOT::Math::XYZVector& xyzVec);
481 void SetXYZ(
const ROOT::Math::XYZVector* xyzVec);
495 std::ostringstream output;
496 output <<
"(x,y,z)=("
497 << std::fixed << std::setprecision(precision)
498 <<
X() <<
"," <<
Y() <<
"," <<
Z() <<
")";
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 <<
")";
528 template <
typename DataType>
531 return (a.X() == b.X() && a.Y() == b.Y() && a.Z() == b.Z());
535 template <
typename DataType>
542 template <
typename DataType>
549 template <
typename DataType>
556 template <
typename DataType>
563 template <
typename DataType>
570 template <
typename DataType>
577 template <
typename DataType>
584 template <
typename DataType>
591 template <
typename DataType>
598 template <
typename DataType>
606 template<
typename DataType >
616 template<
typename DataType >
626 template<
typename DataType >
636 template<
typename DataType >
647 template<
typename DataType >
657 template<
typename DataType >
667 template<
typename DataType >
676 template<
typename DataType >
685 template<
typename DataType >
694 template<
typename DataType >
702 template<
typename DataType >
710 template<
typename DataType >
719 template<
typename DataType >
722 tVec->SetXYZ(
static_cast<Double_t
>(
X()),
723 static_cast<Double_t
>(
Y()),
724 static_cast<Double_t
>(
Z()));
728 template<
typename DataType >
731 xyzVec->SetXYZ(
static_cast<Double_t
>(
X()),
732 static_cast<Double_t
>(
Y()),
733 static_cast<Double_t
>(
Z()));
738 template<
typename DataType >
743 static_cast<Double_t
>(
X()),
744 static_cast<Double_t
>(
Y()),
745 static_cast<Double_t
>(
Z())
751 template<
typename DataType >
755 ROOT::Math::XYZVector(
756 static_cast<Double_t
>(
X()),
757 static_cast<Double_t
>(
Y()),
758 static_cast<Double_t
>(
Z())
764 template <
typename DataType>
773 B2FATAL(this->
name() <<
"::access operator: given index (i=" << i <<
") is out of bounds!");
778 template <
typename DataType>
781 return std::string(
"B2Vector3<") +
typeid(DataType).
name() + std::string(
">");
A fast and root compatible alternative to TVector3.
DataType Phi() const
The azimuth angle.
void SetMag(DataType mag)
Set magnitude keeping theta and phi constant.
B2Vector3< DataType > operator-() const
unary minus
DataType Pz() const
access variable Z (= .at(2) without boundary check)
B2Vector3(const B2Vector3< DataType > &b2Vec3)
Constructor expecting a B2Vector3 of same type.
DataType operator()(unsigned i) const
member access without boundary check
DataType Perp2() const
The transverse component squared (R^2 in cylindrical coordinate system).
void SetPerp(DataType r)
Set the transverse component keeping phi and z constant.
DataType y() const
access variable Y (= .at(1) without boundary check)
void SetX(DataType x)
set X/1st-coordinate
DataType Theta() const
The polar angle.
DataType CosTheta() const
Cosine of the polar angle.
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
DataType z() const
access variable Z (= .at(2) without boundary check)
B2Vector3(const B2Vector3< DataType > *b2Vec3)
Constructor expecting a pointer to a B2Vector3.
void SetMagThetaPhi(DataType mag, DataType theta, DataType phi)
setter with mag, theta, phi
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
B2Vector3< DataType > Orthogonal() const
Vector orthogonal to this one.
DataType Eta() const
Returns the pseudo-rapidity.
B2Vector3< DataType > operator*(DataType a) const
Scaling of 3-vectors with a real number.
DataType DeltaPhi(const B2Vector3< DataType > &v) const
returns phi in the interval [-PI,PI)
void RotateY(DataType angle)
Rotates the B2Vector3 around the y-axis.
DataType operator[](unsigned i) const
member access without boundary check
std::string PrintString(unsigned precision=4) const
create a string containing vector in cartesian and spherical coordinates
DataType Mag() const
The magnitude (rho in spherical coordinate system).
DataType value_type
storage type of the vector
B2Vector3(const ROOT::Math::XYZVector &xyzVec)
Constructor expecting a XYZVector.
bool operator==(const B2Vector3< DataType > &b) const
Comparison for equality with a B2Vector3.
DataType x() const
access variable X (= .at(0) without boundary check)
B2Vector3(const DataType(*coords)[3])
Constructor using a pointer.
DataType DeltaR(const B2Vector3< DataType > &v) const
return deltaR with respect to input-vector
DataType Perp(const B2Vector3< DataType > &axis) const
The transverse component w.r.t.
DataType & operator()(unsigned i)
member access without boundary check
void RotateX(DataType angle)
Rotates the B2Vector3 around the x-axis.
void Abs()
calculates the absolute value of the coordinates element-wise
B2Vector3(const DataType(&coords)[3])
Constructor using a reference.
B2Vector3(const ROOT::Math::XYZVector *xyzVec)
Constructor expecting a pointer to a XYZVector.
DataType Pt(const B2Vector3< DataType > &axis) const
The transverse component w.r.t.
DataType Mag2() const
The magnitude squared (rho^2 in spherical coordinate system).
void SetTheta(DataType theta)
Set theta keeping mag and phi constant.
B2Vector3< DataType > operator+(const B2Vector3< DataType > &b) const
Addition of 3-vectors.
B2Vector3(const TVector3 &tVec3)
Constructor expecting a TVector3.
void RotateZ(DataType angle)
Rotates the B2Vector3 around the z-axis.
void Print()
just for backward compatibility, should not be used with new code
void Sqrt()
calculates the square root of the absolute values of the coordinates element-wise
void SetZ(DataType z)
set Z/3rd-coordinate
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
void SetY(DataType y)
set Y/2nd-coordinate
B2Vector3(const B2Vector3< OtherType > *b2Vec3)
Constructor expecting a pointer to a B2Vector3 of different type.
DataType PseudoRapidity() const
Returns the pseudo-rapidity, i.e.
DataType DrEtaPhi(const B2Vector3< DataType > &v) const
return DrEtaPhi with respect to input-vector
bool operator!=(const B2Vector3< DataType > &b) const
Comparison != with a B2Vector3.
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
B2Vector3(void)
empty Constructor sets everything to 0
DataType Perp2(const B2Vector3< DataType > &axis) const
The transverse component w.r.t.
B2Vector3(const B2Vector3< OtherType > &b2Vec3)
Constructor expecting a B2Vector3 of different type.
void RotateUz(const B2Vector3< DataType > &NewUzVector)
Rotates reference frame from Uz to newUz (unit vector).
DataType Py() const
access variable Y (= .at(1) without boundary check)
static DataType Mpi_pi(DataType angle)
returns given angle in the interval [-PI,PI)
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
DataType Pt() const
The transverse component (R in cylindrical coordinate system).
B2Vector3(const TVector3 *tVec3)
Constructor expecting a pointer to a TVector3.
DataType Px() const
access variable X (= .at(0) without boundary check)
void SetXYZ(DataType x, DataType y, DataType z)
set all coordinates using data type
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
DataType & operator[](unsigned i)
member access without boundary check
std::string PrintStringCyl(unsigned precision=4) const
create a string containing vector in spherical coordinates
B2Vector3< DataType > operator/(DataType a) const
Scaling of 3-vectors with a real number.
void Rotate(DataType alpha, const B2Vector3< DataType > &v)
Rotation around an arbitrary axis v with angle alpha.
void SetPhi(DataType phi)
Set phi keeping mag and theta constant.
B2Vector3(const DataType xVal, const DataType yVal, const DataType zVal)
Constructor expecting 3 coordinates.
bool operator==(const DecayNode &node1, const DecayNode &node2)
Compare two Decay Nodes: They are equal if All daughter decay nodes are equal or one of the daughter ...
bool operator!=(const DecayNode &node1, const DecayNode &node2)
Not equal: See operator==.
void SetXYZ(const ROOT::Math::XYZVector *xyzVec)
set all coordinates using a pointer to XYZVector
void GetXYZ(ROOT::Math::XYZVector *xyzVec) const
directly copies coordinates to a XYZVector
void SetXYZ(const TVector3 &tVec)
set all coordinates using a reference to TVector3
B2Vector3< DataType > & operator-=(const B2Vector3< DataType > &b)
subtraction
void GetXYZ(Float_t *carray) const
directly copies coordinates to an array of float
TVector3 GetTVector3() const
returns a TVector3 containing the same coordinates
B2Vector3< float > B2Vector3F
typedef for common usage with float
void GetXYZ(TVector3 *tVec) const
directly copies coordinates to a TVector3
void SetXYZ(const TVector3 *tVec)
set all coordinates using a pointer to TVector3
ROOT::Math::XYZVector GetXYZVector() const
returns a XYZVector containing the same coordinates
B2Vector3< DataType > & operator+=(const B2Vector3< DataType > &b)
addition
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
B2Vector3< DataType > operator-(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for subtracting a TVector3 from a B2Vector3
B2Vector3< DataType > & operator*=(DataType a)
scaling with real numbers
void GetXYZ(Double_t *carray) const
directly copies coordinates to an array of double
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
void SetXYZ(const ROOT::Math::XYZVector &xyzVec)
set all coordinates using a reference to XYZVector
B2Vector3< DataType > & operator=(const B2Vector3< DataType > &b)
Assignment via B2Vector3.
B2Vector3< double > B2Vector3D
typedef for common usage with double
DataType at(unsigned i) const
safe member access (with boundary check!)
static std::string name()
Returns the name of the B2Vector.
Abstract base class for different kinds of events.