8#include <tracking/trackingUtilities/geometry/GeneralizedCircle.h>
10#include <tracking/trackingUtilities/geometry/Circle2D.h>
11#include <tracking/trackingUtilities/geometry/Line2D.h>
13#include <tracking/trackingUtilities/numerics/EForwardBackward.h>
14#include <tracking/trackingUtilities/numerics/ERotation.h>
16#include <tracking/trackingUtilities/numerics/SpecialFunctions.h>
17#include <tracking/trackingUtilities/numerics/Quadratic.h>
23using namespace TrackingUtilities;
65 return generalizedCircle;
74 return generalizedCircle;
83 return generalizedCircle;
105 setN(loc_n0, loc_n12, loc_n3);
119 ROOT::Math::XYVector gradientAtPoint =
gradient(point);
120 ROOT::Math::XYVector coordinateSystem = VectorUtil::unit(gradientAtPoint);
123 double closestOrthogonal = VectorUtil::Cross(
n12(), point) / gradientAtPoint.R();
126 double nOrthogonal = VectorUtil::unnormalizedOrthogonalComp(
n12(), coordinateSystem);
127 double nParallel = VectorUtil::unnormalizedParallelComp(
n12(), coordinateSystem);
129 double closestParallel = 0.0;
131 closestParallel = -(nOrthogonal * closestOrthogonal +
n0()) / nParallel;
134 const double a =
n3();
135 const double b = nParallel;
136 const double c =
n0() + (nOrthogonal +
n3() * closestOrthogonal) * closestOrthogonal;
138 const std::pair<double, double> closestParallel12 = solveQuadraticABC(a, b, c);
141 const double pointParallel = VectorUtil::unnormalizedParallelComp(point, coordinateSystem);
143 const double criterion1 =
144 closestParallel12.first * (closestParallel12.first - 2 * pointParallel);
145 const double criterion2 =
146 closestParallel12.second * (closestParallel12.second - 2 * pointParallel);
148 closestParallel = criterion1 < criterion2 ? closestParallel12.first : closestParallel12.second;
150 return VectorUtil::compose(coordinateSystem, closestParallel, closestOrthogonal);
155 ROOT::Math::XYVector result(
n12());
156 result *= (-
impact() / result.R());
162 ROOT::Math::XYVector result(
n12());
168 const ROOT::Math::XYVector& end1,
169 const ROOT::Math::XYVector& end2)
const
174 if (lengthOnCurve1 >= 0.0) {
176 if (lengthOnCurve2 >= 0.0) {
177 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
183 if (lengthOnCurve2 >= 0.0) {
192 return ROOT::Math::XYVector(NAN, NAN);
194 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
198 return ROOT::Math::XYVector(NAN, NAN);
210 const ROOT::Math::XYVector nUnit = VectorUtil::unit(
n12());
213 const double sameCylindricalRParallel = -(
n0() +
n3() * square(cylindricalR)) /
n12().R();
216 const double sameCylindricalROrthogonal =
sqrt(square(cylindricalR) - square(sameCylindricalRParallel));
219 ROOT::Math::XYVector sameCylindricalR1 =
220 VectorUtil::compose(nUnit, sameCylindricalRParallel, -sameCylindricalROrthogonal);
222 ROOT::Math::XYVector sameCylindricalR2 =
223 VectorUtil::compose(nUnit, sameCylindricalRParallel, sameCylindricalROrthogonal);
225 std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> result(sameCylindricalR1, sameCylindricalR2);
230 const double cylindricalR)
const
232 std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> candidatePoints =
atCylindricalR(cylindricalR);
242 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
244 ROOT::Math::XYVector closestAtFrom =
closest(from);
245 ROOT::Math::XYVector closestAtTo =
closest(to);
246 double directDistance = VectorUtil::Distance(closestAtFrom, closestAtTo);
248 return static_cast<double>(lengthSign) *
arcLengthFactor(directDistance) * directDistance;
253 const ROOT::Math::XYVector from =
perigee();
259 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
261 const ROOT::Math::XYVector& closestAtFrom = from;
262 ROOT::Math::XYVector closestAtTo =
closest(to);
263 double directDistance = VectorUtil::Distance(closestAtFrom, closestAtTo);
265 return static_cast<double>(lengthSign) *
arcLengthFactor(directDistance) * directDistance;
275 const double dr =
d0();
276 const double directDistance =
277 sqrt((cylindricalR + dr) * (cylindricalR - dr) / (1 + dr *
omega()));
278 const double arcLength =
arcLengthFactor(directDistance) * directDistance;
284 double x = directDistance *
curvature / 2.0;
302 const double a =
n3();
306 std::pair<double, double> distance12 = solveQuadraticABC(a, b, c);
309 return distance12.second;
313std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector>
316 const double m0 = generalizedCircle.
n0();
317 const ROOT::Math::XYVector& m12 = generalizedCircle.
n12();
318 const double m3 = generalizedCircle.
n3();
320 const double loc_n0 = this->
n0();
321 const ROOT::Math::XYVector& loc_n12 = this->
n12();
322 const double loc_n3 = this->
n3();
324 ROOT::Math::XYVector unitC = loc_n12 * m3 - m12 * loc_n3;
325 double absC = unitC.R();
327 unitC *= (1. / absC);
330 double xParallel = (m0 * loc_n3 - m3 * loc_n0) / absC;
333 ROOT::Math::XYVector mn12 = loc_n12 + m12;
334 double mn12Parallel = VectorUtil::unnormalizedParallelComp(unitC, mn12);
335 double mn12Orthogonal = VectorUtil::unnormalizedOrthogonalComp(unitC, mn12);
337 double a = m3 + loc_n3;
338 double b = mn12Orthogonal;
339 double c = (a * xParallel + mn12Parallel) * xParallel + m0 + loc_n0;
341 std::pair<double, double> xOrthogonal = solveQuadraticABC(a, b, c);
343 return std::make_pair(VectorUtil::compose(unitC, xParallel, xOrthogonal.first),
344 VectorUtil::compose(unitC, xParallel, xOrthogonal.second));
350 double chiHalf = chi / 2.0;
352 double atX = arcLength * sinc(chiHalf) * sin(chiHalf) +
impact();
353 double atY = -arcLength * sinc(chi);
354 return VectorUtil::compose(-VectorUtil::unit(
n12()), atX, atY);
357std::ostream& TrackingUtilities::operator<<(std::ostream& output,
const GeneralizedCircle& circle)
360 output <<
"Line support point = " << circle.
perigee();
363 output <<
"CircleCenter = " << circle.
center() <<
", Radius = " << circle.
absRadius();
A two dimensional circle in its natural representation using center and radius as parameters.
GeneralizedCircle()=default
Default constructor for ROOT compatibility.
ROOT::Math::XYVector tangential(const ROOT::Math::XYVector &point) const
Tangential vector to the circle near the given position.
static GeneralizedCircle fromPerigeeParameters(double curvature, const ROOT::Math::XYVector &tangential, double impact)
Constructor of a generalized circle from perigee parameters.
double m_n3
Memory for the fourth parameter.
double n1() const
Getter for the second circle parameter.
ROOT::Math::XYVector gradient(const ROOT::Math::XYVector &point) const
Gradient of the distance field Gives the gradient of the approximated distance field for the given po...
bool isLine() const
Indicates if the generalized circle is actually a line.
ROOT::Math::XYVector apogee() const
Calculates the point on the circle that is furthest away from the origin.
double fastDistance(const ROOT::Math::XYVector &point) const
Approximate distance.
void setN0(const double n0)
Setter for first circle parameter.
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.
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
static GeneralizedCircle fromCenterAndRadius(const ROOT::Math::XYVector ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
void setCenterAndRadius(const ROOT::Math::XYVector ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
const ROOT::Math::XYVector & n12() const
Getter for the second and third circle parameter which natuarally from a vector.
void setN2(const double n2)
Setter for third circle parameter.
ROOT::Math::XYVector closest(const ROOT::Math::XYVector &point) const
Closest approach on the circle to the point.
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.
EForwardBackward isForwardOrBackwardOf(const ROOT::Math::XYVector &from, const ROOT::Math::XYVector &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.
std::pair< ROOT::Math::XYVector, ROOT::Math::XYVector > intersections(const GeneralizedCircle &generalizedCircle) const
Calculates the two points common to both circles.
double distance(const ROOT::Math::XYVector &point) const
Gives the proper distance of the point to the circle line retaining the sign of the fast distance.
double arcLengthTo(const ROOT::Math::XYVector &to) const
Calculates the arc length between the perigee and the given point.
double n3() const
Getter for the fourth circle parameter.
ROOT::Math::XYVector perigee() const
Calculates the closest approach to the two dimensional origin.
double n2() const
Getter for the third circle parameter.
ROOT::Math::XYVector chooseNextForwardOf(const ROOT::Math::XYVector &start, const ROOT::Math::XYVector &end1, const ROOT::Math::XYVector &end2) const
Returns the end point which is first reached if one follows the forward direction of the circle start...
ROOT::Math::XYVector atArcLength(double arcLength) const
Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
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.
void setPerigeeParameters(double curvature, const ROOT::Math::XYVector &tangential, double impact)
Setter for the perigee parameters.
std::pair< ROOT::Math::XYVector, ROOT::Math::XYVector > atCylindricalR(double cylindricalR) const
Calculates the two points with the given cylindrical radius on the generalised circle.
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...
ROOT::Math::XYVector atCylindricalRForwardOf(const ROOT::Math::XYVector &startPoint, double cylindricalR) const
Approach on the circle with the given cylindrical radius that lies in the forward direction of a star...
void normalize()
Normalizes the circle parameters.
double tangentialPhi() const
Gives to azimuth angle phi of the direction of flight at the perigee.
ROOT::Math::XYVector center() const
Gives the center of the circle. If it was a line both components will be infinity.
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...
ROOT::Math::XYVector m_n12
Memory for the second and third parameter.
A two dimensional normal line.
double sqrt(double a)
sqrt for double
bool isValid(EForwardBackward eForwardBackward)
Check whether the given enum instance is one of the valid values.
Abstract base class for different kinds of events.