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