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