24 FourMomentum::FourMomentum() : _vec{{0., 0., 0., 0.}} {
33 const double py,
const double pz) : _vec{{
E,
px,
py, pz}} {
56 return FourMomentum{sqrt(px * px + py * py + pz * pz + mass * mass),
px,
py, pz};
60 return FourMomentum{sqrt(mass * mass + pow(pt * cosh(eta), 2.)), pt * cos(phi), pt * sin(phi), pt * sinh(eta)};
65 throw RangeError(
"Invalid mass and energy relation");
67 double pt = sqrt((E * E - mass * mass) / (1 + pow(sinh(eta), 2.)));
68 return FourMomentum{
E, pt * cos(phi), pt * sin(phi), pt * sinh(eta)};
73 FourMomentum FourMomentum::fromRoot(
const TLorentzVector& v) {
99 return (
E() *
E() -
p2());
104 throw Error(
"Rosebud! Negative mass^2: " + to_string(
mass2()));
106 return sqrt(fabs(
mass2()));
119 return sqrt(
px() *
px() +
py() *
py());
123 return acosh(
E() /
mass());
127 return atan2(
pt(),
pz());
131 return -log(tan(
theta() / 2.));
135 return atan2(
py(),
px());
139 return array<double, 3>{{
px(),
py(),
pz()}};
144 return E() * v.E() -
px() * v.px() -
py() * v.py() -
pz() * v.pz();
147 double operator*(
const FourMomentum& v,
const FourMomentum& w) {
151 double dot(
const FourMomentum& v,
const FourMomentum& w) {
156 for (
size_t i = 0; i <= 3; ++i) {
157 _vec[i] += v._vec[i];
163 for (
size_t i = 0; i <= 3; ++i) {
164 _vec[i] -= v._vec[i];
175 for (
size_t i = 0; i <= 3; ++i) {
182 for (
size_t i = 0; i <= 3; ++i) {
197 throw Error(
"Rosebud! Zero mass: " + to_string(m));
205 throw Error(
"Rosebud! Zero energy: " + to_string(energy));
213 throw Error(
"Rosebud! Zero energy: " + to_string(energy));
215 return {{
_vec[1] / energy,
_vec[2] / energy,
_vec[3] / energy}};
220 const double gamma = 1.0 / sqrt(1.0 - vSq);
222 const double gamma2 = vSq > 0 ? (gamma - 1.0)/vSq : 0.0;
224 _vec[1] =(
px() + (gamma2*vp - gamma*
E())*v[0]);
225 _vec[2] =(
py() + (gamma2*vp - gamma*
E())*v[1]);
226 _vec[3] =(
pz() + (gamma2*vp - gamma*
E())*v[2]);
227 _vec[0] =gamma*(
E()-vp);
241 boostBy(v.PFlip().boostVector());
246 double angle(
const FourMomentum& v,
const FourMomentum& w) {
247 return acos(
costheta(v.pVec(), w.pVec()));
250 double deltaPhi(
const FourMomentum& v,
const FourMomentum& w) {
251 return abs(v.phi() - w.phi());
254 double deltaEta(
const FourMomentum& v,
const FourMomentum& w) {
255 return abs(v.eta() - w.eta());
258 double deltaR(
const FourMomentum& v,
const FourMomentum& w) {
263 double epsilon(
const FourMomentum& a,
const FourMomentum& b,
const FourMomentum& c,
const FourMomentum& d) {
264 array<double, 4> p = {{a.E(), a.px(), a.py(), a.pz()}};
265 array<double, 4> q = {{b.E(), b.px(), b.py(), b.pz()}};
266 array<double, 4> r = {{c.E(), c.px(), c.py(), c.pz()}};
267 array<double, 4> s = {{d.E(), d.px(), d.py(), d.pz()}};
268 double temp = +(-p[3] * q[2] * r[1] * s[0] + p[2] * q[3] * r[1] * s[0] + p[3] * q[1] * r[2] * s[0] -
269 p[1] * q[3] * r[2] * s[0] - p[2] * q[1] * r[3] * s[0] + p[1] * q[2] * r[3] * s[0] +
270 p[3] * q[2] * r[0] * s[1] - p[2] * q[3] * r[0] * s[1] - p[3] * q[0] * r[2] * s[1] +
271 p[0] * q[3] * r[2] * s[1] + p[2] * q[0] * r[3] * s[1] - p[0] * q[2] * r[3] * s[1] -
272 p[3] * q[1] * r[0] * s[2] + p[1] * q[3] * r[0] * s[2] + p[3] * q[0] * r[1] * s[2] -
273 p[0] * q[3] * r[1] * s[2] - p[1] * q[0] * r[3] * s[2] + p[0] * q[1] * r[3] * s[2] +
274 p[2] * q[1] * r[0] * s[3] - p[1] * q[2] * r[0] * s[3] - p[2] * q[0] * r[1] * s[3] +
275 p[0] * q[2] * r[1] * s[3] + p[1] * q[0] * r[2] * s[3] - p[0] * q[1] * r[2] * s[3]);
279 FourMomentum
boostToRestFrameOf(
const FourMomentum& mom,
double vx,
double vy,
double vz) {
280 FourMomentum result = mom;
286 FourMomentum result = mom;
292 FourMomentum result = mom;
297 double dot(
const array<double, 3>& a,
const array<double, 3>& b) {
298 return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
301 double costheta(
const array<double, 3>& a,
const array<double, 3>& b) {
302 double res =
dot(a,b)/sqrt(
dot(a,a)*
dot(b,b));
304 throw Error(
"Nan in Cosine. Cock. In Hungarian.");
FourMomentum boostToRestFrameOf(const FourMomentum &mom, double vx, double vy, double vz)
FourMomentum & boostToRestFrameOf(const FourMomentum &v)
returns a boosted 4-vector
FourMomentum()
default constructor
static FourMomentum fromPM(double px, double py, double pz, double mass)
builder method based on 3-momentum and invariant mass
double eta() const
returns the pseudorapidity (along the z-axis)
double phi() const
returns the azimuthal angle
FourMomentum & operator-=(const FourMomentum &v)
subtract the 4-momentum by another
double p2() const
returns the squared 3-momentum
double p() const
returns the absolute value of the 3-momentum
double gamma() const
returns the for the Lorentz transformation to the rest frame
double E() const
returns the energy
FourMomentum & operator+=(const FourMomentum &v)
adds the another 4-momentum to itself
Hammer four momentum class.
double costheta(const std::array< double, 3 > &a, const std::array< double, 3 > &b)
double dot(const FourMomentum &v) const
contracts the 4-momentum with another
FourMomentum & setPy(double py)
set the 4-momentum momentum y component
double angle(const FourMomentum &v, const FourMomentum &w)
computes the angle between the spatial components of two 4-momenta
double pt() const
returns the transverse momentum
static FourMomentum fromPtEtaPhiM(double pt, double eta, double phi, double mass)
builder method based on collider-friendly variables
double mass2() const
returns the squared invariant mass
double mass() const
returns the invariant mass if the invariant mass squared is negative returns
FourMomentum & setE(double E)
set the 4-momentum energy
FourMomentum PFlip() const
construct a copy of itself with all the signs of the spatial components flipped
double beta() const
returns the value of the boost to the rest frame
Hammer exception definitions.
void boostBy(const std::array< double, 3 > &v)
FourMomentum operator-() const
construct a copy of itself with all the signs of the components flipped
double epsilon(const FourMomentum &a, const FourMomentum &b, const FourMomentum &c, const FourMomentum &d)
contracts four 4-momenta with an 4D epsilon tensor.
std::array< double, 4 > _vec
the contents of the 4-momentum in the notation .
double deltaR(const FourMomentum &v, const FourMomentum &w)
computes between two 4-momenta
FourMomentum & boostFromRestFrameOf(const FourMomentum &v)
FourMomentum & operator*=(double a)
multiplies the components by a constant
std::array< double, 3 > pVec() const
returns the spatial 3-vector as an array
bool fuzzyLess(const double val1, const double val2)
bool isZero(const std::complex< double > val)
Tensor operator*(const Tensor &first, double val)
left multiplies a tensor by a real constant
FourMomentum & operator/=(double a)
divides the components by a constant
double deltaPhi(const FourMomentum &v, const FourMomentum &w)
computes the difference between the azimuthal angles of two 4-momenta
FourMomentum & setPz(double pz)
set the 4-momentum momentum z component
std::array< double, 3 > boostVector() const
returns the boost 3-vector
double pz() const
returns the momentum z component
double deltaEta(const FourMomentum &v, const FourMomentum &w)
computes the difference between the pseudorapidities of two 4-momenta
Tensor & dot(const Tensor &other, const UniqueLabelsList &indices={})
contract this tensor with another and stores the result in this tensor
double py() const
returns the momentum y component
FourMomentum & setPx(double px)
set the 4-momentum momentum x component
static FourMomentum fromEtaPhiME(double eta, double phi, double mass, double E)
builder method based on collider-friendly variables
double theta() const
returns the polar angle (along the z-axis)
double rapidity() const
returns the rapidity (along the z-axis)
double px() const
returns the momentum x component
Tensor dot(const Tensor &first, const Tensor &second, const set< IndexLabel > &indices)