Public Member Functions | Protected Member Functions | Friends | List of all members
geoalgo::Vector Class Reference

#include <GeoVector.h>

Inheritance diagram for geoalgo::Vector:

Public Member Functions

 Vector ()
 Default ctor. More...
 
 Vector (size_t n)
 Ctor to instantiate with invalid value. More...
 
 Vector (const std::vector< double > &obj)
 Default ctor w/ a bare std::vector<double> More...
 
 Vector (const double x, const double y)
 ctor w/ x & y More...
 
 Vector (const double x, const double y, const double z)
 ctor w/ x, y & z More...
 
 Vector (const TVector3 &pt)
 ctor w/ TVector3 More...
 
 Vector (const TLorentzVector &pt)
 ctor w/ TLorentzVector More...
 
void Normalize ()
 Normalize itself. More...
 
bool IsValid () const
 Check if point is valid. More...
 
double SqLength () const
 Compute the squared length of the vector. More...
 
double Length () const
 Compute the length of the vector. More...
 
Vector Dir () const
 Return a direction unit vector. More...
 
double Phi () const
 Compute the angle Phi. More...
 
double Theta () const
 Compute the angle theta. More...
 
double SqDist (const Vector &obj) const
 Compute the squared distance to another vector. More...
 
double Dist (const Vector &obj) const
 Compute the distance to another vector. More...
 
double Dot (const Vector &obj) const
 
Vector Cross (const Vector &obj) const
 Compute a dot product of two vectors. More...
 
double Angle (const Vector &obj) const
 Compute a cross product of two vectors. More...
 
TLorentzVector ToTLorentzVector () const
 Compute an opening angle w.r.t. the given vector. More...
 
void compat (const Vector &obj) const
 Dimensional check for a compatibility. More...
 
void RotateX (const double &theta)
 rotation operations More...
 
void RotateY (const double &theta)
 
void RotateZ (const double &theta)
 
Vectoroperator+= (const Vector &rhs)
 
Vectoroperator-= (const Vector &rhs)
 
Vectoroperator*= (const double rhs)
 
Vectoroperator/= (const double rhs)
 
Vectoroperator= (const Vector &rhs)
 
Vector operator+ (const Vector &rhs) const
 
Vector operator- (const Vector &rhs) const
 
double operator* (const Vector &rhs) const
 
Vector operator* (const double &rhs) const
 
Vector operator/ (const double &rhs) const
 
bool operator< (const Vector &rhs) const
 
bool operator< (const double &rhs) const
 
bool operator== (const Vector &rhs) const
 
bool operator!= (const Vector &rhs) const
 

Protected Member Functions

double _SqDist_ (const Vector &obj) const
 Compute the squared-distance to another vector w/o dimension check. More...
 
double _Dist_ (const Vector &obj) const
 Compute the distance to another vector w/o dimension check. More...
 
double _Dot_ (const Vector &obj) const
 Compute a dot product w/o dimention check. More...
 
Vector _Cross_ (const Vector &obj) const
 Compute a cross product w/o dimension check. More...
 
double _Angle_ (const Vector &obj) const
 Compute the angle in degrees between 2 vectors w/o dimension check. More...
 

Friends

class Trajectory
 
class HalfLine
 
class LineSegment
 
class Sphere
 
class GeoAlgo
 
std::ostream & operator<< (std::ostream &o,::geoalgo::Vector const &a)
 Streamer. More...
 

Detailed Description

This class represents an n-dimensional vector

Definition at line 33 of file GeoVector.h.

Constructor & Destructor Documentation

geoalgo::Vector::Vector ( )
inline

Default ctor.

Definition at line 41 of file GeoVector.h.

41  : std::vector<double>()
42  {}
geoalgo::Vector::Vector ( size_t  n)
inline

Ctor to instantiate with invalid value.

Definition at line 45 of file GeoVector.h.

45  : std::vector<double>(n,kINVALID_DOUBLE)
46  {}
std::void_t< T > n
static const double kINVALID_DOUBLE
geoalgo::Vector::Vector ( const std::vector< double > &  obj)
inline

Default ctor w/ a bare std::vector<double>

Definition at line 49 of file GeoVector.h.

49  : std::vector<double>(obj)
50  {}
geoalgo::Vector::Vector ( const double  x,
const double  y 
)

ctor w/ x & y

Definition at line 10 of file GeoVector.cxx.

10  : Vector(2)
11  { (*this)[0] = x; (*this)[1] = y; }
Vector()
Default ctor.
Definition: GeoVector.h:41
list x
Definition: train.py:276
geoalgo::Vector::Vector ( const double  x,
const double  y,
const double  z 
)

ctor w/ x, y & z

Definition at line 13 of file GeoVector.cxx.

13  : Vector(3)
14  { (*this)[0] = x; (*this)[1] = y; (*this)[2] = z; }
Vector()
Default ctor.
Definition: GeoVector.h:41
list x
Definition: train.py:276
geoalgo::Vector::Vector ( const TVector3 &  pt)

ctor w/ TVector3

Definition at line 16 of file GeoVector.cxx.

16  : Vector(3)
17  { (*this)[0] = pt[0]; (*this)[1] = pt[1]; (*this)[2] = pt[2]; }
Vector()
Default ctor.
Definition: GeoVector.h:41
geoalgo::Vector::Vector ( const TLorentzVector &  pt)

ctor w/ TLorentzVector

Definition at line 19 of file GeoVector.cxx.

19  : Vector(3)
20  { (*this)[0] = pt[0]; (*this)[1] = pt[1]; (*this)[2] = pt[2]; }
Vector()
Default ctor.
Definition: GeoVector.h:41

Member Function Documentation

double geoalgo::Vector::_Angle_ ( const Vector obj) const
protected

Compute the angle in degrees between 2 vectors w/o dimension check.

Definition at line 130 of file GeoVector.cxx.

131  { return acos( _Dot_(obj) / Length() / obj.Length() ); }
double _Dot_(const Vector &obj) const
Compute a dot product w/o dimention check.
Definition: GeoVector.cxx:118
double Length() const
Compute the length of the vector.
Definition: GeoVector.cxx:40
Vector geoalgo::Vector::_Cross_ ( const Vector obj) const
protected

Compute a cross product w/o dimension check.

Definition at line 121 of file GeoVector.cxx.

122  {
123  Vector res(3);
124  res[0] = (*this)[1] * obj[2] - obj[1] * (*this)[2];
125  res[1] = (*this)[2] * obj[0] - obj[2] * (*this)[0];
126  res[2] = (*this)[0] * obj[1] - obj[0] * (*this)[1];
127  return res;
128  }
double geoalgo::Vector::_Dist_ ( const Vector obj) const
protected

Compute the distance to another vector w/o dimension check.

Definition at line 115 of file GeoVector.cxx.

116  { return sqrt(_SqDist_(obj)); }
double _SqDist_(const Vector &obj) const
Compute the squared-distance to another vector w/o dimension check.
Definition: GeoVector.cxx:108
double geoalgo::Vector::_Dot_ ( const Vector obj) const
protected

Compute a dot product w/o dimention check.

Definition at line 118 of file GeoVector.cxx.

119  { return (*this) * obj; }
double geoalgo::Vector::_SqDist_ ( const Vector obj) const
protected

Compute the squared-distance to another vector w/o dimension check.

Definition at line 108 of file GeoVector.cxx.

109  {
110  double dist = 0;
111  for(size_t i=0; i<size(); ++i) dist += ((*this)[i] - obj[i]) * ((*this)[i] - obj[i]);
112  return dist;
113  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
double geoalgo::Vector::Angle ( const Vector obj) const

Compute a cross product of two vectors.

Definition at line 76 of file GeoVector.cxx.

76  {
77  compat(obj);
78  if(size()!=2 && size()!=3)
79  throw GeoAlgoException("<<Angle>> only possible for 2 or 3-dimensional vectors!");
80  return _Angle_(obj);
81  }
double _Angle_(const Vector &obj) const
Compute the angle in degrees between 2 vectors w/o dimension check.
Definition: GeoVector.cxx:130
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:97
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
void geoalgo::Vector::compat ( const Vector obj) const

Dimensional check for a compatibility.

Definition at line 97 of file GeoVector.cxx.

97  {
98  if(size() != obj.size()) {
99  std::ostringstream msg;
100  msg << "<<" << __FUNCTION__ << ">>"
101  << " size mismatch: "
102  << size() << " != " << obj.size()
103  << std::endl;
104  throw GeoAlgoException(msg.str());
105  }
106  }
void msg(const char *fmt,...)
Definition: message.cpp:107
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
size_t size
Definition: lodepng.cpp:55
QTextStream & endl(QTextStream &s)
Vector geoalgo::Vector::Cross ( const Vector obj) const

Compute a dot product of two vectors.

Definition at line 56 of file GeoVector.cxx.

56  {
57 
58  if(size()!=3 || obj.size()!=3)
59 
60  throw GeoAlgoException("<<Cross>> only possible for 3-dimensional vectors!");
61 
62  return _Cross_(obj);
63  }
Vector _Cross_(const Vector &obj) const
Compute a cross product w/o dimension check.
Definition: GeoVector.cxx:121
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
size_t size
Definition: lodepng.cpp:55
Vector geoalgo::Vector::Dir ( ) const

Return a direction unit vector.

Definition at line 91 of file GeoVector.cxx.

91  {
92  Vector res(*this);
93  res /= res.Length();
94  return res;
95  }
double geoalgo::Vector::Dist ( const Vector obj) const

Compute the distance to another vector.

Definition at line 48 of file GeoVector.cxx.

49  { return sqrt(SqDist(obj)); }
double SqDist(const Vector &obj) const
Compute the squared distance to another vector.
Definition: GeoVector.cxx:43
double geoalgo::Vector::Dot ( const Vector obj) const

Definition at line 51 of file GeoVector.cxx.

51  {
52  compat(obj);
53  return _Dot_(obj);
54  }
double _Dot_(const Vector &obj) const
Compute a dot product w/o dimention check.
Definition: GeoVector.cxx:118
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:97
bool geoalgo::Vector::IsValid ( ) const

Check if point is valid.

Definition at line 22 of file GeoVector.cxx.

22  {
23 
24  for (auto const &v : (*this)){
25  // if any point is different from kINVALID_DOUBLE
26  // then the point is valid
27  if (v != kINVALID_DOUBLE)
28  return true;
29  }
30 
31  return false;
32  }
static const double kINVALID_DOUBLE
double geoalgo::Vector::Length ( ) const

Compute the length of the vector.

Definition at line 40 of file GeoVector.cxx.

41  { return sqrt(SqLength()); }
double SqLength() const
Compute the squared length of the vector.
Definition: GeoVector.cxx:34
void geoalgo::Vector::Normalize ( )

Normalize itself.

Definition at line 89 of file GeoVector.cxx.

89 { (*this) /= this->Length(); }
double Length() const
Compute the length of the vector.
Definition: GeoVector.cxx:40
bool geoalgo::Vector::operator!= ( const Vector rhs) const
inline

Definition at line 180 of file GeoVector.h.

181  { return !(*this == rhs); }
double geoalgo::Vector::operator* ( const Vector rhs) const
inline

Definition at line 140 of file GeoVector.h.

141  {
142  double res=0;
143  for(size_t i=0; i<size(); ++i) res += (*this)[i] * rhs[i];
144  return res;
145  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Vector geoalgo::Vector::operator* ( const double &  rhs) const
inline

Definition at line 147 of file GeoVector.h.

148  {
149  Vector res((*this));
150  res *= rhs;
151  return res;
152  }
Vector& geoalgo::Vector::operator*= ( const double  rhs)
inline

Definition at line 110 of file GeoVector.h.

110  {
111  for(auto &v : *this) v *= rhs;
112  return *this;
113  }
Vector geoalgo::Vector::operator+ ( const Vector rhs) const
inline

Definition at line 126 of file GeoVector.h.

127  {
128  Vector res((*this));
129  res+=rhs;
130  return res;
131  }
Vector& geoalgo::Vector::operator+= ( const Vector rhs)
inline

Definition at line 100 of file GeoVector.h.

100  {
101  for(size_t i=0; i<size(); ++i) (*this)[i] += rhs[i];
102  return *this;
103  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Vector geoalgo::Vector::operator- ( const Vector rhs) const
inline

Definition at line 133 of file GeoVector.h.

134  {
135  Vector res((*this));
136  res-=rhs;
137  return res;
138  }
Vector& geoalgo::Vector::operator-= ( const Vector rhs)
inline

Definition at line 105 of file GeoVector.h.

105  {
106  for(size_t i=0; i<size(); ++i) (*this)[i] -= rhs[i];
107  return *this;
108  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Vector geoalgo::Vector::operator/ ( const double &  rhs) const
inline

Definition at line 154 of file GeoVector.h.

155  {
156  Vector res((*this));
157  res /= rhs;
158  return res;
159  }
Vector& geoalgo::Vector::operator/= ( const double  rhs)
inline

Definition at line 115 of file GeoVector.h.

115  {
116  for(auto &v : *this) v /= rhs;
117  return *this;
118  }
bool geoalgo::Vector::operator< ( const Vector rhs) const
inline

Definition at line 161 of file GeoVector.h.

162  {
163  compat(rhs);
164  for(size_t i=0; i<size(); ++i)
165  if((*this)[i] < rhs[i]) return true;
166  return false;
167  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:97
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
bool geoalgo::Vector::operator< ( const double &  rhs) const
inline

Definition at line 169 of file GeoVector.h.

170  { return Length() < rhs; }
double Length() const
Compute the length of the vector.
Definition: GeoVector.cxx:40
Vector& geoalgo::Vector::operator= ( const Vector rhs)
inline

Definition at line 120 of file GeoVector.h.

120  {
121  this->resize(rhs.size());
122  for(size_t i=0; i<rhs.size(); ++i) (*this)[i]=rhs[i];
123  return (*this);
124  }
void resize(Vector< T > &vec1, Index n1, const V &val)
size_t size
Definition: lodepng.cpp:55
bool geoalgo::Vector::operator== ( const Vector rhs) const
inline

Definition at line 172 of file GeoVector.h.

173  {
174  compat(rhs);
175  for(size_t i=0; i<size(); ++i)
176  if((*this)[i] != rhs[i]) return false;
177  return true;
178  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:97
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
double geoalgo::Vector::Phi ( ) const

Compute the angle Phi.

Definition at line 65 of file GeoVector.cxx.

65  {
66  return (*this)[0] == 0.0 && (*this)[1] == 0.0 ? 0.0 : atan2((*this)[1],(*this)[0]);
67  }
void geoalgo::Vector::RotateX ( const double &  theta)

rotation operations

Definition at line 134 of file GeoVector.cxx.

135  {
136 
137  double c = cos(theta);
138  double s = sin(theta);
139 
140  double ynew = (*this)[1] * c - (*this)[2] * s;
141  double znew = (*this)[1] * s + (*this)[2] * c;
142 
143  (*this)[1] = ynew;
144  (*this)[2] = znew;
145 
146  return;
147  }
static QCString * s
Definition: config.cpp:1042
void geoalgo::Vector::RotateY ( const double &  theta)

Definition at line 150 of file GeoVector.cxx.

151  {
152 
153  double c = cos(theta);
154  double s = sin(theta);
155 
156  double xnew = (*this)[0] * c + (*this)[2] * s;
157  double znew = - (*this)[0] * s + (*this)[2] * c;
158 
159  (*this)[0] = xnew;
160  (*this)[2] = znew;
161 
162  return;
163  }
static QCString * s
Definition: config.cpp:1042
void geoalgo::Vector::RotateZ ( const double &  theta)

Definition at line 166 of file GeoVector.cxx.

167  {
168 
169  double c = cos(theta);
170  double s = sin(theta);
171 
172  double xnew = (*this)[0] * c - (*this)[1] * s;
173  double ynew = (*this)[0] * s + (*this)[1] * c;
174 
175  (*this)[0] = xnew;
176  (*this)[1] = ynew;
177 
178  return;
179  }
static QCString * s
Definition: config.cpp:1042
double geoalgo::Vector::SqDist ( const Vector obj) const

Compute the squared distance to another vector.

Definition at line 43 of file GeoVector.cxx.

43  {
44  compat(obj);
45  return _SqDist_(obj);
46  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:97
double _SqDist_(const Vector &obj) const
Compute the squared-distance to another vector w/o dimension check.
Definition: GeoVector.cxx:108
double geoalgo::Vector::SqLength ( ) const

Compute the squared length of the vector.

Definition at line 34 of file GeoVector.cxx.

34  {
35  double res=0;
36  for(auto const &v : (*this)) res += v*v;
37  return res;
38  }
double geoalgo::Vector::Theta ( ) const

Compute the angle theta.

Definition at line 69 of file GeoVector.cxx.

69  {
70  if ( size() != 3 )
71  throw GeoAlgoException("<<Theta>> Only possible for 3-dimensional vectors!");
72 
73  return (*this).Length() == 0.0 ? 0.0 : acos( (*this)[2] / (*this).Length() );
74  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
TLorentzVector geoalgo::Vector::ToTLorentzVector ( ) const

Compute an opening angle w.r.t. the given vector.

Convert geovector to TLorentzVector (with 4th element set equal to 0)

Definition at line 83 of file GeoVector.cxx.

83  {
84  if(size()!=3)
85  throw GeoAlgoException("<<ToTLorentsVector>> only possible for 3-dimensional vectors!");
86  return TLorentzVector((*this)[0],(*this)[1],(*this)[2],0.);
87  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92

Friends And Related Function Documentation

friend class GeoAlgo
friend

Definition at line 38 of file GeoVector.h.

friend class HalfLine
friend

Definition at line 35 of file GeoVector.h.

friend class LineSegment
friend

Definition at line 36 of file GeoVector.h.

std::ostream& operator<< ( std::ostream &  o,
::geoalgo::Vector const &  a 
)
friend

Streamer.

Definition at line 185 of file GeoVector.h.

186  { o << "Vector ("; for(auto const& v : a) o << v << " ";
187  o << ")";
188  return o;
189  }
const double a
friend class Sphere
friend

Definition at line 37 of file GeoVector.h.

friend class Trajectory
friend

Definition at line 34 of file GeoVector.h.


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