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"
40 class Vector3 :
public Vector<3> {
43 friend Vector3
multiply(
const double,
const Vector3&);
44 friend Vector3
multiply(
const Vector3&,
const double);
45 friend Vector3
add(
const Vector3&,
const Vector3&);
46 friend Vector3
subtract(
const Vector3&,
const Vector3&);
49 Vector3() : Vector<3>() { }
51 template<
typename V3TYPE>
52 Vector3(
const V3TYPE& other) {
53 this->setX(other.x());
54 this->setY(other.y());
55 this->setZ(other.z());
58 Vector3(
const Vector<3>& other) {
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) {
75 static Vector3 mkX() {
return Vector3(1,0,0); }
76 static Vector3 mkY() {
return Vector3(0,1,0); }
77 static Vector3 mkZ() {
return Vector3(0,0,1); }
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; }
96 double dot(
const Vector3& v)
const {
97 return _vec.dot(v._vec);
101 Vector3
cross(
const Vector3& v)
const {
103 result._vec = _vec.
cross(v._vec);
108 double angle(
const Vector3& v)
const {
110 if (localDotOther > 1.0)
return 0.0;
111 if (localDotOther < -1.0)
return M_PI;
112 return acos(localDotOther);
120 else return *
this * 1.0/md;
145 return x()*x() + y()*y();
176 if (x() == 0 && y() == 0)
return 0.0;
178 const double value = atan2( y(), x() );
204 const double polarangle = atan2(
polarRadius(), z());
222 if (
mod() == 0.0)
return 0.0;
223 if (
mod() == fabs(z()) )
return std::copysign(INF, z());
224 const double eta = std::log((
mod() + fabs(z())) /
perp());
225 return std::copysign(
eta, z());
255 _vec =
add(*
this, v)._vec;
287 inline Vector3
multiply(
const double a,
const Vector3& v) {
289 result._vec = a * v._vec;
294 inline Vector3
multiply(
const Vector3& v,
const double a) {
300 return multiply(a, v);
305 return multiply(a, v);
310 return multiply(1.0/a, v);
314 inline Vector3
add(
const Vector3& a,
const Vector3& b) {
316 result._vec = a._vec + b._vec;
321 inline Vector3
subtract(
const Vector3& a,
const Vector3& b) {
323 result._vec = a._vec - b._vec;
349 class ThreeMomentum :
public ThreeVector {
353 template<typename V3TYPE, typename std::enable_if<HasXYZ<V3TYPE>::value,
int>::type DUMMY=0>
354 ThreeMomentum(
const V3TYPE& other) {
355 this->
setPx(other.x());
356 this->
setPy(other.y());
357 this->
setPz(other.z());
361 : ThreeVector(other) { }
363 ThreeMomentum(
const double px,
const double py,
const double pz) {
402 double px()
const {
return x(); }
404 double px2()
const {
return x2(); }
407 double py()
const {
return y(); }
409 double py2()
const {
return y2(); }
412 double pz()
const {
return z(); }
414 double pz2()
const {
return z2(); }
418 double p()
const {
return mod(); }
473 _vec =
add(*
this, v)._vec;
479 _vec =
add(*
this, -v)._vec;
485 ThreeMomentum result;
500 inline ThreeMomentum multiply(
const double a,
const ThreeMomentum& v) {
501 ThreeMomentum result;
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;
540 return add(
static_cast<const Vector3&
>(a), b);
542 inline Vector3 operator+(
const Vector3& a,
const ThreeMomentum& b) {
543 return add(a,
static_cast<const Vector3&
>(b));
547 return add(
static_cast<const Vector3&
>(a), -b);
550 return add(a, -
static_cast<const Vector3&
>(b));
621 return sqrt(
deltaR2(v, eta2, phi2));
631 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:349
double pt() const
Calculate the transverse momentum .
Definition Vector3.hh:446
double pz() const
Get z-component of momentum .
Definition Vector3.hh:412
double pz2() const
Get z-squared .
Definition Vector3.hh:414
double pT() const
Calculate the transverse momentum .
Definition Vector3.hh:442
double p() const
Get the modulus of the 3-momentum.
Definition Vector3.hh:418
ThreeMomentum pTvec() const
Calculate the transverse momentum vector .
Definition Vector3.hh:424
double px() const
Get x-component of momentum .
Definition Vector3.hh:402
double py() const
Get y-component of momentum .
Definition Vector3.hh:407
ThreeMomentum & setPy(double py)
Set y-component of momentum .
Definition Vector3.hh:384
ThreeMomentum & operator-=(const ThreeMomentum &v)
Subtract two 3-momenta.
Definition Vector3.hh:478
double pT2() const
Calculate the squared transverse momentum .
Definition Vector3.hh:433
double px2() const
Get x-squared .
Definition Vector3.hh:404
ThreeMomentum & setPz(double pz)
Set z-component of momentum .
Definition Vector3.hh:390
double pt2() const
Calculate the squared transverse momentum .
Definition Vector3.hh:437
ThreeMomentum & operator/=(double a)
Divide by a scalar.
Definition Vector3.hh:466
ThreeMomentum & operator+=(const ThreeMomentum &v)
Add two 3-momenta.
Definition Vector3.hh:472
ThreeMomentum & setPx(double px)
Set x-component of momentum .
Definition Vector3.hh:378
ThreeMomentum operator-() const
Multiply all components by -1.
Definition Vector3.hh:484
ThreeMomentum & operator*=(double a)
Multiply by a scalar.
Definition Vector3.hh:460
ThreeMomentum ptvec() const
Synonym for pTvec.
Definition Vector3.hh:428
double py2() const
Get y-squared .
Definition Vector3.hh:409
double p2() const
Get the modulus-squared of the 3-momentum.
Definition Vector3.hh:420
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
Vector3 rhoVec() const
Synonym for polarVec.
Definition Vector3.hh:139
double polarRadius() const
Polar radius.
Definition Vector3.hh:157
double cosTheta() const
Cosine of the polar angle.
Definition Vector3.hh:197
Vector3 cross(const Vector3 &v) const
Cross-product with another vector.
Definition Vector3.hh:101
double rho() const
Synonym for polarRadius.
Definition Vector3.hh:165
double eta() const
Synonym for pseudorapidity.
Definition Vector3.hh:229
friend Vector3 add(const Vector3 &, const Vector3 &)
Unbound vector addition function.
Definition Vector3.hh:314
double perp() const
Synonym for polarRadius.
Definition Vector3.hh:161
Vector3 & operator-=(const Vector3 &v)
In-place subtraction operator.
Definition Vector3.hh:260
double perp2() const
Synonym for polarRadius2.
Definition Vector3.hh:148
double pseudorapidity() const
Purely geometric approximation to rapidity.
Definition Vector3.hh:221
friend Vector3 multiply(const double, const Vector3 &)
Unbound scalar-product function.
Definition Vector3.hh:287
friend Vector3 subtract(const Vector3 &, const Vector3 &)
Unbound vector subtraction function.
Definition Vector3.hh:321
Vector3 unit() const
Synonym for unitVec.
Definition Vector3.hh:124
double abseta() const
Convenience shortcut for fabs(eta()).
Definition Vector3.hh:234
double tanTheta() const
Tangent of the polar angle.
Definition Vector3.hh:187
double theta() const
Synonym for polarAngle.
Definition Vector3.hh:209
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:182
Vector3 & operator+=(const Vector3 &v)
In-place addition operator.
Definition Vector3.hh:254
Vector3 & operator*=(const double a)
In-place scalar multiplication operator.
Definition Vector3.hh:242
double polarRadius2() const
Square of the polar radius (.
Definition Vector3.hh:144
double sinTheta() const
Sine of the polar angle.
Definition Vector3.hh:192
Vector3 perpVec() const
Synonym for polarVec.
Definition Vector3.hh:135
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:173
double rho2() const
Synonym for polarRadius2.
Definition Vector3.hh:152
Vector3 & operator/=(const double a)
In-place scalar division operator.
Definition Vector3.hh:248
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:202
Vector3 operator-() const
In-place negation operator.
Definition Vector3.hh:266
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:129
A minimal base class for -dimensional vectors.
Definition VectorN.hh:23
double mod() const
Definition VectorN.hh:95
double mod2() const
Definition VectorN.hh:84
Vector< N > & set(const size_t index, const double value)
Definition VectorN.hh:60
double pT(const Vector3 &a, const Vector3 &b)
Calculate transverse momentum of pair of 3-vectors.
Definition Vector3.hh:649
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:275
double deltaR(double rap1, double phi1, double rap2, double phi2)
Definition MathUtils.hh:708
double deltaPhi(double phi1, double phi2, bool sign=false)
Calculate the difference between two angles in radians.
Definition MathUtils.hh:678
double subtract(double a, double b, double tolerance=1e-5)
Subtract two numbers with FP fuzziness.
Definition MathUtils.hh:223
double deltaEta(double eta1, double eta2, bool sign=false)
Definition MathUtils.hh:686
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:701
double mT(double pT1, double pT2, double dphi)
Definition MathUtils.hh:731
std::enable_if_t< std::is_arithmetic_v< NUM >, NUM > sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.hh:218
double add(double a, double b, double tolerance=1e-5)
Add two numbers with FP fuzziness.
Definition MathUtils.hh:229
Vector3 cross(const Vector3 &a, const Vector3 &b)
Unbound cross-product function.
Definition Vector3.hh:282
double mapAngle(double angle, PhiMapping mapping)
Map an angle into the enum-specified range.
Definition MathUtils.hh:656
double mapAngle0ToPi(double angle)
Map an angle into the range [0, PI].
Definition MathUtils.hh:648
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:177
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, bool > fuzzyLessEquals(N1 a, N2 b, double tolerance=1e-5)
Compare two floating point numbers for <= with a degree of fuzziness.
Definition MathUtils.hh:94