 |
Belle II Software
release-05-02-19
|
16 #include <framework/logging/Logger.h>
44 template<
typename DataType>
48 static_assert(std::is_floating_point<DataType>::value,
"B2Vector3 only works with floating point types");
56 B2Vector3(
void) :
m_coordinates {
static_cast<DataType
>(0),
static_cast<DataType
>(0),
static_cast<DataType
>(0)} {};
62 explicit B2Vector3(
const DataType(* coords)[3]):
m_coordinates {(*coords)[0], (*coords)[1], (*coords)[2]} {};
65 B2Vector3(
const TVector3& tVec3):
m_coordinates {
static_cast<DataType
>(tVec3.X()),
static_cast<DataType
>(tVec3.Y()),
static_cast<DataType
>(tVec3.Z())} {};
68 B2Vector3(
const TVector3* tVec3):
m_coordinates {
static_cast<DataType
>(tVec3->X()),
static_cast<DataType
>(tVec3->Y()),
static_cast<DataType
>(tVec3->Z())} {};
76 m_coordinates {
static_cast<DataType
>(b2Vec3.X()),
static_cast<DataType
>(b2Vec3.Y()),
static_cast<DataType
>(b2Vec3.Z())} {};
79 m_coordinates {
static_cast<DataType
>(b2Vec3->X()),
static_cast<DataType
>(b2Vec3->Y()),
static_cast<DataType
>(b2Vec3->Z())} {};
101 bool operator == (
const TVector3& b)
const {
return X() == b.X() &&
Y() == b.Y() &&
Z() == b.Z(); }
103 bool operator != (
const B2Vector3<DataType>& b)
const {
return !(*
this == b); }
105 bool operator != (
const TVector3& b)
const {
return !(*
this == b); }
121 B2Vector3<DataType>
operator - (
const B2Vector3<DataType>& b)
const
123 return B2Vector3<DataType>(
X() - b.X(),
Y() - b.Y(),
Z() - b.Z());
140 DataType
Phi()
const {
return X() == 0 &&
Y() == 0 ? 0 : atan2(
Y(),
X()); }
142 DataType
Theta()
const {
return X() == 0 &&
Y() == 0 &&
Z() == 0 ? 0 : atan2(
Perp(),
Z()); }
144 DataType
CosTheta()
const {
const double pTot =
Mag();
return pTot == 0 ? 1 :
Z() / pTot; }
146 DataType
Mag2()
const {
return X() *
X() +
Y() *
Y() +
Z() *
Z(); }
148 DataType
Mag()
const {
return std::hypot((
double)
Perp(), (
double)
Z()); }
153 const double perp =
Perp();
155 SetY(perp * sin((
double)phi));
162 const double ph =
Phi();
163 const double ctheta = std::cos((
double) theta);
164 const double stheta = std::sin((
double) theta);
165 SetX(ma * stheta * std::cos(ph));
166 SetY(ma * stheta * std::cos(ph));
173 double factor =
Mag();
175 B2WARNING(
name() <<
"::SetMag: zero vector can't be stretched");
177 factor = mag / factor;
185 DataType
Perp2()
const {
return X() *
X() +
Y() *
Y(); }
187 DataType
Pt()
const {
return Perp(); }
189 DataType
Perp()
const {
return std::hypot((
double)
X(), (
double)
Y()); }
194 const double p =
Perp();
204 const double tot = axis.Mag2();
205 const double ss =
Dot(axis);
207 if (tot > 0.0) per -= ss * ss / tot;
208 if (per < 0) per = 0;
215 DataType
Perp(
const B2Vector3<DataType>& axis)
const {
return std::sqrt(
Perp2(axis)); }
217 DataType
DeltaPhi(
const B2Vector3<DataType>& v)
const {
return Mpi_pi(
Phi() - v.Phi()); }
221 static DataType
Mpi_pi(DataType angle)
223 if (std::isnan(angle)) {
224 B2ERROR(
name() <<
"::Mpi_pi: function called with NaN");
227 angle = std::remainder(angle, 2 * M_PI);
229 if (angle == M_PI) angle = -M_PI;
236 const double deta =
Eta() - v.Eta();
238 return std::hypot(deta, dphi);
242 DataType
DrEtaPhi(
const B2Vector3<DataType>& v)
const
250 const double amag = std::abs(mag);
251 const double sinTheta = std::sin((
double)theta);
260 const double tot =
Mag2();
262 return tot > 0.0 ? p *= (1.0 / std::sqrt(tot)) : p;
268 const double xVal = std::abs((
double)
X());
269 const double yVal = std::abs((
double)
Y());
270 const double zVal = std::abs((
double)
Z());
272 return xVal < zVal ? B2Vector3<DataType>(0,
Z(), -
Y()) :
B2Vector3<DataType>(
Y(), -
X(), 0);
274 return yVal < zVal ? B2Vector3<DataType>(-
Z(), 0,
X()) :
B2Vector3<DataType>(
Y(), -
X(), 0);
281 return X() * p.X() +
Y() * p.Y() +
Z() * p.Z();
285 B2Vector3<DataType>
Cross(
const B2Vector3<DataType>& p)
const
287 return B2Vector3<DataType>(
Y() * p.Z() - p.Y() *
Z(),
Z() * p.X() - p.Z() *
X(),
X() * p.Y() - p.X() *
Y());
293 const double ptot2 =
Mag2() * q.Mag2();
297 double arg =
Dot(q) / std::sqrt(ptot2);
298 if (arg > 1.0) arg = 1.0;
299 if (arg < -1.0) arg = -1.0;
300 return std::acos(arg);
311 if (std::abs(cosTheta) < 1)
return -0.5 * std::log((1.0 - cosTheta) / (1.0 + cosTheta));
312 if (
Z() == 0)
return 0;
314 if (
Z() > 0)
return 10e10;
327 const double s = std::sin((
double)angle);
328 const double c = std::cos((
double)angle);
329 const double yOld =
Y();
339 const double s = std::sin((
double)angle);
340 const double c = std::cos((
double)angle);
341 const double zOld =
Z();
351 const double s = std::sin((
double)angle);
352 const double c = std::cos((
double)angle);
353 const double xOld =
X();
363 const double u1 = NewUzVector.X();
364 const double u2 = NewUzVector.Y();
365 const double u3 = NewUzVector.Z();
366 double up = u1 * u1 + u2 * u2;
370 DataType px =
X(), py =
Y(), pz =
Z();
371 m_coordinates[0] = (u1 * u3 * px - u2 * py + u1 * up * pz) / up;
372 m_coordinates[1] = (u2 * u3 * px + u1 * py + u2 * up * pz) / up;
374 }
else if (u3 < 0.) {
388 void Rotate(DataType alpha,
const B2Vector3<DataType>& v)
390 B2Vector3<DataType> n = v.Unit();
391 *
this = (n * (n.Dot(*
this)) + cos(alpha) * ((n.Cross(*
this)).
Cross(n)) + sin(alpha) * (n.Cross(*
this)));
412 DataType
at(
unsigned i)
const;
420 DataType
X()
const {
return x(); }
422 DataType
Y()
const {
return y(); }
424 DataType
Z()
const {
return z(); }
426 DataType
Px()
const {
return x(); }
428 DataType
Py()
const {
return y(); }
430 DataType
Pz()
const {
return z(); }
433 void GetXYZ(Double_t* carray)
const;
435 void GetXYZ(Float_t* carray)
const;
437 void GetXYZ(TVector3* tVec)
const;
449 void SetXYZ(DataType
x, DataType
y, DataType
z)
462 std::string
PrintString(
unsigned precision = 4)
const
470 std::ostringstream output;
471 output <<
"(x,y,z)=("
472 << std::fixed << std::setprecision(precision)
473 <<
X() <<
"," <<
Y() <<
"," <<
Z() <<
")";
480 std::ostringstream output;
481 output <<
"(rho, theta, phi)=("
482 << std::fixed << std::setprecision(precision)
483 <<
Mag() <<
"," <<
Theta() * 180. / M_PI <<
"," <<
Phi() * 180. / M_PI <<
")";
503 template <
typename DataType>
506 return (a.X() == b.X() && a.Y() == b.Y() && a.Z() == b.Z());
510 template <
typename DataType>
517 template <
typename DataType>
518 B2Vector3<DataType>
operator * (DataType a,
const B2Vector3<DataType>& p)
520 return B2Vector3<DataType>(a * p.X(), a * p.Y(), a * p.Z());
524 template <
typename DataType>
525 B2Vector3<DataType>
operator + (
const TVector3& a,
const B2Vector3<DataType>& b)
527 return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
531 template <
typename DataType>
532 B2Vector3<DataType>
operator - (
const TVector3& a,
const B2Vector3<DataType>& b)
534 return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
538 template <
typename DataType>
539 B2Vector3<DataType>
operator + (
const B2Vector3<DataType>& a,
const TVector3& b)
541 return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
545 template <
typename DataType>
546 B2Vector3<DataType>
operator - (
const B2Vector3<DataType>& a,
const TVector3& b)
548 return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
553 template<
typename DataType >
556 m_coordinates[0] = b.X();
557 m_coordinates[1] = b.Y();
558 m_coordinates[2] = b.Z();
563 template<
typename DataType >
566 m_coordinates[0] = b.X();
567 m_coordinates[1] = b.Y();
568 m_coordinates[2] = b.Z();
573 template<
typename DataType >
576 m_coordinates[0] += b.X();
577 m_coordinates[1] += b.Y();
578 m_coordinates[2] += b.Z();
584 template<
typename DataType >
587 m_coordinates[0] -= b.X();
588 m_coordinates[1] -= b.Y();
589 m_coordinates[2] -= b.Z();
594 template<
typename DataType >
597 m_coordinates[0] *= a;
598 m_coordinates[1] *= a;
599 m_coordinates[2] *= a;
604 template<
typename DataType >
607 m_coordinates[0] =
static_cast<Double_t
>(tVec.X());
608 m_coordinates[1] =
static_cast<Double_t
>(tVec.Y());
609 m_coordinates[2] =
static_cast<Double_t
>(tVec.Z());
613 template<
typename DataType >
616 m_coordinates[0] =
static_cast<Double_t
>(tVec->X());
617 m_coordinates[1] =
static_cast<Double_t
>(tVec->Y());
618 m_coordinates[2] =
static_cast<Double_t
>(tVec->Z());
621 template<
typename DataType >
630 template<
typename DataType >
633 tVec->SetXYZ(
static_cast<Double_t
>(X()),
634 static_cast<Double_t
>(Y()),
635 static_cast<Double_t
>(Z()));
640 template<
typename DataType >
645 static_cast<Double_t
>(X()),
646 static_cast<Double_t
>(Y()),
647 static_cast<Double_t
>(Z())
653 template <
typename DataType>
664 B2FATAL(this->name() <<
"::access operator: given index (i=" << i <<
") is out of bounds!");
669 template <
typename DataType>
672 return std::string(
"B2Vector3<") +
typeid(DataType).name() + std::string(
">");
std::string PrintStringCyl(unsigned precision=4) const
create a string containing vector in spherical coordinates
DataType value_type
storage type of the vector
DataType operator[](unsigned i) const
member access without boundary check
B2Vector3< DataType > operator/(DataType a) const
Scaling of 3-vectors with a real number.
B2Vector3< DataType > & operator-=(const B2Vector3< DataType > &b)
subtraction
DataType Py() const
access variable Y (= .at(1) without boundary check)
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
static std::string name()
Returns the name of the B2Vector.
B2Vector3(const DataType xVal, const DataType yVal, const DataType zVal)
Constructor expecting 3 coordinates.
void SetMag(DataType mag)
Set magnitude keeping theta and phi constant.
bool operator!=(const B2Vector3< DataType > &b) const
Comparison != with a B2Vector3.
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< DataType > & operator=(const B2Vector3< DataType > &b)
Assignment via B2Vector3.
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 ...
DataType Eta() const
Returns the pseudo-rapidity.
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
bool operator!=(const DecayNode &node1, const DecayNode &node2)
Not equal: See operator==.
DataType x() const
access variable X (= .at(0) without boundary check)
DataType DeltaPhi(const B2Vector3< DataType > &v) const
returns phi in the interval [-PI,PI)
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
B2Vector3< DataType > operator+(const B2Vector3< DataType > &b) const
Addition of 3-vectors.
B2Vector3(const TVector3 *tVec3)
Constructor expecting a pointer to a TVector3.
std::string PrintString(unsigned precision=4) const
create a string containing vector in cartesian and spherical coordinates
B2Vector3< DataType > & operator+=(const B2Vector3< DataType > &b)
addition
B2Vector3< DataType > & operator*=(DataType a)
scaling with real numbers
B2Vector3< DataType > Orthogonal() const
Vector orthogonal to this one.
DataType Pz() const
access variable Z (= .at(2) without boundary check)
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
void GetXYZ(Double_t *carray) const
directly copies coordinates to an array of double
DataType DeltaR(const B2Vector3< DataType > &v) const
return deltaR with respect to input-vector
DataType Z() const
access variable Z (= .at(2) without boundary check)
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
void SetY(DataType y)
set Y/2nd-coordinate
void RotateUz(const B2Vector3< DataType > &NewUzVector)
Rotates reference frame from Uz to newUz (unit vector).
A fast and root compatible alternative to TVector3.
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 Dot(const B2Vector3< DataType > &p) const
Scalar product.
void Print()
just for backward compatibility, should not be used with new code
DataType Phi() const
The azimuth angle.
void SetTheta(DataType theta)
Set theta keeping mag and phi constant.
B2Vector3< double > B2Vector3D
typedef for common usage with double
B2Vector3(const DataType(*coords)[3])
Constructor using a pointer.
DataType PseudoRapidity() const
Returns the pseudo-rapidity, i.e.
Abstract base class for different kinds of events.
B2Vector3(void)
empty Constructor sets everything to 0
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
void Sqrt()
calculates the square root of the absolute values of the coordinates element-wise
void SetPerp(DataType r)
Set the transverse component keeping phi and z constant.
TVector3 GetTVector3() const
returns a TVector3 containing the same coordinates
void RotateX(DataType angle)
Rotates the B2Vector3 around the x-axis.
DataType y() const
access variable Y (= .at(1) without boundary check)
void SetMagThetaPhi(DataType mag, DataType theta, DataType phi)
setter with mag, theta, phi
B2Vector3< DataType > operator-() const
unary minus
static DataType Mpi_pi(DataType angle)
returns given angle in the interval [-PI,PI)
DataType Px() const
access variable X (= .at(0) without boundary check)
DataType CosTheta() const
Cosine of the polar angle.
DataType Perp2() const
The transverse component squared (R^2 in cylindrical coordinate system).
DataType z() const
access variable Z (= .at(2) without boundary check)
DataType Mag2() const
The magnitude squared (rho^2 in spherical coordinate system).
B2Vector3(const DataType(&coords)[3])
Constructor using a reference.
DataType DrEtaPhi(const B2Vector3< DataType > &v) const
return DrEtaPhi with respect to input-vector
void RotateZ(DataType angle)
Rotates the B2Vector3 around the z-axis.
void RotateY(DataType angle)
Rotates the B2Vector3 around the y-axis.
DataType at(unsigned i) const
safe member access (with boundary check!)
B2Vector3(const TVector3 &tVec3)
Constructor expecting a TVector3.
DataType X() const
access variable X (= .at(0) without boundary check)
B2Vector3< float > B2Vector3F
typedef for common usage with float
bool operator==(const B2Vector3< DataType > &b) const
Comparison for equality with a B2Vector3.
void SetXYZ(DataType x, DataType y, DataType z)
set all coordinates using data type
DataType Pt() const
The transverse component (R in cylindrical coordinate system).
DataType Theta() const
The polar angle.
void Abs()
calculates the absolute value of the coordinates element-wise
DataType Mag() const
The magnitude (rho in spherical coordinate system).
DataType m_coordinates[3]
Make sure that we only have floating point vectors.
void SetZ(DataType z)
set Z/3rd-coordinate
DataType Y() const
access variable Y (= .at(1) without boundary check)
void SetX(DataType x)
set X/1st-coordinate