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.");
41 double&
get(
const size_t index) {
43 throw std::runtime_error(
"Tried to access an invalid vector index.");
60 Vector<N>&
set(
const size_t index,
const double value) {
62 throw std::runtime_error(
"Tried to access an invalid vector index.");
75 bool isZero(
double tolerance=1E-5)
const {
76 for (
size_t i=0; i < N; ++i) {
86 for (
size_t i = 0; i <
size(); ++i) {
87 const double element =
get(i);
88 mod2 += element*element;
96 const double norm =
mod2();
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;
124 bool operator>(
const Vector<N>& a)
const {
125 return _vec > a._vec;
128 bool operator>=(
const Vector<N>& a)
const {
129 return _vec >= a._vec;
133 Eigen::Vector<double,N> _vec;
149 for (
size_t i = 0; i < v.
size(); ++i) {
150 out << (fabs(v[i]) < 1E-30 ? 0.0 : v[i]);
151 if (i < v.
size()-1) out <<
", ";
159 inline std::ostream& operator<<(std::ostream& out, const Vector<N>& v) {
173 for (
size_t i = 0; i < N; ++i) {
174 const double a = va.get(i);
175 const double b = vb.get(i);
185 return v.
isZero(tolerance);
Definition: ALICE_2010_I880049.cc:13
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition: VectorN.hh:75
double mod2() const
Calculate the modulus-squared of a vector. .
Definition: VectorN.hh:84
double & operator[](const size_t index)
Direct access to vector elements by index.
Definition: VectorN.hh:55
General -dimensional mathematical matrix object.
Definition: MatrixN.hh:14
std::enable_if< std::is_arithmetic< N1 >::value &&std::is_arithmetic< N2 >::value &&(std::is_floating_point< N1 >::value||std::is_floating_point< N2 >::value), bool >::type fuzzyEquals(N1 a, N2 b, double tolerance=1e-5)
Compare two numbers for equality with a degree of fuzziness.
Definition: MathUtils.hh:45
A minimal base class for -dimensional vectors.
Definition: VectorN.hh:13
std::enable_if< std::is_floating_point< NUM >::value, bool >::type isZero(NUM val, double tolerance=1e-8)
Compare a number to zero.
Definition: MathUtils.hh:21
size_t size() const
Vector dimensionality.
Definition: VectorN.hh:70
std::string toString(const AnalysisInfo &ai)
String representation.
Definition: AnalysisInfo.cc:144
const double & operator[](const size_t index) const
Direct access to vector elements by index.
Definition: VectorN.hh:50
Vector< N > operator-() const
Invert the vector.
Definition: VectorN.hh:102
double mod() const
Calculate the modulus of a vector. .
Definition: VectorN.hh:95