EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinnedSPGroup.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinnedSPGroup.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 template <typename external_spacepoint_t>
10 template <typename spacepoint_iterator_t>
12  spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd,
13  std::function<Acts::Vector2D(const external_spacepoint_t&, float, float,
14  float)>
15  covTool,
16  std::shared_ptr<Acts::BinFinder<external_spacepoint_t>> botBinFinder,
17  std::shared_ptr<Acts::BinFinder<external_spacepoint_t>> tBinFinder,
18  std::unique_ptr<SpacePointGrid<external_spacepoint_t>> grid,
20  static_assert(
21  std::is_same<
23  const external_spacepoint_t*>::value,
24  "Iterator does not contain type this class was templated with");
25 
26  // get region of interest (or full detector if configured accordingly)
27  float phiMin = config.phiMin;
28  float phiMax = config.phiMax;
29  float zMin = config.zMin;
30  float zMax = config.zMax;
31 
32  // sort by radius
33  // add magnitude of beamPos to rMax to avoid excluding measurements
34  // create number of bins equal to number of millimeters rMax
35  // (worst case minR: configured minR + 1mm)
36  size_t numRBins = (config.rMax + config.beamPos.norm());
38  std::unique_ptr<const InternalSpacePoint<external_spacepoint_t>>>>
39  rBins(numRBins);
40  for (spacepoint_iterator_t it = spBegin; it != spEnd; it++) {
41  if (*it == nullptr) {
42  continue;
43  }
44  const external_spacepoint_t& sp = **it;
45  float spX = sp.x();
46  float spY = sp.y();
47  float spZ = sp.z();
48 
49  if (spZ > zMax || spZ < zMin) {
50  continue;
51  }
52  float spPhi = std::atan2(spY, spX);
53  if (spPhi > phiMax || spPhi < phiMin) {
54  continue;
55  }
56 
57  // 2D variance tool provided by user
58  Acts::Vector2D variance =
59  covTool(sp, config.zAlign, config.rAlign, config.sigmaError);
60  Acts::Vector3D spPosition(spX, spY, spZ);
61  auto isp =
62  std::make_unique<const InternalSpacePoint<external_spacepoint_t>>(
63  sp, spPosition, config.beamPos, variance);
64  // calculate r-Bin index and protect against overflow (underflow not
65  // possible)
66  size_t rIndex = isp->radius();
67  // if index out of bounds, the SP is outside the region of interest
68  if (rIndex >= numRBins) {
69  continue;
70  }
71  rBins[rIndex].push_back(std::move(isp));
72  }
73  // fill rbins into grid such that each grid bin is sorted in r
74  // space points with delta r < rbin size can be out of order
75  for (auto& rbin : rBins) {
76  for (auto& isp : rbin) {
77  Acts::Vector2D spLocation(isp->phi(), isp->z());
79  std::unique_ptr<const InternalSpacePoint<external_spacepoint_t>>>&
80  bin = grid->atPosition(spLocation);
81  bin.push_back(std::move(isp));
82  }
83  }
84  m_binnedSP = std::move(grid);
85  m_bottomBinFinder = botBinFinder;
86  m_topBinFinder = tBinFinder;
87 }