Version: SMASH-2.0
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:
[legend]
Collaboration diagram for smash::FourVector:
[legend]

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
 
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 271 of file fourvector.h.

◆ const_iterator

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

iterates over the components

Definition at line 273 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.}) {}
Here is the caller graph for this function:

◆ 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()}) {}
Here is the call graph for this function:

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 303 of file fourvector.h.

303 { return x_[0]; }
Here is the caller graph for this function:

◆ set_x0()

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

Definition at line 305 of file fourvector.h.

305 { x_[0] = t; }
Here is the caller graph for this function:

◆ x1()

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

Definition at line 307 of file fourvector.h.

307 { return x_[1]; }
Here is the caller graph for this function:

◆ set_x1()

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

Definition at line 309 of file fourvector.h.

309 { x_[1] = x; }
Here is the caller graph for this function:

◆ x2()

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

Definition at line 311 of file fourvector.h.

311 { return x_[2]; }
Here is the caller graph for this function:

◆ set_x2()

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

Definition at line 313 of file fourvector.h.

313 { x_[2] = y; }

◆ x3()

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

Definition at line 315 of file fourvector.h.

315 { return x_[3]; }
Here is the caller graph for this function:

◆ set_x3()

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

Definition at line 317 of file fourvector.h.

317 { x_[3] = z; }
Here is the caller graph for this function:

◆ threevec()

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

Definition at line 319 of file fourvector.h.

319  {
320  return ThreeVector(x_[1], x_[2], x_[3]);
321 }
Here is the caller graph for this function:

◆ 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 323 of file fourvector.h.

323 { return threevec() / x0(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 446 of file fourvector.h.

446  {
447  return x_[0] * a.x_[0] - x_[1] * a.x_[1] - x_[2] * a.x_[2] - x_[3] * a.x_[3];
448 }
Here is the caller graph for this function:

◆ 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 450 of file fourvector.h.

450  {
451  return x_[0] * x_[0] - x_[1] * x_[1] - x_[2] * x_[2] - x_[3] * x_[3];
452 }
Here is the caller graph for this function:

◆ 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 454 of file fourvector.h.

454  {
455  if (this->sqr() > -really_small) {
456  return std::sqrt(std::abs(this->sqr()));
457  } else {
458  throw std::runtime_error(
459  "Absolute value of 4-vector could not be "
460  "determined, taking sqrt of negative value.");
461  }
462 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqr3()

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

calculate the square of the spatial three-vector

Returns
\(\vec x \cdot \vec x\)

Definition at line 464 of file fourvector.h.

464 { return this->threevec().sqr(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ abs3()

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

calculate the absolute value of the spatial three-vector

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

Definition at line 466 of file fourvector.h.

466 { return this->threevec().abs(); }
Here is the call graph for this function:

◆ 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 468 of file fourvector.h.

468  {
469  return std::sqrt(this->x0() * this->x0() - this->x3() * this->x3());
470 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eta()

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

calculate the space-time rapidity from the given four vector

Returns
\(atanh(z/t)\)

Definition at line 472 of file fourvector.h.

472  {
473  return std::atanh(this->x3() / this->x0());
474 }
Here is the call graph for this function:

◆ 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
v( \(\vec{v}\)) is a ThreeVector representing the boost velocity

Algorithmic

(Notation: \(\vec{a}\) is a Three-Vector, \(a^\mu\) is a Four-Vector.)

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

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

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

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

\begin{eqnarray*} x^\prime_i &=& x_i + v_i \cdot (\frac{\gamma - 1}{\vec{v}^2} \cdot \vec{r}\cdot\vec{v} - \gamma \cdot x_0)\\ &=& x_i + v_i \cdot (\frac{\gamma^2}{\gamma + 1} \cdot \vec{r}\cdot\vec{v} - \gamma \cdot x_0)\\ &=& x_i - v_i \cdot \frac{\gamma}{\gamma + 1} \cdot (\gamma(x_0 - \vec{r}\cdot\vec{v}) + x_0 )\\ &=& x_i - v_i \cdot \frac{\gamma}{\gamma + 1} \cdot (x^\prime_0 + x_0) \end{eqnarray*}

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

Definition at line 16 of file fourvector.cc.

16  {
17  const double velocity_squared = v.sqr();
18 
19  const double gamma =
20  velocity_squared < 1. ? 1. / std::sqrt(1. - velocity_squared) : 0;
21 
22  // this is used four times in the Vector:
23  const double xprime_0 = gamma * (this->x0() - this->threevec() * v);
24  // this is the part of the space-like components that is always the same:
25  const double constantpart = gamma / (gamma + 1) * (xprime_0 + this->x0());
26  return FourVector(xprime_0, this->threevec() - v * constantpart);
27 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 29 of file fourvector.cc.

29  {
30  return almost_equal_physics(x_[0], a.x_[0]) &&
31  almost_equal_physics(x_[1], a.x_[1]) &&
32  almost_equal_physics(x_[2], a.x_[2]) &&
33  almost_equal_physics(x_[3], a.x_[3]);
34 }
Here is the call graph for this function:

◆ 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 326 of file fourvector.h.

326  {
327  return !(*this == a);
328 }

◆ 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 330 of file fourvector.h.

330  {
331  return (x_[0] < a.x_[0]) && (x_[1] < a.x_[1]) && (x_[2] < a.x_[2]) &&
332  (x_[3] < a.x_[3]);
333 }

◆ 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 336 of file fourvector.h.

336  {
337  return a < *this;
338 }

◆ 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 341 of file fourvector.h.

341  {
342  return !(*this > a);
343 }

◆ 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 346 of file fourvector.h.

346  {
347  return !(*this < a);
348 }

◆ 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 350 of file fourvector.h.

350  {
351  this->x_[0] += a.x_[0];
352  this->x_[1] += a.x_[1];
353  this->x_[2] += a.x_[2];
354  this->x_[3] += a.x_[3];
355  return *this;
356 }

◆ 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 371 of file fourvector.h.

371  {
372  this->x_[0] -= a.x_[0];
373  this->x_[1] -= a.x_[1];
374  this->x_[2] -= a.x_[2];
375  this->x_[3] -= a.x_[3];
376  return *this;
377 }

◆ 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 392 of file fourvector.h.

392  {
393  this->x_[0] *= a;
394  this->x_[1] *= a;
395  this->x_[2] *= a;
396  this->x_[3] *= a;
397  return *this;
398 }

◆ 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 424 of file fourvector.h.

424  {
425  const double a_inv = 1.0 / a;
426  this->x_[0] *= a_inv;
427  this->x_[1] *= a_inv;
428  this->x_[2] *= a_inv;
429  this->x_[3] *= a_inv;
430  return *this;
431 }

◆ 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 281 of file fourvector.h.

281 { return x_.begin(); }
Here is the caller graph for this function:

◆ end() [1/2]

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

Definition at line 284 of file fourvector.h.

284 { return x_.end(); }
Here is the caller graph for this function:

◆ begin() [2/2]

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

Definition at line 287 of file fourvector.h.

287 { 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 289 of file fourvector.h.

289 { return x_.end(); }

◆ cbegin()

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

Definition at line 292 of file fourvector.h.

292 { return x_.cbegin(); }
Here is the caller graph for this function:

◆ cend()

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

Definition at line 294 of file fourvector.h.

294 { 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 298 of file fourvector.h.


The documentation for this class was generated from the following files:
smash::FourVector::x3
double x3() const
Definition: fourvector.h:315
smash::FourVector::sqr
double sqr() const
calculate the square of the vector (which is a scalar)
Definition: fourvector.h:450
smash::ThreeVector::sqr
double sqr() const
Definition: threevector.h:259
smash::FourVector::x_
std::array< double, 4 > x_
internal storage of this vector's components
Definition: fourvector.h:298
smash::really_small
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
smash::FourVector::x0
double x0() const
Definition: fourvector.h:303
smash::almost_equal_physics
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:62
smash::ThreeVector::abs
double abs() const
Definition: threevector.h:261
smash::FourVector::threevec
ThreeVector threevec() const
Definition: fourvector.h:319
smash::FourVector::FourVector
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:36