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

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