1#ifndef RIVET_MATH_VECTOR3
2#define RIVET_MATH_VECTOR3
4#include "Rivet/Tools/TypeTraits.hh"
5#include "Rivet/Math/MathConstants.hh"
6#include "Rivet/Math/MathUtils.hh"
7#include "Rivet/Math/VectorN.hh"
13 typedef Vector3 ThreeVector;
15 Vector3 multiply(
const double,
const Vector3&);
16 Vector3 multiply(
const Vector3&,
const double);
17 Vector3 add(
const Vector3&,
const Vector3&);
18 Vector3 operator*(
const double,
const Vector3&);
19 Vector3 operator*(
const Vector3&,
const double);
20 Vector3 operator/(
const Vector3&,
const double);
21 Vector3 operator+(
const Vector3&,
const Vector3&);
22 Vector3 operator-(
const Vector3&,
const Vector3&);
25 typedef ThreeMomentum P3;
26 ThreeMomentum multiply(
const double,
const ThreeMomentum&);
27 ThreeMomentum multiply(
const ThreeMomentum&,
const double);
28 ThreeMomentum add(
const ThreeMomentum&,
const ThreeMomentum&);
29 ThreeMomentum operator*(
const double,
const ThreeMomentum&);
30 ThreeMomentum operator*(
const ThreeMomentum&,
const double);
31 ThreeMomentum operator/(
const ThreeMomentum&,
const double);
32 ThreeMomentum operator+(
const ThreeMomentum&,
const ThreeMomentum&);
33 ThreeMomentum operator-(
const ThreeMomentum&,
const ThreeMomentum&);
51 template<
typename V3TYPE>
53 this->setX(
other.x());
54 this->setY(
other.y());
55 this->setZ(
other.z());
59 this->setX(
other.get(0));
60 this->setY(
other.get(1));
61 this->setZ(
other.get(2));
64 Vector3(
double x,
double y,
double z) {
82 double x()
const {
return get(0); }
83 double x2()
const {
return sqr(x()); }
84 Vector3& setX(
double x) {
set(0, x);
return *
this; }
86 double y()
const {
return get(1); }
87 double y2()
const {
return sqr(y()); }
88 Vector3& setY(
double y) {
set(1, y);
return *
this; }
90 double z()
const {
return get(2); }
91 double z2()
const {
return sqr(z()); }
92 Vector3& setZ(
double z) {
set(2, z);
return *
this; }
97 return _vec.dot(
v._vec);
120 else return *
this * 1.0/
md;
146 return x()*x() + y()*y();
177 if (x() == 0 && y() == 0)
return 0.0;
179 const double value =
atan2( y(), x() );
213 if (
mod() == 0.0)
return 0.0;
214 if (
mod() ==
fabs(z()) )
return std::copysign(INF, z());
216 return std::copysign(
eta, z());
246 _vec =
add(*
this,
v)._vec;
280 result._vec = a * v._vec;
286 return multiply(a, v);
291 return multiply(a, v);
296 return multiply(a, v);
301 return multiply(1.0/a, v);
307 result._vec = a._vec + b._vec;
314 result._vec = a._vec - b._vec;
325 return subtract(a, b);
346 this->
setPx(other.x());
347 this->
setPy(other.y());
348 this->
setPz(other.z());
393 double px()
const {
return x(); }
395 double px2()
const {
return x2(); }
398 double py()
const {
return y(); }
400 double py2()
const {
return y2(); }
403 double pz()
const {
return z(); }
405 double pz2()
const {
return z2(); }
409 double p()
const {
return mod(); }
464 _vec =
add(*
this,
v)._vec;
470 _vec =
add(*
this, -
v)._vec;
491 inline ThreeMomentum multiply(
const double a,
const ThreeMomentum& v) {
492 ThreeMomentum result;
493 result._vec = a * v._vec;
497 inline ThreeMomentum multiply(
const ThreeMomentum& v,
const double a) {
498 return multiply(a, v);
501 inline ThreeMomentum operator*(
const double a,
const ThreeMomentum& v) {
502 return multiply(a, v);
505 inline ThreeMomentum operator*(
const ThreeMomentum& v,
const double a) {
506 return multiply(a, v);
509 inline ThreeMomentum operator/(
const ThreeMomentum& v,
const double a) {
510 return multiply(1.0/a, v);
513 inline ThreeMomentum add(
const ThreeMomentum& a,
const ThreeMomentum& b) {
514 ThreeMomentum result;
515 result._vec = a._vec + b._vec;
519 inline ThreeMomentum operator+(
const ThreeMomentum& a,
const ThreeMomentum& b) {
523 inline ThreeMomentum operator-(
const ThreeMomentum& a,
const ThreeMomentum& b) {
531 return add(
static_cast<const Vector3&
>(a), b);
533 inline Vector3 operator+(
const Vector3& a,
const ThreeMomentum& b) {
534 return add(a,
static_cast<const Vector3&
>(b));
537 inline Vector3 operator-(
const ThreeMomentum& a,
const Vector3& b) {
538 return add(
static_cast<const Vector3&
>(a), -b);
540 inline Vector3 operator-(
const Vector3& a,
const ThreeMomentum& b) {
541 return add(a, -
static_cast<const Vector3&
>(b));
612 return sqrt(
deltaR2(v, eta2, phi2));
622 return sqrt(
deltaR2(eta1, phi1, v));
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition Matrix3.hh:13
Specialized version of the ThreeVector with momentum functionality.
Definition Vector3.hh:340
double pt() const
Calculate the transverse momentum .
Definition Vector3.hh:437
double pz() const
Get z-component of momentum .
Definition Vector3.hh:403
double pz2() const
Get z-squared .
Definition Vector3.hh:405
double pT() const
Calculate the transverse momentum .
Definition Vector3.hh:433
double p() const
Get the modulus of the 3-momentum.
Definition Vector3.hh:409
ThreeMomentum pTvec() const
Calculate the transverse momentum vector .
Definition Vector3.hh:415
double px() const
Get x-component of momentum .
Definition Vector3.hh:393
double py() const
Get y-component of momentum .
Definition Vector3.hh:398
ThreeMomentum & setPy(double py)
Set y-component of momentum .
Definition Vector3.hh:375
ThreeMomentum & operator-=(const ThreeMomentum &v)
Subtract two 3-momenta.
Definition Vector3.hh:469
double pT2() const
Calculate the squared transverse momentum .
Definition Vector3.hh:424
double px2() const
Get x-squared .
Definition Vector3.hh:395
ThreeMomentum & setPz(double pz)
Set z-component of momentum .
Definition Vector3.hh:381
double pt2() const
Calculate the squared transverse momentum .
Definition Vector3.hh:428
ThreeMomentum & operator/=(double a)
Divide by a scalar.
Definition Vector3.hh:457
ThreeMomentum & operator+=(const ThreeMomentum &v)
Add two 3-momenta.
Definition Vector3.hh:463
ThreeMomentum & setPx(double px)
Set x-component of momentum .
Definition Vector3.hh:369
ThreeMomentum operator-() const
Multiply all components by -1.
Definition Vector3.hh:475
ThreeMomentum & operator*=(double a)
Multiply by a scalar.
Definition Vector3.hh:451
ThreeMomentum ptvec() const
Synonym for pTvec.
Definition Vector3.hh:419
double py2() const
Get y-squared .
Definition Vector3.hh:400
double p2() const
Get the modulus-squared of the 3-momentum.
Definition Vector3.hh:411
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
Vector3 rhoVec() const
Synonym for polarVec.
Definition Vector3.hh:140
double polarRadius() const
Polar radius.
Definition Vector3.hh:158
Vector3 cross(const Vector3 &v) const
Cross-product with another vector.
Definition Vector3.hh:101
double rho() const
Synonym for polarRadius.
Definition Vector3.hh:166
double eta() const
Synonym for pseudorapidity.
Definition Vector3.hh:220
double perp() const
Synonym for polarRadius.
Definition Vector3.hh:162
Vector3 & operator-=(const Vector3 &v)
In-place subtraction operator.
Definition Vector3.hh:251
double perp2() const
Synonym for polarRadius2.
Definition Vector3.hh:149
double pseudorapidity() const
Purely geometric approximation to rapidity.
Definition Vector3.hh:212
Vector3 unit() const
Synonym for unitVec.
Definition Vector3.hh:124
double abseta() const
Convenience shortcut for fabs(eta())
Definition Vector3.hh:225
double tanTheta() const
Tangent of the polar angle.
Definition Vector3.hh:188
double theta() const
Synonym for polarAngle.
Definition Vector3.hh:200
double dot(const Vector3 &v) const
Dot-product with another vector.
Definition Vector3.hh:96
double phi(const PhiMapping mapping=ZERO_2PI) const
Synonym for azimuthalAngle.
Definition Vector3.hh:183
Vector3 & operator+=(const Vector3 &v)
In-place addition operator.
Definition Vector3.hh:245
friend Vector3 subtract(const Vector3 &, const Vector3 &)
Unbound vector subtraction function.
Definition Vector3.hh:312
Vector3 & operator*=(const double a)
In-place scalar multiplication operator.
Definition Vector3.hh:233
double polarRadius2() const
Square of the polar radius (.
Definition Vector3.hh:145
Vector3 perpVec() const
Synonym for polarVec.
Definition Vector3.hh:136
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:174
friend Vector3 add(const Vector3 &, const Vector3 &)
Unbound vector addition function.
Definition Vector3.hh:305
double rho2() const
Synonym for polarRadius2.
Definition Vector3.hh:153
Vector3 & operator/=(const double a)
In-place scalar division operator.
Definition Vector3.hh:239
double angle(const Vector3 &v) const
Angle in radians to another vector.
Definition Vector3.hh:108
double polarAngle() const
Angle subtended by the vector and the z-axis.
Definition Vector3.hh:193
Vector3 operator-() const
In-place negation operator.
Definition Vector3.hh:257
friend Vector3 multiply(const double, const Vector3 &)
Unbound scalar-product function.
Definition Vector3.hh:278
Vector3 unitVec() const
Unit-normalized version of this vector.
Definition Vector3.hh:117
Vector3 polarVec() const
Polar projection of this vector into the x-y plane.
Definition Vector3.hh:130
A minimal base class for -dimensional vectors.
Definition VectorN.hh:23
double mod() const
Calculate the modulus of a vector. .
Definition VectorN.hh:95
double mod2() const
Calculate the modulus-squared of a vector. .
Definition VectorN.hh:84
Vector< N > & set(const size_t index, const double value)
Set indexed value.
Definition VectorN.hh:60
double pT(const Vector3 &a, const Vector3 &b)
Calculate transverse momentum of pair of 3-vectors.
Definition Vector3.hh:640
Definition MC_CENT_PPB_Projections.hh:10
constexpr std::enable_if_t< std::is_arithmetic_v< NUM >, int > sign(NUM val)
Find the sign of a number.
Definition MathUtils.hh:264
double deltaR(double rap1, double phi1, double rap2, double phi2)
Definition MathUtils.hh:697
double deltaPhi(double phi1, double phi2, bool sign=false)
Calculate the difference between two angles in radians.
Definition MathUtils.hh:667
double deltaEta(double eta1, double eta2, bool sign=false)
Definition MathUtils.hh:675
PhiMapping
Enum for range of to be mapped into.
Definition MathConstants.hh:49
double deltaR2(double rap1, double phi1, double rap2, double phi2)
Definition MathUtils.hh:690
double mT(double pT1, double pT2, double dphi)
Definition MathUtils.hh:719
std::enable_if_t< std::is_arithmetic_v< NUM >, NUM > sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.hh:218
Vector3 cross(const Vector3 &a, const Vector3 &b)
Unbound cross-product function.
Definition Vector3.hh:273
double mapAngle(double angle, PhiMapping mapping)
Map an angle into the enum-specified range.
Definition MathUtils.hh:645
double mapAngle0ToPi(double angle)
Map an angle into the range [0, PI].
Definition MathUtils.hh:637
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:177