Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpacePointBuilder.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SpacePointBuilder.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2022 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 namespace Acts {
9 
10 template <typename spacepoint_t>
13  std::function<spacepoint_t(Acts::Vector3, Acts::Vector2,
14  boost::container::static_vector<SourceLink, 2>)>
15  func,
16  std::unique_ptr<const Logger> logger)
17  : m_config(cfg), m_spConstructor(func), m_logger(std::move(logger)) {
18  m_spUtility = std::make_shared<SpacePointUtility>(cfg);
19 }
20 
21 template <typename spacepoint_t>
22 template <template <typename...> typename container_t>
24  const GeometryContext& gctx, const std::vector<SourceLink>& sourceLinks,
25  const SpacePointBuilderOptions& opt,
26  std::back_insert_iterator<container_t<spacepoint_t>> spacePointIt) const {
27  const unsigned int num_slinks = sourceLinks.size();
28 
29  Acts::Vector3 gPos = Acts::Vector3::Zero();
30  Acts::Vector2 gCov = Acts::Vector2::Zero();
31 
32  if (num_slinks == 1) { // pixel SP formation
33  auto slink = sourceLinks.at(0);
34  auto [param, cov] = opt.paramCovAccessor(sourceLinks.at(0));
35  auto gPosCov = m_spUtility->globalCoords(
36  gctx, slink, m_config.slSurfaceAccessor, param, cov);
37  gPos = gPosCov.first;
38  gCov = gPosCov.second;
39  } else if (num_slinks == 2) { // strip SP formation
40 
41  const auto& ends1 = opt.stripEndsPair.first;
42  const auto& ends2 = opt.stripEndsPair.second;
43 
45 
46  if (!m_config.usePerpProj) { // default strip SP building
47 
48  auto spFound = m_spUtility->calculateStripSPPosition(
49  ends1, ends2, opt.vertex, spParams, opt.stripLengthTolerance);
50 
51  if (!spFound.ok()) {
52  spFound = m_spUtility->recoverSpacePoint(spParams,
54  }
55 
56  if (!spFound.ok()) {
57  return;
58  }
59 
60  gPos = 0.5 *
61  (ends1.first + ends1.second + spParams.m * spParams.firstBtmToTop);
62 
63  } else { // for cosmic without vertex constraint
64 
65  auto resultPerpProj =
66  m_spUtility->calcPerpendicularProjection(ends1, ends2, spParams);
67 
68  if (!resultPerpProj.ok()) {
69  return;
70  }
71  gPos = ends1.first + resultPerpProj.value() * spParams.firstBtmToTop;
72  }
73 
74  double theta =
75  acos(spParams.firstBtmToTop.dot(spParams.secondBtmToTop) /
76  (spParams.firstBtmToTop.norm() * spParams.secondBtmToTop.norm()));
77 
78  gCov = m_spUtility->calcRhoZVars(gctx, sourceLinks.at(0), sourceLinks.at(1),
79  m_config.slSurfaceAccessor,
80  opt.paramCovAccessor, gPos, theta);
81 
82  } else {
83  ACTS_ERROR("More than 2 sourceLinks are given for a space point.");
84  }
85  boost::container::static_vector<SourceLink, 2> slinks(sourceLinks.begin(),
86  sourceLinks.end());
87 
88  spacePointIt = m_spConstructor(gPos, gCov, std::move(slinks));
89 }
90 
91 template <typename spacepoint_t>
93  const GeometryContext& gctx, const std::vector<SourceLink>& slinksFront,
94  const std::vector<SourceLink>& slinksBack,
95  std::vector<std::pair<SourceLink, SourceLink>>& slinkPairs,
96  const StripPairOptions& pairOpt) const {
97  if (slinksFront.empty() || slinksBack.empty()) {
98  return;
99  }
100  double minDistance = 0;
101  unsigned int closestIndex = 0;
102 
103  for (unsigned int i = 0; i < slinksFront.size(); i++) {
104  const auto& slinkFront = slinksFront[i];
105  minDistance = std::numeric_limits<double>::max();
106  closestIndex = slinksBack.size();
107  for (unsigned int j = 0; j < slinksBack.size(); j++) {
108  const auto& slinkBack = slinksBack[j];
109 
110  const auto [paramFront, covFront] = pairOpt.paramCovAccessor(slinkFront);
111  const auto [gposFront, gcovFront] = m_spUtility->globalCoords(
112  gctx, slinkFront, m_config.slSurfaceAccessor, paramFront, covFront);
113 
114  const auto [paramBack, covBack] = pairOpt.paramCovAccessor(slinkBack);
115  const auto [gposBack, gcovBack] = m_spUtility->globalCoords(
116  gctx, slinkBack, m_config.slSurfaceAccessor, paramBack, covBack);
117 
118  auto res = m_spUtility->differenceOfMeasurementsChecked(
119  gposFront, gposBack, pairOpt.vertex, pairOpt.diffDist,
120  pairOpt.diffPhi2, pairOpt.diffTheta2);
121  if (!res.ok()) {
122  continue;
123  }
124  const auto distance = res.value();
125  if (distance >= 0. && distance < minDistance) {
126  minDistance = distance;
127  closestIndex = j;
128  }
129  }
130  if (closestIndex < slinksBack.size()) {
131  slinkPairs.emplace_back(slinksFront[i], slinksBack[closestIndex]);
132  }
133  }
134 }
135 
136 } // namespace Acts