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