source: trunk/CLHEP/src/BoostX.cc@ 18

Last change on this file since 18 was 4, checked in by Pavel Demin, 16 years ago

first commit

File size: 4.3 KB
Line 
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 the HepBoostX class.
7//
8
9#ifdef GNUPRAGMA
10#pragma implementation
11#endif
12
13#include "CLHEP/Vector/defs.h"
14#include "CLHEP/Vector/BoostX.h"
15#include "CLHEP/Vector/Boost.h"
16#include "CLHEP/Vector/Rotation.h"
17#include "CLHEP/Vector/LorentzRotation.h"
18#include "CLHEP/Vector/ZMxpv.h"
19
20namespace CLHEP {
21
22
23// ---------- Constructors and Assignment:
24
25HepBoostX & HepBoostX::set (double beta) {
26 double b2 = beta*beta;
27 if (b2 >= 1) {
28 ZMthrowA (ZMxpvTachyonic(
29 "Beta supplied to set HepBoostX represents speed >= c."));
30 beta_ = 1.0 - 1.0E-8; // NaN-proofing
31 gamma_ = 1.0 / sqrt(1.0 - b2);
32 return *this;
33 }
34 beta_ = beta;
35 gamma_ = 1.0 / sqrt(1.0 - b2);
36 return *this;
37}
38
39// ---------- Accessors:
40
41HepRep4x4 HepBoostX::rep4x4() const {
42 double bg = beta_*gamma_;
43 return HepRep4x4( gamma_, 0, 0, bg,
44 0, 1, 0, 0,
45 0, 0, 1, 0,
46 bg, 0, 0, gamma_ );
47}
48
49HepRep4x4Symmetric HepBoostX::rep4x4Symmetric() const {
50 double bg = beta_*gamma_;
51 return HepRep4x4Symmetric( gamma_, 0, 0, bg,
52 1, 0, 0,
53 1, 0,
54 gamma_ );
55}
56
57// ---------- Decomposition:
58
59void HepBoostX::decompose (HepRotation & rotation, HepBoost & boost) const {
60 HepAxisAngle vdelta = HepAxisAngle();
61 rotation = HepRotation(vdelta);
62 Hep3Vector beta = boostVector();
63 boost = HepBoost(beta);
64}
65
66void HepBoostX::decompose (HepAxisAngle & rotation, Hep3Vector & boost) const {
67 rotation = HepAxisAngle();
68 boost = boostVector();
69}
70
71void HepBoostX::decompose (HepBoost & boost, HepRotation & rotation) const {
72 HepAxisAngle vdelta = HepAxisAngle();
73 rotation = HepRotation(vdelta);
74 Hep3Vector beta = boostVector();
75 boost = HepBoost(beta);
76}
77
78void HepBoostX::decompose (Hep3Vector & boost, HepAxisAngle & rotation) const {
79 rotation = HepAxisAngle();
80 boost = boostVector();
81}
82
83// ---------- Comparisons:
84
85double HepBoostX::distance2( const HepBoost & b ) const {
86 return b.distance2(*this);
87}
88
89double HepBoostX::distance2( const HepRotation & r ) const {
90 double db2 = norm2();
91 double dr2 = r.norm2();
92 return (db2 + dr2);
93}
94
95double HepBoostX::distance2( const HepLorentzRotation & lt ) const {
96 HepBoost b1;
97 HepRotation r1;
98 lt.decompose(b1,r1);
99 double db2 = distance2(b1);
100 double dr2 = r1.norm2();
101 return (db2 + dr2);
102}
103
104bool HepBoostX::isNear (const HepRotation & r, double epsilon) const {
105 double db2 = norm2();
106 if (db2 > epsilon*epsilon) return false;
107 double dr2 = r.norm2();
108 return (db2+dr2 <= epsilon*epsilon);
109}
110
111bool HepBoostX::isNear ( const HepLorentzRotation & lt,
112 double epsilon) const {
113 HepBoost b1;
114 HepRotation r1;
115 double db2 = distance2(b1);
116 lt.decompose(b1,r1);
117 if (db2 > epsilon*epsilon) return false;
118 double dr2 = r1.norm2();
119 return (db2 + dr2);
120}
121
122// ---------- Properties:
123
124void HepBoostX::rectify() {
125 // Assuming the representation of this is close to a true pure boost,
126 // but may have drifted due to round-off error from many operations,
127 // this forms an "exact" pure boostX matrix for again.
128
129 double b2 = beta_*beta_;
130 if (b2 >= 1) {
131 beta_ = 1.0 - 1.0e-8; // NaN-proofing
132 b2 = beta_*beta_;
133 }
134 gamma_ = 1.0 / sqrt(1.0 - b2);
135}
136
137// ---------- Application:
138
139// ---------- Operations in the group of 4-Rotations
140
141HepBoostX HepBoostX::operator * (const HepBoostX & b) const {
142 return HepBoostX ( (beta()+b.beta()) / (1+beta()*b.beta()) );
143}
144HepLorentzRotation HepBoostX::operator * (const HepBoost & b) const {
145 HepLorentzRotation me (*this);
146 return me*b;
147}
148HepLorentzRotation HepBoostX::operator * (const HepRotation & r) const {
149 HepLorentzRotation me (*this);
150 return me*r;
151}
152HepLorentzRotation HepBoostX::operator * (const HepLorentzRotation & lt) const {
153 HepLorentzRotation me (*this);
154 return me*lt;
155}
156
157// ---------- I/O:
158
159std::ostream & HepBoostX::print( std::ostream & os ) const {
160 os << "Boost in X direction (beta = " << beta_
161 << ", gamma = " << gamma_ << ") ";
162 return os;
163}
164
165} // namespace CLHEP
Note: See TracBrowser for help on using the repository browser.