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 HepRotationZ 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/RotationZ.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 
HepRotationZ(double dddelta)32 HepRotationZ::HepRotationZ(double dddelta) :
33 		its_d(proper(dddelta)), its_s(std::sin(dddelta)), its_c(std::cos(dddelta))
34 {}
35 
set(double dddelta)36 HepRotationZ & HepRotationZ::set ( double dddelta ) {
37   its_d = proper(dddelta);
38   its_s = std::sin(its_d);
39   its_c = std::cos(its_d);
40   return *this;
41 }
42 
phi() const43 double  HepRotationZ::phi() const {
44   return  - its_d/2.0;
45 }  // HepRotationZ::phi()
46 
theta() const47 double  HepRotationZ::theta() const {
48   return  0.0 ;
49 }  // HepRotationZ::theta()
50 
psi() const51 double  HepRotationZ::psi() const {
52   return  - its_d/2.0;
53 }  // HepRotationZ::psi()
54 
eulerAngles() const55 HepEulerAngles HepRotationZ::eulerAngles() const {
56   return HepEulerAngles(  phi(),  theta(),  psi() );
57 }  // HepRotationZ::eulerAngles()
58 
59 
60 // From the defining code in the implementation of CLHEP (in Rotation.cc)
61 // it is clear that thetaX, phiX form the polar angles in the original
62 // coordinate system of the new X axis (and similarly for phiY and phiZ).
63 //
64 // This code is take directly from CLHEP original.  However, there are as
65 // shown opportunities for significant speed improvement.
66 
phiX() const67 double HepRotationZ::phiX() const {
68   return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
69   		// or ---- return d;
70 }
71 
phiY() const72 double HepRotationZ::phiY() const {
73   return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
74 }
75 
phiZ() const76 double HepRotationZ::phiZ() const {
77   return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
78 		// or ---- return 0.0;
79 }
80 
thetaX() const81 double HepRotationZ::thetaX() const {
82   return safe_acos(zx());
83 		// or ----  return CLHEP::halfpi;
84 }
85 
thetaY() const86 double HepRotationZ::thetaY() const {
87   return safe_acos(zy());
88 		// or ----  return CLHEP::halfpi;
89 }
90 
thetaZ() const91 double HepRotationZ::thetaZ() const {
92   return safe_acos(zz());
93 		// or ---- return 0.0;
94 }
95 
setDelta(double ddelta)96 void HepRotationZ::setDelta ( double ddelta ) {
97   set(ddelta);
98 }
99 
decompose(HepAxisAngle & rotation,Hep3Vector & boost) const100 void HepRotationZ::decompose
101 	(HepAxisAngle & rotation, Hep3Vector & boost) const {
102   boost.set(0,0,0);
103   rotation = axisAngle();
104 }
105 
decompose(Hep3Vector & boost,HepAxisAngle & rotation) const106 void HepRotationZ::decompose
107 	(Hep3Vector & boost, HepAxisAngle & rotation) const {
108   boost.set(0,0,0);
109   rotation = axisAngle();
110 }
111 
decompose(HepRotation & rotation,HepBoost & boost) const112 void HepRotationZ::decompose
113         (HepRotation & rotation, HepBoost & boost) const {
114   boost.set(0,0,0);
115   rotation = HepRotation(*this);
116 }
117 
decompose(HepBoost & boost,HepRotation & rotation) const118 void HepRotationZ::decompose
119         (HepBoost & boost, HepRotation & rotation) const {
120   boost.set(0,0,0);
121   rotation = HepRotation(*this);
122 }
123 
distance2(const HepRotationZ & r) const124 double HepRotationZ::distance2( const HepRotationZ & r  ) const {
125   double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
126   return (answer >= 0) ? answer : 0;
127 }
128 
distance2(const HepRotation & r) const129 double HepRotationZ::distance2( const HepRotation & r  ) const {
130   double sum =    xx() * r.xx() + xy() * r.xy()
131                    + yx() * r.yx() + yy() * r.yy()
132 						   + r.zz();
133   double answer = 3.0 - sum;
134   return (answer >= 0 ) ? answer : 0;
135 }
136 
distance2(const HepLorentzRotation & lt) const137 double HepRotationZ::distance2( const HepLorentzRotation & lt  ) const {
138   HepAxisAngle a;
139   Hep3Vector   b;
140   lt.decompose(b, a);
141   double bet = b.beta();
142   double bet2 = bet*bet;
143   HepRotation r(a);
144   return bet2/(1-bet2) + distance2(r);
145 }
146 
distance2(const HepBoost & lt) const147 double HepRotationZ::distance2( const HepBoost & lt ) const {
148   return distance2( HepLorentzRotation(lt));
149 }
150 
howNear(const HepRotationZ & r) const151 double HepRotationZ::howNear( const HepRotationZ & r ) const {
152   return std::sqrt(distance2(r));
153 }
howNear(const HepRotation & r) const154 double HepRotationZ::howNear( const HepRotation & r ) const {
155   return std::sqrt(distance2(r));
156 }
howNear(const HepBoost & lt) const157 double HepRotationZ::howNear( const HepBoost & lt ) const {
158   return std::sqrt(distance2(lt));
159 }
howNear(const HepLorentzRotation & lt) const160 double HepRotationZ::howNear( const HepLorentzRotation & lt ) const {
161   return std::sqrt(distance2(lt));
162 }
isNear(const HepRotationZ & r,double epsilon) const163 bool HepRotationZ::isNear(const HepRotationZ & r,double epsilon)const {
164   return (distance2(r) <= epsilon*epsilon);
165 }
isNear(const HepRotation & r,double epsilon) const166 bool HepRotationZ::isNear(const HepRotation & r,double epsilon)const {
167   return (distance2(r) <= epsilon*epsilon);
168 }
isNear(const HepBoost & lt,double epsilon) const169 bool HepRotationZ::isNear( const HepBoost & lt,double epsilon) const {
170   return (distance2(lt) <= epsilon*epsilon);
171 }
isNear(const HepLorentzRotation & lt,double epsilon) const172 bool HepRotationZ::isNear( const HepLorentzRotation & lt,
173                                      double epsilon) const {
174   return (distance2(lt) <= epsilon*epsilon);
175 }
176 
norm2() const177 double HepRotationZ::norm2() const {
178   return 2.0 - 2.0 * its_c;
179 }
180 
print(std::ostream & os) const181 std::ostream & HepRotationZ::print( std::ostream & os ) const {
182   os << "\nRotation about Z (" << its_d <<
183                 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
184   return os;
185 }
186 
187 }  // namespace CLHEP
188 
189