Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-17 07:34:21

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 /// A minimal source link implementation for testing.
0030 ///
0031 /// Instead of storing a reference to a measurement or raw data, the measurement
0032 /// data is stored inline directly in the source link. Only 1d or 2d
0033 /// measurements are supported to limit the overhead. Additionally, a source
0034 /// identifier is stored that can be used to store additional information. How
0035 /// this is interpreted depends on the specific tests.
0036 struct TestSourceLink final {
0037   using SurfaceAccessor = TestSourceLinkSurfaceAccessor;
0038 
0039   GeometryIdentifier m_geometryId{};
0040   std::size_t sourceId = 0u;
0041   // use eBoundSize to indicate unused indices
0042   std::array<BoundIndices, 2> indices = {eBoundSize, eBoundSize};
0043   Acts::Vector2 parameters{};
0044   Acts::SquareMatrix<2> covariance{};
0045 
0046   /// Construct a source link for a 1d measurement.
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   /// Construct a source link for a 2d measurement.
0056   TestSourceLink(BoundIndices idx0, BoundIndices idx1,
0057                  const Acts::Vector2& params, const Acts::SquareMatrix<2>& cov,
0058                  GeometryIdentifier gid = GeometryIdentifier(),
0059                  std::size_t sid = 0u)
0060       : m_geometryId(gid),
0061         sourceId(sid),
0062         indices{idx0, idx1},
0063         parameters(params),
0064         covariance(cov) {}
0065   /// Default-construct an invalid source link to satisfy SourceLinkConcept.
0066   TestSourceLink() = default;
0067   TestSourceLink(const TestSourceLink&) = default;
0068   TestSourceLink(TestSourceLink&&) = default;
0069   TestSourceLink& operator=(const TestSourceLink&) = default;
0070   TestSourceLink& operator=(TestSourceLink&&) = default;
0071 
0072   bool operator==(const TestSourceLink& rhs) const {
0073     return (m_geometryId == rhs.m_geometryId) && (sourceId == rhs.sourceId) &&
0074            (indices == rhs.indices) && (parameters == rhs.parameters) &&
0075            (covariance == rhs.covariance);
0076   }
0077 
0078   std::ostream& print(std::ostream& os) const {
0079     os << "TestsSourceLink(geometryId=" << m_geometryId
0080        << ",sourceId=" << sourceId;
0081     if (indices[0] != eBoundSize) {
0082       os << ",index0=" << indices[0];
0083     }
0084     if (indices[1] != eBoundSize) {
0085       os << ",index1=" << indices[1];
0086     }
0087     os << ")";
0088     return os;
0089   }
0090   constexpr std::size_t index() const { return sourceId; }
0091 };
0092 
0093 struct TestSourceLinkSurfaceAccessor {
0094   const TrackingGeometry& geometry;
0095 
0096   const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
0097     const auto& testSourceLink = sourceLink.get<TestSourceLink>();
0098     return geometry.findSurface(testSourceLink.m_geometryId);
0099   }
0100 };
0101 
0102 inline std::ostream& operator<<(std::ostream& os,
0103                                 const TestSourceLink& sourceLink) {
0104   return sourceLink.print(os);
0105 }
0106 
0107 /// Extract the measurement from a TestSourceLink.
0108 ///
0109 /// @param gctx Unused
0110 /// @param trackState TrackState to calibrated
0111 template <typename trajectory_t>
0112 void testSourceLinkCalibrator(
0113     const GeometryContext& /*gctx*/, const CalibrationContext& /*cctx*/,
0114     const SourceLink& sourceLink,
0115     typename trajectory_t::TrackStateProxy trackState) {
0116   TestSourceLink sl = sourceLink.template get<TestSourceLink>();
0117 
0118   trackState.setUncalibratedSourceLink(SourceLink{sourceLink});
0119 
0120   if ((sl.indices[0] != Acts::eBoundSize) &&
0121       (sl.indices[1] != Acts::eBoundSize)) {
0122     trackState.allocateCalibrated(2);
0123     trackState.template calibrated<2>() = sl.parameters;
0124     trackState.template calibratedCovariance<2>() = sl.covariance;
0125     trackState.setProjectorSubspaceIndices(
0126         std::array{sl.indices[0], sl.indices[1]});
0127   } else if (sl.indices[0] != Acts::eBoundSize) {
0128     trackState.allocateCalibrated(1);
0129     trackState.template calibrated<1>() = sl.parameters.head<1>();
0130     trackState.template calibratedCovariance<1>() =
0131         sl.covariance.topLeftCorner<1, 1>();
0132     trackState.setProjectorSubspaceIndices(std::array{sl.indices[0]});
0133   } else {
0134     throw std::runtime_error(
0135         "Tried to extract measurement from invalid TestSourceLink");
0136   }
0137 }
0138 
0139 }  // namespace Acts::detail::Test