1 #ifndef RIVET_MATH_VECTOR3
2 #define RIVET_MATH_VECTOR3
4 #include "Rivet/Math/MathHeader.hh"
5 #include "Rivet/Math/MathUtils.hh"
6 #include "Rivet/Math/VectorN.hh"
12 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&);
39 this->setX(other.x());
40 this->setY(other.y());
41 this->setZ(other.z());
45 this->setX(other.get(0));
46 this->setY(other.get(1));
47 this->setZ(other.get(2));
50 Vector3(
double x,
double y,
double z) {
64 double x()
const {
return get(0); }
65 double y()
const {
return get(1); }
66 double z()
const {
return get(2); }
67 Vector3& setX(
double x) {
set(0, x);
return *
this; }
68 Vector3& setY(
double y) {
set(1, y);
return *
this; }
69 Vector3& setZ(
double z) {
set(2, z);
return *
this; }
71 double dot(
const Vector3& v)
const {
72 return _vec.dot(v._vec);
77 result._vec = _vec.cross(v._vec);
81 double angle(
const Vector3& v)
const {
82 const double localDotOther =
unit().dot(v.
unit());
84 else if (
fuzzyEquals(localDotOther, -1.0))
return M_PI;
85 return acos(localDotOther);
90 if (
isZero())
return *
this;
91 else return *
this * 1.0/this->
mod();
94 double polarRadius2()
const {
95 return x()*x() + y()*y();
100 return polarRadius2();
105 return polarRadius2();
108 double polarRadius()
const {
109 return sqrt(polarRadius2());
114 return polarRadius();
119 return polarRadius();
128 const double value = atan2( y(), x() );
140 const double polarangle = atan2(polarRadius(), z());
161 Vector3& operator*=(
const double a) {
162 _vec = multiply(a, *
this)._vec;
166 Vector3& operator/=(
const double a) {
167 _vec = multiply(1.0/a, *
this)._vec;
171 Vector3& operator+=(
const Vector3& v) {
172 _vec = add(*
this, v)._vec;
176 Vector3& operator-=(
const Vector3& v) {
177 _vec = subtract(*
this, v)._vec;
181 Vector3 operator-()
const {
191 inline double dot(
const Vector3& a,
const Vector3& b) {
195 inline Vector3 cross(
const Vector3& a,
const Vector3& b) {
199 inline Vector3 multiply(
const double a,
const Vector3& v) {
201 result._vec = a * v._vec;
205 inline Vector3 multiply(
const Vector3& v,
const double a) {
206 return multiply(a, v);
209 inline Vector3 operator*(
const double a,
const Vector3& v) {
210 return multiply(a, v);
213 inline Vector3 operator*(
const Vector3& v,
const double a) {
214 return multiply(a, v);
217 inline Vector3 operator/(
const Vector3& v,
const double a) {
218 return multiply(1.0/a, v);
221 inline Vector3 add(
const Vector3& a,
const Vector3& b) {
223 result._vec = a._vec + b._vec;
227 inline Vector3 subtract(
const Vector3& a,
const Vector3& b) {
229 result._vec = a._vec - b._vec;
233 inline Vector3 operator+(
const Vector3& a,
const Vector3& b) {
237 inline Vector3 operator-(
const Vector3& a,
const Vector3& b) {
238 return subtract(a, b);
250 return v.polarRadius2();
263 return v.polarRadius();
282 return v.
phi(mapping);
315 inline double deltaEta(
const Vector3& v,
double eta2) {
320 inline double deltaEta(
double eta1,
const Vector3& v) {
336 inline double deltaPhi(
const Vector3& v,
double phi2) {
341 inline double deltaPhi(
double phi1,
const Vector3& v) {
358 inline double deltaR(
const Vector3& v,
double eta2,
double phi2) {
363 inline double deltaR(
double eta1,
double phi1,
const Vector3& v) {
Definition: MC_JetAnalysis.hh:9
double theta(const Vector3 &v)
Synonym for polarAngle.
Definition: Vector3.hh:290
double perp(const Vector3 &v)
Synonym for polarRadius.
Definition: Vector3.hh:266
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition: VectorN.hh:67
double mod() const
Calculate the modulus of a vector. .
Definition: VectorN.hh:87
double phi(const Vector3 &v, const PhiMapping mapping=ZERO_2PI)
Synonym for azimuthalAngle.
Definition: Vector3.hh:281
double polarRadius(const Vector3 &v)
Calculate transverse length of a 3-vector.
Definition: Vector3.hh:262
double mapAngle(double angle, PhiMapping mapping)
Map an angle into the enum-specified range.
Definition: MathUtils.hh:441
double rho() const
Synonym for polarRadius.
Definition: Vector3.hh:118
double polarRadius2(const Vector3 &v)
Calculate transverse length sq. of a 3-vector.
Definition: Vector3.hh:249
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition: Matrix3.hh:13
double pseudorapidity() const
Definition: Vector3.hh:151
Vector3 unit() const
Definition: Vector3.hh:88
double rho2() const
Synonym for polarRadius2.
Definition: Vector3.hh:104
double perp() const
Synonym for polarRadius.
Definition: Vector3.hh:113
PhiMapping
Enum for range of to be mapped into.
Definition: MathHeader.hh:63
double phi(const PhiMapping mapping=ZERO_2PI) const
Synonym for azimuthalAngle.
Definition: Vector3.hh:133
double polarAngle(const Vector3 &v)
Calculate polar angle of a 3-vector.
Definition: Vector3.hh:286
double azimuthalAngle(const Vector3 &v, const PhiMapping mapping=ZERO_2PI)
Calculate azimuthal angle of a 3-vector. Returns a number in (-pi, pi] or in [0, 2pi) according to th...
Definition: Vector3.hh:277
Vector< N > & set(const size_t index, const double value)
Set indexed value.
Definition: VectorN.hh:52
double rho(const Vector3 &v)
Synonym for polarRadius.
Definition: Vector3.hh:270
double angle(const Vector3 &a, const Vector3 &b)
Angle (in radians) between two 3-vectors.
Definition: Vector3.hh:244
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.hh:17
A minimal base class for -dimensional vectors.
Definition: VectorN.hh:13
double polarAngle() const
Angle subtended by the vector and the z-axis.
Definition: Vector3.hh:138
double theta() const
Synonym for polarAngle.
Definition: Vector3.hh:145
double mod2() const
Calculate the modulus-squared of a vector. .
Definition: VectorN.hh:76
double perp2() const
Synonym for polarRadius2.
Definition: Vector3.hh:99
double mapAngle0ToPi(double angle)
Map an angle into the range [0, PI].
Definition: MathUtils.hh:433
double eta(const Vector3 &v)
Synonym for pseudorapidity.
Definition: Vector3.hh:299
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
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26
double rho2(const Vector3 &v)
Synonym for polarRadius2.
Definition: Vector3.hh:257
double eta() const
Synonym for pseudorapidity.
Definition: Vector3.hh:156
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.hh:34
double perp2(const Vector3 &v)
Synonym for polarRadius2.
Definition: Vector3.hh:253
double pseudorapidity(const Vector3 &v)
Calculate pseudorapidity of a 3-vector.
Definition: Vector3.hh:295