1 // -*- C++ -*-
2 // ---------------------------------------------------------------------------
3 //
4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
5 //
6 // This is the implementation of methods of the HepRotationX class which
7 // were introduced when ZOOM PhysicsVectors was merged in.
8 //
9
10 #ifdef GNUPRAGMA
11 #pragma implementation
12 #endif
13
14 #include "CLHEP/Vector/defs.h"
15 #include "CLHEP/Vector/RotationX.h"
16 #include "CLHEP/Vector/AxisAngle.h"
17 #include "CLHEP/Vector/EulerAngles.h"
18 #include "CLHEP/Vector/LorentzRotation.h"
19 #include "CLHEP/Units/PhysicalConstants.h"
20
21 #include <cmath>
22 #include <stdlib.h>
23 #include <iostream>
24
25 namespace CLHEP {
26
safe_acos(double x)27 static inline double safe_acos (double x) {
28 if (std::abs(x) <= 1.0) return std::acos(x);
29 return ( (x>0) ? 0 : CLHEP::pi );
30 }
31
HepRotationX(double ddelta)32 HepRotationX::HepRotationX(double ddelta) :
33 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
34 {}
35
set(double ddelta)36 HepRotationX & HepRotationX::set ( double ddelta ) {
37 its_d = proper(ddelta);
38 its_s = std::sin(its_d);
39 its_c = std::cos(its_d);
40 return *this;
41 }
42
phi() const43 double HepRotationX::phi() const {
44 if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
45 return CLHEP::pi;
46 } else {
47 return 0.0;
48 }
49 } // HepRotationX::phi()
50
theta() const51 double HepRotationX::theta() const {
52 return std::fabs( its_d );
53 } // HepRotationX::theta()
54
psi() const55 double HepRotationX::psi() const {
56 if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
57 return CLHEP::pi;
58 } else {
59 return 0.0;
60 }
61 } // HepRotationX::psi()
62
eulerAngles() const63 HepEulerAngles HepRotationX::eulerAngles() const {
64 return HepEulerAngles( phi(), theta(), psi() );
65 } // HepRotationX::eulerAngles()
66
67
68 // From the defining code in the implementation of CLHEP (in Rotation.cc)
69 // it is clear that thetaX, phiX form the polar angles in the original
70 // coordinate system of the new X axis (and similarly for phiY and phiZ).
71 //
72 // This code is taken directly from the original CLHEP. However, there are as
73 // shown opportunities for significant speed improvement.
74
phiX() const75 double HepRotationX::phiX() const {
76 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
77 // or ---- return 0;
78 }
79
phiY() const80 double HepRotationX::phiY() const {
81 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
82 // or ---- return (yy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
83 }
84
phiZ() const85 double HepRotationX::phiZ() const {
86 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
87 // or ---- return (yz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
88 }
89
thetaX() const90 double HepRotationX::thetaX() const {
91 return safe_acos(zx());
92 // or ---- return CLHEP::halfpi;
93 }
94
thetaY() const95 double HepRotationX::thetaY() const {
96 return safe_acos(zy());
97 }
98
thetaZ() const99 double HepRotationX::thetaZ() const {
100 return safe_acos(zz());
101 // or ---- return d;
102 }
103
setDelta(double ddelta)104 void HepRotationX::setDelta ( double ddelta ) {
105 set(ddelta);
106 }
107
decompose(HepAxisAngle & rotation,Hep3Vector & boost) const108 void HepRotationX::decompose
109 (HepAxisAngle & rotation, Hep3Vector & boost) const {
110 boost.set(0,0,0);
111 rotation = axisAngle();
112 }
113
decompose(Hep3Vector & boost,HepAxisAngle & rotation) const114 void HepRotationX::decompose
115 (Hep3Vector & boost, HepAxisAngle & rotation) const {
116 boost.set(0,0,0);
117 rotation = axisAngle();
118 }
119
decompose(HepRotation & rotation,HepBoost & boost) const120 void HepRotationX::decompose
121 (HepRotation & rotation, HepBoost & boost) const {
122 boost.set(0,0,0);
123 rotation = HepRotation(*this);
124 }
125
decompose(HepBoost & boost,HepRotation & rotation) const126 void HepRotationX::decompose
127 (HepBoost & boost, HepRotation & rotation) const {
128 boost.set(0,0,0);
129 rotation = HepRotation(*this);
130 }
131
distance2(const HepRotationX & r) const132 double HepRotationX::distance2( const HepRotationX & r ) const {
133 double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
134 return (answer >= 0) ? answer : 0;
135 }
136
distance2(const HepRotation & r) const137 double HepRotationX::distance2( const HepRotation & r ) const {
138 double sum = r.xx() +
139 yy() * r.yy() + yz() * r.yz()
140 + zy() * r.zy() + zz() * r.zz();
141 double answer = 3.0 - sum;
142 return (answer >= 0 ) ? answer : 0;
143 }
144
distance2(const HepLorentzRotation & lt) const145 double HepRotationX::distance2( const HepLorentzRotation & lt ) const {
146 HepAxisAngle a;
147 Hep3Vector b;
148 lt.decompose(b, a);
149 double bet = b.beta();
150 double bet2 = bet*bet;
151 HepRotation r(a);
152 return bet2/(1-bet2) + distance2(r);
153 }
154
distance2(const HepBoost & lt) const155 double HepRotationX::distance2( const HepBoost & lt ) const {
156 return distance2( HepLorentzRotation(lt));
157 }
158
howNear(const HepRotationX & r) const159 double HepRotationX::howNear( const HepRotationX & r ) const {
160 return std::sqrt(distance2(r));
161 }
howNear(const HepRotation & r) const162 double HepRotationX::howNear( const HepRotation & r ) const {
163 return std::sqrt(distance2(r));
164 }
howNear(const HepBoost & b) const165 double HepRotationX::howNear( const HepBoost & b ) const {
166 return std::sqrt(distance2(b));
167 }
howNear(const HepLorentzRotation & lt) const168 double HepRotationX::howNear( const HepLorentzRotation & lt ) const {
169 return std::sqrt(distance2(lt));
170 }
isNear(const HepRotationX & r,double epsilon) const171 bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{
172 return (distance2(r) <= epsilon*epsilon);
173 }
isNear(const HepRotation & r,double epsilon) const174 bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{
175 return (distance2(r) <= epsilon*epsilon);
176 }
isNear(const HepBoost & lt,double epsilon) const177 bool HepRotationX::isNear( const HepBoost & lt,double epsilon) const {
178 return (distance2(lt) <= epsilon*epsilon);
179 }
180
isNear(const HepLorentzRotation & lt,double epsilon) const181 bool HepRotationX::isNear( const HepLorentzRotation & lt,
182 double epsilon ) const {
183 return (distance2(lt) <= epsilon*epsilon);
184 }
185
norm2() const186 double HepRotationX::norm2() const {
187 return 2.0 - 2.0 * its_c;
188 }
189
print(std::ostream & os) const190 std::ostream & HepRotationX::print( std::ostream & os ) const {
191 os << "\nRotation about X (" << its_d <<
192 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
193 return os;
194 }
195
196 } // namespace CLHEP
197
198