All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbncode/sbncode/OpT0Finder/flashmatch/GeoAlgo/GeoVector.h
Go to the documentation of this file.
1 /**
2  * \file GeoObjects.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 
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 
31  /**
32  \class Vector
33  This class represents an n-dimensional vector
34  */
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:
42  /// Default ctor
43  Vector() : std::vector<double>()
44  {}
45 
46  /// Ctor to instantiate with invalid value
47  Vector(size_t n) : std::vector<double>(n,kINVALID_DOUBLE)
48  {}
49 
50  /// Default ctor w/ a bare std::vector<double>
51  Vector(const std::vector<double> &obj) : std::vector<double>(obj)
52  {}
53 
54 
55  Vector(const double x, const double y); ///< ctor w/ x & y
56  Vector(const double x, const double y, const double z); ///< ctor w/ x, y & z
57  Vector(const TVector3 &pt); ///< ctor w/ TVector3
58  Vector(const TLorentzVector &pt); ///< ctor w/ TLorentzVector
59 
60  virtual ~Vector(){} ///< Default dtor
61 
62  void Normalize(); ///< Normalize itself
63  bool IsValid () const; ///< Check if point is valid
64  double SqLength() const; ///< Compute the squared length of the vector
65  double Length () const; ///< Compute the length of the vector
66  Vector Dir () const; ///< Return a direction unit vector
67  double Phi () const; ///< Compute the angle Phi
68  double Theta () const; ///< Compute the angle theta
69 
70  double SqDist(const Vector &obj) const; ///< Compute the squared distance to another vector
71  double Dist (const Vector& obj) const; ///< Compute the distance to another vector
72  double Dot (const Vector &obj) const; /// Compute a dot product of two vectors
73  Vector Cross (const Vector &obj) const; /// Compute a cross product of two vectors
74  double Angle (const Vector &obj) const; /// Compute an opening angle w.r.t. the given vector
75 
76  TLorentzVector ToTLorentzVector() const; ///< Convert geovector to TLorentzVector (with 4th element set equal to 0)
77 
78  /// Dimensional check for a compatibility
79  void compat(const Vector& obj) const;
80 
81  /// rotation operations
82  void RotateX(const double& theta);
83  void RotateY(const double& theta);
84  void RotateZ(const double& theta);
85 
86  std::string dump() const;
87 
88  protected:
89 
90  /// Compute the squared-distance to another vector w/o dimension check
91  double _SqDist_(const Vector& obj) const;
92  /// Compute the distance to another vector w/o dimension check
93  double _Dist_(const Vector& obj) const;
94  /// Compute a dot product w/o dimention check.
95  double _Dot_(const Vector& obj) const;
96  /// Compute a cross product w/o dimension check.
97  Vector _Cross_(const Vector& obj) const;
98  /// Compute the angle in degrees between 2 vectors w/o dimension check.
99  double _Angle_(const Vector& obj) const;
100 
101  public:
102  //
103  // binary/uniry operators
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 Vector& rhs) {
111  for(size_t i=0; i<size(); ++i) (*this)[i] -= rhs[i];
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 double rhs) {
121  for(auto &v : *this) v /= rhs;
122  return *this;
123  }
124 
125  inline Vector& operator=(const Vector& rhs) {
126  this->resize(rhs.size());
127  for(size_t i=0; i<rhs.size(); ++i) (*this)[i]=rhs[i];
128  return (*this);
129  }
130 
131  inline Vector operator+(const Vector& rhs) const
132  {
133  Vector res((*this));
134  res+=rhs;
135  return res;
136  }
137 
138  inline Vector operator-(const Vector& rhs) const
139  {
140  Vector res((*this));
141  res-=rhs;
142  return res;
143  }
144 
145  inline double operator*(const Vector& rhs) const
146  {
147  double res=0;
148  for(size_t i=0; i<size(); ++i) res += (*this)[i] * rhs[i];
149  return res;
150  }
151 
152  inline Vector operator*(const double& rhs) const
153  {
154  Vector res((*this));
155  res *= rhs;
156  return res;
157  }
158 
159  inline Vector operator/(const double& rhs) const
160  {
161  Vector res((*this));
162  res /= rhs;
163  return res;
164  }
165 
166  inline bool operator< ( const Vector& rhs ) const
167  {
168  compat(rhs);
169  for(size_t i=0; i<size(); ++i)
170  if((*this)[i] < rhs[i]) return true;
171  return false;
172  }
173 
174  inline bool operator< ( const double& rhs) const
175  { return Length() < rhs; }
176 
177  inline bool operator== ( const Vector& rhs) const
178  {
179  compat(rhs);
180  for(size_t i=0; i<size(); ++i)
181  if((*this)[i] != rhs[i]) return false;
182  return true;
183  }
184 
185  inline bool operator!= ( const Vector& rhs) const
186  { return !(*this == rhs); }
187 
188  /// Streamer
189  #ifndef __CINT__
190  friend std::ostream& operator << (std::ostream &o, ::geoalgo::Vector const& a)
191  { o << a.dump(); return o; }
192  #endif
193 
194  };
195 
196  /// Point has same feature as Vector
197  typedef Vector Vector_t;
198  typedef Vector Point_t;
199 }
200 
201 // Define a pointer comparison
202 #ifndef __GCCXML__
203 namespace std {
204  template <>
205  class less<geoalgo::Vector*>
206  {
207  public:
208  bool operator()( const geoalgo::Vector* lhs, const geoalgo::Vector* rhs )
209  { return (*lhs) < (*rhs); }
210  };
211 }
212 #endif
213 
214 #endif
215 /** @} */ // end of doxygen group
216 
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
process_name opflash particleana ie x
double _Angle_(const Vector &obj) const
Compute the angle in degrees between 2 vectors w/o dimension check.
double _Dot_(const Vector &obj) const
Compute a dot product w/o dimention check.
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.
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(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 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.
void RotateX(const double &theta)
rotation operations
Vector Dir() const
Return a direction unit vector.
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.
friend std::ostream & operator<<(std::ostream &o,::geoalgo::Vector const &a)
Streamer.