18 #ifndef ROOT_Math_GenVector_VectorUtil
19 #define ROOT_Math_GenVector_VectorUtil 1
45 namespace VectorUtil {
58 template <
class Vector1,
class Vector2>
59 inline typename Vector1::Scalar DeltaPhi(
const Vector1 & v1,
const Vector2 & v2) {
60 typename Vector1::Scalar dphi = v2.Phi() - v1.Phi();
63 }
else if ( dphi <= -M_PI ) {
79 template <
class Vector1,
class Vector2>
80 inline typename Vector1::Scalar DeltaR2(
const Vector1 & v1,
const Vector2 & v2) {
81 typename Vector1::Scalar dphi = DeltaPhi(v1,v2);
82 typename Vector1::Scalar deta = v2.Eta() - v1.Eta();
83 return dphi*dphi + deta*deta;
94 template <
class Vector1,
class Vector2>
95 inline typename Vector1::Scalar DeltaR(
const Vector1 & v1,
const Vector2 & v2) {
96 return std::sqrt( DeltaR2(v1,v2) );
111 template <
class Vector1,
class Vector2>
112 double CosTheta(
const Vector1 & v1,
const Vector2 & v2) {
114 double v1_r2 = v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z();
115 double v2_r2 = v2.X()*v2.X() + v2.Y()*v2.Y() + v2.Z()*v2.Z();
116 double ptot2 = v1_r2*v2_r2;
120 double pdot = v1.X()*v2.X() + v1.Y()*v2.Y() + v1.Z()*v2.Z();
121 arg = pdot/std::sqrt(ptot2);
122 if(arg > 1.0) arg = 1.0;
123 if(arg < -1.0) arg = -1.0;
137 template <
class Vector1,
class Vector2>
138 inline double Angle(
const Vector1 & v1,
const Vector2 & v2) {
139 return std::acos( CosTheta(v1, v2) );
150 template <
class Vector1,
class Vector2>
151 Vector1 ProjVector(
const Vector1 & v,
const Vector2 & u) {
152 double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
153 if (magU2 == 0)
return Vector1(0,0,0);
154 double d = v.Dot(u)/magU2;
155 return Vector1( u.X() * d, u.Y() * d, u.Z() * d);
166 template <
class Vector1,
class Vector2>
167 inline Vector1 PerpVector(
const Vector1 & v,
const Vector2 & u) {
168 return v - ProjVector(v,u);
179 template <
class Vector1,
class Vector2>
180 inline double Perp2(
const Vector1 & v,
const Vector2 & u) {
181 double magU2 = u.X()*u.X() + u.Y()*u.Y() + u.Z()*u.Z();
182 double prjvu = v.Dot(u);
183 double magV2 = v.Dot(v);
184 return magU2 > 0.0 ? magV2-prjvu*prjvu/magU2 : magV2;
195 template <
class Vector1,
class Vector2>
196 inline double Perp(
const Vector1 & v,
const Vector2 & u) {
197 return std::sqrt(Perp2(v,u) );
214 template <
class Vector1,
class Vector2>
215 inline typename Vector1::Scalar InvariantMass(
const Vector1 & v1,
const Vector2 & v2) {
216 typedef typename Vector1::Scalar Scalar;
217 Scalar ee = (v1.E() + v2.E() );
218 Scalar xx = (v1.X() + v2.X() );
219 Scalar yy = (v1.Y() + v2.Y() );
220 Scalar zz = (v1.Z() + v2.Z() );
221 Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
222 return mm2 < 0.0 ? -std::sqrt(-mm2) : std::sqrt(mm2);
228 template <
class Vector1,
class Vector2>
229 inline typename Vector1::Scalar InvariantMass2(
const Vector1 & v1,
const Vector2 & v2) {
230 typedef typename Vector1::Scalar Scalar;
231 Scalar ee = (v1.E() + v2.E() );
232 Scalar xx = (v1.X() + v2.X() );
233 Scalar yy = (v1.Y() + v2.Y() );
234 Scalar zz = (v1.Z() + v2.Z() );
235 Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz;
252 template <
class Vector>
253 Vector RotateX(
const Vector & v,
double alpha) {
254 double sina = sin(alpha);
255 double cosa = cos(alpha);
256 double y2 = v.Y() * cosa - v.Z()*sina;
257 double z2 = v.Z() * cosa + v.Y() * sina;
259 vrot.SetXYZ(v.X(), y2, z2);
269 template <
class Vector>
270 Vector RotateY(
const Vector & v,
double alpha) {
271 double sina = sin(alpha);
272 double cosa = cos(alpha);
273 double x2 = v.X() * cosa + v.Z() * sina;
274 double z2 = v.Z() * cosa - v.X() * sina;
276 vrot.SetXYZ(x2, v.Y(), z2);
286 template <
class Vector>
287 Vector RotateZ(
const Vector & v,
double alpha) {
288 double sina = sin(alpha);
289 double cosa = cos(alpha);
290 double x2 = v.X() * cosa - v.Y() * sina;
291 double y2 = v.Y() * cosa + v.X() * sina;
293 vrot.SetXYZ(x2, y2, v.Z());
305 template<
class Vector,
class RotationMatrix>
306 Vector Rotate(
const Vector &v,
const RotationMatrix & rot) {
310 double x2 = rot(0,0)*xX + rot(0,1)*yY + rot(0,2)*zZ;
311 double y2 = rot(1,0)*xX + rot(1,1)*yY + rot(1,2)*zZ;
312 double z2 = rot(2,0)*xX + rot(2,1)*yY + rot(2,2)*zZ;
314 vrot.SetXYZ(x2,y2,z2);
326 template <
class LVector,
class BoostVector>
327 LVector boost(
const LVector & v,
const BoostVector & b) {
331 double b2 = bx*bx + by*by + bz*bz;
333 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
336 double gamma = 1.0 / std::sqrt(1.0 - b2);
337 double bp = bx*v.X() + by*v.Y() + bz*v.Z();
338 double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;
339 double x2 = v.X() + gamma2*bp*bx + gamma*bx*v.T();
340 double y2 = v.Y() + gamma2*bp*by + gamma*by*v.T();
341 double z2 = v.Z() + gamma2*bp*bz + gamma*bz*v.T();
342 double t2 = gamma*(v.T() + bp);
344 lv.SetXYZT(x2,y2,z2,t2);
355 template <
class LVector,
class T>
356 LVector boostX(
const LVector & v, T beta) {
358 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
361 T gamma = 1.0/ std::sqrt(1.0 - beta*beta);
362 typename LVector::Scalar x2 = gamma * v.X() + gamma * beta * v.T();
363 typename LVector::Scalar t2 = gamma * beta * v.X() + gamma * v.T();
366 lv.SetXYZT(x2,v.Y(),v.Z(),t2);
376 template <
class LVector>
377 LVector boostY(
const LVector & v,
double beta) {
379 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
382 double gamma = 1.0/ std::sqrt(1.0 - beta*beta);
383 double y2 = gamma * v.Y() + gamma * beta * v.T();
384 double t2 = gamma * beta * v.Y() + gamma * v.T();
386 lv.SetXYZT(v.X(),y2,v.Z(),t2);
396 template <
class LVector>
397 LVector boostZ(
const LVector & v,
double beta) {
399 GenVector::Throw (
"Beta Vector supplied to set Boost represents speed >= c");
402 double gamma = 1.0/ std::sqrt(1.0 - beta*beta);
403 double z2 = gamma * v.Z() + gamma * beta * v.T();
404 double t2 = gamma * beta * v.Z() + gamma * v.T();
406 lv.SetXYZT(v.X(),v.Y(),z2,t2);
423 template<
class Matrix,
class CoordSystem,
class U>
425 DisplacementVector3D<CoordSystem,U> Mult (
const Matrix & m,
const DisplacementVector3D<CoordSystem,U> & v) {
426 DisplacementVector3D<CoordSystem,U> vret;
427 vret.SetXYZ( m(0,0) * v.x() + m(0,1) * v.y() + m(0,2) * v.z() ,
428 m(1,0) * v.x() + m(1,1) * v.y() + m(1,2) * v.z() ,
429 m(2,0) * v.x() + m(2,1) * v.y() + m(2,2) * v.z() );
438 template<
class Matrix,
class CoordSystem,
class U>
440 PositionVector3D<CoordSystem,U> Mult (
const Matrix & m,
const PositionVector3D<CoordSystem,U> & p) {
441 DisplacementVector3D<CoordSystem,U> pret;
442 pret.SetXYZ( m(0,0) * p.x() + m(0,1) * p.y() + m(0,2) * p.z() ,
443 m(1,0) * p.x() + m(1,1) * p.y() + m(1,2) * p.z() ,
444 m(2,0) * p.x() + m(2,1) * p.y() + m(2,2) * p.z() );
455 template<
class CoordSystem,
class Matrix>
457 LorentzVector<CoordSystem> Mult (
const Matrix & m,
const LorentzVector<CoordSystem> & v) {
458 LorentzVector<CoordSystem> vret;
459 vret.SetXYZT( m(0,0)*v.x() + m(0,1)*v.y() + m(0,2)*v.z() + m(0,3)* v.t() ,
460 m(1,0)*v.x() + m(1,1)*v.y() + m(1,2)*v.z() + m(1,3)* v.t() ,
461 m(2,0)*v.x() + m(2,1)*v.y() + m(2,2)*v.z() + m(2,3)* v.t() ,
462 m(3,0)*v.x() + m(3,1)*v.y() + m(3,2)*v.z() + m(3,3)* v.t() );
474 double Phi_0_2pi(
double phi);
478 double Phi_mpi_pi(
double phi);