CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
EulerAngles.cc
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// EulerAngles.cc
4//
5// Methods for classes, and instances of globals, declared in EulerAngles.h
6//
7// History:
8//
9// 04-Dec-1997 MF Stub with just PI
10// 12-Jan-1998 WEB PI now found in ZMutility; used ZMutility headers
11// where available
12// 16-Mar-1998 WEB Corrected ZMpvEulerAnglesRep
13// 15-Jun-1998 WEB Added namespace support
14// 26-Jul-2000 MF CLHEP version
15// 12-Apr-2001 MF NaN-proofing
16// 19-Nov-2001 MF Correction to ZMpvEulerAnglesRep, which was affecting
17// .isNear(). array[3] had been incorrect.
18// Note - the correct form was used in all other places
19// including Rotation.set(phi, theta, psi).
20//
21// ----------------------------------------------------------------------
22
23
24#include "CLHEP/Vector/defs.h"
25#include "CLHEP/Vector/EulerAngles.h"
26
27#include "CLHEP/Vector/ThreeVector.h"
28
29#include <cmath>
30#include <iostream>
31
32namespace CLHEP {
33
34//-*************
35// static consts
36//-*************
37
39
40//-*******************
41// measure of distance
42//-*******************
43
44
45static void ZMpvEulerAnglesRep ( const HepEulerAngles & ex, double array[] ) {
46
47 double sinPhi = std::sin( ex.phi() ) , cosPhi = std::cos( ex.phi() );
48 double sinTheta = std::sin( ex.theta() ), cosTheta = std::cos( ex.theta() );
49 double sinPsi = std::sin( ex.psi() ) , cosPsi = std::cos( ex.psi() );
50
51 array[0] = cosPsi * cosPhi - sinPsi * cosTheta * sinPhi;
52 array[1] = cosPsi * sinPhi + sinPsi * cosTheta * cosPhi;
53 array[2] = sinPsi * sinTheta;
54
55 array[3] = - sinPsi * cosPhi - cosPsi * cosTheta * sinPhi;
56 array[4] = - sinPsi * sinPhi + cosPsi * cosTheta * cosPhi;
57 array[5] = cosPsi * sinTheta;
58
59 array[6] = sinTheta * sinPhi;
60 array[7] = - sinTheta * cosPhi;
61 array[8] = cosTheta;
62
63} // ZMpvEulerAnglesRep
64
65
66double HepEulerAngles::distance( const EA & ex ) const {
67
68 double thisRep[9];
69 double exRep[9];
70
71 ZMpvEulerAnglesRep ( *this, thisRep );
72 ZMpvEulerAnglesRep ( ex, exRep );
73
74 double sum = 0.0;
75 for (int i = 0; i < 9; i++) {
76 sum += thisRep[i] * exRep[i];
77 }
78
79 double d = 3.0 - sum; // NaN-proofing:
80 return (d >= 0) ? d : 0; // std::sqrt(distance) is used in howNear()
81
82} // HepEulerAngles::distance()
83
84
85bool HepEulerAngles::isNear( const EA & ex, double epsilon ) const {
86
87 return distance( ex ) <= epsilon*epsilon ;
88
89} // HepEulerAngles::isNear()
90
91
92double HepEulerAngles::howNear( const EA & ex ) const {
93
94 return std::sqrt( distance( ex ) );
95
96} // HepEulerAngles::howNear()
97
98//-**************
99// Global Methods
100//-**************
101
102std::ostream & operator<<(std::ostream & os, const HepEulerAngles & ea)
103{
104 os << "(" << ea.phi() << ", " << ea.theta() << ", " << ea.psi() << ")";
105 return os;
106} // operator<<()
107
108void ZMinput3doubles ( std::istream & is, const char * type,
109 double & x, double & y, double & z );
110
111std::istream & operator>>(std::istream & is, HepEulerAngles & ea) {
112 double thePhi;
113 double theTheta;
114 double thePsi;
115 ZMinput3doubles ( is, "HepEulerAngle", thePhi , theTheta , thePsi );
116 ea.set ( thePhi , theTheta , thePsi );
117 return is;
118} // operator>>()
119
120} // namespace CLHEP
121
122
static const int ToleranceTicks
Definition: ThreeVector.h:295
double phi() const
double theta() const
double distance(const HepEulerAngles &ex) const
Definition: EulerAngles.cc:66
double psi() const
EA & set(double phi, double theta, double psi)
static double tolerance
Definition: EulerAngles.h:36
double howNear(const EA &ea) const
Definition: EulerAngles.cc:92
bool isNear(const EA &ea, double epsilon=tolerance) const
Definition: EulerAngles.cc:85
std::istream & operator>>(std::istream &is, HepRandom &dist)
Definition: Random.cc:225
std::ostream & operator<<(std::ostream &s, const HepDiagMatrix &q)
Definition: DiagMatrix.cc:560
void ZMinput3doubles(std::istream &is, const char *type, double &x, double &y, double &z)
Definition: ZMinput.cc:37