00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "CLHEP/Vector/EulerAngles.h"
00025
00026 #include "CLHEP/Vector/ThreeVector.h"
00027
00028 #include <iostream>
00029
00030 namespace CLHEP {
00031
00032
00033
00034
00035
00036 double HepEulerAngles::tolerance = Hep3Vector::ToleranceTicks * 1.0e-8;
00037
00038
00039
00040
00041
00042
00043 static void ZMpvEulerAnglesRep ( const HepEulerAngles & ex, double array[] ) {
00044
00045 register double sinPhi = std::sin( ex.phi() ) , cosPhi = std::cos( ex.phi() );
00046 register double sinTheta = std::sin( ex.theta() ), cosTheta = std::cos( ex.theta() );
00047 register double sinPsi = std::sin( ex.psi() ) , cosPsi = std::cos( ex.psi() );
00048
00049 array[0] = cosPsi * cosPhi - sinPsi * cosTheta * sinPhi;
00050 array[1] = cosPsi * sinPhi + sinPsi * cosTheta * cosPhi;
00051 array[2] = sinPsi * sinTheta;
00052
00053 array[3] = - sinPsi * cosPhi - cosPsi * cosTheta * sinPhi;
00054 array[4] = - sinPsi * sinPhi + cosPsi * cosTheta * cosPhi;
00055 array[5] = cosPsi * sinTheta;
00056
00057 array[6] = sinTheta * sinPhi;
00058 array[7] = - sinTheta * cosPhi;
00059 array[8] = cosTheta;
00060
00061 }
00062
00063
00064 double HepEulerAngles::distance( const EA & ex ) const {
00065
00066 double thisRep[9];
00067 double exRep[9];
00068
00069 ZMpvEulerAnglesRep ( *this, thisRep );
00070 ZMpvEulerAnglesRep ( ex, exRep );
00071
00072 double sum = 0.0;
00073 for (int i = 0; i < 9; i++) {
00074 sum += thisRep[i] * exRep[i];
00075 }
00076
00077 double d = 3.0 - sum;
00078 return (d >= 0) ? d : 0;
00079
00080 }
00081
00082
00083 bool HepEulerAngles::isNear( const EA & ex, double epsilon ) const {
00084
00085 return distance( ex ) <= epsilon*epsilon ;
00086
00087 }
00088
00089
00090 double HepEulerAngles::howNear( const EA & ex ) const {
00091
00092 return std::sqrt( distance( ex ) );
00093
00094 }
00095
00096
00097
00098
00099
00100 std::ostream & operator<<(std::ostream & os, const HepEulerAngles & ea)
00101 {
00102 os << "(" << ea.phi() << ", " << ea.theta() << ", " << ea.psi() << ")";
00103 return os;
00104 }
00105
00106 void ZMinput3doubles ( std::istream & is, const char * type,
00107 double & x, double & y, double & z );
00108
00109 std::istream & operator>>(std::istream & is, HepEulerAngles & ea) {
00110 double thePhi;
00111 double theTheta;
00112 double thePsi;
00113 ZMinput3doubles ( is, "HepEulerAngle", thePhi , theTheta , thePsi );
00114 ea.set ( thePhi , theTheta , thePsi );
00115 return is;
00116 }
00117
00118 }
00119
00120