Version: SMASH-3.1
smash::FourVector Class Reference

#include <fourvector.h>

The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.

The overloaded operators are built according to Andrew Koenig recommendations where the compound assignment operators is used as a base for their non-compound counterparts. This means that the operator + is implemented in terms of +=. The operator+ returns a copy of its result. + and friends are non-members, while the compound assignment counterparts, changing the left argument, are a member of the FourVector class.

Definition at line 33 of file fourvector.h.

Inheritance diagram for smash::FourVector:
smash::Test::Momentum smash::Test::Position

Public Types

using iterator = std::array< double, 4 >::iterator
 iterates over the components More...
 
using const_iterator = std::array< double, 4 >::const_iterator
 iterates over the components More...
 

Public Member Functions

 FourVector ()
 default constructor nulls the fourvector components More...
 
 FourVector (double y0, double y1, double y2, double y3)
 copy constructor More...
 
 FourVector (double y0, ThreeVector vec)
 construct from time-like component and a ThreeVector. More...
 
double & operator[] (std::size_t i)
 access the component at offset i. More...
 
double operator[] (std::size_t i) const
 const overload of the [] operator More...
 
double x0 () const
 
void set_x0 (double t)
 
double x1 () const
 
void set_x1 (double x)
 
double x2 () const
 
void set_x2 (double y)
 
double x3 () const
 
void set_x3 (double z)
 
ThreeVector threevec () const
 
void reset ()
 Set all the 4-vector components to 0. More...
 
ThreeVector velocity () const
 Get the velocity (3-vector divided by zero component). More...
 
double Dot (const FourVector &a) const
 calculate the scalar product with another four-vector More...
 
double sqr () const
 calculate the square of the vector (which is a scalar) More...
 
double abs () const
 calculate the lorentz invariant absolute value More...
 
double sqr3 () const
 calculate the square of the spatial three-vector More...
 
double abs3 () const
 calculate the absolute value of the spatial three-vector More...
 
double tau () const
 calculate the proper time from the given four vector More...
 
double eta () const
 calculate the space-time rapidity from the given four vector More...
 
FourVector lorentz_boost (const ThreeVector &v) const
 Returns the FourVector boosted with velocity v. More...
 
bool operator== (const FourVector &a) const
 Check if all four vector components are almost equal (accuracy \(10^{-4}\)). More...
 
bool operator!= (const FourVector &a) const
 checks inequality (logical complement to FourVector::operator==(const FourVector&) const) More...
 
bool operator< (const FourVector &a) const
 checks if \(x^\mu < a^\mu\) for all \(\mu\) (all four vector components are below comparison vector) More...
 
bool operator> (const FourVector &a) const
 checks if \(x^\mu > a^\mu\) for all \(\mu\) (all four vector components are above comparison vector) More...
 
bool operator<= (const FourVector &a) const
 logical complement to FourVector::operator>(const FourVector&) const More...
 
bool operator>= (const FourVector &a) const
 logical complement to FourVector::operator<(const FourVector&) const More...
 
FourVector operator+= (const FourVector &a)
 adds \(a_\mu: x_\mu^\prime = x_\mu + a_\mu\) More...
 
FourVector operator-= (const FourVector &a)
 subtracts \(a_\mu: x_\mu^\prime = x_\mu - a_\mu\) More...
 
FourVector operator*= (const double &a)
 multiplies by \(a: x_\mu^\prime = a \cdot x_\mu\) More...
 
FourVector operator/= (const double &a)
 divides by \(a: x_\mu^\prime = \frac{1}{a} \cdot x_\mu\) More...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 

Private Attributes

std::array< double, 4 > x_
 internal storage of this vector's components More...
 

Member Typedef Documentation

◆ iterator

using smash::FourVector::iterator = std::array<double, 4>::iterator

iterates over the components

Definition at line 281 of file fourvector.h.

◆ const_iterator

using smash::FourVector::const_iterator = std::array<double, 4>::const_iterator

iterates over the components

Definition at line 283 of file fourvector.h.

Constructor & Destructor Documentation

◆ FourVector() [1/3]

smash::FourVector::FourVector ( )
inline

default constructor nulls the fourvector components

Definition at line 36 of file fourvector.h.

36 : x_({0., 0., 0., 0.}) {}
std::array< double, 4 > x_
internal storage of this vector's components
Definition: fourvector.h:308

◆ FourVector() [2/3]

smash::FourVector::FourVector ( double  y0,
double  y1,
double  y2,
double  y3 
)
inline

copy constructor

Parameters
[in]y0The time component to be copied
[in]y1The x component to be copied
[in]y2The y component to be copied
[in]y3the z component to be copied

Definition at line 46 of file fourvector.h.

47  : x_({y0, y1, y2, y3}) {}

◆ FourVector() [3/3]

smash::FourVector::FourVector ( double  y0,
ThreeVector  vec 
)
inline

construct from time-like component and a ThreeVector.

Parameters
[in]y0The time component to be used
[in]vecA ThreeVector (x,y,z) to be used

Definition at line 55 of file fourvector.h.

56  : x_({y0, vec.x1(), vec.x2(), vec.x3()}) {}

Member Function Documentation

◆ operator[]() [1/2]

double& smash::FourVector::operator[] ( std::size_t  i)
inline

access the component at offset i.

This operator results in the same as using the x0()...x3() functions

Parameters
[in]ithe index of the component to access (has to be 0,1,2 or 3)
Returns
the component at index i

Definition at line 65 of file fourvector.h.

65 { return x_[i]; }

◆ operator[]() [2/2]

double smash::FourVector::operator[] ( std::size_t  i) const
inline

const overload of the [] operator

Definition at line 67 of file fourvector.h.

67 { return x_[i]; }

◆ x0()

double smash::FourVector::x0 ( void  ) const
inline
Returns
the time-like component

Definition at line 313 of file fourvector.h.

313 { return x_[0]; }

◆ set_x0()

void smash::FourVector::set_x0 ( double  t)
inline
Parameters
[in]tset time-like component

Definition at line 315 of file fourvector.h.

315 { x_[0] = t; }

◆ x1()

double smash::FourVector::x1 ( ) const
inline
Returns
the first space-like component

Definition at line 317 of file fourvector.h.

317 { return x_[1]; }

◆ set_x1()

void smash::FourVector::set_x1 ( double  x)
inline
Parameters
[in]xset first space-like component

Definition at line 319 of file fourvector.h.

319 { x_[1] = x; }

◆ x2()

double smash::FourVector::x2 ( ) const
inline
Returns
the second space-like component

Definition at line 321 of file fourvector.h.

321 { return x_[2]; }

◆ set_x2()

void smash::FourVector::set_x2 ( double  y)
inline
Parameters
[in]yset second space-like component

Definition at line 323 of file fourvector.h.

323 { x_[2] = y; }

◆ x3()

double smash::FourVector::x3 ( ) const
inline
Returns
the third space-like component

Definition at line 325 of file fourvector.h.

325 { return x_[3]; }

◆ set_x3()

void smash::FourVector::set_x3 ( double  z)
inline
Parameters
[in]zset third space-like component

Definition at line 327 of file fourvector.h.

327 { x_[3] = z; }

◆ threevec()

ThreeVector smash::FourVector::threevec ( ) const
inline
Returns
the space-like three-vector (x,y,z components)

Definition at line 329 of file fourvector.h.

329  {
330  return ThreeVector(x_[1], x_[2], x_[3]);
331 }

◆ reset()

void smash::FourVector::reset ( )
inline

Set all the 4-vector components to 0.

Definition at line 486 of file fourvector.h.

486  {
487  this->x_[0] = 0.;
488  this->x_[1] = 0.;
489  this->x_[2] = 0.;
490  this->x_[3] = 0.;
491 }

◆ velocity()

ThreeVector smash::FourVector::velocity ( ) const
inline

Get the velocity (3-vector divided by zero component).

Should only be used with momentum 4-vectors (not with space-time ones).

Returns
the ThreeVector velocity

Definition at line 333 of file fourvector.h.

333 { return threevec() / x0(); }
ThreeVector threevec() const
Definition: fourvector.h:329
double x0() const
Definition: fourvector.h:313

◆ Dot()

double smash::FourVector::Dot ( const FourVector a) const
inline

calculate the scalar product with another four-vector

Parameters
[in]athe FourVector to dot product with *this
Returns
\(x^\mu a_\mu\)

Definition at line 456 of file fourvector.h.

456  {
457  return x_[0] * a.x_[0] - x_[1] * a.x_[1] - x_[2] * a.x_[2] - x_[3] * a.x_[3];
458 }

◆ sqr()

double smash::FourVector::sqr ( ) const
inline

calculate the square of the vector (which is a scalar)

Returns
\(x^\mu x_\mu\)

Definition at line 460 of file fourvector.h.

460  {
461  return x_[0] * x_[0] - x_[1] * x_[1] - x_[2] * x_[2] - x_[3] * x_[3];
462 }

◆ abs()

double smash::FourVector::abs ( ) const
inline

calculate the lorentz invariant absolute value

Returns
\(\sqrt{x^\mu x_\mu}\)

Note that this will fail for space-like vectors.

Definition at line 464 of file fourvector.h.

464  {
465  if (this->sqr() > -really_small) {
466  return std::sqrt(std::abs(this->sqr()));
467  } else {
468  throw std::runtime_error(
469  "Absolute value of 4-vector could not be "
470  "determined, taking sqrt of negative value.");
471  }
472 }
double sqr() const
calculate the square of the vector (which is a scalar)
Definition: fourvector.h:460
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37

◆ sqr3()

double smash::FourVector::sqr3 ( ) const
inline

calculate the square of the spatial three-vector

Returns
\(\mathbf{x} \cdot \mathbf{x}\)

Definition at line 474 of file fourvector.h.

474 { return this->threevec().sqr(); }
double sqr() const
Definition: threevector.h:266

◆ abs3()

double smash::FourVector::abs3 ( ) const
inline

calculate the absolute value of the spatial three-vector

Returns
\(\sqrt{\mathbf{x} \cdot \mathbf{x}}\)

Definition at line 476 of file fourvector.h.

476 { return this->threevec().abs(); }
double abs() const
Definition: threevector.h:268

◆ tau()

double smash::FourVector::tau ( ) const
inline

calculate the proper time from the given four vector

Returns
\(\sqrt{t^2 - z^2}\)

Definition at line 478 of file fourvector.h.

478  {
479  return std::sqrt(this->x0() * this->x0() - this->x3() * this->x3());
480 }
double x3() const
Definition: fourvector.h:325

◆ eta()

double smash::FourVector::eta ( ) const
inline

calculate the space-time rapidity from the given four vector

Returns
\(atanh(z/t)\)

Definition at line 482 of file fourvector.h.

482  {
483  return std::atanh(this->x3() / this->x0());
484 }

◆ lorentz_boost()

FourVector smash::FourVector::lorentz_boost ( const ThreeVector v) const

Returns the FourVector boosted with velocity v.

The current FourVector is not changed.

Parameters
[in]v( \(\mathbf{v}\) in the explanation below) is a ThreeVector representing the boost velocity

Algorithmic

Notation:

  • \(\mathbf{a}\) is a Three-Vector,
  • \(a^\mu\) is a Four-Vector.

The gamma factor is \(\gamma = 1/\sqrt{1-\mathbf{v}^2}\).

The time-like component of a Lorentz-boosted FourVector \(x^\mu = (x_0, x_1, x_2, x_3) = (x_0, \mathbf{r})\) with velocity \(\mathbf{v}\) is

\begin{eqnarray*} x^\prime_0 = \gamma \cdot (x_0 - \mathbf{r}\cdot\mathbf{v})\;, \end{eqnarray*}

and the space-like components i = 1, 2, 3 are:

\begin{eqnarray*} x^\prime_i &=& x_i + v_i \cdot \Bigl(\frac{\gamma - 1}{\mathbf{v}^2} \cdot \mathbf{r}\cdot\mathbf{v} - \gamma \cdot x_0\Bigr)\\ &=& x_i + v_i \cdot \Bigl(\frac{\gamma^2}{\gamma + 1} \cdot \mathbf{r}\cdot\mathbf{v} - \gamma \cdot x_0\Bigr)\\ &=& x_i - v_i \cdot \frac{\gamma}{\gamma + 1} \cdot \bigl[\gamma\,(x_0 - \mathbf{r}\cdot\mathbf{v})+x_0\bigr]\\ &=& x_i - v_i \cdot \frac{\gamma}{\gamma + 1} \cdot (x^\prime_0 + x^{\vphantom{\prime}}_0) \end{eqnarray*}

Note: This function is equivalent to -velocity Boost from ROOT

Definition at line 17 of file fourvector.cc.

17  {
18  const double velocity_squared = v.sqr();
19 
20  const double gamma =
21  velocity_squared < 1. ? 1. / std::sqrt(1. - velocity_squared) : 0;
22 
23  // this is used four times in the Vector:
24  const double xprime_0 = gamma * (this->x0() - this->threevec() * v);
25  // this is the part of the space-like components that is always the same:
26  const double constantpart = gamma / (gamma + 1) * (xprime_0 + this->x0());
27  return FourVector(xprime_0, this->threevec() - v * constantpart);
28 }
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:36

◆ operator==()

bool smash::FourVector::operator== ( const FourVector a) const

Check if all four vector components are almost equal (accuracy \(10^{-4}\)).

Parameters
[in]aThe FourVector to compare to
Returns
Whether *this and a are almost equal

Definition at line 30 of file fourvector.cc.

30  {
31  return almost_equal_physics(x_[0], a.x_[0]) &&
32  almost_equal_physics(x_[1], a.x_[1]) &&
33  almost_equal_physics(x_[2], a.x_[2]) &&
34  almost_equal_physics(x_[3], a.x_[3]);
35 }
bool almost_equal_physics(const N x, const N y)
Same as smash::almost_equal, but for physical checks like energy-momentum conservation small_number i...
Definition: numerics.h:64

◆ operator!=()

bool smash::FourVector::operator!= ( const FourVector a) const
inline

checks inequality (logical complement to FourVector::operator==(const FourVector&) const)

Parameters
[in]aThe FourVector to compare to
Returns
Whether *this and a are not almost equal

Definition at line 336 of file fourvector.h.

336  {
337  return !(*this == a);
338 }

◆ operator<()

bool smash::FourVector::operator< ( const FourVector a) const
inline

checks if \(x^\mu < a^\mu\) for all \(\mu\) (all four vector components are below comparison vector)

Parameters
[in]aThe FourVector to compare to
Returns
Whether all components of *this are strictly below the corresponding components of a

Definition at line 340 of file fourvector.h.

340  {
341  return (x_[0] < a.x_[0]) && (x_[1] < a.x_[1]) && (x_[2] < a.x_[2]) &&
342  (x_[3] < a.x_[3]);
343 }

◆ operator>()

bool smash::FourVector::operator> ( const FourVector a) const
inline

checks if \(x^\mu > a^\mu\) for all \(\mu\) (all four vector components are above comparison vector)

Parameters
[in]aThe FourVector to compare to
Returns
Whether all components of *this are strictly above the corresponding components of a

Definition at line 346 of file fourvector.h.

346  {
347  return a < *this;
348 }

◆ operator<=()

bool smash::FourVector::operator<= ( const FourVector a) const
inline

logical complement to FourVector::operator>(const FourVector&) const

Parameters
[in]aThe FourVector to compare to
Returns
Whether all components of *this are below or equal to the corresponding components of a

Definition at line 351 of file fourvector.h.

351  {
352  return !(*this > a);
353 }

◆ operator>=()

bool smash::FourVector::operator>= ( const FourVector a) const
inline

logical complement to FourVector::operator<(const FourVector&) const

Parameters
[in]aThe FourVector to compare to
Returns
Whether all components of *this are above or equal to the corresponding components of a

Definition at line 356 of file fourvector.h.

356  {
357  return !(*this < a);
358 }

◆ operator+=()

FourVector smash::FourVector::operator+= ( const FourVector a)
inline

adds \(a_\mu: x_\mu^\prime = x_\mu + a_\mu\)

Parameters
[in]aThe FourVector to add
Returns
FourVector that consists of the added components of *this and a

Definition at line 360 of file fourvector.h.

360  {
361  this->x_[0] += a.x_[0];
362  this->x_[1] += a.x_[1];
363  this->x_[2] += a.x_[2];
364  this->x_[3] += a.x_[3];
365  return *this;
366 }

◆ operator-=()

FourVector smash::FourVector::operator-= ( const FourVector a)
inline

subtracts \(a_\mu: x_\mu^\prime = x_\mu - a_\mu\)

Parameters
[in]aThe FourVector to subtract
Returns
FourVector consisting of the components of a subtracted from *this

Definition at line 381 of file fourvector.h.

381  {
382  this->x_[0] -= a.x_[0];
383  this->x_[1] -= a.x_[1];
384  this->x_[2] -= a.x_[2];
385  this->x_[3] -= a.x_[3];
386  return *this;
387 }

◆ operator*=()

FourVector smash::FourVector::operator*= ( const double &  a)
inline

multiplies by \(a: x_\mu^\prime = a \cdot x_\mu\)

Parameters
[in]aThe value with which to multiply
Returns
FourVector where each component of *this has been multiplied by a

Definition at line 402 of file fourvector.h.

402  {
403  this->x_[0] *= a;
404  this->x_[1] *= a;
405  this->x_[2] *= a;
406  this->x_[3] *= a;
407  return *this;
408 }

◆ operator/=()

FourVector smash::FourVector::operator/= ( const double &  a)
inline

divides by \(a: x_\mu^\prime = \frac{1}{a} \cdot x_\mu\)

Parameters
[in]aThe value by which to divide
Returns
FourVector where each component of *this has been divided by a

Definition at line 434 of file fourvector.h.

434  {
435  const double a_inv = 1.0 / a;
436  this->x_[0] *= a_inv;
437  this->x_[1] *= a_inv;
438  this->x_[2] *= a_inv;
439  this->x_[3] *= a_inv;
440  return *this;
441 }

◆ begin() [1/2]

iterator smash::FourVector::begin ( )
inline
Returns
An iterator starting at the 0th component.

The iterator implements the randomIterator concept. Thus, you can simply write begin() + 1 to get an iterator that points to the 1st component.

Definition at line 291 of file fourvector.h.

291 { return x_.begin(); }

◆ end() [1/2]

iterator smash::FourVector::end ( )
inline
Returns
An iterator pointing after the 4th component.

Definition at line 294 of file fourvector.h.

294 { return x_.end(); }

◆ begin() [2/2]

const_iterator smash::FourVector::begin ( ) const
inline
Returns
A const_iterator pointing at the 0th component.

Definition at line 297 of file fourvector.h.

297 { return x_.begin(); }

◆ end() [2/2]

const_iterator smash::FourVector::end ( ) const
inline
Returns
A const_iterator pointing after the 4th component.

Definition at line 299 of file fourvector.h.

299 { return x_.end(); }

◆ cbegin()

const_iterator smash::FourVector::cbegin ( ) const
inline
See also
begin

Definition at line 302 of file fourvector.h.

302 { return x_.cbegin(); }

◆ cend()

const_iterator smash::FourVector::cend ( ) const
inline
See also
end

Definition at line 304 of file fourvector.h.

304 { return x_.cend(); }

Member Data Documentation

◆ x_

std::array<double, 4> smash::FourVector::x_
private

internal storage of this vector's components

Definition at line 308 of file fourvector.h.


The documentation for this class was generated from the following files: