rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.2
LorentzTrans.hh
1#ifndef RIVET_MATH_LORENTZTRANS
2#define RIVET_MATH_LORENTZTRANS
3
4#include "Rivet/Math/MathConstants.hh"
5#include "Rivet/Math/MathUtils.hh"
6#include "Rivet/Math/MatrixN.hh"
7#include "Rivet/Math/Matrix3.hh"
8#include "Rivet/Math/Vector4.hh"
9#include <ostream>
10
11namespace Rivet {
12
13
22 public:
23
26
28 static double beta2gamma(double beta) {
29 return 1.0 / sqrt(1 - sqr(beta));
30 }
31
33 static double gamma2beta(double gamma) {
34 return sqrt(1 - sqr(1/gamma));
35 }
36
38
39
42
45 _boostMatrix = Matrix<4>::mkIdentity();
46 }
47
49 LorentzTransform(const Matrix<4>& boostMatrix) {
50 _boostMatrix = boostMatrix;
51 }
52
56 return rtn.setBetaVec(vbeta);
57 }
58
62 return rtn.setBetaVec(-vbeta);
63 }
64
68 if (!vgamma.isZero()) rtn.setGammaVec(vgamma);
69 return rtn;
70 }
71
75 if (!vgamma.isZero()) rtn.setGammaVec(-vgamma);
76 return rtn;
77 }
78
83
88
90
91
94
96 LorentzTransform& _setBoost(const Vector3& vec, double beta, double gamma) {
97 // Set to identity for null boosts
98 _boostMatrix = Matrix<4>::mkIdentity();
99 if (isZero(beta)) return *this;
100 //
101 // It's along the x, y, or z axis if 2 Cartesian components are zero
102 const bool alongxyz = (int(vec.x() == 0) + int(vec.y() == 0) + int(vec.z() == 0) == 2);
103 const int i = (!alongxyz || vec.x() != 0) ? 1 : (vec.y() != 0) ? 2 : 3;
104 const int isign = !alongxyz ? 1 : sign(vec[i-1]);
105 //
106 _boostMatrix.set(0, 0, gamma);
107 _boostMatrix.set(i, i, gamma);
108 _boostMatrix.set(0, i, +isign*beta*gamma); //< +ve coeff since active boost
109 _boostMatrix.set(i, 0, +isign*beta*gamma); //< +ve coeff since active boost
110 //
111 if (!alongxyz) _boostMatrix = rotate(Vector3::mkX(), vec)._boostMatrix;
112 return *this;
113 }
114
117 // Set to identity for null boosts
118 _boostMatrix = Matrix<4>::mkIdentity();
119 if (isZero(vbeta.mod2())) return *this;
120 const double beta = vbeta.mod();
121 const double gamma = beta2gamma(beta);
122 return _setBoost(vbeta.unit(), beta, gamma);
123 }
124
126 Vector3 betaVec() const {
127 FourMomentum boost(_boostMatrix.getColumn(0)); //< @todo WRONG?!
128 //cout << "!!!" << boost << '\n';
129 if (boost.isZero()) return Vector3();
130 assert(boost.E() > 0);
131 const double beta = boost.p3().mod() / boost.E();
132 return boost.p3().unit() * beta;
133 }
134
136 double beta() const {
137 return betaVec().mod();
138 }
139
140
143 // Set to identity for null boosts
144 _boostMatrix = Matrix<4>::mkIdentity();
145 if (isZero(vgamma.mod2() - 1)) return *this;
146 const double gamma = vgamma.mod();
147 const double beta = gamma2beta(gamma);
148 return _setBoost(vgamma.unit(), beta, gamma);
149 }
150
153 FourMomentum boost(_boostMatrix.getColumn(0)); //< @todo WRONG?!
154 if (boost.isZero()) return Vector3();
155 assert(boost.E() > 0);
156 const double beta = boost.p3().mod() / boost.E();
157 return boost.p3().unit() * beta;
158 }
159
161 double gamma() const {
162 return beta2gamma(beta());
163 }
164
166
167
169 FourVector transform(const FourVector& v4) const {
170 return multiply(_boostMatrix, v4);
171 }
172
175 return multiply(_boostMatrix, v4);
176 }
177
180 return transform(v4);
181 }
182
185 return transform(v4);
186 }
187
188
191
193 LorentzTransform rotate(const Vector3& from, const Vector3& to) const {
194 return rotate(Matrix3(from, to));
195 }
196
198 LorentzTransform rotate(const Vector3& axis, double angle) const {
199 return rotate(Matrix3(axis, angle));
200 }
201
203 LorentzTransform rotate(const Matrix3& rot) const {
204 LorentzTransform lt = *this;
205 const Matrix4 rot4 = _mkMatrix4(rot);
206 const Matrix4 newlt = rot4 * _boostMatrix * rot4.inverse();
207 lt._boostMatrix = newlt;
208 return lt;
209 }
210
214 rtn._boostMatrix = _boostMatrix.inverse();
215 return rtn;
216 }
217
221 rtn._boostMatrix = _boostMatrix * lt._boostMatrix;
222 return rtn;
223 }
224
227 return combine(lt);
228 }
229
232 _boostMatrix = multiply(_mkMatrix4(m3),_boostMatrix);
233 return *this;
234 }
235
238 _boostMatrix *= _mkMatrix4(m3);
239 return *this;
240 }
241
243
244
247 return _boostMatrix;
248 }
249
250
251 private:
252
253 Matrix4 _mkMatrix4(const Matrix3& m3) const {
254 Matrix4 m4 = Matrix4::mkIdentity();
255 for (size_t i = 0; i < 3; ++i) {
256 for (size_t j = 0; j < 3; ++j) {
257 m4.set(i+1, j+1, m3.get(i, j));
258 }
259 }
260 return m4;
261 }
262
263 Matrix4 _boostMatrix;
264
265 };
266
267
268
269 inline LorentzTransform inverse(const LorentzTransform& lt) {
270 return lt.inverse();
271 }
272
273 inline LorentzTransform combine(const LorentzTransform& a, const LorentzTransform& b) {
274 return a.combine(b);
275 }
276
277 inline FourVector transform(const LorentzTransform& lt, const FourVector& v4) {
278 return lt.transform(v4);
279 }
280
281
283
284
285 inline string toString(const LorentzTransform& lt) {
286 return toString(lt.toMatrix());
287 }
288
289 inline std::ostream& operator<<(std::ostream& out, const LorentzTransform& lt) {
290 out << toString(lt);
291 return out;
292 }
293
294
295}
296
297#endif
Specialized version of the FourVector with momentum/energy functionality.
Definition Vector4.hh:316
Vector3 p3() const
Get 3-momentum part, .
Definition Vector4.hh:593
Vector3 betaVec() const
Definition Vector4.hh:688
double E() const
Get energy (time component of momentum).
Definition Vector4.hh:553
Specialisation of VectorN to a general (non-momentum) Lorentz 4-vector.
Definition Vector4.hh:30
Object implementing Lorentz transform calculations and boosts.
Definition LorentzTrans.hh:21
static LorentzTransform mkFrameTransformFromGamma(const Vector3 &vgamma)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition LorentzTrans.hh:73
LorentzTransform rotate(const Vector3 &from, const Vector3 &to) const
Rotate the transformation cf. the difference between vectors from and to.
Definition LorentzTrans.hh:193
LorentzTransform & setBetaVec(const Vector3 &vbeta)
Set up an active Lorentz boost from the vector.
Definition LorentzTrans.hh:116
static LorentzTransform mkObjTransformFromBeta(const Vector3 &vbeta)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition LorentzTrans.hh:54
static LorentzTransform mkFrameTransformFromBeta(const Vector3 &vbeta)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition LorentzTrans.hh:60
FourVector operator()(const FourVector &v4) const
Apply this transformation to the given 4-vector.
Definition LorentzTrans.hh:179
LorentzTransform preMult(const Matrix3 &m3)
Pre-multiply m3 by this LT.
Definition LorentzTrans.hh:231
LorentzTransform rotate(const Matrix3 &rot) const
Rotate the transformation by the 3D rotation matrix rot.
Definition LorentzTrans.hh:203
static LorentzTransform mkObjTransformFromGamma(const Vector3 &vgamma)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition LorentzTrans.hh:66
double beta() const
Get the factor.
Definition LorentzTrans.hh:136
Vector3 betaVec() const
Get the vector for an active Lorentz boost.
Definition LorentzTrans.hh:126
LorentzTransform operator*(const LorentzTransform &lt) const
Operator combination of two LTs.
Definition LorentzTrans.hh:226
static double beta2gamma(double beta)
Calculate the factor from .
Definition LorentzTrans.hh:28
LorentzTransform()
Default (identity) constructor.
Definition LorentzTrans.hh:44
static LorentzTransform mkFrameTransform(const FourMomentum &p4)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition LorentzTrans.hh:85
LorentzTransform postMult(const Matrix3 &m3)
Post-multiply m3 by this LT.
Definition LorentzTrans.hh:237
static LorentzTransform mkObjTransform(const FourMomentum &p4)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition LorentzTrans.hh:80
Matrix4 toMatrix() const
Return the matrix form.
Definition LorentzTrans.hh:246
LorentzTransform inverse() const
Calculate the inverse transform.
Definition LorentzTrans.hh:212
static double gamma2beta(double gamma)
Calculate from the factor.
Definition LorentzTrans.hh:33
LorentzTransform(const Matrix< 4 > &boostMatrix)
Constructor from a 4x4 matrix.
Definition LorentzTrans.hh:49
FourMomentum transform(const FourMomentum &v4) const
Apply this transformation to the given 4-mometum.
Definition LorentzTrans.hh:174
LorentzTransform & setGammaVec(const Vector3 &vgamma)
Set up an active Lorentz boost from the vector.
Definition LorentzTrans.hh:142
FourVector transform(const FourVector &v4) const
Apply this transformation to the given 4-vector.
Definition LorentzTrans.hh:169
LorentzTransform rotate(const Vector3 &axis, double angle) const
Rotate the transformation by angle radians about axis.
Definition LorentzTrans.hh:198
Vector3 gammaVec() const
Get the vector for an active Lorentz boost.
Definition LorentzTrans.hh:152
double gamma() const
Get the factor.
Definition LorentzTrans.hh:161
LorentzTransform combine(const LorentzTransform &lt) const
Combine LTs, treating this as the LH matrix.
Definition LorentzTrans.hh:219
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition Matrix3.hh:13
General -dimensional mathematical matrix object.
Definition MatrixN.hh:30
Matrix< N > inverse() const
Calculate inverse.
Definition MatrixN.hh:131
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
Vector3 unit() const
Synonym for unitVec.
Definition Vector3.hh:124
double mod() const
Calculate the modulus of a vector. .
Definition VectorN.hh:95
double mod2() const
Calculate the modulus-squared of a vector. .
Definition VectorN.hh:84
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition VectorN.hh:75
Definition MC_CENT_PPB_Projections.hh:10
constexpr std::enable_if_t< std::is_arithmetic_v< NUM >, int > sign(NUM val)
Find the sign of a number.
Definition MathUtils.hh:264
std::ostream & operator<<(std::ostream &os, const AnalysisInfo &ai)
Stream an AnalysisInfo as a text description.
Definition AnalysisInfo.hh:362
std::enable_if_t< std::is_floating_point_v< NUM >, bool > isZero(NUM val, double tolerance=1e-8)
Compare a number to zero.
Definition MathUtils.hh:24
std::enable_if_t< std::is_arithmetic_v< NUM >, NUM > sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.hh:218
std::string toString(const AnalysisInfo &ai)
String representation.
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:177