Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndexedRootVolumeFinderBuilder.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file IndexedRootVolumeFinderBuilder.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
10 
16 
17 namespace {
18 
19 template <typename Grid2D>
20 void fillGridIndices2D(
22  const std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>&
23  rootVolumes,
24  const std::array<std::vector<Acts::ActsScalar>, 2u>& boundaries,
25  const std::array<Acts::BinningValue, 2u>& casts) {
26  // Brute force loop over all bins & all volumes
27  for (const auto [ic0, c0] : Acts::enumerate(boundaries[0u])) {
28  if (ic0 > 0) {
29  Acts::ActsScalar v0 = 0.5 * (c0 + boundaries[0u][ic0 - 1]);
30  for (const auto [ic1, c1] : Acts::enumerate(boundaries[1u])) {
31  if (ic1 > 0) {
32  Acts::ActsScalar v1 = 0.5 * (c1 + boundaries[1u][ic1 - 1]);
33  if (casts ==
34  std::array<Acts::BinningValue, 2u>{Acts::binZ, Acts::binR}) {
35  Acts::Vector3 zrPosition{v1, 0., v0};
36  for (const auto [iv, v] : Acts::enumerate(rootVolumes)) {
37  if (v->inside(gctx, zrPosition)) {
38  typename Grid2D::point_t p{v0, v1};
39  grid.atPosition(p) = iv;
40  }
41  }
42  }
43  }
44  }
45  }
46  }
47 }
48 } // namespace
49 
51  IndexedRootVolumeFinderBuilder(std::vector<Acts::BinningValue> binning)
52  : m_casts(std::move(binning)) {
53  if (m_casts != std::vector<Acts::BinningValue>{Acts::binZ, Acts::binR}) {
54  throw std::invalid_argument("Online (z,r) binning is currently supported.");
55  }
56 }
57 
60  const GeometryContext& gctx,
61  const std::vector<std::shared_ptr<DetectorVolume>>& rootVolumes) const {
62  auto rzphis =
64 
65  using AxesGeneratorType =
67 
68  AxesGeneratorType zrAxes{rzphis[1], rzphis[0]};
69 
70  // Create the grid with the provided axis generator
71  using GridType = typename AxesGeneratorType::template grid_type<std::size_t>;
72  GridType grid(zrAxes());
73 
74  auto casts = std::array<BinningValue, 2u>{m_casts[0u], m_casts[1u]};
75 
76  auto boundaries =
77  std::array<std::vector<ActsScalar>, 2u>{rzphis[1], rzphis[0]};
78  fillGridIndices2D(gctx, grid, rootVolumes, boundaries, casts);
79 
83 
84  auto indexedDetectorVolumeImpl =
85  std::make_unique<const IndexedDetectorVolumeImpl>(std::move(grid), casts);
86 
87  // Return the root volume finder
88  DetectorVolumeUpdator rootVolumeFinder;
89  rootVolumeFinder.connect<&IndexedDetectorVolumeImpl::update>(
90  std::move(indexedDetectorVolumeImpl));
91  return rootVolumeFinder;
92 }