Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestSourceLink.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TestSourceLink.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
20 
21 #include <algorithm>
22 #include <array>
23 #include <cassert>
24 #include <cstddef>
25 #include <iosfwd>
26 #include <stdexcept>
27 
28 namespace Acts {
29 namespace Test {
30 
38 struct TestSourceLink final {
40  size_t sourceId = 0u;
41  // use eBoundSize to indicate unused indices
42  std::array<BoundIndices, 2> indices = {eBoundSize, eBoundSize};
45 
49  : m_geometryId(gid),
50  sourceId(sid),
52  parameters(val, 0),
53  covariance(Acts::ActsVector<2>(var, 0).asDiagonal()) {}
56  const Acts::ActsVector<2>& params,
59  : m_geometryId(gid),
60  sourceId(sid),
61  indices{idx0, idx1},
62  parameters(params),
63  covariance(cov) {}
65  TestSourceLink() = default;
66  TestSourceLink(const TestSourceLink&) = default;
67  TestSourceLink(TestSourceLink&&) = default;
68  TestSourceLink& operator=(const TestSourceLink&) = default;
70 
71  constexpr size_t index() const { return sourceId; }
72 
73  struct SurfaceAccessor {
75 
76  const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
77  const auto& testSourceLink = sourceLink.get<TestSourceLink>();
78  return trackingGeometry.findSurface(testSourceLink.m_geometryId);
79  }
80  };
81 };
82 
83 bool operator==(const TestSourceLink& lhs, const TestSourceLink& rhs);
84 bool operator!=(const TestSourceLink& lhs, const TestSourceLink& rhs);
85 std::ostream& operator<<(std::ostream& os, const TestSourceLink& sourceLink);
86 
92 template <typename trajectory_t>
94  const GeometryContext& /*gctx*/, const CalibrationContext& /*cctx*/,
95  const SourceLink& sourceLink,
96  typename trajectory_t::TrackStateProxy trackState) {
97  TestSourceLink sl = sourceLink.template get<TestSourceLink>();
98 
99  trackState.setUncalibratedSourceLink(sourceLink);
100 
101  if ((sl.indices[0] != Acts::eBoundSize) and
102  (sl.indices[1] != Acts::eBoundSize)) {
103  auto meas =
104  makeMeasurement(trackState.getUncalibratedSourceLink(), sl.parameters,
105  sl.covariance, sl.indices[0], sl.indices[1]);
106  trackState.allocateCalibrated(2);
107  trackState.setCalibrated(meas);
108  return meas;
109  } else if (sl.indices[0] != Acts::eBoundSize) {
110  auto meas = makeMeasurement(
111  trackState.getUncalibratedSourceLink(), sl.parameters.head<1>(),
112  sl.covariance.topLeftCorner<1, 1>(), sl.indices[0]);
113  trackState.allocateCalibrated(1);
114  trackState.setCalibrated(meas);
115  return meas;
116  } else {
117  throw std::runtime_error(
118  "Tried to extract measurement from invalid TestSourceLink");
119  }
120 }
125 template <typename trajectory_t>
127  const GeometryContext& gctx, const CalibrationContext& cctx,
128  const SourceLink& sourceLink,
129  typename trajectory_t::TrackStateProxy trackState) {
130  testSourceLinkCalibratorReturn<trajectory_t>(gctx, cctx, sourceLink,
131  trackState);
132 }
133 
134 } // namespace Test
135 } // namespace Acts