Belle II Software  release-08-01-10
Point2D.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #ifndef TRGPoint2D_FLAG_
10 #define TRGPoint2D_FLAG_
11 
12 #include <cmath>
13 #include "CLHEP/Geometry/Point3D.h"
14 #include "CLHEP/Geometry/Vector3D.h"
15 
16 namespace Belle2 {
22  typedef HepGeom::Vector3D<double> Vector3D;
23 
24 // class CLHEP::Hep3Vector;
25 
27  class TRGPoint2D {
28 
29  public:
31  TRGPoint2D();
33  TRGPoint2D(double, double);
35  // cppcheck-suppress noExplicitConstructor
38  explicit TRGPoint2D(const Vector3D&);
40  explicit TRGPoint2D(const CLHEP::Hep3Vector&);
41 
43  virtual ~TRGPoint2D();
44 
45  public:// Selectors
47  double x(void) const;
49  double y(void) const;
51  double mag(void) const;
53  double mag2(void) const;
55  double phi(void) const;
56 
57  public:// Modifiers
59  double x(double);
61  double y(double);
62 
63  public:// Operators
65  double dot(const TRGPoint2D&) const;
67  double cross(const TRGPoint2D&) const;
69  TRGPoint2D unit(void) const;
71  TRGPoint2D operator + (const TRGPoint2D&) const;
73  TRGPoint2D operator - (const TRGPoint2D&) const;
75  TRGPoint2D operator - () const;
77  bool operator == (const TRGPoint2D&) const;
78 
79  private:
81  double _p[2];
82  };
83 
85  std::ostream&
86  operator << (std::ostream&, const TRGPoint2D&);
87 
88 //-----------------------------------------------------------------------------
89 
90  inline
91  double
92  TRGPoint2D::x(void) const
93  {
94  return _p[0];
95  }
96 
97  inline
98  double
99  TRGPoint2D::y(void) const
100  {
101  return _p[1];
102  }
103 
104  inline
105  double
106  TRGPoint2D::x(double a)
107  {
108  return _p[0] = a;
109  }
110 
111  inline
112  double
113  TRGPoint2D::y(double a)
114  {
115  return _p[1] = a;
116  }
117 
118  inline
119  double
120  TRGPoint2D::mag(void) const
121  {
122  return sqrt(_p[0] * _p[0] + _p[1] * _p[1]);
123  }
124 
125  inline
126  double
127  TRGPoint2D::mag2(void) const
128  {
129  return _p[0] * _p[0] + _p[1] * _p[1];
130  }
131 
132  inline
133  double
134  TRGPoint2D::phi(void) const
135  {
136  if (_p[0] == 0.0 && _p[1] == 0.0) return 0.;
137  double a = atan2(_p[1], _p[0]);
138  if (a > 0) return a;
139  return a + 2. * M_PI;
140  }
141 
142  inline
143  double
144  TRGPoint2D::dot(const TRGPoint2D& a) const
145  {
146  return _p[0] * a.x() + _p[1] * a.y();
147  }
148 
149  inline
150  double
152  {
153  return _p[0] * a.y() - a.x() * _p[1];
154  }
155 
156  inline
157  TRGPoint2D
159  {
160  return TRGPoint2D(_p[0] + a.x(), _p[1] + a.y());
161  }
162 
163  inline
164  TRGPoint2D
166  {
167  return TRGPoint2D(_p[0] - a.x(), _p[1] - a.y());
168  }
169 
170  inline
171  TRGPoint2D
173  {
174  return TRGPoint2D(- _p[0], - _p[1]);
175  }
176 
177  inline
178  bool
180  {
181  if (a.x() == _p[0] && a.y() == _p[1]) return true;
182  return false;
183  }
184 
185  inline
186  TRGPoint2D
187  TRGPoint2D::unit(void) const
188  {
189  double sum2 = _p[0] * _p[0] + _p[1] * _p[1];
190  if (sum2 == 0.) return TRGPoint2D(0., 0.);
191  double sum = sqrt(sum2);
192  return TRGPoint2D(_p[0] / sum, _p[1] / sum);
193  }
194 
196 } // namespace Belle2k
197 
198 #endif /* TRGPoint2D_FLAG_ */
A class to represent a point in 2D.
Definition: Point2D.h:27
double _p[2]
vector
Definition: Point2D.h:81
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
double phi(void) const
phi of the point
Definition: Point2D.h:134
TRGPoint2D()
Constructor.
Definition: Point2D.cc:17
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:34
double y(void) const
y of the point
Definition: Point2D.h:99
double mag2(void) const
magnitude square of the point
Definition: Point2D.h:127
double mag(void) const
magnitude of the point
Definition: Point2D.h:120
bool operator==(const TRGPoint2D &) const
equal operator
Definition: Point2D.h:179
TRGPoint2D operator-() const
Definition: Point2D.h:172
double x(void) const
x of the point
Definition: Point2D.h:92
double cross(const TRGPoint2D &) const
outer product
Definition: Point2D.h:151
TRGPoint2D operator+(const TRGPoint2D &) const
Definition: Point2D.h:158
virtual ~TRGPoint2D()
Destructor.
Definition: Point2D.cc:47
double dot(const TRGPoint2D &) const
inner product
Definition: Point2D.h:144
TRGPoint2D unit(void) const
unit vector
Definition: Point2D.h:187
Abstract base class for different kinds of events.