Version: SMASH-1.5
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 32 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...
 
FourVector LorentzBoost (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 258 of file fourvector.h.

◆ const_iterator

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

iterates over the components

Definition at line 260 of file fourvector.h.

Constructor & Destructor Documentation

◆ FourVector() [1/3]

smash::FourVector::FourVector ( )
inline

default constructor nulls the fourvector components

Definition at line 35 of file fourvector.h.

35 : x_({0., 0., 0., 0.}) {}
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 45 of file fourvector.h.

46  : x_({y0, y1, y2, y3}) {}
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

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

55  : x_({y0, vec.x1(), vec.x2(), vec.x3()}) {}
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 64 of file fourvector.h.

64 { return x_[i]; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

◆ operator[]() [2/2]

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

const overload of the [] operator

Definition at line 66 of file fourvector.h.

66 { return x_[i]; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

◆ x0()

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

Definition at line 290 of file fourvector.h.

290 { return x_[0]; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 292 of file fourvector.h.

292 { x_[0] = t; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
Here is the caller graph for this function:

◆ x1()

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

Definition at line 294 of file fourvector.h.

294 { return x_[1]; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 296 of file fourvector.h.

296 { x_[1] = x; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
Here is the caller graph for this function:

◆ x2()

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

Definition at line 298 of file fourvector.h.

298 { return x_[2]; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 300 of file fourvector.h.

300 { x_[2] = y; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

◆ x3()

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

Definition at line 302 of file fourvector.h.

302 { return x_[3]; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 304 of file fourvector.h.

304 { x_[3] = z; }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 306 of file fourvector.h.

306  {
307  return ThreeVector(x_[1], x_[2], x_[3]);
308 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 310 of file fourvector.h.

310 { return threevec() / x0(); }
double x0() const
Definition: fourvector.h:290
ThreeVector threevec() const
Definition: fourvector.h:306
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 433 of file fourvector.h.

433  {
434  return x_[0] * a.x_[0] - x_[1] * a.x_[1] - x_[2] * a.x_[2] - x_[3] * a.x_[3];
435 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

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

437  {
438  return x_[0] * x_[0] - x_[1] * x_[1] - x_[2] * x_[2] - x_[3] * x_[3];
439 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 441 of file fourvector.h.

441  {
442  if (this->sqr() > -really_small) {
443  return std::sqrt(std::abs(this->sqr()));
444  } else {
445  throw std::runtime_error(
446  "Absolute value of 4-vector could not be "
447  "determined, taking sqrt of negative value.");
448  }
449 }
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:34
double sqr() const
calculate the square of the vector (which is a scalar)
Definition: fourvector.h:437
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 451 of file fourvector.h.

451 { return this->threevec().sqr(); }
ThreeVector threevec() const
Definition: fourvector.h:306
double sqr() const
Definition: threevector.h:249
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 453 of file fourvector.h.

453 { return this->threevec().abs(); }
double abs() const
Definition: threevector.h:251
ThreeVector threevec() const
Definition: fourvector.h:306
Here is the call graph for this function:

◆ LorentzBoost()

FourVector smash::FourVector::LorentzBoost ( 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 }
double x0() const
Definition: fourvector.h:290
ThreeVector threevec() const
Definition: fourvector.h:306
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:35
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 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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
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 313 of file fourvector.h.

313  {
314  return !(*this == a);
315 }

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

317  {
318  return (x_[0] < a.x_[0]) && (x_[1] < a.x_[1]) && (x_[2] < a.x_[2]) &&
319  (x_[3] < a.x_[3]);
320 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

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

323  {
324  return a < *this;
325 }

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

328  {
329  return !(*this > a);
330 }

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

333  {
334  return !(*this < a);
335 }

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

337  {
338  this->x_[0] += a.x_[0];
339  this->x_[1] += a.x_[1];
340  this->x_[2] += a.x_[2];
341  this->x_[3] += a.x_[3];
342  return *this;
343 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

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

358  {
359  this->x_[0] -= a.x_[0];
360  this->x_[1] -= a.x_[1];
361  this->x_[2] -= a.x_[2];
362  this->x_[3] -= a.x_[3];
363  return *this;
364 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

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

379  {
380  this->x_[0] *= a;
381  this->x_[1] *= a;
382  this->x_[2] *= a;
383  this->x_[3] *= a;
384  return *this;
385 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

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

411  {
412  const double a_inv = 1.0 / a;
413  this->x_[0] *= a_inv;
414  this->x_[1] *= a_inv;
415  this->x_[2] *= a_inv;
416  this->x_[3] *= a_inv;
417  return *this;
418 }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

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

268 { return x_.begin(); }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 271 of file fourvector.h.

271 { return x_.end(); }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
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 274 of file fourvector.h.

274 { return x_.begin(); }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

◆ end() [2/2]

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

Definition at line 276 of file fourvector.h.

276 { return x_.end(); }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

◆ cbegin()

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

Definition at line 279 of file fourvector.h.

279 { return x_.cbegin(); }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285
Here is the caller graph for this function:

◆ cend()

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

Definition at line 281 of file fourvector.h.

281 { return x_.cend(); }
std::array< double, 4 > x_
internal storage of this vector&#39;s components
Definition: fourvector.h:285

Member Data Documentation

◆ x_

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

internal storage of this vector's components

Definition at line 285 of file fourvector.h.


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