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