CLHEP/Vector/RotationInterfaces.h

00001 // -*- C++ -*-
00002 // CLASSDOC OFF
00003 // ---------------------------------------------------------------------------
00004 // CLASSDOC ON
00005 
00006 #ifndef HEP_ROTATION_INTERFACES_H
00007 #define HEP_ROTATION_INTERFACES_H
00008 
00009 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00010 //
00011 // This contains the definition of two abstract interface classes:
00012 // Hep4RotationInterface 
00013 // Hep3RotationInterface.  
00014 // However, these are mostly for defining methods which should be present in
00015 // any 4- or 3-rotation class, however specialized.  The actual classes do
00016 // not inherit from these.  The virtual function overhead turns out 
00017 // to be too steep for that to be practical.
00018 //
00019 // It may be desirable in the future to turn these classes into constraints
00020 // in the Stroustrup sense, so as to enforce this interface, still without 
00021 // inheritance.  However, they do contain an important static:
00022 // static double tolerance to set criteria for relative nearness.
00023 //
00024 // This file also defines structs 
00025 // HepRep3x3;
00026 // HepRep4x4;
00027 // HepRep4x4Symmetric;
00028 // which are used by various Rotation classes.
00029 // 
00030 // Hep4RotationInterface 
00031 //      contains all the methods to get attributes of either a
00032 //      HepLorentzRotation or a HepRotation -- any information 
00033 //      that pertains to a LorentzRotation can also be defined
00034 //      for a HepRotation.(For example, the 4x4 representation
00035 //      would just have 0's in the space-time entries and 1 in
00036 //      the time-time entry.) 
00037 //
00038 // Hep3RotationInterface 
00039 //      inherits from Hep4RotationInterface,  and adds methods
00040 //      which are well-defined only in the case of a Rotation.
00041 //      For example, a 3x3 representation is an attribute only
00042 //      if the generic LorentzRotation involves no boost.
00043 //
00044 // In terms of classes in the ZOOM PhysicsVectors package, 
00045 //      Hep4RotationInterface <--> LorentzTransformationInterface
00046 //      Hep3RotationInterface <--> RotationInterface
00047 //
00048 // Hep4RotationInterface defines the required methods for:
00049 //      HepLorentzRotation
00050 //      HepBoost
00051 //      HepBoostX
00052 //      HepBoostY
00053 //      HepBoostZ
00054 //
00055 // Hep3RotationInterface defines the required methods for:
00056 //      HepRotation
00057 //      HepRotationX
00058 //      HepRotationY
00059 //      HepRotationZ
00060 //
00061 // .SS See Also
00062 // Rotation.h, LorentzRotation.h
00063 //
00064 // .SS Author
00065 // Mark Fischler
00066 //
00067 
00068 #include "CLHEP/config/CLHEP.h"
00069 
00070 #ifdef HEP_NO_INLINE_IN_DECLARATION
00071 #define inline
00072 #endif
00073 
00074 #include "CLHEP/Vector/ThreeVector.h"
00075 #include "CLHEP/Vector/LorentzVector.h"
00076 #include "CLHEP/Vector/AxisAngle.h"
00077 
00078 struct HepRep3x3;
00079 struct HepRep4x4;
00080 struct HepRep4x4Symmetric;
00081 
00082 class HepRotation;
00083 class HepRotationX;
00084 class HepRotationY;
00085 class HepRotationZ;
00086 class HepLorentzRotation;
00087 class HepBoost;
00088 class HepBoostX;
00089 class HepBoostY;
00090 class HepBoostZ;
00091 
00092 
00093 //-******************************
00094 //
00095 // Hep4RotationInterface 
00096 //
00097 //-******************************
00098 
00103 class Hep4RotationInterface  {
00104 
00105   // All attributes of shared by HepLorentzRotation, HepBoost, 
00106   // HepBoostX, HepBoostY, HepBoostZ.  HepRotation, HepRotationX, 
00107   // HepRotationY, HepRotationZ also share this attribute interface.
00108 
00109   friend class  HepRotation;
00110   friend class  HepRotationX;
00111   friend class  HepRotationY;
00112   friend class  HepRotationZ;
00113   friend class  HepLorentzRotation;
00114   friend class  HepBoost;
00115   friend class  HepBoostX;
00116   friend class  HepBoostY;
00117   friend class  HepBoostZ;
00118 
00119 public:
00120 
00121   static double tolerance;        // to determine relative nearness
00122 
00123   // ----------  Accessors:
00124 
00125 #ifdef ONLY_IN_CONCRETE_CLASSES
00126   //  orthosymplectic 4-vectors:
00127   HepLorentzVector col1() const;
00128   HepLorentzVector col2() const;
00129   HepLorentzVector col3() const;
00130   HepLorentzVector col4() const;
00131   HepLorentzVector row1() const;
00132   HepLorentzVector row2() const;
00133   HepLorentzVector row3() const;
00134   HepLorentzVector row4() const;
00135 
00136   //  individual elements:
00137   double xx() const  ;
00138   double xy() const  ;
00139   double xz() const  ;
00140   double xt() const  ;
00141   double yx() const  ;
00142   double yy() const  ;
00143   double yz() const  ;
00144   double yt() const  ;
00145   double zx() const  ;
00146   double zy() const  ;
00147   double zz() const  ;
00148   double zt() const  ;
00149   double tx() const  ;
00150   double ty() const  ;
00151   double tz() const  ;
00152   double tt() const  ;
00153 
00154   //   4x4 representation:
00155 //HepRep4x4 rep4x4() const;     JMM  Declared here but not defined anywhere!
00156 
00157   // ----------  Operations:
00158   //   comparisons:
00159 
00160   inline int compare( const Hep4RotationInterface & lt ) const;
00161   // Dictionary-order comparisons, utilizing the decompose(b,r) method
00162 
00163   //   decomposition:
00164 
00165   void decompose (HepAxisAngle & rotation, Hep3Vector & boost)const;
00166   // Decompose as T= R * B, where R is pure rotation, B is pure boost.
00167 
00168   void decompose (Hep3Vector & boost, HepAxisAngle & rotation)const;
00169   // Decompose as T= B * R, where R is pure rotation, B is pure boost.
00170 
00171   bool operator == (const Hep4RotationInterface & r) const;
00172   bool operator != (const Hep4RotationInterface & r) const;
00173 
00174   //   relative comparison:
00175 
00176   double norm2() const  ;
00177   double  distance2( const Hep4RotationInterface & lt ) const  ;
00178   double  howNear( const Hep4RotationInterface & lt ) const  ;
00179   bool isNear (const Hep4RotationInterface & lt, 
00180                                    double epsilon=tolerance) const  ;
00181 
00182   void rectify()  ;
00183   // non-const but logically const correction for accumulated roundoff errors
00184 
00185   // ----------  Apply LorentzTransformations:
00186 
00187   HepLorentzVector operator* ( const HepLorentzVector & w ) const  ;
00188   HepLorentzVector operator()( const HepLorentzVector & w ) const  ;
00189   // Apply to a 4-vector
00190 
00191   // ----------  I/O:
00192 
00193   HepStd::ostream & print( HepStd::ostream & os ) const;
00194 
00195 #endif /* ONLY_IN_CONCRETE_CLASSES */
00196 
00197   static double getTolerance();
00198   static double setTolerance( double tol );
00199 
00200   enum { ToleranceTicks = 100 };
00201 
00202 protected:
00203 
00204   ~Hep4RotationInterface();     // protect destructor to forbid instatiation
00205 
00206 };  // Hep4RotationInterface
00207 
00208 
00209 
00210 //-******************************
00211 //
00212 // Hep3RotationInterface 
00213 //
00214 //-******************************
00215 
00220 class Hep3RotationInterface : public Hep4RotationInterface {
00221 
00222   // All attributes of HepRotation, HepRotationX, HepRotationY, HepRotationZ
00223   // beyond those available by virtue of being a Hep3RotationInterface.
00224 
00225   friend class  HepRotation;
00226   friend class  HepRotationX;
00227   friend class  HepRotationY;
00228   friend class  HepRotationZ;
00229 
00230 public:
00231 
00232 #ifdef ONLY_IN_CONCRETE_CLASSES
00233 
00234   //   Euler angles:
00235   double getPhi  () const  ;
00236   double getTheta() const  ;
00237   double getPsi  () const  ;
00238   double    phi  () const  ;
00239   double    theta() const  ;
00240   double    psi  () const  ;
00241   HepEulerAngles eulerAngles() const  ;
00242 
00243   //   axis & angle of rotation:
00244   double  getDelta() const  ;
00245   Hep3Vector getAxis () const  ;
00246   double     delta() const  ;
00247   Hep3Vector    axis () const  ;
00248   HepAxisAngle axisAngle() const  ;
00249 
00250   //   orthogonal unit-length vectors:
00251   Hep3Vector rowX() const;
00252   Hep3Vector rowY() const;
00253   Hep3Vector rowZ() const;
00254 
00255   Hep3Vector colX() const;
00256   Hep3Vector colY() const;
00257   Hep3Vector colZ() const;
00258 
00259 //HepRep3x3 rep3x3() const;     JMM  Declared here but not defined anywhere!
00260   //   3x3 representation
00261 
00262   //  orthosymplectic 4-vectors treating this as a 4-rotation:
00263   HepLorentzVector col1() const;
00264   HepLorentzVector col2() const;
00265   HepLorentzVector col3() const;
00266   HepLorentzVector col4() const;
00267   HepLorentzVector row1() const;
00268   HepLorentzVector row2() const;
00269   HepLorentzVector row3() const;
00270   HepLorentzVector row4() const;
00271 
00272   //  individual elements treating this as a 4-rotation:
00273   double xt() const; 
00274   double yt() const; 
00275   double zt() const; 
00276   double tx() const; 
00277   double ty() const;
00278   double tz() const;
00279   double tt() const;
00280 
00281   // ---------- Operations in the Rotation group
00282 
00283   HepRotation operator * ( const Hep3RotationInterface & r ) const  ;
00284 
00285   // ---------- Application
00286 
00287   HepLorentzVector operator* ( const HepLorentzVector & w ) const  ;
00288   HepLorentzVector operator()( const HepLorentzVector & w ) const  ;
00289   //   apply to HepLorentzVector
00290 
00291   Hep3Vector operator* ( const Hep3Vector & v ) const  ;
00292   Hep3Vector operator()( const Hep3Vector & v ) const  ;
00293   //   apply to Hep3Vector
00294 
00295   // ---------- I/O and a helper method
00296 
00297   HepStd::ostream & print( HepStd::ostream & os ) const;
00298 
00299 #endif /* ONLY_IN_CONCRETE_CLASSES */
00300 
00301 private:
00302 
00303   ~Hep3RotationInterface();     // private destructor to forbid instatiation
00304 
00305 };  // Hep3RotationInterface
00306 
00307 
00308 //-***************************
00309 // 3x3 and 4x4 representations
00310 //-***************************
00311 
00312 struct HepRep3x3 {
00313 
00314   // -----  Constructors:
00315 
00316   inline HepRep3x3();
00317 
00318   inline HepRep3x3(  double xx, double xy, double xz
00319                    , double yx, double yy, double yz
00320                    , double zx, double zy, double zz
00321                    );
00322 
00323   inline HepRep3x3( const double * array );
00324   // construct from an array of doubles, holding the rotation matrix
00325   // in ROW order (xx, xy, ...)
00326 
00327   inline void setToIdentity();
00328 
00329   // -----  The data members are public:
00330   double xx_, xy_, xz_,
00331             yx_, yy_, yz_,
00332             zx_, zy_, zz_;
00333 
00334   inline void getArray ( double * array ) const;
00335   // fill array with the NINE doubles xx, xy, xz ... zz
00336 
00337 };  // HepRep3x3
00338 
00339 struct HepRep4x4 {
00340 
00341   // -----  Constructors:
00342   inline HepRep4x4();
00343 
00344   inline HepRep4x4(  double xx, double xy, double xz, double xt
00345                    , double yx, double yy, double yz, double yt
00346                    , double zx, double zy, double zz, double zt
00347                    , double tx, double ty, double tz, double tt
00348                    );
00349 
00350   inline HepRep4x4( const HepRep4x4Symmetric & rep );
00351 
00352   inline HepRep4x4( const double * array );
00353   // construct from an array of doubles, holding the transformation matrix
00354   // in ROW order xx, xy, ...
00355 
00356   inline void setToIdentity();
00357 
00358   // -----  The data members are public:
00359   double xx_, xy_, xz_, xt_,
00360             yx_, yy_, yz_, yt_,
00361             zx_, zy_, zz_, zt_,
00362             tx_, ty_, tz_, tt_;
00363                          
00364   inline void getArray ( double * array ) const;
00365   // fill array with the SIXTEEN doubles xx, xy, xz ... tz, tt
00366 
00367   inline bool operator==(HepRep4x4 const & r) const;
00368   inline bool operator!=(HepRep4x4 const & r) const;
00369 
00370 
00371 };  // HepRep4x4
00372 
00373 struct HepRep4x4Symmetric {
00374 
00375   // -----  Constructors:
00376 
00377   inline HepRep4x4Symmetric();
00378 
00379   inline HepRep4x4Symmetric
00380         ( double xx, double xy, double xz, double xt
00381                       , double yy, double yz, double yt
00382                                     , double zz, double zt
00383                                                   , double tt );
00384 
00385   inline HepRep4x4Symmetric( const double * array );
00386   // construct from an array of doubles, holding the transformation matrix
00387   // elements in this order:  xx, xy, xz, xt, yy, yz, yt, zz, zt, tt
00388 
00389   inline void setToIdentity();
00390 
00391   // -----  The data members are public:
00392   double xx_, xy_, xz_, xt_,
00393                  yy_, yz_, yt_,
00394                       zz_, zt_,
00395                            tt_;
00396 
00397   inline void getArray ( double * array ) const;
00398   // fill array with the TEN doubles xx, xy, xz, xt, yy, yz, yt, zz, zt, tt
00399 
00400 };
00401 
00402 #ifndef HEP_DEBUG_INLINE
00403 #include "CLHEP/Vector/RotationInterfaces.icc"
00404 #endif
00405 
00406 #endif // ROTATION_INTERFACES_H

Class Library for High Energy Physics (version 1.8)