LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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...
 
virtual ~Vector ()
 Default dtor. 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 35 of file GeoVector.h.

Constructor & Destructor Documentation

geoalgo::Vector::Vector ( )
inline

Default ctor.

Definition at line 43 of file GeoVector.h.

Referenced by Vector().

43  : std::vector<double>()
44  {}
geoalgo::Vector::Vector ( size_t  n)
inline

Ctor to instantiate with invalid value.

Definition at line 47 of file GeoVector.h.

47  : std::vector<double>(n,kINVALID_DOUBLE)
48  {}
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 51 of file GeoVector.h.

References pt, Vector(), x, y, and z.

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

ctor w/ x & y

Definition at line 14 of file GeoVector.cxx.

References x, and y.

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

ctor w/ x, y & z

Definition at line 17 of file GeoVector.cxx.

References x, y, and z.

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

ctor w/ TVector3

Definition at line 20 of file GeoVector.cxx.

20  : Vector(3)
21  { (*this)[0] = pt[0]; (*this)[1] = pt[1]; (*this)[2] = pt[2]; }
Vector()
Default ctor.
Definition: GeoVector.h:43
TMarker * pt
Definition: egs.C:25
geoalgo::Vector::Vector ( const TLorentzVector &  pt)

ctor w/ TLorentzVector

Definition at line 23 of file GeoVector.cxx.

23  : Vector(3)
24  { (*this)[0] = pt[0]; (*this)[1] = pt[1]; (*this)[2] = pt[2]; }
Vector()
Default ctor.
Definition: GeoVector.h:43
TMarker * pt
Definition: egs.C:25
virtual geoalgo::Vector::~Vector ( )
inlinevirtual

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

References _Dot_(), and Length().

Referenced by Angle(), and ~Vector().

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

Compute a cross product w/o dimension check.

Definition at line 125 of file GeoVector.cxx.

Referenced by Cross(), and ~Vector().

126  {
127  Vector res(3);
128  res[0] = (*this)[1] * obj[2] - obj[1] * (*this)[2];
129  res[1] = (*this)[2] * obj[0] - obj[2] * (*this)[0];
130  res[2] = (*this)[0] * obj[1] - obj[0] * (*this)[1];
131  return res;
132  }
Vector()
Default ctor.
Definition: GeoVector.h:43
double geoalgo::Vector::_Dist_ ( const Vector obj) const
protected

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

Definition at line 119 of file GeoVector.cxx.

References _SqDist_().

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

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

Compute a dot product w/o dimention check.

Definition at line 122 of file GeoVector.cxx.

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

123  { 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 112 of file GeoVector.cxx.

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

113  {
114  double dist = 0;
115  for(size_t i=0; i<size(); ++i) dist += ((*this)[i] - obj[i]) * ((*this)[i] - obj[i]);
116  return dist;
117  }
double geoalgo::Vector::Angle ( const Vector obj) const

Compute a cross product of two vectors.

Definition at line 80 of file GeoVector.cxx.

References _Angle_(), and compat().

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

80  {
81  compat(obj);
82  if(size()!=2 && size()!=3)
83  throw GeoAlgoException("<<Angle>> only possible for 2 or 3-dimensional vectors!");
84  return _Angle_(obj);
85  }
double _Angle_(const Vector &obj) const
Compute the angle in degrees between 2 vectors w/o dimension check.
Definition: GeoVector.cxx:134
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:101
void geoalgo::Vector::compat ( const Vector obj) const

Dimensional check for a compatibility.

Definition at line 101 of file GeoVector.cxx.

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

101  {
102  if(size() != obj.size()) {
103  std::ostringstream msg;
104  msg << "<<" << __FUNCTION__ << ">>"
105  << " size mismatch: "
106  << size() << " != " << obj.size()
107  << std::endl;
108  throw GeoAlgoException(msg.str());
109  }
110  }
Vector geoalgo::Vector::Cross ( const Vector obj) const

Compute a dot product of two vectors.

Definition at line 60 of file GeoVector.cxx.

References _Cross_().

Referenced by ~Vector().

60  {
61 
62  if(size()!=3 || obj.size()!=3)
63 
64  throw GeoAlgoException("<<Cross>> only possible for 3-dimensional vectors!");
65 
66  return _Cross_(obj);
67  }
Vector _Cross_(const Vector &obj) const
Compute a cross product w/o dimension check.
Definition: GeoVector.cxx:125
Vector geoalgo::Vector::Dir ( ) const

Return a direction unit vector.

Definition at line 95 of file GeoVector.cxx.

References Length().

Referenced by ~Vector().

95  {
96  Vector res(*this);
97  res /= res.Length();
98  return res;
99  }
Vector()
Default ctor.
Definition: GeoVector.h:43
double geoalgo::Vector::Dist ( const Vector obj) const

Compute the distance to another vector.

Definition at line 52 of file GeoVector.cxx.

References SqDist().

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

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

Definition at line 55 of file GeoVector.cxx.

References _Dot_(), and compat().

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

55  {
56  compat(obj);
57  return _Dot_(obj);
58  }
double _Dot_(const Vector &obj) const
Compute a dot product w/o dimention check.
Definition: GeoVector.cxx:122
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:101
bool geoalgo::Vector::IsValid ( ) const

Check if point is valid.

Definition at line 26 of file GeoVector.cxx.

References geoalgo::kINVALID_DOUBLE.

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

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

Compute the length of the vector.

Definition at line 44 of file GeoVector.cxx.

References SqLength().

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

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

Normalize itself.

Definition at line 93 of file GeoVector.cxx.

References Length().

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

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

Definition at line 184 of file GeoVector.h.

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

Definition at line 144 of file GeoVector.h.

145  {
146  double res=0;
147  for(size_t i=0; i<size(); ++i) res += (*this)[i] * rhs[i];
148  return res;
149  }
Vector geoalgo::Vector::operator* ( const double &  rhs) const
inline

Definition at line 151 of file GeoVector.h.

152  {
153  Vector res((*this));
154  res *= rhs;
155  return res;
156  }
Vector()
Default ctor.
Definition: GeoVector.h:43
Vector& geoalgo::Vector::operator*= ( const double  rhs)
inline

Definition at line 114 of file GeoVector.h.

114  {
115  for(auto &v : *this) v *= rhs;
116  return *this;
117  }
Vector geoalgo::Vector::operator+ ( const Vector rhs) const
inline

Definition at line 130 of file GeoVector.h.

131  {
132  Vector res((*this));
133  res+=rhs;
134  return res;
135  }
Vector()
Default ctor.
Definition: GeoVector.h:43
Vector& geoalgo::Vector::operator+= ( const Vector rhs)
inline

Definition at line 104 of file GeoVector.h.

104  {
105  for(size_t i=0; i<size(); ++i) (*this)[i] += rhs[i];
106  return *this;
107  }
Vector geoalgo::Vector::operator- ( const Vector rhs) const
inline

Definition at line 137 of file GeoVector.h.

138  {
139  Vector res((*this));
140  res-=rhs;
141  return res;
142  }
Vector()
Default ctor.
Definition: GeoVector.h:43
Vector& geoalgo::Vector::operator-= ( const Vector rhs)
inline

Definition at line 109 of file GeoVector.h.

109  {
110  for(size_t i=0; i<size(); ++i) (*this)[i] -= rhs[i];
111  return *this;
112  }
Vector geoalgo::Vector::operator/ ( const double &  rhs) const
inline

Definition at line 158 of file GeoVector.h.

159  {
160  Vector res((*this));
161  res /= rhs;
162  return res;
163  }
Vector()
Default ctor.
Definition: GeoVector.h:43
Vector& geoalgo::Vector::operator/= ( const double  rhs)
inline

Definition at line 119 of file GeoVector.h.

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

Definition at line 165 of file GeoVector.h.

References compat().

166  {
167  compat(rhs);
168  for(size_t i=0; i<size(); ++i)
169  if((*this)[i] < rhs[i]) return true;
170  return false;
171  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:101
bool geoalgo::Vector::operator< ( const double &  rhs) const
inline

Definition at line 173 of file GeoVector.h.

References Length().

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

Definition at line 124 of file GeoVector.h.

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

Definition at line 176 of file GeoVector.h.

References compat().

177  {
178  compat(rhs);
179  for(size_t i=0; i<size(); ++i)
180  if((*this)[i] != rhs[i]) return false;
181  return true;
182  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:101
double geoalgo::Vector::Phi ( ) const

Compute the angle Phi.

Definition at line 69 of file GeoVector.cxx.

Referenced by ~Vector().

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

rotation operations

Definition at line 138 of file GeoVector.cxx.

References s.

Referenced by ~Vector().

139  {
140 
141  double c = cos(theta);
142  double s = sin(theta);
143 
144  double ynew = (*this)[1] * c - (*this)[2] * s;
145  double znew = (*this)[1] * s + (*this)[2] * c;
146 
147  (*this)[1] = ynew;
148  (*this)[2] = znew;
149 
150  return;
151  }
Float_t s
Definition: plot.C:23
void geoalgo::Vector::RotateY ( const double &  theta)

Definition at line 154 of file GeoVector.cxx.

References s.

Referenced by ~Vector().

155  {
156 
157  double c = cos(theta);
158  double s = sin(theta);
159 
160  double xnew = (*this)[0] * c + (*this)[2] * s;
161  double znew = - (*this)[0] * s + (*this)[2] * c;
162 
163  (*this)[0] = xnew;
164  (*this)[2] = znew;
165 
166  return;
167  }
Float_t s
Definition: plot.C:23
void geoalgo::Vector::RotateZ ( const double &  theta)

Definition at line 170 of file GeoVector.cxx.

References s.

Referenced by ~Vector().

171  {
172 
173  double c = cos(theta);
174  double s = sin(theta);
175 
176  double xnew = (*this)[0] * c - (*this)[1] * s;
177  double ynew = (*this)[0] * s + (*this)[1] * c;
178 
179  (*this)[0] = xnew;
180  (*this)[1] = ynew;
181 
182  return;
183  }
Float_t s
Definition: plot.C:23
double geoalgo::Vector::SqDist ( const Vector obj) const

Compute the squared distance to another vector.

Definition at line 47 of file GeoVector.cxx.

References _SqDist_(), and compat().

Referenced by Dist(), and ~Vector().

47  {
48  compat(obj);
49  return _SqDist_(obj);
50  }
void compat(const Vector &obj) const
Dimensional check for a compatibility.
Definition: GeoVector.cxx:101
double _SqDist_(const Vector &obj) const
Compute the squared-distance to another vector w/o dimension check.
Definition: GeoVector.cxx:112
double geoalgo::Vector::SqLength ( ) const

Compute the squared length of the vector.

Definition at line 38 of file GeoVector.cxx.

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

38  {
39  double res=0;
40  for(auto const &v : (*this)) res += v*v;
41  return res;
42  }
double geoalgo::Vector::Theta ( ) const

Compute the angle theta.

Definition at line 73 of file GeoVector.cxx.

Referenced by ~Vector().

73  {
74  if ( size() != 3 )
75  throw GeoAlgoException("<<Theta>> Only possible for 3-dimensional vectors!");
76 
77  return (*this).Length() == 0.0 ? 0.0 : acos( (*this)[2] / (*this).Length() );
78  }
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 87 of file GeoVector.cxx.

Referenced by ~Vector().

87  {
88  if(size()!=3)
89  throw GeoAlgoException("<<ToTLorentsVector>> only possible for 3-dimensional vectors!");
90  return TLorentzVector((*this)[0],(*this)[1],(*this)[2],0.);
91  }

Friends And Related Function Documentation

friend class GeoAlgo
friend

Definition at line 40 of file GeoVector.h.

friend class HalfLine
friend

Definition at line 37 of file GeoVector.h.

friend class LineSegment
friend

Definition at line 38 of file GeoVector.h.

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

Streamer.

Definition at line 189 of file GeoVector.h.

190  { o << "Vector ("; for(auto const& v : a) o << v << " ";
191  o << ")";
192  return o;
193  }
friend class Sphere
friend

Definition at line 39 of file GeoVector.h.

friend class Trajectory
friend

Definition at line 36 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: