Belle II Software development
Circle2D.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#pragma once
9
10#include <tracking/trackingUtilities/geometry/VectorUtil.h>
11
12#include <tracking/trackingUtilities/numerics/ERightLeft.h>
13#include <tracking/trackingUtilities/numerics/ERotation.h>
14#include <tracking/trackingUtilities/numerics/ESign.h>
15
16#include <framework/geometry/VectorUtil.h>
17
18#include <Math/Vector2D.h>
19#include <Math/VectorUtil.h>
20
21#include <cmath>
22
23namespace Belle2 {
28 namespace TrackingUtilities {
29
32 class Circle2D {
33
34 public:
37 : m_center(0.0, 0.0)
38 , m_radius(0.0)
39 {
40 }
41
43 Circle2D(const ROOT::Math::XYVector& center, const double radius)
46 {
47 }
48
50 Circle2D(const ROOT::Math::XYVector& center, const double absRadius, const ERotation ccwInfo)
52 , m_radius(fabs(absRadius) * static_cast<double>(ccwInfo))
53 {
54 }
55
56 public:
58 void reverse()
59 {
60 m_radius *= -1;
61 }
62
65 {
66 return Circle2D(center(), -radius());
67 }
68
81 {
82 double denominator = 1 / (center().Mag2() - radius() * radius());
83 m_center *= denominator;
84 m_radius *= -denominator;
85 }
86
99 {
100 double denominator = 1 / (center().Mag2() - radius() * radius());
101 return Circle2D(center() * denominator, -radius() * denominator);
102 }
103
104 public:
106 double distance(const ROOT::Math::XYVector& point) const
107 {
108 return copysign(VectorUtil::Distance(center(), point), radius()) - radius();
109 }
110
112 double impact() const
113 {
114 return copysign(center().R(), radius()) - radius();
115 }
116
118 double absDistance(const ROOT::Math::XYVector& point) const
119 {
120 return fabs(VectorUtil::Distance(center(), point) - absRadius());
121 }
122
124 ERightLeft isRightOrLeft(const ROOT::Math::XYVector& point) const
125 {
126 return static_cast<ERightLeft>(sign(distance(point)));
127 }
128
130 bool isLeft(const ROOT::Math::XYVector& rhs) const
131 {
132 return isRightOrLeft(rhs) == ERightLeft::c_Left;
133 }
134
136 bool isRight(const ROOT::Math::XYVector& rhs) const
137 {
138 return isRightOrLeft(rhs) == ERightLeft::c_Right;
139 }
140
142 ROOT::Math::XYVector closest(const ROOT::Math::XYVector& point) const
143 {
144 ROOT::Math::XYVector connection = point - center();
145 if (connection.R() != 0.0) {
146 connection *= (absRadius() / connection.R());
147 }
148 connection += center();
149 return connection;
150 }
151
153 ROOT::Math::XYVector perigee() const
154 {
155 ROOT::Math::XYVector connection = center();
156 if (connection.R() != 0.0) {
157 connection *= (-absRadius() / connection.R());
158 }
159 connection += center();
160 return connection;
161 }
162
164 ROOT::Math::XYVector tangential() const
165 {
166 return VectorUtil::unit(tangential(ROOT::Math::XYVector(0.0, 0.0)));
167 }
168
170 double tangentialPhi() const
171 {
172 return tangential().Phi();
173 }
174
176 ROOT::Math::XYVector gradient(const ROOT::Math::XYVector& point) const
177 {
178 ROOT::Math::XYVector connection = (point - center()) * orientation();
179 return VectorUtil::unit(connection);
180 }
181
183 ROOT::Math::XYVector normal(const ROOT::Math::XYVector& point) const
184 {
185 return VectorUtil::unit(gradient(point));
186 }
187
189 ROOT::Math::XYVector tangential(const ROOT::Math::XYVector& point) const
190 {
191 return VectorUtil::Orthogonal(normal(point));
192 }
193
195 double openingAngle(const ROOT::Math::XYVector& from, const ROOT::Math::XYVector& to) const
196 {
197 return ROOT::Math::VectorUtil::DeltaPhi(gradient(from), gradient(to));
198 } // can be optimized in the number of computations
199
201 double arcLengthBetween(const ROOT::Math::XYVector& from, const ROOT::Math::XYVector& to) const
202 {
203 return openingAngle(from, to) * radius();
204 }
205
207 double radius() const
208 {
209 return m_radius;
210 }
211
213 double radiusSquared() const
214 {
215 return radius() * radius();
216 }
217
219 double absRadius() const
220 {
221 return fabs(radius());
222 }
223
225 ERotation orientation() const
226 {
227 return static_cast<ERotation>(sign(radius()));
228 }
229
231 ROOT::Math::XYVector center() const
232 {
233 return m_center;
234 }
235
239 void moveBy(const ROOT::Math::XYVector& by)
240 {
241 m_center += by;
242 }
243
245 void moveAlongFirst(const double first)
246 {
247 m_center.SetX(m_center.X() + first);
248 }
249
251 void moveAlongSecond(const double second)
252 {
253 m_center.SetY(m_center.Y() + second);
254 }
255
257 void passiveMoveBy(const ROOT::Math::XYVector& by)
258 {
259 m_center -= by;
260 }
261
263 void passiveMoveAlongFirst(const double first)
264 {
265 m_center.SetX(m_center.X() - first);
266 }
267
269 void passiveMoveAlongSecond(const double second)
270 {
271 m_center.SetY(m_center.Y() - second);
272 }
273
274
275 private:
277 ROOT::Math::XYVector m_center;
278
280 double m_radius;
281
282 };
283 }
285}
double R
typedef autogenerated by FFTW
ROOT::Math::XYVector tangential(const ROOT::Math::XYVector &point) const
Tangential vector to the circle near the given position.
Definition Circle2D.h:189
ROOT::Math::XYVector m_center
Memory for the central point.
Definition Circle2D.h:277
Circle2D reversed() const
Returns a copy of the line with the reversed orientation.
Definition Circle2D.h:64
ROOT::Math::XYVector gradient(const ROOT::Math::XYVector &point) const
Gradient of the distance field.
Definition Circle2D.h:176
double m_radius
Memory for the signed radius.
Definition Circle2D.h:280
bool isRight(const ROOT::Math::XYVector &rhs) const
Return if the point given is right of the circle line.
Definition Circle2D.h:136
void reverse()
Flips orientation the circle in place.
Definition Circle2D.h:58
double arcLengthBetween(const ROOT::Math::XYVector &from, const ROOT::Math::XYVector &to) const
Calculates the arc length between two points of closest approach on the circle.
Definition Circle2D.h:201
double radius() const
Getter for the signed radius.
Definition Circle2D.h:207
Circle2D(const ROOT::Math::XYVector &center, const double radius)
Constructs a circle with given center and radius/ orientation as given by the signedRadius.
Definition Circle2D.h:43
void moveBy(const ROOT::Math::XYVector &by)
Actively moves the circle in the direction given in place by the vector given.
Definition Circle2D.h:239
bool isLeft(const ROOT::Math::XYVector &rhs) const
Return if the point given is left of the circle line.
Definition Circle2D.h:130
ROOT::Math::XYVector closest(const ROOT::Math::XYVector &point) const
Calculates the point of closest approach on the line to the point.
Definition Circle2D.h:142
Circle2D conformalTransformed() const
Returns a copy of the circle in conformal space.
Definition Circle2D.h:98
void moveAlongFirst(const double first)
Actively moves the circle in the direction given in place along the first coordinate.
Definition Circle2D.h:245
ROOT::Math::XYVector normal(const ROOT::Math::XYVector &point) const
Normal vector to the circle near the given position.
Definition Circle2D.h:183
double impact() const
Returns the signed distance to the origin.
Definition Circle2D.h:112
Circle2D()
Default constructor for ROOT compatibility. Creates an invalid circle.
Definition Circle2D.h:36
double absDistance(const ROOT::Math::XYVector &point) const
Returns the euclidean distance of the point to the circle line.
Definition Circle2D.h:118
double distance(const ROOT::Math::XYVector &point) const
Calculates the signed distance of the point to the circle line.
Definition Circle2D.h:106
void passiveMoveAlongFirst(const double first)
Passively move the coordinate system in place along the first coordinate.
Definition Circle2D.h:263
ERightLeft isRightOrLeft(const ROOT::Math::XYVector &point) const
Return if the point given is right or left of the line.
Definition Circle2D.h:124
ROOT::Math::XYVector perigee() const
Returns the point closest to the origin.
Definition Circle2D.h:153
double radiusSquared() const
Getter for the squared radius.
Definition Circle2D.h:213
void passiveMoveBy(const ROOT::Math::XYVector &by)
Passively move the coordinate system in place by the given vector.
Definition Circle2D.h:257
ROOT::Math::XYVector tangential() const
Gives the tangential vector at the closest approach to the origin / at the perigee.
Definition Circle2D.h:164
void conformalTransform()
Transforms the circle to conformal space inplace.
Definition Circle2D.h:80
double absRadius() const
Getter for the absolute radius.
Definition Circle2D.h:219
double openingAngle(const ROOT::Math::XYVector &from, const ROOT::Math::XYVector &to) const
Calculates the angle between two points as seen from the center of the circle.
Definition Circle2D.h:195
Circle2D(const ROOT::Math::XYVector &center, const double absRadius, const ERotation ccwInfo)
Constructs a circle with given center, absolute value of the radius and orientation.
Definition Circle2D.h:50
double tangentialPhi() const
Gives to azimuth phi of the direction of flight at the perigee.
Definition Circle2D.h:170
ROOT::Math::XYVector center() const
Getter for the central point of the circle.
Definition Circle2D.h:231
void passiveMoveAlongSecond(const double second)
Passively move the coordinate system in place along the second coordinate.
Definition Circle2D.h:269
ERotation orientation() const
Indicates if the circle is to be interpreted counterclockwise or clockwise.
Definition Circle2D.h:225
void moveAlongSecond(const double second)
Actively moves the circle in the direction given in place along the second coordinate.
Definition Circle2D.h:251
Abstract base class for different kinds of events.