CLHEP/Vector/LorentzRotation.h

00001 // -*- C++ -*-
00002 // CLASSDOC OFF
00003 // $Id: LorentzRotation.h,v 1.14 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 // This is the definition of the HepLorentzRotation class for performing 
00010 // Lorentz transformations (rotations and boosts) on objects of the
00011 // HepLorentzVector class.
00012 //
00013 // HepLorentzRotation is a concrete implementation of Hep4RotationInterface.
00014 //
00015 // .SS See Also
00016 // RotationInterfaces.h
00017 // ThreeVector.h, LorentzVector.h
00018 // Rotation.h, Boost.h
00019 //
00020 // .SS Author
00021 // Leif Lonnblad, Mark Fischler
00022 
00023 #ifndef HEP_LORENTZROTATION_H
00024 #define HEP_LORENTZROTATION_H
00025 
00026 #ifdef GNUPRAGMA
00027 #pragma interface
00028 #endif
00029 
00030 #ifdef HEP_NO_INLINE_IN_DECLARATION
00031 #define inline
00032 #endif
00033 
00034 #include "CLHEP/Vector/RotationInterfaces.h"
00035 #include "CLHEP/Vector/Rotation.h" 
00036 #include "CLHEP/Vector/Boost.h" 
00037 #include "CLHEP/Vector/LorentzVector.h"
00038 
00039 // Global methods
00040 
00041 inline HepLorentzRotation inverseOf ( const HepLorentzRotation & lt );
00042 HepLorentzRotation operator * (const HepRotation & r,
00043                                         const HepLorentzRotation & lt);
00044 HepLorentzRotation operator * (const HepRotationX & r,
00045                                         const HepLorentzRotation & lt);
00046 HepLorentzRotation operator * (const HepRotationY & r,
00047                                         const HepLorentzRotation & lt);
00048 HepLorentzRotation operator * (const HepRotationZ & r,
00049                                         const HepLorentzRotation & lt);
00050 
00055 class HepLorentzRotation {
00056 
00057 public:
00058   // ----------  Identity HepLorentzRotation:
00059 
00060   static const HepLorentzRotation IDENTITY;
00061 
00062   // ----------  Constructors and Assignment:
00063 
00064   inline HepLorentzRotation();
00065   // Default constructor. Gives a unit matrix.
00066 
00067   inline  HepLorentzRotation       (const HepLorentzRotation & r);
00068   // Copy constructor.
00069 
00070   inline  HepLorentzRotation       (const HepRotation & r);
00071   inline  HepLorentzRotation       (const HepBoost    & b);
00072   // Constructors from special cases.  
00073 
00074   inline HepLorentzRotation & operator = (const HepLorentzRotation & m);
00075   inline HepLorentzRotation & operator = (const HepRotation        & m);
00076   inline HepLorentzRotation & operator = (const HepBoost           & m);
00077   // Assignment.
00078 
00079   HepLorentzRotation & set (double bx, double by, double bz);
00080   inline HepLorentzRotation & set (const Hep3Vector & p);
00081   inline HepLorentzRotation & set (const HepBoost & boost);
00082   inline HepLorentzRotation (double bx, double by, double bz);
00083   inline HepLorentzRotation (const Hep3Vector & p);
00084   // Other Constructors giving a Lorentz-boost.
00085 
00086          HepLorentzRotation & set( const HepBoost & B, const HepRotation & R );
00087   inline HepLorentzRotation (      const HepBoost & B, const HepRotation & R );
00088   //   supply B and R:  T = B R:
00089 
00090          HepLorentzRotation & set( const HepRotation & R, const HepBoost & B );
00091   inline HepLorentzRotation (      const HepRotation & R, const HepBoost & B );
00092   //   supply R and B:  T = R B:
00093 
00094   HepLorentzRotation ( const HepLorentzVector & col1,
00095                        const HepLorentzVector & col2,
00096                        const HepLorentzVector & col3,
00097                        const HepLorentzVector & col4 );
00098   // Construct from four *orthosymplectic* LorentzVectors for the columns:
00099         // NOTE:
00100         //      This constructor, and the two set methods below,
00101         //      will check that the columns (or rows) form an orthosymplectic
00102         //      matrix, and will adjust values so that this relation is
00103         //      as exact as possible.
00104         //      Orthosymplectic means the dot product USING THE METRIC
00105         //      of two different coumns will be 0, and of a column with
00106         //      itself will be one. 
00107 
00108   HepLorentzRotation & set( const HepLorentzVector & col1,
00109                             const HepLorentzVector & col2,
00110                             const HepLorentzVector & col3,
00111                             const HepLorentzVector & col4 );
00112   //   supply four *orthosymplectic* HepLorentzVectors for the columns
00113 
00114   HepLorentzRotation & setRows( const HepLorentzVector & row1,
00115                                 const HepLorentzVector & row2,
00116                                 const HepLorentzVector & row3,
00117                                 const HepLorentzVector & row4 );
00118   //   supply four *orthosymplectic* HepLorentzVectors for the columns
00119 
00120   inline HepLorentzRotation & set( const HepRep4x4 & rep );
00121   inline HepLorentzRotation      ( const HepRep4x4 & rep );
00122   //   supply a HepRep4x4 structure (16 numbers)
00123   // WARNING:
00124   //            This constructor and set method will assume the
00125   //            HepRep4x4 supplied is in fact an orthosymplectic matrix.
00126   //            No checking or correction is done.  If you are
00127   //            not certain the matrix is orthosymplectic, break it
00128   //            into four HepLorentzVector columns and use the form
00129   //            HepLorentzRotation (col1, col2, col3, col4)
00130 
00131   // ----------  Accessors:
00132 
00133   inline double xx() const;
00134   inline double xy() const;
00135   inline double xz() const;
00136   inline double xt() const;
00137   inline double yx() const;
00138   inline double yy() const;
00139   inline double yz() const;
00140   inline double yt() const;
00141   inline double zx() const;
00142   inline double zy() const;
00143   inline double zz() const;
00144   inline double zt() const;
00145   inline double tx() const;
00146   inline double ty() const;
00147   inline double tz() const;
00148   inline double tt() const;
00149   // Elements of the matrix.
00150 
00151   inline HepLorentzVector col1() const;
00152   inline HepLorentzVector col2() const;
00153   inline HepLorentzVector col3() const;
00154   inline HepLorentzVector col4() const;
00155   // orthosymplectic column vectors
00156 
00157   inline HepLorentzVector row1() const;
00158   inline HepLorentzVector row2() const;
00159   inline HepLorentzVector row3() const;
00160   inline HepLorentzVector row4() const;
00161   // orthosymplectic row vectors
00162 
00163   inline HepRep4x4 rep4x4() const;
00164   //   4x4 representation:
00165 
00166   // ------------  Subscripting:
00167 
00168   class HepLorentzRotation_row {
00169   public:
00170     inline HepLorentzRotation_row(const HepLorentzRotation &, int);
00171     inline double operator [] (int) const;
00172   private:
00173     const HepLorentzRotation & rr;
00174     int ii;
00175   };
00176   // Helper class for implemention of C-style subscripting r[i][j] 
00177 
00178   inline const HepLorentzRotation_row operator [] (int) const; 
00179   // Returns object of the helper class for C-style subscripting r[i][j]
00180 
00181   double operator () (int, int) const;
00182   // Fortran-style subscripting: returns (i,j) element of the matrix.
00183 
00184   // ----------  Decomposition:
00185 
00186   void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
00187   void decompose (HepBoost   & boost, HepRotation  & rotation) const;
00188   // Find B and R such that L = B*R
00189 
00190   void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
00191   void decompose (HepRotation  & rotation, HepBoost   & boost) const;
00192   // Find R and B such that L = R*B 
00193 
00194   // ----------  Comparisons:
00195 
00196   int compare( const HepLorentzRotation & m  ) const;
00197   // Dictionary-order comparison, in order tt,tz,...zt,zz,zy,zx,yt,yz,...,xx
00198   // Used in operator<, >, <=, >=
00199 
00200   inline bool operator == (const HepLorentzRotation &) const;
00201   inline bool operator != (const HepLorentzRotation &) const;
00202   inline bool operator <= (const HepLorentzRotation &) const;
00203   inline bool operator >= (const HepLorentzRotation &) const;
00204   inline bool operator <  (const HepLorentzRotation &) const;
00205   inline bool operator >  (const HepLorentzRotation &) const;
00206 
00207   inline bool isIdentity() const;
00208   // Returns true if the Identity matrix.
00209 
00210   double distance2( const HepBoost & b  ) const;
00211   double distance2( const HepRotation & r  ) const;
00212   double distance2( const HepLorentzRotation & lt  ) const;
00213   // Decomposes L = B*R, returns the sum of distance2 for B and R.
00214 
00215   double howNear(   const HepBoost & b ) const;
00216   double howNear(   const HepRotation & r) const;
00217   double howNear(   const HepLorentzRotation & lt ) const;
00218 
00219   bool isNear(const HepBoost & b,
00220              double epsilon=Hep4RotationInterface::tolerance) const;
00221   bool isNear(const HepRotation & r,
00222              double epsilon=Hep4RotationInterface::tolerance) const;
00223   bool isNear(const HepLorentzRotation & lt,
00224              double epsilon=Hep4RotationInterface::tolerance) const;
00225 
00226   // ----------  Properties:
00227 
00228   double norm2() const;
00229   // distance2 (IDENTITY), which involves decomposing into B and R and summing 
00230   // norm2 for the individual B and R parts. 
00231 
00232   void rectify();
00233   // non-const but logically moot correction for accumulated roundoff errors
00234         // rectify averages the matrix with the orthotranspose of its actual
00235         // inverse (absent accumulated roundoff errors, the orthotranspose IS
00236         // the inverse)); this removes to first order those errors.
00237         // Then it formally decomposes that, extracts axis and delta for its
00238         // Rotation part, forms a LorentzRotation from a true HepRotation 
00239         // with those values of axis and delta, times the true Boost
00240         // with that boost vector.
00241 
00242   // ---------- Application:
00243 
00244   inline HepLorentzVector vectorMultiplication(const HepLorentzVector&) const;
00245   inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
00246   inline HepLorentzVector operator* ( const HepLorentzVector & p ) const;
00247   // Multiplication with a Lorentz Vector.
00248 
00249   // ---------- Operations in the group of 4-Rotations
00250 
00251   HepLorentzRotation matrixMultiplication(const HepRep4x4 & m) const;
00252 
00253   inline HepLorentzRotation operator * (const HepBoost & b) const;
00254   inline HepLorentzRotation operator * (const HepRotation & r) const;
00255   inline HepLorentzRotation operator * (const HepLorentzRotation & lt) const;
00256   // Product of two Lorentz Rotations (this) * lt - matrix multiplication  
00257 
00258   inline  HepLorentzRotation & operator *= (const HepBoost & b);
00259   inline  HepLorentzRotation & operator *= (const HepRotation & r);
00260   inline  HepLorentzRotation & operator *= (const HepLorentzRotation & lt);
00261   inline  HepLorentzRotation & transform   (const HepBoost & b);
00262   inline  HepLorentzRotation & transform   (const HepRotation & r);
00263   inline  HepLorentzRotation & transform   (const HepLorentzRotation & lt);
00264   // Matrix multiplication.
00265   // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
00266 
00267   // Here there is an opportunity for speedup by providing specialized forms
00268   // of lt * r and lt * b where r is a RotationX Y or Z or b is a BoostX Y or Z
00269   // These are, in fact, provided below for the transform() methods.
00270 
00271   HepLorentzRotation & rotateX(double delta);
00272   // Rotation around the x-axis; equivalent to LT = RotationX(delta) * LT
00273 
00274   HepLorentzRotation & rotateY(double delta);
00275   // Rotation around the y-axis; equivalent to LT = RotationY(delta) * LT
00276 
00277   HepLorentzRotation & rotateZ(double delta);
00278   // Rotation around the z-axis; equivalent to LT = RotationZ(delta) * LT
00279 
00280   inline HepLorentzRotation & rotate(double delta, const Hep3Vector& axis);
00281   inline HepLorentzRotation & rotate(double delta, const Hep3Vector *axis);
00282   // Rotation around specified vector - LT = Rotation(delta,axis)*LT
00283 
00284   HepLorentzRotation & boostX(double beta);
00285   // Pure boost along the x-axis; equivalent to LT = BoostX(beta) * LT
00286 
00287   HepLorentzRotation & boostY(double beta);
00288   // Pure boost along the y-axis; equivalent to LT = BoostX(beta) * LT
00289 
00290   HepLorentzRotation & boostZ(double beta);
00291   // Pure boost along the z-axis; equivalent to LT = BoostX(beta) * LT
00292 
00293   inline HepLorentzRotation & boost(double, double, double);
00294   inline HepLorentzRotation & boost(const Hep3Vector &);
00295   // Lorenz boost.
00296 
00297   inline HepLorentzRotation inverse() const;
00298   // Return the inverse.
00299 
00300   inline friend HepLorentzRotation inverseOf 
00301                                         ( const Hep4RotationInterface & lt );
00302   // global method to invert.
00303 
00304   inline HepLorentzRotation & invert();
00305   // Inverts the LorentzRotation matrix.
00306 
00307   // ---------- I/O:
00308 
00309   HepStd::ostream & print( HepStd::ostream & os ) const;
00310   // Aligned six-digit-accurate output of the transformation matrix. 
00311 
00312   // ---------- Tolerance
00313 
00314   static inline double getTolerance();
00315   static inline double setTolerance(double tol); 
00316 
00317   friend HepLorentzRotation inverseOf ( const HepLorentzRotation & lt );
00318 
00319 protected:
00320 
00321   inline HepLorentzRotation
00322        (double mxx, double mxy, double mxz, double mxt,
00323         double myx, double myy, double myz, double myt,
00324         double mzx, double mzy, double mzz, double mzt,
00325         double mtx, double mty, double mtz, double mtt);
00326   // Protected constructor.
00327   // DOES NOT CHECK FOR VALIDITY AS A LORENTZ TRANSFORMATION.
00328 
00329   inline void setBoost(double, double, double);
00330   // Set elements according to a boost vector.
00331 
00332   double mxx, mxy, mxz, mxt,
00333             myx, myy, myz, myt,
00334             mzx, mzy, mzz, mzt,
00335             mtx, mty, mtz, mtt;
00336   // The matrix elements.
00337 
00338 };
00339 
00340 #ifdef HEP_NO_INLINE_IN_DECLARATION
00341 #undef inline
00342 #endif
00343 
00344 #ifdef HEP_SHORT_NAMES
00345 typedef HepLorentzRotation LRotation;
00346 #endif
00347 
00348 #ifndef HEP_DEBUG_INLINE
00349 #include "CLHEP/Vector/LorentzRotation.icc"
00350 #endif
00351 
00352 #endif /* HEP_LORENTZROTATION_H */
00353 

Class Library for High Energy Physics (version 1.8)