1 #ifndef RIVET_MATH_VECTORN 2 #define RIVET_MATH_VECTORN 4 #include "Rivet/Math/MathConstants.hh" 5 #include "Rivet/Math/MathUtils.hh" 7 #include "Rivet/Math/eigen3/Dense" 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.");
70 constexpr
size_t size()
const {
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;
148 std::ostringstream out;
150 for (
size_t i = 0; i < v.
size(); ++i) {
151 out << (fabs(v[i]) < 1E-30 ? 0.0 : v[i]);
152 if (i < v.
size()-1) out <<
", ";
160 inline std::ostream& operator<<(std::ostream& out, const Vector<N>& v) {
174 for (
size_t i = 0; i < N; ++i) {
175 const double a = va.get(i);
176 const double b = vb.get(i);
186 return v.
isZero(tolerance);
Definition: MC_Cent_pPb.hh:10
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
constexpr size_t size() const
Vector dimensionality.
Definition: VectorN.hh:70
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:54
A minimal base class for -dimensional vectors.
Definition: VectorN.hh:13
Eigen::Matrix< double, N, 1 > EVector
Vector.
Definition: VectorN.hh:133
std::string toString(const AnalysisInfo &ai)
String representation.
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
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