17#ifndef ROOT_MathX_GenVectorX_VectorUtil
18#define ROOT_MathX_GenVectorX_VectorUtil 1
60template <
class Vector1,
class Vector2>
61inline typename Vector1::Scalar
DeltaPhi(
const Vector1 &
v1,
const Vector2 &
v2)
63 typename Vector1::Scalar dphi =
v2.Phi() -
v1.Phi();
66 }
else if (dphi <= -
M_PI) {
80template <
class Vector1,
class Vector2>
81inline typename Vector1::Scalar
DeltaR2(
const Vector1 &
v1,
const Vector2 &
v2)
84 typename Vector1::Scalar deta =
v2.Eta() -
v1.Eta();
85 return dphi * dphi + deta * deta;
96template <
class Vector1,
class Vector2>
100 typename Vector1::Scalar drap =
v2.Rapidity() -
v1.Rapidity();
101 return dphi * dphi + drap * drap;
112template <
class Vector1,
class Vector2>
113inline typename Vector1::Scalar
DeltaR(
const Vector1 &
v1,
const Vector2 &
v2)
126template <
class Vector1,
class Vector2>
142template <
class Vector1,
class Vector2>
146 double v1_r2 =
v1.X() *
v1.X() +
v1.Y() *
v1.Y() +
v1.Z() *
v1.Z();
147 double v2_r2 =
v2.X() *
v2.X() +
v2.Y() *
v2.Y() +
v2.Z() *
v2.Z();
148 double ptot2 = v1_r2 * v2_r2;
152 double pdot =
v1.X() *
v2.X() +
v1.Y() *
v2.Y() +
v1.Z() *
v2.Z();
170template <
class Vector1,
class Vector2>
171inline double Angle(
const Vector1 &
v1,
const Vector2 &
v2)
184template <
class Vector1,
class Vector2>
187 double magU2 = u.X() * u.X() + u.Y() * u.Y() + u.Z() * u.Z();
189 return Vector1(0, 0, 0);
190 double d =
v.Dot(u) / magU2;
191 return Vector1(u.X() *
d, u.Y() *
d, u.Z() *
d);
202template <
class Vector1,
class Vector2>
216template <
class Vector1,
class Vector2>
217inline double Perp2(
const Vector1 &
v,
const Vector2 &u)
219 double magU2 = u.X() * u.X() + u.Y() * u.Y() + u.Z() * u.Z();
220 double prjvu =
v.Dot(u);
221 double magV2 =
v.Dot(
v);
222 return magU2 > 0.0 ? magV2 - prjvu * prjvu / magU2 : magV2;
233template <
class Vector1,
class Vector2>
234inline double Perp(
const Vector1 &
v,
const Vector2 &u)
250template <
class Vector1,
class Vector2>
253 typedef typename Vector1::Scalar
Scalar;
258 Scalar mm2 = ee * ee - xx * xx - yy * yy - zz * zz;
267template <
class Vector1,
class Vector2>
270 typedef typename Vector1::Scalar
Scalar;
275 Scalar mm2 = ee * ee - xx * xx - yy * yy - zz * zz;
291template <
class Vector>
298 double y2 =
v.Y() * cosa -
v.Z() * sina;
299 double z2 =
v.Z() * cosa +
v.Y() * sina;
301 vrot.SetXYZ(
v.X(), y2, z2);
311template <
class Vector>
318 double x2 =
v.X() * cosa +
v.Z() * sina;
319 double z2 =
v.Z() * cosa -
v.X() * sina;
321 vrot.SetXYZ(x2,
v.Y(), z2);
331template <
class Vector>
338 double x2 =
v.X() * cosa -
v.Y() * sina;
339 double y2 =
v.Y() * cosa +
v.X() * sina;
341 vrot.SetXYZ(x2, y2,
v.Z());
351template <
class Vector>
352Vector
Rotate(
const Vector &
v,
double alpha,
const Vector &axis)
356 const double ll =
math_sqrt(axis.X() * axis.X() + axis.Y() * axis.Y() + axis.Z() * axis.Z());
357#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
363 const double dx = axis.X() / ll;
364 const double dy = axis.Y() / ll;
365 const double dz = axis.Z() / ll;
367 const double rot00 = (1 - ca) * dx * dx + ca , rot01 = (1 - ca) * dx * dy - sa * dz, rot02 = (1 - ca) * dx * dz + sa * dy,
368 rot10 = (1 - ca) * dy * dx + sa * dz, rot11 = (1 - ca) * dy * dy + ca , rot12 = (1 - ca) * dy * dz - sa * dx,
369 rot20 = (1 - ca) * dz * dx - sa * dy, rot21 = (1 - ca) * dz * dy + sa * dx, rot22 = (1 - ca) * dz * dz + ca ;
371 const double xX =
v.X();
372 const double yY =
v.Y();
373 const double zZ =
v.Z();
374 const double x2 = rot00 * xX + rot01 * yY + rot02 * zZ;
375 const double y2 = rot10 * xX + rot11 * yY + rot12 * zZ;
376 const double z2 = rot20 * xX + rot21 * yY + rot22 * zZ;
378 vrot.SetXYZ(x2, y2, z2);
389template <
class Vector,
class RotationMatrix>
390Vector
Rotate(
const Vector &
v,
const RotationMatrix &rot)
395 double x2 = rot(0, 0) * xX + rot(0, 1) * yY + rot(0, 2) * zZ;
396 double y2 = rot(1, 0) * xX + rot(1, 1) * yY + rot(1, 2) * zZ;
397 double z2 = rot(2, 0) * xX + rot(2, 1) * yY + rot(2, 2) * zZ;
399 vrot.SetXYZ(x2, y2, z2);
411template <
class LVector,
class BoostVector>
412LVector
boost(
const LVector &
v,
const BoostVector &
b)
417 double b2 = bx * bx + by * by + bz * bz;
419#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
420 GenVector_Throw(
"Beta Vector supplied to set Boost represents speed >= c");
424 double gamma = 1.0 /
math_sqrt(1.0 - b2);
425 double bp = bx *
v.X() + by *
v.Y() + bz *
v.Z();
426 double gamma2 = b2 > 0 ? (gamma - 1.0) / b2 : 0.0;
427 double x2 =
v.X() + gamma2 * bp * bx + gamma * bx *
v.T();
428 double y2 =
v.Y() + gamma2 * bp * by + gamma * by *
v.T();
429 double z2 =
v.Z() + gamma2 * bp * bz + gamma * bz *
v.T();
430 double t2 = gamma * (
v.T() + bp);
432 lv.SetXYZT(x2, y2, z2, t2);
442template <
class LVector,
class T>
446#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
447 GenVector_Throw(
"Beta Vector supplied to set Boost represents speed >= c");
451 T gamma = 1.0 /
math_sqrt(1.0 - beta * beta);
452 typename LVector::Scalar x2 = gamma *
v.X() + gamma * beta *
v.T();
453 typename LVector::Scalar t2 = gamma * beta *
v.X() + gamma *
v.T();
456 lv.SetXYZT(x2,
v.Y(),
v.Z(), t2);
466template <
class LVector>
470#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
471 GenVector_Throw(
"Beta Vector supplied to set Boost represents speed >= c");
475 double gamma = 1.0 /
math_sqrt(1.0 - beta * beta);
476 double y2 = gamma *
v.Y() + gamma * beta *
v.T();
477 double t2 = gamma * beta *
v.Y() + gamma *
v.T();
479 lv.SetXYZT(
v.X(), y2,
v.Z(), t2);
489template <
class LVector>
493#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
494 GenVector_Throw(
"Beta Vector supplied to set Boost represents speed >= c");
498 double gamma = 1.0 /
math_sqrt(1.0 - beta * beta);
499 double z2 = gamma *
v.Z() + gamma * beta *
v.T();
500 double t2 = gamma * beta *
v.Z() + gamma *
v.T();
502 lv.SetXYZT(
v.X(),
v.Y(), z2, t2);
517template <
class Matrix,
class CoordSystem,
class U>
521 vret.
SetXYZ(
m(0, 0) *
v.x() +
m(0, 1) *
v.y() +
m(0, 2) *
v.z(),
m(1, 0) *
v.x() +
m(1, 1) *
v.y() +
m(1, 2) *
v.z(),
522 m(2, 0) *
v.x() +
m(2, 1) *
v.y() +
m(2, 2) *
v.z());
531template <
class Matrix,
class CoordSystem,
class U>
535 pret.
SetXYZ(
m(0, 0) * p.
x() +
m(0, 1) * p.
y() +
m(0, 2) * p.
z(),
m(1, 0) * p.
x() +
m(1, 1) * p.
y() +
m(1, 2) * p.
z(),
536 m(2, 0) * p.
x() +
m(2, 1) * p.
y() +
m(2, 2) * p.
z());
547template <
class CoordSystem,
class Matrix>
551 vret.
SetXYZT(
m(0, 0) *
v.x() +
m(0, 1) *
v.y() +
m(0, 2) *
v.z() +
m(0, 3) *
v.t(),
552 m(1, 0) *
v.x() +
m(1, 1) *
v.y() +
m(1, 2) *
v.z() +
m(1, 3) *
v.t(),
553 m(2, 0) *
v.x() +
m(2, 1) *
v.y() +
m(2, 2) *
v.z() +
m(2, 3) *
v.t(),
554 m(3, 0) *
v.x() +
m(3, 1) *
v.y() +
m(3, 2) *
v.z() +
m(3, 3) *
v.t());
Class describing a generic displacement vector in 3 dimensions.
DisplacementVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
LorentzVector< CoordSystem > & SetXYZT(Scalar xx, Scalar yy, Scalar zz, Scalar tt)
set the values of the vector from the cartesian components (x,y,z,t) (if the vector is held in anothe...
Class describing a generic position vector (point) in 3 dimensions.
double Phi_mpi_pi(double phi)
Returns phi angle in the interval (-PI,PI].
double Perp2(const Vector1 &v, const Vector2 &u)
Find the magnitude square of the vector component of v perpendicular to the given direction of u.
Vector1::Scalar DeltaR2(const Vector1 &v1, const Vector2 &v2)
Find square of the difference in pseudorapidity (Eta) and Phi between two generic vectors The only re...
Vector1 PerpVector(const Vector1 &v, const Vector2 &u)
Find the vector component of v perpendicular to the given direction of u.
double CosTheta(const Vector1 &v1, const Vector2 &v2)
Find CosTheta Angle between two generic 3D vectors pre-requisite: vectors implement the X(),...
LVector boostZ(const LVector &v, double beta)
Boost a generic Lorentz Vector class along the Z direction with a factor beta The only requirement on...
Vector1::Scalar DeltaRapidityPhi(const Vector1 &v1, const Vector2 &v2)
Find difference in Rapidity (y) and Phi between two generic vectors The only requirements on the Vect...
Vector1::Scalar DeltaR(const Vector1 &v1, const Vector2 &v2)
Find difference in pseudorapidity (Eta) and Phi between two generic vectors The only requirements on ...
Vector RotateX(const Vector &v, double alpha)
rotation along X axis for a generic vector by an Angle alpha returning a new vector.
Vector1::Scalar DeltaPhi(const Vector1 &v1, const Vector2 &v2)
Find aximutal Angle difference between two generic vectors ( v2.Phi() - v1.Phi() ) The only requireme...
double Perp(const Vector1 &v, const Vector2 &u)
Find the magnitude of the vector component of v perpendicular to the given direction of u.
DisplacementVector3D< CoordSystem, U > Mult(const Matrix &m, const DisplacementVector3D< CoordSystem, U > &v)
Multiplications of a generic matrices with a DisplacementVector3D of any coordinate system.
double Angle(const Vector1 &v1, const Vector2 &v2)
Find Angle between two vectors.
Vector1::Scalar DeltaR2RapidityPhi(const Vector1 &v1, const Vector2 &v2)
Find square of the difference in true rapidity (y) and Phi between two generic vectors The only requi...
LVector boost(const LVector &v, const BoostVector &b)
Boost a generic Lorentz Vector class using a generic 3D Vector class describing the boost The only re...
Vector Rotate(const Vector &v, double alpha, const Vector &axis)
rotation along a custom axis for a generic vector by an Angle alpha (in rad) returning a new vector.
LVector boostX(const LVector &v, T beta)
Boost a generic Lorentz Vector class along the X direction with a factor beta The only requirement on...
Vector1::Scalar InvariantMass2(const Vector1 &v1, const Vector2 &v2)
Returns the square of what InvariantMass(const Vector1&, const Vector2&) would return.
double Phi_0_2pi(double phi)
Return a phi angle in the interval (0,2*PI].
Vector RotateZ(const Vector &v, double alpha)
rotation along Z axis for a generic vector by an Angle alpha returning a new vector.
Vector1::Scalar InvariantMass(const Vector1 &v1, const Vector2 &v2)
return the invariant mass of two LorentzVector The only requirement on the LorentzVector is that they...
LVector boostY(const LVector &v, double beta)
Boost a generic Lorentz Vector class along the Y direction with a factor beta The only requirement on...
Vector1 ProjVector(const Vector1 &v, const Vector2 &u)
Find the projection of v along the given direction u.
Vector RotateY(const Vector &v, double alpha)
rotation along Y axis for a generic vector by an Angle alpha returning a new vector.
Global Helper functions for generic Vector classes.
Scalar math_cos(Scalar x)
Rotation3D::Scalar Scalar
void GenVector_Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed
Scalar math_sqrt(Scalar x)
Scalar math_acos(Scalar x)
Scalar math_fmod(Scalar x, Scalar y)
Scalar math_sin(Scalar x)