Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:19

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 http://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/Measurement.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 <algorithm>
0022 #include <array>
0023 #include <cassert>
0024 #include <cstddef>
0025 #include <iosfwd>
0026 #include <stdexcept>
0027 
0028 namespace Acts::detail::Test {
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   GeometryIdentifier m_geometryId{};
0039   std::size_t sourceId = 0u;
0040   // use eBoundSize to indicate unused indices
0041   std::array<BoundIndices, 2> indices = {eBoundSize, eBoundSize};
0042   Acts::ActsVector<2> parameters;
0043   Acts::ActsSquareMatrix<2> covariance;
0044 
0045   /// Construct a source link for a 1d measurement.
0046   TestSourceLink(BoundIndices idx, ActsScalar val, ActsScalar var,
0047                  GeometryIdentifier gid = GeometryIdentifier(),
0048                  std::size_t sid = 0u)
0049       : m_geometryId(gid),
0050         sourceId(sid),
0051         indices{idx, eBoundSize},
0052         parameters(val, 0),
0053         covariance(Acts::ActsVector<2>(var, 0).asDiagonal()) {}
0054   /// Construct a source link for a 2d measurement.
0055   TestSourceLink(BoundIndices idx0, BoundIndices idx1,
0056                  const Acts::ActsVector<2>& params,
0057                  const Acts::ActsSquareMatrix<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   bool operator==(const TestSourceLink& rhs) const {
0072     return (m_geometryId == rhs.m_geometryId) && (sourceId == rhs.sourceId) &&
0073            (indices == rhs.indices) && (parameters == rhs.parameters) &&
0074            (covariance == rhs.covariance);
0075   }
0076   bool operator!=(const TestSourceLink& rhs) const { return !(*this == rhs); }
0077   std::ostream& print(std::ostream& os) const {
0078     os << "TestsSourceLink(geometryId=" << m_geometryId
0079        << ",sourceId=" << sourceId;
0080     if (indices[0] != eBoundSize) {
0081       os << ",index0=" << indices[0];
0082     }
0083     if (indices[1] != eBoundSize) {
0084       os << ",index1=" << indices[1];
0085     }
0086     os << ")";
0087     return os;
0088   }
0089   constexpr std::size_t index() const { return sourceId; }
0090 
0091   struct SurfaceAccessor {
0092     const Acts::TrackingGeometry& trackingGeometry;
0093 
0094     const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
0095       const auto& testSourceLink = sourceLink.get<TestSourceLink>();
0096       return trackingGeometry.findSurface(testSourceLink.m_geometryId);
0097     }
0098   };
0099 };
0100 
0101 inline std::ostream& operator<<(std::ostream& os,
0102                                 const TestSourceLink& sourceLink) {
0103   return sourceLink.print(os);
0104 }
0105 
0106 /// Extract the measurement from a TestSourceLink.
0107 ///
0108 /// @param gctx Unused
0109 /// @param trackState TrackState to calibrated
0110 /// @return The measurement used
0111 template <typename trajectory_t>
0112 Acts::BoundVariantMeasurement testSourceLinkCalibratorReturn(
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);
0119 
0120   if ((sl.indices[0] != Acts::eBoundSize) &&
0121       (sl.indices[1] != Acts::eBoundSize)) {
0122     auto meas =
0123         makeMeasurement(trackState.getUncalibratedSourceLink(), sl.parameters,
0124                         sl.covariance, sl.indices[0], sl.indices[1]);
0125     trackState.allocateCalibrated(2);
0126     trackState.setCalibrated(meas);
0127     return meas;
0128   } else if (sl.indices[0] != Acts::eBoundSize) {
0129     auto meas = makeMeasurement(
0130         trackState.getUncalibratedSourceLink(), sl.parameters.head<1>(),
0131         sl.covariance.topLeftCorner<1, 1>(), sl.indices[0]);
0132     trackState.allocateCalibrated(1);
0133     trackState.setCalibrated(meas);
0134     return meas;
0135   } else {
0136     throw std::runtime_error(
0137         "Tried to extract measurement from invalid TestSourceLink");
0138   }
0139 }
0140 /// Extract the measurement from a TestSourceLink.
0141 ///
0142 /// @param gctx Unused
0143 /// @param trackState TrackState to calibrated
0144 template <typename trajectory_t>
0145 void testSourceLinkCalibrator(
0146     const GeometryContext& gctx, const CalibrationContext& cctx,
0147     const SourceLink& sourceLink,
0148     typename trajectory_t::TrackStateProxy trackState) {
0149   testSourceLinkCalibratorReturn<trajectory_t>(gctx, cctx, sourceLink,
0150                                                trackState);
0151 }
0152 
0153 }  // namespace Acts::detail::Test