Geant4_10
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"
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 
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 
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 
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 }
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 
void set(double x, double y, double z)
double phiX() const
Definition: RotationZ.cc:66
double psi() const
Definition: RotationZ.cc:50
double xx() const
bool isNear(const HepRotationZ &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationZ.cc:162
tuple a
Definition: test.py:11
double zy() const
double xx() const
double yy() const
double thetaX() const
Definition: RotationZ.cc:80
tuple x
Definition: test.py:50
double theta() const
Definition: RotationZ.cc:46
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationZ.cc:100
double phi() const
Definition: RotationZ.cc:42
double yz() const
double distance2(const HepRotationZ &r) const
Definition: RotationZ.cc:123
double zz() const
double phiY() const
Definition: RotationZ.cc:71
tuple b
Definition: test.py:12
double yy() const
double thetaY() const
Definition: RotationZ.cc:85
HepEulerAngles eulerAngles() const
Definition: RotationZ.cc:54
double zx() const
jump r
Definition: plot.C:36
std::ostream & print(std::ostream &os) const
Definition: RotationZ.cc:180
double thetaZ() const
Definition: RotationZ.cc:90
double beta() const
Definition: SpaceVectorP.cc:30
double xy() const
double howNear(const HepRotationZ &r) const
Definition: RotationZ.cc:150
HepBoost & set(double betaX, double betaY, double betaZ)
Definition: Boost.cc:21
void decompose(Hep3Vector &boost, HepAxisAngle &rotation) const
double yx() const
static double proper(double delta)
double phiZ() const
Definition: RotationZ.cc:75
double yx() const
HepRotationZ & set(double delta)
Definition: RotationZ.cc:35
double xz() const
double norm2() const
Definition: RotationZ.cc:176
double zz() const
double xy() const
void setDelta(double delta)
Definition: RotationZ.cc:95