8#include <tracking/trackingUtilities/geometry/PerigeeCircle.h>
10#include <tracking/trackingUtilities/geometry/PerigeeParameters.h>
12#include <tracking/trackingUtilities/geometry/Circle2D.h>
14#include <tracking/trackingUtilities/numerics/EForwardBackward.h>
15#include <tracking/trackingUtilities/numerics/ERotation.h>
16#include <tracking/trackingUtilities/numerics/Quadratic.h>
17#include <tracking/trackingUtilities/numerics/SpecialFunctions.h>
18#include <tracking/trackingUtilities/numerics/Angle.h>
29 namespace TrackingUtilities {
37using namespace TrackingUtilities;
118 double chiHalf = chi / 2.0;
120 double atX = arcLength * sinc(chi);
121 double atY = arcLength * sinc(chiHalf) * sin(chiHalf) +
impact();
122 return VectorUtil::compose(
phi0Vec(), atX, atY);
152 double newCurvature = -
impact() * denominator;
154 ROOT::Math::XYVector newPhi0Vec = -
phi0Vec();
155 double newImpact = -
curvature() / denominator;
156 return PerigeeCircle(newCurvature, newPhi0, newPhi0Vec, newImpact);
163 m_phi0Vec = ROOT::Math::XYVector(0.0, 0.0);
169 return (not std::isfinite(
phi0()) or not std::isfinite(
curvature()) or
170 not std::isfinite(
impact()) or VectorUtil::isNull(
phi0Vec()));
191 ROOT::Math::XYVector deltaVec = by -
perigee();
192 double delta = deltaVec.R();
193 double deltaParallel =
phi0Vec().Dot(deltaVec);
197 ROOT::Math::XYVector UVec =
gradient(by);
199 double USquared = UVec.Mag2();
200 double UOrthogonal = VectorUtil::Cross(
phi0Vec(), UVec);
222 jacobian(c_Curv, c_Curv) = 1;
223 jacobian(c_Curv, c_Phi0) = 0;
224 jacobian(c_Curv, c_I) = 0;
226 jacobian(c_Phi0, c_Curv) = deltaParallel / USquared;
227 jacobian(c_Phi0, c_Phi0) = -u * UOrthogonal / USquared;
230 jacobian(c_I, c_Curv) = (delta - dr) * (delta + dr) / U / 2;
231 jacobian(c_I, c_Phi0) = u * deltaParallel / U;
232 jacobian(c_I, c_I) = -UOrthogonal / U;
237 ROOT::Math::XYVector closestToPoint =
closest(point);
238 double secantLength = VectorUtil::Distance(
perigee(), closestToPoint);
239 double deltaParallel =
phi0Vec().Dot(point);
248 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
249 ROOT::Math::XYVector closestAtFrom =
closest(from);
250 ROOT::Math::XYVector closestAtTo =
closest(to);
251 double secantLength = VectorUtil::Distance(closestAtFrom, closestAtTo);
267 const double secantLength =
sqrt((delta + dr) * (delta - dr) / (1 + dr *
curvature()));
274 double x = secantLength *
curvature() / 2.0;
275 double arcLengthFactor = asinc(x);
276 return secantLength * arcLengthFactor;
282 const double orthogonal = ((square(
impact()) + square(cylindricalR)) *
curvature() / 2.0 +
impact()) / u;
283 const double parallel =
sqrt(square(cylindricalR) - square(orthogonal));
284 ROOT::Math::XYVector atCylindricalR1 = VectorUtil::compose(
phi0Vec(), -parallel, orthogonal);
285 ROOT::Math::XYVector atCylindricalR2 = VectorUtil::compose(
phi0Vec(), parallel, orthogonal);
286 std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> result(atCylindricalR1, atCylindricalR2);
291 const double cylindricalR)
const
293 std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> candidatePoints =
atCylindricalR(cylindricalR);
298 const ROOT::Math::XYVector& end1,
299 const ROOT::Math::XYVector& end2)
const
305 if (fmin(arcLength1, arcLength2) == arcLength1) {
307 }
else if (fmin(arcLength1, arcLength2) == arcLength2) {
310 return ROOT::Math::XYVector(NAN, NAN);
322 double U = std::sqrt(1 + A *
curvature());
323 return A / (1.0 + U);
328 ROOT::Math::XYVector delta = point -
perigee();
329 double deltaOrthogonal = VectorUtil::Cross(
phi0Vec(), delta);
330 return -deltaOrthogonal +
curvature() * delta.Mag2() / 2;
348 double normalization =
sqrt(
n12.Mag2() - 4 *
n0 *
n3);
358std::ostream& TrackingUtilities::operator<<(std::ostream& output,
const PerigeeCircle& circle)
360 return output <<
"PerigeeCircle("
361 <<
"curvature=" << circle.
curvature() <<
","
362 <<
"phi0=" << circle.
phi0() <<
","
363 <<
"impact=" << circle.
impact() <<
")";
A two dimensional circle in its natural representation using center and radius as parameters.
double absRadius() const
Getter for the absolute radius.
ROOT::Math::XYVector center() const
Getter for the central point of the circle.
ERotation orientation() const
Indicates if the circle is to be interpreted counterclockwise or clockwise.
A two dimensional normal line.
Extension of the generalized circle also caching the perigee coordinates.
PerigeeCircle reversed() const
Returns a copy of the circle with opposite orientation.
static PerigeeCircle fromCenterAndRadius(const ROOT::Math::XYVector ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
double m_phi0
Memory for the azimuth angle of the direction of flight at the perigee.
double n1() const
Getter for the generalised circle parameters n1.
double arcLengthTo(const ROOT::Math::XYVector &point) const
Calculates the arc length between the perigee and the given point.
ROOT::Math::XYVector gradient(const ROOT::Math::XYVector &point) const
Gradient of the distance field, hence indicates the direction of increasing distance.
double phi0() const
Getter for the azimuth angle of the direction of flight at the perigee.
double fastDistance(const ROOT::Math::XYVector &point) const
Getter for the linearised distance measure to a point.
bool isInvalid() const
Indicates if all circle parameters are zero.
void reverse()
Flips the orientation of the circle in place.
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.
void setCenterAndRadius(const ROOT::Math::XYVector ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
ROOT::Math::XYVector closest(const ROOT::Math::XYVector &point) const
Calculates the point of closest approach on the circle to the given point.
EForwardBackward isForwardOrBackwardOf(const ROOT::Math::XYVector &from, const ROOT::Math::XYVector &to) const
Indicates whether to given point lies in the forward direction from the perigee.
ROOT::Math::XYVector normal(const ROOT::Math::XYVector &point) const
Unit normal vector from the circle to the given point.
double impact() const
Getter for the signed distance of the origin to the circle.
double distance(const ROOT::Math::XYVector &point) const
Getter for the proper signed distance of the point to the circle.
double arcLengthAtDeltaLength(double delta, double dr) const
Helper method to calculate the arc length to a point at distance delta to the perigee and dr to circl...
double n3() const
Getter for the generalised circle parameter n3.
void invalidate()
Sets all circle parameters to zero.
ROOT::Math::XYVector perigee() const
Getter for the perigee point.
PerigeeParameters perigeeParameters() const
Getter for the three perigee parameters in the order defined by EPerigeeParameter....
void passiveMoveBy(const ROOT::Math::XYVector &by)
Moves the coordinates system by the given vector. Updates perigee parameters in place.
void conformalTransform()
Transforms the generalized circle to conformal space inplace.
double m_impact
Memory for the signed impact parameter.
double n2() const
Getter for the generalised circle parameters n2.
PerigeeJacobian passiveMoveByJacobian(const ROOT::Math::XYVector &by) const
Computes the Jacobi matrix for a move of the coordinate system by the given vector.
PerigeeCircle()
Default constructor for ROOT compatibility.
ROOT::Math::XYVector chooseNextForwardOf(const ROOT::Math::XYVector &start, const ROOT::Math::XYVector &end1, const ROOT::Math::XYVector &end2) const
Returns the one of two end point which is first reached from the given start if one strictly follows ...
ROOT::Math::XYVector atArcLength(double arcLength) const
Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
double m_curvature
Memory for the signed curvature.
double curvature() const
Getter for the signed curvature.
void setN(double n0, double n1, double n2, double n3=0.0)
Setter for four generalised circle parameters.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
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 arcLengthAtSecantLength(double secantLength) const
Helper method to calculate the arc length between to points on the circle from a given direct secant ...
PerigeeCircle conformalTransformed() const
Returns a copy of the circle in conformal space.
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...
ROOT::Math::XYVector center() const
Getter for the center of the circle. If it was a line both components will be infinity.
const ROOT::Math::XYVector & phi0Vec() const
Getter for the unit vector of the direction of flight at the perigee.
ROOT::Math::XYVector n12() const
Getter for the generalised circle parameters n1 and n2.
double n0() const
Getter for the generalised circle parameter n0.
ROOT::Math::XYVector m_phi0Vec
Cached unit direction of flight at the perigee.
static PerigeeCircle fromN(double n0, double n1, double n2, double n3=0)
Constructor with the four parameters of the generalized circle.
ERotation orientation() const
Getter for 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...
double sqrt(double a)
sqrt for double
bool isValid(EForwardBackward eForwardBackward)
Check whether the given enum instance is one of the valid values.
Namespace to hide the contained enum constants.
ERotation reversed(ERotation eRotation)
Return the reversed rotation. Leaves ERotation::c_Invalid the same.
Abstract base class for different kinds of events.
static void normalise(double &angle)
Normalise an angle inplace to lie in the range from [-pi, pi].
static double reversed(const double angle)
Get the angle that point in the opposite direction.
static CovarianceMatrix identity()