HepMC3 event record library: FourVector Class Reference

HepMC3 event record library

Public Member Functions | Static Public Member Functions | Private Attributes
FourVector Class Reference

## Detailed Description

Generic 4-vector.

Interpretation of its content depends on accessors used: it's much simpler to do this than to distinguish between space and momentum vectors via the type system (especially given the need for backward compatibility with HepMC2). Be sensible and don't call energy functions on spatial vectors! To avoid duplication, most definitions are only implemented on the spatial function names, with the energy-momentum functions as aliases.

This is not intended to be a fully featured 4-vector, but does contain the majority of common non-boosting functionality, as well as a few support operations on 4-vectors.

The implementations in this class are fully inlined.

Examples
  basic_tree.cc.

Definition at line 36 of file FourVector.h.

`#include <FourVector.h>`

## Public Member Functions
| FourVector ()
| Default constructor.
| FourVector (double xx, double yy, double zz, double ee)
| Sets all FourVector fields.
| FourVector (const FourVector &)=default
| Copy constructor.
| FourVector (FourVector &&)=default
| Move constructor.
FourVector & | operator= (const FourVector &)=default
| =
FourVector & | operator= (FourVector &&)=default
| =
Component accessors
void | set (double x1, double x2, double x3, double x4)
| Set all FourVector fields, in order x,y,z,t.
void | set_component (const int i, const double x)
| set component of position/displacement
double | get_component (const int i) const
| get component of position/displacement
double | x () const
| x-component of position/displacement
void | set_x (double xx)
| Set x-component of position/displacement.
void | setX (double xx)
double | y () const
| y-component of position/displacement
void | set_y (double yy)
| Set y-component of position/displacement.
void | setY (double yy)
double | z () const
| z-component of position/displacement
void | set_z (double zz)
| Set z-component of position/displacement.
void | setZ (double zz)
double | t () const
| Time component of position/displacement.
void | set_t (double tt)
| Set time component of position/displacement.
void | setT (double tt)
double | px () const
| x-component of momentum
void | set_px (double pxx)
| Set x-component of momentum.
void | setPx (double pxx)
double | py () const
| y-component of momentum
void | set_py (double pyy)
| Set y-component of momentum.
void | setPy (double pyy)
double | pz () const
| z-component of momentum
void | set_pz (double pzz)
| Set z-component of momentum.
void | setPz (double pzz)
double | e () const
| Energy component of momentum.
void | set_e (double ee)
| Set energy component of momentum.
void | setE (double ee)
Computed properties
double | length2 () const
| Squared magnitude of (x, y, z) 3-vector.
double | length () const
| Magnitude of spatial (x, y, z) 3-vector.
double | rho () const
| Magnitude of spatial (x, y, z) 3-vector, for HepMC2 compatibility.
double | perp2 () const
| Squared magnitude of (x, y) vector.
double | perp () const
| Magnitude of (x, y) vector.
double | interval () const
| Spacetime invariant interval s^2 = t^2 - x^2 - y^2 - z^2.
double | p3mod2 () const
| Squared magnitude of p3 = (px, py, pz) vector.
double | p3mod () const
| Magnitude of p3 = (px, py, pz) vector.
double | pt2 () const
| Squared transverse momentum px^2 + py^2.
double | pt () const
| Transverse momentum.
double | m2 () const
| Squared invariant mass m^2 = E^2 - px^2 - py^2 - pz^2.
double | m () const
| Invariant mass. Returns -sqrt(-m) if e^2 - P^2 is negative.
double | phi () const
| Azimuthal angle.
double | theta () const
| Polar angle w.r.t. z direction.
double | eta () const
| Pseudorapidity.
double | rap () const
| Rapidity.
double | abs_eta () const
| Absolute pseudorapidity.
double | abs_rap () const
| Absolute rapidity.
double | pseudoRapidity () const
Comparisons to another FourVector
bool | is_zero () const
| Check if the length of this vertex is zero.
double | delta_phi (const FourVector &v) const
| Signed azimuthal angle separation in [-pi, pi].
double | delta_eta (const FourVector &v) const
| Pseudorapidity separation.
double | delta_rap (const FourVector &v) const
| Rapidity separation.
double | delta_r2_eta (const FourVector &v) const
| R_eta^2-distance separation dR^2 = dphi^2 + deta^2.
double | delta_r_eta (const FourVector &v) const
| R_eta-distance separation dR = sqrt(dphi^2 + deta^2).
double | delta_r2_rap (const FourVector &v) const
| R_rap^2-distance separation dR^2 = dphi^2 + drap^2.
double | delta_r_rap (const FourVector &v) const
| R-rap-distance separation dR = sqrt(dphi^2 + drap^2).
Operators
bool | operator== (const FourVector &rhs) const
| Equality.
bool | operator!= (const FourVector &rhs) const
| Inequality.
FourVector | operator+ (const FourVector &rhs) const
| Arithmetic operator +.
FourVector | operator- (const FourVector &rhs) const
| Arithmetic operator -.
FourVector | operator* (const double rhs) const
| Arithmetic operator * by scalar.
FourVector | operator/ (const double rhs) const
| Arithmetic operator / by scalar.
void | operator+= (const FourVector &rhs)
| Arithmetic operator +=.
void | operator-= (const FourVector &rhs)
| Arithmetic operator -=.
void | operator*= (const double rhs)
| Arithmetic operator *= by scalar.
void | operator/= (const double rhs)
| Arithmetic operator /= by scalar.

## Static Public Member Functions
static const FourVector & | ZERO_VECTOR ()
| Static null FourVector = (0,0,0,0).

## Private Attributes
double | m_v1
| px or x. Interpretation depends on accessors used
double | m_v2
| py or y. Interpretation depends on accessors used
double | m_v3
| pz or z. Interpretation depends on accessors used
double | m_v4
| e or t. Interpretation depends on accessors used

## Constructor & Destructor Documentation

## ◆ FourVector() [1/4]

FourVector | ( |  | ) |
| inline

Default constructor.

Definition at line 40 of file FourVector.h.

References m_v1, m_v2, m_v3, and m_v4.

## ◆ FourVector() [2/4]

FourVector | ( | double | xx,
|  | double | yy,
|  | double | zz,
|  | double | ee )
| inline

Sets all FourVector fields.

Definition at line 43 of file FourVector.h.

References m_v1, m_v2, m_v3, and m_v4.

## ◆ FourVector() [3/4]

FourVector | ( | const FourVector & |  | ) |
| default

Copy constructor.

References FourVector().

## ◆ FourVector() [4/4]

FourVector | ( | FourVector && |  | ) |
| default

Move constructor.

References FourVector().

## Member Function Documentation

## ◆ abs_eta()

double abs_eta | ( |  | ) | const
| inline

Absolute pseudorapidity.

Definition at line 190 of file FourVector.h.

References eta().

## ◆ abs_rap()

double abs_rap | ( |  | ) | const
| inline

Absolute rapidity.

Definition at line 192 of file FourVector.h.

References rap().

## ◆ delta_eta()

double delta_eta | ( | const FourVector & | v | ) | const
| inline

Pseudorapidity separation.

Definition at line 218 of file FourVector.h.

References eta(), and FourVector().

## ◆ delta_phi()

double delta_phi | ( | const FourVector & | v | ) | const
| inline

Signed azimuthal angle separation in [-pi, pi].

Definition at line 209 of file FourVector.h.

References FourVector(), M_PI, and phi().

## ◆ delta_r2_eta()

double delta_r2_eta | ( | const FourVector & | v | ) | const
| inline

R_eta^2-distance separation dR^2 = dphi^2 + deta^2.

Definition at line 224 of file FourVector.h.

References delta_eta(), delta_phi(), and FourVector().

## ◆ delta_r2_rap()

double delta_r2_rap | ( | const FourVector & | v | ) | const
| inline

R_rap^2-distance separation dR^2 = dphi^2 + drap^2.

Definition at line 234 of file FourVector.h.

References delta_phi(), delta_rap(), and FourVector().

## ◆ delta_r_eta()

double delta_r_eta | ( | const FourVector & | v | ) | const
| inline

R_eta-distance separation dR = sqrt(dphi^2 + deta^2).

Definition at line 229 of file FourVector.h.

References delta_r2_eta(), and FourVector().

## ◆ delta_r_rap()

double delta_r_rap | ( | const FourVector & | v | ) | const
| inline

R-rap-distance separation dR = sqrt(dphi^2 + drap^2).

Definition at line 239 of file FourVector.h.

References delta_r2_rap(), and FourVector().

## ◆ delta_rap()

double delta_rap | ( | const FourVector & | v | ) | const
| inline

Rapidity separation.

Definition at line 221 of file FourVector.h.

References FourVector(), and rap().

## ◆ e()

double e | ( |  | ) | const
| inline

Energy component of momentum.

Definition at line 135 of file FourVector.h.

References t().

## ◆ eta()

double eta | ( |  | ) | const
| inline

Pseudorapidity.

Definition at line 178 of file FourVector.h.

References p3mod(), and pz().

## ◆ get_component()

double get_component | ( | const int | i | ) | const
| inline

get component of position/displacement

Definition at line 74 of file FourVector.h.

References m_v1, m_v2, m_v3, and m_v4.

## ◆ interval()

double interval | ( |  | ) | const
| inline

Spacetime invariant interval s^2 = t^2 - x^2 - y^2 - z^2.

Definition at line 158 of file FourVector.h.

References length2(), and t().

## ◆ is_zero()

bool is_zero | ( |  | ) | const
| inline

Check if the length of this vertex is zero.

Definition at line 206 of file FourVector.h.

References t(), x(), y(), and z().

## ◆ length()

double length | ( |  | ) | const
| inline

Magnitude of spatial (x, y, z) 3-vector.

Definition at line 150 of file FourVector.h.

References length2().

## ◆ length2()

double length2 | ( |  | ) | const
| inline

Squared magnitude of (x, y, z) 3-vector.

Definition at line 148 of file FourVector.h.

References x(), y(), and z().

## ◆ m()

double m | ( |  | ) | const
| inline

Invariant mass. Returns -sqrt(-m) if e^2 - P^2 is negative.

Definition at line 171 of file FourVector.h.

References m2().

## ◆ m2()

double m2 | ( |  | ) | const
| inline

Squared invariant mass m^2 = E^2 - px^2 - py^2 - pz^2.

Definition at line 169 of file FourVector.h.

References interval().

## ◆ operator!=()

bool operator!= | ( | const FourVector & | rhs | ) | const
| inline

Inequality.

Definition at line 254 of file FourVector.h.

References FourVector().

## ◆ operator*()

FourVector operator* | ( | const double | rhs | ) | const
| inline

Arithmetic operator * by scalar.

Definition at line 265 of file FourVector.h.

References FourVector(), t(), x(), y(), and z().

## ◆ operator*=()

void operator*= | ( | const double | rhs | ) |
| inline

Arithmetic operator *= by scalar.

Definition at line 288 of file FourVector.h.

References setT(), setX(), setY(), setZ(), t(), x(), y(), and z().

## ◆ operator+()

FourVector operator+ | ( | const FourVector & | rhs | ) | const
| inline

Arithmetic operator +.

Definition at line 257 of file FourVector.h.

References FourVector(), t(), x(), y(), and z().

## ◆ operator+=()

void operator+= | ( | const FourVector & | rhs | ) |
| inline

Arithmetic operator +=.

Definition at line 274 of file FourVector.h.

References FourVector(), setT(), setX(), setY(), setZ(), t(), x(), y(), and z().

## ◆ operator-()

FourVector operator- | ( | const FourVector & | rhs | ) | const
| inline

Arithmetic operator -.

Definition at line 261 of file FourVector.h.

References FourVector(), t(), x(), y(), and z().

## ◆ operator-=()

void operator-= | ( | const FourVector & | rhs | ) |
| inline

Arithmetic operator -=.

Definition at line 281 of file FourVector.h.

References FourVector(), setT(), setX(), setY(), setZ(), t(), x(), y(), and z().

## ◆ operator/()

FourVector operator/ | ( | const double | rhs | ) | const
| inline

Arithmetic operator / by scalar.

Definition at line 269 of file FourVector.h.

References FourVector(), t(), x(), y(), and z().

## ◆ operator/=()

void operator/= | ( | const double | rhs | ) |
| inline

Arithmetic operator /= by scalar.

Definition at line 295 of file FourVector.h.

References setT(), setX(), setY(), setZ(), t(), x(), y(), and z().

## ◆ operator=() [1/2]

FourVector & operator= | ( | const FourVector & |  | ) |
| default

=

References FourVector().

## ◆ operator=() [2/2]

FourVector & operator= | ( | FourVector && |  | ) |
| default

=

References FourVector().

## ◆ operator==()

bool operator== | ( | const FourVector & | rhs | ) | const
| inline

Equality.

Definition at line 250 of file FourVector.h.

References FourVector(), t(), x(), y(), and z().

## ◆ p3mod()

double p3mod | ( |  | ) | const
| inline

Magnitude of p3 = (px, py, pz) vector.

Definition at line 163 of file FourVector.h.

References length().

## ◆ p3mod2()

double p3mod2 | ( |  | ) | const
| inline

Squared magnitude of p3 = (px, py, pz) vector.

Definition at line 161 of file FourVector.h.

References length2().

## ◆ perp()

double perp | ( |  | ) | const
| inline

Magnitude of (x, y) vector.

Definition at line 156 of file FourVector.h.

References perp2().

## ◆ perp2()

double perp2 | ( |  | ) | const
| inline

Squared magnitude of (x, y) vector.

Definition at line 154 of file FourVector.h.

References x(), and y().

## ◆ phi()

double phi | ( |  | ) | const
| inline

Azimuthal angle.

Definition at line 174 of file FourVector.h.

References x(), and y().

## ◆ pseudoRapidity()

double pseudoRapidity | ( |  | ) | const
| inline

Same as eta()

Deprecated
  Prefer 'only one way to do it', and we don't have equivalent long names for e.g. pid, phi or eta

Definition at line 197 of file FourVector.h.

References eta().

## ◆ pt()

double pt | ( |  | ) | const
| inline

Transverse momentum.

Definition at line 167 of file FourVector.h.

References perp().

## ◆ pt2()

double pt2 | ( |  | ) | const
| inline

Squared transverse momentum px^2 + py^2.

Definition at line 165 of file FourVector.h.

References perp2().

## ◆ px()

double px | ( |  | ) | const
| inline

x-component of momentum

Definition at line 114 of file FourVector.h.

References x().

## ◆ py()

double py | ( |  | ) | const
| inline

y-component of momentum

Definition at line 121 of file FourVector.h.

References y().

## ◆ pz()

double pz | ( |  | ) | const
| inline

z-component of momentum

Definition at line 128 of file FourVector.h.

References z().

## ◆ rap()

double rap | ( |  | ) | const
| inline

Rapidity.

Definition at line 184 of file FourVector.h.

References e(), and pz().

## ◆ rho()

double rho | ( |  | ) | const
| inline

Magnitude of spatial (x, y, z) 3-vector, for HepMC2 compatibility.

Definition at line 152 of file FourVector.h.

References length().

## ◆ set()

void set | ( | double | x1,
|  | double | x2,
|  | double | x3,
|  | double | x4 )
| inline

Set all FourVector fields, in order x,y,z,t.

Definition at line 58 of file FourVector.h.

References m_v1, m_v2, m_v3, and m_v4.

## ◆ set_component()

void set_component | ( | const int | i,
|  | const double | x )
| inline

set component of position/displacement

Definition at line 66 of file FourVector.h.

References m_v1, m_v2, m_v3, m_v4, and x().

## ◆ set_e()

void set_e | ( | double | ee | ) |
| inline

Set energy component of momentum.

Definition at line 137 of file FourVector.h.

References set_t().

## ◆ set_px()

void set_px | ( | double | pxx | ) |
| inline

Set x-component of momentum.

Definition at line 116 of file FourVector.h.

References set_x().

## ◆ set_py()

void set_py | ( | double | pyy | ) |
| inline

Set y-component of momentum.

Definition at line 123 of file FourVector.h.

References set_y().

## ◆ set_pz()

void set_pz | ( | double | pzz | ) |
| inline

Set z-component of momentum.

Definition at line 130 of file FourVector.h.

References set_z().

## ◆ set_t()

void set_t | ( | double | tt | ) |
| inline

Set time component of position/displacement.

Definition at line 108 of file FourVector.h.

References m_v4.

## ◆ set_x()

void set_x | ( | double | xx | ) |
| inline

Set x-component of position/displacement.

Definition at line 87 of file FourVector.h.

References m_v1.

## ◆ set_y()

void set_y | ( | double | yy | ) |
| inline

Set y-component of position/displacement.

Definition at line 94 of file FourVector.h.

References m_v2.

## ◆ set_z()

void set_z | ( | double | zz | ) |
| inline

Set z-component of position/displacement.

Definition at line 101 of file FourVector.h.

References m_v3.

## ◆ setE()

void setE | ( | double | ee | ) |
| inline

Deprecated
  Prefer the HepMC-style set_y() function

Definition at line 139 of file FourVector.h.

References set_e().

## ◆ setPx()

void setPx | ( | double | pxx | ) |
| inline

Deprecated
  Prefer the HepMC-style set_px() function

Definition at line 118 of file FourVector.h.

References set_px().

## ◆ setPy()

void setPy | ( | double | pyy | ) |
| inline

Deprecated
  Prefer the HepMC-style set_py() function

Definition at line 125 of file FourVector.h.

References set_py().

## ◆ setPz()

void setPz | ( | double | pzz | ) |
| inline

Deprecated
  Prefer the HepMC-style set_pz() function

Definition at line 132 of file FourVector.h.

References set_pz().

## ◆ setT()

void setT | ( | double | tt | ) |
| inline

Deprecated
  Prefer the HepMC-style set_t() function

Definition at line 110 of file FourVector.h.

References set_t().

## ◆ setX()

void setX | ( | double | xx | ) |
| inline

Deprecated
  Prefer the HepMC-style set_x() function

Definition at line 89 of file FourVector.h.

References set_x().

## ◆ setY()

void setY | ( | double | yy | ) |
| inline

Deprecated
  Prefer the HepMC-style set_y() function

Definition at line 96 of file FourVector.h.

References set_y().

## ◆ setZ()

void setZ | ( | double | zz | ) |
| inline

Deprecated
  Prefer the HepMC-style set_z() function

Definition at line 103 of file FourVector.h.

References set_z().

## ◆ t()

double t | ( |  | ) | const
| inline

Time component of position/displacement.

Definition at line 106 of file FourVector.h.

References m_v4.

## ◆ theta()

double theta | ( |  | ) | const
| inline

Polar angle w.r.t. z direction.

Definition at line 176 of file FourVector.h.

References perp(), and z().

## ◆ x()

double x | ( |  | ) | const
| inline

x-component of position/displacement

Definition at line 85 of file FourVector.h.

References m_v1.

## ◆ y()

double y | ( |  | ) | const
| inline

y-component of position/displacement

Definition at line 92 of file FourVector.h.

References m_v2.

## ◆ z()

double z | ( |  | ) | const
| inline

z-component of position/displacement

Definition at line 99 of file FourVector.h.

References m_v3.

## ◆ ZERO_VECTOR()

const FourVector & ZERO_VECTOR | ( |  | ) |
| inlinestatic

Static null FourVector = (0,0,0,0).

Definition at line 306 of file FourVector.h.

References FourVector().

## Field Documentation

## ◆ m_v1

double m_v1
| private

px or x. Interpretation depends on accessors used

Definition at line 314 of file FourVector.h.

## ◆ m_v2

double m_v2
| private

py or y. Interpretation depends on accessors used

Definition at line 315 of file FourVector.h.

## ◆ m_v3

double m_v3
| private

pz or z. Interpretation depends on accessors used

Definition at line 316 of file FourVector.h.

## ◆ m_v4

double m_v4
| private

e or t. Interpretation depends on accessors used

Definition at line 317 of file FourVector.h.

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

- FourVector.h