BoostX.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // ---------------------------------------------------------------------------
00003 //
00004 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00005 //
00006 // This is the implementation of the HepBoostX class.
00007 //
00008 
00009 #ifdef GNUPRAGMA
00010 #pragma implementation
00011 #endif
00012 
00013 #include "CLHEP/Vector/BoostX.h"
00014 #include "CLHEP/Vector/Boost.h"
00015 #include "CLHEP/Vector/Rotation.h"
00016 #include "CLHEP/Vector/LorentzRotation.h"
00017 
00018 namespace CLHEP  {
00019 
00020 
00021 // ----------  Constructors and Assignment:
00022 
00023 HepBoostX & HepBoostX::set (double bbeta) {
00024   double b2 = bbeta*bbeta;
00025   if (b2 >= 1) {
00026     std::cerr << "HepBoostX::set() - "
00027       << "Beta supplied to set HepBoostX represents speed >= c." << std::endl;
00028     beta_  = 1.0 - 1.0E-8;              // NaN-proofing
00029     gamma_ = 1.0 / std::sqrt(1.0 - b2);
00030     return *this;
00031   }    
00032   beta_  = bbeta;
00033   gamma_ = 1.0 / std::sqrt(1.0 - b2);
00034   return *this;
00035 }
00036 
00037 // ----------  Accessors:
00038 
00039 HepRep4x4 HepBoostX::rep4x4() const {
00040   double bg = beta_*gamma_;
00041   return HepRep4x4( gamma_,   0,    0,    bg,
00042                       0,      1,    0,    0,
00043                       0,      0,    1,    0,
00044                      bg,      0,    0,  gamma_ );
00045 }
00046 
00047 HepRep4x4Symmetric HepBoostX::rep4x4Symmetric() const {
00048   double bg = beta_*gamma_;
00049   return HepRep4x4Symmetric( gamma_,   0,    0,    bg,
00050                                        1,    0,    0,
00051                                              1,    0,
00052                                                  gamma_ );
00053 }
00054 
00055 // ----------  Decomposition:
00056 
00057 void HepBoostX::decompose (HepRotation & rotation, HepBoost & boost) const {
00058   HepAxisAngle vdelta = HepAxisAngle();
00059   rotation = HepRotation(vdelta);
00060   Hep3Vector bbeta = boostVector();
00061   boost = HepBoost(bbeta);
00062 }
00063 
00064 void HepBoostX::decompose (HepAxisAngle & rotation, Hep3Vector & boost) const {
00065   rotation = HepAxisAngle();
00066   boost = boostVector();
00067 }
00068 
00069 void HepBoostX::decompose (HepBoost & boost, HepRotation & rotation) const {
00070   HepAxisAngle vdelta = HepAxisAngle();
00071   rotation = HepRotation(vdelta);
00072   Hep3Vector bbeta = boostVector();
00073   boost = HepBoost(bbeta);
00074 }
00075 
00076 void HepBoostX::decompose (Hep3Vector & boost, HepAxisAngle & rotation) const {
00077   rotation = HepAxisAngle();
00078   boost = boostVector();
00079 }
00080 
00081 // ----------  Comparisons:
00082 
00083 double HepBoostX::distance2( const HepBoost & b ) const {
00084   return b.distance2(*this);
00085 }
00086 
00087 double HepBoostX::distance2( const HepRotation & r ) const {
00088   double db2 = norm2();
00089   double dr2  = r.norm2();
00090   return (db2 + dr2);
00091 }
00092 
00093 double HepBoostX::distance2( const HepLorentzRotation & lt ) const {
00094   HepBoost b1;
00095   HepRotation r1;
00096   lt.decompose(b1,r1);
00097   double db2 = distance2(b1);
00098   double dr2  = r1.norm2();
00099   return (db2 + dr2);
00100 }
00101 
00102 bool HepBoostX::isNear (const HepRotation & r, double epsilon) const {
00103   double db2 = norm2();
00104   if (db2 > epsilon*epsilon) return false;
00105   double dr2  = r.norm2();
00106   return (db2+dr2 <= epsilon*epsilon);
00107 }
00108 
00109 bool HepBoostX::isNear ( const HepLorentzRotation & lt,
00110                                      double epsilon) const {
00111   HepBoost b1;
00112   HepRotation r1;
00113   double db2 = distance2(b1);
00114   lt.decompose(b1,r1);
00115   if (db2 > epsilon*epsilon) return false;
00116   double dr2  = r1.norm2();
00117   return (db2 + dr2);
00118 }
00119 
00120 // ----------  Properties:
00121 
00122 void HepBoostX::rectify() {
00123   // Assuming the representation of this is close to a true pure boost,
00124   // but may have drifted due to round-off error from many operations,
00125   // this forms an "exact" pure boostX matrix for again.
00126   
00127   double b2 = beta_*beta_;
00128   if (b2 >= 1) {
00129     beta_ = 1.0 - 1.0e-8;               // NaN-proofing
00130     b2 = beta_*beta_;
00131   } 
00132   gamma_ = 1.0 / std::sqrt(1.0 - b2);
00133 }
00134 
00135 // ---------- Application:
00136 
00137 // ---------- Operations in the group of 4-Rotations
00138 
00139 HepBoostX HepBoostX::operator * (const HepBoostX & b) const {
00140   return HepBoostX ( (beta()+b.beta()) / (1+beta()*b.beta()) );
00141 }
00142 HepLorentzRotation HepBoostX::operator * (const HepBoost & b) const {
00143   HepLorentzRotation me (*this);
00144   return me*b;
00145 }
00146 HepLorentzRotation HepBoostX::operator * (const HepRotation & r) const {
00147   HepLorentzRotation me (*this);
00148   return me*r;
00149 }
00150 HepLorentzRotation HepBoostX::operator * (const HepLorentzRotation & lt) const {
00151   HepLorentzRotation me (*this);
00152   return me*lt;
00153 }
00154 
00155 // ---------- I/O:
00156  
00157 std::ostream & HepBoostX::print( std::ostream & os ) const {
00158   os << "Boost in X direction (beta = " << beta_ 
00159                         << ", gamma = " << gamma_ << ") ";
00160   return os;
00161 }
00162 
00163 }  // namespace CLHEP

Generated on Mon May 27 17:47:34 2013 for Geant4 by  doxygen 1.4.7