LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
 

Public Attributes

elements
 STL member. More...
 

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 42 of file GeoVector.h.

Referenced by Vector().

42 : std::vector<double>() {}
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) {}
Char_t n[5]
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 48 of file GeoVector.h.

References _Angle_(), _Cross_(), _Dist_(), _Dot_(), _SqDist_(), Angle(), compat(), Cross(), Dir(), Dist(), Dot(), IsValid(), Length(), Normalize(), Phi(), pt, RotateX(), RotateY(), RotateZ(), SqDist(), SqLength(), Theta(), ToTLorentzVector(), Vector(), x, y, and z.

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

ctor w/ x & y

Definition at line 10 of file GeoVector.cxx.

References x, and y.

10  : Vector(2)
11  {
12  (*this)[0] = x;
13  (*this)[1] = y;
14  }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Vector()
Default ctor.
Definition: GeoVector.h:42
geoalgo::Vector::Vector ( const double  x,
const double  y,
const double  z 
)

ctor w/ x, y & z

Definition at line 16 of file GeoVector.cxx.

References x, y, and z.

16  : Vector(3)
17  {
18  (*this)[0] = x;
19  (*this)[1] = y;
20  (*this)[2] = z;
21  }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Vector()
Default ctor.
Definition: GeoVector.h:42
Double_t z
Definition: plot.C:276
geoalgo::Vector::Vector ( const TVector3 &  pt)

ctor w/ TVector3

Definition at line 23 of file GeoVector.cxx.

23  : Vector(3)
24  {
25  (*this)[0] = pt[0];
26  (*this)[1] = pt[1];
27  (*this)[2] = pt[2];
28  }
Vector()
Default ctor.
Definition: GeoVector.h:42
TMarker * pt
Definition: egs.C:25
geoalgo::Vector::Vector ( const TLorentzVector &  pt)

ctor w/ TLorentzVector

Definition at line 30 of file GeoVector.cxx.

30  : Vector(3)
31  {
32  (*this)[0] = pt[0];
33  (*this)[1] = pt[1];
34  (*this)[2] = pt[2];
35  }
Vector()
Default ctor.
Definition: GeoVector.h:42
TMarker * pt
Definition: egs.C:25

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 165 of file GeoVector.cxx.

References _Dot_(), and Length().

Referenced by Angle(), and Vector().

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

Compute a cross product w/o dimension check.

Definition at line 156 of file GeoVector.cxx.

Referenced by Cross(), and Vector().

157  {
158  Vector res(3);
159  res[0] = (*this)[1] * obj[2] - obj[1] * (*this)[2];
160  res[1] = (*this)[2] * obj[0] - obj[2] * (*this)[0];
161  res[2] = (*this)[0] * obj[1] - obj[0] * (*this)[1];
162  return res;
163  }
Vector()
Default ctor.
Definition: GeoVector.h:42
double geoalgo::Vector::_Dist_ ( const Vector obj) const
protected

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

Definition at line 146 of file GeoVector.cxx.

References _SqDist_().

Referenced by geoalgo::Sphere::Contain(), and Vector().

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

Compute a dot product w/o dimention check.

Definition at line 151 of file GeoVector.cxx.

Referenced by _Angle_(), Dot(), and Vector().

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

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

Definition at line 138 of file GeoVector.cxx.

References larg4::dist(), and util::size().

Referenced by _Dist_(), geoalgo::GeoAlgo::_SqDist_(), geoalgo::GeoAlgo::Intersection(), SqDist(), and Vector().

139  {
140  double dist = 0;
141  for (size_t i = 0; i < size(); ++i)
142  dist += ((*this)[i] - obj[i]) * ((*this)[i] - obj[i]);
143  return dist;
144  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
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 101 of file GeoVector.cxx.

References _Angle_(), compat(), and util::size().

Referenced by geoalgo::Cylinder::Contain(), and Vector().

102  {
103  compat(obj);
104  if (size() != 2 && size() != 3)
105  throw GeoAlgoException("<<Angle>> only possible for 2 or 3-dimensional vectors!");
106  return _Angle_(obj);
107  }
double _Angle_(const Vector &obj) const
Compute the angle in degrees between 2 vectors w/o dimension check.
Definition: GeoVector.cxx:165
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:128
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
void geoalgo::Vector::compat ( const Vector obj) const

Dimensional check for a compatibility.

Definition at line 128 of file GeoVector.cxx.

References util::size().

Referenced by Angle(), geoalgo::GeoAlgo::ClosestPt(), geoalgo::GeoAlgo::commonOrigin(), geoalgo::Sphere::Contain(), Dot(), operator<(), operator==(), SqDist(), geoalgo::GeoAlgo::SqDist(), and Vector().

129  {
130  if (size() != obj.size()) {
131  std::ostringstream msg;
132  msg << "<<" << __FUNCTION__ << ">>"
133  << " size mismatch: " << size() << " != " << obj.size() << std::endl;
134  throw GeoAlgoException(msg.str());
135  }
136  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Vector geoalgo::Vector::Cross ( const Vector obj) const

Compute a dot product of two vectors.

Definition at line 79 of file GeoVector.cxx.

References _Cross_(), and util::size().

Referenced by Vector().

80  {
81 
82  if (size() != 3 || obj.size() != 3)
83 
84  throw GeoAlgoException("<<Cross>> only possible for 3-dimensional vectors!");
85 
86  return _Cross_(obj);
87  }
Vector _Cross_(const Vector &obj) const
Compute a cross product w/o dimension check.
Definition: GeoVector.cxx:156
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Vector geoalgo::Vector::Dir ( ) const

Return a direction unit vector.

Definition at line 121 of file GeoVector.cxx.

References Length().

Referenced by Vector().

122  {
123  Vector res(*this);
124  res /= res.Length();
125  return res;
126  }
Vector()
Default ctor.
Definition: GeoVector.h:42
double geoalgo::Vector::Dist ( const Vector obj) const

Compute the distance to another vector.

Definition at line 68 of file GeoVector.cxx.

References SqDist().

Referenced by geoalgo::Sphere::Sphere(), and Vector().

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

Definition at line 73 of file GeoVector.cxx.

References _Dot_(), and compat().

Referenced by geoalgo::GeoAlgo::_commonOrigin_(), geoalgo::Sphere::Sphere(), and Vector().

74  {
75  compat(obj);
76  return _Dot_(obj);
77  }
double _Dot_(const Vector &obj) const
Compute a dot product w/o dimention check.
Definition: GeoVector.cxx:151
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:128
bool geoalgo::Vector::IsValid ( ) const

Check if point is valid.

Definition at line 37 of file GeoVector.cxx.

References geoalgo::kINVALID_DOUBLE.

Referenced by geoalgo::GeoAlgo::Intersection(), and Vector().

38  {
39 
40  for (auto const& v : (*this)) {
41  // if any point is different from kINVALID_DOUBLE
42  // then the point is valid
43  if (v != kINVALID_DOUBLE) return true;
44  }
45 
46  return false;
47  }
static const double kINVALID_DOUBLE
double geoalgo::Vector::Length ( ) const

Compute the length of the vector.

Definition at line 57 of file GeoVector.cxx.

References SqLength().

Referenced by _Angle_(), geoalgo::GeoAlgo::_ClosestPt_(), Dir(), Normalize(), geoalgo::HalfLine::Normalize(), operator<(), geoalgo::Sphere::Sphere(), and Vector().

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

Normalize itself.

Definition at line 116 of file GeoVector.cxx.

References Length().

Referenced by geoalgo::GeoAlgo::_commonOrigin_(), geoalgo::GeoAlgo::_RemainingPoints_(), and Vector().

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

Definition at line 187 of file GeoVector.h.

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

Definition at line 147 of file GeoVector.h.

References util::size().

148  {
149  double res = 0;
150  for (size_t i = 0; i < size(); ++i)
151  res += (*this)[i] * rhs[i];
152  return res;
153  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Vector geoalgo::Vector::operator* ( const double &  rhs) const
inline

Definition at line 155 of file GeoVector.h.

156  {
157  Vector res((*this));
158  res *= rhs;
159  return res;
160  }
Vector()
Default ctor.
Definition: GeoVector.h:42
Vector& geoalgo::Vector::operator*= ( const double  rhs)
inline

Definition at line 111 of file GeoVector.h.

112  {
113  for (auto& v : *this)
114  v *= rhs;
115  return *this;
116  }
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()
Default ctor.
Definition: GeoVector.h:42
Vector& geoalgo::Vector::operator+= ( const Vector rhs)
inline

Definition at line 97 of file GeoVector.h.

References util::size().

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

Definition at line 140 of file GeoVector.h.

141  {
142  Vector res((*this));
143  res -= rhs;
144  return res;
145  }
Vector()
Default ctor.
Definition: GeoVector.h:42
Vector& geoalgo::Vector::operator-= ( const Vector rhs)
inline

Definition at line 104 of file GeoVector.h.

References util::size().

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

Definition at line 162 of file GeoVector.h.

163  {
164  Vector res((*this));
165  res /= rhs;
166  return res;
167  }
Vector()
Default ctor.
Definition: GeoVector.h:42
Vector& geoalgo::Vector::operator/= ( const double  rhs)
inline

Definition at line 118 of file GeoVector.h.

119  {
120  for (auto& v : *this)
121  v /= rhs;
122  return *this;
123  }
bool geoalgo::Vector::operator< ( const Vector rhs) const
inline

Definition at line 169 of file GeoVector.h.

References compat(), and util::size().

170  {
171  compat(rhs);
172  for (size_t i = 0; i < size(); ++i)
173  if ((*this)[i] < rhs[i]) return true;
174  return false;
175  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:128
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
bool geoalgo::Vector::operator< ( const double &  rhs) const
inline

Definition at line 177 of file GeoVector.h.

References Length().

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

Definition at line 125 of file GeoVector.h.

126  {
127  this->resize(rhs.size());
128  for (size_t i = 0; i < rhs.size(); ++i)
129  (*this)[i] = rhs[i];
130  return (*this);
131  }
bool geoalgo::Vector::operator== ( const Vector rhs) const
inline

Definition at line 179 of file GeoVector.h.

References compat(), and util::size().

180  {
181  compat(rhs);
182  for (size_t i = 0; i < size(); ++i)
183  if ((*this)[i] != rhs[i]) return false;
184  return true;
185  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:128
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
double geoalgo::Vector::Phi ( ) const

Compute the angle Phi.

Definition at line 89 of file GeoVector.cxx.

Referenced by Vector().

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

rotation operations

Definition at line 170 of file GeoVector.cxx.

Referenced by Vector().

171  {
172 
173  double c = cos(theta);
174  double s = sin(theta);
175 
176  double ynew = (*this)[1] * c - (*this)[2] * s;
177  double znew = (*this)[1] * s + (*this)[2] * c;
178 
179  (*this)[1] = ynew;
180  (*this)[2] = znew;
181 
182  return;
183  }
void geoalgo::Vector::RotateY ( const double &  theta)

Definition at line 185 of file GeoVector.cxx.

Referenced by Vector().

186  {
187 
188  double c = cos(theta);
189  double s = sin(theta);
190 
191  double xnew = (*this)[0] * c + (*this)[2] * s;
192  double znew = -(*this)[0] * s + (*this)[2] * c;
193 
194  (*this)[0] = xnew;
195  (*this)[2] = znew;
196 
197  return;
198  }
void geoalgo::Vector::RotateZ ( const double &  theta)

Definition at line 200 of file GeoVector.cxx.

Referenced by Vector().

201  {
202 
203  double c = cos(theta);
204  double s = sin(theta);
205 
206  double xnew = (*this)[0] * c - (*this)[1] * s;
207  double ynew = (*this)[0] * s + (*this)[1] * c;
208 
209  (*this)[0] = xnew;
210  (*this)[1] = ynew;
211 
212  return;
213  }
double geoalgo::Vector::SqDist ( const Vector obj) const

Compute the squared distance to another vector.

Definition at line 62 of file GeoVector.cxx.

References _SqDist_(), and compat().

Referenced by Dist(), and Vector().

63  {
64  compat(obj);
65  return _SqDist_(obj);
66  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:128
double _SqDist_(const Vector &obj) const
Compute the squared-distance to another vector w/o dimension check.
Definition: GeoVector.cxx:138
double geoalgo::Vector::SqLength ( ) const

Compute the squared length of the vector.

Definition at line 49 of file GeoVector.cxx.

Referenced by geoalgo::GeoAlgo::_ClosestPt_(), geoalgo::GeoAlgo::_SqDist_(), Length(), and Vector().

50  {
51  double res = 0;
52  for (auto const& v : (*this))
53  res += v * v;
54  return res;
55  }
double geoalgo::Vector::Theta ( ) const

Compute the angle theta.

Definition at line 94 of file GeoVector.cxx.

References util::size().

Referenced by Vector().

95  {
96  if (size() != 3) throw GeoAlgoException("<<Theta>> Only possible for 3-dimensional vectors!");
97 
98  return (*this).Length() == 0.0 ? 0.0 : acos((*this)[2] / (*this).Length());
99  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
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 109 of file GeoVector.cxx.

References util::size().

Referenced by Vector().

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

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 191 of file GeoVector.h.

192  {
193  o << "Vector (";
194  for (auto const& v : a)
195  o << v << " ";
196  o << ")";
197  return o;
198  }
friend class Sphere
friend

Definition at line 37 of file GeoVector.h.

friend class Trajectory
friend

Definition at line 34 of file GeoVector.h.

Member Data Documentation

T std::vector< T >::elements
inherited

STL member.


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