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