rivet is hosted by Hepforge, IPPP Durham
Rivet  2.7.0
LorentzTrans.hh
1 #ifndef RIVET_MATH_LORENTZTRANS
2 #define RIVET_MATH_LORENTZTRANS
3 
4 #include "Rivet/Math/MathHeader.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 <iostream>
10 
11 namespace Rivet {
12 
13 
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 
37  // /// Calculate the \f$ \gamma \f$ factor from \f$ \bar{\beta}^2 = 1-\beta^2 \f$
38  // static double betabarsq2gamma(double betabarsq) {
39  // return 1.0 / sqrt(betabarsq);
40  // }
41 
42  // /// Calculate \f$ \bar{\beta}^2 = 1-\beta^2 \f$ from the \f$ \gamma \f$ factor
43  // static double gamma2betabarsq(double gamma) {
44  // return 1.0 / sqr(gamma);
45  // }
46 
48 
49 
51 
52 
55  _boostMatrix = Matrix<4>::mkIdentity();
56  }
57 
58 
61  LorentzTransform rtn;
62  return rtn.setBetaVec(vbeta);
63  }
64 
67  LorentzTransform rtn;
68  return rtn.setBetaVec(-vbeta);
69  }
70 
73  LorentzTransform rtn;
74  if (!vgamma.isZero()) rtn.setGammaVec(vgamma);
75  return rtn;
76  }
77 
80  LorentzTransform rtn;
81  if (!vgamma.isZero()) rtn.setGammaVec(-vgamma);
82  return rtn;
83  }
84 
87  return mkObjTransformFromBeta(p4.betaVec());
88  }
89 
92  return mkObjTransformFromBeta(-p4.betaVec());
93  }
94 
96 
97 
99 
100 
103  assert(vbeta.mod2() < 1);
104  const double beta = vbeta.mod();
105  const double gamma = beta2gamma(beta);
106  _boostMatrix = Matrix<4>::mkIdentity();
107  _boostMatrix.set(0, 0, gamma);
108  _boostMatrix.set(1, 1, gamma);
109  _boostMatrix.set(0, 1, +beta*gamma); //< +ve coeff since active boost
110  _boostMatrix.set(1, 0, +beta*gamma); //< +ve coeff since active boost
111  if (beta > 0) _boostMatrix = rotate(Vector3::mkX(), vbeta)._boostMatrix;
112  return *this;
113  }
114 
116  Vector3 betaVec() const {
117  FourMomentum boost(_boostMatrix.getColumn(0)); //< @todo WRONG?!
118  //cout << "!!!" << boost << endl;
119  if (boost.isZero()) return Vector3();
120  assert(boost.E() > 0);
121  const double beta = boost.p3().mod() / boost.E();
122  return boost.p3().unit() * beta;
123  }
124 
126  double beta() const {
127  return betaVec().mod();
128  }
129 
130 
133  const double gamma = vgamma.mod();
134  const double beta = gamma2beta(gamma);
135  _boostMatrix = Matrix<4>::mkIdentity();
136  _boostMatrix.set(0, 0, gamma);
137  _boostMatrix.set(1, 1, gamma);
138  _boostMatrix.set(0, 1, +beta*gamma); //< +ve coeff since active boost
139  _boostMatrix.set(1, 0, +beta*gamma); //< +ve coeff since active boost
140  if (beta > 0) _boostMatrix = rotate(Vector3::mkX(), vgamma)._boostMatrix;
141  return *this;
142  }
143 
145  Vector3 gammaVec() const {
146  FourMomentum boost(_boostMatrix.getColumn(0)); //< @todo WRONG?!
147  if (boost.isZero()) return Vector3();
148  assert(boost.E() > 0);
149  const double beta = boost.p3().mod() / boost.E();
150  return boost.p3().unit() * beta;
151  }
152 
154  double gamma() const {
155  return beta2gamma(beta());
156  }
157 
159 
160 
162  FourVector transform(const FourVector& v4) const {
163  return multiply(_boostMatrix, v4);
164  }
165 
168  return multiply(_boostMatrix, v4);
169  }
170 
172  FourVector operator () (const FourVector& v4) const {
173  return transform(v4);
174  }
175 
178  return transform(v4);
179  }
180 
181 
183 
184 
186  LorentzTransform rotate(const Vector3& from, const Vector3& to) const {
187  return rotate(Matrix3(from, to));
188  }
189 
191  LorentzTransform rotate(const Vector3& axis, double angle) const {
192  return rotate(Matrix3(axis, angle));
193  }
194 
196  LorentzTransform rotate(const Matrix3& rot) const {
197  LorentzTransform lt = *this;
198  const Matrix4 rot4 = _mkMatrix4(rot);
199  const Matrix4 newlt = rot4 * _boostMatrix * rot4.inverse();
200  lt._boostMatrix = newlt;
201  return lt;
202  }
203 
206  LorentzTransform rtn;
207  rtn._boostMatrix = _boostMatrix.inverse();
208  return rtn;
209  }
210 
213  LorentzTransform rtn;
214  rtn._boostMatrix = _boostMatrix * lt._boostMatrix;
215  return rtn;
216  }
217 
220  return combine(lt);
221  }
222 
225  _boostMatrix = multiply(_mkMatrix4(m3),_boostMatrix);
226  return *this;
227  }
228 
231  _boostMatrix *= _mkMatrix4(m3);
232  return *this;
233  }
234 
236 
237 
239  Matrix4 toMatrix() const {
240  return _boostMatrix;
241  }
242 
243 
244  private:
245 
246  Matrix4 _mkMatrix4(const Matrix3& m3) const {
247  Matrix4 m4 = Matrix4::mkIdentity();
248  for (size_t i = 0; i < 3; ++i) {
249  for (size_t j = 0; j < 3; ++j) {
250  m4.set(i+1, j+1, m3.get(i, j));
251  }
252  }
253  return m4;
254  }
255 
256  Matrix4 _boostMatrix;
257 
258  };
259 
260 
261 
262  inline LorentzTransform inverse(const LorentzTransform& lt) {
263  return lt.inverse();
264  }
265 
266  inline LorentzTransform combine(const LorentzTransform& a, const LorentzTransform& b) {
267  return a.combine(b);
268  }
269 
270  inline FourVector transform(const LorentzTransform& lt, const FourVector& v4) {
271  return lt.transform(v4);
272  }
273 
274 
276 
277 
278  inline string toString(const LorentzTransform& lt) {
279  return toString(lt.toMatrix());
280  }
281 
282  inline ostream& operator<<(std::ostream& out, const LorentzTransform& lt) {
283  out << toString(lt);
284  return out;
285  }
286 
287 
288 }
289 
290 #endif
Definition: ALICE_2010_I880049.cc:13
static LorentzTransform mkFrameTransformFromBeta(const Vector3 &vbeta)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition: LorentzTrans.hh:66
Matrix4 toMatrix() const
Return the matrix form.
Definition: LorentzTrans.hh:239
FourVector operator()(const FourVector &v4) const
Apply this transformation to the given 4-vector.
Definition: LorentzTrans.hh:172
Vector3 betaVec() const
Definition: Vector4.hh:671
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition: VectorN.hh:75
double mod2() const
Calculate the modulus-squared of a vector. .
Definition: VectorN.hh:84
LorentzTransform rotate(const Vector3 &axis, double angle) const
Rotate the transformation by angle radians about axis.
Definition: LorentzTrans.hh:191
LorentzTransform()
Default (identity) constructor.
Definition: LorentzTrans.hh:54
LorentzTransform inverse() const
Calculate the inverse transform.
Definition: LorentzTrans.hh:205
Matrix< N > inverse() const
Calculate inverse.
Definition: MatrixN.hh:134
LorentzTransform & setGammaVec(const Vector3 &vgamma)
Set up an active Lorentz boost from the vector.
Definition: LorentzTrans.hh:132
static double beta2gamma(double beta)
Calculate the factor from .
Definition: LorentzTrans.hh:28
LorentzTransform operator*(const LorentzTransform &lt) const
Operator combination of two LTs.
Definition: LorentzTrans.hh:219
double beta() const
Get the factor.
Definition: LorentzTrans.hh:126
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition: Matrix3.hh:13
FourVector transform(const FourVector &v4) const
Apply this transformation to the given 4-vector.
Definition: LorentzTrans.hh:162
LorentzTransform combine(const LorentzTransform &lt) const
Combine LTs, treating this as the LH matrix.
Definition: LorentzTrans.hh:212
LorentzTransform & setBetaVec(const Vector3 &vbeta)
Set up an active Lorentz boost from the vector.
Definition: LorentzTrans.hh:102
FourMomentum transform(const FourMomentum &v4) const
Apply this transformation to the given 4-mometum.
Definition: LorentzTrans.hh:167
Object implementing Lorentz transform calculations and boosts.
Definition: LorentzTrans.hh:21
double angle(const Vector3 &a, const Vector3 &b)
Angle (in radians) between two 3-vectors.
Definition: Vector3.hh:286
LorentzTransform rotate(const Vector3 &from, const Vector3 &to) const
Rotate the transformation cf. the difference between vectors from and to.
Definition: LorentzTrans.hh:186
General -dimensional mathematical matrix object.
Definition: MatrixN.hh:14
Specialisation of VectorN to a general (non-momentum) Lorentz 4-vector.
Definition: Vector4.hh:22
static LorentzTransform mkObjTransform(const FourMomentum &p4)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition: LorentzTrans.hh:86
static LorentzTransform mkFrameTransformFromGamma(const Vector3 &vgamma)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition: LorentzTrans.hh:79
LorentzTransform preMult(const Matrix3 &m3)
Pre-multiply m3 by this LT.
Definition: LorentzTrans.hh:224
static LorentzTransform mkObjTransformFromBeta(const Vector3 &vbeta)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition: LorentzTrans.hh:60
Vector3 betaVec() const
Get the vector for an active Lorentz boost.
Definition: LorentzTrans.hh:116
double gamma() const
Get the factor.
Definition: LorentzTrans.hh:154
LorentzTransform rotate(const Matrix3 &rot) const
Rotate the transformation by the 3D rotation matrix rot.
Definition: LorentzTrans.hh:196
std::string toString(const AnalysisInfo &ai)
String representation.
Definition: AnalysisInfo.cc:144
Vector3 gammaVec() const
Get the vector for an active Lorentz boost.
Definition: LorentzTrans.hh:145
static double gamma2beta(double gamma)
Calculate from the factor.
Definition: LorentzTrans.hh:33
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26
Specialized version of the FourVector with momentum/energy functionality.
Definition: Vector4.hh:301
LorentzTransform postMult(const Matrix3 &m3)
Post-multiply m3 by this LT.
Definition: LorentzTrans.hh:230
std::enable_if< std::is_arithmetic< NUM >::value, NUM >::type sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.hh:189
double mod() const
Calculate the modulus of a vector. .
Definition: VectorN.hh:95
static LorentzTransform mkObjTransformFromGamma(const Vector3 &vgamma)
Make an LT for an active boost (i.e. object velocity += in boost direction)
Definition: LorentzTrans.hh:72
static LorentzTransform mkFrameTransform(const FourMomentum &p4)
Make an LT for a passive boost (i.e. object velocity -= in boost direction)
Definition: LorentzTrans.hh:91