23static inline double safe_acos (
double x) {
24 if (std::abs(x) <= 1.0)
return std::acos(x);
25 return ( (x>0) ? 0 : CLHEP::pi );
34 double sinPhi = std::sin( phi1 ), cosPhi = std::cos( phi1 );
35 double sinTheta = std::sin( theta1 ), cosTheta = std::cos( theta1 );
36 double sinPsi = std::sin( psi1 ), cosPsi = std::cos( psi1 );
38 rxx = cosPsi * cosPhi - cosTheta * sinPhi * sinPsi;
39 rxy = cosPsi * sinPhi + cosTheta * cosPhi * sinPsi;
40 rxz = sinPsi * sinTheta;
42 ryx = - sinPsi * cosPhi - cosTheta * sinPhi * cosPsi;
43 ryy = - sinPsi * sinPhi + cosTheta * cosPhi * cosPsi;
44 ryz = cosPsi * sinTheta;
46 rzx = sinTheta * sinPhi;
47 rzy = - sinTheta * cosPhi;
56 set (phi1, theta1, psi1);
71 std::cerr <<
"HepRotation::phi() - "
72 <<
"HepRotation::phi() finds | rzz | > 1 " << std::endl;
75 const double sinTheta = std::sqrt( s2 );
83 const double cscTheta = 1/sinTheta;
84 double cosabsphi = -
rzy * cscTheta;
85 if ( std::fabs(cosabsphi) > 1 ) {
86 std::cerr <<
"HepRotation::phi() - "
87 <<
"HepRotation::phi() finds | cos phi | > 1 " << std::endl;
90 const double absPhi = std::acos ( cosabsphi );
96 return (
rzy < 0) ? 0 : CLHEP::pi;
103 return safe_acos(
rzz );
110 if ( std::fabs(
rzz) > 1 ) {
111 std::cerr <<
"HepRotation::psi() - "
112 <<
"HepRotation::psi() finds | rzz | > 1" << std::endl;
115 sinTheta = std::sqrt( 1.0 -
rzz*
rzz );
118 if (sinTheta < .01) {
124 const double cscTheta = 1/sinTheta;
125 double cosabspsi =
ryz * cscTheta;
126 if ( std::fabs(cosabspsi) > 1 ) {
127 std::cerr <<
"HepRotation::psi() - "
128 <<
"HepRotation::psi() finds | cos psi | > 1" << std::endl;
131 const double absPsi = std::acos ( cosabspsi );
134 }
else if (
rxz < 0) {
137 return (
ryz > 0) ? 0 : CLHEP::pi;
145void correctByPi (
double& psi1,
double& phi1 ) {
159void correctPsiPhi (
double rxz,
double rzx,
double ryz,
double rzy,
160 double& psi1,
double& phi1 ) {
165 w[0] = rxz; w[1] = rzx; w[2] = ryz; w[3] = -rzy;
168 double maxw = std::abs(w[0]);
170 for (
int i = 1; i < 4; ++i) {
171 if (std::abs(w[i]) > maxw) {
172 maxw = std::abs(w[i]);
180 if (w[0] > 0 && psi1 < 0) correctByPi ( psi1, phi1 );
181 if (w[0] < 0 && psi1 > 0) correctByPi ( psi1, phi1 );
184 if (w[1] > 0 && phi1 < 0) correctByPi ( psi1, phi1 );
185 if (w[1] < 0 && phi1 > 0) correctByPi ( psi1, phi1 );
188 if (w[2] > 0 && std::abs(psi1) > CLHEP::halfpi) correctByPi ( psi1, phi1 );
189 if (w[2] < 0 && std::abs(psi1) < CLHEP::halfpi) correctByPi ( psi1, phi1 );
192 if (w[3] > 0 && std::abs(phi1) > CLHEP::halfpi) correctByPi ( psi1, phi1 );
193 if (w[3] < 0 && std::abs(phi1) < CLHEP::halfpi) correctByPi ( psi1, phi1 );
202 double phi1, theta1, psi1;
203 double psiPlusPhi, psiMinusPhi;
205 theta1 = safe_acos(
rzz );
212 double cosTheta =
rzz;
213 if (cosTheta > 1) cosTheta = 1;
214 if (cosTheta < -1) cosTheta = -1;
220 }
else if (cosTheta >= 0) {
228 psiMinusPhi = std::atan2 ( s1, c1 );
230 }
else if (cosTheta > -1) {
238 psiPlusPhi = std::atan2 ( s1, c1 );
247 psi1 = .5 * (psiPlusPhi + psiMinusPhi);
248 phi1 = .5 * (psiPlusPhi - psiMinusPhi);
HepEulerAngles eulerAngles() const
HepRotation & set(const Hep3Vector &axis, double delta)
void setTheta(double theta)