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

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