CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

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