Geant4  10.00.p03
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 
14 #include "CLHEP/Vector/RotationZ.h"
15 #include "CLHEP/Vector/AxisAngle.h"
16 #include "CLHEP/Vector/EulerAngles.h"
17 #include "CLHEP/Vector/LorentzRotation.h"
18 #include "CLHEP/Units/PhysicalConstants.h"
19 
20 #include <cmath>
21 #include <stdlib.h>
22 #include <iostream>
23 
24 namespace CLHEP {
25 
26 static 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 
31 HepRotationZ::HepRotationZ(double ddelta) :
32  its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
33 {}
34 
35 HepRotationZ & 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 
42 double HepRotationZ::phi() const {
43  return - its_d/2.0;
44 } // HepRotationZ::phi()
45 
46 double HepRotationZ::theta() const {
47  return 0.0 ;
48 } // HepRotationZ::theta()
49 
50 double HepRotationZ::psi() const {
51  return - its_d/2.0;
52 } // HepRotationZ::psi()
53 
54 HepEulerAngles HepRotationZ::eulerAngles() const {
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 
66 double HepRotationZ::phiX() const {
67  return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
68  // or ---- return d;
69 }
70 
71 double HepRotationZ::phiY() const {
72  return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
73 }
74 
75 double HepRotationZ::phiZ() const {
76  return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
77  // or ---- return 0.0;
78 }
79 
80 double HepRotationZ::thetaX() const {
81  return safe_acos(zx());
82  // or ---- return CLHEP::halfpi;
83 }
84 
85 double HepRotationZ::thetaY() const {
86  return safe_acos(zy());
87  // or ---- return CLHEP::halfpi;
88 }
89 
90 double HepRotationZ::thetaZ() const {
91  return safe_acos(zz());
92  // or ---- return 0.0;
93 }
94 
95 void HepRotationZ::setDelta ( double ddelta ) {
96  set(ddelta);
97 }
98 
99 void HepRotationZ::decompose
100  (HepAxisAngle & rotation, Hep3Vector & boost) const {
101  boost.set(0,0,0);
102  rotation = axisAngle();
103 }
104 
105 void HepRotationZ::decompose
106  (Hep3Vector & boost, HepAxisAngle & rotation) const {
107  boost.set(0,0,0);
108  rotation = axisAngle();
109 }
110 
111 void HepRotationZ::decompose
112  (HepRotation & rotation, HepBoost & boost) const {
113  boost.set(0,0,0);
114  rotation = HepRotation(*this);
115 }
116 
117 void HepRotationZ::decompose
118  (HepBoost & boost, HepRotation & rotation) const {
119  boost.set(0,0,0);
120  rotation = HepRotation(*this);
121 }
122 
123 double 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 
128 double 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 
136 double 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 
146 double HepRotationZ::distance2( const HepBoost & lt ) const {
147  return distance2( HepLorentzRotation(lt));
148 }
149 
150 double HepRotationZ::howNear( const HepRotationZ & r ) const {
151  return std::sqrt(distance2(r));
152 }
153 double HepRotationZ::howNear( const HepRotation & r ) const {
154  return std::sqrt(distance2(r));
155 }
156 double HepRotationZ::howNear( const HepBoost & lt ) const {
157  return std::sqrt(distance2(lt));
158 }
159 double HepRotationZ::howNear( const HepLorentzRotation & lt ) const {
160  return std::sqrt(distance2(lt));
161 }
162 bool HepRotationZ::isNear(const HepRotationZ & r,double epsilon)const {
163  return (distance2(r) <= epsilon*epsilon);
164 }
165 bool HepRotationZ::isNear(const HepRotation & r,double epsilon)const {
166  return (distance2(r) <= epsilon*epsilon);
167 }
168 bool HepRotationZ::isNear( const HepBoost & lt,double epsilon) const {
169  return (distance2(lt) <= epsilon*epsilon);
170 }
171 bool HepRotationZ::isNear( const HepLorentzRotation & lt,
172  double epsilon) const {
173  return (distance2(lt) <= epsilon*epsilon);
174 }
175 
176 double HepRotationZ::norm2() const {
177  return 2.0 - 2.0 * its_c;
178 }
179 
180 std::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 
const G4double pi
G4double a
Definition: TRTMaterials.hh:39
static double safe_acos(double x)
Definition: Rotation.cc:23
void print(const std::vector< T > &data)
Definition: DicomRun.hh:111