Belle II Software  release-08-01-10
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/trackFindingCDC/geometry/GeneralizedCircle.h>
11 #include <tracking/trackFindingCDC/geometry/Line2D.h>
12 
13 #include <tracking/trackFindingCDC/geometry/PerigeeParameters.h>
14 
15 #include <tracking/trackFindingCDC/geometry/Vector2D.h>
16 
17 #include <tracking/trackFindingCDC/numerics/EForwardBackward.h>
18 #include <tracking/trackFindingCDC/numerics/ERightLeft.h>
19 #include <tracking/trackFindingCDC/numerics/ERotation.h>
20 #include <tracking/trackFindingCDC/numerics/ESign.h>
21 
22 #include <utility>
23 #include <cmath>
24 #include <iosfwd>
25 
26 namespace Belle2 {
32  namespace TrackFindingCDC {
33  class Circle2D;
34 
36  class PerigeeCircle {
37 
38  public:
40  PerigeeCircle();
41 
44  PerigeeCircle(double curvature, const Vector2D& phi0Vec, double impact);
45 
48  PerigeeCircle(double curvature, double phi0, double impact);
49 
52 
53  private:
55  PerigeeCircle(double curvature, double phi0, const Vector2D& phi0Vec, double impact);
56 
57  public:
59  explicit PerigeeCircle(const Line2D& n012);
60 
62  explicit PerigeeCircle(const GeneralizedCircle& n0123);
63 
65  explicit PerigeeCircle(const Circle2D& circle);
66 
68  static PerigeeCircle fromN(double n0, double n1, double n2, double n3 = 0);
69 
71  static PerigeeCircle fromN(double n0, const Vector2D& n12, double n3 = 0);
72 
81  static PerigeeCircle
83  double absRadius,
84  ERotation orientation = ERotation::c_CounterClockwise);
85 
86  public:
88  void invalidate();
89 
91  bool isInvalid() const;
92 
94  bool isValid() const
95  {
96  return not isInvalid();
97  }
98 
100  void reverse();
101 
103  PerigeeCircle reversed() const;
104 
105  public:
113  void conformalTransform();
114 
124 
126  void passiveMoveBy(const Vector2D& by);
127 
130 
133  void passiveMoveByJacobian(const Vector2D& by, PerigeeJacobian& jacobian) const;
134 
137  Vector2D atArcLength(double arcLength) const;
138 
140  double arcLengthTo(const Vector2D& point) const;
141 
151  double arcLengthBetween(const Vector2D& from, const Vector2D& to) const;
152 
159  double arcLengthToCylindricalR(double cylindricalR) const;
160 
162  std::pair<Vector2D, Vector2D> atCylindricalR(double cylindricalR) const;
163 
177  Vector2D atCylindricalRForwardOf(const Vector2D& startPoint, double cylindricalR) const;
178 
181  {
182  return tangential(from).isForwardOrBackwardOf(to - from);
183  }
184 
187  {
188  return tangential().isForwardOrBackwardOf(to);
189  }
190 
204  Vector2D
205  chooseNextForwardOf(const Vector2D& start, const Vector2D& end1, const Vector2D& end2) const;
207  Vector2D closest(const Vector2D& point) const;
208 
210  double distance(const Vector2D& point) const
211  {
212  return distance(fastDistance(point));
213  }
214 
216  double distance(double fastDistance) const;
217 
226  double fastDistance(const Vector2D& point) const;
227 
229  double fastImpact() const
230  {
231  return fastDistance(impact());
232  }
233 
238  double fastDistance(double distance) const
239  {
240  return distance * (1.0 + distance * curvature() / 2);
241  }
242 
244  ERightLeft isRightOrLeft(const Vector2D& point) const
245  {
246  return static_cast<ERightLeft>(sign(fastDistance(point)));
247  }
248 
250  bool isLine() const
251  {
252  return curvature() == 0.0;
253  }
254 
256  bool isCircle() const
257  {
258  return curvature() != 0.0;
259  }
260 
263  {
264  return static_cast<ERotation>(sign(curvature()));
265  }
266 
268  Vector2D gradient(const Vector2D& point) const
269  {
270  return (point - perigee()) * curvature() - phi0Vec().orthogonal();
271  }
272 
274  Vector2D normal(const Vector2D& point) const
275  {
276  return gradient(point).unit();
277  }
278 
280  Vector2D tangential(const Vector2D& point) const
281  {
282  return normal(point).orthogonal();
283  }
284 
286  const Vector2D& tangential() const
287  {
288  return phi0Vec();
289  }
290 
293  {
294  return phi0Vec().orthogonal() * impact();
295  }
296 
298  Vector2D center() const
299  {
300  return phi0Vec().orthogonal() * (impact() + radius());
301  }
302 
304  Vector2D apogee() const
305  {
306  return phi0Vec().orthogonal() * (impact() + 2 * radius());
307  }
308 
310  double minimalCylindricalR() const
311  {
312  return fabs(impact());
313  }
314 
316  double maximalCylindricalR() const
317  {
318  return fabs(impact() + 2 * radius());
319  }
320 
322  double arcLengthPeriod() const
323  {
324  return std::fabs(perimeter());
325  }
326 
328  double perimeter() const
329  {
330  return 2 * M_PI * radius();
331  }
332 
334  double radius() const
335  {
336  return 1 / curvature();
337  }
338 
340  double absRadius() const
341  {
342  return fabs(radius());
343  }
344 
346  void setCenterAndRadius(const Vector2D& center,
347  double absRadius,
348  ERotation orientation = ERotation::c_CounterClockwise);
349 
351  double n0() const
352  {
353  return impact() * (impact() * curvature() / 2.0 + 1.0);
354  }
355 
357  Vector2D n12() const
358  {
359  return -phi0Vec().orthogonal() * (1 + curvature() * impact());
360  }
361 
363  double n1() const
364  {
365  return n12().x();
366  }
367  //{ return phi0Vec().y() * (1 + curvature() * impact()); }
368 
370  double n2() const
371  {
372  return n12().y();
373  }
374  //{ return -(phi0Vec().x()) * (1 + curvature() * impact()); }
375 
377  double n3() const
378  {
379  return curvature() / 2.0;
380  }
381 
383  void setN(double n0, double n1, double n2, double n3 = 0.0)
384  {
385  setN(n0, Vector2D(n1, n2), n3);
386  }
387 
389  void setN(double n0, const Vector2D& n12, double n3 = 0.0);
390 
392  void setN(const Line2D& n012)
393  {
394  setN(n012.n0(), n012.n12());
395  }
396 
398  void setN(const GeneralizedCircle& n0123)
399  {
400  setN(n0123.n0(), n0123.n12(), n0123.n3());
401  }
402 
404  double omega() const
405  {
406  return -curvature();
407  }
408 
410  double d0() const
411  {
412  return -impact();
413  }
414 
416  double curvature() const
417  {
418  return m_curvature;
419  }
420 
422  double phi0() const
423  {
424  return m_phi0;
425  }
426 
428  const Vector2D& phi0Vec() const
429  {
430  return m_phi0Vec;
431  }
432 
434  double impact() const
435  {
436  return m_impact;
437  }
438 
441  {
442  using namespace NPerigeeParameterIndices;
443  PerigeeParameters result;
444  result(c_Curv) = curvature();
445  result(c_Phi0) = phi0();
446  result(c_I) = impact();
447  return result;
448  }
449 
451  void setCurvature(double curvature)
452  {
454  }
455 
457  void setPhi0(double phi0)
458  {
459  m_phi0 = phi0;
461  }
462 
464  void setPhi0(const Vector2D& phi0Vec)
465  {
466  m_phi0 = phi0Vec.phi();
467  m_phi0Vec = phi0Vec.unit();
468  }
469 
471  void setImpact(double impact)
472  {
473  m_impact = impact;
474  }
475 
477  void setPerigeeParameters(double curvature, const Vector2D& phi0Vec, double impact)
478  {
479  m_impact = impact;
480  m_phi0 = phi0Vec.phi();
481  m_phi0Vec = phi0Vec.unit();
483  }
484 
486  void setPerigeeParameters(double curvature, double phi0, double impact)
487  {
488  m_impact = impact;
489  m_phi0 = phi0;
492  }
493 
494  private:
496  double arcLengthAtDeltaLength(double delta, double dr) const;
497 
499  double arcLengthAtSecantLength(double secantLength) const;
500 
501  private:
503  double m_curvature;
504 
506  double m_phi0;
507 
510 
512  double m_impact;
513 
514  };
515 
517  std::ostream& operator<<(std::ostream& output, const PerigeeCircle& circle);
518  }
520 }
A two dimensional circle in its natural representation using center and radius as parameters.
Definition: Circle2D.h:26
const Vector2D & 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:37
const Vector2D & n12() const
Getter for the unit normal vector to the line.
Definition: Line2D.h:117
double n0() const
Getter for the first line parameter.
Definition: Line2D.h:99
Extension of the generalized circle also caching the perigee coordinates.
Definition: PerigeeCircle.h:36
Vector2D atArcLength(double arcLength) const
Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
PerigeeCircle reversed() const
Returns a copy of the circle with opposite orientation.
const Vector2D & phi0Vec() const
Getter for the unit vector of the direction of flight at the perigee.
void setCenterAndRadius(const Vector2D &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
double fastImpact() const
Getter for the linearised distance to the origin.
double fastDistance(const Vector2D &point) const
Getter for the linearised distance measure to a point.
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.
bool isLine() const
Indicates if the perigee parameters represent a line.
Vector2D perigee() const
Getter for the perigee point.
Vector2D gradient(const Vector2D &point) const
Gradient of the distance field, hence indicates the direction of increasing distance.
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 phi0() const
Getter for the azimuth angle of the direction of flight at the perigee.
Vector2D tangential(const Vector2D &point) const
Tangential vector to the circle near the given position.
double arcLengthBetween(const Vector2D &from, const Vector2D &to) const
Calculates the arc length between two points of closest approach on the circle.
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.
EForwardBackward isForwardOrBackward(const Vector2D &to) const
Indicates whether to given point lies in the forward direction from the perigee.
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
Vector2D normal(const Vector2D &point) const
Unit normal vector from the circle to the given point.
void setCurvature(double curvature)
Setter for signed curvature.
Vector2D chooseNextForwardOf(const Vector2D &start, const Vector2D &end1, const Vector2D &end2) const
Returns the one of two end point which is first reached from the given start if one stricly follows t...
void setN(const Line2D &n012)
Setter for generalised circle parameters from a normal line.
double distance(const Vector2D &point) const
Getter for the proper signed distance of the point to the circle.
Vector2D apogee() const
Getter for the apogee of the circle. If it was a line both components will be infinity.
double omega() const
Getter for omega parameter of the common Belle2::Helix which is the wrong sign curvature.
void passiveMoveBy(const Vector2D &by)
Moves the coordinates system by the given vector. Updates perigee parameters in place.
bool isValid() const
Indicates if the combination of the circle parameters makes up a valid circle.
Definition: PerigeeCircle.h:94
void setN(const GeneralizedCircle &n0123)
Setter for four generalised circle parameters.
void setImpact(double impact)
Sets the impact parameter of the circle.
void setPhi0(const Vector2D &phi0Vec)
Sets the unit direction of flight at the perigee.
EForwardBackward isForwardOrBackwardOf(const Vector2D &from, const Vector2D &to) const
Indicates whether to given point lies in the forward direction from the perigee.
Vector2D n12() const
Getter for the generalised circle parameters n1 and n2.
double impact() const
Getter for the signed distance of the origin to the circle.
Vector2D center() const
Getter for the center of the circle. If it was a line both components will be infinity.
double maximalCylindricalR() const
Gives the maximal cylindrical radius the circle reaches.
static PerigeeCircle fromCenterAndRadius(const Vector2D &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
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.
PerigeeParameters perigeeParameters() const
Getter for the three perigee parameters in the order defined by EPerigeeParameter....
void conformalTransform()
Transforms the generalized circle to conformal space inplace.
const Vector2D & tangential() const
Getter for the tangtial vector at the perigee.
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.
ERightLeft isRightOrLeft(const Vector2D &point) const
Indicates if the point is on the right or left side of the circle.
PerigeeCircle()
Default constructor for ROOT compatibility.
Vector2D m_phi0Vec
Cached unit direction of flight at 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...
Vector2D closest(const Vector2D &point) const
Calculates the point of closest approach on the circle to the given point.
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.
PerigeeJacobian passiveMoveByJacobian(const Vector2D &by) const
Computes the Jacobi matrix for a move of the coordinate system by the given vector.
std::pair< Vector2D, Vector2D > atCylindricalR(double cylindricalR) const
Calculates the two points with the given cylindrical radius on the generalised circle.
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.
void setPerigeeParameters(double curvature, const Vector2D &phi0Vec, double impact)
Setter for the perigee parameters.
double n0() const
Getter for the generalised circle parameter n0.
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 arcLengthTo(const Vector2D &point) 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 no...
A matrix implementation to be used as an interface typ through out the track finder.
Definition: PlainMatrix.h:40
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:35
EForwardBackward isForwardOrBackwardOf(const Vector2D &rhs) const
Indicates if the given vector is more coaligned or reverse if you looked in the direction of this vec...
Definition: Vector2D.h:505
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:607
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
Definition: Vector2D.h:581
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:301
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:617
Vector2D unit() const
Returns a unit vector colaligned with this.
Definition: Vector2D.h:333
static Vector2D Phi(const double phi)
Constucts a unit vector with azimuth angle equal to phi.
Definition: Vector2D.h:71
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: ERotation.h:25
Abstract base class for different kinds of events.