File indexing completed on 2025-12-16 09:22:16
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/EventData/MultiTrajectory.hpp"
0014 #include "Acts/EventData/SourceLink.hpp"
0015 #include "Acts/Geometry/GeometryContext.hpp"
0016 #include "Acts/Geometry/GeometryIdentifier.hpp"
0017 #include "Acts/Geometry/TrackingGeometry.hpp"
0018 #include "Acts/Utilities/CalibrationContext.hpp"
0019
0020 #include <array>
0021 #include <cstddef>
0022 #include <iosfwd>
0023 #include <stdexcept>
0024
0025 namespace Acts::detail::Test {
0026
0027 struct TestSourceLinkSurfaceAccessor;
0028
0029
0030
0031
0032
0033
0034
0035
0036 struct TestSourceLink final {
0037 using SurfaceAccessor = TestSourceLinkSurfaceAccessor;
0038
0039 GeometryIdentifier m_geometryId{};
0040 std::size_t sourceId = 0u;
0041
0042 std::array<BoundIndices, 2> indices = {eBoundSize, eBoundSize};
0043 Acts::Vector2 parameters{};
0044 Acts::ActsSquareMatrix<2> covariance{};
0045
0046
0047 TestSourceLink(BoundIndices idx, double val, double var,
0048 GeometryIdentifier gid = GeometryIdentifier(),
0049 std::size_t sid = 0u)
0050 : m_geometryId(gid),
0051 sourceId(sid),
0052 indices{idx, eBoundSize},
0053 parameters(val, 0),
0054 covariance(Acts::Vector2(var, 0).asDiagonal()) {}
0055
0056 TestSourceLink(BoundIndices idx0, BoundIndices idx1,
0057 const Acts::Vector2& params,
0058 const Acts::ActsSquareMatrix<2>& cov,
0059 GeometryIdentifier gid = GeometryIdentifier(),
0060 std::size_t sid = 0u)
0061 : m_geometryId(gid),
0062 sourceId(sid),
0063 indices{idx0, idx1},
0064 parameters(params),
0065 covariance(cov) {}
0066
0067 TestSourceLink() = default;
0068 TestSourceLink(const TestSourceLink&) = default;
0069 TestSourceLink(TestSourceLink&&) = default;
0070 TestSourceLink& operator=(const TestSourceLink&) = default;
0071 TestSourceLink& operator=(TestSourceLink&&) = default;
0072
0073 bool operator==(const TestSourceLink& rhs) const {
0074 return (m_geometryId == rhs.m_geometryId) && (sourceId == rhs.sourceId) &&
0075 (indices == rhs.indices) && (parameters == rhs.parameters) &&
0076 (covariance == rhs.covariance);
0077 }
0078
0079 std::ostream& print(std::ostream& os) const {
0080 os << "TestsSourceLink(geometryId=" << m_geometryId
0081 << ",sourceId=" << sourceId;
0082 if (indices[0] != eBoundSize) {
0083 os << ",index0=" << indices[0];
0084 }
0085 if (indices[1] != eBoundSize) {
0086 os << ",index1=" << indices[1];
0087 }
0088 os << ")";
0089 return os;
0090 }
0091 constexpr std::size_t index() const { return sourceId; }
0092 };
0093
0094 struct TestSourceLinkSurfaceAccessor {
0095 const TrackingGeometry& geometry;
0096
0097 const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
0098 const auto& testSourceLink = sourceLink.get<TestSourceLink>();
0099 return geometry.findSurface(testSourceLink.m_geometryId);
0100 }
0101 };
0102
0103 inline std::ostream& operator<<(std::ostream& os,
0104 const TestSourceLink& sourceLink) {
0105 return sourceLink.print(os);
0106 }
0107
0108
0109
0110
0111
0112 template <typename trajectory_t>
0113 void testSourceLinkCalibrator(
0114 const GeometryContext& , const CalibrationContext& ,
0115 const SourceLink& sourceLink,
0116 typename trajectory_t::TrackStateProxy trackState) {
0117 TestSourceLink sl = sourceLink.template get<TestSourceLink>();
0118
0119 trackState.setUncalibratedSourceLink(SourceLink{sourceLink});
0120
0121 if ((sl.indices[0] != Acts::eBoundSize) &&
0122 (sl.indices[1] != Acts::eBoundSize)) {
0123 trackState.allocateCalibrated(2);
0124 trackState.template calibrated<2>() = sl.parameters;
0125 trackState.template calibratedCovariance<2>() = sl.covariance;
0126 trackState.setProjectorSubspaceIndices(
0127 std::array{sl.indices[0], sl.indices[1]});
0128 } else if (sl.indices[0] != Acts::eBoundSize) {
0129 trackState.allocateCalibrated(1);
0130 trackState.template calibrated<1>() = sl.parameters.head<1>();
0131 trackState.template calibratedCovariance<1>() =
0132 sl.covariance.topLeftCorner<1, 1>();
0133 trackState.setProjectorSubspaceIndices(std::array{sl.indices[0]});
0134 } else {
0135 throw std::runtime_error(
0136 "Tried to extract measurement from invalid TestSourceLink");
0137 }
0138 }
0139
0140 }