Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:34

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Detector/IndexedRootVolumeFinderBuilder.hpp"
0010 
0011 #include "Acts/Detector/DetectorVolume.hpp"
0012 #include "Acts/Detector/detail/CylindricalDetectorHelper.hpp"
0013 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0014 #include "Acts/Utilities/Enumerate.hpp"
0015 #include "Acts/Utilities/GridAxisGenerators.hpp"
0016 
0017 namespace {
0018 
0019 template <typename Grid2D>
0020 void fillGridIndices2D(
0021     const Acts::GeometryContext& gctx, Grid2D& grid,
0022     const std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>&
0023         rootVolumes,
0024     const std::array<std::vector<Acts::ActsScalar>, 2u>& boundaries,
0025     const std::array<Acts::BinningValue, 2u>& casts) {
0026   // Brute force loop over all bins & all volumes
0027   for (const auto [ic0, c0] : Acts::enumerate(boundaries[0u])) {
0028     if (ic0 > 0) {
0029       Acts::ActsScalar v0 = 0.5 * (c0 + boundaries[0u][ic0 - 1]);
0030       for (const auto [ic1, c1] : Acts::enumerate(boundaries[1u])) {
0031         if (ic1 > 0) {
0032           Acts::ActsScalar v1 = 0.5 * (c1 + boundaries[1u][ic1 - 1]);
0033           if (casts ==
0034               std::array<Acts::BinningValue, 2u>{Acts::binZ, Acts::binR}) {
0035             Acts::Vector3 zrPosition{v1, 0., v0};
0036             for (const auto [iv, v] : Acts::enumerate(rootVolumes)) {
0037               if (v->inside(gctx, zrPosition)) {
0038                 typename Grid2D::point_t p{v0, v1};
0039                 grid.atPosition(p) = iv;
0040               }
0041             }
0042           }
0043         }
0044       }
0045     }
0046   }
0047 }
0048 }  // namespace
0049 
0050 Acts::Experimental::IndexedRootVolumeFinderBuilder::
0051     IndexedRootVolumeFinderBuilder(std::vector<Acts::BinningValue> binning)
0052     : m_casts(std::move(binning)) {
0053   if (m_casts != std::vector<Acts::BinningValue>{Acts::binZ, Acts::binR}) {
0054     throw std::invalid_argument("Online (z,r) binning is currently supported.");
0055   }
0056 }
0057 
0058 Acts::Experimental::DetectorVolumeUpdater
0059 Acts::Experimental::IndexedRootVolumeFinderBuilder::construct(
0060     const GeometryContext& gctx,
0061     const std::vector<std::shared_ptr<DetectorVolume>>& rootVolumes) const {
0062   auto rzphis =
0063       detail::CylindricalDetectorHelper::rzphiBoundaries(gctx, rootVolumes);
0064 
0065   using AxesGeneratorType = Acts::GridAxisGenerators::VarBoundVarBound;
0066 
0067   AxesGeneratorType zrAxes{rzphis[1], rzphis[0]};
0068 
0069   // Create the grid with the provided axis generator
0070   using GridType = typename AxesGeneratorType::template grid_type<std::size_t>;
0071   GridType grid(zrAxes());
0072 
0073   auto casts = std::array<BinningValue, 2u>{m_casts[0u], m_casts[1u]};
0074 
0075   auto boundaries =
0076       std::array<std::vector<ActsScalar>, 2u>{rzphis[1], rzphis[0]};
0077   fillGridIndices2D(gctx, grid, rootVolumes, boundaries, casts);
0078 
0079   using IndexedDetectorVolumesImpl =
0080       IndexedUpdaterImpl<GridType, IndexedDetectorVolumeExtractor,
0081                          DetectorVolumeFiller>;
0082 
0083   auto indexedDetectorVolumeImpl =
0084       std::make_unique<const IndexedDetectorVolumesImpl>(std::move(grid),
0085                                                          casts);
0086 
0087   // Return the root volume finder
0088   DetectorVolumeUpdater rootVolumeFinder;
0089   rootVolumeFinder.connect<&IndexedDetectorVolumesImpl::update>(
0090       std::move(indexedDetectorVolumeImpl));
0091   return rootVolumeFinder;
0092 }