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;
215 return std::copysign(
eta, z());
245 _vec =
add(*
this,
v)._vec;
279 result._vec = a * v._vec;
285 return multiply(a, v);
290 return multiply(a, v);
295 return multiply(a, v);
300 return multiply(1.0/a, v);
306 result._vec = a._vec + b._vec;
313 result._vec = a._vec - b._vec;
324 return subtract(a, b);
345 this->
setPx(other.x());
346 this->
setPy(other.y());
347 this->
setPz(other.z());
392 double px()
const {
return x(); }
394 double px2()
const {
return x2(); }
397 double py()
const {
return y(); }
399 double py2()
const {
return y2(); }
402 double pz()
const {
return z(); }
404 double pz2()
const {
return z2(); }
408 double p()
const {
return mod(); }
463 _vec =
add(*
this,
v)._vec;
469 _vec =
add(*
this, -
v)._vec;
490 inline ThreeMomentum multiply(
const double a,
const ThreeMomentum& v) {
491 ThreeMomentum result;
492 result._vec = a * v._vec;
496 inline ThreeMomentum multiply(
const ThreeMomentum& v,
const double a) {
497 return multiply(a, v);
500 inline ThreeMomentum operator*(
const double a,
const ThreeMomentum& v) {
501 return multiply(a, v);
504 inline ThreeMomentum operator*(
const ThreeMomentum& v,
const double a) {
505 return multiply(a, v);
508 inline ThreeMomentum operator/(
const ThreeMomentum& v,
const double a) {
509 return multiply(1.0/a, v);
512 inline ThreeMomentum add(
const ThreeMomentum& a,
const ThreeMomentum& b) {
513 ThreeMomentum result;
514 result._vec = a._vec + b._vec;
518 inline ThreeMomentum operator+(
const ThreeMomentum& a,
const ThreeMomentum& b) {
522 inline ThreeMomentum operator-(
const ThreeMomentum& a,
const ThreeMomentum& b) {
530 return add(
static_cast<const Vector3&
>(a), b);
532 inline Vector3 operator+(
const Vector3& a,
const ThreeMomentum& b) {
533 return add(a,
static_cast<const Vector3&
>(b));
536 inline Vector3 operator-(
const ThreeMomentum& a,
const Vector3& b) {
537 return add(
static_cast<const Vector3&
>(a), -b);
539 inline Vector3 operator-(
const Vector3& a,
const ThreeMomentum& b) {
540 return add(a, -
static_cast<const Vector3&
>(b));
611 return sqrt(
deltaR2(v, eta2, phi2));
621 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:339
double pt() const
Calculate the transverse momentum .
Definition Vector3.hh:436
double pz() const
Get z-component of momentum .
Definition Vector3.hh:402
double pz2() const
Get z-squared .
Definition Vector3.hh:404
double pT() const
Calculate the transverse momentum .
Definition Vector3.hh:432
double p() const
Get the modulus of the 3-momentum.
Definition Vector3.hh:408
ThreeMomentum pTvec() const
Calculate the transverse momentum vector .
Definition Vector3.hh:414
double px() const
Get x-component of momentum .
Definition Vector3.hh:392
double py() const
Get y-component of momentum .
Definition Vector3.hh:397
ThreeMomentum & setPy(double py)
Set y-component of momentum .
Definition Vector3.hh:374
ThreeMomentum & operator-=(const ThreeMomentum &v)
Subtract two 3-momenta.
Definition Vector3.hh:468
double pT2() const
Calculate the squared transverse momentum .
Definition Vector3.hh:423
double px2() const
Get x-squared .
Definition Vector3.hh:394
ThreeMomentum & setPz(double pz)
Set z-component of momentum .
Definition Vector3.hh:380
double pt2() const
Calculate the squared transverse momentum .
Definition Vector3.hh:427
ThreeMomentum & operator/=(double a)
Divide by a scalar.
Definition Vector3.hh:456
ThreeMomentum & operator+=(const ThreeMomentum &v)
Add two 3-momenta.
Definition Vector3.hh:462
ThreeMomentum & setPx(double px)
Set x-component of momentum .
Definition Vector3.hh:368
ThreeMomentum operator-() const
Multiply all components by -1.
Definition Vector3.hh:474
ThreeMomentum & operator*=(double a)
Multiply by a scalar.
Definition Vector3.hh:450
ThreeMomentum ptvec() const
Synonym for pTvec.
Definition Vector3.hh:418
double py2() const
Get y-squared .
Definition Vector3.hh:399
double p2() const
Get the modulus-squared of the 3-momentum.
Definition Vector3.hh:410
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:219
double perp() const
Synonym for polarRadius.
Definition Vector3.hh:162
Vector3 & operator-=(const Vector3 &v)
In-place subtraction operator.
Definition Vector3.hh:250
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:224
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:244
friend Vector3 subtract(const Vector3 &, const Vector3 &)
Unbound vector subtraction function.
Definition Vector3.hh:311
Vector3 & operator*=(const double a)
In-place scalar multiplication operator.
Definition Vector3.hh:232
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:304
double rho2() const
Synonym for polarRadius2.
Definition Vector3.hh:153
Vector3 & operator/=(const double a)
In-place scalar division operator.
Definition Vector3.hh:238
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:256
friend Vector3 multiply(const double, const Vector3 &)
Unbound scalar-product function.
Definition Vector3.hh:277
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:639
Definition MC_CENT_PPB_Projections.hh:10
double deltaR(double rap1, double phi1, double rap2, double phi2)
Definition MathUtils.hh:698
double deltaPhi(double phi1, double phi2, bool sign=false)
Calculate the difference between two angles in radians.
Definition MathUtils.hh:668
double deltaEta(double eta1, double eta2, bool sign=false)
Definition MathUtils.hh:676
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:691
double mT(double pT1, double pT2, double dphi)
Definition MathUtils.hh:720
constexpr std::enable_if< std::is_arithmetic< NUM >::value, int >::type sign(NUM val)
Find the sign of a number.
Definition MathUtils.hh:265
Vector3 cross(const Vector3 &a, const Vector3 &b)
Unbound cross-product function.
Definition Vector3.hh:272
double mapAngle(double angle, PhiMapping mapping)
Map an angle into the enum-specified range.
Definition MathUtils.hh:646
double mapAngle0ToPi(double angle)
Map an angle into the range [0, PI].
Definition MathUtils.hh:638
std::enable_if< std::is_arithmetic< NUM >::value, NUM >::type sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.hh:219
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:177