File indexing completed on 2025-01-18 09:11:02
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Definitions/Algebra.hpp"
0010
0011 namespace Acts {
0012
0013 template <typename spacepoint_t>
0014 SpacePointBuilder<spacepoint_t>::SpacePointBuilder(
0015 const SpacePointBuilderConfig& cfg, BuilderFunction func,
0016 std::unique_ptr<const Logger> logger)
0017 : m_config(cfg), m_spConstructor(func), m_logger(std::move(logger)) {
0018 m_spUtility = std::make_shared<SpacePointUtility>(cfg);
0019 }
0020
0021 template <typename spacepoint_t>
0022 template <template <typename...> typename container_t>
0023 void SpacePointBuilder<spacepoint_t>::buildSpacePoint(
0024 const GeometryContext& gctx, const std::vector<SourceLink>& sourceLinks,
0025 const SpacePointBuilderOptions& opt,
0026 std::back_insert_iterator<container_t<spacepoint_t>> spacePointIt) const {
0027 const unsigned int num_slinks = sourceLinks.size();
0028
0029 Acts::Vector3 gPos = Acts::Vector3::Zero();
0030 std::optional<double> gTime = std::nullopt;
0031 Acts::Vector2 gCov = Acts::Vector2::Zero();
0032 std::optional<double> gCovT = std::nullopt;
0033
0034 if (num_slinks == 1) {
0035 auto slink = sourceLinks.at(0);
0036 auto [param, cov] = opt.paramCovAccessor(slink);
0037 std::tie(gPos, gTime, gCov, gCovT) = m_spUtility->globalCoords(
0038 gctx, slink, m_config.slSurfaceAccessor, param, cov);
0039 } else if (num_slinks == 2) {
0040
0041 const auto& ends1 = opt.stripEndsPair.first;
0042 const auto& ends2 = opt.stripEndsPair.second;
0043
0044 Acts::SpacePointParameters spParams;
0045
0046 if (!m_config.usePerpProj) {
0047
0048 auto spFound = m_spUtility->calculateStripSPPosition(
0049 ends1, ends2, opt.vertex, spParams, opt.stripLengthTolerance);
0050
0051 if (!spFound.ok()) {
0052 spFound = m_spUtility->recoverSpacePoint(spParams,
0053 opt.stripLengthGapTolerance);
0054 }
0055
0056 if (!spFound.ok()) {
0057 return;
0058 }
0059
0060 gPos = 0.5 *
0061 (ends1.first + ends1.second + spParams.m * spParams.firstBtmToTop);
0062
0063 } else {
0064
0065 auto resultPerpProj =
0066 m_spUtility->calcPerpendicularProjection(ends1, ends2, spParams);
0067
0068 if (!resultPerpProj.ok()) {
0069 return;
0070 }
0071 gPos = ends1.first + resultPerpProj.value() * spParams.firstBtmToTop;
0072 }
0073
0074 double theta = std::acos(
0075 spParams.firstBtmToTop.dot(spParams.secondBtmToTop) /
0076 (spParams.firstBtmToTop.norm() * spParams.secondBtmToTop.norm()));
0077
0078 gCov = m_spUtility->calcRhoZVars(gctx, sourceLinks.at(0), sourceLinks.at(1),
0079 m_config.slSurfaceAccessor,
0080 opt.paramCovAccessor, gPos, theta);
0081
0082 } else {
0083 ACTS_ERROR("More than 2 sourceLinks are given for a space point.");
0084 }
0085 boost::container::static_vector<SourceLink, 2> slinks(sourceLinks.begin(),
0086 sourceLinks.end());
0087
0088 spacePointIt = m_spConstructor(gPos, gTime, gCov, gCovT, std::move(slinks));
0089 }
0090
0091 template <typename spacepoint_t>
0092 void SpacePointBuilder<spacepoint_t>::makeSourceLinkPairs(
0093 const GeometryContext& gctx, const std::vector<SourceLink>& slinksFront,
0094 const std::vector<SourceLink>& slinksBack,
0095 std::vector<std::pair<SourceLink, SourceLink>>& slinkPairs,
0096 const StripPairOptions& pairOpt) const {
0097 if (slinksFront.empty() || slinksBack.empty()) {
0098 return;
0099 }
0100 double minDistance = 0;
0101 unsigned int closestIndex = 0;
0102
0103 for (unsigned int i = 0; i < slinksFront.size(); i++) {
0104 const auto& slinkFront = slinksFront[i];
0105 minDistance = std::numeric_limits<double>::max();
0106 closestIndex = slinksBack.size();
0107 for (unsigned int j = 0; j < slinksBack.size(); j++) {
0108 const auto& slinkBack = slinksBack[j];
0109
0110 const auto [paramFront, covFront] = pairOpt.paramCovAccessor(slinkFront);
0111 const auto [gposFront, gtimeFront, gcovFront, gcovtFront] =
0112 m_spUtility->globalCoords(gctx, slinkFront,
0113 m_config.slSurfaceAccessor, paramFront,
0114 covFront);
0115
0116 const auto [paramBack, covBack] = pairOpt.paramCovAccessor(slinkBack);
0117 const auto [gposBack, gtimeBack, gcovBack, gcovtBack] =
0118 m_spUtility->globalCoords(gctx, slinkBack, m_config.slSurfaceAccessor,
0119 paramBack, covBack);
0120
0121 auto res = m_spUtility->differenceOfMeasurementsChecked(
0122 gposFront, gposBack, pairOpt.vertex, pairOpt.diffDist,
0123 pairOpt.diffPhi2, pairOpt.diffTheta2);
0124 if (!res.ok()) {
0125 continue;
0126 }
0127 const auto distance = res.value();
0128 if (distance >= 0. && distance < minDistance) {
0129 minDistance = distance;
0130 closestIndex = j;
0131 }
0132 }
0133 if (closestIndex < slinksBack.size()) {
0134 slinkPairs.emplace_back(slinksFront[i], slinksBack[closestIndex]);
0135 }
0136 }
0137 }
0138
0139 }