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

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