Vector3.hh
#ifndef RIVET_MATH_VECTOR3
#define RIVET_MATH_VECTOR3
#include "Rivet/Math/MathHeader.hh"
#include "Rivet/Math/MathUtils.hh"
#include "Rivet/Math/VectorN.hh"
namespace Rivet {
class Vector3;
typedef Vector3 ThreeVector;
class Matrix3;
Vector3 multiply(const double, const Vector3&);
Vector3 multiply(const Vector3&, const double);
Vector3 add(const Vector3&, const Vector3&);
Vector3 operator*(const double, const Vector3&);
Vector3 operator*(const Vector3&, const double);
Vector3 operator/(const Vector3&, const double);
Vector3 operator+(const Vector3&, const Vector3&);
Vector3 operator-(const Vector3&, const Vector3&);
class Vector3 : public Vector<3> {
friend class Matrix3;
friend Vector3 multiply(const double, const Vector3&);
friend Vector3 multiply(const Vector3&, const double);
friend Vector3 add(const Vector3&, const Vector3&);
friend Vector3 subtract(const Vector3&, const Vector3&);
public:
Vector3() : Vector<3>() { }
template<typename V3>
Vector3(const V3& other) {
this->setX(other.x());
this->setY(other.y());
this->setZ(other.z());
}
Vector3(const Vector<3>& other) {
this->setX(other.get(0));
this->setY(other.get(1));
this->setZ(other.get(2));
}
Vector3(double x, double y, double z) {
this->setX(x);
this->setY(y);
this->setZ(z);
}
~Vector3() { }
public:
static Vector3 mkX() { return Vector3(1,0,0); }
static Vector3 mkY() { return Vector3(0,1,0); }
static Vector3 mkZ() { return Vector3(0,0,1); }
public:
double x() const { return get(0); }
double y() const { return get(1); }
double z() const { return get(2); }
Vector3& setX(double x) { set(0, x); return *this; }
Vector3& setY(double y) { set(1, y); return *this; }
Vector3& setZ(double z) { set(2, z); return *this; }
double dot(const Vector3& v) const {
return _vec.dot(v._vec);
}
Vector3 cross(const Vector3& v) const {
Vector3 result;
result._vec = _vec.cross(v._vec);
return result;
}
double angle(const Vector3& v) const {
const double localDotOther = unit().dot(v.unit());
if (fuzzyEquals(localDotOther, 1.0)) return 0.0;
else if (fuzzyEquals(localDotOther, -1.0)) return M_PI;
return acos(localDotOther);
}
Vector3 unit() const {
if (isZero()) return *this;
else return *this * 1.0/this->mod();
}
double polarRadius2() const {
return x()*x() + y()*y();
}
double perp2() const {
return polarRadius2();
}
double rho2() const {
return polarRadius2();
}
double polarRadius() const {
return sqrt(polarRadius2());
}
double perp() const {
return polarRadius();
}
double rho() const {
return polarRadius();
}
double azimuthalAngle(const PhiMapping mapping = ZERO_2PI) const {
// If this is a null vector, return zero rather than let atan2 set an error state
if (Rivet::isZero(mod2())) return 0.0;
// Calculate the arctan and return in the requested range
const double value = atan2( y(), x() );
return mapAngle(value, mapping);
}
double phi(const PhiMapping mapping = ZERO_2PI) const {
return azimuthalAngle(mapping);
}
double polarAngle() const {
// Get number beween [0,PI]
const double polarangle = atan2(polarRadius(), z());
return mapAngle0ToPi(polarangle);
}
double theta() const {
return polarAngle();
}
double pseudorapidity() const {
return -std::log(tan( 0.5 * polarAngle() ));
}
double eta() const {
return pseudorapidity();
}
public:
Vector3& operator*=(const double a) {
_vec = multiply(a, *this)._vec;
return *this;
}
Vector3& operator/=(const double a) {
_vec = multiply(1.0/a, *this)._vec;
return *this;
}
Vector3& operator+=(const Vector3& v) {
_vec = add(*this, v)._vec;
return *this;
}
Vector3& operator-=(const Vector3& v) {
_vec = subtract(*this, v)._vec;
return *this;
}
Vector3 operator-() const {
Vector3 rtn;
rtn._vec = -_vec;
return rtn;
}
};
inline double dot(const Vector3& a, const Vector3& b) {
return a.dot(b);
}
inline Vector3 cross(const Vector3& a, const Vector3& b) {
return a.cross(b);
}
inline Vector3 multiply(const double a, const Vector3& v) {
Vector3 result;
result._vec = a * v._vec;
return result;
}
inline Vector3 multiply(const Vector3& v, const double a) {
return multiply(a, v);
}
inline Vector3 operator*(const double a, const Vector3& v) {
return multiply(a, v);
}
inline Vector3 operator*(const Vector3& v, const double a) {
return multiply(a, v);
}
inline Vector3 operator/(const Vector3& v, const double a) {
return multiply(1.0/a, v);
}
inline Vector3 add(const Vector3& a, const Vector3& b) {
Vector3 result;
result._vec = a._vec + b._vec;
return result;
}
inline Vector3 subtract(const Vector3& a, const Vector3& b) {
Vector3 result;
result._vec = a._vec - b._vec;
return result;
}
inline Vector3 operator+(const Vector3& a, const Vector3& b) {
return add(a, b);
}
inline Vector3 operator-(const Vector3& a, const Vector3& b) {
return subtract(a, b);
}
// More physicsy coordinates etc.
inline double angle(const Vector3& a, const Vector3& b) {
return a.angle(b);
}
inline double polarRadius2(const Vector3& v) {
return v.polarRadius2();
}
inline double perp2(const Vector3& v) {
return v.perp2();
}
inline double rho2(const Vector3& v) {
return v.rho2();
}
inline double polarRadius(const Vector3& v) {
return v.polarRadius();
}
inline double perp(const Vector3& v) {
return v.perp();
}
inline double rho(const Vector3& v) {
return v.rho();
}
inline double azimuthalAngle(const Vector3& v, const PhiMapping mapping = ZERO_2PI) {
return v.azimuthalAngle(mapping);
}
inline double phi(const Vector3& v, const PhiMapping mapping = ZERO_2PI) {
return v.phi(mapping);
}
inline double polarAngle(const Vector3& v) {
return v.polarAngle();
}
inline double theta(const Vector3& v) {
return v.theta();
}
inline double pseudorapidity(const Vector3& v) {
return v.pseudorapidity();
}
inline double eta(const Vector3& v) {
return v.eta();
}
inline double deltaEta(const Vector3& a, const Vector3& b) {
return deltaEta(a.pseudorapidity(), b.pseudorapidity());
}
inline double deltaEta(const Vector3& v, double eta2) {
return deltaEta(v.pseudorapidity(), eta2);
}
inline double deltaEta(double eta1, const Vector3& v) {
return deltaEta(eta1, v.pseudorapidity());
}
inline double deltaPhi(const Vector3& a, const Vector3& b) {
return deltaPhi(a.azimuthalAngle(), b.azimuthalAngle());
}
inline double deltaPhi(const Vector3& v, double phi2) {
return deltaPhi(v.azimuthalAngle(), phi2);
}
inline double deltaPhi(double phi1, const Vector3& v) {
return deltaPhi(phi1, v.azimuthalAngle());
}
inline double deltaR(const Vector3& a, const Vector3& b) {
return deltaR(a.pseudorapidity(), a.azimuthalAngle(),
b.pseudorapidity(), b.azimuthalAngle());
}
inline double deltaR(const Vector3& v, double eta2, double phi2) {
return deltaR(v.pseudorapidity(), v.azimuthalAngle(), eta2, phi2);
}
inline double deltaR(double eta1, double phi1, const Vector3& v) {
return deltaR(eta1, phi1, v.pseudorapidity(), v.azimuthalAngle());
}
}
#endif
Rivet
Definition: MC_JetAnalysis.hh:9
Rivet::Vector< 3 >::isZero
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition: VectorN.hh:67
Rivet::Vector< 3 >::mod2
double mod2() const
Calculate the modulus-squared of a vector. .
Definition: VectorN.hh:76
Rivet::Vector3::rho
double rho() const
Synonym for polarRadius.
Definition: Vector3.hh:118
Rivet::Vector3::perp
double perp() const
Synonym for polarRadius.
Definition: Vector3.hh:113
Rivet::mapAngle
double mapAngle(double angle, PhiMapping mapping)
Map an angle into the enum-specified range.
Definition: MathUtils.hh:441
Rivet::Matrix3
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition: Matrix3.hh:13
Rivet::Vector3::polarAngle
double polarAngle() const
Angle subtended by the vector and the z-axis.
Definition: Vector3.hh:138
Rivet::PhiMapping
PhiMapping
Enum for range of to be mapped into.
Definition: MathHeader.hh:63
Rivet::Vector3::pseudorapidity
double pseudorapidity() const
Definition: Vector3.hh:151
Rivet::Vector3::rho2
double rho2() const
Synonym for polarRadius2.
Definition: Vector3.hh:104
Rivet::isZero
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.hh:17
Rivet::Vector
A minimal base class for -dimensional vectors.
Definition: VectorN.hh:13
Rivet::mapAngle0ToPi
double mapAngle0ToPi(double angle)
Map an angle into the range [0, PI].
Definition: MathUtils.hh:433
Rivet::Vector3::unit
Vector3 unit() const
Definition: Vector3.hh:88
Rivet::Vector3::azimuthalAngle
double azimuthalAngle(const PhiMapping mapping=ZERO_2PI) const
Angle subtended by the vector&#39;s projection in x-y and the x-axis.
Definition: Vector3.hh:123
Rivet::Vector3::theta
double theta() const
Synonym for polarAngle.
Definition: Vector3.hh:145
Rivet::Vector3::phi
double phi(const PhiMapping mapping=ZERO_2PI) const
Synonym for azimuthalAngle.
Definition: Vector3.hh:133
Rivet::Vector3
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26
Rivet::Vector3::eta
double eta() const
Synonym for pseudorapidity.
Definition: Vector3.hh:156
Rivet::fuzzyEquals
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
Rivet::Vector< 3 >::mod
double mod() const
Calculate the modulus of a vector. .
Definition: VectorN.hh:87
Rivet::Vector3::perp2
double perp2() const
Synonym for polarRadius2.
Definition: Vector3.hh:99