12 #include <framework/logging/Logger.h>
40 template<
typename DataType>
44 static_assert(std::is_floating_point<DataType>::value,
"B2Vector3 only works with floating point types");
61 B2Vector3(
const TVector3& tVec3):
m_coordinates {static_cast<DataType>(tVec3.
X()), static_cast<DataType>(tVec3.
Y()), static_cast<DataType>(tVec3.
Z())} {};
64 B2Vector3(
const TVector3* tVec3):
m_coordinates {static_cast<DataType>(tVec3->
X()), static_cast<DataType>(tVec3->
Y()), static_cast<DataType>(tVec3->
Z())} {};
72 m_coordinates {static_cast<DataType>(b2Vec3.
X()), static_cast<DataType>(b2Vec3.
Y()), static_cast<DataType>(b2Vec3.
Z())} {};
75 m_coordinates {static_cast<DataType>(b2Vec3->
X()), static_cast<DataType>(b2Vec3->
Y()), static_cast<DataType>(b2Vec3->
Z())} {};
97 bool operator == (
const TVector3& b)
const {
return X() == b.X() &&
Y() == b.Y() &&
Z() == b.Z(); }
101 bool operator != (
const TVector3& b)
const {
return !(*
this == b); }
136 DataType
Phi()
const {
return X() == 0 &&
Y() == 0 ? 0 : atan2(
Y(),
X()); }
138 DataType
Theta()
const {
return X() == 0 &&
Y() == 0 &&
Z() == 0 ? 0 : atan2(
Perp(),
Z()); }
140 DataType
CosTheta()
const {
const double pTot =
Mag();
return pTot == 0 ? 1 :
Z() / pTot; }
142 DataType
Mag2()
const {
return X() *
X() +
Y() *
Y() +
Z() *
Z(); }
144 DataType
Mag()
const {
return std::hypot((
double)
Perp(), (
double)
Z()); }
149 const double perp =
Perp();
150 SetX(perp * cos((
double)phi));
151 SetY(perp * sin((
double)phi));
157 const double ma =
Mag();
158 const double ph =
Phi();
159 const double ctheta = std::cos((
double) theta);
160 const double stheta = std::sin((
double) theta);
161 SetX(ma * stheta * std::cos(ph));
162 SetY(ma * stheta * std::cos(ph));
169 double factor =
Mag();
171 B2WARNING(
name() <<
"::SetMag: zero vector can't be stretched");
173 factor = mag / factor;
181 DataType
Perp2()
const {
return X() *
X() +
Y() *
Y(); }
185 DataType
Perp()
const {
return std::hypot((
double)
X(), (
double)
Y()); }
190 const double p =
Perp();
200 const double tot = axis.Mag2();
201 const double ss =
Dot(axis);
203 if (tot > 0.0) per -= ss * ss / tot;
204 if (per < 0) per = 0;
219 if (std::isnan(angle)) {
220 B2ERROR(
name() <<
"::Mpi_pi: function called with NaN");
223 angle = std::remainder(angle, 2 * M_PI);
225 if (angle == M_PI) angle = -M_PI;
232 const double deta =
Eta() - v.Eta();
234 return std::hypot(deta, dphi);
246 const double amag = std::abs(mag);
247 const double sinTheta = std::sin((
double)theta);
256 const double tot =
Mag2();
258 return tot > 0.0 ? p *= (1.0 / std::sqrt(tot)) : p;
264 const double xVal = std::abs((
double)
X());
265 const double yVal = std::abs((
double)
Y());
266 const double zVal = std::abs((
double)
Z());
277 return X() * p.X() +
Y() * p.Y() +
Z() * p.Z();
289 const double ptot2 =
Mag2() * q.Mag2();
293 double arg =
Dot(q) / std::sqrt(ptot2);
294 if (arg > 1.0) arg = 1.0;
295 if (arg < -1.0) arg = -1.0;
296 return std::acos(arg);
307 if (std::abs(cosTheta) < 1)
return -0.5 * std::log((1.0 - cosTheta) / (1.0 + cosTheta));
308 if (
Z() == 0)
return 0;
310 if (
Z() > 0)
return 10e10;
323 const double s = std::sin((
double)angle);
324 const double c = std::cos((
double)angle);
325 const double yOld =
Y();
335 const double s = std::sin((
double)angle);
336 const double c = std::cos((
double)angle);
337 const double zOld =
Z();
347 const double s = std::sin((
double)angle);
348 const double c = std::cos((
double)angle);
349 const double xOld =
X();
359 const double u1 = NewUzVector.
X();
360 const double u2 = NewUzVector.
Y();
361 const double u3 = NewUzVector.
Z();
362 double up = u1 * u1 + u2 * u2;
366 DataType px =
X(), py =
Y(), pz =
Z();
367 m_coordinates[0] = (u1 * u3 * px - u2 * py + u1 * up * pz) / up;
368 m_coordinates[1] = (u2 * u3 * px + u1 * py + u2 * up * pz) / up;
370 }
else if (u3 < 0.) {
387 *
this = (n * (n.Dot(*
this)) + cos(alpha) * ((n.Cross(*
this)).
Cross(n)) + sin(alpha) * (n.Cross(*
this)));
408 DataType
at(
unsigned i)
const;
416 DataType
X()
const {
return x(); }
418 DataType
Y()
const {
return y(); }
420 DataType
Z()
const {
return z(); }
422 DataType
Px()
const {
return x(); }
424 DataType
Py()
const {
return y(); }
426 DataType
Pz()
const {
return z(); }
466 std::ostringstream output;
467 output <<
"(x,y,z)=("
468 << std::fixed << std::setprecision(precision)
469 <<
X() <<
"," <<
Y() <<
"," <<
Z() <<
")";
476 std::ostringstream output;
477 output <<
"(rho, theta, phi)=("
478 << std::fixed << std::setprecision(precision)
479 <<
Mag() <<
"," <<
Theta() * 180. / M_PI <<
"," <<
Phi() * 180. / M_PI <<
")";
499 template <
typename DataType>
502 return (a.X() == b.X() && a.Y() == b.Y() && a.Z() == b.Z());
506 template <
typename DataType>
513 template <
typename DataType>
520 template <
typename DataType>
527 template <
typename DataType>
534 template <
typename DataType>
541 template <
typename DataType>
549 template<
typename DataType >
552 m_coordinates[0] = b.X();
553 m_coordinates[1] = b.Y();
554 m_coordinates[2] = b.Z();
559 template<
typename DataType >
562 m_coordinates[0] = b.X();
563 m_coordinates[1] = b.Y();
564 m_coordinates[2] = b.Z();
569 template<
typename DataType >
572 m_coordinates[0] += b.X();
573 m_coordinates[1] += b.Y();
574 m_coordinates[2] += b.Z();
580 template<
typename DataType >
583 m_coordinates[0] -= b.X();
584 m_coordinates[1] -= b.Y();
585 m_coordinates[2] -= b.Z();
590 template<
typename DataType >
593 m_coordinates[0] *= a;
594 m_coordinates[1] *= a;
595 m_coordinates[2] *= a;
600 template<
typename DataType >
603 m_coordinates[0] =
static_cast<Double_t
>(tVec.X());
604 m_coordinates[1] =
static_cast<Double_t
>(tVec.Y());
605 m_coordinates[2] =
static_cast<Double_t
>(tVec.Z());
609 template<
typename DataType >
612 m_coordinates[0] =
static_cast<Double_t
>(tVec->X());
613 m_coordinates[1] =
static_cast<Double_t
>(tVec->Y());
614 m_coordinates[2] =
static_cast<Double_t
>(tVec->Z());
617 template<
typename DataType >
626 template<
typename DataType >
629 tVec->SetXYZ(
static_cast<Double_t
>(X()),
630 static_cast<Double_t
>(Y()),
631 static_cast<Double_t
>(Z()));
636 template<
typename DataType >
641 static_cast<Double_t
>(X()),
642 static_cast<Double_t
>(Y()),
643 static_cast<Double_t
>(Z())
649 template <
typename DataType>
660 B2FATAL(this->name() <<
"::access operator: given index (i=" << i <<
") is out of bounds!");
665 template <
typename DataType>
668 return std::string(
"B2Vector3<") +
typeid(DataType).name() + std::string(
">");
A fast and root compatible alternative to TVector3.
DataType Phi() const
The azimuth angle.
B2Vector3< DataType > operator+(const B2Vector3< DataType > &b) const
Addition of 3-vectors.
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
void SetMag(DataType mag)
Set magnitude keeping theta and phi constant.
DataType Pz() const
access variable Z (= .at(2) without boundary check)
DataType m_coordinates[3]
Make sure that we only have floating point vectors.
B2Vector3(const B2Vector3< DataType > &b2Vec3)
Constructor expecting a B2Vector3 of same type.
B2Vector3< DataType > operator/(DataType a) const
Scaling of 3-vectors with a real number.
DataType & operator()(unsigned i)
member access without boundary check
DataType operator()(unsigned i) const
member access without boundary check
B2Vector3< DataType > operator*(DataType a) const
Scaling of 3-vectors with a real number.
DataType Z() const
access variable Z (= .at(2) 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.
DataType & operator[](unsigned i)
member access without boundary check
void GetXYZ(Float_t *carray) const
directly copies coordinates to an array of float
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
DataType X() const
access variable X (= .at(0) without boundary check)
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
DataType Eta() const
Returns the pseudo-rapidity.
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 Y() const
access variable Y (= .at(1) without boundary check)
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
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.
B2Vector3< DataType > operator-() const
unary minus
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.
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.
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(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
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
void SetZ(DataType z)
set Z/3rd-coordinate
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
B2Vector3< DataType > Orthogonal() const
Vector orthogonal to this one.
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 GetXYZ(Double_t *carray) const
directly copies coordinates to an array of double
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)
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.
std::string PrintStringCyl(unsigned precision=4) const
create a string containing vector in spherical coordinates
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 TVector3 &tVec)
set all coordinates using a reference to TVector3
B2Vector3< DataType > & operator-=(const B2Vector3< DataType > &b)
subtraction
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
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*=(DataType a)
scaling with real numbers
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.
B2Vector3< DataType > operator-(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for substracting a TVector3 from a B2Vector3
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
Abstract base class for different kinds of events.