Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:47

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/Detector/Detector.hpp"
0014 #include "Acts/EventData/MultiTrajectory.hpp"
0015 #include "Acts/EventData/SourceLink.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Geometry/GeometryIdentifier.hpp"
0018 #include "Acts/Geometry/TrackingGeometry.hpp"
0019 #include "Acts/Utilities/CalibrationContext.hpp"
0020 
0021 #include <array>
0022 #include <cstddef>
0023 #include <iosfwd>
0024 #include <stdexcept>
0025 
0026 namespace Acts::detail::Test {
0027 
0028 struct TestSourceLinkSurfaceAccessor;
0029 
0030 /// A minimal source link implementation for testing.
0031 ///
0032 /// Instead of storing a reference to a measurement or raw data, the measurement
0033 /// data is stored inline directly in the source link. Only 1d or 2d
0034 /// measurements are supported to limit the overhead. Additionally, a source
0035 /// identifier is stored that can be used to store additional information. How
0036 /// this is interpreted depends on the specific tests.
0037 struct TestSourceLink final {
0038   using SurfaceAccessor = TestSourceLinkSurfaceAccessor;
0039 
0040   GeometryIdentifier m_geometryId{};
0041   std::size_t sourceId = 0u;
0042   // use eBoundSize to indicate unused indices
0043   std::array<BoundIndices, 2> indices = {eBoundSize, eBoundSize};
0044   Acts::Vector2 parameters;
0045   Acts::ActsSquareMatrix<2> covariance;
0046 
0047   /// Construct a source link for a 1d measurement.
0048   TestSourceLink(BoundIndices idx, double val, double var,
0049                  GeometryIdentifier gid = GeometryIdentifier(),
0050                  std::size_t sid = 0u)
0051       : m_geometryId(gid),
0052         sourceId(sid),
0053         indices{idx, eBoundSize},
0054         parameters(val, 0),
0055         covariance(Acts::Vector2(var, 0).asDiagonal()) {}
0056   /// Construct a source link for a 2d measurement.
0057   TestSourceLink(BoundIndices idx0, BoundIndices idx1,
0058                  const Acts::Vector2& params,
0059                  const Acts::ActsSquareMatrix<2>& cov,
0060                  GeometryIdentifier gid = GeometryIdentifier(),
0061                  std::size_t sid = 0u)
0062       : m_geometryId(gid),
0063         sourceId(sid),
0064         indices{idx0, idx1},
0065         parameters(params),
0066         covariance(cov) {}
0067   /// Default-construct an invalid source link to satisfy SourceLinkConcept.
0068   TestSourceLink() = default;
0069   TestSourceLink(const TestSourceLink&) = default;
0070   TestSourceLink(TestSourceLink&&) = default;
0071   TestSourceLink& operator=(const TestSourceLink&) = default;
0072   TestSourceLink& operator=(TestSourceLink&&) = default;
0073 
0074   bool operator==(const TestSourceLink& rhs) const {
0075     return (m_geometryId == rhs.m_geometryId) && (sourceId == rhs.sourceId) &&
0076            (indices == rhs.indices) && (parameters == rhs.parameters) &&
0077            (covariance == rhs.covariance);
0078   }
0079 
0080   std::ostream& print(std::ostream& os) const {
0081     os << "TestsSourceLink(geometryId=" << m_geometryId
0082        << ",sourceId=" << sourceId;
0083     if (indices[0] != eBoundSize) {
0084       os << ",index0=" << indices[0];
0085     }
0086     if (indices[1] != eBoundSize) {
0087       os << ",index1=" << indices[1];
0088     }
0089     os << ")";
0090     return os;
0091   }
0092   constexpr std::size_t index() const { return sourceId; }
0093 };
0094 
0095 struct TestSourceLinkSurfaceAccessor {
0096   const TrackingGeometry& geometry;
0097 
0098   const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
0099     const auto& testSourceLink = sourceLink.get<TestSourceLink>();
0100     return geometry.findSurface(testSourceLink.m_geometryId);
0101   }
0102 };
0103 
0104 namespace Experimental {
0105 
0106 struct TestSourceLinkSurfaceAccessor {
0107   const Acts::Experimental::Detector& geometry;
0108 
0109   const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
0110     const auto& testSourceLink = sourceLink.get<TestSourceLink>();
0111     return geometry.findSurface(testSourceLink.m_geometryId);
0112   }
0113 };
0114 
0115 }  // namespace Experimental
0116 
0117 inline std::ostream& operator<<(std::ostream& os,
0118                                 const TestSourceLink& sourceLink) {
0119   return sourceLink.print(os);
0120 }
0121 
0122 /// Extract the measurement from a TestSourceLink.
0123 ///
0124 /// @param gctx Unused
0125 /// @param trackState TrackState to calibrated
0126 template <typename trajectory_t>
0127 void testSourceLinkCalibrator(
0128     const GeometryContext& /*gctx*/, const CalibrationContext& /*cctx*/,
0129     const SourceLink& sourceLink,
0130     typename trajectory_t::TrackStateProxy trackState) {
0131   TestSourceLink sl = sourceLink.template get<TestSourceLink>();
0132 
0133   trackState.setUncalibratedSourceLink(SourceLink{sourceLink});
0134 
0135   if ((sl.indices[0] != Acts::eBoundSize) &&
0136       (sl.indices[1] != Acts::eBoundSize)) {
0137     trackState.allocateCalibrated(2);
0138     trackState.template calibrated<2>() = sl.parameters;
0139     trackState.template calibratedCovariance<2>() = sl.covariance;
0140     trackState.setProjectorSubspaceIndices(
0141         std::array{sl.indices[0], sl.indices[1]});
0142   } else if (sl.indices[0] != Acts::eBoundSize) {
0143     trackState.allocateCalibrated(1);
0144     trackState.template calibrated<1>() = sl.parameters.head<1>();
0145     trackState.template calibratedCovariance<1>() =
0146         sl.covariance.topLeftCorner<1, 1>();
0147     trackState.setProjectorSubspaceIndices(std::array{sl.indices[0]});
0148   } else {
0149     throw std::runtime_error(
0150         "Tried to extract measurement from invalid TestSourceLink");
0151   }
0152 }
0153 
0154 }  // namespace Acts::detail::Test