forked from sPHENIX-Collaboration/acts
/
MeasurementHelpersTests.cpp
126 lines (99 loc) · 4.28 KB
/
MeasurementHelpersTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// This file is part of the Acts project.
//
// Copyright (C) 2016-2018 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <boost/test/unit_test.hpp>
#include "Acts/EventData/Measurement.hpp"
#include "Acts/EventData/MeasurementHelpers.hpp"
#include "Acts/Surfaces/CylinderSurface.hpp"
namespace Acts {
namespace Test {
// Create a test context
GeometryContext tgContext = GeometryContext();
using SourceLink = MinimalSourceLink;
template <BoundIndices... params>
using MeasurementType = Measurement<SourceLink, BoundIndices, params...>;
using FittableMeasurement = FittableMeasurement<SourceLink>;
BOOST_AUTO_TEST_CASE(getSurface_test) {
auto cylinderBounds = std::make_shared<CylinderBounds>(3, 10);
auto cylinder = Surface::makeShared<CylinderSurface>(Transform3D::Identity(),
cylinderBounds);
auto cylinder2 = Surface::makeShared<CylinderSurface>(Transform3D::Identity(),
cylinderBounds);
SymMatrix2D cov;
cov << 0.04, 0, 0, 0.1;
MeasurementType<BoundIndices::eBoundLoc0, BoundIndices::eBoundLoc1> m(
cylinder, {}, std::move(cov), -0.1, 0.45);
FittableMeasurement fm = m;
BOOST_CHECK_EQUAL(MeasurementHelpers::getSurface(fm), cylinder.get());
MeasurementType<BoundIndices::eBoundLoc0, BoundIndices::eBoundLoc1> m2(
cylinder2, {}, std::move(cov), -0.1, 0.45);
fm = m2;
BOOST_CHECK_EQUAL(MeasurementHelpers::getSurface(fm), cylinder2.get());
}
BOOST_AUTO_TEST_CASE(getSize_test) {
auto cylinder =
Surface::makeShared<CylinderSurface>(Transform3D::Identity(), 3, 10);
SymMatrix2D cov;
cov << 0.04, 0, 0, 0.1;
MeasurementType<BoundIndices::eBoundLoc0, BoundIndices::eBoundLoc1> m(
cylinder, {}, std::move(cov), -0.1, 0.45);
FittableMeasurement fm = m;
BOOST_CHECK_EQUAL(MeasurementHelpers::getSize(fm), 2u);
ActsSymMatrixD<3> cov3;
cov.setRandom();
MeasurementType<BoundIndices::eBoundLoc0, BoundIndices::eBoundLoc1,
BoundIndices::eBoundTime>
m2(cylinder, {}, std::move(cov3), -0.1, 0.45, 42);
fm = m2;
BOOST_CHECK_EQUAL(MeasurementHelpers::getSize(fm), 3u);
}
BOOST_AUTO_TEST_CASE(MinimalSourceLinkTest) {
auto cylinder =
Surface::makeShared<CylinderSurface>(Transform3D::Identity(), 3, 10);
SymMatrix2D cov;
cov << 0.04, 0, 0, 0.1;
MeasurementType<BoundIndices::eBoundLoc0, BoundIndices::eBoundLoc1> m(
cylinder, {}, std::move(cov), -0.1, 0.45);
FittableMeasurement fm = m;
MinimalSourceLink msl{&fm};
BOOST_CHECK_EQUAL(&msl.referenceSurface(), cylinder.get());
MinimalSourceLink msl2{&fm};
BOOST_CHECK_EQUAL(msl, msl2);
MeasurementType<BoundIndices::eBoundLoc0, BoundIndices::eBoundLoc1> m2(
cylinder, {}, std::move(cov), -0.1, 0.45);
FittableMeasurement fm2 = m2;
MinimalSourceLink msl3{&fm2};
BOOST_CHECK_NE(msl, msl3);
BOOST_CHECK_EQUAL(&*msl, &fm);
}
BOOST_AUTO_TEST_CASE(visit_measurement_test) {
// Overallocated full size parameter vector and covariance
BoundVector parFull = BoundVector::Random();
BoundMatrix covFull = BoundMatrix::Random();
// constant variants
const auto& parFullConst = parFull;
const auto& covFullConst = covFull;
for (BoundVector::Index dim = 1; dim <= parFull.size(); ++dim) {
visit_measurement(parFull, covFull, dim, [&](auto param, auto cov) {
BOOST_CHECK_EQUAL(param, parFull.head(dim));
BOOST_CHECK_EQUAL(cov, covFull.topLeftCorner(dim, dim));
});
visit_measurement(parFull, covFull, dim,
[&](const auto& param, const auto& cov) {
BOOST_CHECK_EQUAL(param, parFull.head(dim));
BOOST_CHECK_EQUAL(cov, covFull.topLeftCorner(dim, dim));
});
visit_measurement(parFullConst, covFullConst, dim,
[&](const auto& param, const auto& cov) {
BOOST_CHECK_EQUAL(param, parFullConst.head(dim));
BOOST_CHECK_EQUAL(cov,
covFullConst.topLeftCorner(dim, dim));
});
}
}
} // namespace Test
} // namespace Acts