Geant4 Cross Reference |
1 // ------------------------------------------- 1 // ---------------------------------------------------------------------- 2 // 2 // 3 // EulerAngles.cc 3 // EulerAngles.cc 4 // 4 // 5 // Methods for classes, and instances of globa 5 // Methods for classes, and instances of globals, declared in EulerAngles.h 6 // 6 // 7 // History: 7 // History: 8 // 8 // 9 // 04-Dec-1997 MF Stub with just PI 9 // 04-Dec-1997 MF Stub with just PI 10 // 12-Jan-1998 WEB PI now found in ZMutility; 10 // 12-Jan-1998 WEB PI now found in ZMutility; used ZMutility headers 11 // where available 11 // where available 12 // 16-Mar-1998 WEB Corrected ZMpvEulerAnglesR 12 // 16-Mar-1998 WEB Corrected ZMpvEulerAnglesRep 13 // 15-Jun-1998 WEB Added namespace support 13 // 15-Jun-1998 WEB Added namespace support 14 // 26-Jul-2000 MF CLHEP version 14 // 26-Jul-2000 MF CLHEP version 15 // 12-Apr-2001 MF NaN-proofing 15 // 12-Apr-2001 MF NaN-proofing 16 // 19-Nov-2001 MF Correction to ZMpvEulerA 16 // 19-Nov-2001 MF Correction to ZMpvEulerAnglesRep, which was affecting 17 // .isNear(). array[3] had been incorrec 17 // .isNear(). array[3] had been incorrect. 18 // Note - the correct form was used in al 18 // Note - the correct form was used in all other places 19 // including Rotation.set(phi, theta, psi 19 // including Rotation.set(phi, theta, psi). 20 // 20 // 21 // ------------------------------------------- 21 // ---------------------------------------------------------------------- 22 22 23 23 24 #include "CLHEP/Vector/EulerAngles.h" 24 #include "CLHEP/Vector/EulerAngles.h" 25 25 26 #include "CLHEP/Vector/ThreeVector.h" 26 #include "CLHEP/Vector/ThreeVector.h" 27 27 28 #include <cmath> << 29 #include <iostream> 28 #include <iostream> 30 29 31 namespace CLHEP { 30 namespace CLHEP { 32 31 33 //-************* 32 //-************* 34 // static consts 33 // static consts 35 //-************* 34 //-************* 36 35 37 double HepEulerAngles::tolerance = Hep3Vector: 36 double HepEulerAngles::tolerance = Hep3Vector::ToleranceTicks * 1.0e-8; 38 37 39 //-******************* 38 //-******************* 40 // measure of distance 39 // measure of distance 41 //-******************* 40 //-******************* 42 41 43 42 44 static void ZMpvEulerAnglesRep ( const HepEule 43 static void ZMpvEulerAnglesRep ( const HepEulerAngles & ex, double array[] ) { 45 44 46 double sinPhi = std::sin( ex.phi() ) , co 45 double sinPhi = std::sin( ex.phi() ) , cosPhi = std::cos( ex.phi() ); 47 double sinTheta = std::sin( ex.theta() ), co 46 double sinTheta = std::sin( ex.theta() ), cosTheta = std::cos( ex.theta() ); 48 double sinPsi = std::sin( ex.psi() ) , co 47 double sinPsi = std::sin( ex.psi() ) , cosPsi = std::cos( ex.psi() ); 49 48 50 array[0] = cosPsi * cosPhi - sinPsi * co 49 array[0] = cosPsi * cosPhi - sinPsi * cosTheta * sinPhi; 51 array[1] = cosPsi * sinPhi + sinPsi * co 50 array[1] = cosPsi * sinPhi + sinPsi * cosTheta * cosPhi; 52 array[2] = sinPsi * sinTheta; 51 array[2] = sinPsi * sinTheta; 53 52 54 array[3] = - sinPsi * cosPhi - cosPsi * cosT 53 array[3] = - sinPsi * cosPhi - cosPsi * cosTheta * sinPhi; 55 array[4] = - sinPsi * sinPhi + cosPsi * co 54 array[4] = - sinPsi * sinPhi + cosPsi * cosTheta * cosPhi; 56 array[5] = cosPsi * sinTheta; 55 array[5] = cosPsi * sinTheta; 57 56 58 array[6] = sinTheta * sinPhi; 57 array[6] = sinTheta * sinPhi; 59 array[7] = - sinTheta * cosPhi; 58 array[7] = - sinTheta * cosPhi; 60 array[8] = cosTheta; 59 array[8] = cosTheta; 61 60 62 } // ZMpvEulerAnglesRep 61 } // ZMpvEulerAnglesRep 63 62 64 63 65 double HepEulerAngles::distance( const EA & ex 64 double HepEulerAngles::distance( const EA & ex ) const { 66 65 67 double thisRep[9]; 66 double thisRep[9]; 68 double exRep[9]; 67 double exRep[9]; 69 68 70 ZMpvEulerAnglesRep ( *this, thisRep ); 69 ZMpvEulerAnglesRep ( *this, thisRep ); 71 ZMpvEulerAnglesRep ( ex, exRep ); 70 ZMpvEulerAnglesRep ( ex, exRep ); 72 71 73 double sum = 0.0; 72 double sum = 0.0; 74 for (int i = 0; i < 9; i++) { 73 for (int i = 0; i < 9; i++) { 75 sum += thisRep[i] * exRep[i]; 74 sum += thisRep[i] * exRep[i]; 76 } 75 } 77 76 78 double d = 3.0 - sum; // NaN-proofing: 77 double d = 3.0 - sum; // NaN-proofing: 79 return (d >= 0) ? d : 0; // sqrt(distance 78 return (d >= 0) ? d : 0; // sqrt(distance) is used in howNear() 80 79 81 } // HepEulerAngles::distance() 80 } // HepEulerAngles::distance() 82 81 83 82 84 bool HepEulerAngles::isNear( const EA & ex, do 83 bool HepEulerAngles::isNear( const EA & ex, double epsilon ) const { 85 84 86 return distance( ex ) <= epsilon*epsilon ; 85 return distance( ex ) <= epsilon*epsilon ; 87 86 88 } // HepEulerAngles::isNear() 87 } // HepEulerAngles::isNear() 89 88 90 89 91 double HepEulerAngles::howNear( const EA & ex 90 double HepEulerAngles::howNear( const EA & ex ) const { 92 91 93 return std::sqrt( distance( ex ) ); 92 return std::sqrt( distance( ex ) ); 94 93 95 } // HepEulerAngles::howNear() 94 } // HepEulerAngles::howNear() 96 95 97 //-************** 96 //-************** 98 // Global Methods 97 // Global Methods 99 //-************** 98 //-************** 100 99 101 std::ostream & operator<<(std::ostream & os, c 100 std::ostream & operator<<(std::ostream & os, const HepEulerAngles & ea) 102 { 101 { 103 os << "(" << ea.phi() << ", " << ea.theta() 102 os << "(" << ea.phi() << ", " << ea.theta() << ", " << ea.psi() << ")"; 104 return os; 103 return os; 105 } // operator<<() 104 } // operator<<() 106 105 107 void ZMinput3doubles ( std::istream & is, cons 106 void ZMinput3doubles ( std::istream & is, const char * type, 108 double & x, double & y, 107 double & x, double & y, double & z ); 109 108 110 std::istream & operator>>(std::istream & is, H 109 std::istream & operator>>(std::istream & is, HepEulerAngles & ea) { 111 double thePhi; 110 double thePhi; 112 double theTheta; 111 double theTheta; 113 double thePsi; 112 double thePsi; 114 ZMinput3doubles ( is, "HepEulerAngle", thePh 113 ZMinput3doubles ( is, "HepEulerAngle", thePhi , theTheta , thePsi ); 115 ea.set ( thePhi , theTheta , thePsi ); 114 ea.set ( thePhi , theTheta , thePsi ); 116 return is; 115 return is; 117 } // operator>>() 116 } // operator>>() 118 117 119 } // namespace CLHEP 118 } // namespace CLHEP 120 119 121 120 122 121