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) {
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();
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();
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;
206 inline FourVector multiply(
const double a,
const FourVector& v) {
208 result._vec = a * v._vec;
212 inline FourVector multiply(
const FourVector& v,
const double a) {
213 return multiply(a, v);
216 inline FourVector operator*(
const double a,
const FourVector& v) {
217 return multiply(a, v);
220 inline FourVector operator*(
const FourVector& v,
const double a) {
221 return multiply(a, v);
224 inline FourVector operator/(
const FourVector& v,
const double a) {
225 return multiply(1.0/a, v);
228 inline FourVector add(
const FourVector& a,
const FourVector& b) {
230 result._vec = a._vec + b._vec;
234 inline FourVector operator+(
const FourVector& a,
const FourVector& b) {
238 inline FourVector operator-(
const FourVector& a,
const FourVector& b) {
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());
355 double E()
const {
return t(); }
361 double px()
const {
return x(); }
364 double py()
const {
return y(); }
367 double pz()
const {
return z(); }
401 return 0.5 * std::log( (
E() +
pz()) / (
E() -
pz()) );
406 return vector3().polarRadius2();
443 double pt2left = left.
E();
444 double pt2right = right.
E();
445 return pt2left < pt2right;
449 return (*
this)(left, right);
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;
500 inline FourMomentum multiply(
const double a,
const FourMomentum& v) {
502 result._vec = a * v._vec;
506 inline FourMomentum multiply(
const FourMomentum& v,
const double a) {
507 return multiply(a, v);
510 inline FourMomentum operator*(
const double a,
const FourMomentum& v) {
511 return multiply(a, v);
514 inline FourMomentum operator*(
const FourMomentum& v,
const double a) {
515 return multiply(a, v);
518 inline FourMomentum operator/(
const FourMomentum& v,
const double a) {
519 return multiply(1.0/a, v);
522 inline FourMomentum add(
const FourMomentum& a,
const FourMomentum& b) {
524 result._vec = a._vec + b._vec;
528 inline FourMomentum operator+(
const FourMomentum& a,
const FourMomentum& b) {
532 inline FourMomentum operator-(
const FourMomentum& a,
const FourMomentum& b) {
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())