Belle II Software  release-05-02-19
ParameterLine2D.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/geometry/GeneralizedCircle.h>
13 #include <tracking/trackFindingCDC/geometry/Line2D.h>
14 #include <tracking/trackFindingCDC/geometry/Vector2D.h>
15 
16 #include <tracking/trackFindingCDC/numerics/Quadratic.h>
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 {
31  namespace TrackFindingCDC {
32 
34 
40  class ParameterLine2D {
41 
42  public:
45  : m_support(0.0, 0.0)
46  , m_tangential(0.0, 0.0)
47  {
48  }
49 
54  {
55  }
56 
58 
61  static ParameterLine2D fromSlopeIntercept(const double slope, const double intercept)
62  {
63  return ParameterLine2D(Vector2D(0.0, intercept), Vector2D(1.0, slope));
64  }
65 
68 
71  static ParameterLine2D fromSlopeIntercept(const double slope,
72  const double intercept,
73  const EForwardBackward orientation)
74  {
75  return ParameterLine2D(Vector2D(0.0, intercept),
76  Vector2D(orientation, orientation * slope));
77  }
78 
80 
84  static ParameterLine2D throughPoints(const Vector2D& start, const Vector2D& end)
85  {
86  return ParameterLine2D(start, end - start);
87  }
88 
90 
95  explicit ParameterLine2D(const Line2D& line)
96  : m_support(line.support())
97  , m_tangential(line.tangential())
98  {
99  }
100 
102 
110  static ParameterLine2D touchingCircles(const Vector2D& fromCenter,
111  double fromSignedRadius,
112  const Vector2D& toCenter,
113  double toSignedRadius);
114 
116 
120  operator Line2D()
121  {
122  return Line2D(distanceToOrigin(), normal().unit());
123  } // not optimal yet. tangential.norm() is getting calculated two times.
124 
125  public:
127  const Vector2D& tangential() const
128  {
129  return m_tangential;
130  }
132  Vector2D normal() const
133  {
134  return tangential().orthogonal(ERotation::c_Clockwise);
135  }
136 
138  const Vector2D& support() const
139  {
140  return m_support;
141  }
142 
144  Vector2D at(const double parameter) const
145  {
146  return tangential() * parameter += support();
147  }
148 
152  {
153  return static_cast<EForwardBackward>(sign(tangential().first()));
154  }
155 
159  {
160  return static_cast<EForwardBackward>(sign(tangential().second()));
161  }
162 
164 
169  void normalize()
170  {
172  }
173 
175  void invalidate()
176  {
177  m_support.set(0, 0);
178  m_tangential.set(0, 0);
179  }
180 
182  bool isInvalid() const
183  {
184  return m_tangential.isNull();
185  }
186 
188  void reverse()
189  {
191  }
192 
194  ParameterLine2D reversed() const
195  {
197  }
198 
199  public:
201 
203  double distance(const Vector2D& point) const
204  {
205  return distanceToOrigin() - point.orthogonalComp(tangential());
206  }
207 
209 
211  double distance(const double first, const double second) const
212  {
213  return distance(Vector2D(first, second));
214  }
215 
217  double distanceToOrigin() const
218  {
220  }
221 
223  double absoluteDistance(const Vector2D& point) const
224  {
225  return fabs(distance(point));
226  }
227 
229  ERightLeft isRightOrLeft(const Vector2D& point) const
230  {
231  return static_cast<ERightLeft>(sign(distance(point)));
232  }
233 
235  bool isLeft(const Vector2D& rhs) const
236  {
237  return isRightOrLeft(rhs) == ERightLeft::c_Left;
238  }
239 
241  bool isRight(const Vector2D& rhs) const
242  {
243  return isRightOrLeft(rhs) == ERightLeft::c_Right;
244  }
245 
247  Vector2D closest(const Vector2D& point) const
248  {
249  double norm_squared = tangential().normSquared();
250  return Vector2D(tangential(),
251  tangential().dot(point) / norm_squared,
252  tangential().cross(support()) / norm_squared);
253  }
254 
256  double closestAt(const Vector2D& point) const
257  {
258  return (tangential().dot(point) - tangential().dot(support())) / tangential().normSquared();
259  }
260 
262  Vector2D closestToOrigin() const
263  {
264  return tangential().orthogonal() *=
266  }
267 
269  double closestToOriginAt() const
270  {
271  return -tangential().dot(support()) / tangential().normSquared();
272  }
273 
275  double lengthOnCurve(const Vector2D& from, const Vector2D& to) const
276  {
277  return (to.dot(tangential()) - from.dot(tangential())) / tangential().norm();
278  }
279 
281  double intersectionAt(const Line2D& line) const
282  {
283  return -(line.n0() + support().dot(line.normal())) / tangential().dot(line.normal());
284  }
285 
287  double intersectionAt(const ParameterLine2D& line) const
288  {
289  return (line.tangential().cross(support()) - line.tangential().cross(line.support())) /
290  tangential().cross(line.tangential());
291  }
292 
294 
298  std::pair<double, double> intersectionsAt(const GeneralizedCircle& genCircle) const
299  {
300  double a = genCircle.n3() * tangential().normSquared();
301  double b = tangential().dot(genCircle.gradient(support()));
302  double c = genCircle.fastDistance(support());
303 
304  return solveQuadraticABC(a, b, c);
305  }
306 
308  Vector2D intersection(const Line2D& line) const
309  {
310  return at(intersectionAt(line));
311  }
312 
314  Vector2D intersection(const ParameterLine2D& line) const
315  {
316  return at(intersectionAt(line));
317  }
318 
321 
325  void passiveMoveAtBy(const double delta)
326  {
327  m_support += tangential() * delta;
328  }
329 
331  void moveBy(const Vector2D& by)
332  {
333  m_support += by;
334  }
335 
338  void moveAlongFirst(const double first)
339  {
340  m_support.setFirst(m_support.first() + first);
341  }
342 
345  void moveAlongSecond(const double second)
346  {
347  m_support.setSecond(m_support.second() + second);
348  }
349 
352  void passiveMoveBy(const Vector2D& by)
353  {
354  m_support -= by;
355  }
356 
359  void passiveMoveAlongFirst(const double first)
360  {
361  m_support.setFirst(m_support.first() - first);
362  }
363 
366  void passiveMoveAlongSecond(const double second)
367  {
368  m_support.setSecond(m_support.second() - second);
369  }
377  double slope() const
379  {
380  return tangential().second() / tangential().first();
381  }
382 
384  double inverseSlope() const
385  {
386  return tangential().first() / tangential().second();
387  }
388 
390  double intercept() const
391  {
392  return support().second() - slope() * support().first();
393  }
394 
396  double zero() const
397  {
398  return support().first() - inverseSlope() * support().second();
399  }
400 
402  double map(const double first) const
403  {
404  return support().second() + slope() * (first - support().first());
405  }
406 
408  double operator()(const double first) const
409  {
410  return map(first);
411  }
412 
414  double inverseMap(const double second) const
415  {
416  return support().first() + inverseSlope() * (second - support().second());
417  }
418 
420  void invert()
421  {
424  }
425 
427  ParameterLine2D inverted() const
428  {
429  return ParameterLine2D(Vector2D(support().second(), support().first()),
430  Vector2D(tangential().second(), tangential().first()));
431  }
433 
434  private:
437 
440  };
441 
443  std::ostream& operator<<(std::ostream& output, const ParameterLine2D& line);
444  }
446 }
Belle2::TrackFindingCDC::ParameterLine2D::invert
void invert()
Turns the line into its inverse function in place. Orientation will be flipped as well.
Definition: ParameterLine2D.h:428
Belle2::TrackFindingCDC::ParameterLine2D::isRightOrLeft
ERightLeft isRightOrLeft(const Vector2D &point) const
Return if the point given is right or left of the line.
Definition: ParameterLine2D.h:237
Belle2::TrackFindingCDC::Vector2D::setSecond
void setSecond(const double second)
Setter for the second coordinate.
Definition: Vector2D.h:658
Belle2::TrackFindingCDC::ParameterLine2D::intersectionAt
double intersectionAt(const Line2D &line) const
Gives the line parameter where the two lines meet. Infinity for parallels.
Definition: ParameterLine2D.h:289
Belle2::TrackFindingCDC::Vector2D::orthogonal
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:303
Belle2::operator<<
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Definition: IntervalOfValidity.cc:196
Belle2::TrackFindingCDC::ParameterLine2D::touchingCircles
static ParameterLine2D touchingCircles(const Vector2D &fromCenter, double fromSignedRadius, const Vector2D &toCenter, double toSignedRadius)
Constructs a line touching two circles in one point each.
Definition: ParameterLine2D.cc:19
Belle2::TrackFindingCDC::ParameterLine2D::reverse
void reverse()
Reverses the tangential vector inplace.
Definition: ParameterLine2D.h:196
Belle2::TrackFindingCDC::ParameterLine2D::inverted
ParameterLine2D inverted() const
Gives the line assoziated with the inverse function as a copy.
Definition: ParameterLine2D.h:435
Belle2::TrackFindingCDC::ParameterLine2D::isLeft
bool isLeft(const Vector2D &rhs) const
Return if the point given is left of the line.
Definition: ParameterLine2D.h:243
Belle2::TrackFindingCDC::Vector2D
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:37
Belle2::TrackFindingCDC::Vector2D::normalize
double normalize()
Normalizes the vector to unit length.
Definition: Vector2D.h:317
Belle2::TrackFindingCDC::ParameterLine2D::alignedWithSecond
EForwardBackward alignedWithSecond() const
Indicates if the tangential vector point in a commmon direction with the second coordinate axes.
Definition: ParameterLine2D.h:166
Belle2::TrackFindingCDC::Vector2D::normSquared
double normSquared() const
Calculates .
Definition: Vector2D.h:183
Belle2::TrackFindingCDC::ParameterLine2D::passiveMoveBy
void passiveMoveBy(const Vector2D &by)
Moves the coordinate system in the given direction in place.
Definition: ParameterLine2D.h:360
Belle2::TrackFindingCDC::ParameterLine2D::intercept
double intercept() const
Second coordinate for first being zero.
Definition: ParameterLine2D.h:398
Belle2::TrackFindingCDC::ParameterLine2D::at
Vector2D at(const double parameter) const
Evaluates the line formula at the parameter given.
Definition: ParameterLine2D.h:152
Belle2::TrackFindingCDC::ParameterLine2D::closestToOriginAt
double closestToOriginAt() const
Gives the line parameter at the closest approach to the origin.
Definition: ParameterLine2D.h:277
Belle2::TrackFindingCDC::Vector2D::second
double second() const
Getter for the second coordinate.
Definition: Vector2D.h:653
Belle2::TrackFindingCDC::Vector2D::isNull
bool isNull() const
Checks if the vector is the null vector.
Definition: Vector2D.h:157
Belle2::TrackFindingCDC::ParameterLine2D::isInvalid
bool isInvalid() const
Check it the line is in an invalid state.
Definition: ParameterLine2D.h:190
Belle2::TrackFindingCDC::ParameterLine2D::isRight
bool isRight(const Vector2D &rhs) const
Return if the point given is right of the line.
Definition: ParameterLine2D.h:249
Belle2::TrackFindingCDC::NForwardBackward::EForwardBackward
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: EForwardBackward.h:35
Belle2::TrackFindingCDC::ParameterLine2D
A line with a support point and tangential vector.
Definition: ParameterLine2D.h:48
Belle2::TrackFindingCDC::GeneralizedCircle
A generalized circle.
Definition: GeneralizedCircle.h:61
Belle2::TrackFindingCDC::Vector2D::dot
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
Definition: Vector2D.h:172
Belle2::TrackFindingCDC::Vector2D::setFirst
void setFirst(const double first)
Setter for the first coordinate.
Definition: Vector2D.h:648
Belle2::TrackFindingCDC::ParameterLine2D::map
double map(const double first) const
Method mapping the first coordinate to the second according to the line.
Definition: ParameterLine2D.h:410
Belle2::TrackFindingCDC::ParameterLine2D::m_support
Vector2D m_support
Support vector of the line.
Definition: ParameterLine2D.h:444
Belle2::TrackFindingCDC::Vector2D::first
double first() const
Getter for the first coordinate.
Definition: Vector2D.h:643
Belle2::TrackFindingCDC::GeneralizedCircle::n3
double n3() const
Getter for the fourth circle parameter.
Definition: GeneralizedCircle.h:303
Belle2::TrackFindingCDC::ParameterLine2D::m_tangential
Vector2D m_tangential
Tangential vector of the line.
Definition: ParameterLine2D.h:447
Belle2::TrackFindingCDC::Vector2D::cross
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
Definition: Vector2D.h:177
Belle2::TrackFindingCDC::ParameterLine2D::passiveMoveAlongSecond
void passiveMoveAlongSecond(const double second)
Moves the coordinate system along the second coordinate axes in place.
Definition: ParameterLine2D.h:374
Belle2::TrackFindingCDC::GeneralizedCircle::fastDistance
double fastDistance(const Vector2D &point) const
Approximate distance.
Definition: GeneralizedCircle.h:469
Belle2::TrackFindingCDC::Vector2D::orthogonalComp
double orthogonalComp(const Vector2D &relativTo) const
Calculates the component orthogonal to the given vector.
Definition: Vector2D.h:446
Belle2::TrackFindingCDC::GeneralizedCircle::gradient
Vector2D gradient(const Vector2D &point) const
Gradient of the distance field Gives the gradient of the approximated distance field for the given po...
Definition: GeneralizedCircle.h:357
Belle2::TrackFindingCDC::ParameterLine2D::invalidate
void invalidate()
Clear all information from the line.
Definition: ParameterLine2D.h:183
Belle2::TrackFindingCDC::ParameterLine2D::moveAlongSecond
void moveAlongSecond(const double second)
Moves the line along the second coordinate axes in place.
Definition: ParameterLine2D.h:353
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ParameterLine2D::distanceToOrigin
double distanceToOrigin() const
Gives the signed distance of the origin.
Definition: ParameterLine2D.h:225
Belle2::TrackFindingCDC::Vector2D::swapCoordinates
void swapCoordinates()
Swaps the coordinates in place.
Definition: Vector2D.h:565
Belle2::TrackFindingCDC::ParameterLine2D::reversed
ParameterLine2D reversed() const
Makes a copy line which has the opposite tangential vector but same support point.
Definition: ParameterLine2D.h:202
Belle2::TrackFindingCDC::ParameterLine2D::inverseSlope
double inverseSlope() const
The inveres line slope.
Definition: ParameterLine2D.h:392
Belle2::TrackFindingCDC::ParameterLine2D::fromSlopeIntercept
static ParameterLine2D fromSlopeIntercept(const double slope, const double intercept)
Constructs a line with slope and intercept.
Definition: ParameterLine2D.h:69
Belle2::TrackFindingCDC::ParameterLine2D::closest
Vector2D closest(const Vector2D &point) const
Gives the position at the closest approach on the line to point.
Definition: ParameterLine2D.h:255
Belle2::TrackFindingCDC::Vector2D::reverse
Vector2D & reverse()
Reverses the direction of the vector in place.
Definition: Vector2D.h:341
Belle2::TrackFindingCDC::ParameterLine2D::throughPoints
static ParameterLine2D throughPoints(const Vector2D &start, const Vector2D &end)
Static constructor for a line between to points.
Definition: ParameterLine2D.h:92
Belle2::TrackFindingCDC::NRightLeft::ERightLeft
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:35
Belle2::TrackFindingCDC::ParameterLine2D::lengthOnCurve
double lengthOnCurve(const Vector2D &from, const Vector2D &to) const
Denotes the length on the line between the two points.
Definition: ParameterLine2D.h:283
Belle2::TrackFindingCDC::ParameterLine2D::moveAlongFirst
void moveAlongFirst(const double first)
Moves the line along the first coordinate axes in place.
Definition: ParameterLine2D.h:346
Belle2::TrackFindingCDC::ParameterLine2D::closestToOrigin
Vector2D closestToOrigin() const
Gives the position of closest approach to the origin.
Definition: ParameterLine2D.h:270
Belle2::TrackFindingCDC::ParameterLine2D::ParameterLine2D
ParameterLine2D()
Default constructor for ROOT compatibility.
Definition: ParameterLine2D.h:52
Belle2::TrackFindingCDC::ParameterLine2D::closestAt
double closestAt(const Vector2D &point) const
Gives the line parameter at the closest approach to point.
Definition: ParameterLine2D.h:264
Belle2::TrackFindingCDC::ParameterLine2D::slope
double slope() const
The line slope.
Definition: ParameterLine2D.h:386
Belle2::TrackFindingCDC::ParameterLine2D::intersection
Vector2D intersection(const Line2D &line) const
Gives the point where the two lines meet. Infinities for parallels.
Definition: ParameterLine2D.h:316
Belle2::TrackFindingCDC::ParameterLine2D::passiveMoveAlongFirst
void passiveMoveAlongFirst(const double first)
Moves the coordinate system along the first coordinate axes in place.
Definition: ParameterLine2D.h:367
Belle2::TrackFindingCDC::ParameterLine2D::inverseMap
double inverseMap(const double second) const
Method for the inverse mapping the second coordinate to the first according to the line.
Definition: ParameterLine2D.h:422
Belle2::TrackFindingCDC::Line2D
A two dimensional normal line.
Definition: Line2D.h:47
Belle2::TrackFindingCDC::ParameterLine2D::distance
double distance(const Vector2D &point) const
Gives the signed distance of a point to the line.
Definition: ParameterLine2D.h:211
Belle2::TrackFindingCDC::ParameterLine2D::tangential
const Vector2D & tangential() const
Gives the tangential vector of the line.
Definition: ParameterLine2D.h:135
Belle2::TrackFindingCDC::ParameterLine2D::operator()
double operator()(const double first) const
Operator mapping the first coordinate to the second according to the line.
Definition: ParameterLine2D.h:416
Belle2::TrackFindingCDC::Vector2D::norm
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:189
Belle2::TrackFindingCDC::ParameterLine2D::normalize
void normalize()
Normalizes the tangential vector inplace.
Definition: ParameterLine2D.h:177
Belle2::TrackFindingCDC::ParameterLine2D::intersectionsAt
std::pair< double, double > intersectionsAt(const GeneralizedCircle &genCircle) const
Gives the line parameters of this line, where it intersects with the generalized circle.
Definition: ParameterLine2D.h:306
Belle2::TrackFindingCDC::ParameterLine2D::passiveMoveAtBy
void passiveMoveAtBy(const double delta)
Moves the support point by the given amount of the parameter in the forward direction.
Definition: ParameterLine2D.h:333
Belle2::TrackFindingCDC::ParameterLine2D::support
const Vector2D & support() const
Gives the support vector of the line.
Definition: ParameterLine2D.h:146
Belle2::TrackFindingCDC::ParameterLine2D::normal
Vector2D normal() const
Gives the normal vector of the line.
Definition: ParameterLine2D.h:140
Belle2::TrackFindingCDC::ParameterLine2D::alignedWithFirst
EForwardBackward alignedWithFirst() const
Indicates if the tangential vector point in a commmon direction with the first coordinate axes.
Definition: ParameterLine2D.h:159
Belle2::TrackFindingCDC::ParameterLine2D::zero
double zero() const
First coordinate for second being zero.
Definition: ParameterLine2D.h:404
Belle2::TrackFindingCDC::Vector2D::set
void set(const double first, const double second)
Setter for both coordinate.
Definition: Vector2D.h:664
Belle2::TrackFindingCDC::ParameterLine2D::absoluteDistance
double absoluteDistance(const Vector2D &point) const
Gives the unsigned distance of a point to the line.
Definition: ParameterLine2D.h:231
Belle2::TrackFindingCDC::ParameterLine2D::moveBy
void moveBy(const Vector2D &by)
Moves the line in the given direction in place. Corresponds to an active transformation.
Definition: ParameterLine2D.h:339