Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
Boost.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 the HepBoost class.
7//
8
12
13#include <cmath>
14#include <iostream>
15
16namespace CLHEP {
17
18// ---------- Constructors and Assignment:
19
20HepBoost & HepBoost::set (double bx, double by, double bz) {
21 double bp2 = bx*bx + by*by + bz*bz;
22// if (bp2 >= 1) {
23// std::cerr << "HepBoost::set() - "
24// << "Boost Vector supplied to set HepBoost represents speed >= c." << std::endl;
25// }
26 double ggamma = 1.0 / std::sqrt(1.0 - bp2);
27 double bgamma = ggamma * ggamma / (1.0 + ggamma);
28 rep_.xx_ = 1.0 + bgamma * bx * bx;
29 rep_.yy_ = 1.0 + bgamma * by * by;
30 rep_.zz_ = 1.0 + bgamma * bz * bz;
31 rep_.xy_ = bgamma * bx * by;
32 rep_.xz_ = bgamma * bx * bz;
33 rep_.yz_ = bgamma * by * bz;
34 rep_.xt_ = ggamma * bx;
35 rep_.yt_ = ggamma * by;
36 rep_.zt_ = ggamma * bz;
37 rep_.tt_ = ggamma;
38 return *this;
39}
40
42 rep_ = m1;
43 return *this;
44}
45
46HepBoost & HepBoost::set (Hep3Vector ddirection, double bbeta) {
47 double length = ddirection.mag();
48 if (length <= 0) { // Nan-proofing
49 std::cerr << "HepBoost::set() - "
50 << "Direction supplied to set HepBoost is zero." << std::endl;
51 set (0,0,0);
52 return *this;
53 }
54 set(bbeta*ddirection.x()/length,
55 bbeta*ddirection.y()/length,
56 bbeta*ddirection.z()/length);
57 return *this;
58}
59
60HepBoost & HepBoost::set (const Hep3Vector & bboost) {
61 return set (bboost.x(), bboost.y(), bboost.z());
62}
63
64// ---------- Accessors:
65
66// ---------- Decomposition:
67
68void HepBoost::decompose (HepRotation & rotation, HepBoost & boost) const {
69 HepAxisAngle vdelta = HepAxisAngle();
70 rotation = HepRotation(vdelta);
71 Hep3Vector bbeta = boostVector();
72 boost = HepBoost(bbeta);
73}
74
75void HepBoost::decompose (HepAxisAngle & rotation, Hep3Vector & boost) const {
76 rotation = HepAxisAngle();
77 boost = boostVector();
78}
79
80void HepBoost::decompose (HepBoost & boost, HepRotation & rotation) const {
81 HepAxisAngle vdelta = HepAxisAngle();
82 rotation = HepRotation(vdelta);
83 Hep3Vector bbeta = boostVector();
84 boost = HepBoost(bbeta);
85}
86
87void HepBoost::decompose (Hep3Vector & boost, HepAxisAngle & rotation) const {
88 rotation = HepAxisAngle();
89 boost = boostVector();
90}
91
92// ---------- Comparisons:
93
94double HepBoost::distance2( const HepRotation & r ) const {
95 double db2 = norm2();
96 double dr2 = r.norm2();
97 return (db2 + dr2);
98}
99
100double HepBoost::distance2( const HepLorentzRotation & lt ) const {
101 HepBoost b1;
102 HepRotation r1;
103 lt.decompose(b1,r1);
104 double db2 = distance2(b1);
105 double dr2 = r1.norm2();
106 return (db2 + dr2);
107}
108
109double HepBoost::howNear ( const HepRotation & r ) const {
110 return std::sqrt(distance2(r));
111}
112
113double HepBoost::howNear ( const HepLorentzRotation & lt ) const {
114 return std::sqrt(distance2(lt));
115}
116
117bool HepBoost::isNear (const HepRotation & r, double epsilon) const {
118 double db2 = norm2();
119 if (db2 > epsilon*epsilon) return false;
120 double dr2 = r.norm2();
121 return (db2+dr2 <= epsilon*epsilon);
122}
123
125 double epsilon) const {
126 HepBoost b1;
127 HepRotation r1;
128 double db2 = distance2(b1);
129 lt.decompose(b1,r1);
130 if (db2 > epsilon*epsilon) return false;
131 double dr2 = r1.norm2();
132 return (db2 + dr2);
133}
134
135// ---------- Properties:
136
137double HepBoost::norm2() const {
138 double bgx = rep_.xt_;
139 double bgy = rep_.yt_;
140 double bgz = rep_.zt_;
141 return bgx*bgx+bgy*bgy+bgz*bgz;
142}
143
145 // Assuming the representation of this is close to a true pure boost,
146 // but may have drifted due to round-off error from many operations,
147 // this forms an "exact" pure boost matrix for the LT again.
148
149 // The natural way to do this is to use the t column as a boost and set
150 // based on that boost vector.
151
152 // There is perhaps danger that this boost vector will appear equal to or
153 // greater than a unit vector; the best we can do for such a case is use
154 // a boost in that direction but rescaled to just less than one.
155
156 // There is in principle no way that gamma could have become negative,
157 // but if that happens, we ZMthrow and (if continuing) just rescale, which
158 // will change the sign of the last column when computing the boost.
159
160 double gam = tt();
161 if (gam <= 0) { // 4/12/01 mf
162 std::cerr << "HepBoost::rectify() - "
163 << "Attempt to rectify a boost with non-positive gamma." << std::endl;
164 if (gam==0) return; // NaN-proofing
165 }
166 Hep3Vector boost (xt(), yt(), zt());
167 boost /= tt();
168 if ( boost.mag2() >= 1 ) { // NaN-proofing:
169 boost /= ( boost.mag() * ( 1.0 + 1.0e-16 ) ); // used to just check > 1
170 }
171 set ( boost );
172}
173
174// ---------- Application is all in .icc
175
176// ---------- Operations in the group of 4-Rotations
177
182 r.xx_*m1.xx_ + r.xy_*m1.yx_ + r.xz_*m1.zx_ + r.xt_*m1.tx_,
183 r.xx_*m1.xy_ + r.xy_*m1.yy_ + r.xz_*m1.zy_ + r.xt_*m1.ty_,
184 r.xx_*m1.xz_ + r.xy_*m1.yz_ + r.xz_*m1.zz_ + r.xt_*m1.tz_,
185 r.xx_*m1.xt_ + r.xy_*m1.yt_ + r.xz_*m1.zt_ + r.xt_*m1.tt_,
186
187 r.xy_*m1.xx_ + r.yy_*m1.yx_ + r.yz_*m1.zx_ + r.yt_*m1.tx_,
188 r.xy_*m1.xy_ + r.yy_*m1.yy_ + r.yz_*m1.zy_ + r.yt_*m1.ty_,
189 r.xy_*m1.xz_ + r.yy_*m1.yz_ + r.yz_*m1.zz_ + r.yt_*m1.tz_,
190 r.xy_*m1.xt_ + r.yy_*m1.yt_ + r.yz_*m1.zt_ + r.yt_*m1.tt_,
191
192 r.xz_*m1.xx_ + r.yz_*m1.yx_ + r.zz_*m1.zx_ + r.zt_*m1.tx_,
193 r.xz_*m1.xy_ + r.yz_*m1.yy_ + r.zz_*m1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_*m1.xt_ + r.yz_*m1.yt_ + r.zz_*m1.zt_ + r.zt_*m1.tt_,
221
222 r.xt_*m1.xx_ + r.yt_*m1.xy_ + r.zt_*m1.xz_ + r.tt_*m1.xt_,
223 r.xt_*m1.xy_ + r.yt_*m1.yy_ + r.zt_*m1.yz_ + r.tt_*m1.yt_,
224 r.xt_*m1.xz_ + r.yt_*m1.yz_ + r.zt_*m1.zz_ + r.tt_*m1.zt_,
225 r.xt_*m1.xt_ + r.yt_*m1.yt_ + r.zt_*m1.zt_ + r.tt_*m1.tt_) );
226}
227
230 return matrixMultiplication(lt.rep4x4());
231}
232
235 return matrixMultiplication(b.rep_);
236}
237
240 return matrixMultiplication(r.rep4x4());
241}
242
243// ---------- I/O:
244
245std::ostream & HepBoost::print( std::ostream & os ) const {
246 if ( rep_.tt_ <= 1 ) {
247 os << "Lorentz Boost( IDENTITY )";
248 } else {
249 double norm = boostVector().mag();
250 os << "\nLorentz Boost " << boostVector()/norm <<
251 "\n{beta = " << beta() << " gamma = " << gamma() << "}\n";
252 }
253 return os;
254}
255
256} // namespace CLHEP
double epsilon(double density, double temperature)
double z() const
double x() const
double mag2() const
double y() const
double mag() const
double norm2() const
Definition: Boost.cc:137
HepBoost & set(double betaX, double betaY, double betaZ)
Definition: Boost.cc:20
HepRep4x4Symmetric rep4x4Symmetric() const
void decompose(HepRotation &rotation, HepBoost &boost) const
Definition: Boost.cc:68
double beta() const
HepLorentzRotation matrixMultiplication(const HepRep4x4 &m) const
Definition: Boost.cc:179
bool isNear(const HepBoost &b, double epsilon=Hep4RotationInterface::tolerance) const
void rectify()
Definition: Boost.cc:144
HepLorentzVector operator*(const HepLorentzVector &p) const
double yt() const
double xt() const
double howNear(const HepBoost &b) const
double distance2(const HepBoost &b) const
double tt() const
Hep3Vector boostVector() const
double gamma() const
HepRep4x4Symmetric rep_
Definition: Boost.h:233
std::ostream & print(std::ostream &os) const
Definition: Boost.cc:245
double zt() const
HepRep4x4 rep4x4() const
void decompose(Hep3Vector &boost, HepAxisAngle &rotation) const
double norm2() const
Definition: RotationP.cc:46
HepRep4x4 rep4x4() const
Definition: DoubConv.h:17