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 | using std::abs;
|
---|
26 |
|
---|
27 | namespace CLHEP {
|
---|
28 |
|
---|
29 | static inline double safe_acos (double x) {
|
---|
30 | if (abs(x) <= 1.0) return acos(x);
|
---|
31 | return ( (x>0) ? 0 : CLHEP::pi );
|
---|
32 | }
|
---|
33 |
|
---|
34 | HepRotationZ::HepRotationZ(double delta) :
|
---|
35 | d(proper(delta)), s(sin(delta)), c(cos(delta))
|
---|
36 | {}
|
---|
37 |
|
---|
38 | HepRotationZ & HepRotationZ::set ( double delta ) {
|
---|
39 | d = proper(delta);
|
---|
40 | s = sin(d);
|
---|
41 | c = cos(d);
|
---|
42 | return *this;
|
---|
43 | }
|
---|
44 |
|
---|
45 | double HepRotationZ::phi() const {
|
---|
46 | return - d/2.0;
|
---|
47 | } // HepRotationZ::phi()
|
---|
48 |
|
---|
49 | double HepRotationZ::theta() const {
|
---|
50 | return 0.0 ;
|
---|
51 | } // HepRotationZ::theta()
|
---|
52 |
|
---|
53 | double HepRotationZ::psi() const {
|
---|
54 | return - d/2.0;
|
---|
55 | } // HepRotationZ::psi()
|
---|
56 |
|
---|
57 | HepEulerAngles HepRotationZ::eulerAngles() const {
|
---|
58 | return HepEulerAngles( phi(), theta(), psi() );
|
---|
59 | } // HepRotationZ::eulerAngles()
|
---|
60 |
|
---|
61 |
|
---|
62 | // From the defining code in the implementation of CLHEP (in Rotation.cc)
|
---|
63 | // it is clear that thetaX, phiX form the polar angles in the original
|
---|
64 | // coordinate system of the new X axis (and similarly for phiY and phiZ).
|
---|
65 | //
|
---|
66 | // This code is take directly from CLHEP original. However, there are as
|
---|
67 | // shown opportunities for significant speed improvement.
|
---|
68 |
|
---|
69 | double HepRotationZ::phiX() const {
|
---|
70 | return (yx() == 0.0 && xx() == 0.0) ? 0.0 : atan2(yx(),xx());
|
---|
71 | // or ---- return d;
|
---|
72 | }
|
---|
73 |
|
---|
74 | double HepRotationZ::phiY() const {
|
---|
75 | return (yy() == 0.0 && xy() == 0.0) ? 0.0 : atan2(yy(),xy());
|
---|
76 | }
|
---|
77 |
|
---|
78 | double HepRotationZ::phiZ() const {
|
---|
79 | return (yz() == 0.0 && xz() == 0.0) ? 0.0 : atan2(yz(),xz());
|
---|
80 | // or ---- return 0.0;
|
---|
81 | }
|
---|
82 |
|
---|
83 | double HepRotationZ::thetaX() const {
|
---|
84 | return safe_acos(zx());
|
---|
85 | // or ---- return CLHEP::halfpi;
|
---|
86 | }
|
---|
87 |
|
---|
88 | double HepRotationZ::thetaY() const {
|
---|
89 | return safe_acos(zy());
|
---|
90 | // or ---- return CLHEP::halfpi;
|
---|
91 | }
|
---|
92 |
|
---|
93 | double HepRotationZ::thetaZ() const {
|
---|
94 | return safe_acos(zz());
|
---|
95 | // or ---- return 0.0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | void HepRotationZ::setDelta ( double delta ) {
|
---|
99 | set(delta);
|
---|
100 | }
|
---|
101 |
|
---|
102 | void HepRotationZ::decompose
|
---|
103 | (HepAxisAngle & rotation, Hep3Vector & boost) const {
|
---|
104 | boost.set(0,0,0);
|
---|
105 | rotation = axisAngle();
|
---|
106 | }
|
---|
107 |
|
---|
108 | void HepRotationZ::decompose
|
---|
109 | (Hep3Vector & boost, HepAxisAngle & rotation) const {
|
---|
110 | boost.set(0,0,0);
|
---|
111 | rotation = axisAngle();
|
---|
112 | }
|
---|
113 |
|
---|
114 | void HepRotationZ::decompose
|
---|
115 | (HepRotation & rotation, HepBoost & boost) const {
|
---|
116 | boost.set(0,0,0);
|
---|
117 | rotation = HepRotation(*this);
|
---|
118 | }
|
---|
119 |
|
---|
120 | void HepRotationZ::decompose
|
---|
121 | (HepBoost & boost, HepRotation & rotation) const {
|
---|
122 | boost.set(0,0,0);
|
---|
123 | rotation = HepRotation(*this);
|
---|
124 | }
|
---|
125 |
|
---|
126 | double HepRotationZ::distance2( const HepRotationZ & r ) const {
|
---|
127 | double answer = 2.0 * ( 1.0 - ( s * r.s + c * r.c ) ) ;
|
---|
128 | return (answer >= 0) ? answer : 0;
|
---|
129 | }
|
---|
130 |
|
---|
131 | double HepRotationZ::distance2( const HepRotation & r ) const {
|
---|
132 | double sum = xx() * r.xx() + xy() * r.xy()
|
---|
133 | + yx() * r.yx() + yy() * r.yy()
|
---|
134 | + r.zz();
|
---|
135 | double answer = 3.0 - sum;
|
---|
136 | return (answer >= 0 ) ? answer : 0;
|
---|
137 | }
|
---|
138 |
|
---|
139 | double HepRotationZ::distance2( const HepLorentzRotation & lt ) const {
|
---|
140 | HepAxisAngle a;
|
---|
141 | Hep3Vector b;
|
---|
142 | lt.decompose(b, a);
|
---|
143 | double bet = b.beta();
|
---|
144 | double bet2 = bet*bet;
|
---|
145 | HepRotation r(a);
|
---|
146 | return bet2/(1-bet2) + distance2(r);
|
---|
147 | }
|
---|
148 |
|
---|
149 | double HepRotationZ::distance2( const HepBoost & lt ) const {
|
---|
150 | return distance2( HepLorentzRotation(lt));
|
---|
151 | }
|
---|
152 |
|
---|
153 | double HepRotationZ::howNear( const HepRotationZ & r ) const {
|
---|
154 | return sqrt(distance2(r));
|
---|
155 | }
|
---|
156 | double HepRotationZ::howNear( const HepRotation & r ) const {
|
---|
157 | return sqrt(distance2(r));
|
---|
158 | }
|
---|
159 | double HepRotationZ::howNear( const HepBoost & lt ) const {
|
---|
160 | return sqrt(distance2(lt));
|
---|
161 | }
|
---|
162 | double HepRotationZ::howNear( const HepLorentzRotation & lt ) const {
|
---|
163 | return sqrt(distance2(lt));
|
---|
164 | }
|
---|
165 | bool HepRotationZ::isNear(const HepRotationZ & r,double epsilon)const {
|
---|
166 | return (distance2(r) <= epsilon*epsilon);
|
---|
167 | }
|
---|
168 | bool HepRotationZ::isNear(const HepRotation & r,double epsilon)const {
|
---|
169 | return (distance2(r) <= epsilon*epsilon);
|
---|
170 | }
|
---|
171 | bool HepRotationZ::isNear( const HepBoost & lt,double epsilon) const {
|
---|
172 | return (distance2(lt) <= epsilon*epsilon);
|
---|
173 | }
|
---|
174 | bool HepRotationZ::isNear( const HepLorentzRotation & lt,
|
---|
175 | double epsilon) const {
|
---|
176 | return (distance2(lt) <= epsilon*epsilon);
|
---|
177 | }
|
---|
178 |
|
---|
179 | double HepRotationZ::norm2() const {
|
---|
180 | return 2.0 - 2.0 * c;
|
---|
181 | }
|
---|
182 |
|
---|
183 | std::ostream & HepRotationZ::print( std::ostream & os ) const {
|
---|
184 | os << "\nRotation about Z (" << d <<
|
---|
185 | ") [cos d = " << c << " sin d = " << s << "]\n";
|
---|
186 | return os;
|
---|
187 | }
|
---|
188 |
|
---|
189 | } // namespace CLHEP
|
---|
190 |
|
---|