Rivet: /Users/chrisg/software/rivet/include/Rivet/Math/LorentzTrans.hh Source File

| Rivet 3.1.9

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
21 class LorentzTransform {
22 public:
23
25
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
41
42
44 LorentzTransform() {
45 _boostMatrix = Matrix<4>::mkIdentity();
46 }
47
49 LorentzTransform(const Matrix<4>& boostMatrix) {
50 _boostMatrix = boostMatrix;
51 }
52
54 static LorentzTransform mkObjTransformFromBeta(const Vector3& vbeta) {
55 LorentzTransform rtn;
56 return rtn.setBetaVec(vbeta);
57 }
58
60 static LorentzTransform mkFrameTransformFromBeta(const Vector3& vbeta) {
61 LorentzTransform rtn;
62 return rtn.setBetaVec(-vbeta);
63 }
64
66 static LorentzTransform mkObjTransformFromGamma(const Vector3& vgamma) {
67 LorentzTransform rtn;
68 if (!vgamma.isZero()) rtn.setGammaVec(vgamma);
69 return rtn;
70 }
71
73 static LorentzTransform mkFrameTransformFromGamma(const Vector3& vgamma) {
74 LorentzTransform rtn;
75 if (!vgamma.isZero()) rtn.setGammaVec(-vgamma);
76 return rtn;
77 }
78
80 static LorentzTransform mkObjTransform(const FourMomentum& p4) {
81 return mkObjTransformFromBeta(p4.betaVec());
82 }
83
85 static LorentzTransform mkFrameTransform(const FourMomentum& p4) {
86 return mkObjTransformFromBeta(-p4.betaVec());
87 }
88
90
91
93
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
116 LorentzTransform& setBetaVec(const Vector3& vbeta) {
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
142 LorentzTransform& setGammaVec(const Vector3& vgamma) {
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
152 Vector3 gammaVec() const {
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
174 FourMomentum transform(const FourMomentum& v4) const {
175 return multiply(_boostMatrix, v4);
176 }
177
179 FourVector operator () (const FourVector& v4) const {
180 return transform(v4);
181 }
182
184 FourMomentum operator () (const FourMomentum& v4) const {
185 return transform(v4);
186 }
187
188
190
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
212 LorentzTransform inverse() const {
213 LorentzTransform rtn;
214 rtn._boostMatrix = _boostMatrix.inverse();
215 return rtn;
216 }
217
219 LorentzTransform combine(const LorentzTransform& lt) const {
220 LorentzTransform rtn;
221 rtn._boostMatrix = _boostMatrix * lt._boostMatrix;
222 return rtn;
223 }
224
226 LorentzTransform operator*(const LorentzTransform& lt) const {
227 return combine(lt);
228 }
229
231 LorentzTransform preMult(const Matrix3& m3) {
232 _boostMatrix = multiply(_mkMatrix4(m3),_boostMatrix);
233 return *this;
234 }
235
237 LorentzTransform postMult(const Matrix3& m3) {
238 _boostMatrix *= _mkMatrix4(m3);
239 return *this;
240 }
241
243
244
246 Matrix4 toMatrix() const {
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
Rivet::FourMomentum
Specialized version of the FourVector with momentum/energy functionality.
Definition Vector4.hh:316
Rivet::FourVector
Specialisation of VectorN to a general (non-momentum) Lorentz 4-vector.
Definition Vector4.hh:30
Rivet::LorentzTransform
Object implementing Lorentz transform calculations and boosts.
Definition LorentzTrans.hh:21
Rivet::LorentzTransform::mkFrameTransformFromGamma
static LorentzTransform mkFrameTransformFromGamma(const Vector3 &vgamma)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition LorentzTrans.hh:73
Rivet::LorentzTransform::rotate
LorentzTransform rotate(const Vector3 &from, const Vector3 &to) const
Rotate the transformation cf. the difference between vectors from and to.
Definition LorentzTrans.hh:193
Rivet::LorentzTransform::setBetaVec
LorentzTransform & setBetaVec(const Vector3 &vbeta)
Set up an active Lorentz boost from the vector.
Definition LorentzTrans.hh:116
Rivet::LorentzTransform::mkObjTransformFromBeta
static LorentzTransform mkObjTransformFromBeta(const Vector3 &vbeta)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition LorentzTrans.hh:54
Rivet::LorentzTransform::mkFrameTransformFromBeta
static LorentzTransform mkFrameTransformFromBeta(const Vector3 &vbeta)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition LorentzTrans.hh:60
Rivet::LorentzTransform::operator()
FourVector operator()(const FourVector &v4) const
Apply this transformation to the given 4-vector.
Definition LorentzTrans.hh:179
Rivet::LorentzTransform::preMult
LorentzTransform preMult(const Matrix3 &m3)
Pre-multiply m3 by this LT.
Definition LorentzTrans.hh:231
Rivet::LorentzTransform::rotate
LorentzTransform rotate(const Matrix3 &rot) const
Rotate the transformation by the 3D rotation matrix rot.
Definition LorentzTrans.hh:203
Rivet::LorentzTransform::mkObjTransformFromGamma
static LorentzTransform mkObjTransformFromGamma(const Vector3 &vgamma)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition LorentzTrans.hh:66
Rivet::LorentzTransform::beta
double beta() const
Get the factor.
Definition LorentzTrans.hh:136
Rivet::LorentzTransform::betaVec
Vector3 betaVec() const
Get the vector for an active Lorentz boost.
Definition LorentzTrans.hh:126
Rivet::LorentzTransform::operator*
LorentzTransform operator*(const LorentzTransform &lt) const
Operator combination of two LTs.
Definition LorentzTrans.hh:226
Rivet::LorentzTransform::beta2gamma
static double beta2gamma(double beta)
Calculate the factor from .
Definition LorentzTrans.hh:28
Rivet::LorentzTransform::LorentzTransform
LorentzTransform()
Default (identity) constructor.
Definition LorentzTrans.hh:44
Rivet::LorentzTransform::mkFrameTransform
static LorentzTransform mkFrameTransform(const FourMomentum &p4)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition LorentzTrans.hh:85
Rivet::LorentzTransform::postMult
LorentzTransform postMult(const Matrix3 &m3)
Post-multiply m3 by this LT.
Definition LorentzTrans.hh:237
Rivet::LorentzTransform::mkObjTransform
static LorentzTransform mkObjTransform(const FourMomentum &p4)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition LorentzTrans.hh:80
Rivet::LorentzTransform::toMatrix
Matrix4 toMatrix() const
Return the matrix form.
Definition LorentzTrans.hh:246
Rivet::LorentzTransform::inverse
LorentzTransform inverse() const
Calculate the inverse transform.
Definition LorentzTrans.hh:212
Rivet::LorentzTransform::gamma2beta
static double gamma2beta(double gamma)
Calculate from the factor.
Definition LorentzTrans.hh:33
Rivet::LorentzTransform::LorentzTransform
LorentzTransform(const Matrix< 4 > &boostMatrix)
Constructor from a 4x4 matrix.
Definition LorentzTrans.hh:49
Rivet::LorentzTransform::transform
FourMomentum transform(const FourMomentum &v4) const
Apply this transformation to the given 4-mometum.
Definition LorentzTrans.hh:174
Rivet::LorentzTransform::setGammaVec
LorentzTransform & setGammaVec(const Vector3 &vgamma)
Set up an active Lorentz boost from the vector.
Definition LorentzTrans.hh:142
Rivet::LorentzTransform::transform
FourVector transform(const FourVector &v4) const
Apply this transformation to the given 4-vector.
Definition LorentzTrans.hh:169
Rivet::LorentzTransform::rotate
LorentzTransform rotate(const Vector3 &axis, double angle) const
Rotate the transformation by angle radians about axis.
Definition LorentzTrans.hh:198
Rivet::LorentzTransform::gammaVec
Vector3 gammaVec() const
Get the vector for an active Lorentz boost.
Definition LorentzTrans.hh:152
Rivet::LorentzTransform::gamma
double gamma() const
Get the factor.
Definition LorentzTrans.hh:161
Rivet::LorentzTransform::combine
LorentzTransform combine(const LorentzTransform &lt) const
Combine LTs, treating this as the LH matrix.
Definition LorentzTrans.hh:219
Rivet::Matrix3
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition Matrix3.hh:13
Rivet::Matrix
General -dimensional mathematical matrix object.
Definition MatrixN.hh:30
Rivet::Matrix::inverse
Matrix< N > inverse() const
Calculate inverse.
Definition MatrixN.hh:130
Rivet::Vector3
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
Rivet::Vector3::unit
Vector3 unit() const
Synonym for unitVec.
Definition Vector3.hh:124
Rivet::Vector::mod
double mod() const
Calculate the modulus of a vector. .
Definition VectorN.hh:95
Rivet::Vector::mod2
double mod2() const
Calculate the modulus-squared of a vector. .
Definition VectorN.hh:84
Rivet::Vector::isZero
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition VectorN.hh:75
Rivet::FourMomentum::p3
Vector3 p3() const
Get 3-momentum part, .
Definition Vector4.hh:593
Rivet::FourMomentum::betaVec
Vector3 betaVec() const
Definition Vector4.hh:686
Rivet::FourMomentum::E
double E() const
Get energy (time component of momentum).
Definition Vector4.hh:553
Rivet::Kin::p4
FourMomentum p4(const ParticleBase &p)
Unbound function access to momentum.
Definition ParticleBaseUtils.hh:675
Rivet
Definition MC_Cent_pPb.hh:10
Rivet::operator<<
std::ostream & operator<<(std::ostream &os, const AnalysisInfo &ai)
Stream an AnalysisInfo as a text description.
Definition AnalysisInfo.hh:368
Rivet::sign
constexpr std::enable_if< std::is_arithmetic< NUM >::value, int >::type sign(NUM val)
Find the sign of a number.
Definition MathUtils.hh:266
Rivet::toString
std::string toString(const AnalysisInfo &ai)
String representation.
Rivet::sqr
std::enable_if< std::is_arithmetic< NUM >::value, NUM >::type sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.hh:219
Rivet::isZero
std::enable_if< std::is_floating_point< NUM >::value, bool >::type isZero(NUM val, double tolerance=1e-8)
Compare a number to zero.
Definition MathUtils.hh:24
Rivet::angle
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:177