Belle II Software development
GeneralizedCircle Class Reference

A generalized circle. More...

#include <GeneralizedCircle.h>

Public Member Functions

 GeneralizedCircle ()=default
 Default constructor for ROOT compatibility.
 
 GeneralizedCircle (double n0, double n1, double n2, double n3=0)
 Constructor with the four parameters of the generalized circle.
 
 GeneralizedCircle (double n0, const ROOT::Math::XYVector &n12, double n3=0)
 Constructor with the four parameters of the generalized circle.
 
 GeneralizedCircle (const Line2D &n012)
 Constructor from a two dimensional line.
 
 GeneralizedCircle (const Circle2D &circle)
 Constructor from a two dimensional circle.
 
void setCenterAndRadius (const ROOT::Math::XYVector &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
 Setter for the circle center and radius.
 
void setPerigeeParameters (double curvature, const ROOT::Math::XYVector &tangential, double impact)
 Setter for the perigee parameters.
 
void setPerigeeParameters (const double curvature, const double tangentialPhi, const double impact)
 Setter for the perigee parameters.
 
void setN (const double n0, const double n1, const double n2, const double n3=0.0)
 Setter for all four circle parameters.
 
void setN (const double n0, const ROOT::Math::XYVector &n12, const double n3=0.0)
 Setter for all four circle parameters.
 
void setN (const Line2D &n012)
 Setter for all four circle parameters from another circle.
 
void setN (const GeneralizedCircle &n0123)
 Setter for all four circle parameters from another circle.
 
void invalidate ()
 Sets all circle parameters to zero.
 
void reverse ()
 Flips the orientation of the circle in place.
 
void conformalTransform ()
 Transforms the generalized circle to conformal space inplace Applies the conformal map in the self-inverse form X = x / (x^2 + y^2) and Y = y / (x^2 +y^2) inplace It works most easily by the exchange of the circle parameters n0 <-> n3.
 
void passiveMoveBy (const ROOT::Math::XYVector &by)
 Moves the coordinate system by the given vector.
 
double n0 () const
 Getter for the first circle parameter.
 
double n1 () const
 Getter for the second circle parameter.
 
double n2 () const
 Getter for the third circle parameter.
 
const ROOT::Math::XYVector & n12 () const
 Getter for the second and third circle parameter which natuarally from a vector.
 
double n3 () const
 Getter for the fourth circle parameter.
 
bool isInvalid () const
 Indicates if all circle parameters are zero.
 
bool isValid () const
 Indicates if the combination of the circle parameters makes up a valid circle.
 
double normalizationSquared () const
 Calculates the generalized circle specific squared norm.
 
GeneralizedCircle reversed () const
 Returns a copy of the circle with opposite orientation.
 
GeneralizedCircle conformalTransformed () const
 Returns a copy of the circle in conformal space.
 
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 point.
 
ROOT::Math::XYVector normal (const ROOT::Math::XYVector &point) const
 Normal vector to the circle near the given position.
 
ROOT::Math::XYVector tangential (const ROOT::Math::XYVector &point) const
 Tangential vector to the circle near the given position.
 
ROOT::Math::XYVector closest (const ROOT::Math::XYVector &point) const
 Closest approach on the circle to the point.
 
ROOT::Math::XYVector perigee () const
 Calculates the closest approach to the two dimensional origin.
 
ROOT::Math::XYVector apogee () const
 Calculates the point on the circle that is furthest away from the origin.
 
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 circle or against.
 
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 starting from the start point.
 
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.
 
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 start point.
 
double fastDistance (const ROOT::Math::XYVector &point) const
 Approximate distance.
 
double fastImpact () const
 Approximate distance to the origin.
 
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 distance (double fastDistance) const
 Helper function to translate the fast linearized distance measure of the generalized circle to the proper distance from the circle retaining the sign of the distance.
 
double fastDistance (const double distance) const
 Helper function to translate the proper distance to the linearized distance measure of the generalized circle retaining the sign of the distance.
 
double impact () const
 Gives the signed distance of the origin to the circle.
 
double d0 () const
 Getter for the absolute distance to the z axes at the support point.
 
ROOT::Math::XYVector tangential () const
 Gives the tangential vector at the closest approach to the origin / at the perigee.
 
double tangentialPhi () const
 Gives to azimuth angle phi of the direction of flight at the perigee.
 
double minimalCylindricalR () const
 Gives the minimal cylindrical radius the circle reaches (unsigned)
 
double maximalCylindricalR () const
 Gives the maximal cylindrical radius the circle reaches.
 
double absDistance (const ROOT::Math::XYVector &point) const
 Gives the proper absolute distance of the point to the circle line.
 
ERightLeft isRightOrLeft (const ROOT::Math::XYVector &point) const
 Indicates if the point is on the right or left side of the circle.
 
bool isLeft (const ROOT::Math::XYVector &rhs) const
 Return if the point given is left of the line.
 
bool isRight (const ROOT::Math::XYVector &rhs) const
 Return if the point given is right of the line.
 
bool isLine () const
 Indicates if the generalized circle is actually a line.
 
bool isCircle () const
 Indicates if the generalized circle is actually a circle.
 
double radius () const
 Gives the signed radius of the circle. If it was a line this will be infinity.
 
double absRadius () const
 Gives the signed radius of the circle. If it was a line this will be infinity.
 
double curvature () const
 Gives the signed curvature of the generalized circle.
 
double omega () const
 Gives the omega parameter as used by the framework helix.
 
ROOT::Math::XYVector center () const
 Gives the center of the circle. If it was a line both components will be infinity.
 
double perimeter () const
 Gives the perimeter of the circle.
 
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 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 arcLengthTo (const ROOT::Math::XYVector &to) const
 Calculates the arc length between the perigee and the given point.
 
double arcLengthToCylindricalR (double cylindricalR) const
 Calculates the two dimensional arc length till the cylindrical radius is reached If the radius can not be reached return NAN.
 
double arcLengthFactor (const double directDistance) const
 Helper function the calculate the factor between the length of a secant line and the length on the arc.
 
std::pair< ROOT::Math::XYVector, ROOT::Math::XYVector > intersections (const GeneralizedCircle &generalizedCircle) const
 Calculates the two points common to both circles.
 
ROOT::Math::XYVector atArcLength (double arcLength) const
 Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
 

Static Public Member Functions

static GeneralizedCircle fromCenterAndRadius (const ROOT::Math::XYVector &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
 Constructor from center, radius and a optional orientation.
 
static GeneralizedCircle fromPerigeeParameters (double curvature, const ROOT::Math::XYVector &tangential, double impact)
 Constructor of a generalized circle from perigee parameters.
 
static GeneralizedCircle fromPerigeeParameters (double curvature, double tangentialPhi, double impact)
 Constructor of a generalized circle from perigee parameters.
 
static double arcLengthFactor (double directDistance, double curvature)
 Helper function the calculate the factor between the length of a secant line and the length on the arc.
 

Protected Member Functions

void setN0 (const double n0)
 Setter for first circle parameter.
 
void setN1 (const double n1)
 Setter for second circle parameter.
 
void setN2 (const double n2)
 Setter for third circle parameter.
 
void setN12 (const double n1, const double n2)
 Setter for second and third circle parameter.
 
void setN12 (const ROOT::Math::XYVector &n12)
 Setter for second and third circle parameter.
 
void setN3 (const double n3)
 Setter for fourth circle parameter.
 
void normalize ()
 Normalizes the circle parameters.
 

Private Member Functions

void scaleN (const double factor)
 Scales the circle parameters by a common factor.
 

Private Attributes

double m_n3 = 0.0
 Memory for the fourth parameter.
 
ROOT::Math::XYVector m_n12
 Memory for the second and third parameter.
 
double m_n0 = 0.0
 Memory for the first parameter.
 

Detailed Description

A generalized circle.

Makes a smooth generalization from a two dimensional normal line ( like Line2D ) to a circle.

The parameterisation is best suited for low curvature circle. The representation takes four parameters. They correspond to the normal circle parameters like
n0 = (m_x*m_x + m_y*m_y - r*r)/2r
n1 = -m_x/r
n2 = -m_y/r
n3 = 1/2r
where the normalization condition is n1*n1 + n2*n2 - 4 * n0 * n3 = 1. The overall sign is fixed in the following way: If the last parameter is positive the circle is assumed to be orientated counterclockwise else the circle is assumed to be orientated clockwise. The parameters n1 and n2 are indeed a vector in two dimensions and we keep them stored as ROOT::Math::XYVector. Additionally we can represent a line with same parameters by setting n3 = 0. Compare Line2D.

Definition at line 53 of file GeneralizedCircle.h.

Constructor & Destructor Documentation

◆ GeneralizedCircle() [1/4]

GeneralizedCircle ( double n0,
double n1,
double n2,
double n3 = 0 )

Constructor with the four parameters of the generalized circle.

Definition at line 25 of file GeneralizedCircle.cc.

29 : m_n3(n3)
30 , m_n12(n1, n2)
31 , m_n0(n0)
32{
33 normalize();
34}
double m_n3
Memory for the fourth parameter.
double n1() const
Getter for the second circle parameter.
double m_n0
Memory for the first parameter.
double n3() const
Getter for the fourth circle parameter.
double n2() const
Getter for the third circle parameter.
void normalize()
Normalizes the circle parameters.
double n0() const
Getter for the first circle parameter.
ROOT::Math::XYVector m_n12
Memory for the second and third parameter.

◆ GeneralizedCircle() [2/4]

GeneralizedCircle ( double n0,
const ROOT::Math::XYVector & n12,
double n3 = 0 )

Constructor with the four parameters of the generalized circle.

Definition at line 36 of file GeneralizedCircle.cc.

37 : m_n3(n3)
38 , m_n12(n12)
39 , m_n0(n0)
40{
41 normalize();
42}
const ROOT::Math::XYVector & n12() const
Getter for the second and third circle parameter which natuarally from a vector.

◆ GeneralizedCircle() [3/4]

GeneralizedCircle ( const Line2D & n012)
explicit

Constructor from a two dimensional line.

Definition at line 44 of file GeneralizedCircle.cc.

45 : m_n3(0.0)
46 , m_n12(n012.n12())
47 , m_n0(n012.n0())
48{
49 normalize();
50}
const ROOT::Math::XYVector & n12() const
Getter for the unit normal vector to the line.
Definition Line2D.h:119
double n0() const
Getter for the first line parameter.
Definition Line2D.h:101

◆ GeneralizedCircle() [4/4]

GeneralizedCircle ( const Circle2D & circle)
explicit

Constructor from a two dimensional circle.

Definition at line 52 of file GeneralizedCircle.cc.

53 : m_n3(1.0 / 2.0 / circle.radius())
54 , m_n12(-circle.center().x() * (m_n3 * 2.0), -circle.center().y() * (m_n3 * 2.0))
55 , m_n0((circle.center().Mag2() - circle.radiusSquared()) * m_n3)
56{
57}
double radius() const
Getter for the signed radius.
Definition Circle2D.h:207
double radiusSquared() const
Getter for the squared radius.
Definition Circle2D.h:213
ROOT::Math::XYVector center() const
Getter for the central point of the circle.
Definition Circle2D.h:231

Member Function Documentation

◆ absDistance()

double absDistance ( const ROOT::Math::XYVector & point) const
inline

Gives the proper absolute distance of the point to the circle line.

Definition at line 531 of file GeneralizedCircle.h.

532 {
533 return fabs(distance(point));
534 }

◆ absRadius()

double absRadius ( ) const
inline

Gives the signed radius of the circle. If it was a line this will be infinity.

Definition at line 576 of file GeneralizedCircle.h.

577 {
578 return fabs(radius());
579 }

◆ apogee()

ROOT::Math::XYVector apogee ( ) const

Calculates the point on the circle that is furthest away from the origin.

This results in ROOT::Math::XYVector(NAN, NAN) in the straight line case.

Definition at line 160 of file GeneralizedCircle.cc.

161{
162 ROOT::Math::XYVector result(n12());
163 result *= ((-impact() - 2 * radius()) / result.R());
164 return result;
165}
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
double impact() const
Gives the signed distance of the origin to the circle.

◆ arcLengthBetween()

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.

The arc length is signed positive for travel in orientation direction. In the circle case the arc length is between -pi*radius and pi*radius, hence the discontinuity is on the far side of the circle relative to the given from point. The points are essentially first taken to their closest approach before we take the length on the curve. For the line case the length is the distance component parallel to the line.

Definition at line 236 of file GeneralizedCircle.cc.

237{
238 EForwardBackward lengthSign = isForwardOrBackwardOf(from, to);
239 if (not NForwardBackward::isValid(lengthSign)) return NAN;
240
241 // Handling the rare case that from and to correspond to opposing points on the circle
242 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
243
244 ROOT::Math::XYVector closestAtFrom = closest(from);
245 ROOT::Math::XYVector closestAtTo = closest(to);
246 double directDistance = VectorUtil::Distance(closestAtFrom, closestAtTo);
247
248 return static_cast<double>(lengthSign) * arcLengthFactor(directDistance) * directDistance;
249}
ROOT::Math::XYVector closest(const ROOT::Math::XYVector &point) const
Closest approach on the circle to the point.
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 arcLengthFactor(const double directDistance) const
Helper function the calculate the factor between the length of a secant line and the length on the ar...
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.

◆ arcLengthFactor() [1/2]

double arcLengthFactor ( const double directDistance) const
inline

Helper function the calculate the factor between the length of a secant line and the length on the arc.

Smooth function expressing the relation between arc length and direct length only using the curvature of the circle as additional information. It enables better handling of the line limit compared to the former implementation which used the opening angle of the arc.

Definition at line 656 of file GeneralizedCircle.h.

657 {
658 return arcLengthFactor(directDistance, curvature());
659 }

◆ arcLengthFactor() [2/2]

double arcLengthFactor ( double directDistance,
double curvature )
static

Helper function the calculate the factor between the length of a secant line and the length on the arc.

Smooth function expressing the relation between arc length and direct length only using the curvature of the circle as additional information. It enables better handling of the line limit compared to the former implementation which used the opening angle of the arc.

Definition at line 282 of file GeneralizedCircle.cc.

283{
284 double x = directDistance * curvature / 2.0;
285 return asinc(x);
286}
double curvature() const
Gives the signed curvature of the generalized circle.

◆ arcLengthPeriod()

double arcLengthPeriod ( ) const
inline

Getter for the arc length for a full round of the circle.

Definition at line 621 of file GeneralizedCircle.h.

622 {
623 return std::fabs(perimeter());
624 }

◆ arcLengthTo()

double arcLengthTo ( const ROOT::Math::XYVector & to) const

Calculates the arc length between the perigee and the given point.

Definition at line 251 of file GeneralizedCircle.cc.

252{
253 const ROOT::Math::XYVector from = perigee();
254
255 EForwardBackward lengthSign = isForwardOrBackwardOf(from, to);
256 if (not NForwardBackward::isValid(lengthSign)) return NAN;
257
258 // Handling the rare case that from and to correspond to opposing points on the circle
259 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
260
261 const ROOT::Math::XYVector& closestAtFrom = from;
262 ROOT::Math::XYVector closestAtTo = closest(to);
263 double directDistance = VectorUtil::Distance(closestAtFrom, closestAtTo);
264
265 return static_cast<double>(lengthSign) * arcLengthFactor(directDistance) * directDistance;
266}
ROOT::Math::XYVector perigee() const
Calculates the closest approach to the two dimensional origin.

◆ arcLengthToCylindricalR()

double arcLengthToCylindricalR ( double cylindricalR) const

Calculates the two dimensional arc length till the cylindrical radius is reached If the radius can not be reached return NAN.

Note that there are two solutions which have equivalent arc lengths with different sign Always return the positive solution.

Definition at line 268 of file GeneralizedCircle.cc.

269{
270 // Slight trick here
271 // Since the sought point is on the helix we treat it as the perigee
272 // and the origin as the point to extrapolate to.
273 // We know the distance of the origin to the circle, which is just d0
274 // The direct distance from the origin to the imaginary perigee is just the given cylindricalR.
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;
279 return arcLength;
280}
double omega() const
Gives the omega parameter as used by the framework helix.
double d0() const
Getter for the absolute distance to the z axes at the support point.
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28

◆ atArcLength()

ROOT::Math::XYVector atArcLength ( double arcLength) const

Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)

Definition at line 347 of file GeneralizedCircle.cc.

348{
349 double chi = arcLength * curvature();
350 double chiHalf = chi / 2.0;
351
352 double atX = arcLength * sinc(chiHalf) * sin(chiHalf) + impact();
353 double atY = -arcLength * sinc(chi);
354 return VectorUtil::compose(-VectorUtil::unit(n12()), atX, atY);
355}

◆ atCylindricalR()

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.

Two versions in this case

Definition at line 201 of file GeneralizedCircle.cc.

202{
203 // extraploted to r
204 // solve
205 // n0 + n1*x + n2*y + n3*r*r == 0
206 // and r = cylindricalR
207 // search for x and y
208
209 // solve the equation in a coordinate system parallel and orthogonal to the reduced circle center
210 const ROOT::Math::XYVector nUnit = VectorUtil::unit(n12());
211
212 // parallel component
213 const double sameCylindricalRParallel = -(n0() + n3() * square(cylindricalR)) / n12().R();
214
215 // orthogonal component
216 const double sameCylindricalROrthogonal = sqrt(square(cylindricalR) - square(sameCylindricalRParallel));
217
219 ROOT::Math::XYVector sameCylindricalR1 =
220 VectorUtil::compose(nUnit, sameCylindricalRParallel, -sameCylindricalROrthogonal);
221
222 ROOT::Math::XYVector sameCylindricalR2 =
223 VectorUtil::compose(nUnit, sameCylindricalRParallel, sameCylindricalROrthogonal);
224
225 std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> result(sameCylindricalR1, sameCylindricalR2);
226 return result;
227}
constexpr T square(const T &x)
Calculate the square of the input.
Definition MathHelpers.h:21

◆ atCylindricalRForwardOf()

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 start point.

Calculates the point on the circle with cylindrical radius cylindricalR, which is closest following the circle in the direction of positive forward orientation This is particularly useful to extraplotate into a certain layer. In case no intersection with this cylindrical radius exists the function returns ROOT::Math::XYVector(NAN,NAN)

Parameters
startPointStart point from which to follow in the circle in the forward direction
cylindricalRCylindrical radius of interest
Returns
Close point in forward direction with same cylindrical radius on the circle.

Definition at line 229 of file GeneralizedCircle.cc.

231{
232 std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> candidatePoints = atCylindricalR(cylindricalR);
233 return chooseNextForwardOf(startPoint, candidatePoints.first, candidatePoints.second);
234}
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...
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.

◆ center()

ROOT::Math::XYVector center ( ) const
inline

Gives the center of the circle. If it was a line both components will be infinity.

Definition at line 597 of file GeneralizedCircle.h.

598 {
599 ROOT::Math::XYVector tmp = n12();
600 return tmp / (-2. * n3());
601 }

◆ chooseNextForwardOf()

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 starting from the start point.

Evaluates which of the given end points end1 and end2 is closer to start This especially treats the discontinuity on the far side of the circle correctly. If the generalized circle is truly a line none of the points might lie in the forward direction and ROOT::Math::XYVector(NAN,NAN) is returned.

Parameters
startPoint to start the traversal
end1One possible end point
end2Other possible end point
Returns
end1 or end2 depending, which lies closer to start in the forward direction or ROOT::Math::XYVector(NAN,NAN) if neither end1 nor end2 are reachable in the forward direction (line case only)

Definition at line 167 of file GeneralizedCircle.cc.

170{
171 double lengthOnCurve1 = arcLengthBetween(start, end1);
172 double lengthOnCurve2 = arcLengthBetween(start, end2);
173
174 if (lengthOnCurve1 >= 0.0) {
175
176 if (lengthOnCurve2 >= 0.0) {
177 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
178 } else {
179 return end1;
180 }
181 } else {
182
183 if (lengthOnCurve2 >= 0.0) {
184 return end2;
185 } else {
186
187 // both lengths on curve have a negative sign
188 // the candidate with the lesser length on curve wins because of the discontinuaty
189 // unless the generalized circle is a line
190 // in this case their is no forward intersection with the same cylindrical radius
191 if (isLine()) {
192 return ROOT::Math::XYVector(NAN, NAN);
193 } else {
194 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
195 }
196 }
197 }
198 return ROOT::Math::XYVector(NAN, NAN); // just avoid a compiler warning
199}
bool isLine() const
Indicates if the generalized circle is actually a line.
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.

◆ closest()

ROOT::Math::XYVector closest ( const ROOT::Math::XYVector & point) const

Closest approach on the circle to the point.

Calculates the closest point on the circle relative to the given point.

Parameters
pointPoint in the plane to calculate the closest approach to
Returns
Point of closest approach on the circle.

Definition at line 108 of file GeneralizedCircle.cc.

109{
110 if (fastDistance(point) == 0) return point;
111
112 // solve the minimization | point - pointOnCirlce | ^2 subjected to the on circle constraint
113 // 1.0 * m_n0 +
114 // point.x() * m_n1 +
115 // point.y() * m_n2 +
116 // point.cylindricalRSquared() * m_n3 == 0
117 // solved with a Lagrangian multiplicator for the constraint
118
119 ROOT::Math::XYVector gradientAtPoint = gradient(point);
120 ROOT::Math::XYVector coordinateSystem = VectorUtil::unit(gradientAtPoint);
121
122 // component of closest approach orthogonal to coordinateSystem
123 double closestOrthogonal = VectorUtil::Cross(n12(), point) / gradientAtPoint.R();
124
125 // component of closest approach parallel to coordinateSystem - two solutions expected
126 double nOrthogonal = VectorUtil::unnormalizedOrthogonalComp(n12(), coordinateSystem);
127 double nParallel = VectorUtil::unnormalizedParallelComp(n12(), coordinateSystem);
128
129 double closestParallel = 0.0;
130 if (isLine()) {
131 closestParallel = -(nOrthogonal * closestOrthogonal + n0()) / nParallel;
132
133 } else {
134 const double a = n3();
135 const double b = nParallel;
136 const double c = n0() + (nOrthogonal + n3() * closestOrthogonal) * closestOrthogonal;
137
138 const std::pair<double, double> closestParallel12 = solveQuadraticABC(a, b, c);
139
140 // take the solution with smaller distance to point
141 const double pointParallel = VectorUtil::unnormalizedParallelComp(point, coordinateSystem);
142
143 const double criterion1 =
144 closestParallel12.first * (closestParallel12.first - 2 * pointParallel);
145 const double criterion2 =
146 closestParallel12.second * (closestParallel12.second - 2 * pointParallel);
147
148 closestParallel = criterion1 < criterion2 ? closestParallel12.first : closestParallel12.second;
149 }
150 return VectorUtil::compose(coordinateSystem, closestParallel, closestOrthogonal);
151}
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...
double fastDistance(const ROOT::Math::XYVector &point) const
Approximate distance.

◆ conformalTransform()

void conformalTransform ( )
inline

Transforms the generalized circle to conformal space inplace Applies the conformal map in the self-inverse form X = x / (x^2 + y^2) and Y = y / (x^2 +y^2) inplace It works most easily by the exchange of the circle parameters n0 <-> n3.

Definition at line 231 of file GeneralizedCircle.h.

232 {
233 std::swap(m_n0, m_n3);
234 reverse(); // Correct orientation
235 }

◆ conformalTransformed()

GeneralizedCircle conformalTransformed ( ) const
inline

Returns a copy of the circle in conformal space.

Applies the conformal map in the self-inverse from X = x / (x^2 + y^2) and Y = y / (x^2 +y^2) and returns the result as a new GeneralizedCircle. It works most easily by the exchange of the circle parameters n0 <-> n3

Definition at line 337 of file GeneralizedCircle.h.

338 {
339 return GeneralizedCircle(-n3(), -n12(), -n0());
340 }

◆ curvature()

double curvature ( ) const
inline

Gives the signed curvature of the generalized circle.

Definition at line 582 of file GeneralizedCircle.h.

583 {
584 return 2 * n3();
585 }

◆ d0()

double d0 ( ) const
inline

Getter for the absolute distance to the z axes at the support point.

Definition at line 501 of file GeneralizedCircle.h.

502 {
503 return -impact();
504 }

◆ distance() [1/2]

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.

Definition at line 288 of file GeneralizedCircle.cc.

289{
290 const double fastD = fastDistance(point);
291 return distance(fastD);
292}
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.

◆ distance() [2/2]

double distance ( double fastDistance) const

Helper function to translate the fast linearized distance measure of the generalized circle to the proper distance from the circle retaining the sign of the distance.

Definition at line 294 of file GeneralizedCircle.cc.

295{
296 if (fastDistance == 0.0 or isLine()) {
297 // special case for unfitted state
298 // and line
299 return fastDistance;
300 } else {
301
302 const double a = n3();
303 const double b = 1;
304 const double c = -fastDistance;
305
306 std::pair<double, double> distance12 = solveQuadraticABC(a, b, c);
307
308 // take the small solution which has always the same sign of the fastDistance
309 return distance12.second;
310 }
311}

◆ fastDistance() [1/2]

double fastDistance ( const double distance) const
inline

Helper function to translate the proper distance to the linearized distance measure of the generalized circle retaining the sign of the distance.

Definition at line 489 of file GeneralizedCircle.h.

490 {
491 return (distance * n3() + 1.0) * distance;
492 }

◆ fastDistance() [2/2]

double fastDistance ( const ROOT::Math::XYVector & point) const
inline

Approximate distance.

Gives a fast signed approximation of the distance to the circle. The absolute value of the fast distance is accurate up to first order of distance/circle radius, hence best used with big circles and small distances. The sign of the fast distance indicates if the point is to the right or to the left of the circle.

Definition at line 461 of file GeneralizedCircle.h.

462 {
463 return n0() + point.Dot(n12()) + point.Mag2() * n3();
464 }

◆ fastImpact()

double fastImpact ( ) const
inline

Approximate distance to the origin.

Definition at line 467 of file GeneralizedCircle.h.

468 {
469 return n0();
470 }

◆ fromCenterAndRadius()

GeneralizedCircle fromCenterAndRadius ( const ROOT::Math::XYVector & center,
double absRadius,
ERotation orientation = ERotation::c_CounterClockwise )
static

Constructor from center, radius and a optional orientation.

The center and radius alone do not carry any orientation. However the generalized circle does. This constructor makes an orientated representation from them. If not given the orientation defaults to mathematical positive counterclockwise.

Definition at line 59 of file GeneralizedCircle.cc.

62{
63 GeneralizedCircle generalizedCircle;
65 return generalizedCircle;
66}
GeneralizedCircle()=default
Default constructor for ROOT compatibility.
void setCenterAndRadius(const ROOT::Math::XYVector &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
ROOT::Math::XYVector center() const
Gives the center of the circle. If it was a line both components will be infinity.
ERotation orientation() const
Gives the orientation of the circle.

◆ fromPerigeeParameters() [1/2]

GeneralizedCircle fromPerigeeParameters ( double curvature,
const ROOT::Math::XYVector & tangential,
double impact )
static

Constructor of a generalized circle from perigee parameters.

Tangential at perigee given as two dimensional vector.

Definition at line 68 of file GeneralizedCircle.cc.

71{
72 GeneralizedCircle generalizedCircle;
74 return generalizedCircle;
75}
ROOT::Math::XYVector tangential(const ROOT::Math::XYVector &point) const
Tangential vector to the circle near the given position.
void setPerigeeParameters(double curvature, const ROOT::Math::XYVector &tangential, double impact)
Setter for the perigee parameters.

◆ fromPerigeeParameters() [2/2]

GeneralizedCircle fromPerigeeParameters ( double curvature,
double tangentialPhi,
double impact )
static

Constructor of a generalized circle from perigee parameters.

Tangential at perigee given as azimuth angle.

Definition at line 77 of file GeneralizedCircle.cc.

80{
81 GeneralizedCircle generalizedCircle;
83 return generalizedCircle;
84}
double tangentialPhi() const
Gives to azimuth angle phi of the direction of flight at the perigee.

◆ gradient()

ROOT::Math::XYVector gradient ( const ROOT::Math::XYVector & point) const
inline

Gradient of the distance field Gives the gradient of the approximated distance field for the given point.

Parameters
pointPoint in the plane to calculate the gradient
Returns
Gradient of the distance field

Definition at line 349 of file GeneralizedCircle.h.

350 {
351 return point * (2.0 * n3()) + n12();
352 }

◆ impact()

double impact ( ) const
inline

Gives the signed distance of the origin to the circle.

Definition at line 495 of file GeneralizedCircle.h.

496 {
497 return distance(fastImpact());
498 }

◆ intersections()

std::pair< ROOT::Math::XYVector, ROOT::Math::XYVector > intersections ( const GeneralizedCircle & generalizedCircle) const

Calculates the two points common to both circles.

If the two points coincide both returned points are the same. If there is no common point both returned points will be made of NAN.

Definition at line 314 of file GeneralizedCircle.cc.

315{
316 const double m0 = generalizedCircle.n0();
317 const ROOT::Math::XYVector& m12 = generalizedCircle.n12();
318 const double m3 = generalizedCircle.n3();
319
320 const double loc_n0 = this->n0();
321 const ROOT::Math::XYVector& loc_n12 = this->n12();
322 const double loc_n3 = this->n3();
323
324 ROOT::Math::XYVector unitC = loc_n12 * m3 - m12 * loc_n3;
325 double absC = unitC.R();
326 if (absC != 0.0) {
327 unitC *= (1. / absC);
328 }
329
330 double xParallel = (m0 * loc_n3 - m3 * loc_n0) / absC;
331
332 // Use symmetric solution and use all input parameters
333 ROOT::Math::XYVector mn12 = loc_n12 + m12;
334 double mn12Parallel = VectorUtil::unnormalizedParallelComp(unitC, mn12);
335 double mn12Orthogonal = VectorUtil::unnormalizedOrthogonalComp(unitC, mn12);
336
337 double a = m3 + loc_n3;
338 double b = mn12Orthogonal;
339 double c = (a * xParallel + mn12Parallel) * xParallel + m0 + loc_n0;
340
341 std::pair<double, double> xOrthogonal = solveQuadraticABC(a, b, c);
342
343 return std::make_pair(VectorUtil::compose(unitC, xParallel, xOrthogonal.first),
344 VectorUtil::compose(unitC, xParallel, xOrthogonal.second));
345}

◆ invalidate()

void invalidate ( )
inline

Sets all circle parameters to zero.

Definition at line 214 of file GeneralizedCircle.h.

215 {
216 setN(0.0, 0.0, 0.0, 0.0);
217 }

◆ isCircle()

bool isCircle ( ) const
inline

Indicates if the generalized circle is actually a circle.

Definition at line 564 of file GeneralizedCircle.h.

565 {
566 return n3() != 0.0;
567 }

◆ isForwardOrBackwardOf()

EForwardBackward isForwardOrBackwardOf ( const ROOT::Math::XYVector & from,
const ROOT::Math::XYVector & to ) const
inline

Calculates if the to vector is closer to the from vector following the along orientation of the circle or against.

Returns
  • EForwardBackward::c_Forward in case the to vector is closer following the along the orientation
  • EForwardBackward::c_Backward in case the to vector is closer against the orientation.
  • EForwardBackward::c_Unknown if neither can be determined.

Definition at line 410 of file GeneralizedCircle.h.

411 {
412 ROOT::Math::XYVector difference = to - from;
413 ROOT::Math::XYVector tangentialAtFrom = tangential(from);
414 return VectorUtil::isForwardOrBackwardOf(tangentialAtFrom, difference);
415 }

◆ isInvalid()

bool isInvalid ( ) const
inline

Indicates if all circle parameters are zero.

Definition at line 302 of file GeneralizedCircle.h.

303 {
304 return n0() == 0 and VectorUtil::isNull(n12()) and n3() == 0;
305 }

◆ isLeft()

bool isLeft ( const ROOT::Math::XYVector & rhs) const
inline

Return if the point given is left of the line.

Definition at line 546 of file GeneralizedCircle.h.

547 {
548 return isRightOrLeft(rhs) == ERightLeft::c_Left;
549 }

◆ isLine()

bool isLine ( ) const
inline

Indicates if the generalized circle is actually a line.

Definition at line 558 of file GeneralizedCircle.h.

559 {
560 return n3() == 0.0;
561 }

◆ isRight()

bool isRight ( const ROOT::Math::XYVector & rhs) const
inline

Return if the point given is right of the line.

Definition at line 552 of file GeneralizedCircle.h.

553 {
554 return isRightOrLeft(rhs) == ERightLeft::c_Right;
555 }

◆ isRightOrLeft()

ERightLeft isRightOrLeft ( const ROOT::Math::XYVector & point) const
inline

Indicates if the point is on the right or left side of the circle.

This is also referred to as alpha.

Definition at line 540 of file GeneralizedCircle.h.

541 {
542 return static_cast<ERightLeft>(sign(fastDistance(point)));
543 }
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition ERightLeft.h:25

◆ isValid()

bool isValid ( ) const
inline

Indicates if the combination of the circle parameters makes up a valid circle.

Definition at line 308 of file GeneralizedCircle.h.

309 {
310 return not isInvalid();
311 }

◆ maximalCylindricalR()

double maximalCylindricalR ( ) const
inline

Gives the maximal cylindrical radius the circle reaches.

Definition at line 525 of file GeneralizedCircle.h.

526 {
527 return std::fabs(impact() + 2 * radius());
528 }

◆ minimalCylindricalR()

double minimalCylindricalR ( ) const
inline

Gives the minimal cylindrical radius the circle reaches (unsigned)

Definition at line 519 of file GeneralizedCircle.h.

520 {
521 return std::fabs(impact());
522 }

◆ n0()

double n0 ( ) const
inline

Getter for the first circle parameter.

Definition at line 271 of file GeneralizedCircle.h.

272 {
273 return m_n0;
274 }

◆ n1()

double n1 ( ) const
inline

Getter for the second circle parameter.

Definition at line 277 of file GeneralizedCircle.h.

278 {
279 return m_n12.x();
280 }

◆ n12()

const ROOT::Math::XYVector & n12 ( ) const
inline

Getter for the second and third circle parameter which natuarally from a vector.

Definition at line 289 of file GeneralizedCircle.h.

290 {
291 return m_n12;
292 }

◆ n2()

double n2 ( ) const
inline

Getter for the third circle parameter.

Definition at line 283 of file GeneralizedCircle.h.

284 {
285 return m_n12.y();
286 }

◆ n3()

double n3 ( ) const
inline

Getter for the fourth circle parameter.

Definition at line 295 of file GeneralizedCircle.h.

296 {
297 return m_n3;
298 }

◆ normal()

ROOT::Math::XYVector normal ( const ROOT::Math::XYVector & point) const
inline

Normal vector to the circle near the given position.

Gives the unit normal vector to the circle line. It points to the outside of the circle for counterclockwise orientation, and inwards for the clockwise orientation. It is essentially the gradient normalized to unit length

Parameters
pointPoint in the plane to calculate the tangential
Returns
Unit normal vector to the circle line

Definition at line 363 of file GeneralizedCircle.h.

364 {
365 return VectorUtil::unit(gradient(point));
366 }

◆ normalizationSquared()

double normalizationSquared ( ) const
inline

Calculates the generalized circle specific squared norm.

Correctly normalized this should give one.

Definition at line 317 of file GeneralizedCircle.h.

318 {
319 return n12().Mag2() - 4 * n0() * n3();
320 }

◆ normalize()

void normalize ( )
inlineprotected

Normalizes the circle parameters.

The normalization is only made if the circle parameters have a valid positive norm. If the normalization of the circle is negative or zero all circle parameters are not changed.

Definition at line 254 of file GeneralizedCircle.h.

255 {
256 double normalization_squared = normalizationSquared();
257 if (normalization_squared > 0) scaleN(1.0 / std::sqrt(normalization_squared));
258 }

◆ omega()

double omega ( ) const
inline

Gives the omega parameter as used by the framework helix.

It is the signed curvature of the generalized circle with the opposite sign.

Definition at line 591 of file GeneralizedCircle.h.

592 {
593 return -curvature();
594 }

◆ orientation()

ERotation orientation ( ) const
inline

Gives the orientation of the circle.

The circle can be either orientated counterclockwise or clockwise.

Returns
ERotation::c_CounterClockwise for counterclockwise travel, ERotation::c_Clockwise for clockwise.

Definition at line 615 of file GeneralizedCircle.h.

616 {
617 return static_cast<ERotation>(sign(n3()));
618 }
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition ERotation.h:25

◆ passiveMoveBy()

void passiveMoveBy ( const ROOT::Math::XYVector & by)
inline

Moves the coordinate system by the given vector.

Updates the circle parameters inplace.

Definition at line 241 of file GeneralizedCircle.h.

242 {
243 setN(fastDistance(by), gradient(by), n3());
244 }

◆ perigee()

ROOT::Math::XYVector perigee ( ) const

Calculates the closest approach to the two dimensional origin.

Definition at line 153 of file GeneralizedCircle.cc.

154{
155 ROOT::Math::XYVector result(n12());
156 result *= (-impact() / result.R());
157 return result;
158}

◆ perimeter()

double perimeter ( ) const
inline

Gives the perimeter of the circle.

Definition at line 604 of file GeneralizedCircle.h.

605 {
606 return 2 * M_PI * radius();
607 }

◆ radius()

double radius ( ) const
inline

Gives the signed radius of the circle. If it was a line this will be infinity.

Definition at line 570 of file GeneralizedCircle.h.

571 {
572 return 1 / curvature();
573 }

◆ reverse()

void reverse ( )
inline

Flips the orientation of the circle in place.

Definition at line 220 of file GeneralizedCircle.h.

221 {
222 scaleN(-1);
223 }

◆ reversed()

GeneralizedCircle reversed ( ) const
inline

Returns a copy of the circle with opposite orientation.

Definition at line 324 of file GeneralizedCircle.h.

325 {
326 return GeneralizedCircle(-n0(), -n12(), -n3());
327 }

◆ scaleN()

void scaleN ( const double factor)
inlineprivate

Scales the circle parameters by a common factor.

Definition at line 262 of file GeneralizedCircle.h.

263 {
264 m_n0 *= factor;
265 m_n12 *= factor;
266 m_n3 *= factor;
267 }

◆ setCenterAndRadius()

void setCenterAndRadius ( const ROOT::Math::XYVector & center,
double absRadius,
ERotation orientation = ERotation::c_CounterClockwise )

Setter for the circle center and radius.

Definition at line 86 of file GeneralizedCircle.cc.

89{
90 double curvature = static_cast<double>(orientation) / fabs(absRadius);
91 setN0((center.Mag2() - absRadius * absRadius) * curvature / 2.0);
92 setN1(-center.x() * curvature);
93 setN2(-center.y() * curvature);
94 setN3(curvature / 2.0);
95 normalize(); // the call to normalize should be superfluous
96}
void setN0(const double n0)
Setter for first circle parameter.
void setN2(const double n2)
Setter for third circle parameter.
void setN3(const double n3)
Setter for fourth circle parameter.
void setN1(const double n1)
Setter for second circle parameter.

◆ setN() [1/4]

void setN ( const double n0,
const double n1,
const double n2,
const double n3 = 0.0 )
inline

Setter for all four circle parameters.

Makes a normalization after setting. The normal representation of a line leave out the last parameter.

Definition at line 180 of file GeneralizedCircle.h.

181 {
182 setN0(n0);
183 setN12(n1, n2);
184 setN3(n3);
185 normalize();
186 }

◆ setN() [2/4]

void setN ( const double n0,
const ROOT::Math::XYVector & n12,
const double n3 = 0.0 )
inline

Setter for all four circle parameters.

Makes a normalization after setting. The normal representation of a line leave out the last parameter.

Definition at line 193 of file GeneralizedCircle.h.

194 {
195 setN0(n0);
196 setN12(n12);
197 setN3(n3);
198 normalize();
199 }

◆ setN() [3/4]

void setN ( const GeneralizedCircle & n0123)
inline

Setter for all four circle parameters from another circle.

Definition at line 208 of file GeneralizedCircle.h.

209 {
210 setN(n0123.n0(), n0123.n12(), n0123.n3());
211 }

◆ setN() [4/4]

void setN ( const Line2D & n012)
inline

Setter for all four circle parameters from another circle.

Definition at line 202 of file GeneralizedCircle.h.

203 {
204 setN(n012.n0(), n012.n12());
205 }

◆ setN0()

void setN0 ( const double n0)
inlineprotected

Setter for first circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 104 of file GeneralizedCircle.h.

105 {
106 m_n0 = n0;
107 }

◆ setN1()

void setN1 ( const double n1)
inlineprotected

Setter for second circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 114 of file GeneralizedCircle.h.

115 {
116 m_n12.SetX(n1);
117 }

◆ setN12() [1/2]

void setN12 ( const double n1,
const double n2 )
inlineprotected

Setter for second and third circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 134 of file GeneralizedCircle.h.

135 {
136 m_n12.SetXY(n1, n2);
137 }

◆ setN12() [2/2]

void setN12 ( const ROOT::Math::XYVector & n12)
inlineprotected

Setter for second and third circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 144 of file GeneralizedCircle.h.

145 {
146 m_n12.SetXY(n12.X(), n12.Y());
147 }

◆ setN2()

void setN2 ( const double n2)
inlineprotected

Setter for third circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 124 of file GeneralizedCircle.h.

125 {
126 m_n12.SetY(n2);
127 }

◆ setN3()

void setN3 ( const double n3)
inlineprotected

Setter for fourth circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 154 of file GeneralizedCircle.h.

155 {
156 m_n3 = n3;
157 }

◆ setPerigeeParameters() [1/2]

void setPerigeeParameters ( const double curvature,
const double tangentialPhi,
const double impact )
inline

Setter for the perigee parameters.

Definition at line 170 of file GeneralizedCircle.h.

171 {
172 setPerigeeParameters(curvature, VectorUtil::Phi(tangentialPhi), impact);
173 }

◆ setPerigeeParameters() [2/2]

void setPerigeeParameters ( double curvature,
const ROOT::Math::XYVector & tangential,
double impact )

Setter for the perigee parameters.

Definition at line 98 of file GeneralizedCircle.cc.

101{
102 double loc_n0 = impact * (impact * curvature / 2.0 + 1.0);
103 ROOT::Math::XYVector loc_n12 = -VectorUtil::Orthogonal(tangential) * (1 + curvature * impact);
104 double loc_n3 = curvature / 2.0;
105 setN(loc_n0, loc_n12, loc_n3);
106}
void setN(const double n0, const double n1, const double n2, const double n3=0.0)
Setter for all four circle parameters.

◆ tangential() [1/2]

ROOT::Math::XYVector tangential ( ) const
inline

Gives the tangential vector at the closest approach to the origin / at the perigee.

Definition at line 507 of file GeneralizedCircle.h.

508 {
509 return VectorUtil::unit(tangential(ROOT::Math::XYVector(0.0, 0.0)));
510 }

◆ tangential() [2/2]

ROOT::Math::XYVector tangential ( const ROOT::Math::XYVector & point) const
inline

Tangential vector to the circle near the given position.

Gives the unit tangential vector to the circle line. It always points in the direction of positive advance at the point of closest approach from the given point.

Parameters
pointPoint in the plane to calculate the tangential
Returns
Unit tangential vector to the circle line

Definition at line 376 of file GeneralizedCircle.h.

377 {
378 return VectorUtil::Orthogonal(normal(point));
379 }

◆ tangentialPhi()

double tangentialPhi ( ) const
inline

Gives to azimuth angle phi of the direction of flight at the perigee.

Definition at line 513 of file GeneralizedCircle.h.

514 {
515 return tangential().Phi();
516 }

Member Data Documentation

◆ m_n0

double m_n0 = 0.0
private

Memory for the first parameter.

Definition at line 694 of file GeneralizedCircle.h.

◆ m_n12

ROOT::Math::XYVector m_n12
private

Memory for the second and third parameter.

Definition at line 691 of file GeneralizedCircle.h.

◆ m_n3

double m_n3 = 0.0
private

Memory for the fourth parameter.

Definition at line 688 of file GeneralizedCircle.h.


The documentation for this class was generated from the following files: