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 methods of th 6 // This is the implementation of methods of the HepRotationY class which 7 // were introduced when ZOOM PhysicsVectors wa 7 // were introduced when ZOOM PhysicsVectors was merged in. 8 // 8 // 9 9 10 #include "CLHEP/Vector/RotationY.h" 10 #include "CLHEP/Vector/RotationY.h" 11 #include "CLHEP/Vector/AxisAngle.h" 11 #include "CLHEP/Vector/AxisAngle.h" 12 #include "CLHEP/Vector/EulerAngles.h" 12 #include "CLHEP/Vector/EulerAngles.h" 13 #include "CLHEP/Vector/LorentzRotation.h" 13 #include "CLHEP/Vector/LorentzRotation.h" 14 #include "CLHEP/Units/PhysicalConstants.h" 14 #include "CLHEP/Units/PhysicalConstants.h" 15 15 16 #include <cmath> 16 #include <cmath> 17 #include <stdlib.h> 17 #include <stdlib.h> 18 #include <iostream> 18 #include <iostream> 19 19 20 namespace CLHEP { 20 namespace CLHEP { 21 21 22 static inline double safe_acos (double x) { 22 static inline double safe_acos (double x) { 23 if (std::abs(x) <= 1.0) return std::acos(x); 23 if (std::abs(x) <= 1.0) return std::acos(x); 24 return ( (x>0) ? 0 : CLHEP::pi ); 24 return ( (x>0) ? 0 : CLHEP::pi ); 25 } 25 } 26 26 27 HepRotationY::HepRotationY(double ddelta) : 27 HepRotationY::HepRotationY(double ddelta) : 28 its_d(proper(ddelta)), its_s(std::sin(ddel 28 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta)) 29 {} 29 {} 30 30 31 HepRotationY & HepRotationY::set ( double ddel 31 HepRotationY & HepRotationY::set ( double ddelta ) { 32 its_d = proper(ddelta); 32 its_d = proper(ddelta); 33 its_s = std::sin(its_d); 33 its_s = std::sin(its_d); 34 its_c = std::cos(its_d); 34 its_c = std::cos(its_d); 35 return *this; 35 return *this; 36 } 36 } 37 37 38 double HepRotationY::phi() const { 38 double HepRotationY::phi() const { 39 if ( its_d == 0 ) { 39 if ( its_d == 0 ) { 40 return 0; 40 return 0; 41 } else if ( (its_d < 0) || (its_d == CLHEP:: 41 } else if ( (its_d < 0) || (its_d == CLHEP::pi) ) { 42 return +CLHEP::halfpi; 42 return +CLHEP::halfpi; 43 } else { 43 } else { 44 return -CLHEP::halfpi; 44 return -CLHEP::halfpi; 45 } 45 } 46 } // HepRotationY::phi() 46 } // HepRotationY::phi() 47 47 48 double HepRotationY::theta() const { 48 double HepRotationY::theta() const { 49 return std::fabs( its_d ); 49 return std::fabs( its_d ); 50 } // HepRotationY::theta() 50 } // HepRotationY::theta() 51 51 52 double HepRotationY::psi() const { 52 double HepRotationY::psi() const { 53 if ( its_d == 0 ) { 53 if ( its_d == 0 ) { 54 return 0; 54 return 0; 55 } else if ( (its_d < 0) || (its_d == CLHEP:: 55 } else if ( (its_d < 0) || (its_d == CLHEP::pi) ) { 56 return -CLHEP::halfpi; 56 return -CLHEP::halfpi; 57 } else { 57 } else { 58 return +CLHEP::halfpi; 58 return +CLHEP::halfpi; 59 } 59 } 60 } // HepRotationY::psi() 60 } // HepRotationY::psi() 61 61 62 HepEulerAngles HepRotationY::eulerAngles() con 62 HepEulerAngles HepRotationY::eulerAngles() const { 63 return HepEulerAngles( phi(), theta(), ps 63 return HepEulerAngles( phi(), theta(), psi() ); 64 } // HepRotationY::eulerAngles() 64 } // HepRotationY::eulerAngles() 65 65 66 66 67 // From the defining code in the implementatio 67 // From the defining code in the implementation of CLHEP (in Rotation.cc) 68 // it is clear that thetaX, phiX form the pola 68 // it is clear that thetaX, phiX form the polar angles in the original 69 // coordinate system of the new X axis (and si 69 // coordinate system of the new X axis (and similarly for phiY and phiZ). 70 // 70 // 71 // This code is taken directly from the origin 71 // This code is taken directly from the original CLHEP. However, there are as 72 // shown opportunities for significant speed i 72 // shown opportunities for significant speed improvement. 73 73 74 double HepRotationY::phiX() const { 74 double HepRotationY::phiX() const { 75 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : 75 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx()); 76 // or ---- return 0; 76 // or ---- return 0; 77 } 77 } 78 78 79 double HepRotationY::phiY() const { 79 double HepRotationY::phiY() const { 80 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : 80 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy()); 81 // or ---- return CLHEP::halfpi; 81 // or ---- return CLHEP::halfpi; 82 } 82 } 83 83 84 double HepRotationY::phiZ() const { 84 double HepRotationY::phiZ() const { 85 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : 85 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz()); 86 // or ---- return 0; 86 // or ---- return 0; 87 } 87 } 88 88 89 double HepRotationY::thetaX() const { 89 double HepRotationY::thetaX() const { 90 return safe_acos(zx()); 90 return safe_acos(zx()); 91 } 91 } 92 92 93 double HepRotationY::thetaY() const { 93 double HepRotationY::thetaY() const { 94 return safe_acos(zy()); 94 return safe_acos(zy()); 95 // or ---- return CLHEP::halfpi; 95 // or ---- return CLHEP::halfpi; 96 } 96 } 97 97 98 double HepRotationY::thetaZ() const { 98 double HepRotationY::thetaZ() const { 99 return safe_acos(zz()); 99 return safe_acos(zz()); 100 // or ---- return d; 100 // or ---- return d; 101 } 101 } 102 102 103 void HepRotationY::setDelta ( double ddelta ) 103 void HepRotationY::setDelta ( double ddelta ) { 104 set(ddelta); 104 set(ddelta); 105 } 105 } 106 106 107 void HepRotationY::decompose 107 void HepRotationY::decompose 108 (HepAxisAngle & rotation, Hep3Vector & boost 108 (HepAxisAngle & rotation, Hep3Vector & boost) const { 109 boost.set(0,0,0); 109 boost.set(0,0,0); 110 rotation = axisAngle(); 110 rotation = axisAngle(); 111 } 111 } 112 112 113 void HepRotationY::decompose 113 void HepRotationY::decompose 114 (Hep3Vector & boost, HepAxisAngle & rotation 114 (Hep3Vector & boost, HepAxisAngle & rotation) const { 115 boost.set(0,0,0); 115 boost.set(0,0,0); 116 rotation = axisAngle(); 116 rotation = axisAngle(); 117 } 117 } 118 118 119 void HepRotationY::decompose 119 void HepRotationY::decompose 120 (HepRotation & rotation, HepBoost & bo 120 (HepRotation & rotation, HepBoost & boost) const { 121 boost.set(0,0,0); 121 boost.set(0,0,0); 122 rotation = HepRotation(*this); 122 rotation = HepRotation(*this); 123 } 123 } 124 124 125 void HepRotationY::decompose 125 void HepRotationY::decompose 126 (HepBoost & boost, HepRotation & rotat 126 (HepBoost & boost, HepRotation & rotation) const { 127 boost.set(0,0,0); 127 boost.set(0,0,0); 128 rotation = HepRotation(*this); 128 rotation = HepRotation(*this); 129 } 129 } 130 130 131 double HepRotationY::distance2( const HepRotat 131 double HepRotationY::distance2( const HepRotationY & r ) const { 132 double answer = 2.0 * ( 1.0 - ( its_s * r.it 132 double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ; 133 return (answer >= 0) ? answer : 0; 133 return (answer >= 0) ? answer : 0; 134 } 134 } 135 135 136 double HepRotationY::distance2( const HepRotat 136 double HepRotationY::distance2( const HepRotation & r ) const { 137 double sum = xx() * r.xx() + 137 double sum = xx() * r.xx() + xz() * r.xz() 138 + r.yy() 138 + r.yy() 139 + zx() * r.zx() 139 + zx() * r.zx() + zz() * r.zz(); 140 double answer = 3.0 - sum; 140 double answer = 3.0 - sum; 141 return (answer >= 0 ) ? answer : 0; 141 return (answer >= 0 ) ? answer : 0; 142 } 142 } 143 143 144 double HepRotationY::distance2( const HepLoren 144 double HepRotationY::distance2( const HepLorentzRotation & lt ) const { 145 HepAxisAngle a; 145 HepAxisAngle a; 146 Hep3Vector b; 146 Hep3Vector b; 147 lt.decompose(b, a); 147 lt.decompose(b, a); 148 double bet = b.beta(); 148 double bet = b.beta(); 149 double bet2 = bet*bet; 149 double bet2 = bet*bet; 150 HepRotation r(a); 150 HepRotation r(a); 151 return bet2/(1-bet2) + distance2(r); 151 return bet2/(1-bet2) + distance2(r); 152 } 152 } 153 153 154 double HepRotationY::distance2( const HepBoost 154 double HepRotationY::distance2( const HepBoost & lt ) const { 155 return distance2( HepLorentzRotation(lt)); 155 return distance2( HepLorentzRotation(lt)); 156 } 156 } 157 157 158 double HepRotationY::howNear( const HepRotatio 158 double HepRotationY::howNear( const HepRotationY & r ) const { 159 return std::sqrt(distance2(r)); 159 return std::sqrt(distance2(r)); 160 } 160 } 161 double HepRotationY::howNear( const HepRotatio 161 double HepRotationY::howNear( const HepRotation & r ) const { 162 return std::sqrt(distance2(r)); 162 return std::sqrt(distance2(r)); 163 } 163 } 164 double HepRotationY::howNear( const HepBoost & 164 double HepRotationY::howNear( const HepBoost & lt ) const { 165 return std::sqrt(distance2(lt)); 165 return std::sqrt(distance2(lt)); 166 } 166 } 167 double HepRotationY::howNear( const HepLorentz 167 double HepRotationY::howNear( const HepLorentzRotation & lt ) const { 168 return std::sqrt(distance2(lt)); 168 return std::sqrt(distance2(lt)); 169 } 169 } 170 bool HepRotationY::isNear(const HepRotationY & 170 bool HepRotationY::isNear(const HepRotationY & r,double epsilon)const{ 171 return (distance2(r) <= epsilon*epsilon); 171 return (distance2(r) <= epsilon*epsilon); 172 } 172 } 173 bool HepRotationY::isNear(const HepRotation & 173 bool HepRotationY::isNear(const HepRotation & r,double epsilon)const { 174 return (distance2(r) <= epsilon*epsilon); 174 return (distance2(r) <= epsilon*epsilon); 175 } 175 } 176 bool HepRotationY::isNear( const HepBoost & lt 176 bool HepRotationY::isNear( const HepBoost & lt,double epsilon) const { 177 return (distance2(lt) <= epsilon*epsilon); 177 return (distance2(lt) <= epsilon*epsilon); 178 } 178 } 179 bool HepRotationY::isNear( const HepLorentzRot 179 bool HepRotationY::isNear( const HepLorentzRotation & lt, 180 double ep 180 double epsilon) const { 181 return (distance2(lt) <= epsilon*epsilon); 181 return (distance2(lt) <= epsilon*epsilon); 182 } 182 } 183 183 184 double HepRotationY::norm2() const { 184 double HepRotationY::norm2() const { 185 return 2.0 - 2.0 * its_c; 185 return 2.0 - 2.0 * its_c; 186 } 186 } 187 187 188 std::ostream & HepRotationY::print( std::ostre 188 std::ostream & HepRotationY::print( std::ostream & os ) const { 189 os << "\nRotation about Y (" << its_d << 189 os << "\nRotation about Y (" << its_d << 190 ") [cos d = " << its_c << " si 190 ") [cos d = " << its_c << " sin d = " << its_s << "]\n"; 191 return os; 191 return os; 192 } 192 } 193 193 194 } // namespace CLHEP 194 } // namespace CLHEP 195 195