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
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
36HepRotationX & 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
43double 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
51double HepRotationX::theta() const {
52 return std::fabs( its_d );
53} // HepRotationX::theta()
54
55double 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
75double HepRotationX::phiX() const {
76 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
77 // or ---- return 0;
78}
79
80double 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
85double 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
90double HepRotationX::thetaX() const {
91 return safe_acos(zx());
92 // or ---- return CLHEP::halfpi;
93}
94
95double HepRotationX::thetaY() const {
96 return safe_acos(zy());
97}
98
99double HepRotationX::thetaZ() const {
100 return safe_acos(zz());
101 // or ---- return d;
102}
103
104void 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
132double 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
137double 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
145double HepRotationX::distance2( const HepLorentzRotation & lt ) const {
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 HepRotationX::distance2( const HepBoost & lt ) const {
156 return distance2( HepLorentzRotation(lt));
157}
158
159double HepRotationX::howNear( const HepRotationX & r ) const {
160 return std::sqrt(distance2(r));
161}
162double HepRotationX::howNear( const HepRotation & r ) const {
163 return std::sqrt(distance2(r));
164}
165double HepRotationX::howNear( const HepBoost & b ) const {
166 return std::sqrt(distance2(b));
167}
168double HepRotationX::howNear( const HepLorentzRotation & lt ) const {
169 return std::sqrt(distance2(lt));
170}
171bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{
172 return (distance2(r) <= epsilon*epsilon);
173}
174bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{
175 return (distance2(r) <= epsilon*epsilon);
176}
177bool 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
186double HepRotationX::norm2() const {
187 return 2.0 - 2.0 * its_c;
188}
189
190std::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)
HepBoost & set(double betaX, double betaY, double betaZ)
Definition: Boost.cc:23
void decompose(Hep3Vector &boost, HepAxisAngle &rotation) const
double phiX() const
Definition: RotationX.cc:75
double xy() const
double thetaZ() const
Definition: RotationX.cc:99
double xx() const
double phiY() const
Definition: RotationX.cc:80
double yz() const
static double proper(double delta)
double zy() const
HepRotationX & set(double delta)
Definition: RotationX.cc:36
HepEulerAngles eulerAngles() const
Definition: RotationX.cc:63
double psi() const
Definition: RotationX.cc:55
double howNear(const HepRotationX &r) const
Definition: RotationX.cc:159
void setDelta(double delta)
Definition: RotationX.cc:104
double yy() const
double phi() const
Definition: RotationX.cc:43
double thetaY() const
Definition: RotationX.cc:95
double xz() const
double phiZ() const
Definition: RotationX.cc:85
double thetaX() const
Definition: RotationX.cc:90
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationX.cc:109
HepAxisAngle axisAngle() const
std::ostream & print(std::ostream &os) const
Definition: RotationX.cc:190
bool isNear(const HepRotationX &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationX.cc:171
double theta() const
Definition: RotationX.cc:51
double zz() const
double distance2(const HepRotationX &r) const
Definition: RotationX.cc:132
double norm2() const
Definition: RotationX.cc:186
double yx() const
double zx() const
double zz() const
double yz() const
double zy() const
double xx() const
double yy() const
@ b
@ a