rivet is hosted by Hepforge, IPPP Durham
Vector< N > Class Template Reference

A minimal base class for $ N $-dimensional vectors. More...

#include <VectorN.hh>

List of all members.

Public Member Functions

 Vector ()
 Vector (const Vector< N > &other)
const double & get (const size_t index) const
double & get (const size_t index)
const double & operator[] (const size_t index) const
 Direct access to vector elements by index.
double & operator[] (const size_t index)
 Direct access to vector elements by index.
Vector< N > & set (const size_t index, const double value)
 Set indexed value.
size_t size () const
 Vector dimensionality.
bool isZero (double tolerance=1E-5) const
 Check for nullness, allowing for numerical precision.
double mod2 () const
 Calculate the modulus-squared of a vector. $ \sum_{i=1}^N x_i^2 $.
double mod () const
 Calculate the modulus of a vector. $ \sqrt{\sum_{i=1}^N x_i^2} $.
Vector< N > operator- () const
 Invert the vector.
bool operator== (const Vector< N > &a) const
bool operator!= (const Vector< N > &a) const
bool operator< (const Vector< N > &a) const
bool operator<= (const Vector< N > &a) const
bool operator> (const Vector< N > &a) const
bool operator>= (const Vector< N > &a) const

Public Attributes

Eigen::Vector< double, N > _vec
 Vector.

Friends

template<size_t M>
Vector< M > multiply (const Matrix< M > &a, const Vector< M > &b)

Detailed Description

template<size_t N>
class Rivet::Vector< N >

A minimal base class for $ N $-dimensional vectors.

Definition at line 23 of file VectorN.hh.


Constructor & Destructor Documentation

Vector ( ) [inline]

Definition at line 28 of file VectorN.hh.

{ _vec.loadZero(); }
Vector ( const Vector< N > &  other) [inline]

Definition at line 30 of file VectorN.hh.

      : _vec(other._vec) { }

Member Function Documentation

const double& get ( const size_t  index) const [inline]

Definition at line 33 of file VectorN.hh.

                                                {
      if (index >= N) {
        throw std::runtime_error("Tried to access an invalid vector index.");
      } else {
        return _vec(index);
      }
    }
double& get ( const size_t  index) [inline]

Definition at line 41 of file VectorN.hh.

                                    {
      if (index >= N) {
        throw std::runtime_error("Tried to access an invalid vector index.");
      } else {
        return _vec(index);
      }
    }
bool isZero ( double  tolerance = 1E-5) const [inline]

Check for nullness, allowing for numerical precision.

Definition at line 75 of file VectorN.hh.

                                             {
      for (size_t i=0; i < N; ++i) {
        if (! Rivet::isZero(_vec[i], tolerance) ) return false;
      }
      return true;
    }
double mod ( ) const [inline]

Calculate the modulus of a vector. $ \sqrt{\sum_{i=1}^N x_i^2} $.

Definition at line 95 of file VectorN.hh.

                       {
      const double norm = mod2();
      assert(norm >= 0);
      return sqrt(norm);
    }
double mod2 ( ) const [inline]

Calculate the modulus-squared of a vector. $ \sum_{i=1}^N x_i^2 $.

Definition at line 84 of file VectorN.hh.

                        {
      double mod2 = 0.0;
      for (size_t i = 0; i < size(); ++i) {
        const double element = get(i);
        mod2 += element*element;
      }
      return mod2;
    }
bool operator!= ( const Vector< N > &  a) const [inline]

Definition at line 112 of file VectorN.hh.

                                              {
      return _vec != a._vec;
    }
Vector<N> operator- ( ) const [inline]

Invert the vector.

Reimplemented in FourMomentum, FourVector, and Vector3.

Definition at line 102 of file VectorN.hh.

                                {
      Vector<N> rtn;
      rtn._vec = -_vec;
      return rtn;
    }
bool operator< ( const Vector< N > &  a) const [inline]

Definition at line 116 of file VectorN.hh.

                                             {
      return _vec < a._vec;
    }
bool operator<= ( const Vector< N > &  a) const [inline]

Definition at line 120 of file VectorN.hh.

                                              {
      return _vec <= a._vec;
    }
bool operator== ( const Vector< N > &  a) const [inline]

Definition at line 108 of file VectorN.hh.

                                              {
      return _vec == a._vec;
    }
bool operator> ( const Vector< N > &  a) const [inline]

Definition at line 124 of file VectorN.hh.

                                             {
      return _vec > a._vec;
    }
bool operator>= ( const Vector< N > &  a) const [inline]

Definition at line 128 of file VectorN.hh.

                                              {
      return _vec >= a._vec;
    }
const double& operator[] ( const size_t  index) const [inline]

Direct access to vector elements by index.

Definition at line 50 of file VectorN.hh.

                                                       {
      return get(index);
    }
double& operator[] ( const size_t  index) [inline]

Direct access to vector elements by index.

Definition at line 55 of file VectorN.hh.

                                           {
      return get(index);
    }
Vector<N>& set ( const size_t  index,
const double  value 
) [inline]

Set indexed value.

Definition at line 60 of file VectorN.hh.

                                                           {
      if (index >= N) {
        throw std::runtime_error("Tried to access an invalid vector index.");
      } else {
        _vec[index] = value;
      }
      return *this;
    }
size_t size ( ) const [inline]

Vector dimensionality.

Definition at line 70 of file VectorN.hh.

                        {
      return N;
    }

Friends And Related Function Documentation

Vector<M> multiply ( const Matrix< M > &  a,
const Vector< M > &  b 
) [friend]

Member Data Documentation

Eigen::Vector<double,N> _vec

Vector.

Definition at line 133 of file VectorN.hh.


The documentation for this class was generated from the following file: