1 #ifndef RIVET_MATH_VECTORN
2 #define RIVET_MATH_VECTORN
4 #include "Rivet/Math/MathHeader.hh"
5 #include "Rivet/Math/MathUtils.hh"
7 #include "Rivet/Math/eigen/vector.h"
28 Vector() { _vec.loadZero(); }
31 : _vec(other._vec) { }
33 const double&
get(
const size_t index)
const {
35 throw std::runtime_error(
"Tried to access an invalid vector index.");
54 throw std::runtime_error(
"Tried to access an invalid vector index.");
67 bool isZero(
double tolerance=1E-5)
const {
68 for (
size_t i=0; i < N; ++i) {
78 for (
size_t i = 0; i <
size(); ++i) {
79 const double element =
get(i);
80 mod2 += element*element;
88 const double norm =
mod2();
100 bool operator==(
const Vector<N>& a)
const {
101 return _vec == a._vec;
104 bool operator!=(
const Vector<N>& a)
const {
105 return _vec != a._vec;
108 bool operator<(const Vector<N>& a)
const {
109 return _vec < a._vec;
112 bool operator<=(const Vector<N>& a)
const {
113 return _vec <= a._vec;
116 bool operator>(
const Vector<N>& a)
const {
117 return _vec > a._vec;
120 bool operator>=(
const Vector<N>& a)
const {
121 return _vec >= a._vec;
126 double&
get(
const size_t index) {
128 throw std::runtime_error(
"Tried to access an invalid vector index.");
135 Eigen::Vector<double,N> _vec;
166 for (
size_t i = 0; i < v.
size(); ++i) {
167 out << (fabs(v[i]) < 1E-30 ? 0.0 : v[i]);
168 if (i < v.
size()-1) out <<
", ";
176 inline std::ostream& operator<<(std::ostream& out, const Vector<N>& v) {
190 for (
size_t i = 0; i < N; ++i) {
191 const double a = va.get(i);
192 const double b = vb.get(i);
202 return v.
isZero(tolerance);
Definition: MC_JetAnalysis.hh:9
Vector< N > operator-() const
Invert the vector.
Definition: VectorN.hh:94
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition: VectorN.hh:67
double & operator[](const size_t index)
Direct access to vector elements by index.
Definition: VectorN.hh:47
double mod() const
Calculate the modulus of a vector. .
Definition: VectorN.hh:87
Vector< N > & set(const size_t index, const double value)
Set indexed value.
Definition: VectorN.hh:52
size_t size() const
Vector dimensionality.
Definition: VectorN.hh:62
General -dimensional mathematical matrix object.
Definition: MatrixN.hh:14
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.hh:17
A minimal base class for -dimensional vectors.
Definition: VectorN.hh:13
double mod2(const Vector< N > &v)
Definition: VectorN.hh:143
const double & operator[](const size_t index) const
Direct access to vector elements by index.
Definition: VectorN.hh:42
double mod(const Vector< N > &v)
Definition: VectorN.hh:150
double mod2() const
Calculate the modulus-squared of a vector. .
Definition: VectorN.hh:76
std::string toString(const AnalysisInfo &ai)
String representation.
Definition: AnalysisInfo.cc:234
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