CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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#include "CLHEP/Vector/defs.h"
11#include "CLHEP/Vector/RotationY.h"
12#include "CLHEP/Vector/AxisAngle.h"
13#include "CLHEP/Vector/EulerAngles.h"
14#include "CLHEP/Vector/LorentzRotation.h"
15#include "CLHEP/Units/PhysicalConstants.h"
16
17#include <cmath>
18#include <stdlib.h>
19#include <iostream>
20
21namespace CLHEP {
22
23static inline double safe_acos (double x) {
24 if (std::abs(x) <= 1.0) return std::acos(x);
25 return ( (x>0) ? 0 : CLHEP::pi );
26}
27
29 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
30{}
31
32HepRotationY & HepRotationY::set ( double ddelta ) {
33 its_d = proper(ddelta);
34 its_s = std::sin(its_d);
35 its_c = std::cos(its_d);
36 return *this;
37}
38
39double HepRotationY::phi() const {
40 if ( its_d == 0 ) {
41 return 0;
42 } else if ( (its_d < 0) || (its_d == CLHEP::pi) ) {
43 return +CLHEP::halfpi;
44 } else {
45 return -CLHEP::halfpi;
46 }
47} // HepRotationY::phi()
48
49double HepRotationY::theta() const {
50 return std::fabs( its_d );
51} // HepRotationY::theta()
52
53double HepRotationY::psi() const {
54 if ( its_d == 0 ) {
55 return 0;
56 } else if ( (its_d < 0) || (its_d == CLHEP::pi) ) {
57 return -CLHEP::halfpi;
58 } else {
59 return +CLHEP::halfpi;
60 }
61} // HepRotationY::psi()
62
64 return HepEulerAngles( phi(), theta(), psi() );
65} // HepRotationY::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
75double HepRotationY::phiX() const {
76 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
77 // or ---- return 0;
78}
79
80double HepRotationY::phiY() const {
81 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
82 // or ---- return CLHEP::halfpi;
83}
84
85double HepRotationY::phiZ() const {
86 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
87 // or ---- return 0;
88}
89
90double HepRotationY::thetaX() const {
91 return safe_acos(zx());
92}
93
94double HepRotationY::thetaY() const {
95 return safe_acos(zy());
96 // or ---- return CLHEP::halfpi;
97}
98
99double HepRotationY::thetaZ() const {
100 return safe_acos(zz());
101 // or ---- return d;
102}
103
104void HepRotationY::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
132double HepRotationY::distance2( const HepRotationY & 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
137double HepRotationY::distance2( const HepRotation & r ) const {
138 double sum = xx() * r.xx() + xz() * r.xz()
139 + r.yy()
140 + zx() * r.zx() + zz() * r.zz();
141 double answer = 3.0 - sum;
142 return (answer >= 0 ) ? answer : 0;
143}
144
145double HepRotationY::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
155double HepRotationY::distance2( const HepBoost & lt ) const {
156 return distance2( HepLorentzRotation(lt));
157}
158
159double HepRotationY::howNear( const HepRotationY & r ) const {
160 return std::sqrt(distance2(r));
161}
162double HepRotationY::howNear( const HepRotation & r ) const {
163 return std::sqrt(distance2(r));
164}
165double HepRotationY::howNear( const HepBoost & lt ) const {
166 return std::sqrt(distance2(lt));
167}
168double HepRotationY::howNear( const HepLorentzRotation & lt ) const {
169 return std::sqrt(distance2(lt));
170}
171bool HepRotationY::isNear(const HepRotationY & r,double epsilon)const{
172 return (distance2(r) <= epsilon*epsilon);
173}
174bool HepRotationY::isNear(const HepRotation & r,double epsilon)const {
175 return (distance2(r) <= epsilon*epsilon);
176}
177bool HepRotationY::isNear( const HepBoost & lt,double epsilon) const {
178 return (distance2(lt) <= epsilon*epsilon);
179}
181 double epsilon) const {
182 return (distance2(lt) <= epsilon*epsilon);
183}
184
185double HepRotationY::norm2() const {
186 return 2.0 - 2.0 * its_c;
187}
188
189std::ostream & HepRotationY::print( std::ostream & os ) const {
190 os << "\nRotation about Y (" << its_d <<
191 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
192 return os;
193}
194
195} // namespace CLHEP
double beta() const
Definition: SpaceVectorP.cc:28
void set(double x, double y, double z)
HepBoost & set(double betaX, double betaY, double betaZ)
Definition: Boost.cc:22
void decompose(Hep3Vector &boost, HepAxisAngle &rotation) const
void setDelta(double delta)
Definition: RotationY.cc:104
static double proper(double delta)
double phiZ() const
Definition: RotationY.cc:85
double zz() const
double yz() const
double theta() const
Definition: RotationY.cc:49
double yx() const
bool isNear(const HepRotationY &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationY.cc:171
double howNear(const HepRotationY &r) const
Definition: RotationY.cc:159
double zy() const
double zx() const
double xx() const
double phi() const
Definition: RotationY.cc:39
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationY.cc:109
HepRotationY & set(double delta)
Definition: RotationY.cc:32
double xz() const
HepAxisAngle axisAngle() const
double thetaY() const
Definition: RotationY.cc:94
double distance2(const HepRotationY &r) const
Definition: RotationY.cc:132
std::ostream & print(std::ostream &os) const
Definition: RotationY.cc:189
double yy() const
double phiY() const
Definition: RotationY.cc:80
double psi() const
Definition: RotationY.cc:53
double xy() const
double thetaX() const
Definition: RotationY.cc:90
double thetaZ() const
Definition: RotationY.cc:99
double phiX() const
Definition: RotationY.cc:75
double norm2() const
Definition: RotationY.cc:185
HepEulerAngles eulerAngles() const
Definition: RotationY.cc:63
double zz() const
double zx() const
double xx() const
double yy() const
double xz() const