Belle II Software development
PerigeeCircle.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/trackingUtilities/geometry/GeneralizedCircle.h>
11#include <tracking/trackingUtilities/geometry/Line2D.h>
12
13#include <tracking/trackingUtilities/geometry/PerigeeParameters.h>
14
15#include <tracking/trackingUtilities/geometry/VectorUtil.h>
16
17#include <tracking/trackingUtilities/numerics/EForwardBackward.h>
18#include <tracking/trackingUtilities/numerics/ERightLeft.h>
19#include <tracking/trackingUtilities/numerics/ERotation.h>
20#include <tracking/trackingUtilities/numerics/ESign.h>
21
22#include <Math/Vector2D.h>
23
24#include <utility>
25#include <cmath>
26#include <iosfwd>
27
28namespace Belle2 {
33
34 namespace TrackingUtilities {
35 class Circle2D;
36
39
40 public:
43
46 PerigeeCircle(double curvature, const ROOT::Math::XYVector& phi0Vec, double impact);
47
50 PerigeeCircle(double curvature, double phi0, double impact);
51
53 explicit PerigeeCircle(const PerigeeParameters& perigeeParameters);
54
55 private:
57 PerigeeCircle(double curvature, double phi0, const ROOT::Math::XYVector& phi0Vec, double impact);
58
59 public:
61 explicit PerigeeCircle(const Line2D& n012);
62
64 explicit PerigeeCircle(const GeneralizedCircle& n0123);
65
67 explicit PerigeeCircle(const Circle2D& circle);
68
70 static PerigeeCircle fromN(double n0, double n1, double n2, double n3 = 0);
71
73 static PerigeeCircle fromN(double n0, const ROOT::Math::XYVector& n12, double n3 = 0);
74
83 static PerigeeCircle
84 fromCenterAndRadius(const ROOT::Math::XYVector& center,
85 double absRadius,
86 ERotation orientation = ERotation::c_CounterClockwise);
87
88 public:
90 void invalidate();
91
93 bool isInvalid() const;
94
96 bool isValid() const
97 {
98 return not isInvalid();
99 }
100
102 void reverse();
103
105 PerigeeCircle reversed() const;
106
107 public:
115 void conformalTransform();
116
126
128 void passiveMoveBy(const ROOT::Math::XYVector& by);
129
131 PerigeeJacobian passiveMoveByJacobian(const ROOT::Math::XYVector& by) const;
132
135 void passiveMoveByJacobian(const ROOT::Math::XYVector& by, PerigeeJacobian& jacobian) const;
136
139 ROOT::Math::XYVector atArcLength(double arcLength) const;
140
142 double arcLengthTo(const ROOT::Math::XYVector& point) const;
143
153 double arcLengthBetween(const ROOT::Math::XYVector& from, const ROOT::Math::XYVector& to) const;
154
161 double arcLengthToCylindricalR(double cylindricalR) const;
162
164 std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> atCylindricalR(double cylindricalR) const;
165
179 ROOT::Math::XYVector atCylindricalRForwardOf(const ROOT::Math::XYVector& startPoint, double cylindricalR) const;
180
182 EForwardBackward isForwardOrBackwardOf(const ROOT::Math::XYVector& from, const ROOT::Math::XYVector& to) const
183 {
184 return VectorUtil::isForwardOrBackwardOf(tangential(from), (to - from));
185 }
186
188 EForwardBackward isForwardOrBackward(const ROOT::Math::XYVector& to) const
189 {
190 return VectorUtil::isForwardOrBackwardOf(tangential(), to);
191 }
192
206 ROOT::Math::XYVector
207 chooseNextForwardOf(const ROOT::Math::XYVector& start, const ROOT::Math::XYVector& end1, const ROOT::Math::XYVector& end2) const;
209 ROOT::Math::XYVector closest(const ROOT::Math::XYVector& point) const;
210
212 double distance(const ROOT::Math::XYVector& point) const
213 {
214 return distance(fastDistance(point));
215 }
216
218 double distance(double fastDistance) const;
219
228 double fastDistance(const ROOT::Math::XYVector& point) const;
229
231 double fastImpact() const
232 {
233 return fastDistance(impact());
234 }
235
240 double fastDistance(double distance) const
241 {
242 return distance * (1.0 + distance * curvature() / 2);
243 }
244
246 ERightLeft isRightOrLeft(const ROOT::Math::XYVector& point) const
247 {
248 return static_cast<ERightLeft>(sign(fastDistance(point)));
249 }
250
252 bool isLine() const
253 {
254 return curvature() == 0.0;
255 }
256
258 bool isCircle() const
259 {
260 return curvature() != 0.0;
261 }
262
264 ERotation orientation() const
265 {
266 return static_cast<ERotation>(sign(curvature()));
267 }
268
270 ROOT::Math::XYVector gradient(const ROOT::Math::XYVector& point) const
271 {
272 return (point - perigee()) * curvature() - VectorUtil::Orthogonal(phi0Vec());
273 }
274
276 ROOT::Math::XYVector normal(const ROOT::Math::XYVector& point) const
277 {
278 return VectorUtil::unit(gradient(point));
279 }
280
282 ROOT::Math::XYVector tangential(const ROOT::Math::XYVector& point) const
283 {
284 return VectorUtil::Orthogonal(normal(point));
285 }
286
288 const ROOT::Math::XYVector& tangential() const
289 {
290 return phi0Vec();
291 }
292
294 ROOT::Math::XYVector perigee() const
295 {
296 return VectorUtil::Orthogonal(phi0Vec()) * impact();
297 }
298
300 ROOT::Math::XYVector center() const
301 {
302 return VectorUtil::Orthogonal(phi0Vec()) * (impact() + radius());
303 }
304
306 ROOT::Math::XYVector apogee() const
307 {
308 return VectorUtil::Orthogonal(phi0Vec()) * (impact() + 2 * radius());
309 }
310
312 double minimalCylindricalR() const
313 {
314 return fabs(impact());
315 }
316
318 double maximalCylindricalR() const
319 {
320 return fabs(impact() + 2 * radius());
321 }
322
324 double arcLengthPeriod() const
325 {
326 return std::fabs(perimeter());
327 }
328
330 double perimeter() const
331 {
332 return 2 * M_PI * radius();
333 }
334
336 double radius() const
337 {
338 return 1 / curvature();
339 }
340
342 double absRadius() const
343 {
344 return fabs(radius());
345 }
346
348 void setCenterAndRadius(const ROOT::Math::XYVector& center,
349 double absRadius,
350 ERotation orientation = ERotation::c_CounterClockwise);
351
353 double n0() const
354 {
355 return impact() * (impact() * curvature() / 2.0 + 1.0);
356 }
357
359 ROOT::Math::XYVector n12() const
360 {
361 return -VectorUtil::Orthogonal(phi0Vec()) * (1 + curvature() * impact());
362 }
363
365 double n1() const
366 {
367 return n12().x();
368 }
369 //{ return phi0Vec().y() * (1 + curvature() * impact()); }
370
372 double n2() const
373 {
374 return n12().y();
375 }
376 //{ return -(phi0Vec().x()) * (1 + curvature() * impact()); }
377
379 double n3() const
380 {
381 return curvature() / 2.0;
382 }
383
385 void setN(double n0, double n1, double n2, double n3 = 0.0)
386 {
387 setN(n0, ROOT::Math::XYVector(n1, n2), n3);
388 }
389
391 void setN(double n0, const ROOT::Math::XYVector& n12, double n3 = 0.0);
392
394 void setN(const Line2D& n012)
395 {
396 setN(n012.n0(), n012.n12());
397 }
398
400 void setN(const GeneralizedCircle& n0123)
401 {
402 setN(n0123.n0(), n0123.n12(), n0123.n3());
403 }
404
406 double omega() const
407 {
408 return -curvature();
409 }
410
412 double d0() const
413 {
414 return -impact();
415 }
416
418 double curvature() const
419 {
420 return m_curvature;
421 }
422
424 double phi0() const
425 {
426 return m_phi0;
427 }
428
430 const ROOT::Math::XYVector& phi0Vec() const
431 {
432 return m_phi0Vec;
433 }
434
436 double impact() const
437 {
438 return m_impact;
439 }
440
442 PerigeeParameters perigeeParameters() const
443 {
444 using namespace NPerigeeParameterIndices;
445 PerigeeParameters result;
446 result(c_Curv) = curvature();
447 result(c_Phi0) = phi0();
448 result(c_I) = impact();
449 return result;
450 }
451
454 {
456 }
457
459 void setPhi0(double phi0)
460 {
461 m_phi0 = phi0;
462 m_phi0Vec = VectorUtil::Phi(phi0);
463 }
464
466 void setPhi0(const ROOT::Math::XYVector& phi0Vec)
467 {
468 m_phi0 = phi0Vec.Phi();
469 m_phi0Vec = VectorUtil::unit(phi0Vec);
470 }
471
473 void setImpact(double impact)
474 {
476 }
477
479 void setPerigeeParameters(double curvature, const ROOT::Math::XYVector& phi0Vec, double impact)
480 {
482 m_phi0 = phi0Vec.Phi();
483 m_phi0Vec = VectorUtil::unit(phi0Vec);
485 }
486
488 void setPerigeeParameters(double curvature, double phi0, double impact)
489 {
491 m_phi0 = phi0;
492 m_phi0Vec = VectorUtil::Phi(phi0);
494 }
495
496 private:
498 double arcLengthAtDeltaLength(double delta, double dr) const;
499
501 double arcLengthAtSecantLength(double secantLength) const;
502
503 private:
505 double m_curvature = 0.0;
506
508 double m_phi0 = NAN;
509
511 ROOT::Math::XYVector m_phi0Vec;
512
514 double m_impact = 0.0;
515
516 };
517
519 std::ostream& operator<<(std::ostream& output, const PerigeeCircle& circle);
520 }
522}
A two dimensional circle in its natural representation using center and radius as parameters.
Definition Circle2D.h:32
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.
double n0() const
Getter for the first circle parameter.
A two dimensional normal line.
Definition Line2D.h:39
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
Extension of the generalized circle also caching the perigee coordinates.
PerigeeCircle reversed() const
Returns a copy of the circle with opposite orientation.
ROOT::Math::XYVector tangential(const ROOT::Math::XYVector &point) const
Tangential vector to the circle near the given position.
static PerigeeCircle fromCenterAndRadius(const ROOT::Math::XYVector &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
double fastImpact() const
Getter for the linearised distance to the origin.
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.
bool isLine() const
Indicates if the perigee parameters represent a line.
ROOT::Math::XYVector apogee() const
Getter for the apogee of the circle. If it was a line both components will be infinity.
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.
double minimalCylindricalR() const
Gives the minimal cylindrical radius the circle reaches (unsigned)
void reverse()
Flips the orientation of the circle in place.
void setPerigeeParameters(double curvature, const ROOT::Math::XYVector &phi0Vec, double impact)
Setter for the perigee parameters.
EForwardBackward isForwardOrBackward(const ROOT::Math::XYVector &to) const
Indicates whether to given point lies in the forward direction from the perigee.
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.
void setCurvature(double curvature)
Setter for signed curvature.
void setN(const Line2D &n012)
Setter for generalised circle parameters from a normal line.
void setCenterAndRadius(const ROOT::Math::XYVector &center, 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.
double omega() const
Getter for omega parameter of the common Belle2::Helix which is the wrong sign curvature.
bool isValid() const
Indicates if the combination of the circle parameters makes up a valid circle.
void setN(const GeneralizedCircle &n0123)
Setter for four generalised circle parameters.
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.
void setImpact(double impact)
Sets the impact parameter of the circle.
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 maximalCylindricalR() const
Gives the maximal cylindrical radius the circle reaches.
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.
ERightLeft isRightOrLeft(const ROOT::Math::XYVector &point) const
Indicates if the point is on the right or left side of the circle.
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 perimeter() const
Gives the signed perimeter of the circle.
double n2() const
Getter for the generalised circle parameters n2.
bool isCircle() const
Indicates if the perigee parameters represent a closed circle.
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 d0() const
Getter for d0 parameter of the common Belle2::Helix representation.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
double fastDistance(double distance) const
Helper function to translate the proper distance to the linearized distance measure of the circle ret...
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...
void setPhi0(double phi0)
Sets the azimuth angle of the direction of flight at the perigee.
void setPerigeeParameters(double curvature, double phi0, double impact)
Setter for the perigee parameters.
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 & tangential() const
Getter for the tangtial vector at the perigee.
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.
void setPhi0(const ROOT::Math::XYVector &phi0Vec)
Sets the unit direction of flight at the perigee.
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...
Namespace to hide the contained enum constants.
Abstract base class for different kinds of events.