ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MeasurementHelpersTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MeasurementHelpersTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
14 
15 namespace Acts {
16 namespace Test {
17 
18 // Create a test context
20 
21 using SourceLink = MinimalSourceLink;
22 
23 template <ParID_t... params>
26 
27 BOOST_AUTO_TEST_CASE(getSurface_test) {
28  auto cylinderBounds = std::make_shared<CylinderBounds>(3, 10);
29 
30  auto cylinder = Surface::makeShared<CylinderSurface>(nullptr, cylinderBounds);
31  auto cylinder2 =
32  Surface::makeShared<CylinderSurface>(nullptr, cylinderBounds);
33 
35  cov << 0.04, 0, 0, 0.1;
37  std::move(cov), -0.1, 0.45);
38 
40 
41  BOOST_CHECK_EQUAL(MeasurementHelpers::getSurface(fm), cylinder.get());
42 
44  cylinder2, {}, std::move(cov), -0.1, 0.45);
45  fm = m2;
46  BOOST_CHECK_EQUAL(MeasurementHelpers::getSurface(fm), cylinder2.get());
47 }
48 
49 BOOST_AUTO_TEST_CASE(getSize_test) {
50  auto cylinder = Surface::makeShared<CylinderSurface>(nullptr, 3, 10);
51 
53  cov << 0.04, 0, 0, 0.1;
55  std::move(cov), -0.1, 0.45);
56 
58  BOOST_CHECK_EQUAL(MeasurementHelpers::getSize(fm), 2u);
59 
60  ActsSymMatrixD<3> cov3;
61  cov.setRandom();
63  cylinder, {}, std::move(cov3), -0.1, 0.45, 42);
64  fm = m2;
65 
66  BOOST_CHECK_EQUAL(MeasurementHelpers::getSize(fm), 3u);
67 }
68 
69 BOOST_AUTO_TEST_CASE(MinimalSourceLinkTest) {
70  auto cylinder = Surface::makeShared<CylinderSurface>(nullptr, 3, 10);
71 
73  cov << 0.04, 0, 0, 0.1;
75  std::move(cov), -0.1, 0.45);
76 
78  MinimalSourceLink msl{&fm};
79 
80  BOOST_CHECK_EQUAL(&msl.referenceSurface(), cylinder.get());
81 
82  MinimalSourceLink msl2{&fm};
83  BOOST_CHECK_EQUAL(msl, msl2);
84 
86  cylinder, {}, std::move(cov), -0.1, 0.45);
87  FittableMeasurement fm2 = m2;
88  MinimalSourceLink msl3{&fm2};
89  BOOST_CHECK_NE(msl, msl3);
90 
91  BOOST_CHECK_EQUAL(&*msl, &fm);
92 }
93 
94 BOOST_AUTO_TEST_CASE(visit_measurement_test) {
95  // Overallocated full size parameter vector and covariance
96  BoundVector parFull = BoundVector::Random();
97  BoundMatrix covFull = BoundMatrix::Random();
98  // constant variants
99  const auto& parFullConst = parFull;
100  const auto& covFullConst = covFull;
101 
102  for (BoundVector::Index dim = 1; dim <= parFull.size(); ++dim) {
103  visit_measurement(parFull, covFull, dim, [&](auto param, auto cov) {
104  BOOST_CHECK_EQUAL(param, parFull.head(dim));
105  BOOST_CHECK_EQUAL(cov, covFull.topLeftCorner(dim, dim));
106  });
107  visit_measurement(parFull, covFull, dim,
108  [&](const auto& param, const auto& cov) {
109  BOOST_CHECK_EQUAL(param, parFull.head(dim));
110  BOOST_CHECK_EQUAL(cov, covFull.topLeftCorner(dim, dim));
111  });
112  visit_measurement(parFullConst, covFullConst, dim,
113  [&](const auto& param, const auto& cov) {
114  BOOST_CHECK_EQUAL(param, parFullConst.head(dim));
115  BOOST_CHECK_EQUAL(cov,
116  covFullConst.topLeftCorner(dim, dim));
117  });
118  }
119 }
120 
121 } // namespace Test
122 } // namespace Acts