1 #ifndef RIVET_MATH_VECTOR4 2 #define RIVET_MATH_VECTOR4 4 #include "Rivet/Math/MathHeader.hh" 5 #include "Rivet/Math/MathUtils.hh" 6 #include "Rivet/Math/VectorN.hh" 7 #include "Rivet/Math/Vector3.hh" 14 class LorentzTransform;
15 typedef FourVector Vector4;
16 FourVector transform(
const LorentzTransform& lt,
const FourVector& v4);
32 this->setT(other.t());
33 this->setX(other.x());
34 this->setY(other.y());
35 this->setZ(other.z());
41 FourVector(
const double t,
const double x,
const double y,
const double z) {
48 virtual ~FourVector() { }
52 double t()
const {
return get(0); }
53 double x()
const {
return get(1); }
54 double y()
const {
return get(2); }
55 double z()
const {
return get(3); }
56 FourVector& setT(
const double t) {
set(0, t);
return *
this; }
57 FourVector& setX(
const double x) {
set(1, x);
return *
this; }
58 FourVector& setY(
const double y) {
set(2, y);
return *
this; }
59 FourVector& setZ(
const double z) {
set(3, z);
return *
this; }
61 double invariant()
const {
63 return (t() + z())*(t() - z()) - x()*x() - y()*y();
67 double angle(
const FourVector& v)
const {
80 return vector3().polarRadius2();
140 return Vector3(
get(1),
get(2),
get(3));
148 const double result = t()*v.t() - x()*v.x() - y()*v.y() - z()*v.z();
153 double dot(
const FourVector& v)
const {
164 _vec = multiply(a, *
this)._vec;
170 _vec = multiply(1.0/a, *
this)._vec;
176 _vec = add(*
this, v)._vec;
182 _vec = add(*
this, -v)._vec;
208 result._vec = a * v._vec;
213 return multiply(a, v);
217 return multiply(a, v);
221 return multiply(a, v);
225 return multiply(1.0/a, v);
230 result._vec = a._vec + b._vec;
245 return lv.invariant();
295 return v.
phi(mapping);
333 template<
typename V4>
335 this->setE(other.t());
336 this->setPx(other.x());
337 this->setPy(other.y());
338 this->setPz(other.z());
344 FourMomentum(
const double E,
const double px,
const double py,
const double pz) {
355 double E()
const {
return t(); }
361 double px()
const {
return x(); }
364 double py()
const {
return y(); }
367 double pz()
const {
return z(); }
370 FourMomentum&
setE(
double E) { setT(E);
return *
this; }
373 FourMomentum&
setPx(
double px) { setX(px);
return *
this; }
376 FourMomentum&
setPy(
double py) { setY(py);
return *
this; }
379 FourMomentum&
setPz(
double pz) { setZ(pz);
return *
this; }
401 return 0.5 * std::log( (E() + pz()) / (E() - pz()) );
406 return vector3().polarRadius2();
437 return Vector3(px()/E(), py()/E(), pz()/E());
442 bool operator()(
const FourMomentum& left,
const FourMomentum& right)
const{
443 double pt2left = left.
E();
444 double pt2right = right.
E();
445 return pt2left < pt2right;
448 bool operator()(
const FourMomentum* left,
const FourMomentum* right)
const{
449 return (*
this)(left, right);
455 bool operator()(
const FourMomentum& left,
const FourMomentum& right)
const{
459 bool operator()(
const FourMomentum* left,
const FourVector* right)
const{
460 return (*
this)(left, right);
467 _vec = multiply(a, *
this)._vec;
473 _vec = multiply(1.0/a, *
this)._vec;
479 _vec = add(*
this, v)._vec;
485 _vec = add(*
this, -v)._vec;
502 result._vec = a * v._vec;
507 return multiply(a, v);
511 return multiply(a, v);
515 return multiply(a, v);
519 return multiply(1.0/a, v);
524 result._vec = a._vec + b._vec;
594 case PSEUDORAPIDITY :
601 string err =
"deltaR with scheme RAPIDITY can only be called with FourMomentum objects, not FourVectors";
602 throw std::runtime_error(err);
604 return deltaR(*ma, *mb, scheme);
607 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
618 double eta2,
double phi2,
621 case PSEUDORAPIDITY :
622 return deltaR(v.
vector3(), eta2, phi2);
627 string err =
"deltaR with scheme RAPIDITY can only be called with FourMomentum objects, not FourVectors";
628 throw std::runtime_error(err);
630 return deltaR(*mv, eta2, phi2, scheme);
633 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
643 inline double deltaR(
double eta1,
double phi1,
647 case PSEUDORAPIDITY :
648 return deltaR(eta1, phi1, v.
vector3());
653 string err =
"deltaR with scheme RAPIDITY can only be called with FourMomentum objects, not FourVectors";
654 throw std::runtime_error(err);
656 return deltaR(eta1, phi1, *mv, scheme);
659 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
677 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
687 double eta2,
double phi2,
691 return deltaR(v.
vector3(), eta2, phi2);
695 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
705 inline double deltaR(
double eta1,
double phi1,
710 return deltaR(eta1, phi1, v.
vector3());
714 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
731 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
748 throw std::runtime_error(
"The specified deltaR scheme is not yet implemented");
788 return deltaPhi(v.
vector3(), phi2);
793 return deltaPhi(phi1, v.
vector3());
803 return deltaPhi(v.
vector3(), phi2);
808 return deltaPhi(phi1, v.
vector3());
823 return deltaPhi(a.
vector3(), b);
828 return deltaPhi(a, b.
vector3());
833 return deltaPhi(a.
vector3(), b);
838 return deltaPhi(a, b.
vector3());
853 return deltaEta(v.
vector3(), eta2);
858 return deltaEta(eta1, v.
vector3());
868 return deltaEta(v.
vector3(), eta2);
873 return deltaEta(eta1, v.
vector3());
888 return deltaEta(a.
vector3(), b);
893 return deltaEta(a, b.
vector3());
898 return deltaEta(a.
vector3(), b);
903 return deltaEta(a, b.
vector3());
917 out <<
"(" << (fabs(lv.t()) < 1E-30 ? 0.0 : lv.t())
918 <<
"; " << (fabs(lv.x()) < 1E-30 ? 0.0 : lv.x())
919 <<
", " << (fabs(lv.y()) < 1E-30 ? 0.0 : lv.y())
920 <<
", " << (fabs(lv.z()) < 1E-30 ? 0.0 : lv.z())
FourMomentum & setPy(double py)
Set y-component of momentum .
Definition: Vector4.hh:376
FourVector operator-() const
Multiply all components (space and time) by -1.
Definition: Vector4.hh:187
Definition: MC_JetAnalysis.hh:9
Vector3 boostVector(const FourMomentum &v)
Calculate the velocity boost vector of a momentum 4-vector.
Definition: Vector4.hh:573
double pT() const
Calculate the transverse momentum .
Definition: Vector4.hh:410
FourMomentum & operator+=(const FourMomentum &v)
Subtract from this 4-vector. NB time as well as space components are subtracted.
Definition: Vector4.hh:478
double perp() const
Synonym for polarRadius.
Definition: Vector4.hh:99
double rapidity(double E, double pz)
Calculate a rapidity value from the supplied energy E and longitudinal momentum pz.
Definition: MathUtils.hh:481
double px() const
Get x-component of momentum .
Definition: Vector4.hh:361
double eta() const
Synonym for pseudorapidity.
Definition: Vector4.hh:134
FourMomentum & setPz(double pz)
Set z-component of momentum .
Definition: Vector4.hh:379
FourVector & operator*=(double a)
Multiply by a scalar.
Definition: Vector4.hh:163
double azimuthalAngle(const PhiMapping mapping=ZERO_2PI) const
Angle subtended by the 3-vector's projection in x-y and the x-axis.
Definition: Vector4.hh:109
double Et() const
Calculate the transverse energy .
Definition: Vector4.hh:420
double rho() const
Synonym for polarRadius.
Definition: Vector3.hh:118
double Et2(const FourMomentum &v)
Calculate the transverse energy squared, of a momentum 4-vector.
Definition: Vector4.hh:564
FourMomentum & operator*=(double a)
Multiply by a scalar.
Definition: Vector4.hh:466
double perp() const
Synonym for polarRadius.
Definition: Vector3.hh:113
FourMomentum & setE(double E)
Set energy (time component of momentum).
Definition: Vector4.hh:370
double contract(const FourVector &v) const
Contract two 4-vectors, with metric signature (+ - - -).
Definition: Vector4.hh:147
double mass2() const
Get the squared mass (the Lorentz self-invariant).
Definition: Vector4.hh:395
double rapidity() const
Calculate the rapidity.
Definition: Vector4.hh:400
FourMomentum & operator-=(const FourMomentum &v)
Subtract from this 4-vector. NB time as well as space components are subtracted.
Definition: Vector4.hh:484
double pseudorapidity() const
Pseudorapidity (defined purely by the 3-vector components)
Definition: Vector4.hh:129
double polarRadius() const
Projection of 3-vector on to the plane.
Definition: Vector4.hh:94
FourMomentum & setPx(double px)
Set x-component of momentum .
Definition: Vector4.hh:373
Struct for sorting by increasing energy.
Definition: Vector4.hh:441
double polarAngle() const
Angle subtended by the vector and the z-axis.
Definition: Vector3.hh:138
PhiMapping
Enum for range of to be mapped into.
Definition: MathHeader.hh:63
double dot(const FourVector &v) const
Contract two 4-vectors, with metric signature (+ - - -).
Definition: Vector4.hh:153
double pseudorapidity() const
Definition: Vector3.hh:151
double angle(const Vector3 &v3) const
Angle between this vector and another (3-vector)
Definition: Vector4.hh:72
double rho2() const
Synonym for polarRadius2.
Definition: Vector3.hh:104
double mass() const
Get the mass (the Lorentz self-invariant).
Definition: Vector4.hh:384
double rho2() const
Synonym for polarRadius2.
Definition: Vector4.hh:89
FourMomentum operator-() const
Multiply all components (time and space) by -1.
Definition: Vector4.hh:490
Specialisation of VectorN to a general (non-momentum) Lorentz 4-vector.
Definition: Vector4.hh:20
double invariant(const FourVector &lv)
Definition: Vector4.hh:244
A minimal base class for -dimensional vectors.
Definition: VectorN.hh:13
double polarRadius2() const
Square of the projection of the 3-vector on to the plane This is a more efficient function than pola...
Definition: Vector4.hh:79
double E() const
Get energy (time component of momentum).
Definition: Vector4.hh:355
RapScheme
Enum for rapidity variable to be used in calculating , applying rapidity cuts, etc.
Definition: MathHeader.hh:60
FourMomentum & operator/=(double a)
Divide by a scalar.
Definition: Vector4.hh:472
double operator*(const FourVector &v) const
Contract two 4-vectors, with metric signature (+ - - -).
Definition: Vector4.hh:158
int sign(double val)
Find the sign of a number.
Definition: MathUtils.hh:187
double Et(const FourMomentum &v)
Calculate the transverse energy of a momentum 4-vector.
Definition: Vector4.hh:568
double perp2() const
Synonym for polarRadius2.
Definition: Vector4.hh:84
Vector3 vector3() const
Get the spatial part of the 4-vector as a 3-vector.
Definition: Vector4.hh:139
Vector3 p() const
Get 3-momentum part, .
Definition: Vector4.hh:358
double angle(const FourVector &v) const
Angle between this vector and another.
Definition: Vector4.hh:67
double theta() const
Synonym for polarAngle.
Definition: Vector4.hh:124
double polarAngle() const
Angle subtended by the 3-vector and the z-axis.
Definition: Vector4.hh:119
double pz() const
Get z-component of momentum .
Definition: Vector4.hh:367
double phi(const PhiMapping mapping=ZERO_2PI) const
Synonym for azimuthalAngle.
Definition: Vector4.hh:114
double py() const
Get y-component of momentum .
Definition: Vector4.hh:364
double azimuthalAngle(const PhiMapping mapping=ZERO_2PI) const
Angle subtended by the vector's projection in x-y and the x-axis.
Definition: Vector3.hh:123
std::string toString(const AnalysisInfo &ai)
String representation.
Definition: AnalysisInfo.cc:234
FourVector & operator-=(const FourVector &v)
Subtract from this 4-vector. NB time as well as space components are subtracted.
Definition: Vector4.hh:181
double theta() const
Synonym for polarAngle.
Definition: Vector3.hh:145
double phi(const PhiMapping mapping=ZERO_2PI) const
Synonym for azimuthalAngle.
Definition: Vector3.hh:133
double mass(const FourMomentum &v)
Get the mass (the Lorentz self-invariant) of a momentum 4-vector.
Definition: Vector4.hh:539
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26
double pT2(const FourMomentum &v)
Calculate the squared transverse momentum of a momentum 4-vector.
Definition: Vector4.hh:554
FourVector & operator+=(const FourVector &v)
Add to this 4-vector.
Definition: Vector4.hh:175
Struct for sorting by decreasing energy.
Definition: Vector4.hh:454
std::ostream & operator<<(std::ostream &os, const AnalysisInfo &ai)
Stream an AnalysisInfo as a text description.
Definition: AnalysisInfo.hh:239
FourVector & operator/=(double a)
Divide by a scalar.
Definition: Vector4.hh:169
Specialized version of the FourVector with momentum/energy functionality.
Definition: Vector4.hh:324
double eta() const
Synonym for pseudorapidity.
Definition: Vector3.hh:156
double Et2() const
Calculate the transverse energy .
Definition: Vector4.hh:415
double pT(const FourMomentum &v)
Calculate the transverse momentum of a momentum 4-vector.
Definition: Vector4.hh:559
double rho() const
Synonym for polarRadius.
Definition: Vector4.hh:104
double perp2() const
Synonym for polarRadius2.
Definition: Vector3.hh:99
double pT2() const
Calculate the squared transverse momentum .
Definition: Vector4.hh:405
double mass2(const FourMomentum &v)
Get the squared mass (the Lorentz self-invariant) of a momentum 4-vector.
Definition: Vector4.hh:544
Vector3 boostVector() const
Calculate the boost vector (in units of ).
Definition: Vector4.hh:425