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
25namespace CLHEP {
26
27static 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
33 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
34{}
35
36HepRotationY & HepRotationY::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
43double HepRotationY::phi() const {
44 if ( its_d == 0 ) {
45 return 0;
46 } else if ( (its_d < 0) || (its_d == CLHEP::pi) ) {
47 return +CLHEP::halfpi;
48 } else {
49 return -CLHEP::halfpi;
50 }
51} // HepRotationY::phi()
52
53double HepRotationY::theta() const {
54 return std::fabs( its_d );
55} // HepRotationY::theta()
56
57double HepRotationY::psi() const {
58 if ( its_d == 0 ) {
59 return 0;
60 } else if ( (its_d < 0) || (its_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
79double HepRotationY::phiX() const {
80 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
81 // or ---- return 0;
82}
83
84double HepRotationY::phiY() const {
85 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
86 // or ---- return CLHEP::halfpi;
87}
88
89double HepRotationY::phiZ() const {
90 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
91 // or ---- return 0;
92}
93
94double HepRotationY::thetaX() const {
95 return safe_acos(zx());
96}
97
98double HepRotationY::thetaY() const {
99 return safe_acos(zy());
100 // or ---- return CLHEP::halfpi;
101}
102
103double HepRotationY::thetaZ() const {
104 return safe_acos(zz());
105 // or ---- return d;
106}
107
108void 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
136double HepRotationY::distance2( const HepRotationY & r ) const {
137 double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
138 return (answer >= 0) ? answer : 0;
139}
140
141double 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
149double HepRotationY::distance2( const HepLorentzRotation & lt ) const {
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
159double HepRotationY::distance2( const HepBoost & lt ) const {
160 return distance2( HepLorentzRotation(lt));
161}
162
163double HepRotationY::howNear( const HepRotationY & r ) const {
164 return std::sqrt(distance2(r));
165}
166double HepRotationY::howNear( const HepRotation & r ) const {
167 return std::sqrt(distance2(r));
168}
169double HepRotationY::howNear( const HepBoost & lt ) const {
170 return std::sqrt(distance2(lt));
171}
172double HepRotationY::howNear( const HepLorentzRotation & lt ) const {
173 return std::sqrt(distance2(lt));
174}
175bool HepRotationY::isNear(const HepRotationY & r,double epsilon)const{
176 return (distance2(r) <= epsilon*epsilon);
177}
178bool HepRotationY::isNear(const HepRotation & r,double epsilon)const {
179 return (distance2(r) <= epsilon*epsilon);
180}
181bool 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
189double HepRotationY::norm2() const {
190 return 2.0 - 2.0 * its_c;
191}
192
193std::ostream & HepRotationY::print( std::ostream & os ) const {
194 os << "\nRotation about Y (" << its_d <<
195 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
196 return os;
197}
198
199} // namespace CLHEP
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
void setDelta(double delta)
Definition RotationY.cc:108
static double proper(double delta)
double phiZ() const
Definition RotationY.cc:89
double zz() const
double yz() const
double theta() const
Definition RotationY.cc:53
double yx() const
bool isNear(const HepRotationY &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition RotationY.cc:175
double howNear(const HepRotationY &r) const
Definition RotationY.cc:163
double zy() const
double zx() const
double xx() const
double phi() const
Definition RotationY.cc:43
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition RotationY.cc:113
HepRotationY & set(double delta)
Definition RotationY.cc:36
double xz() const
HepAxisAngle axisAngle() const
double thetaY() const
Definition RotationY.cc:98
double distance2(const HepRotationY &r) const
Definition RotationY.cc:136
std::ostream & print(std::ostream &os) const
Definition RotationY.cc:193
double yy() const
double phiY() const
Definition RotationY.cc:84
double psi() const
Definition RotationY.cc:57
double xy() const
double thetaX() const
Definition RotationY.cc:94
double thetaZ() const
Definition RotationY.cc:103
double phiX() const
Definition RotationY.cc:79
double norm2() const
Definition RotationY.cc:189
HepEulerAngles eulerAngles() const
Definition RotationY.cc:67
double zz() const
double zx() const
double xx() const
double yy() const
double xz() const