14#include "CLHEP/Vector/defs.h"
15#include "CLHEP/Vector/Rotation.h"
16#include "CLHEP/Vector/EulerAngles.h"
17#include "CLHEP/Units/PhysicalConstants.h"
25static inline double safe_acos (
double x) {
26 if (std::abs(x) <= 1.0)
return std::acos(x);
27 return ( (x>0) ? 0 : CLHEP::pi );
36 double sinPhi = std::sin( phi1 ), cosPhi = std::cos( phi1 );
37 double sinTheta = std::sin( theta1 ), cosTheta = std::cos( theta1 );
38 double sinPsi = std::sin( psi1 ), cosPsi = std::cos( psi1 );
40 rxx = cosPsi * cosPhi - cosTheta * sinPhi * sinPsi;
41 rxy = cosPsi * sinPhi + cosTheta * cosPhi * sinPsi;
42 rxz = sinPsi * sinTheta;
44 ryx = - sinPsi * cosPhi - cosTheta * sinPhi * cosPsi;
45 ryy = - sinPsi * sinPhi + cosTheta * cosPhi * cosPsi;
46 ryz = cosPsi * sinTheta;
48 rzx = sinTheta * sinPhi;
49 rzy = - sinTheta * cosPhi;
58 set (phi1, theta1, psi1);
75 "HepRotation::phi() finds | rzz | > 1 "));
78 const double sinTheta = std::sqrt( s2 );
86 const double cscTheta = 1/sinTheta;
87 double cosabsphi = -
rzy * cscTheta;
88 if ( std::fabs(cosabsphi) > 1 ) {
90 "HepRotation::phi() finds | cos phi | > 1 "));
93 const double absPhi = std::acos ( cosabsphi );
99 return (
rzy < 0) ? 0 : CLHEP::pi;
106 return safe_acos(
rzz );
113 if ( std::fabs(
rzz) > 1 ) {
115 "HepRotation::psi() finds | rzz | > 1"));
118 sinTheta = std::sqrt( 1.0 -
rzz*
rzz );
121 if (sinTheta < .01) {
127 const double cscTheta = 1/sinTheta;
128 double cosabspsi =
ryz * cscTheta;
129 if ( std::fabs(cosabspsi) > 1 ) {
131 "HepRotation::psi() finds | cos psi | > 1"));
134 const double absPsi = std::acos ( cosabspsi );
137 }
else if (
rxz < 0) {
140 return (
ryz > 0) ? 0 : CLHEP::pi;
149void correctByPi (
double& psi1,
double& phi1 ) {
163void correctPsiPhi (
double rxz,
double rzx,
double ryz,
double rzy,
164 double& psi1,
double& phi1 ) {
169 w[0] = rxz; w[1] = rzx; w[2] = ryz; w[3] = -rzy;
172 double maxw = std::abs(w[0]);
174 for (
int i = 1; i < 4; ++i) {
175 if (std::abs(w[i]) > maxw) {
176 maxw = std::abs(w[i]);
184 if (w[0] > 0 && psi1 < 0) correctByPi ( psi1, phi1 );
185 if (w[0] < 0 && psi1 > 0) correctByPi ( psi1, phi1 );
188 if (w[1] > 0 && phi1 < 0) correctByPi ( psi1, phi1 );
189 if (w[1] < 0 && phi1 > 0) correctByPi ( psi1, phi1 );
192 if (w[2] > 0 && std::abs(psi1) > CLHEP::halfpi) correctByPi ( psi1, phi1 );
193 if (w[2] < 0 && std::abs(psi1) < CLHEP::halfpi) correctByPi ( psi1, phi1 );
196 if (w[3] > 0 && std::abs(phi1) > CLHEP::halfpi) correctByPi ( psi1, phi1 );
197 if (w[3] < 0 && std::abs(phi1) < CLHEP::halfpi) correctByPi ( psi1, phi1 );
207 double phi1, theta1, psi1;
208 double psiPlusPhi, psiMinusPhi;
210 theta1 = safe_acos(
rzz );
212 if (
rzz > 1 ||
rzz < -1) {
214 "HepRotation::eulerAngles() finds | rzz | > 1 "));
217 double cosTheta =
rzz;
218 if (cosTheta > 1) cosTheta = 1;
219 if (cosTheta < -1) cosTheta = -1;
225 }
else if (cosTheta >= 0) {
233 psiMinusPhi = std::atan2 ( s1, c );
235 }
else if (cosTheta > -1) {
243 psiPlusPhi = std::atan2 ( s1, c );
252 psi1 = .5 * (psiPlusPhi + psiMinusPhi);
253 phi1 = .5 * (psiPlusPhi - psiMinusPhi);
HepEulerAngles eulerAngles() const
HepRotation & set(const Hep3Vector &axis, double delta)
void setTheta(double theta)