Geant4 Cross Reference |
1 // -*- C++ -*- 1 // -*- C++ -*- 2 // ------------------------------------------- 2 // --------------------------------------------------------------------------- 3 // 3 // 4 // This file is a part of the CLHEP - a Class 4 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 5 // 5 // 6 // This is the implementation of the HepBoostX 6 // This is the implementation of the HepBoostX class. 7 // 7 // 8 8 9 #include "CLHEP/Vector/BoostX.h" 9 #include "CLHEP/Vector/BoostX.h" 10 #include "CLHEP/Vector/Boost.h" 10 #include "CLHEP/Vector/Boost.h" 11 #include "CLHEP/Vector/Rotation.h" 11 #include "CLHEP/Vector/Rotation.h" 12 #include "CLHEP/Vector/LorentzRotation.h" 12 #include "CLHEP/Vector/LorentzRotation.h" 13 13 14 #include <cmath> 14 #include <cmath> 15 #include <iostream> 15 #include <iostream> 16 16 17 namespace CLHEP { 17 namespace CLHEP { 18 18 19 19 20 // ---------- Constructors and Assignment: 20 // ---------- Constructors and Assignment: 21 21 22 HepBoostX & HepBoostX::set (double bbeta) { 22 HepBoostX & HepBoostX::set (double bbeta) { 23 double b2 = bbeta*bbeta; 23 double b2 = bbeta*bbeta; 24 if (b2 >= 1) { 24 if (b2 >= 1) { 25 std::cerr << "HepBoostX::set() - " 25 std::cerr << "HepBoostX::set() - " 26 << "Beta supplied to set HepBoostX repre 26 << "Beta supplied to set HepBoostX represents speed >= c." << std::endl; 27 beta_ = 1.0 - 1.0E-8; // NaN-proofing 27 beta_ = 1.0 - 1.0E-8; // NaN-proofing 28 gamma_ = 1.0 / std::sqrt(1.0 - b2); 28 gamma_ = 1.0 / std::sqrt(1.0 - b2); 29 return *this; 29 return *this; 30 } 30 } 31 beta_ = bbeta; 31 beta_ = bbeta; 32 gamma_ = 1.0 / std::sqrt(1.0 - b2); 32 gamma_ = 1.0 / std::sqrt(1.0 - b2); 33 return *this; 33 return *this; 34 } 34 } 35 35 36 // ---------- Accessors: 36 // ---------- Accessors: 37 37 38 HepRep4x4 HepBoostX::rep4x4() const { 38 HepRep4x4 HepBoostX::rep4x4() const { 39 double bg = beta_*gamma_; 39 double bg = beta_*gamma_; 40 return HepRep4x4( gamma_, 0, 0, bg, 40 return HepRep4x4( gamma_, 0, 0, bg, 41 0, 1, 0, 0, 41 0, 1, 0, 0, 42 0, 0, 1, 0, 42 0, 0, 1, 0, 43 bg, 0, 0, gamma_ 43 bg, 0, 0, gamma_ ); 44 } 44 } 45 45 46 HepRep4x4Symmetric HepBoostX::rep4x4Symmetric( 46 HepRep4x4Symmetric HepBoostX::rep4x4Symmetric() const { 47 double bg = beta_*gamma_; 47 double bg = beta_*gamma_; 48 return HepRep4x4Symmetric( gamma_, 0, 0 48 return HepRep4x4Symmetric( gamma_, 0, 0, bg, 49 1, 0, 49 1, 0, 0, 50 1, 50 1, 0, 51 gam 51 gamma_ ); 52 } 52 } 53 53 54 // ---------- Decomposition: 54 // ---------- Decomposition: 55 55 56 void HepBoostX::decompose (HepRotation & rotat 56 void HepBoostX::decompose (HepRotation & rotation, HepBoost & boost) const { 57 HepAxisAngle vdelta = HepAxisAngle(); 57 HepAxisAngle vdelta = HepAxisAngle(); 58 rotation = HepRotation(vdelta); 58 rotation = HepRotation(vdelta); 59 Hep3Vector bbeta = boostVector(); 59 Hep3Vector bbeta = boostVector(); 60 boost = HepBoost(bbeta); 60 boost = HepBoost(bbeta); 61 } 61 } 62 62 63 void HepBoostX::decompose (HepAxisAngle & rota 63 void HepBoostX::decompose (HepAxisAngle & rotation, Hep3Vector & boost) const { 64 rotation = HepAxisAngle(); 64 rotation = HepAxisAngle(); 65 boost = boostVector(); 65 boost = boostVector(); 66 } 66 } 67 67 68 void HepBoostX::decompose (HepBoost & boost, H 68 void HepBoostX::decompose (HepBoost & boost, HepRotation & rotation) const { 69 HepAxisAngle vdelta = HepAxisAngle(); 69 HepAxisAngle vdelta = HepAxisAngle(); 70 rotation = HepRotation(vdelta); 70 rotation = HepRotation(vdelta); 71 Hep3Vector bbeta = boostVector(); 71 Hep3Vector bbeta = boostVector(); 72 boost = HepBoost(bbeta); 72 boost = HepBoost(bbeta); 73 } 73 } 74 74 75 void HepBoostX::decompose (Hep3Vector & boost, 75 void HepBoostX::decompose (Hep3Vector & boost, HepAxisAngle & rotation) const { 76 rotation = HepAxisAngle(); 76 rotation = HepAxisAngle(); 77 boost = boostVector(); 77 boost = boostVector(); 78 } 78 } 79 79 80 // ---------- Comparisons: 80 // ---------- Comparisons: 81 81 82 double HepBoostX::distance2( const HepBoost & 82 double HepBoostX::distance2( const HepBoost & b ) const { 83 return b.distance2(*this); 83 return b.distance2(*this); 84 } 84 } 85 85 86 double HepBoostX::distance2( const HepRotation 86 double HepBoostX::distance2( const HepRotation & r ) const { 87 double db2 = norm2(); 87 double db2 = norm2(); 88 double dr2 = r.norm2(); 88 double dr2 = r.norm2(); 89 return (db2 + dr2); 89 return (db2 + dr2); 90 } 90 } 91 91 92 double HepBoostX::distance2( const HepLorentzR 92 double HepBoostX::distance2( const HepLorentzRotation & lt ) const { 93 HepBoost b1; 93 HepBoost b1; 94 HepRotation r1; 94 HepRotation r1; 95 lt.decompose(b1,r1); 95 lt.decompose(b1,r1); 96 double db2 = distance2(b1); 96 double db2 = distance2(b1); 97 double dr2 = r1.norm2(); 97 double dr2 = r1.norm2(); 98 return (db2 + dr2); 98 return (db2 + dr2); 99 } 99 } 100 100 101 bool HepBoostX::isNear (const HepRotation & r, 101 bool HepBoostX::isNear (const HepRotation & r, double epsilon) const { 102 double db2 = norm2(); 102 double db2 = norm2(); 103 if (db2 > epsilon*epsilon) return false; 103 if (db2 > epsilon*epsilon) return false; 104 double dr2 = r.norm2(); 104 double dr2 = r.norm2(); 105 return (db2+dr2 <= epsilon*epsilon); 105 return (db2+dr2 <= epsilon*epsilon); 106 } 106 } 107 107 108 bool HepBoostX::isNear ( const HepLorentzRotat 108 bool HepBoostX::isNear ( const HepLorentzRotation & lt, 109 double epsilon) const { 109 double epsilon) const { 110 HepBoost b1; 110 HepBoost b1; 111 HepRotation r1; 111 HepRotation r1; 112 double db2 = distance2(b1); 112 double db2 = distance2(b1); 113 lt.decompose(b1,r1); 113 lt.decompose(b1,r1); 114 if (db2 > epsilon*epsilon) return false; 114 if (db2 > epsilon*epsilon) return false; 115 double dr2 = r1.norm2(); 115 double dr2 = r1.norm2(); 116 return (db2 + dr2); 116 return (db2 + dr2); 117 } 117 } 118 118 119 // ---------- Properties: 119 // ---------- Properties: 120 120 121 void HepBoostX::rectify() { 121 void HepBoostX::rectify() { 122 // Assuming the representation of this is cl 122 // Assuming the representation of this is close to a true pure boost, 123 // but may have drifted due to round-off err 123 // but may have drifted due to round-off error from many operations, 124 // this forms an "exact" pure boostX matrix 124 // this forms an "exact" pure boostX matrix for again. 125 125 126 double b2 = beta_*beta_; 126 double b2 = beta_*beta_; 127 if (b2 >= 1) { 127 if (b2 >= 1) { 128 beta_ = 1.0 - 1.0e-8; // NaN-proofing 128 beta_ = 1.0 - 1.0e-8; // NaN-proofing 129 b2 = beta_*beta_; 129 b2 = beta_*beta_; 130 } 130 } 131 gamma_ = 1.0 / std::sqrt(1.0 - b2); 131 gamma_ = 1.0 / std::sqrt(1.0 - b2); 132 } 132 } 133 133 134 // ---------- Application: 134 // ---------- Application: 135 135 136 // ---------- Operations in the group of 4-Rot 136 // ---------- Operations in the group of 4-Rotations 137 137 138 HepBoostX HepBoostX::operator * (const HepBoos 138 HepBoostX HepBoostX::operator * (const HepBoostX & b) const { 139 return HepBoostX ( (beta()+b.beta()) / (1+be 139 return HepBoostX ( (beta()+b.beta()) / (1+beta()*b.beta()) ); 140 } 140 } 141 HepLorentzRotation HepBoostX::operator * (cons 141 HepLorentzRotation HepBoostX::operator * (const HepBoost & b) const { 142 HepLorentzRotation me (*this); 142 HepLorentzRotation me (*this); 143 return me*b; 143 return me*b; 144 } 144 } 145 HepLorentzRotation HepBoostX::operator * (cons 145 HepLorentzRotation HepBoostX::operator * (const HepRotation & r) const { 146 HepLorentzRotation me (*this); 146 HepLorentzRotation me (*this); 147 return me*r; 147 return me*r; 148 } 148 } 149 HepLorentzRotation HepBoostX::operator * (cons 149 HepLorentzRotation HepBoostX::operator * (const HepLorentzRotation & lt) const { 150 HepLorentzRotation me (*this); 150 HepLorentzRotation me (*this); 151 return me*lt; 151 return me*lt; 152 } 152 } 153 153 154 // ---------- I/O: 154 // ---------- I/O: 155 155 156 std::ostream & HepBoostX::print( std::ostream 156 std::ostream & HepBoostX::print( std::ostream & os ) const { 157 os << "Boost in X direction (beta = " << bet 157 os << "Boost in X direction (beta = " << beta_ 158 << ", gamma = " << gamma_ << ") "; 158 << ", gamma = " << gamma_ << ") "; 159 return os; 159 return os; 160 } 160 } 161 161 162 } // namespace CLHEP 162 } // namespace CLHEP 163 163