All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
larcorealg/larcorealg/GeoAlgo/GeoVector.h
Go to the documentation of this file.
1 /**
2  * \file GeoVector.h
3  *
4  * \ingroup GeoAlgo
5  *
6  * \brief Class def header for a class Point and Vector
7  *
8  * @author kazuhiro
9  */
10 
11 /** \addtogroup GeoAlgo
12 
13  @{*/
14 #ifndef BASICTOOL_GEOVECTOR_H
15 #define BASICTOOL_GEOVECTOR_H
16 
18 
19 #include "TVector3.h"
20 #include "TLorentzVector.h"
21 
22 #include <stddef.h>
23 #include <functional>
24 #include <ostream>
25 #include <vector>
26 
27 namespace geoalgo {
28 
29  /**
30  \class Vector
31  This class represents an n-dimensional vector
32  */
33  class Vector : public std::vector<double> {
34  friend class Trajectory;
35  friend class HalfLine;
36  friend class LineSegment;
37  friend class Sphere;
38  friend class GeoAlgo;
39  public:
40  /// Default ctor
41  Vector() : std::vector<double>()
42  {}
43 
44  /// Ctor to instantiate with invalid value
45  Vector(size_t n) : std::vector<double>(n,kINVALID_DOUBLE)
46  {}
47 
48  /// Default ctor w/ a bare std::vector<double>
49  Vector(const std::vector<double> &obj) : std::vector<double>(obj)
50  {}
51 
52 
53  Vector(const double x, const double y); ///< ctor w/ x & y
54  Vector(const double x, const double y, const double z); ///< ctor w/ x, y & z
55  Vector(const TVector3 &pt); ///< ctor w/ TVector3
56  Vector(const TLorentzVector &pt); ///< ctor w/ TLorentzVector
57 
58  void Normalize(); ///< Normalize itself
59 
60  bool IsValid () const; ///< Check if point is valid
61  double SqLength() const; ///< Compute the squared length of the vector
62  double Length () const; ///< Compute the length of the vector
63  Vector Dir () const; ///< Return a direction unit vector
64  double Phi () const; ///< Compute the angle Phi
65  double Theta () const; ///< Compute the angle theta
66 
67  double SqDist(const Vector &obj) const; ///< Compute the squared distance to another vector
68  double Dist (const Vector& obj) const; ///< Compute the distance to another vector
69  double Dot (const Vector &obj) const; /// Compute a dot product of two vectors
70  Vector Cross (const Vector &obj) const; /// Compute a cross product of two vectors
71  double Angle (const Vector &obj) const; /// Compute an opening angle w.r.t. the given vector
72 
73  TLorentzVector ToTLorentzVector() const; ///< Convert geovector to TLorentzVector (with 4th element set equal to 0)
74 
75  /// Dimensional check for a compatibility
76  void compat(const Vector& obj) const;
77 
78  /// rotation operations
79  void RotateX(const double& theta);
80  void RotateY(const double& theta);
81  void RotateZ(const double& theta);
82 
83  protected:
84 
85  /// Compute the squared-distance to another vector w/o dimension check
86  double _SqDist_(const Vector& obj) const;
87  /// Compute the distance to another vector w/o dimension check
88  double _Dist_(const Vector& obj) const;
89  /// Compute a dot product w/o dimention check.
90  double _Dot_(const Vector& obj) const;
91  /// Compute a cross product w/o dimension check.
92  Vector _Cross_(const Vector& obj) const;
93  /// Compute the angle in degrees between 2 vectors w/o dimension check.
94  double _Angle_(const Vector& obj) const;
95 
96  public:
97  //
98  // binary/uniry operators
99  //
100  inline Vector& operator+=(const Vector& rhs) {
101  for(size_t i=0; i<size(); ++i) (*this)[i] += rhs[i];
102  return *this;
103  }
104 
105  inline Vector& operator-=(const Vector& rhs) {
106  for(size_t i=0; i<size(); ++i) (*this)[i] -= rhs[i];
107  return *this;
108  }
109 
110  inline Vector& operator*=(const double rhs) {
111  for(auto &v : *this) v *= rhs;
112  return *this;
113  }
114 
115  inline Vector& operator/=(const double rhs) {
116  for(auto &v : *this) v /= rhs;
117  return *this;
118  }
119 
120  inline Vector& operator=(const Vector& rhs) {
121  this->resize(rhs.size());
122  for(size_t i=0; i<rhs.size(); ++i) (*this)[i]=rhs[i];
123  return (*this);
124  }
125 
126  inline Vector operator+(const Vector& rhs) const
127  {
128  Vector res((*this));
129  res+=rhs;
130  return res;
131  }
132 
133  inline Vector operator-(const Vector& rhs) const
134  {
135  Vector res((*this));
136  res-=rhs;
137  return res;
138  }
139 
140  inline double operator*(const Vector& rhs) const
141  {
142  double res=0;
143  for(size_t i=0; i<size(); ++i) res += (*this)[i] * rhs[i];
144  return res;
145  }
146 
147  inline Vector operator*(const double& rhs) const
148  {
149  Vector res((*this));
150  res *= rhs;
151  return res;
152  }
153 
154  inline Vector operator/(const double& rhs) const
155  {
156  Vector res((*this));
157  res /= rhs;
158  return res;
159  }
160 
161  inline bool operator< ( const Vector& rhs ) const
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  }
168 
169  inline bool operator< ( const double& rhs) const
170  { return Length() < rhs; }
171 
172  inline bool operator== ( const Vector& rhs) const
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  }
179 
180  inline bool operator!= ( const Vector& rhs) const
181  { return !(*this == rhs); }
182 
183  /// Streamer
184  #ifndef __CINT__
185  friend std::ostream& operator << (std::ostream &o, ::geoalgo::Vector const& a)
186  { o << "Vector ("; for(auto const& v : a) o << v << " ";
187  o << ")";
188  return o;
189  }
190  #endif
191 
192  };
193 
194  /// Point has same feature as Vector
195  typedef Vector Vector_t;
196  typedef Vector Point_t;
197 }
198 
199 // Define a pointer comparison
200 namespace std {
201  template <>
202  class less<geoalgo::Vector*>
203  {
204  public:
205  bool operator()( const geoalgo::Vector* lhs, const geoalgo::Vector* rhs )
206  { return (*lhs) < (*rhs); }
207  };
208 }
209 
210 #endif
211 /** @} */ // end of doxygen group
bool operator<(const Vector &rhs) const
process_name opflash particleana ie ie ie z
bool operator!=(const Vector &rhs) const
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
Algorithm to compute various geometrical relation among geometrical objects. In particular functions ...
process_name opflash particleana ie x
double _Angle_(const Vector &obj) const
Compute the angle in degrees between 2 vectors w/o dimension check.
Vector & operator+=(const Vector &rhs)
Vector operator+(const Vector &rhs) const
double _Dot_(const Vector &obj) const
Compute a dot product w/o dimention check.
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.
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void compat(const Vector &obj) const
Dimensional check for a compatibility.
double _SqDist_(const Vector &obj) const
Compute the squared-distance to another vector w/o dimension check.
double Dist(const Vector &obj) const
Compute the distance to another vector.
Vector & operator*=(const double rhs)
Vector operator*(const double &rhs) const
double SqLength() const
Compute the squared length of the vector.
Vector(const std::vector< double > &obj)
Default ctor w/ a bare std::vector&lt;double&gt;
process_name gaushit a
Vector _Cross_(const Vector &obj) const
Compute a cross product w/o dimension check.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Vector operator/(const double &rhs) const
Vector(size_t n)
Ctor to instantiate with invalid value.
double Length() const
Compute the length of the vector.
process_name opflash particleana ie ie y
double Dot(const Vector &obj) const
bool IsValid() const
Check if point is valid.
Vector operator-(const Vector &rhs) const
Vector Cross(const Vector &obj) const
Compute a dot product of two vectors.
double SqDist(const Vector &obj) const
Compute the squared distance to another vector.
TLorentzVector ToTLorentzVector() const
Compute an opening angle w.r.t. the given vector.
Vector & operator/=(const double rhs)
double operator*(const Vector &rhs) const
Representation of a 3D semi-infinite line. Defines a semi-infinite 3D line by having a start point (P...
void RotateX(const double &theta)
rotation operations
Vector Dir() const
Return a direction unit vector.
Vector & operator=(const Vector &rhs)
Vector Vector_t
Point has same feature as Vector.
double Theta() const
Compute the angle theta.
double _Dist_(const Vector &obj) const
Compute the distance to another vector w/o dimension check.
bool operator==(const Vector &rhs) const
bool operator()(const geoalgo::Vector *lhs, const geoalgo::Vector *rhs)
double Angle(const Vector &obj) const
Compute a cross product of two vectors.
Vector & operator-=(const Vector &rhs)
friend std::ostream & operator<<(std::ostream &o,::geoalgo::Vector const &a)
Streamer.