10 #include <tracking/trackFindingCDC/numerics/Quadratic.h>
12 #include <tracking/trackFindingCDC/numerics/EForwardBackward.h>
13 #include <tracking/trackFindingCDC/numerics/ERightLeft.h>
14 #include <tracking/trackFindingCDC/numerics/ERotation.h>
15 #include <tracking/trackFindingCDC/numerics/ESign.h>
29 namespace TrackFindingCDC {
46 explicit Vector2D(
const TVector2& tVector2);
61 Vector2D(
const Vector2D& coordinateVec,
const double parallelCoor,
const double orthoCoor)
62 :
m_x(coordinateVec.
x() * parallelCoor - coordinateVec.
y() * orthoCoor)
63 ,
m_y(coordinateVec.
y() * parallelCoor + coordinateVec.
x() * orthoCoor)
83 compose(
const Vector2D& coordinateVec,
const double parallelCoor,
const double orthoCoor)
85 return Vector2D(coordinateVec, parallelCoor, orthoCoor);
100 return Vector2D((one.
x() + two.
x()) / 2.0, (one.
y() + two.
y()) / 2.0);
115 }
else if (two.
hasNAN()) {
117 }
else if (three.
hasNAN()) {
120 return Vector2D((one.
x() + two.
x() + three.
x()) / 3.0,
121 (one.
y() + two.
y() + three.
y()) / 3.0);
126 operator const TVector2();
131 return x() == rhs.
x() and
y() == rhs.
y();
157 return x() == 0.0 and
y() == 0.0;
163 return std::isnan(
x()) or std::isnan(
y());
172 return x() * rhs.
x() +
y() * rhs.
y();
177 return x() * rhs.
y() -
y() * rhs.
x();
183 return x() *
x() +
y() *
y();
189 return hypot2(
x(),
y());
218 double deltaX =
x() - rhs.x();
219 double deltaY =
y() - rhs.y();
220 return hypot2(deltaX, deltaY);
233 return scale(factor);
245 return vec2D.
scaled(factor);
259 return divide(denominator);
265 return Vector2D(
x() / denominator,
y() / denominator);
309 return isValid(ccwInfo) ?
Vector2D(-
static_cast<double>(ccwInfo) *
y(),
static_cast<double>(ccwInfo) *
x()) :
Vector2D();
317 double originalLength =
norm();
318 if (originalLength != 0.0)
divide(originalLength);
319 return originalLength;
327 double originalLength =
norm();
328 if (originalLength != 0.0)
scale(toLength / originalLength);
329 return originalLength;
425 return relativTo.
dot(*
this) / relativTo.
norm();
439 return relativTo.
dot(*
this);
446 return relativTo.
cross(*
this) / relativTo.
norm();
460 return relativTo.
cross(*
this);
493 return isCCWOrCWOf(rhs) == ERotation::c_CounterClockwise;
528 return ((n1 > 0 and n2 > 0 and n3 > 0) or (n1 < 0 and n2 < 0 and n3 < 0));
545 double det = lower.
cross(upper);
550 bool flipsOrientation = det < 0;
552 double transformedX =
cross(upper);
553 double transformedY = -
cross(lower);
554 bool inFirstQuadrant =
sameSign(det, transformedX, transformedY);
555 if (flipsOrientation) {
556 inFirstQuadrant = not inFirstQuadrant;
558 return inFirstQuadrant;
571 return hypot2(
x(),
y());
583 return isNull() ? NAN : atan2(
y(),
x());
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
void setSecond(const double second)
Setter for the second coordinate.
double normalize()
Normalizes the vector to unit length.
void swapCoordinates()
Swaps the coordinates in place.
double parallelComp(const Vector2D &relativTo) const
Calculates the component parallel to the given vector.
void flipSecond()
Flips the first coordinate inplace (no difference between active and passive)
Vector2D(const Vector2D &coordinateVec, const double parallelCoor, const double orthoCoor)
Constructs a vector from a unit coordinate system vector and the coordinates in that system.
std::string __str__() const
Output operator for python.
Vector2D flippedSecond() const
Makes a copy of the vector with the second coordinate flipped (no difference between active and passi...
Vector2D & add(const Vector2D &rhs)
Adds a vector to this in place.
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
Vector2D(const double x, const double y)
Constructor from two coordinates.
static Vector2D compose(const Vector2D &coordinateVec, const double parallelCoor, const double orthoCoor)
Constructs a vector from a unit coordinate system vector and the coordinates in that system.
Vector2D operator-(const Vector2D &rhs) const
Returns a new vector as differenc of this and rhs.
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
static Vector2D average(const Vector2D &one, const Vector2D &two)
Constructs the average of two vectors.
Vector2D reversed() const
Returns a vector pointing in the opposite direction.
void setXY(const double x, const double y)
Setter for both coordinate.
Vector2D & operator/=(const double denominator)
Same as divide()
static bool sameSign(float n1, float n2, float n3)
Check if three values have the same sign.
Vector2D scaled(const double factor) const
Returns a scaled copy of the vector.
void set(const double first, const double second)
Setter for both coordinate.
double distance(const Vector2D &rhs=Vector2D(0.0, 0.0)) const
Calculates the distance of this point to the rhs.
double cylindricalR() const
Gives the cylindrical radius of the vector. Same as norm()
double unnormalizedParallelComp(const Vector2D &relativTo) const
Same as parallelComp() but assumes the given vector to be of unit length.
double cosWith(const Vector2D &rhs) const
void flipFirst()
Flips the first coordinate inplace (no difference between active and passive)
void passiveMoveBy(const Vector2D &by)
Passivelly moves the vector inplace by the given vector.
Vector2D orthogonalVector(const Vector2D &relativTo) const
Calculates the part of this vector that is parallel to the given vector.
Vector2D operator-() const
Same as reversed()
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...
ERotation isCCWOrCWOf(const Vector2D &rhs) const
Indicates if the given vector is more counterclockwise or more clockwise if you looked in the directi...
void set(const Vector2D &both)
Setter for both coordinate by an other vector.
Vector2D & subtract(const Vector2D &rhs)
Subtracts a vector from this in place.
Vector2D flippedFirst() const
Makes a copy of the vector with the first coordinate flipped (no difference between active and passiv...
friend Vector2D operator*(const Vector2D &vec2D, const double factor)
Same as scaled()
Vector2D operator+(const Vector2D &rhs) const
Returns a new vector as sum of this and rhs.
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
double m_x
Memory for the first coordinate.
Vector2D orthogonal(const ERotation ccwInfo) const
Orthogonal vector to the direction given by the counterclockwise info.
Vector2D()
Default constructor for ROOT compatibility.
ERightLeft isRightOrLeftOf(const Vector2D &rhs) const
Indicates if the given vector is more left or more right if you looked in the direction of this vecto...
Vector2D operator/(const double denominator) const
Same as divided()
Vector2D & operator-=(const Vector2D &rhs)
Same as subtract()
Vector2D & divide(const double denominator)
Divides all coordinates by a common denominator in place.
double x() const
Getter for the x coordinate.
double sinWith(const Vector2D &rhs) const
Sine of the angle between this and rhs.
Vector2D conformalTransformed() const
Returns a copy of the vector transformed in conformal space.
Vector2D & operator+=(const Vector2D &rhs)
Same as add()
bool isRightOf(const Vector2D &rhs) const
Indicates if the given vector is more right if you looked in the direction of this vector.
void conformalTransform()
Transforms the vector to conformal space inplace.
bool isCCWOf(const Vector2D &rhs) const
Indicates if the given vector is more counterclockwise if you looked in the direction of this vector.
double orthogonalComp(const Vector2D &relativTo) const
Calculates the component orthogonal to the given vector.
void setCylindricalR(const double cylindricalR)
Set the cylindrical radius while keeping the azimuth angle phi the same.
static Vector2D average(const Vector2D &one, const Vector2D &two, const Vector2D &three)
Constructs the average of three vectors.
bool isBetween(const Vector2D &lower, const Vector2D &upper) const
Checks if this vector is between two other vectors Between means here that when rotating the lower ve...
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
bool operator==(const Vector2D &rhs) const
Equality comparison with both coordinates.
Vector2D & operator=(const TVector2 &tvector)
Assignment translating from a TVector2 instance.
static Vector2D getLowest()
Getter for the lowest possible vector.
Vector2D parallelVector(const Vector2D &relativTo) const
Calculates the part of this vector that is parallel to the given vector.
double second() const
Getter for the second coordinate.
void setXY(const Vector2D &xy)
Setter for both coordinate by an other vector.
double normSquared() const
Calculates .
Vector2D & scale(const double factor)
Scales the vector in place by the given factor.
bool isNull() const
Checks if the vector is the null vector.
Vector2D & operator*=(const double factor)
Same as scale()
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
bool hasNAN() const
Checks if one of the coordinates is NAN.
Vector2D divided(const double denominator) const
Returns a copy where all coordinates got divided by a common denominator.
void setY(const double y)
Setter for the y coordinate.
double y() const
Getter for the y coordinate.
double first() const
Getter for the first coordinate.
Vector2D flippedOver(const Vector2D &reflectionLine) const
Reflects this vector over line designated by the given vector.
Vector2D & reverse()
Reverses the direction of the vector in place.
Vector2D flippedAlong(const Vector2D &flippingDirection) const
Reflects this vector along line designated by the given vector.
Vector2D unit() const
Returns a unit vector colaligned with this.
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
double norm() const
Calculates the length of the vector.
Vector2D passiveRotatedBy(const Vector2D &phiVec) const
Returns a transformed vector version rotated by the given vector.
double m_y
Memory for the second coordinate.
bool isLeftOf(const Vector2D &rhs) const
Indicates if the given vector is more left if you looked in the direction of this vector.
void setFirst(const double first)
Setter for the first coordinate.
bool isForwardOf(const Vector2D &rhs) const
Indicates if the given vector is more coaligned if you looked in the direction of this vector.
void setX(const double x)
Setter for the x coordinate.
bool isCWOf(const Vector2D &rhs) const
Indicates if the given vector is more clockwise if you looked in the direction of this vector.
bool isBackwardOf(const Vector2D &rhs) const
Indicates if the given vector is more Reverse if you looked in the direction of this vector.
double unnormalizedOrthogonalComp(const Vector2D &relativTo) const
Same as orthogonalComp() but assumes the given vector to be of unit length.
bool operator<(const Vector2D &rhs) const
Total ordering based on cylindrical radius first and azimuth angle second.
static Vector2D Phi(const double phi)
Constucts a unit vector with azimuth angle equal to phi.
Vector2D passiveMovedBy(const Vector2D &by) const
Returns a transformed vector passivelly moved by the given vector.
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.
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Abstract base class for different kinds of events.