BoostY.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 HepBoostY class.
00007 //
00008 
00009 #ifdef GNUPRAGMA
00010 #pragma implementation
00011 #endif
00012 
00013 #include "CLHEP/Vector/BoostY.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 HepBoostY & HepBoostY::set (double bbeta) {
00023   double b2 = bbeta*bbeta;
00024   if (b2 >= 1) {
00025     std::cerr << "HepBoostY::set() - "
00026       << "Beta supplied to set HepBoostY 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 HepBoostY::rep4x4() const {
00039   double bg = beta_*gamma_;
00040   return HepRep4x4(   1,      0,    0,    0, 
00041                       0,    gamma_, 0,    bg,
00042                       0,      0,    1,    0,
00043                       0,     bg,    0,  gamma_ );
00044 }
00045 
00046 HepRep4x4Symmetric HepBoostY::rep4x4Symmetric() const {
00047   double bg = beta_*gamma_;
00048   return HepRep4x4Symmetric (   1,      0,    0,    0, 
00049                                       gamma_, 0,    bg,
00050                                               1,    0,
00051                                                   gamma_ );
00052 }
00053 
00054 // ----------  Decomposition:
00055 
00056 void HepBoostY::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 HepBoostY::decompose (HepAxisAngle & rotation, Hep3Vector & boost) const {
00064   rotation = HepAxisAngle();
00065   boost = boostVector();
00066 }
00067 
00068 void HepBoostY::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 HepBoostY::decompose (Hep3Vector & boost, HepAxisAngle & rotation) const {
00076   rotation = HepAxisAngle();
00077   boost = boostVector();
00078 }
00079 
00080 // ----------  Comparisons:
00081 
00082 double HepBoostY::distance2( const HepBoost & b ) const {
00083   return b.distance2(*this);
00084 }
00085 
00086 double HepBoostY::distance2( const HepRotation & r ) const {
00087   double db2 = norm2();
00088   double dr2  = r.norm2();
00089   return (db2 + dr2);
00090 }
00091 
00092 double HepBoostY::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 HepBoostY::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 HepBoostY::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 HepBoostY::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 BoostY 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 HepBoostY HepBoostY::operator * (const HepBoostY & b) const {
00139   return HepBoostY ( (beta()+b.beta()) / (1+beta()*b.beta()) );
00140 }
00141 HepLorentzRotation HepBoostY::operator * (const HepBoost & b) const {
00142   HepLorentzRotation me (*this);
00143   return me*b;
00144 }
00145 HepLorentzRotation HepBoostY::operator * (const HepRotation & r) const {
00146   HepLorentzRotation me (*this);
00147   return me*r;
00148 }
00149 HepLorentzRotation HepBoostY::operator * (const HepLorentzRotation & lt) const {
00150   HepLorentzRotation me (*this);
00151   return me*lt;
00152 }
00153  
00154 // ---------- I/O
00155  
00156 std::ostream & HepBoostY::print( std::ostream & os ) const {
00157   os << "Boost in Y 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