Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:40

0001 // -*- C++ -*-
0002 // CLASSDOC OFF
0003 // $Id: LorentzVector.h,v 1.2 2003/10/23 21:29:52 garren Exp $
0004 // ---------------------------------------------------------------------------
0005 // CLASSDOC ON
0006 //
0007 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
0008 //
0009 // HepLorentzVector is a Lorentz vector consisting of Hep3Vector and
0010 // double components. Lorentz transformations (rotations and boosts)
0011 // of these vectors are perfomed by multiplying with objects of
0012 // the HepLorenzRotation class.
0013 //
0014 // .SS See Also
0015 // ThreeVector.h, Rotation.h, LorentzRotation.h
0016 //
0017 // .SS Authors
0018 // Leif Lonnblad and Anders Nilsson. Modified by Evgueni Tcherniaev, Mark Fischler
0019 //
0020 
0021 #ifndef HEP_LORENTZVECTOR_H
0022 #define HEP_LORENTZVECTOR_H
0023 
0024 #include <iostream>
0025 #include "CLHEP/Vector/defs.h" 
0026 #include "CLHEP/Vector/ThreeVector.h"
0027 
0028 namespace CLHEP {
0029 
0030 // Declarations of classes and global methods
0031 class HepLorentzVector;
0032 class HepLorentzRotation;
0033 class HepRotation;
0034 class HepAxisAngle;
0035 class HepEulerAngles;
0036 class Tcomponent;
0037 HepLorentzVector rotationXOf( const HepLorentzVector & vec, double delta );
0038 HepLorentzVector rotationYOf( const HepLorentzVector & vec, double delta );
0039 HepLorentzVector rotationZOf( const HepLorentzVector & vec, double delta );
0040 HepLorentzVector rotationOf
0041     ( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
0042 HepLorentzVector rotationOf
0043     ( const HepLorentzVector & vec, const HepAxisAngle & ax );
0044 HepLorentzVector rotationOf
0045     ( const HepLorentzVector & vec, const HepEulerAngles & e1 );
0046 HepLorentzVector rotationOf
0047     ( const HepLorentzVector & vec, double phi,
0048                                     double theta,
0049                                     double psi );
0050 inline 
0051 HepLorentzVector  boostXOf( const HepLorentzVector & vec, double beta );
0052 inline 
0053 HepLorentzVector  boostYOf( const HepLorentzVector & vec, double beta );
0054 inline 
0055 HepLorentzVector  boostZOf( const HepLorentzVector & vec, double beta );
0056 inline HepLorentzVector  boostOf
0057     ( const HepLorentzVector & vec, const Hep3Vector & betaVector );
0058 inline HepLorentzVector  boostOf
0059     ( const HepLorentzVector & vec, const Hep3Vector & axis,  double beta );
0060 
0061 enum ZMpvMetric_t { TimePositive, TimeNegative };
0062 
0063 
0064 /**
0065  * @author
0066  * @ingroup vector
0067  */
0068 class HepLorentzVector {
0069 
0070 public:
0071 
0072   enum { X=0, Y=1, Z=2, T=3, NUM_COORDINATES=4, SIZE=NUM_COORDINATES };
0073   // Safe indexing of the coordinates when using with matrices, arrays, etc.
0074   // (BaBar)
0075 
0076   inline HepLorentzVector(double x, double y,
0077               double z, double t);
0078   // Constructor giving the components x, y, z, t.
0079 
0080   inline HepLorentzVector(double x, double y, double z);
0081   // Constructor giving the components x, y, z with t-component set to 0.0.
0082 
0083   explicit HepLorentzVector(double t);
0084   // Constructor giving the t-component with x, y and z set to 0.0.
0085 
0086   inline HepLorentzVector();
0087   // Default constructor with x, y, z and t set to 0.0.
0088 
0089   inline HepLorentzVector(const Hep3Vector & p, double e);
0090   inline HepLorentzVector(double e, const Hep3Vector & p);
0091   // Constructor giving a 3-Vector and a time component.
0092 
0093   inline HepLorentzVector(const HepLorentzVector &);
0094   inline HepLorentzVector(HepLorentzVector &&) = default;
0095   // Copy and move constructors.
0096 
0097   inline ~HepLorentzVector();
0098   // The destructor.
0099 
0100   inline operator const Hep3Vector & () const;
0101   inline operator Hep3Vector & ();
0102   // Conversion (cast) to Hep3Vector.
0103 
0104   inline double x() const;
0105   inline double y() const;
0106   inline double z() const;
0107   inline double t() const;
0108   // Get position and time.
0109 
0110   inline void setX(double);
0111   inline void setY(double);
0112   inline void setZ(double);
0113   inline void setT(double);
0114   // Set position and time.
0115 
0116   inline double px() const;
0117   inline double py() const;
0118   inline double pz() const;
0119   inline double e() const;
0120   // Get momentum and energy.
0121 
0122   inline void setPx(double);
0123   inline void setPy(double);
0124   inline void setPz(double);
0125   inline void setE(double);
0126   // Set momentum and energy.
0127 
0128   inline Hep3Vector vect() const;
0129   // Get spatial component. 
0130 
0131   inline void setVect(const Hep3Vector &);
0132   // Set spatial component. 
0133 
0134   inline double theta() const;
0135   inline double cosTheta() const;
0136   inline double phi() const;
0137   inline double rho() const;
0138   // Get spatial vector components in spherical coordinate system.
0139 
0140   inline void setTheta(double);
0141   inline void setPhi(double);
0142   inline void setRho(double);
0143   // Set spatial vector components in spherical coordinate system.
0144 
0145   double operator () (int) const;
0146   inline double operator [] (int) const;
0147   // Get components by index.
0148 
0149   double & operator () (int);
0150   inline double & operator [] (int);
0151   // Set components by index.
0152 
0153   inline HepLorentzVector & operator = (const HepLorentzVector &);
0154   inline HepLorentzVector & operator = (HepLorentzVector &&) = default;
0155   // Copy and move assignment operators. 
0156 
0157   inline HepLorentzVector   operator +  (const HepLorentzVector &) const;
0158   inline HepLorentzVector & operator += (const HepLorentzVector &);
0159   // Additions.
0160 
0161   inline HepLorentzVector   operator -  (const HepLorentzVector &) const;
0162   inline HepLorentzVector & operator -= (const HepLorentzVector &);
0163   // Subtractions.
0164 
0165   inline HepLorentzVector operator - () const;
0166   // Unary minus.
0167 
0168   inline HepLorentzVector & operator *= (double);
0169          HepLorentzVector & operator /= (double);
0170   // Scaling with real numbers.
0171 
0172   inline bool operator == (const HepLorentzVector &) const;
0173   inline bool operator != (const HepLorentzVector &) const;
0174   // Comparisons.
0175 
0176   inline double perp2() const;
0177   // Transverse component of the spatial vector squared.
0178 
0179   inline double perp() const;
0180   // Transverse component of the spatial vector (R in cylindrical system).
0181 
0182   inline void setPerp(double);
0183   // Set the transverse component of the spatial vector.
0184 
0185   inline double perp2(const Hep3Vector &) const;
0186   // Transverse component of the spatial vector w.r.t. given axis squared.
0187 
0188   inline double perp(const Hep3Vector &) const;
0189   // Transverse component of the spatial vector w.r.t. given axis.
0190 
0191   inline double angle(const Hep3Vector &) const;
0192   // Angle wrt. another vector.
0193 
0194   inline double mag2() const;
0195   // Dot product of 4-vector with itself. 
0196   // By default the metric is TimePositive, and mag2() is the same as m2().
0197 
0198   inline double m2() const;
0199   // Invariant mass squared.
0200 
0201   inline double mag() const;
0202   inline double m() const;
0203   // Invariant mass. If m2() is negative then -sqrt(-m2()) is returned.
0204 
0205   inline double mt2() const;
0206   // Transverse mass squared.
0207 
0208   inline double mt() const;
0209   // Transverse mass.
0210 
0211   inline double et2() const;
0212   // Transverse energy squared.
0213 
0214   inline double et() const;
0215   // Transverse energy.
0216 
0217   inline double dot(const HepLorentzVector &) const;
0218   inline double operator * (const HepLorentzVector &) const;
0219   // Scalar product.
0220 
0221   inline double invariantMass2( const HepLorentzVector & w ) const;
0222   // Invariant mass squared of pair of 4-vectors 
0223 
0224   double invariantMass ( const HepLorentzVector & w ) const;
0225   // Invariant mass of pair of 4-vectors 
0226 
0227   inline void setVectMag(const Hep3Vector & spatial, double magnitude);
0228   inline void setVectM(const Hep3Vector & spatial, double mass);
0229   // Copy spatial coordinates, and set energy = sqrt(mass^2 + spatial^2)
0230 
0231   inline double plus() const;
0232   inline double minus() const;
0233   // Returns the positive/negative light-cone component t +/- z.
0234 
0235   Hep3Vector boostVector() const;
0236   // Boost needed from rest4Vector in rest frame to form this 4-vector
0237   // Returns the spatial components divided by the time component.
0238 
0239   HepLorentzVector & boost(double, double, double);
0240   inline HepLorentzVector & boost(const Hep3Vector &);
0241   // Lorentz boost.
0242 
0243   HepLorentzVector & boostX( double beta );
0244   HepLorentzVector & boostY( double beta );
0245   HepLorentzVector & boostZ( double beta );
0246   // Boost along an axis, by magnitue beta (fraction of speed of light)
0247 
0248   double rapidity() const;
0249   // Returns the rapidity, i.e. 0.5*ln((E+pz)/(E-pz))
0250 
0251   inline double pseudoRapidity() const;
0252   // Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))
0253 
0254   inline bool isTimelike() const;
0255   // Test if the 4-vector is timelike
0256 
0257   inline bool isSpacelike() const;
0258   // Test if the 4-vector is spacelike
0259 
0260   inline bool isLightlike(double epsilon=tolerance) const;
0261   // Test for lightlike is within tolerance epsilon
0262 
0263   HepLorentzVector &  rotateX(double);
0264   // Rotate the spatial component around the x-axis.
0265 
0266   HepLorentzVector &  rotateY(double);
0267   // Rotate the spatial component around the y-axis.
0268 
0269   HepLorentzVector &  rotateZ(double);
0270   // Rotate the spatial component around the z-axis.
0271 
0272   HepLorentzVector &  rotateUz(const Hep3Vector &);
0273   // Rotates the reference frame from Uz to newUz (unit vector).
0274 
0275   HepLorentzVector & rotate(double, const Hep3Vector &);
0276   // Rotate the spatial component around specified axis.
0277 
0278   inline HepLorentzVector & operator *= (const HepRotation &);
0279   inline HepLorentzVector & transform(const HepRotation &);
0280   // Transformation with HepRotation.
0281 
0282   HepLorentzVector & operator *= (const HepLorentzRotation &);
0283   HepLorentzVector & transform(const HepLorentzRotation &);
0284   // Transformation with HepLorenzRotation.
0285 
0286 // = = = = = = = = = = = = = = = = = = = = = = = =
0287 //
0288 // Esoteric properties and operations on 4-vectors:  
0289 //
0290 // 0 - Flexible metric convention and axial unit 4-vectors
0291 // 1 - Construct and set 4-vectors in various ways 
0292 // 2 - Synonyms for accessing coordinates and properties
0293 // 2a - Setting space coordinates in different ways 
0294 // 3 - Comparisions (dictionary, near-ness, and geometric)
0295 // 4 - Intrinsic properties 
0296 // 4a - Releativistic kinematic properties 
0297 // 4b - Methods combining two 4-vectors
0298 // 5 - Properties releative to z axis and to arbitrary directions
0299 // 7 - Rotations and Boosts
0300 //
0301 // = = = = = = = = = = = = = = = = = = = = = = = =
0302 
0303 // 0 - Flexible metric convention 
0304 
0305   static ZMpvMetric_t setMetric( ZMpvMetric_t a1 );
0306   static ZMpvMetric_t getMetric();
0307 
0308 // 1 - Construct and set 4-vectors in various ways 
0309 
0310   inline void set        (double x, double y, double z, double  t);
0311   inline void set        (double x, double y, double z, Tcomponent t);
0312   inline HepLorentzVector(double x, double y, double z, Tcomponent t);
0313   // Form 4-vector by supplying cartesian coordinate components
0314 
0315   inline void set        (Tcomponent t, double x, double y, double z);
0316   inline HepLorentzVector(Tcomponent t, double x, double y, double z);
0317   // Deprecated because the 4-doubles form uses x,y,z,t, not t,x,y,z.
0318 
0319   inline void set                 ( double t );
0320 
0321   inline void set                 ( Tcomponent t );
0322   inline explicit HepLorentzVector( Tcomponent t );
0323   // Form 4-vector with zero space components, by supplying t component
0324 
0325   inline void set                 ( const Hep3Vector & v );
0326   inline explicit HepLorentzVector( const Hep3Vector & v );
0327   // Form 4-vector with zero time component, by supplying space 3-vector 
0328 
0329   inline HepLorentzVector & operator=( const Hep3Vector & v );
0330   // Form 4-vector with zero time component, equal to space 3-vector 
0331 
0332   inline void set ( const Hep3Vector & v, double t );
0333   inline void set ( double t, const Hep3Vector & v );
0334   // Set using specified space vector and time component
0335 
0336 // 2 - Synonyms for accessing coordinates and properties
0337 
0338   inline double getX() const;
0339   inline double getY() const;
0340   inline double getZ() const;
0341   inline double getT() const;
0342   // Get position and time.
0343 
0344   inline Hep3Vector v() const;
0345   inline Hep3Vector getV() const;
0346   // Get spatial component.   Same as vect.
0347 
0348   inline void setV(const Hep3Vector &);
0349   // Set spatial component.   Same as setVect.
0350 
0351 // 2a - Setting space coordinates in different ways 
0352 
0353   inline void setV( double x, double y, double z );
0354 
0355   inline void setRThetaPhi( double r, double theta, double phi);
0356   inline void setREtaPhi( double r, double eta, double phi);
0357   inline void setRhoPhiZ( double rho, double phi, double z );
0358 
0359 // 3 - Comparisions (dictionary, near-ness, and geometric)
0360 
0361   int compare( const HepLorentzVector & w ) const;
0362 
0363   bool operator >( const HepLorentzVector & w ) const;
0364   bool operator <( const HepLorentzVector & w ) const;
0365   bool operator>=( const HepLorentzVector & w ) const;
0366   bool operator<=( const HepLorentzVector & w ) const;
0367 
0368   bool   isNear ( const HepLorentzVector & w, 
0369                     double epsilon=tolerance ) const;
0370   double howNear( const HepLorentzVector & w ) const;
0371   // Is near using Euclidean measure t**2 + v**2
0372 
0373   bool   isNearCM ( const HepLorentzVector & w, 
0374                     double epsilon=tolerance ) const;
0375   double howNearCM( const HepLorentzVector & w ) const;
0376   // Is near in CM frame:  Applicable only for two timelike HepLorentzVectors
0377 
0378         // If w1 and w2 are already in their CM frame, then w1.isNearCM(w2)
0379         // is exactly equivalent to w1.isNear(w2).
0380         // If w1 and w2 have T components of zero, w1.isNear(w2) is exactly
0381         // equivalent to w1.getV().isNear(w2.v()).  
0382 
0383   bool isParallel( const HepLorentzVector & w, 
0384                     double epsilon=tolerance ) const;
0385   // Test for isParallel is within tolerance epsilon
0386   double howParallel (const HepLorentzVector & w) const;
0387 
0388   static double getTolerance();
0389   static double setTolerance( double tol );
0390   // Set the tolerance for HepLorentzVectors to be considered near
0391   // The same tolerance is used for determining isLightlike, and isParallel
0392 
0393   double deltaR(const HepLorentzVector & v) const;
0394   // sqrt ( (delta eta)^2 + (delta phi)^2 ) of space part
0395 
0396 // 4 - Intrinsic properties 
0397 
0398          double howLightlike() const;
0399   // Close to zero for almost lightlike 4-vectors; up to 1.
0400 
0401   inline double euclideanNorm2()  const;
0402   // Sum of the squares of time and space components; not Lorentz invariant. 
0403 
0404   inline double euclideanNorm()  const; 
0405   // Length considering the metric as (+ + + +); not Lorentz invariant.
0406 
0407 
0408 // 4a - Relativistic kinematic properties 
0409 
0410 // All Relativistic kinematic properties are independent of the sense of metric
0411 
0412   inline double restMass2() const;
0413   inline double invariantMass2() const; 
0414   // Rest mass squared -- same as m2()
0415 
0416   inline double restMass() const;
0417   inline double invariantMass() const; 
0418   // Same as m().  If m2() is negative then -sqrt(-m2()) is returned.
0419 
0420 // The following properties are rest-frame related, 
0421 // and are applicable only to non-spacelike 4-vectors
0422 
0423   HepLorentzVector rest4Vector() const;
0424   // This 4-vector, boosted into its own rest frame:  (0, 0, 0, m()) 
0425           // The following relation holds by definition:
0426           // w.rest4Vector().boost(w.boostVector()) == w
0427 
0428   // Beta and gamma of the boost vector
0429   double beta() const;
0430   // Relativistic beta of the boost vector
0431 
0432   double gamma() const;
0433   // Relativistic gamma of the boost vector
0434 
0435   inline double eta() const;
0436   // Pseudorapidity (of the space part)
0437 
0438   inline double eta(const Hep3Vector & ref) const;
0439   // Pseudorapidity (of the space part) w.r.t. specified direction
0440 
0441   double rapidity(const Hep3Vector & ref) const;
0442   // Rapidity in specified direction
0443 
0444   double coLinearRapidity() const;
0445   // Rapidity, in the relativity textbook sense:  atanh (|P|/E)
0446 
0447   Hep3Vector findBoostToCM() const;
0448   // Boost needed to get to center-of-mass  frame:
0449           // w.findBoostToCM() == - w.boostVector()
0450           // w.boost(w.findBoostToCM()) == w.rest4Vector()
0451 
0452   Hep3Vector findBoostToCM( const HepLorentzVector & w ) const;
0453   // Boost needed to get to combined center-of-mass frame:
0454           // w1.findBoostToCM(w2) == w2.findBoostToCM(w1)
0455           // w.findBoostToCM(w) == w.findBoostToCM()
0456 
0457   inline double et2(const Hep3Vector &) const;
0458   // Transverse energy w.r.t. given axis squared.
0459 
0460   inline double et(const Hep3Vector &) const;
0461   // Transverse energy w.r.t. given axis.
0462 
0463 // 4b - Methods combining two 4-vectors
0464 
0465   inline double diff2( const HepLorentzVector & w ) const;
0466   // (this - w).dot(this-w); sign depends on metric choice
0467 
0468   inline double delta2Euclidean ( const HepLorentzVector & w ) const;
0469   // Euclidean norm of differnce:  (delta_T)^2  + (delta_V)^2
0470 
0471 // 5 - Properties releative to z axis and to arbitrary directions
0472 
0473   double  plus(  const Hep3Vector & ref ) const;
0474   // t + projection in reference direction
0475 
0476   double  minus( const Hep3Vector & ref ) const;
0477   // t - projection in reference direction
0478 
0479 // 7 - Rotations and boosts
0480 
0481   HepLorentzVector & rotate ( const Hep3Vector & axis, double delta );
0482   // Same as rotate (delta, axis)
0483 
0484   HepLorentzVector & rotate ( const HepAxisAngle & ax );
0485   HepLorentzVector & rotate ( const HepEulerAngles & e );
0486   HepLorentzVector & rotate ( double phi,
0487                               double theta,
0488                               double psi );
0489   // Rotate using these HepEuler angles - see Goldstein page 107 for conventions
0490 
0491   HepLorentzVector & boost ( const Hep3Vector & axis,  double beta );
0492   // Normalizes the Hep3Vector to define a direction, and uses beta to
0493   // define the magnitude of the boost.
0494 
0495   friend HepLorentzVector rotationXOf
0496     ( const HepLorentzVector & vec, double delta );
0497   friend HepLorentzVector rotationYOf
0498     ( const HepLorentzVector & vec, double delta );
0499   friend HepLorentzVector rotationZOf
0500     ( const HepLorentzVector & vec, double delta );
0501   friend HepLorentzVector rotationOf
0502     ( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
0503   friend HepLorentzVector rotationOf
0504     ( const HepLorentzVector & vec, const HepAxisAngle & ax );
0505   friend HepLorentzVector rotationOf
0506     ( const HepLorentzVector & vec, const HepEulerAngles & e );
0507   friend HepLorentzVector rotationOf
0508     ( const HepLorentzVector & vec, double phi,
0509                                     double theta,
0510                                     double psi );
0511 
0512   inline friend HepLorentzVector  boostXOf
0513     ( const HepLorentzVector & vec, double beta );
0514   inline friend HepLorentzVector  boostYOf
0515     ( const HepLorentzVector & vec, double beta );
0516   inline friend HepLorentzVector  boostZOf
0517     ( const HepLorentzVector & vec, double beta );
0518   inline friend HepLorentzVector  boostOf
0519     ( const HepLorentzVector & vec, const Hep3Vector & betaVector );
0520   inline friend HepLorentzVector  boostOf
0521     ( const HepLorentzVector & vec, const Hep3Vector & axis,  double beta );
0522  
0523 private:
0524 
0525   Hep3Vector pp;
0526   double  ee;
0527 
0528   static double tolerance;
0529   static double metric;
0530 
0531 };  // HepLorentzVector
0532 
0533 // 8 - Axial Unit 4-vectors
0534 
0535 static const HepLorentzVector X_HAT4 = HepLorentzVector( 1, 0, 0, 0 );
0536 static const HepLorentzVector Y_HAT4 = HepLorentzVector( 0, 1, 0, 0 );
0537 static const HepLorentzVector Z_HAT4 = HepLorentzVector( 0, 0, 1, 0 );
0538 static const HepLorentzVector T_HAT4 = HepLorentzVector( 0, 0, 0, 1 );
0539 
0540 // Global methods
0541 
0542 std::ostream & operator << (std::ostream &, const HepLorentzVector &);
0543 // Output to a stream.
0544 
0545 std::istream & operator >> (std::istream &, HepLorentzVector &);
0546 // Input from a stream.
0547 
0548 typedef HepLorentzVector HepLorentzVectorD;
0549 typedef HepLorentzVector HepLorentzVectorF;
0550 
0551 inline HepLorentzVector operator * (const HepLorentzVector &, double a);
0552 inline HepLorentzVector operator * (double a, const HepLorentzVector &);
0553 // Scaling LorentzVector with a real number
0554 
0555        HepLorentzVector operator / (const HepLorentzVector &, double a);
0556 // Dividing LorentzVector by a real number
0557 
0558 // Tcomponent definition:
0559 
0560 // Signature protection for 4-vector constructors taking 4 components
0561 class Tcomponent {
0562 private:
0563   double t_;
0564 public:
0565   explicit Tcomponent(double t) : t_(t) {}
0566   operator double() const { return t_; }
0567 };  // Tcomponent
0568 
0569 }  // namespace CLHEP
0570 
0571 #include "CLHEP/Vector/LorentzVector.icc"
0572 
0573 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0574 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0575 using namespace CLHEP;
0576 #endif
0577 
0578 #endif /* HEP_LORENTZVECTOR_H */