Belle II Software  release-05-02-19
Circle2D.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 #include <tracking/trackFindingCDC/geometry/Vector2D.h>
12 
13 #include <tracking/trackFindingCDC/numerics/ERightLeft.h>
14 #include <tracking/trackFindingCDC/numerics/ERotation.h>
15 #include <tracking/trackFindingCDC/numerics/ESign.h>
16 
17 #include <cmath>
18 
19 namespace Belle2 {
24  namespace TrackFindingCDC {
25 
28  class Circle2D {
29 
30  public:
32  Circle2D()
33  : m_center(0.0, 0.0)
34  , m_radius(0.0)
35  {
36  }
37 
39  Circle2D(const Vector2D& center, const double radius)
41  , m_radius(radius)
42  {
43  }
44 
46  Circle2D(const Vector2D& center, const double absRadius, const ERotation ccwInfo)
48  , m_radius(fabs(absRadius) * ccwInfo)
49  {
50  }
51 
52  public:
54  void reverse()
55  {
56  m_radius *= -1;
57  }
58 
60  Circle2D reversed() const
61  {
62  return Circle2D(center(), -radius());
63  }
64 
76  void conformalTransform()
77  {
78  double denominator = 1 / (center().normSquared() - radius() * radius());
79  m_center *= denominator;
80  m_radius *= -denominator;
81  }
82 
95  {
96  double denominator = 1 / (center().normSquared() - radius() * radius());
97  return Circle2D(center() * denominator, -radius() * denominator);
98  }
99 
100  public:
102  double distance(const Vector2D& point) const
103  {
104  return copysign(center().distance(point), radius()) - radius();
105  }
106 
108  double impact() const
109  {
110  return copysign(center().norm(), radius()) - radius();
111  }
112 
114  double absDistance(const Vector2D& point) const
115  {
116  return fabs(center().distance(point) - absRadius());
117  }
118 
120  ERightLeft isRightOrLeft(const Vector2D& point) const
121  {
122  return static_cast<ERightLeft>(sign(distance(point)));
123  }
124 
126  bool isLeft(const Vector2D& rhs) const
127  {
128  return isRightOrLeft(rhs) == ERightLeft::c_Left;
129  }
130 
132  bool isRight(const Vector2D& rhs) const
133  {
134  return isRightOrLeft(rhs) == ERightLeft::c_Right;
135  }
136 
138  Vector2D closest(const Vector2D& point) const
139  {
140  Vector2D connection = point - center();
141  connection.normalizeTo(absRadius());
142  connection += center();
143  return connection;
144  }
145 
147  Vector2D perigee() const
148  {
149  Vector2D connection = center();
150  connection.normalizeTo(-absRadius());
151  connection += center();
152  return connection;
153  }
154 
156  Vector2D tangential() const
157  {
158  return tangential(Vector2D(0.0, 0.0)).unit();
159  }
160 
162  double tangentialPhi() const
163  {
164  return tangential().phi();
165  }
166 
168  Vector2D gradient(const Vector2D& point) const
169  {
170  Vector2D connection = (point - center()) * orientation();
171  return connection.unit();
172  }
173 
175  Vector2D normal(const Vector2D& point) const
176  {
177  return gradient(point).unit();
178  }
179 
181  Vector2D tangential(const Vector2D& point) const
182  {
183  return normal(point).orthogonal();
184  }
185 
187  double openingAngle(const Vector2D& from, const Vector2D& to) const
188  {
189  return gradient(from).angleWith(gradient(to));
190  } // can be optimized in the number of computations
191 
193  double arcLengthBetween(const Vector2D& from, const Vector2D& to) const
194  {
195  return openingAngle(from, to) * radius();
196  }
197 
199  double radius() const
200  {
201  return m_radius;
202  }
203 
205  double radiusSquared() const
206  {
207  return radius() * radius();
208  }
209 
211  double absRadius() const
212  {
213  return fabs(radius());
214  }
215 
217  ERotation orientation() const
218  {
219  return static_cast<ERotation>(sign(radius()));
220  }
221 
223  Vector2D center() const
224  {
225  return m_center;
226  }
227 
230  void moveBy(const Vector2D& by)
232  {
233  m_center += by;
234  }
235 
237  void moveAlongFirst(const double first)
238  {
240  }
241 
243  void moveAlongSecond(const double second)
244  {
246  }
247 
249  void passiveMoveBy(const Vector2D& by)
250  {
251  m_center -= by;
252  }
253 
255  void passiveMoveAlongFirst(const double first)
256  {
258  }
259 
261  void passiveMoveAlongSecond(const double second)
262  {
264  }
267  private:
270 
272  double m_radius;
273 
274  };
275  }
277 }
Belle2::TrackFindingCDC::Vector2D::setSecond
void setSecond(const double second)
Setter for the second coordinate.
Definition: Vector2D.h:658
Belle2::TrackFindingCDC::Vector2D::orthogonal
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:303
Belle2::TrackFindingCDC::Circle2D::arcLengthBetween
double arcLengthBetween(const Vector2D &from, const Vector2D &to) const
Calculates the arc length between two points of closest approach on the circle.
Definition: Circle2D.h:201
Belle2::TrackFindingCDC::Vector2D::unit
Vector2D unit() const
Returns a unit vector colaligned with this.
Definition: Vector2D.h:335
Belle2::TrackFindingCDC::Vector2D::normalizeTo
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
Definition: Vector2D.h:327
Belle2::TrackFindingCDC::Vector2D
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:37
Belle2::TrackFindingCDC::Circle2D::closest
Vector2D closest(const Vector2D &point) const
Calculates the point of closest approach on the line to the point.
Definition: Circle2D.h:146
Belle2::TrackFindingCDC::Circle2D::Circle2D
Circle2D()
Default constructor for ROOT compatibility. Creates an invalid circle.
Definition: Circle2D.h:40
Belle2::TrackFindingCDC::Vector2D::normSquared
double normSquared() const
Calculates .
Definition: Vector2D.h:183
Belle2::TrackFindingCDC::Circle2D::conformalTransformed
Circle2D conformalTransformed() const
Returns a copy of the circle in conformal space.
Definition: Circle2D.h:102
Belle2::TrackFindingCDC::Circle2D::isRightOrLeft
ERightLeft isRightOrLeft(const Vector2D &point) const
Return if the point given is right or left of the line.
Definition: Circle2D.h:128
Belle2::TrackFindingCDC::Circle2D::impact
double impact() const
Returns the signed distance to the origin.
Definition: Circle2D.h:116
Belle2::TrackFindingCDC::Vector2D::second
double second() const
Getter for the second coordinate.
Definition: Vector2D.h:653
Belle2::TrackFindingCDC::Circle2D::normal
Vector2D normal(const Vector2D &point) const
Normal vector to the circle near the given position.
Definition: Circle2D.h:183
Belle2::TrackFindingCDC::Circle2D::moveBy
void moveBy(const Vector2D &by)
Activelly moves the circle in the direction given in place by the vector given.
Definition: Circle2D.h:239
Belle2::TrackFindingCDC::Circle2D::passiveMoveAlongFirst
void passiveMoveAlongFirst(const double first)
Passivelly move the coordinate system in place along the first coordinate.
Definition: Circle2D.h:263
Belle2::TrackFindingCDC::Circle2D::moveAlongFirst
void moveAlongFirst(const double first)
Activelly moves the circle in the direction given in place along the first coordinate.
Definition: Circle2D.h:245
Belle2::TrackFindingCDC::Circle2D::radiusSquared
double radiusSquared() const
Getter for the squared radius.
Definition: Circle2D.h:213
Belle2::TrackFindingCDC::Circle2D
A two dimensional circle in its natural representation using center and radius as parameters.
Definition: Circle2D.h:36
Belle2::TrackFindingCDC::Circle2D::tangential
Vector2D tangential() const
Gives the tangential vector at the closest approach to the origin / at the perigee.
Definition: Circle2D.h:164
Belle2::TrackFindingCDC::Vector2D::phi
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
Definition: Vector2D.h:583
Belle2::TrackFindingCDC::Circle2D::radius
double radius() const
Getter for the signed radius.
Definition: Circle2D.h:207
Belle2::TrackFindingCDC::Vector2D::setFirst
void setFirst(const double first)
Setter for the first coordinate.
Definition: Vector2D.h:648
Belle2::TrackFindingCDC::Circle2D::m_radius
double m_radius
Memory for the signed radius.
Definition: Circle2D.h:280
Belle2::TrackFindingCDC::Vector2D::first
double first() const
Getter for the first coordinate.
Definition: Vector2D.h:643
Belle2::TrackFindingCDC::Circle2D::distance
double distance(const Vector2D &point) const
Calculates the signed distance of the point to the circle line.
Definition: Circle2D.h:110
Belle2::TrackFindingCDC::Circle2D::absDistance
double absDistance(const Vector2D &point) const
Returns the euclidian distance of the point to the circle line.
Definition: Circle2D.h:122
Belle2::TrackFindingCDC::Circle2D::moveAlongSecond
void moveAlongSecond(const double second)
Activelly moves the circle in the direction given in place along the second coordinate.
Definition: Circle2D.h:251
Belle2::TrackFindingCDC::Circle2D::reversed
Circle2D reversed() const
Returns a copy of the line with the reversed orientation.
Definition: Circle2D.h:68
Belle2::TrackFindingCDC::Circle2D::tangentialPhi
double tangentialPhi() const
Gives to azimuth phi of the direction of flight at the perigee.
Definition: Circle2D.h:170
Belle2::TrackFindingCDC::Circle2D::orientation
ERotation orientation() const
Indicates if the circle is to be interpreted counterclockwise or clockwise.
Definition: Circle2D.h:225
Belle2::TrackFindingCDC::Circle2D::passiveMoveBy
void passiveMoveBy(const Vector2D &by)
Passivelly move the coordinate system in place by the given vector.
Definition: Circle2D.h:257
Belle2::TrackFindingCDC::Circle2D::reverse
void reverse()
Flips orientation the circle in place.
Definition: Circle2D.h:62
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::Circle2D::openingAngle
double openingAngle(const Vector2D &from, const Vector2D &to) const
Calculates the angle between two points as seen from the center of the circle.
Definition: Circle2D.h:195
Belle2::TrackFindingCDC::Circle2D::isRight
bool isRight(const Vector2D &rhs) const
Return if the point given is right of the circle line.
Definition: Circle2D.h:140
Belle2::TrackFindingCDC::Circle2D::perigee
Vector2D perigee() const
Returns the point closest to the origin.
Definition: Circle2D.h:155
Belle2::TrackFindingCDC::NRightLeft::ERightLeft
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:35
Belle2::TrackFindingCDC::NRotation::ERotation
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: ERotation.h:35
Belle2::TrackFindingCDC::Circle2D::gradient
Vector2D gradient(const Vector2D &point) const
Gradient of the distance field.
Definition: Circle2D.h:176
Belle2::TrackFindingCDC::Circle2D::passiveMoveAlongSecond
void passiveMoveAlongSecond(const double second)
Passivelly move the coordinate system in place along the second coordinate.
Definition: Circle2D.h:269
Belle2::TrackFindingCDC::Circle2D::isLeft
bool isLeft(const Vector2D &rhs) const
Return if the point given is left of the circle line.
Definition: Circle2D.h:134
Belle2::TrackFindingCDC::Circle2D::center
Vector2D center() const
Getter for the central point of the circle.
Definition: Circle2D.h:231
Belle2::TrackFindingCDC::Circle2D::conformalTransform
void conformalTransform()
Transforms the circle to conformal space inplace.
Definition: Circle2D.h:84
Belle2::TrackFindingCDC::Circle2D::m_center
Vector2D m_center
Memory for the central point.
Definition: Circle2D.h:277
Belle2::TrackFindingCDC::Circle2D::absRadius
double absRadius() const
Getter for the absolute radius.
Definition: Circle2D.h:219
Belle2::TrackFindingCDC::Vector2D::angleWith
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
Definition: Vector2D.h:211