Belle II Software development
GeneralizedCircle.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/trackFindingCDC/geometry/Line2D.h>
11#include <tracking/trackFindingCDC/geometry/Vector2D.h>
12
13#include <tracking/trackFindingCDC/numerics/EForwardBackward.h>
14#include <tracking/trackFindingCDC/numerics/ERightLeft.h>
15#include <tracking/trackFindingCDC/numerics/ERotation.h>
16#include <tracking/trackFindingCDC/numerics/ESign.h>
17
18#include <utility>
19#include <iosfwd>
20#include <cmath>
21
22namespace Belle2 {
28 namespace TrackFindingCDC {
29 class Circle2D;
30
52
53 public:
56
58 GeneralizedCircle(double n0, double n1, double n2, double n3 = 0);
59
61 GeneralizedCircle(double n0, const Vector2D& n12, double n3 = 0);
62
64 explicit GeneralizedCircle(const Line2D& n012);
65
67 explicit GeneralizedCircle(const Circle2D& circle);
68
79 double absRadius,
80 ERotation orientation = ERotation::c_CounterClockwise);
81
88
95
96 protected:
102 void setN0(const double n0)
103 {
104 m_n0 = n0;
105 }
106
112 void setN1(const double n1)
113 {
114 m_n12.setX(n1);
115 }
116
122 void setN2(const double n2)
123 {
124 m_n12.setY(n2);
125 }
126
132 void setN12(const double n1, const double n2)
133 {
134 m_n12.setXY(n1, n2);
135 }
136
142 void setN12(const Vector2D& n12)
143 {
144 m_n12.setXY(n12);
145 }
146
152 void setN3(const double n3)
153 {
154 m_n3 = n3;
155 }
156
157 public:
160 double absRadius,
161 ERotation orientation = ERotation::c_CounterClockwise);
162
164 void setPerigeeParameters(double curvature, const Vector2D& tangential, double impact);
165
167 void
168 setPerigeeParameters(const double curvature, const double tangentialPhi, const double impact)
169 {
171 }
172
178 void setN(const double n0, const double n1, const double n2, const double n3 = 0.0)
179 {
180 setN0(n0);
181 setN12(n1, n2);
182 setN3(n3);
183 normalize();
184 }
185
191 void setN(const double n0, const Vector2D& n12, const double n3 = 0.0)
192 {
193 setN0(n0);
194 setN12(n12);
195 setN3(n3);
196 normalize();
197 }
198
200 void setN(const Line2D& n012)
201 {
202 setN(n012.n0(), n012.n12());
203 }
204
206 void setN(const GeneralizedCircle& n0123)
207 {
208 setN(n0123.n0(), n0123.n12(), n0123.n3());
209 }
210
213 {
214 setN(0.0, 0.0, 0.0, 0.0);
215 }
216
218 void reverse()
219 {
220 scaleN(-1);
221 }
222
230 {
231 std::swap(m_n0, m_n3);
232 reverse(); // Correct orientation
233 }
234
239 void passiveMoveBy(const Vector2D& by)
240 {
241 setN(fastDistance(by), gradient(by), n3());
242 }
243
244 protected:
253 {
254 double normalization_squared = normalizationSquared();
255 if (normalization_squared > 0) scaleN(1.0 / std::sqrt(normalization_squared));
256 }
257
258 private:
260 void scaleN(const double factor)
261 {
262 m_n0 *= factor;
263 m_n12 *= factor;
264 m_n3 *= factor;
265 }
266
267 public:
269 double n0() const
270 {
271 return m_n0;
272 }
273
275 double n1() const
276 {
277 return m_n12.x();
278 }
279
281 double n2() const
282 {
283 return m_n12.y();
284 }
285
287 const Vector2D& n12() const
288 {
289 return m_n12;
290 }
291
293 double n3() const
294 {
295 return m_n3;
296 }
297
298 public:
300 bool isInvalid() const
301 {
302 return n0() == 0 and n12().isNull() and n3() == 0;
303 }
304
306 bool isValid() const
307 {
308 return not isInvalid();
309 }
310
315 double normalizationSquared() const
316 {
317 return n12().normSquared() - 4 * n0() * n3();
318 }
319
320 public:
323 {
324 return GeneralizedCircle(-n0(), -n12(), -n3());
325 }
326
327 public:
336 {
337 return GeneralizedCircle(-n3(), -n12(), -n0());
338 }
339
340 public:
347 Vector2D gradient(const Vector2D& point) const
348 {
349 return point * (2.0 * n3()) + n12();
350 }
351
361 Vector2D normal(const Vector2D& point) const
362 {
363 return gradient(point).unit();
364 }
365
374 Vector2D tangential(const Vector2D& point) const
375 {
376 return normal(point).orthogonal();
377 }
378
385 Vector2D closest(const Vector2D& point) const;
386
390 Vector2D perigee() const;
391
396 Vector2D apogee() const;
397
409 {
410 Vector2D difference = to - from;
411 Vector2D tangentialAtFrom = tangential(from);
412 return tangentialAtFrom.isForwardOrBackwardOf(difference);
413 }
414
430 chooseNextForwardOf(const Vector2D& start, const Vector2D& end1, const Vector2D& end2) const;
431
433 std::pair<Belle2::TrackFindingCDC::Vector2D, Belle2::TrackFindingCDC::Vector2D>
434 atCylindricalR(double cylindricalR) const;
435
449 Vector2D atCylindricalRForwardOf(const Vector2D& startPoint, double cylindricalR) const;
450
459 double fastDistance(const Vector2D& point) const
460 {
461 return n0() + point.dot(n12()) + point.normSquared() * n3();
462 }
463
465 double fastImpact() const
466 {
467 return n0();
468 }
469
474 double distance(const Vector2D& point) const;
475
481 double distance(double fastDistance) const;
482
487 double fastDistance(const double distance) const
488 {
489 return (distance * n3() + 1.0) * distance;
490 }
491
493 double impact() const
494 {
495 return distance(fastImpact());
496 }
497
499 double d0() const
500 {
501 return -impact();
502 }
503
506 {
507 return tangential(Vector2D(0.0, 0.0)).unit();
508 }
509
511 double tangentialPhi() const
512 {
513 return tangential().phi();
514 }
515
517 double minimalCylindricalR() const
518 {
519 return std::fabs(impact());
520 }
521
523 double maximalCylindricalR() const
524 {
525 return std::fabs(impact() + 2 * radius());
526 }
527
529 double absDistance(const Vector2D& point) const
530 {
531 return fabs(distance(point));
532 }
533
539 {
540 return static_cast<ERightLeft>(sign(fastDistance(point)));
541 }
542
544 bool isLeft(const Vector2D& rhs) const
545 {
546 return isRightOrLeft(rhs) == ERightLeft::c_Left;
547 }
548
550 bool isRight(const Vector2D& rhs) const
551 {
552 return isRightOrLeft(rhs) == ERightLeft::c_Right;
553 }
554
556 bool isLine() const
557 {
558 return n3() == 0.0;
559 }
560
562 bool isCircle() const
563 {
564 return n3() != 0.0;
565 }
566
568 double radius() const
569 {
570 return 1 / curvature();
571 }
572
574 double absRadius() const
575 {
576 return fabs(radius());
577 }
578
580 double curvature() const
581 {
582 return 2 * n3();
583 }
584
589 double omega() const
590 {
591 return -curvature();
592 }
593
596 {
597 return n12().divided(-2 * n3());
598 }
599
601 double perimeter() const
602 {
603 return 2 * M_PI * radius();
604 }
605
613 {
614 return static_cast<ERotation>(sign(n3()));
615 }
616
618 double arcLengthPeriod() const
619 {
620 return std::fabs(perimeter());
621 }
622
632 double arcLengthBetween(const Vector2D& from, const Vector2D& to) const;
633
635 double arcLengthTo(const Vector2D& to) const;
636
643 double arcLengthToCylindricalR(double cylindricalR) const;
644
653 double arcLengthFactor(const double directDistance) const
654 {
655 return arcLengthFactor(directDistance, curvature());
656 }
657
666 static double arcLengthFactor(double directDistance, double curvature);
667
673 std::pair<Vector2D, Vector2D> intersections(const GeneralizedCircle& generalizedCircle) const;
674
679 Vector2D atArcLength(double arcLength) const;
680
681 private:
682 // Order of this parameters make them easier to initialize
683
685 double m_n3;
686
689
691 double m_n0;
692 };
693
695 std::ostream& operator<<(std::ostream& output, const GeneralizedCircle& circle);
696 }
698}
A two dimensional circle in its natural representation using center and radius as parameters.
Definition: Circle2D.h:26
Vector2D atArcLength(double arcLength) const
Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
void setCenterAndRadius(const Vector2D &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
double fastImpact() const
Approximate distance to the origin.
Vector2D tangential() const
Gives the tangential vector at the closest approach to the origin / at the perigee.
double fastDistance(const Vector2D &point) const
Approximate distance.
double absDistance(const Vector2D &point) const
Gives the proper absolute distance of the point to the circle line.
double m_n3
Memory for the fourth parameter.
double n1() const
Getter for the second circle parameter.
bool isLine() const
Indicates if the generalized circle is actually a line.
Vector2D perigee() const
Calculates the closest approach to the two dimensional origin.
Vector2D gradient(const Vector2D &point) const
Gradient of the distance field Gives the gradient of the approximated distance field for the given po...
GeneralizedCircle reversed() const
Returns a copy of the circle with opposite orientation.
Vector2D atCylindricalRForwardOf(const Vector2D &startPoint, double cylindricalR) const
Approach on the circle with the given cylindrical radius that lies in the forward direction of a star...
Vector2D tangential(const Vector2D &point) const
Tangential vector to the circle near the given position.
double arcLengthBetween(const Vector2D &from, const Vector2D &to) const
Calculates the arc length between two points of closest approach on the circle.
bool isInvalid() const
Indicates if all circle parameters are zero.
void setPerigeeParameters(double curvature, const Vector2D &tangential, double impact)
Setter for the perigee parameters.
double minimalCylindricalR() const
Gives the minimal cylindrical radius the circle reaches (unsigned)
void reverse()
Flips the orientation of the circle in place.
void setN0(const double n0)
Setter for first circle parameter.
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
Vector2D normal(const Vector2D &point) const
Normal vector to the circle near the given position.
Vector2D chooseNextForwardOf(const Vector2D &start, const Vector2D &end1, const Vector2D &end2) const
Returns the end point which is first reached if one follows the forward direction of the circle start...
const Vector2D & n12() const
Getter for the second and third circle parameter which natuarally from a vector.
void setN(const Line2D &n012)
Setter for all four circle parameters from another circle.
double distance(const Vector2D &point) const
Gives the proper distance of the point to the circle line retaining the sign of the fast distance.
void setN2(const double n2)
Setter for third circle parameter.
Vector2D apogee() const
Calculates the point on the circle that is furthest away from the origin.
double omega() const
Gives the omega parameter as used by the framework helix.
void setN3(const double n3)
Setter for fourth circle parameter.
void setN1(const double n1)
Setter for second circle parameter.
double m_n0
Memory for the first parameter.
void passiveMoveBy(const Vector2D &by)
Moves the coordinate system by the given vector.
bool isValid() const
Indicates if the combination of the circle parameters makes up a valid circle.
bool isLeft(const Vector2D &rhs) const
Return if the point given is left of the line.
void setN(const GeneralizedCircle &n0123)
Setter for all four circle parameters from another circle.
bool isRight(const Vector2D &rhs) const
Return if the point given is right of the line.
EForwardBackward isForwardOrBackwardOf(const Vector2D &from, const Vector2D &to) const
Calculates if the to vector is closer to the from vector following the along orientation of the circl...
double impact() const
Gives the signed distance of the origin to the circle.
Vector2D center() const
Gives the center of the circle. If it was a line both components will be infinity.
void setN12(const double n1, const double n2)
Setter for second and third circle parameter.
double normalizationSquared() const
Calculates the generalized circle specific squared norm.
double maximalCylindricalR() const
Gives the maximal cylindrical radius the circle reaches.
static GeneralizedCircle fromPerigeeParameters(double curvature, const Vector2D &tangential, double impact)
Constructor of a generalized circle from perigee parameters.
GeneralizedCircle()
Default constructor for ROOT compatibility.
double n3() const
Getter for the fourth circle parameter.
void invalidate()
Sets all circle parameters to zero.
void conformalTransform()
Transforms the generalized circle to conformal space inplace Applies the conformal map in the self-in...
static GeneralizedCircle fromCenterAndRadius(const Vector2D &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
void scaleN(const double factor)
Scales the circle parameters by a common factor.
double perimeter() const
Gives the perimeter of the circle.
double n2() const
Getter for the third circle parameter.
bool isCircle() const
Indicates if the generalized circle is actually a circle.
double arcLengthTo(const Vector2D &to) const
Calculates the arc length between the perigee and the given point.
ERightLeft isRightOrLeft(const Vector2D &point) const
Indicates if the point is on the right or left side of the circle.
void setPerigeeParameters(const double curvature, const double tangentialPhi, const double impact)
Setter for the perigee parameters.
void setN12(const Vector2D &n12)
Setter for second and third circle parameter.
double curvature() const
Gives the signed curvature of the generalized circle.
double d0() const
Getter for the absolute distance to the z axes at the support point.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
Vector2D closest(const Vector2D &point) const
Closest approach on the circle to the point.
double arcLengthFactor(const double directDistance) const
Helper function the calculate the factor between the length of a secant line and the length on the ar...
std::pair< Belle2::TrackFindingCDC::Vector2D, Belle2::TrackFindingCDC::Vector2D > atCylindricalR(double cylindricalR) const
Calculates the two points with the given cylindrical radius on the generalised circle.
void normalize()
Normalizes the circle parameters.
double tangentialPhi() const
Gives to azimuth angle phi of the direction of flight at the perigee.
Vector2D m_n12
Memory for the second and third parameter.
double fastDistance(const double distance) const
Helper function to translate the proper distance to the linearized distance measure of the generalize...
void setN(const double n0, const Vector2D &n12, const double n3=0.0)
Setter for all four circle parameters.
double n0() const
Getter for the first circle parameter.
void setN(const double n0, const double n1, const double n2, const double n3=0.0)
Setter for all four circle parameters.
ERotation orientation() const
Gives the orientation of the circle.
double arcLengthPeriod() const
Getter for the arc length for a full round of the circle.
double arcLengthToCylindricalR(double cylindricalR) const
Calculates the two dimensional arc length till the cylindrical radius is reached If the radius can no...
std::pair< Vector2D, Vector2D > intersections(const GeneralizedCircle &generalizedCircle) const
Calculates the two points common to both circles.
GeneralizedCircle conformalTransformed() const
Returns a copy of the circle in conformal space.
A two dimensional normal line.
Definition: Line2D.h:37
const Vector2D & n12() const
Getter for the unit normal vector to the line.
Definition: Line2D.h:117
double n0() const
Getter for the first line parameter.
Definition: Line2D.h:99
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:32
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
Definition: Vector2D.h:158
void setXY(const double x, const double y)
Setter for both coordinate.
Definition: Vector2D.h:616
EForwardBackward isForwardOrBackwardOf(const Vector2D &rhs) const
Indicates if the given vector is more coaligned or reverse if you looked in the direction of this vec...
Definition: Vector2D.h:493
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:595
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
Definition: Vector2D.h:569
double normSquared() const
Calculates .
Definition: Vector2D.h:169
bool isNull() const
Checks if the vector is the null vector.
Definition: Vector2D.h:143
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:289
Vector2D divided(const double denominator) const
Returns a copy where all coordinates got divided by a common denominator.
Definition: Vector2D.h:251
void setY(const double y)
Setter for the y coordinate.
Definition: Vector2D.h:610
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:605
Vector2D unit() const
Returns a unit vector colaligned with this.
Definition: Vector2D.h:321
void setX(const double x)
Setter for the x coordinate.
Definition: Vector2D.h:600
static Vector2D Phi(const double phi)
Constucts a unit vector with azimuth angle equal to phi.
Definition: Vector2D.h:62
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: ERotation.h:25
Abstract base class for different kinds of events.