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