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