Belle II Software  release-08-01-10
Helix.test.cc
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 
9 #include <tracking/trackFindingCDC/geometry/Helix.h>
10 
11 #include <gtest/gtest.h>
12 
13 
14 using namespace Belle2;
15 using namespace TrackFindingCDC;
16 
17 TEST(TrackFindingCDCTest, geometry_Helix_closest)
18 {
19  // Tests the calculation of points of closest approach under various orientation of the helix.
20  // Here this is done by moving the coordinate system and thereby changing the perigee point to
21  // different representations.
22  // The point of closest approach should always lie at the position of the original origin / its
23  // transformed counterpart.
24  std::vector<Vector3D> bys = {Vector3D(0.0, 0.0, 0.0),
25  Vector3D(0.0, 0.0, 5.0),
26  Vector3D(0.0, 3.0, 0.0),
27  Vector3D(3.0, 0.0, 0.0),
28  Vector3D(-1.0, -2.0, 3.0)
29  };
30 
31  for (const Vector3D& by : bys) {
32  double curvature = +1.0 / 2.0;
33  double phi0 = -M_PI / 2.0;
34  double impact = +1.0;
35  double tanLambda = 1.0 / 2.0;
36  double z0 = 0.0;
37 
38  Helix helix(curvature, phi0, impact, tanLambda, z0);
39  Vector3D point(0.0, 0.0, 0.0);
40 
41  Vector3D expectedClosest = helix.perigee();
42 
43  helix.passiveMoveBy(by);
44  expectedClosest.passiveMoveBy(by);
45  point.passiveMoveBy(by);
46  {
47  Vector3D realClosest = helix.closest(point, true);
48  EXPECT_NEAR(expectedClosest.x(), realClosest.x(), 10e-7) << "Test for displacement by " << by;
49  EXPECT_NEAR(expectedClosest.y(), realClosest.y(), 10e-7) << "Test for displacement by " << by;
50  EXPECT_NEAR(expectedClosest.z(), realClosest.z(), 10e-7) << "Test for displacement by " << by;
51  }
52 
53  helix.shiftPeriod(2);
54  {
55  Vector3D realClosest = helix.closest(point, false);
56  EXPECT_NEAR(expectedClosest.x(), realClosest.x(), 10e-7) << "Test for displacement by " << by;
57  EXPECT_NEAR(expectedClosest.y(), realClosest.y(), 10e-7) << "Test for displacement by " << by;
58  EXPECT_NEAR(expectedClosest.z(), realClosest.z(), 10e-7) << "Test for displacement by " << by;
59  }
60  }
61 }
62 
63 TEST(TrackFindingCDCTest, geometry_Helix_arcLength2DToCylndricalR)
64 {
65  double curvature = -1.0;
66  double phi0 = +M_PI / 2.0;
67  double impact = -1.0;
68  double tanLambda = 1.0 / 2.0;
69  double z0 = 3.0;
70 
71  Helix helix(curvature, phi0, impact, tanLambda, z0);
72  EXPECT_EQ(-1, helix.radiusXY());
73 
74  double closestArcLength2D = helix.arcLength2DToCylindricalR(1);
75  EXPECT_NEAR(0, closestArcLength2D, 10e-7);
76 
77  double widestArcLength2D = helix.arcLength2DToCylindricalR(3);
78  EXPECT_NEAR(M_PI, widestArcLength2D, 10e-7);
79 
80  double halfArcLength2D = helix.arcLength2DToCylindricalR(sqrt(5.0));
81  EXPECT_NEAR(M_PI / 2, halfArcLength2D, 10e-7);
82 
83  double unreachableHighArcLength2D = helix.arcLength2DToCylindricalR(4);
84  EXPECT_TRUE(std::isnan(unreachableHighArcLength2D));
85 
86  double unreachableLowArcLength2D = helix.arcLength2DToCylindricalR(0.5);
87  EXPECT_TRUE(std::isnan(unreachableLowArcLength2D));
88 }
89 
90 TEST(TrackFindingCDCTest, geometry_Helix_arcLength2DToXY)
91 {
92  double curvature = -1.0;
93  double phi0 = +M_PI / 2.0;
94  double impact = -1.0;
95  double tanLambda = 1.0 / 2.0;
96  double z0 = 3.0;
97 
98  Helix helix(curvature, phi0, impact, tanLambda, z0);
99 
100  Vector2D origin(0.0, 0.0);
101  double closestArcLength2D = helix.arcLength2DToXY(origin);
102  EXPECT_NEAR(0, closestArcLength2D, 10e-7);
103 
104  double widestArcLength2D = helix.arcLength2DToXY(Vector2D(5.0, 0.0));
105  EXPECT_NEAR(M_PI, widestArcLength2D, 10e-7);
106 
107  double halfArcLength2D = helix.arcLength2DToXY(Vector2D(2.0, 5.0));
108  EXPECT_NEAR(M_PI / 2, halfArcLength2D, 10e-7);
109 
110  double otherHalfArcLength2D = helix.arcLength2DToXY(Vector2D(2.0, -5.0));
111  EXPECT_NEAR(-M_PI / 2, otherHalfArcLength2D, 10e-7);
112 }
Helix parameter class.
Definition: Helix.h:48
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:35
A three dimensional vector.
Definition: Vector3D.h:33
void passiveMoveBy(const Vector3D &by)
Passivelly moves the vector inplace by the given vector.
Definition: Vector3D.h:460
double x() const
Getter for the x coordinate.
Definition: Vector3D.h:472
double y() const
Getter for the y coordinate.
Definition: Vector3D.h:484
double z() const
Getter for the z coordinate.
Definition: Vector3D.h:496
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:34
Abstract base class for different kinds of events.