9#include <tracking/trackFindingCDC/geometry/PerigeeCircle.h>
10#include <tracking/trackFindingCDC/geometry/GeneralizedCircle.h>
11#include <tracking/trackFindingCDC/geometry/Vector2D.h>
13#include <gtest/gtest.h>
17using namespace TrackFindingCDC;
19TEST(TrackFindingCDCTest, geometry_PerigeeCircle_inheritance)
22 double curvature = 1.0;
23 double phi0 = M_PI / 4.0;
33 EXPECT_NEAR(curvature, generalizedCircle.curvature(), 10e-7);
34 EXPECT_NEAR(impact, generalizedCircle.impact(), 10e-7);
35 EXPECT_NEAR(perigeeCircle.tangential().x(), generalizedCircle.tangential().x(), 10e-7);
36 EXPECT_NEAR(perigeeCircle.tangential().y(), generalizedCircle.tangential().y(), 10e-7);
40 EXPECT_NEAR(curvature, roundTripCircle.curvature(), 10e-7);
41 EXPECT_NEAR(impact, roundTripCircle.impact(), 10e-7);
42 EXPECT_NEAR(cos(phi0), roundTripCircle.phi0Vec().x(), 10e-7);
43 EXPECT_NEAR(sin(phi0), roundTripCircle.phi0Vec().y(), 10e-7);
44 EXPECT_NEAR(phi0, roundTripCircle.phi0(), 10e-7);
47 roundTripCircle2.
setN(generalizedCircle);
49 EXPECT_NEAR(curvature, roundTripCircle2.
curvature(), 10e-7);
50 EXPECT_NEAR(impact, roundTripCircle2.
impact(), 10e-7);
51 EXPECT_NEAR(cos(phi0), roundTripCircle2.
tangential().
x(), 10e-7);
52 EXPECT_NEAR(sin(phi0), roundTripCircle2.
tangential().
y(), 10e-7);
53 EXPECT_NEAR(phi0, roundTripCircle2.
phi0(), 10e-7);
56TEST(TrackFindingCDCTest, geometry_PerigeeCircle_isLine)
62 EXPECT_FALSE(circle.
isLine());
65 float phi0 = M_PI / 2;
69 EXPECT_TRUE(line.isLine());
72TEST(TrackFindingCDCTest, geometry_PerigeeCircle_isCircle)
81 float phi0 = M_PI / 2;
85 EXPECT_FALSE(line.isCircle());
88TEST(TrackFindingCDCTest, geometry_PerigeeCircle_orientation)
95 EXPECT_EQ(ERotation::c_CounterClockwise, circle.orientation());
98 EXPECT_EQ(ERotation::c_Clockwise, reversedCircle.
orientation());
102 EXPECT_EQ(ERotation::c_CounterClockwise, line.orientation());
105 EXPECT_EQ(ERotation::c_Clockwise, reversedLine.
orientation());
108TEST(TrackFindingCDCTest, geometry_PerigeeCircle_minimalCylindricalR)
110 double curvature = 1.0 / 2.0;
111 double tangtialPhi = M_PI / 4.0;
112 double impact = -1.0;
117 EXPECT_EQ(1, perigeeCircle.minimalCylindricalR());
120TEST(TrackFindingCDCTest, geometry_PerigeeCircle_maximalCylindricalR)
122 double curvature = 1.0 / 2.0;
123 double tangtialPhi = M_PI / 4.0;
124 double impact = -1.0;
129 EXPECT_EQ(3, perigeeCircle.maximalCylindricalR());
132TEST(TrackFindingCDCTest, geometry_PerigeeCircle_setCenterAndRadius)
140 EXPECT_FALSE(circle.
isLine());
142 EXPECT_NEAR(1.5, circle.
radius(), 10e-7);
143 EXPECT_NEAR(0.5, circle.
center().
x(), 10e-7);
144 EXPECT_NEAR(0.0, circle.
center().
y(), 10e-7);
147TEST(TrackFindingCDCTest, geometry_PerigeeCircle_distance)
150 double curvature = -1.;
151 double phi0 = 3. * M_PI / 4.;
152 double impact = 1. -
sqrt(2.);
157 EXPECT_FALSE(circle.
isLine());
159 EXPECT_NEAR(-1.0, circle.
radius(), 10e-7);
160 EXPECT_NEAR(1.0, circle.
center().
x(), 10e-7);
161 EXPECT_NEAR(1.0, circle.
center().
y(), 10e-7);
163 EXPECT_NEAR(curvature, circle.
curvature(), 10e-7);
164 EXPECT_NEAR(phi0, circle.
phi0(), 10e-7);
165 EXPECT_NEAR(impact, circle.
impact(), 10e-7);
177TEST(TrackFindingCDCTest, geometry_PerigeeCircle_invalidate)
182 double curvature = -1.;
183 double phi0 = 3. * M_PI / 4.;
184 double impact = 1. -
sqrt(2.0);
199 circle.
setN(generalizedCircle);
204TEST(TrackFindingCDCTest, geometry_PerigeeCircle_passiveMoveBy)
212 EXPECT_NEAR(5.0, circle.
radius(), 10e-7);
213 EXPECT_NEAR(0.0, circle.
perigee().
x(), 10e-7);
214 EXPECT_NEAR(-3.0, circle.
perigee().
y(), 10e-7);
217TEST(TrackFindingCDCTest, geometry_PerigeeCircle_conformalTranform)
227 EXPECT_NEAR(1.0, circle.
curvature(), 10e-7);
228 EXPECT_NEAR(-M_PI / 2.0, circle.
phi0(), 10e-7);
229 EXPECT_NEAR(0.0, circle.
impact(), 10e-7);
230 EXPECT_NEAR(0.0, circle.
distance(firstPos), 10e-7);
231 EXPECT_NEAR(0.0, circle.
distance(secondPos), 10e-7);
237 EXPECT_NEAR(0.0, circle.
curvature(), 10e-7);
238 EXPECT_NEAR(M_PI / 2.0, circle.
phi0(), 10e-7);
239 EXPECT_NEAR(-1.0 / 2.0, circle.
impact(), 10e-7);
241 double firstConformalArcLength = circle.
arcLengthTo(firstPos);
242 double secondConformalArcLength = circle.
arcLengthTo(secondPos);
243 EXPECT_LT(firstConformalArcLength, secondConformalArcLength);
245 EXPECT_NEAR(0.0, circle.
distance(firstPos), 10e-7);
246 EXPECT_NEAR(0.0, circle.
distance(secondPos), 10e-7);
250 EXPECT_NEAR(1.0, conformalCopy.
curvature(), 10e-7);
251 EXPECT_NEAR(-M_PI / 2.0, conformalCopy.
phi0(), 10e-7);
252 EXPECT_NEAR(0.0, conformalCopy.
impact(), 10e-7);
255TEST(TrackFindingCDCTest, geometry_PerigeeCircle_closest)
265 double smallAngle = M_PI / 100;
266 Vector2D near(2.0 - cos(smallAngle), sin(smallAngle));
269 EXPECT_NEAR(near.x(), closestOfNear.
x(), 10e-7);
270 EXPECT_NEAR(near.y(), closestOfNear.
y(), 10e-7);
273TEST(TrackFindingCDCTest, geometry_PerigeeCircle_atArcLength)
280 double smallAngle = M_PI / 100;
281 Vector2D near(2.0 - cos(smallAngle), sin(smallAngle));
283 double nearArcLength =
284 -smallAngle * radius;
288 EXPECT_NEAR(near.x(), atNear.
x(), 10e-7);
289 EXPECT_NEAR(near.y(), atNear.
y(), 10e-7);
292 double downArcLength =
293 +M_PI / 2.0 * radius;
297 EXPECT_NEAR(down.x(), atDown.
x(), 10e-7);
298 EXPECT_NEAR(down.y(), atDown.
y(), 10e-7);
301TEST(TrackFindingCDCTest, geometry_PerigeeCircle_arcLengthToCylindricalR)
309 EXPECT_NEAR(0, closestArcLength, 10e-7);
312 EXPECT_NEAR(M_PI, widestArcLength, 10e-7);
315 EXPECT_NEAR(M_PI / 2, halfArcLength, 10e-7);
318 EXPECT_TRUE(std::isnan(unreachableHighArcLength));
321 EXPECT_TRUE(std::isnan(unreachableLowArcLength));
327 EXPECT_NEAR(0, closestArcLength, 10e-7);
330 EXPECT_NEAR(M_PI, widestArcLength, 10e-7);
333 EXPECT_NEAR(M_PI / 2, halfArcLength, 10e-7);
336 EXPECT_TRUE(std::isnan(unreachableHighArcLength));
339 EXPECT_TRUE(std::isnan(unreachableLowArcLength));
343TEST(TrackFindingCDCTest, geometry_PerigeeCircle_atCylindricalR)
351 EXPECT_NEAR(2, solutions.first.x(), 10e-7);
352 EXPECT_NEAR(1, solutions.first.y(), 10e-7);
354 EXPECT_NEAR(2, solutions.second.x(), 10e-7);
355 EXPECT_NEAR(-1, solutions.second.y(), 10e-7);
358TEST(TrackFindingCDCTest, geometry_PerigeeCircle_atCylindricalR_opposite_orientation)
366 EXPECT_NEAR(2, solutions.first.x(), 10e-7);
367 EXPECT_NEAR(-1, solutions.first.y(), 10e-7);
369 EXPECT_NEAR(2, solutions.second.x(), 10e-7);
370 EXPECT_NEAR(1, solutions.second.y(), 10e-7);
373TEST(TrackFindingCDCTest, geometry_PerigeeCircle_OriginCircleFromPointDirection)
375 double expectedCurvature = 1.0 / 2.0;
376 double expectedPhi0 = M_PI / 4.0;
380 const PerigeeCircle perigeeCircle(expectedCurvature, expectedPhi0, impact);
381 const Vector2D& expectedPhi0Vec = perigeeCircle.phi0Vec();
383 double randomArcLength = 2.0;
384 Vector2D pos2D = perigeeCircle.atArcLength(randomArcLength);
385 Vector2D phiVec = perigeeCircle.tangential(pos2D);
390 EXPECT_NEAR(expectedCurvature, curvature, 10e-7);
391 EXPECT_NEAR(expectedPhi0Vec.
x(), phi0Vec.
x(), 10e-7);
392 EXPECT_NEAR(expectedPhi0Vec.
y(), phi0Vec.
y(), 10e-7);
393 EXPECT_NEAR(expectedPhi0, phi0Vec.
phi(), 10e-7);
394 EXPECT_NEAR(1, phi0Vec.
norm(), 10e-7);
void invalidate()
Sets all circle parameters to zero.
Extension of the generalized circle also caching the perigee coordinates.
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.
void setCenterAndRadius(const Vector2D ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
bool isLine() const
Indicates if the perigee parameters represent a line.
Vector2D perigee() const
Getter for the perigee point.
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.
bool isInvalid() const
Indicates if all circle parameters are zero.
void reverse()
Flips the orientation of the circle in place.
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
double distance(const Vector2D &point) const
Getter for the proper signed distance of the point to the circle.
void passiveMoveBy(const Vector2D &by)
Moves the coordinates system by the given vector. Updates perigee parameters in place.
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.
static PerigeeCircle fromCenterAndRadius(const Vector2D ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
void invalidate()
Sets all circle parameters to zero.
void conformalTransform()
Transforms the generalized circle to conformal space inplace.
bool isCircle() const
Indicates if the perigee parameters represent a closed circle.
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.
Vector2D closest(const Vector2D &point) const
Calculates the point of closest approach on the circle to the given point.
PerigeeCircle conformalTransformed() const
Returns a copy of the circle in conformal space.
std::pair< Vector2D, Vector2D > atCylindricalR(double cylindricalR) const
Calculates the two points with the given cylindrical radius on the generalised circle.
ERotation orientation() const
Getter for the orientation 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 two dimensional vector which is equipped with functions for correct handling of orientation relate...
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
double x() const
Getter for the x coordinate.
void conformalTransform()
Transforms the vector to conformal space inplace.
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
double normSquared() const
Calculates .
double y() const
Getter for the y coordinate.
Vector2D flippedOver(const Vector2D &reflectionLine) const
Reflects this vector over line designated by the given vector.
double norm() const
Calculates the length of the vector.
static Vector2D Phi(const double phi)
Constructs a unit vector with azimuth angle equal to phi.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.