CLHEP/Vector/LorentzVector.h

00001 // -*- C++ -*-
00002 // CLASSDOC OFF
00003 // $Id: LorentzVector.h,v 1.29 2002/04/12 15:02:46 evc Exp $
00004 // ---------------------------------------------------------------------------
00005 // CLASSDOC ON
00006 //
00007 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00008 //
00009 // HepLorentzVector is a Lorentz vector consisting of Hep3Vector and
00010 // double components. Lorentz transformations (rotations and boosts)
00011 // of these vectors are perfomed by multiplying with objects of
00012 // the HepLorenzRotation class.
00013 //
00014 // .SS See Also
00015 // ThreeVector.h, Rotation.h, LorentzRotation.h
00016 //
00017 // .SS Authors
00018 // Leif Lonnblad and Anders Nilsson. Modified by Evgueni Tcherniaev, Mark Fischler
00019 //
00020 
00021 #ifndef HEP_LORENTZVECTOR_H
00022 #define HEP_LORENTZVECTOR_H
00023 
00024 #ifdef GNUPRAGMA
00025 #pragma interface
00026 #endif
00027 
00028 #include "CLHEP/config/CLHEP.h"
00029 #include "CLHEP/Vector/ThreeVector.h"
00030 #include "CLHEP/config/iostream.h"
00031 
00032 #ifdef HEP_NO_INLINE_IN_DECLARATION
00033 #define inline
00034 #endif
00035 
00036 // Declarations of classes and global methods
00037 class HepLorentzVector;
00038 class HepLorentzRotation;
00039 class HepRotation;
00040 class HepAxisAngle;
00041 class HepEulerAngles;
00042 class Tcomponent;
00043 HepLorentzVector rotationXOf( const HepLorentzVector & vec, double delta );
00044 HepLorentzVector rotationYOf( const HepLorentzVector & vec, double delta );
00045 HepLorentzVector rotationZOf( const HepLorentzVector & vec, double delta );
00046 HepLorentzVector rotationOf
00047     ( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
00048 HepLorentzVector rotationOf
00049     ( const HepLorentzVector & vec, const HepAxisAngle & ax );
00050 HepLorentzVector rotationOf
00051     ( const HepLorentzVector & vec, const HepEulerAngles & e );
00052 HepLorentzVector rotationOf
00053     ( const HepLorentzVector & vec, double phi,
00054                                     double theta,
00055                                     double psi );
00056 inline 
00057 HepLorentzVector  boostXOf( const HepLorentzVector & vec, double beta );
00058 inline 
00059 HepLorentzVector  boostYOf( const HepLorentzVector & vec, double beta );
00060 inline 
00061 HepLorentzVector  boostZOf( const HepLorentzVector & vec, double beta );
00062 inline HepLorentzVector  boostOf
00063     ( const HepLorentzVector & vec, const Hep3Vector & betaVector );
00064 inline HepLorentzVector  boostOf
00065     ( const HepLorentzVector & vec, const Hep3Vector & axis,  double beta );
00066 
00067 enum ZMpvMetric_t { TimePositive, TimeNegative };
00068 
00069 
00074 class HepLorentzVector {
00075 
00076 public:
00077 
00078   enum { X=0, Y=1, Z=2, T=3, NUM_COORDINATES=4, SIZE=NUM_COORDINATES };
00079   // Safe indexing of the coordinates when using with matrices, arrays, etc.
00080   // (BaBar)
00081 
00082   inline HepLorentzVector(double x, double y,
00083                           double z, double t);
00084   // Constructor giving the components x, y, z, t.
00085 
00086   inline HepLorentzVector(double x, double y, double z);
00087   // Constructor giving the components x, y, z with t-component set to 0.0.
00088 
00089   inline HepLorentzVector(double t);
00090   // Constructor giving the t-component with x, y and z set to 0.0.
00091 
00092   inline HepLorentzVector();
00093   // Default constructor with x, y, z and t set to 0.0.
00094 
00095   inline HepLorentzVector(const Hep3Vector & p, double e);
00096   inline HepLorentzVector(double e, const Hep3Vector & p);
00097   // Constructor giving a 3-Vector and a time component.
00098 
00099   inline HepLorentzVector(const HepLorentzVector &);
00100   // Copy constructor.
00101 
00102   inline ~HepLorentzVector();
00103   // The destructor.
00104 
00105   inline operator const Hep3Vector & () const;
00106   inline operator Hep3Vector & ();
00107   // Conversion (cast) to Hep3Vector.
00108 
00109   inline double x() const;
00110   inline double y() const;
00111   inline double z() const;
00112   inline double t() const;
00113   // Get position and time.
00114 
00115   inline void setX(double);
00116   inline void setY(double);
00117   inline void setZ(double);
00118   inline void setT(double);
00119   // Set position and time.
00120 
00121   inline double px() const;
00122   inline double py() const;
00123   inline double pz() const;
00124   inline double e() const;
00125   // Get momentum and energy.
00126 
00127   inline void setPx(double);
00128   inline void setPy(double);
00129   inline void setPz(double);
00130   inline void setE(double);
00131   // Set momentum and energy.
00132 
00133   inline Hep3Vector vect() const;
00134   // Get spatial component. 
00135 
00136   inline void setVect(const Hep3Vector &);
00137   // Set spatial component. 
00138 
00139   inline double theta() const;
00140   inline double cosTheta() const;
00141   inline double phi() const;
00142   inline double rho() const;
00143   // Get spatial vector components in spherical coordinate system.
00144 
00145   inline void setTheta(double);
00146   inline void setPhi(double);
00147   inline void setRho(double);
00148   // Set spatial vector components in spherical coordinate system.
00149 
00150   double operator () (int) const;
00151   inline double operator [] (int) const;
00152   // Get components by index.
00153 
00154   double & operator () (int);
00155   inline double & operator [] (int);
00156   // Set components by index.
00157 
00158   inline HepLorentzVector & operator = (const HepLorentzVector &);
00159   // Assignment. 
00160 
00161   inline HepLorentzVector   operator +  (const HepLorentzVector &) const;
00162   inline HepLorentzVector & operator += (const HepLorentzVector &);
00163   // Additions.
00164 
00165   inline HepLorentzVector   operator -  (const HepLorentzVector &) const;
00166   inline HepLorentzVector & operator -= (const HepLorentzVector &);
00167   // Subtractions.
00168 
00169   inline HepLorentzVector operator - () const;
00170   // Unary minus.
00171 
00172   inline HepLorentzVector & operator *= (double);
00173          HepLorentzVector & operator /= (double);
00174   // Scaling with real numbers.
00175 
00176   inline bool operator == (const HepLorentzVector &) const;
00177   inline bool operator != (const HepLorentzVector &) const;
00178   // Comparisons.
00179 
00180   inline double perp2() const;
00181   // Transverse component of the spatial vector squared.
00182 
00183   inline double perp() const;
00184   // Transverse component of the spatial vector (R in cylindrical system).
00185 
00186   inline void setPerp(double);
00187   // Set the transverse component of the spatial vector.
00188 
00189   inline double perp2(const Hep3Vector &) const;
00190   // Transverse component of the spatial vector w.r.t. given axis squared.
00191 
00192   inline double perp(const Hep3Vector &) const;
00193   // Transverse component of the spatial vector w.r.t. given axis.
00194 
00195   inline double angle(const Hep3Vector &) const;
00196   // Angle wrt. another vector.
00197 
00198   inline double mag2() const;
00199   // Dot product of 4-vector with itself. 
00200   // By default the metric is TimePositive, and mag2() is the same as m2().
00201 
00202   inline double m2() const;
00203   // Invariant mass squared.
00204 
00205   inline double mag() const;
00206   inline double m() const;
00207   // Invariant mass. If m2() is negative then -sqrt(-m2()) is returned.
00208 
00209   inline double mt2() const;
00210   // Transverse mass squared.
00211 
00212   inline double mt() const;
00213   // Transverse mass.
00214 
00215   inline double et2() const;
00216   // Transverse energy squared.
00217 
00218   inline double et() const;
00219   // Transverse energy.
00220 
00221   inline double dot(const HepLorentzVector &) const;
00222   inline double operator * (const HepLorentzVector &) const;
00223   // Scalar product.
00224 
00225   inline double invariantMass2( const HepLorentzVector & w ) const;
00226   // Invariant mass squared of pair of 4-vectors 
00227 
00228   double invariantMass ( const HepLorentzVector & w ) const;
00229   // Invariant mass of pair of 4-vectors 
00230 
00231   inline void setVectMag(const Hep3Vector & spatial, double magnitude);
00232   inline void setVectM(const Hep3Vector & spatial, double mass);
00233   // Copy spatial coordinates, and set energy = sqrt(mass^2 + spatial^2)
00234 
00235   inline double plus() const;
00236   inline double minus() const;
00237   // Returns the positive/negative light-cone component t +/- z.
00238 
00239   Hep3Vector boostVector() const;
00240   // Boost needed from rest4Vector in rest frame to form this 4-vector
00241   // Returns the spatial components divided by the time component.
00242 
00243   HepLorentzVector & boost(double, double, double);
00244   inline HepLorentzVector & boost(const Hep3Vector &);
00245   // Lorentz boost.
00246 
00247   HepLorentzVector & boostX( double beta );
00248   HepLorentzVector & boostY( double beta );
00249   HepLorentzVector & boostZ( double beta );
00250   // Boost along an axis, by magnitue beta (fraction of speed of light)
00251 
00252   double rapidity() const;
00253   // Returns the rapidity, i.e. 0.5*ln((E+pz)/(E-pz))
00254 
00255   inline double pseudoRapidity() const;
00256   // Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))
00257 
00258   inline bool isTimelike() const;
00259   // Test if the 4-vector is timelike
00260 
00261   inline bool isSpacelike() const;
00262   // Test if the 4-vector is spacelike
00263 
00264   inline bool isLightlike(double epsilon=tolerance) const;
00265   // Test for lightlike is within tolerance epsilon
00266 
00267   HepLorentzVector &  rotateX(double);
00268   // Rotate the spatial component around the x-axis.
00269 
00270   HepLorentzVector &  rotateY(double);
00271   // Rotate the spatial component around the y-axis.
00272 
00273   HepLorentzVector &  rotateZ(double);
00274   // Rotate the spatial component around the z-axis.
00275 
00276   HepLorentzVector &  rotateUz(const Hep3Vector &);
00277   // Rotates the reference frame from Uz to newUz (unit vector).
00278 
00279   HepLorentzVector & rotate(double, const Hep3Vector &);
00280   // Rotate the spatial component around specified axis.
00281 
00282   inline HepLorentzVector & operator *= (const HepRotation &);
00283   inline HepLorentzVector & transform(const HepRotation &);
00284   // Transformation with HepRotation.
00285 
00286   HepLorentzVector & operator *= (const HepLorentzRotation &);
00287   HepLorentzVector & transform(const HepLorentzRotation &);
00288   // Transformation with HepLorenzRotation.
00289 
00290 // = = = = = = = = = = = = = = = = = = = = = = = =
00291 //
00292 // Esoteric properties and operations on 4-vectors:  
00293 //
00294 // 0 - Flexible metric convention and axial unit 4-vectors
00295 // 1 - Construct and set 4-vectors in various ways 
00296 // 2 - Synonyms for accessing coordinates and properties
00297 // 2a - Setting space coordinates in different ways 
00298 // 3 - Comparisions (dictionary, near-ness, and geometric)
00299 // 4 - Intrinsic properties 
00300 // 4a - Releativistic kinematic properties 
00301 // 4b - Methods combining two 4-vectors
00302 // 5 - Properties releative to z axis and to arbitrary directions
00303 // 7 - Rotations and Boosts
00304 //
00305 // = = = = = = = = = = = = = = = = = = = = = = = =
00306 
00307 // 0 - Flexible metric convention 
00308 
00309   static ZMpvMetric_t setMetric( ZMpvMetric_t m );
00310   static ZMpvMetric_t getMetric();
00311 
00312 // 1 - Construct and set 4-vectors in various ways 
00313 
00314   inline void set        (double x, double y, double z, double  t);
00315   inline void set        (double x, double y, double z, Tcomponent t);
00316   inline HepLorentzVector(double x, double y, double z, Tcomponent t);
00317   // Form 4-vector by supplying cartesian coordinate components
00318 
00319   inline void set        (Tcomponent t, double x, double y, double z);
00320   inline HepLorentzVector(Tcomponent t, double x, double y, double z);
00321   // Deprecated because the 4-doubles form uses x,y,z,t, not t,x,y,z.
00322 
00323   inline void set                 ( double t );
00324 
00325   inline void set                 ( Tcomponent t );
00326   inline explicit HepLorentzVector( Tcomponent t );
00327   // Form 4-vector with zero space components, by supplying t component
00328 
00329   inline void set                 ( const Hep3Vector & v );
00330   inline explicit HepLorentzVector( const Hep3Vector & v );
00331   // Form 4-vector with zero time component, by supplying space 3-vector 
00332 
00333   inline HepLorentzVector & operator=( const Hep3Vector & v );
00334   // Form 4-vector with zero time component, equal to space 3-vector 
00335 
00336   inline void set ( const Hep3Vector & v, double t );
00337   inline void set ( double t, const Hep3Vector & v );
00338   // Set using specified space vector and time component
00339 
00340 // 2 - Synonyms for accessing coordinates and properties
00341 
00342   inline double getX() const;
00343   inline double getY() const;
00344   inline double getZ() const;
00345   inline double getT() const;
00346   // Get position and time.
00347 
00348   inline Hep3Vector v() const;
00349   inline Hep3Vector getV() const;
00350   // Get spatial component.   Same as vect.
00351 
00352   inline void setV(const Hep3Vector &);
00353   // Set spatial component.   Same as setVect.
00354 
00355 // 2a - Setting space coordinates in different ways 
00356 
00357   inline void setV( double x, double y, double z );
00358 
00359   inline void setRThetaPhi( double r, double theta, double phi);
00360   inline void setREtaPhi( double r, double eta, double phi);
00361   inline void setRhoPhiZ( double rho, double phi, double z );
00362 
00363 // 3 - Comparisions (dictionary, near-ness, and geometric)
00364 
00365   int compare( const HepLorentzVector & w ) const;
00366 
00367   bool operator >( const HepLorentzVector & w ) const;
00368   bool operator <( const HepLorentzVector & w ) const;
00369   bool operator>=( const HepLorentzVector & w ) const;
00370   bool operator<=( const HepLorentzVector & w ) const;
00371 
00372   bool   isNear ( const HepLorentzVector & w, 
00373                                         double epsilon=tolerance ) const;
00374   double howNear( const HepLorentzVector & w ) const;
00375   // Is near using Euclidean measure t**2 + v**2
00376 
00377   bool   isNearCM ( const HepLorentzVector & w, 
00378                                         double epsilon=tolerance ) const;
00379   double howNearCM( const HepLorentzVector & w ) const;
00380   // Is near in CM frame:  Applicable only for two timelike HepLorentzVectors
00381 
00382         // If w1 and w2 are already in their CM frame, then w1.isNearCM(w2)
00383         // is exactly equivalent to w1.isNear(w2).
00384         // If w1 and w2 have T components of zero, w1.isNear(w2) is exactly
00385         // equivalent to w1.getV().isNear(w2.v()).  
00386 
00387   bool isParallel( const HepLorentzVector & w, 
00388                                         double epsilon=tolerance ) const;
00389   // Test for isParallel is within tolerance epsilon
00390   double howParallel (const HepLorentzVector & w) const;
00391 
00392   static double getTolerance();
00393   static double setTolerance( double tol );
00394   // Set the tolerance for HepLorentzVectors to be considered near
00395   // The same tolerance is used for determining isLightlike, and isParallel
00396 
00397   double deltaR(const HepLorentzVector & v) const;
00398   // sqrt ( (delta eta)^2 + (delta phi)^2 ) of space part
00399 
00400 // 4 - Intrinsic properties 
00401 
00402          double howLightlike() const;
00403   // Close to zero for almost lightlike 4-vectors; up to 1.
00404 
00405   inline double euclideanNorm2()  const;
00406   // Sum of the squares of time and space components; not Lorentz invariant. 
00407 
00408   inline double euclideanNorm()  const; 
00409   // Length considering the metric as (+ + + +); not Lorentz invariant.
00410 
00411 
00412 // 4a - Relativistic kinematic properties 
00413 
00414 // All Relativistic kinematic properties are independent of the sense of metric
00415 
00416   inline double restMass2() const;
00417   inline double invariantMass2() const; 
00418   // Rest mass squared -- same as m2()
00419 
00420   inline double restMass() const;
00421   inline double invariantMass() const; 
00422   // Same as m().  If m2() is negative then -sqrt(-m2()) is returned.
00423 
00424 // The following properties are rest-frame related, 
00425 // and are applicable only to non-spacelike 4-vectors
00426 
00427   HepLorentzVector rest4Vector() const;
00428   // This 4-vector, boosted into its own rest frame:  (0, 0, 0, m()) 
00429           // The following relation holds by definition:
00430           // w.rest4Vector().boost(w.boostVector()) == w
00431 
00432   // Beta and gamma of the boost vector
00433   double beta() const;
00434   // Relativistic beta of the boost vector
00435 
00436   double gamma() const;
00437   // Relativistic gamma of the boost vector
00438 
00439   inline double eta() const;
00440   // Pseudorapidity (of the space part)
00441 
00442   inline double eta(const Hep3Vector & ref) const;
00443   // Pseudorapidity (of the space part) w.r.t. specified direction
00444 
00445   double rapidity(const Hep3Vector & ref) const;
00446   // Rapidity in specified direction
00447 
00448   double coLinearRapidity() const;
00449   // Rapidity, in the relativity textbook sense:  atanh (|P|/E)
00450 
00451   Hep3Vector findBoostToCM() const;
00452   // Boost needed to get to center-of-mass  frame:
00453           // w.findBoostToCM() == - w.boostVector()
00454           // w.boost(w.findBoostToCM()) == w.rest4Vector()
00455 
00456   Hep3Vector findBoostToCM( const HepLorentzVector & w ) const;
00457   // Boost needed to get to combined center-of-mass frame:
00458           // w1.findBoostToCM(w2) == w2.findBoostToCM(w1)
00459           // w.findBoostToCM(w) == w.findBoostToCM()
00460 
00461   inline double et2(const Hep3Vector &) const;
00462   // Transverse energy w.r.t. given axis squared.
00463 
00464   inline double et(const Hep3Vector &) const;
00465   // Transverse energy w.r.t. given axis.
00466 
00467 // 4b - Methods combining two 4-vectors
00468 
00469   inline double diff2( const HepLorentzVector & w ) const;
00470   // (this - w).dot(this-w); sign depends on metric choice
00471 
00472   inline double delta2Euclidean ( const HepLorentzVector & w ) const;
00473   // Euclidean norm of differnce:  (delta_T)^2  + (delta_V)^2
00474 
00475 // 5 - Properties releative to z axis and to arbitrary directions
00476 
00477   double  plus(  const Hep3Vector & ref ) const;
00478   // t + projection in reference direction
00479 
00480   double  minus( const Hep3Vector & ref ) const;
00481   // t - projection in reference direction
00482 
00483 // 7 - Rotations and boosts
00484 
00485   HepLorentzVector & rotate ( const Hep3Vector & axis, double delta );
00486   // Same as rotate (delta, axis)
00487 
00488   HepLorentzVector & rotate ( const HepAxisAngle & ax );
00489   HepLorentzVector & rotate ( const HepEulerAngles & e );
00490   HepLorentzVector & rotate ( double phi,
00491                               double theta,
00492                               double psi );
00493   // Rotate using these HepEuler angles - see Goldstein page 107 for conventions
00494 
00495   HepLorentzVector & boost ( const Hep3Vector & axis,  double beta );
00496   // Normalizes the Hep3Vector to define a direction, and uses beta to
00497   // define the magnitude of the boost.
00498 
00499   friend HepLorentzVector rotationXOf
00500     ( const HepLorentzVector & vec, double delta );
00501   friend HepLorentzVector rotationYOf
00502     ( const HepLorentzVector & vec, double delta );
00503   friend HepLorentzVector rotationZOf
00504     ( const HepLorentzVector & vec, double delta );
00505   friend HepLorentzVector rotationOf
00506     ( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
00507   friend HepLorentzVector rotationOf
00508     ( const HepLorentzVector & vec, const HepAxisAngle & ax );
00509   friend HepLorentzVector rotationOf
00510     ( const HepLorentzVector & vec, const HepEulerAngles & e );
00511   friend HepLorentzVector rotationOf
00512     ( const HepLorentzVector & vec, double phi,
00513                                     double theta,
00514                                     double psi );
00515 
00516   inline friend HepLorentzVector  boostXOf
00517     ( const HepLorentzVector & vec, double beta );
00518   inline friend HepLorentzVector  boostYOf
00519     ( const HepLorentzVector & vec, double beta );
00520   inline friend HepLorentzVector  boostZOf
00521     ( const HepLorentzVector & vec, double beta );
00522   inline friend HepLorentzVector  boostOf
00523     ( const HepLorentzVector & vec, const Hep3Vector & betaVector );
00524   inline friend HepLorentzVector  boostOf
00525     ( const HepLorentzVector & vec, const Hep3Vector & axis,  double beta );
00526  
00527 private:
00528 
00529   Hep3Vector pp;
00530   double  ee;
00531 
00532   static double tolerance;
00533   static double metric;
00534 
00535 };
00536 
00537 // 8 - Axial Unit 4-vectors
00538 
00539 static const HepLorentzVector X_HAT4 = HepLorentzVector( 1, 0, 0, 0 );
00540 static const HepLorentzVector Y_HAT4 = HepLorentzVector( 0, 1, 0, 0 );
00541 static const HepLorentzVector Z_HAT4 = HepLorentzVector( 0, 0, 1, 0 );
00542 static const HepLorentzVector T_HAT4 = HepLorentzVector( 0, 0, 0, 1 );
00543 
00544 // Global methods
00545 
00546 HepStd::ostream & operator << (HepStd::ostream &, const HepLorentzVector &);
00547 // Output to a stream.
00548 
00549 HepStd::istream & operator >> (HepStd::istream &, HepLorentzVector &);
00550 // Input from a stream.
00551 
00552 #ifdef HEP_NO_INLINE_IN_DECLARATION
00553 #undef inline
00554 #endif
00555 
00556 #ifdef HEP_SHORT_NAMES
00557 typedef HepLorentzVector VectorL;
00558 typedef HepLorentzVector Vector4;
00559 typedef HepLorentzVector DVectorL;
00560 typedef HepLorentzVector DVector4;
00561 typedef HepLorentzVector FVectorL;
00562 typedef HepLorentzVector FVector4;
00563 #endif
00564 
00565 typedef HepLorentzVector HepLorentzVectorD;
00566 typedef HepLorentzVector HepLorentzVectorF;
00567 
00568 inline HepLorentzVector operator * (const HepLorentzVector &, double a);
00569 inline HepLorentzVector operator * (double a, const HepLorentzVector &);
00570 // Scaling LorentzVector with a real number
00571 
00572        HepLorentzVector operator / (const HepLorentzVector &, double a);
00573 // Dividing LorentzVector by a real number
00574 
00575 // Tcomponent definition:
00576 
00577 // Signature protection for 4-vector constructors taking 4 components
00578 class Tcomponent {
00579 private:
00580   double t_;
00581 public:
00582   explicit Tcomponent(double t) : t_(t) {}
00583   operator double() const { return t_; }
00584 };
00585 
00586 #ifndef HEP_DEBUG_INLINE
00587 #include "CLHEP/Vector/LorentzVector.icc"
00588 #endif
00589 
00590 #endif /* HEP_LORENTZVECTOR_H */

Class Library for High Energy Physics (version 1.8)