LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
GeoVector.h
Go to the documentation of this file.
1 
14 #ifndef BASICTOOL_GEOVECTOR_H
15 #define BASICTOOL_GEOVECTOR_H
16 
17 #include "GeoAlgoConstants.h"
18 #include "GeoAlgoException.h"
19 #include <TVector3.h>
20 #include <TLorentzVector.h>
21 
22 namespace geoalgo {
23 
24  // Forward declaration (don't worry)
25  class Trajectory;
26  class LineSegment;
27  class HalfLine;
28  class Sphere;
29  class GeoAlgo;
30 
35  class Vector : public std::vector<double> {
36  friend class Trajectory;
37  friend class HalfLine;
38  friend class LineSegment;
39  friend class Sphere;
40  friend class GeoAlgo;
41  public:
43  Vector() : std::vector<double>()
44  {}
45 
47  Vector(size_t n) : std::vector<double>(n,kINVALID_DOUBLE)
48  {}
49 
51  Vector(const std::vector<double> &obj) : std::vector<double>(obj)
52  {}
53 
54 
55  Vector(const double x, const double y);
56  Vector(const double x, const double y, const double z);
57  Vector(const TVector3 &pt);
58  Vector(const TLorentzVector &pt);
59 
60  virtual ~Vector(){}
61 
62  void Normalize();
63 
64  bool IsValid () const;
65  double SqLength() const;
66  double Length () const;
67  Vector Dir () const;
68  double Phi () const;
69  double Theta () const;
70 
71  double SqDist(const Vector &obj) const;
72  double Dist (const Vector& obj) const;
73  double Dot (const Vector &obj) const;
74  Vector Cross (const Vector &obj) const;
75  double Angle (const Vector &obj) const;
76 
77  TLorentzVector ToTLorentzVector() const;
78 
80  void compat(const Vector& obj) const;
81 
83  void RotateX(const double& theta);
84  void RotateY(const double& theta);
85  void RotateZ(const double& theta);
86 
87  protected:
88 
90  double _SqDist_(const Vector& obj) const;
92  double _Dist_(const Vector& obj) const;
94  double _Dot_(const Vector& obj) const;
96  Vector _Cross_(const Vector& obj) const;
98  double _Angle_(const Vector& obj) const;
99 
100  public:
101  //
102  // binary/uniry operators
103  //
104  inline Vector& operator+=(const Vector& rhs) {
105  for(size_t i=0; i<size(); ++i) (*this)[i] += rhs[i];
106  return *this;
107  }
108 
109  inline Vector& operator-=(const Vector& rhs) {
110  for(size_t i=0; i<size(); ++i) (*this)[i] -= rhs[i];
111  return *this;
112  }
113 
114  inline Vector& operator*=(const double rhs) {
115  for(auto &v : *this) v *= rhs;
116  return *this;
117  }
118 
119  inline Vector& operator/=(const double rhs) {
120  for(auto &v : *this) v /= rhs;
121  return *this;
122  }
123 
124  inline Vector& operator=(const Vector& rhs) {
125  this->resize(rhs.size());
126  for(size_t i=0; i<rhs.size(); ++i) (*this)[i]=rhs[i];
127  return (*this);
128  }
129 
130  inline Vector operator+(const Vector& rhs) const
131  {
132  Vector res((*this));
133  res+=rhs;
134  return res;
135  }
136 
137  inline Vector operator-(const Vector& rhs) const
138  {
139  Vector res((*this));
140  res-=rhs;
141  return res;
142  }
143 
144  inline double operator*(const Vector& rhs) const
145  {
146  double res=0;
147  for(size_t i=0; i<size(); ++i) res += (*this)[i] * rhs[i];
148  return res;
149  }
150 
151  inline Vector operator*(const double& rhs) const
152  {
153  Vector res((*this));
154  res *= rhs;
155  return res;
156  }
157 
158  inline Vector operator/(const double& rhs) const
159  {
160  Vector res((*this));
161  res /= rhs;
162  return res;
163  }
164 
165  inline bool operator< ( const Vector& rhs ) const
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  }
172 
173  inline bool operator< ( const double& rhs) const
174  { return Length() < rhs; }
175 
176  inline bool operator== ( const Vector& rhs) const
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  }
183 
184  inline bool operator!= ( const Vector& rhs) const
185  { return !(*this == rhs); }
186 
188  #ifndef __CINT__
189  friend std::ostream& operator << (std::ostream &o, ::geoalgo::Vector const& a)
190  { o << "Vector ("; for(auto const& v : a) o << v << " ";
191  o << ")";
192  return o;
193  }
194  #endif
195 
196  };
197 
199  typedef Vector Vector_t;
200  typedef Vector Point_t;
201 }
202 
203 // Define a pointer comparison
204 #ifndef __GCCXML__
205 namespace std {
206  template <>
207  class less<geoalgo::Vector*>
208  {
209  public:
210  bool operator()( const geoalgo::Vector* lhs, const geoalgo::Vector* rhs )
211  { return (*lhs) < (*rhs); }
212  };
213 }
214 #endif
215 
216 #endif
217  // end of doxygen group
218 
Float_t x
Definition: compare.C:6
bool operator<(const Vector &rhs) const
Definition: GeoVector.h:165
bool operator!=(const Vector &rhs) const
Definition: GeoVector.h:184
Algorithm to compute various geometrical relation among geometrical objects. In particular functions ...
Definition: GeoAlgo.h:42
virtual ~Vector()
Default dtor.
Definition: GeoVector.h:60
double _Angle_(const Vector &obj) const
Compute the angle in degrees between 2 vectors w/o dimension check.
Definition: GeoVector.cxx:134
Vector & operator+=(const Vector &rhs)
Definition: GeoVector.h:104
Vector operator+(const Vector &rhs) const
Definition: GeoVector.h:130
Float_t y
Definition: compare.C:6
double _Dot_(const Vector &obj) const
Compute a dot product w/o dimention check.
Definition: GeoVector.cxx:122
Class def header for a class GeoAlgoException.
Vector()
Default ctor.
Definition: GeoVector.h:43
Double_t z
Definition: plot.C:279
Representation of a simple 3D line segment Defines a finite 3D straight line by having the start and ...
double Phi() const
Compute the angle Phi.
Definition: GeoVector.cxx:69
STL namespace.
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 Dist(const Vector &obj) const
Compute the distance to another vector.
Definition: GeoVector.cxx:52
Vector & operator*=(const double rhs)
Definition: GeoVector.h:114
Vector operator*(const double &rhs) const
Definition: GeoVector.h:151
void Normalize()
Normalize itself.
Definition: GeoVector.cxx:93
double SqLength() const
Compute the squared length of the vector.
Definition: GeoVector.cxx:38
Vector(const std::vector< double > &obj)
Default ctor w/ a bare std::vector<double>
Definition: GeoVector.h:51
Vector _Cross_(const Vector &obj) const
Compute a cross product w/o dimension check.
Definition: GeoVector.cxx:125
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Vector operator/(const double &rhs) const
Definition: GeoVector.h:158
Vector(size_t n)
Ctor to instantiate with invalid value.
Definition: GeoVector.h:47
double Length() const
Compute the length of the vector.
Definition: GeoVector.cxx:44
double Dot(const Vector &obj) const
Definition: GeoVector.cxx:55
bool IsValid() const
Check if point is valid.
Definition: GeoVector.cxx:26
Vector operator-(const Vector &rhs) const
Definition: GeoVector.h:137
TMarker * pt
Definition: egs.C:25
Vector Cross(const Vector &obj) const
Compute a dot product of two vectors.
Definition: GeoVector.cxx:60
void RotateY(const double &theta)
Definition: GeoVector.cxx:154
Vector Point_t
Definition: GeoVector.h:200
double SqDist(const Vector &obj) const
Compute the squared distance to another vector.
Definition: GeoVector.cxx:47
TLorentzVector ToTLorentzVector() const
Compute an opening angle w.r.t. the given vector.
Definition: GeoVector.cxx:87
Vector & operator/=(const double rhs)
Definition: GeoVector.h:119
double operator*(const Vector &rhs) const
Definition: GeoVector.h:144
Representation of a 3D semi-infinite line. Defines a semi-infinite 3D line by having a start point (P...
Definition: GeoHalfLine.h:26
void RotateX(const double &theta)
rotation operations
Definition: GeoVector.cxx:138
Vector Dir() const
Return a direction unit vector.
Definition: GeoVector.cxx:95
Vector & operator=(const Vector &rhs)
Definition: GeoVector.h:124
Vector Vector_t
Point has same feature as Vector.
Definition: GeoVector.h:199
Char_t n[5]
double Theta() const
Compute the angle theta.
Definition: GeoVector.cxx:73
double _Dist_(const Vector &obj) const
Compute the distance to another vector w/o dimension check.
Definition: GeoVector.cxx:119
static const double kINVALID_DOUBLE
void RotateZ(const double &theta)
Definition: GeoVector.cxx:170
bool operator==(const Vector &rhs) const
Definition: GeoVector.h:176
bool operator()(const geoalgo::Vector *lhs, const geoalgo::Vector *rhs)
Definition: GeoVector.h:210
double Angle(const Vector &obj) const
Compute a cross product of two vectors.
Definition: GeoVector.cxx:80
Vector & operator-=(const Vector &rhs)
Definition: GeoVector.h:109
friend std::ostream & operator<<(std::ostream &o,::geoalgo::Vector const &a)
Streamer.
Definition: GeoVector.h:189