8#include <tracking/trackFindingCDC/geometry/GeneralizedCircle.h>
10#include <tracking/trackFindingCDC/geometry/Circle2D.h>
11#include <tracking/trackFindingCDC/geometry/Line2D.h>
12#include <tracking/trackFindingCDC/geometry/Vector2D.h>
14#include <tracking/trackFindingCDC/numerics/EForwardBackward.h>
15#include <tracking/trackFindingCDC/numerics/ERotation.h>
17#include <tracking/trackFindingCDC/numerics/SpecialFunctions.h>
18#include <tracking/trackFindingCDC/numerics/Quadratic.h>
24using namespace TrackFindingCDC;
61 : m_n3(1.0 / 2.0 / circle.radius())
62 , m_n12(-circle.center().x() * (m_n3 * 2.0), -circle.center().y() * (m_n3 * 2.0))
63 , m_n0((circle.center().normSquared() - circle.radiusSquared()) * m_n3)
68 const double absRadius,
73 return generalizedCircle;
82 return generalizedCircle;
86 const double tangentialPhi,
91 return generalizedCircle;
95 const double absRadius,
131 double closestOrthogonal =
n12().
cross(point) / gradientAtPoint.
norm();
137 double closestParallel = 0.0;
139 closestParallel = -(nOrthogonal * closestOrthogonal +
n0()) / nParallel;
142 const double a =
n3();
143 const double b = nParallel;
144 const double c =
n0() + (nOrthogonal +
n3() * closestOrthogonal) * closestOrthogonal;
146 const std::pair<double, double> closestParallel12 = solveQuadraticABC(a, b, c);
151 const double criterion1 =
152 closestParallel12.first * (closestParallel12.first - 2 * pointParallel);
153 const double criterion2 =
154 closestParallel12.second * (closestParallel12.second - 2 * pointParallel);
156 closestParallel = criterion1 < criterion2 ? closestParallel12.first : closestParallel12.second;
164 result.setCylindricalR(-
impact());
182 if (lengthOnCurve1 >= 0.0) {
184 if (lengthOnCurve2 >= 0.0) {
185 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
191 if (lengthOnCurve2 >= 0.0) {
202 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
221 const double sameCylindricalRParallel = -(
n0() +
n3() * square(cylindricalR)) /
n12().
norm();
224 const double sameCylindricalROrthogonal =
sqrt(square(cylindricalR) - square(sameCylindricalRParallel));
233 std::pair<Vector2D, Vector2D> result(sameCylindricalR1, sameCylindricalR2);
238 const double cylindricalR)
const
240 std::pair<Vector2D, Vector2D> candidatePoints =
atCylindricalR(cylindricalR);
250 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
254 double directDistance = closestAtFrom.
distance(closestAtTo);
256 return static_cast<double>(lengthSign) *
arcLengthFactor(directDistance) * directDistance;
267 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
269 const Vector2D& closestAtFrom = from;
271 double directDistance = closestAtFrom.
distance(closestAtTo);
273 return static_cast<double>(lengthSign) *
arcLengthFactor(directDistance) * directDistance;
283 const double dr =
d0();
284 const double directDistance =
285 sqrt((cylindricalR + dr) * (cylindricalR - dr) / (1 + dr *
omega()));
286 const double arcLength =
arcLengthFactor(directDistance) * directDistance;
292 double x = directDistance *
curvature / 2.0;
310 const double a =
n3();
314 std::pair<double, double> distance12 = solveQuadraticABC(a, b, c);
317 return distance12.second;
321std::pair<Vector2D, Vector2D>
324 const double m0 = generalizedCircle.
n0();
326 const double m3 = generalizedCircle.
n3();
328 const double n0 = this->
n0();
330 const double n3 = this->
n3();
335 double xParallel = (m0 *
n3 - m3 *
n0) / absC;
343 double b = mn12Orthogonal;
344 double c = (a * xParallel + mn12Parallel) * xParallel + m0 +
n0;
346 std::pair<double, double> xOrthogonal = solveQuadraticABC(a, b, c);
355 double chiHalf = chi / 2.0;
357 double atX = arcLength * sinc(chiHalf) * sin(chiHalf) +
impact();
358 double atY = -arcLength * sinc(chi);
362std::ostream& TrackFindingCDC::operator<<(std::ostream& output,
const GeneralizedCircle& circle)
365 output <<
"Line support point = " << circle.
perigee();
368 output <<
"CircleCenter = " << circle.
center() <<
", Radius = " << circle.
absRadius();
A two dimensional circle in its natural representation using center and radius as parameters.
Vector2D atArcLength(double arcLength) const
Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
void setCenterAndRadius(const Vector2D ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
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.
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...
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...
double arcLengthBetween(const Vector2D &from, const Vector2D &to) const
Calculates the arc length between two points of closest approach on the circle.
void setPerigeeParameters(double curvature, const Vector2D &tangential, double impact)
Setter for the perigee parameters.
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 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.
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.
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.
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.
static GeneralizedCircle fromCenterAndRadius(const Vector2D ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
double arcLengthTo(const Vector2D &to) const
Calculates the arc length between the perigee and the given point.
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.
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 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.
A two dimensional normal line.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
double normalize()
Normalizes the vector to unit length.
static Vector2D compose(const Vector2D &coordinateVec, const double parallelCoor, const double orthoCoor)
Constructs a vector from a unit coordinate system vector and the coordinates in that system.
double distance(const Vector2D &rhs=Vector2D(0.0, 0.0)) const
Calculates the distance of this point to the rhs.
double unnormalizedParallelComp(const Vector2D &relativTo) const
Same as parallelComp() but assumes the given vector to be of unit length.
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
double x() const
Getter for the x coordinate.
double second() const
Getter for the second coordinate.
double normSquared() const
Calculates .
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
double y() const
Getter for the y coordinate.
double first() const
Getter for the first coordinate.
Vector2D unit() const
Returns a unit vector colaligned with this.
double norm() const
Calculates the length of the vector.
double unnormalizedOrthogonalComp(const Vector2D &relativTo) const
Same as orthogonalComp() but assumes the given vector to be of unit length.
double sqrt(double a)
sqrt for double
bool isValid(EForwardBackward eForwardBackward)
Check whether the given enum instance is one of the valid values.
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Abstract base class for different kinds of events.