18 #ifndef ROOT_Math_GenVector_VectorUtil
19 #define ROOT_Math_GenVector_VectorUtil 1
21 #ifndef ROOT_Math_Math
47 namespace VectorUtil {
60 template <
class Vector1,
class Vector2>
65 }
else if ( dphi <= -
M_PI ) {
81 template <
class Vector1,
class Vector2>
85 return dphi*dphi + deta*deta;
96 template <
class Vector1,
class Vector2>
113 template <
class Vector1,
class Vector2>
116 double v1_r2 = v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z();
117 double v2_r2 = v2.X()*v2.X() + v2.Y()*v2.Y() + v2.Z()*v2.Z();
118 double ptot2 = v1_r2*v2_r2;
122 double pdot = v1.X()*v2.X() + v1.Y()*v2.Y() + v1.Z()*v2.Z();
124 if(arg > 1.0) arg = 1.0;
125 if(arg < -1.0) arg = -1.0;
139 template <
class Vector1,
class Vector2>
140 inline double Angle(
const Vector1 &
v1,
const Vector2 & v2) {
152 template <
class Vector1,
class Vector2>
154 double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
155 if (magU2 == 0)
return Vector1(0,0,0);
156 double d = v.Dot(u)/magU2;
157 return Vector1( u.X() * d, u.Y() * d, u.Z() * d);
168 template <
class Vector1,
class Vector2>
169 inline Vector1
PerpVector(
const Vector1 &
v,
const Vector2 & u) {
181 template <
class Vector1,
class Vector2>
182 inline double Perp2(
const Vector1 &
v,
const Vector2 & u) {
183 double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
184 double prjvu = v.Dot(u);
185 double magV2 = v.Dot(v);
186 return magU2 > 0.0 ? magV2-prjvu*prjvu/magU2 : magV2;
197 template <
class Vector1,
class Vector2>
198 inline double Perp(
const Vector1 &
v,
const Vector2 & u) {
216 template <
class Vector1,
class Vector2>
219 Scalar ee = (v1.E() + v2.E() );
220 Scalar xx = (v1.X() + v2.X() );
221 Scalar yy = (v1.Y() + v2.Y() );
222 Scalar zz = (v1.Z() + v2.Z() );
223 Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
230 template <
class Vector1,
class Vector2>
233 Scalar ee = (v1.E() + v2.E() );
234 Scalar xx = (v1.X() + v2.X() );
235 Scalar yy = (v1.Y() + v2.Y() );
236 Scalar zz = (v1.Z() + v2.Z() );
237 Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
254 template <
class Vector>
256 double sina =
sin(alpha);
257 double cosa =
cos(alpha);
258 double y2 = v.Y() * cosa - v.Z()*sina;
259 double z2 = v.Z() * cosa + v.Y() * sina;
261 vrot.SetXYZ(v.X(), y2, z2);
271 template <
class Vector>
273 double sina =
sin(alpha);
274 double cosa =
cos(alpha);
275 double x2 = v.X() * cosa + v.Z() * sina;
276 double z2 = v.Z() * cosa - v.X() * sina;
278 vrot.SetXYZ(x2, v.Y(), z2);
288 template <
class Vector>
290 double sina =
sin(alpha);
291 double cosa =
cos(alpha);
292 double x2 = v.X() * cosa - v.Y() * sina;
293 double y2 = v.Y() * cosa + v.X() * sina;
295 vrot.SetXYZ(x2, y2, v.Z());
307 template<
class Vector,
class RotationMatrix>
308 Vector
Rotate(
const Vector &
v,
const RotationMatrix & rot) {
312 double x2 = rot(0,0)*xX + rot(0,1)*yY + rot(0,2)*zZ;
313 double y2 = rot(1,0)*xX + rot(1,1)*yY + rot(1,2)*zZ;
314 double z2 = rot(2,0)*xX + rot(2,1)*yY + rot(2,2)*zZ;
316 vrot.SetXYZ(x2,y2,z2);
328 template <
class LVector,
class BoostVector>
329 LVector
boost(
const LVector &
v,
const BoostVector & b) {
333 double b2 = bx*bx + by*by + bz*bz;
335 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
339 double bp = bx*v.X() + by*v.Y() + bz*v.Z();
340 double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;
341 double x2 = v.X() + gamma2*bp*bx + gamma*bx*v.T();
342 double y2 = v.Y() + gamma2*bp*by + gamma*by*v.T();
343 double z2 = v.Z() + gamma2*bp*bz + gamma*bz*v.T();
344 double t2 = gamma*(v.T() + bp);
346 lv.SetXYZT(x2,y2,z2,t2);
357 template <
class LVector,
class T>
360 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
368 lv.SetXYZT(x2,v.Y(),v.Z(),t2);
378 template <
class LVector>
381 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
385 double y2 = gamma * v.Y() + gamma * beta * v.T();
386 double t2 = gamma * beta * v.Y() + gamma * v.T();
388 lv.SetXYZT(v.X(),y2,v.Z(),t2);
398 template <
class LVector>
401 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
405 double z2 = gamma * v.Z() + gamma * beta * v.T();
406 double t2 = gamma * beta * v.Z() + gamma * v.T();
408 lv.SetXYZT(v.X(),v.Y(),z2,t2);
425 template<
class Matrix,
class CoordSystem,
class U>
429 vret.
SetXYZ(
m(0,0) * v.
x() +
m(0,1) * v.
y() +
m(0,2) * v.
z() ,
430 m(1,0) * v.
x() +
m(1,1) * v.
y() +
m(1,2) * v.
z() ,
431 m(2,0) * v.
x() +
m(2,1) * v.
y() +
m(2,2) * v.
z() );
440 template<
class Matrix,
class CoordSystem,
class U>
444 pret.
SetXYZ(
m(0,0) * p.
x() +
m(0,1) * p.
y() +
m(0,2) * p.
z() ,
445 m(1,0) * p.
x() +
m(1,1) * p.
y() +
m(1,2) * p.
z() ,
446 m(2,0) * p.
x() +
m(2,1) * p.
y() +
m(2,2) * p.
z() );
457 template<
class CoordSystem,
class Matrix>
461 vret.
SetXYZT(
m(0,0)*v.
x() +
m(0,1)*v.
y() +
m(0,2)*v.
z() +
m(0,3)* v.
t() ,
462 m(1,0)*v.
x() +
m(1,1)*v.
y() +
m(1,2)*v.
z() +
m(1,3)* v.
t() ,
463 m(2,0)*v.
x() +
m(2,1)*v.
y() +
m(2,2)*v.
z() +
m(2,3)* v.
t() ,
464 m(3,0)*v.
x() +
m(3,1)*v.
y() +
m(3,2)*v.
z() +
m(3,3)* v.
t() );
double Phi_0_2pi(double phi)
Return a phi angle in the interval (0,2*PI].
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
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...
Namespace for new ROOT classes and functions.
Vector1::Scalar DeltaR2(const Vector1 &v1, const Vector2 &v2)
Find square of the difference in pseudorapidity (Eta) and Phi betwen two generic vectors The only req...
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)
Vector1 ProjVector(const Vector1 &v, const Vector2 &u)
Find the projection of v along the given direction u.
Class describing a generic position vector (point) in 3 dimensions.
Vector RotateX(const Vector &v, double alpha)
rotation along X axis for a generic vector by an Angle alpha returning a new vector.
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...
double beta(double x, double y)
Calculates the beta function.
static const double x2[5]
Vector1::Scalar DeltaR(const Vector1 &v1, const Vector2 &v2)
Find difference in pseudorapidity (Eta) and Phi betwen two generic vectors The only requirements on t...
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 InvariantMass(const Vector1 &v1, const Vector2 &v2)
return the invariant mass of two LorentzVector The only requirement on the LorentzVector is that they...
Vector RotateZ(const Vector &v, double alpha)
rotation along Z axis for a generic vector by an Angle alpha returning a new vector.
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...
Class describing a generic displacement vector in 3 dimensions.
Vector1::Scalar DeltaPhi(const Vector1 &v1, const Vector2 &v2)
Find aximutal Angle difference between two generic vectors ( v2.Phi() - v1.Phi() ) The only requireme...
void Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed ...
double Angle(const Vector1 &v1, const Vector2 &v2)
Find Angle between two vectors.
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 RotateY(const Vector &v, double alpha)
rotation along Y axis for a generic vector by an Angle alpha returning a new vector.
double Phi_mpi_pi(double phi)
Returns phi angle in the interval (-PI,PI].
Vector Rotate(const Vector &v, const RotationMatrix &rot)
rotation on a generic vector using a generic rotation class.
DisplacementVector3D< CoordSystem, U > Mult(const Matrix &m, const DisplacementVector3D< CoordSystem, U > &v)
Multiplications of a generic matrices with a DisplacementVector3D of any coordinate system...
Namespace for new Math classes and functions.
Vector1 PerpVector(const Vector1 &v, const Vector2 &u)
Find the vector component of v perpendicular to the given direction of u.
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...
double Perp(const Vector1 &v, const Vector2 &u)
Find the magnitude of 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()...