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"
18 Vector<N> multiply(
const Matrix<N>& a,
const Vector<N>& b);
31 Vector() : _vec(EVector::Zero()) { }
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.");
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;
133 using EVector = RivetEigen::Matrix<double,N,1>;
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 <<
", ";
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);
General -dimensional mathematical matrix object.
Definition MatrixN.hh:30
A minimal base class for -dimensional vectors.
Definition VectorN.hh:23
double mod() const
Calculate the modulus of a vector. .
Definition VectorN.hh:95
double mod2() const
Calculate the modulus-squared of a vector. .
Definition VectorN.hh:84
RivetEigen::Matrix< double, N, 1 > EVector
Vector.
Definition VectorN.hh:133
constexpr size_t size() const
Vector dimensionality.
Definition VectorN.hh:70
Vector< N > & set(const size_t index, const double value)
Set indexed value.
Definition VectorN.hh:60
bool isZero(double tolerance=1E-5) const
Check for nullness, allowing for numerical precision.
Definition VectorN.hh:75
const double & operator[](const size_t index) const
Direct access to vector elements by index.
Definition VectorN.hh:50
double & operator[](const size_t index)
Direct access to vector elements by index.
Definition VectorN.hh:55
Vector< N > operator-() const
Invert the vector.
Definition VectorN.hh:102
Definition MC_CENT_PPB_Projections.hh:10
std::ostream & operator<<(std::ostream &os, const AnalysisInfo &ai)
Stream an AnalysisInfo as a text description.
Definition AnalysisInfo.hh:362
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:57
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:24