18#ifndef ROOT_Math_GenVector_VectorUtil
19#define ROOT_Math_GenVector_VectorUtil 1
47 namespace VectorUtil {
60 template <
class Vector1,
class Vector2>
61 inline typename Vector1::Scalar
DeltaPhi(
const Vector1 &
v1,
const Vector2 &
v2) {
62 typename Vector1::Scalar dphi =
v2.Phi() -
v1.Phi();
65 }
else if ( dphi <= -
M_PI ) {
81 template <
class Vector1,
class Vector2>
82 inline 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;
96 template <
class Vector1,
class Vector2>
99 typename Vector1::Scalar drap =
v2.Rapidity() -
v1.Rapidity();
100 return dphi*dphi + drap*drap;
111 template <
class Vector1,
class Vector2>
112 inline typename Vector1::Scalar
DeltaR(
const Vector1 &
v1,
const Vector2 &
v2) {
125 template <
class Vector1,
class Vector2>
141 template <
class Vector1,
class Vector2>
144 double v1_r2 =
v1.X()*
v1.X() +
v1.Y()*
v1.Y() +
v1.Z()*
v1.Z();
145 double v2_r2 =
v2.X()*
v2.X() +
v2.Y()*
v2.Y() +
v2.Z()*
v2.Z();
146 double ptot2 = v1_r2*v2_r2;
150 double pdot =
v1.X()*
v2.X() +
v1.Y()*
v2.Y() +
v1.Z()*
v2.Z();
152 arg = pdot/
sqrt(ptot2);
153 if(arg > 1.0) arg = 1.0;
154 if(arg < -1.0) arg = -1.0;
168 template <
class Vector1,
class Vector2>
169 inline double Angle(
const Vector1 &
v1,
const Vector2 &
v2) {
182 template <
class Vector1,
class Vector2>
184 double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
185 if (magU2 == 0)
return Vector1(0,0,0);
186 double d =
v.Dot(u)/magU2;
187 return Vector1( u.X() *
d, u.Y() *
d, u.Z() *
d);
198 template <
class Vector1,
class Vector2>
199 inline Vector1
PerpVector(
const Vector1 &
v,
const Vector2 & u) {
211 template <
class Vector1,
class Vector2>
212 inline double Perp2(
const Vector1 &
v,
const Vector2 & u) {
213 double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
214 double prjvu =
v.Dot(u);
215 double magV2 =
v.Dot(
v);
216 return magU2 > 0.0 ? magV2-prjvu*prjvu/magU2 : magV2;
227 template <
class Vector1,
class Vector2>
228 inline double Perp(
const Vector1 &
v,
const Vector2 & u) {
247 template <
class Vector1,
class Vector2>
249 typedef typename Vector1::Scalar
Scalar;
254 Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
256 return mm2 < 0.0 ? -
sqrt(-mm2) :
sqrt(mm2);
262 template <
class Vector1,
class Vector2>
264 typedef typename Vector1::Scalar
Scalar;
269 Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
286 template <
class Vector>
289 double sina = sin(alpha);
291 double cosa = cos(alpha);
292 double y2 =
v.Y() * cosa -
v.Z()*sina;
293 double z2 =
v.Z() * cosa +
v.Y() * sina;
295 vrot.SetXYZ(
v.X(),
y2, z2);
305 template <
class Vector>
308 double sina = sin(alpha);
310 double cosa = cos(alpha);
311 double x2 =
v.X() * cosa +
v.Z() * sina;
312 double z2 =
v.Z() * cosa -
v.X() * sina;
314 vrot.SetXYZ(
x2,
v.Y(), z2);
324 template <
class Vector>
327 double sina = sin(alpha);
329 double cosa = cos(alpha);
330 double x2 =
v.X() * cosa -
v.Y() * sina;
331 double y2 =
v.Y() * cosa +
v.X() * sina;
333 vrot.SetXYZ(
x2,
y2,
v.Z());
345 template<
class Vector,
class RotationMatrix>
346 Vector
Rotate(
const Vector &
v,
const RotationMatrix & rot) {
350 double x2 = rot(0,0)*xX + rot(0,1)*yY + rot(0,2)*zZ;
351 double y2 = rot(1,0)*xX + rot(1,1)*yY + rot(1,2)*zZ;
352 double z2 = rot(2,0)*xX + rot(2,1)*yY + rot(2,2)*zZ;
354 vrot.SetXYZ(
x2,
y2,z2);
366 template <
class LVector,
class BoostVector>
367 LVector
boost(
const LVector &
v,
const BoostVector &
b) {
371 double b2 = bx*bx + by*by + bz*bz;
373 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
377 double gamma = 1.0 /
sqrt(1.0 - b2);
378 double bp = bx*
v.X() + by*
v.Y() + bz*
v.Z();
379 double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;
380 double x2 =
v.X() + gamma2*bp*bx + gamma*bx*
v.T();
381 double y2 =
v.Y() + gamma2*bp*by + gamma*by*
v.T();
382 double z2 =
v.Z() + gamma2*bp*bz + gamma*bz*
v.T();
383 double t2 = gamma*(
v.T() + bp);
396 template <
class LVector,
class T>
399 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
404 typename LVector::Scalar
x2 = gamma *
v.X() + gamma *
beta *
v.T();
405 typename LVector::Scalar t2 = gamma *
beta *
v.X() + gamma *
v.T();
408 lv.SetXYZT(
x2,
v.Y(),
v.Z(),t2);
418 template <
class LVector>
421 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
426 double y2 = gamma *
v.Y() + gamma *
beta *
v.T();
427 double t2 = gamma *
beta *
v.Y() + gamma *
v.T();
429 lv.SetXYZT(
v.X(),
y2,
v.Z(),t2);
439 template <
class LVector>
442 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
447 double z2 = gamma *
v.Z() + gamma *
beta *
v.T();
448 double t2 = gamma *
beta *
v.Z() + gamma *
v.T();
450 lv.SetXYZT(
v.X(),
v.Y(),z2,t2);
467 template<
class Matrix,
class CoordSystem,
class U>
471 vret.
SetXYZ(
m(0,0) *
v.x() +
m(0,1) *
v.y() +
m(0,2) *
v.z() ,
472 m(1,0) *
v.x() +
m(1,1) *
v.y() +
m(1,2) *
v.z() ,
473 m(2,0) *
v.x() +
m(2,1) *
v.y() +
m(2,2) *
v.z() );
482 template<
class Matrix,
class CoordSystem,
class U>
486 pret.
SetXYZ(
m(0,0) *
p.x() +
m(0,1) *
p.y() +
m(0,2) *
p.z() ,
487 m(1,0) *
p.x() +
m(1,1) *
p.y() +
m(1,2) *
p.z() ,
488 m(2,0) *
p.x() +
m(2,1) *
p.y() +
m(2,2) *
p.z() );
499 template<
class CoordSystem,
class Matrix>
503 vret.
SetXYZT(
m(0,0)*
v.x() +
m(0,1)*
v.y() +
m(0,2)*
v.z() +
m(0,3)*
v.t() ,
504 m(1,0)*
v.x() +
m(1,1)*
v.y() +
m(1,2)*
v.z() +
m(1,3)*
v.t() ,
505 m(2,0)*
v.x() +
m(2,1)*
v.y() +
m(2,2)*
v.z() +
m(2,3)*
v.t() ,
506 m(3,0)*
v.x() +
m(3,1)*
v.y() +
m(3,2)*
v.z() +
m(3,3)*
v.t() );
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char y2
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 beta(double x, double y)
Calculates the beta function.
Namespace for new Math classes and functions.
void Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed
DisplacementVector3D< CoordSystem, U > Mult(const Matrix &m, const DisplacementVector3D< CoordSystem, U > &v)
Multiplications of a generic matrices with a DisplacementVector3D of any coordinate system.
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...
double Perp(const Vector1 &v, const Vector2 &u)
Find the magnitude of 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...
Vector1::Scalar DeltaRapidityPhi(const Vector1 &v1, const Vector2 &v2)
Find difference in Rapidity (y) and Phi betwen two generic vectors The only requirements on the Vecto...
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...
Vector1::Scalar DeltaPhi(const Vector1 &v1, const Vector2 &v2)
Find aximutal Angle difference between two generic vectors ( v2.Phi() - v1.Phi() ) The only requireme...
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...
double Angle(const Vector1 &v1, const Vector2 &v2)
Find Angle between two vectors.
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 DeltaR2RapidityPhi(const Vector1 &v1, const Vector2 &v2)
Find square of the difference in true rapidity (y) and Phi betwen two generic vectors The only requir...
Vector RotateY(const Vector &v, double alpha)
rotation along Y axis for a generic vector by an Angle alpha returning a new vector.
Vector RotateX(const Vector &v, double alpha)
rotation along X axis for a generic vector by an Angle alpha returning a new vector.
double CosTheta(const Vector1 &v1, const Vector2 &v2)
Find CosTheta Angle between two generic 3D vectors pre-requisite: vectors implement the X(),...
Vector1 PerpVector(const Vector1 &v, const Vector2 &u)
Find the vector component of v perpendicular to the given direction of u.
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.
double Phi_0_2pi(double phi)
Return a phi angle in the interval (0,2*PI].
Vector Rotate(const Vector &v, const RotationMatrix &rot)
rotation on a generic vector using a generic rotation class.
double Phi_mpi_pi(double phi)
Returns phi angle in the interval (-PI,PI].
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.
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...
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 InvariantMass(const Vector1 &v1, const Vector2 &v2)
return the invariant mass of two LorentzVector The only requirement on the LorentzVector is that they...
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Rotation3D::Scalar Scalar
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.