Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:45

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Detector/DetectorComponents.hpp"
0014 #include "Acts/Detector/Portal.hpp"
0015 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Geometry/VolumeBounds.hpp"
0018 #include "Acts/Utilities/Logger.hpp"
0019 
0020 #include <array>
0021 #include <limits>
0022 #include <map>
0023 #include <memory>
0024 #include <vector>
0025 
0026 namespace Acts::Experimental {
0027 
0028 class DetectorVolume;
0029 class Portal;
0030 
0031 namespace detail::CylindricalDetectorHelper {
0032 
0033 /// @brief Connect detector volumes in R
0034 ///
0035 /// @param gctx The geometry context
0036 /// @param volumes the volumes
0037 /// @param selectedOnly switch only selected boundaries
0038 /// @param logLevel is the screen logging level
0039 ///
0040 /// @note a fair amount of consistency checking is done,
0041 /// and exceptions are thrown if any of the tests fail
0042 ///
0043 /// @return a proto container with the outside portals
0044 DetectorComponent::PortalContainer connectInR(
0045     const GeometryContext& gctx,
0046     std::vector<std::shared_ptr<DetectorVolume>>& volumes,
0047     const std::vector<unsigned int>& selectedOnly = {},
0048     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0049 
0050 /// @brief Connect detector volumes in Z
0051 ///
0052 /// @param gctx The geometry context
0053 /// @param volumes the volumes
0054 /// @param selectedOnly switch only selected boundaries
0055 /// @param logLevel is the screen logging level
0056 ///
0057 /// @note a fair amount of consistency checking is done,
0058 /// and exceptions are thrown if any of the tests fail
0059 ///
0060 /// @return a proto container with the outside portals
0061 DetectorComponent::PortalContainer connectInZ(
0062     const GeometryContext& gctx,
0063     std::vector<std::shared_ptr<DetectorVolume>>& volumes,
0064     const std::vector<unsigned int>& selectedOnly = {},
0065     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0066 
0067 /// @brief Connect detector volumes in phi
0068 ///
0069 /// @param gctx The geometry context
0070 /// @param volumes the volumes
0071 /// @param selectedOnly switch only selected boundaries
0072 /// @param logLevel is the screen logging level
0073 ///
0074 /// @note a fair amount of consistency checking is done,
0075 /// and exceptions are thrown if any of the tests fail
0076 ///
0077 /// @return a proto container with the outside portals
0078 DetectorComponent::PortalContainer connectInPhi(
0079     const GeometryContext& gctx,
0080     std::vector<std::shared_ptr<DetectorVolume>>& volumes,
0081     const std::vector<unsigned int>& selectedOnly = {},
0082     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0083 
0084 /// @brief Wrap detector volumes in R,Z
0085 ///
0086 /// @param gctx The geometry context
0087 /// @param volumes the volumes
0088 /// @param logLevel is the screen logging level
0089 ///
0090 /// @note a fair amount of consistency checking is done,
0091 /// and exceptions are thrown if any of the tests fail
0092 ///
0093 /// @return a proto container with the outside portals
0094 DetectorComponent::PortalContainer wrapInZR(
0095     const GeometryContext& gctx,
0096     std::vector<std::shared_ptr<DetectorVolume>>& volumes,
0097     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0098 
0099 /// @brief Connect containers in R
0100 ///
0101 /// @param gctx The geometry context
0102 /// @param containers the containers
0103 /// @param selectedOnly switch only selected boundaries
0104 /// @param logLevel is the screen logging level
0105 ///
0106 /// @note not much checking is done anymore, as the DetectorComponent::PortalContainer
0107 /// are assumed to come properly formed from the prior methods
0108 ///
0109 /// @return a proto container with the outside portals
0110 DetectorComponent::PortalContainer connectInR(
0111     const GeometryContext& gctx,
0112     const std::vector<DetectorComponent::PortalContainer>& containers,
0113     const std::vector<unsigned int>& selectedOnly = {},
0114     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0115 
0116 /// @brief Connect containers in Z
0117 ///
0118 /// @param gctx The geometry context
0119 /// @param containers the containers
0120 /// @param selectedOnly switch only selected boundaries
0121 /// @param logLevel is the screen logging level
0122 ///
0123 /// @note not much checking is done anymore, as the DetectorComponent::PortalContainer
0124 /// are assumed to come properly formed from the prior methods
0125 ///
0126 /// @return a proto container with the outside portals
0127 DetectorComponent::PortalContainer connectInZ(
0128     const GeometryContext& gctx,
0129     const std::vector<DetectorComponent::PortalContainer>& containers,
0130     const std::vector<unsigned int>& selectedOnly = {},
0131     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0132 
0133 /// @brief Connect containers in Phi
0134 ///
0135 /// @param gctx The geometry context
0136 /// @param containers the containers
0137 /// @param selectedOnly switch only selected boundaries
0138 /// @param logLevel is the screen logging level
0139 ///
0140 /// @note not much checking is done anymore, as the DetectorComponent::PortalContainer
0141 /// are assumed to come properly formed from the prior methods
0142 ///
0143 /// @return a proto container with the outside portals
0144 DetectorComponent::PortalContainer connectInPhi(
0145     const GeometryContext& gctx,
0146     const std::vector<DetectorComponent::PortalContainer>& containers,
0147     const std::vector<unsigned int>& selectedOnly = {},
0148     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0149 
0150 /// @brief Wrap container in R,Z - this uses the cutout cylinder bounds
0151 ///
0152 /// @param gctx The geometry context
0153 /// @param containers the containers, i.e. the inner volume and the wrapping container
0154 /// @param logLevel is the screen logging level
0155 ///
0156 /// @note not much checking is done anymore, as the DetectorComponent::PortalContainer
0157 /// are assumed to come properly formed from the prior methods
0158 ///
0159 /// @return a proto container with the outside portals
0160 DetectorComponent::PortalContainer wrapInZR(
0161     const GeometryContext& gctx,
0162     const std::vector<DetectorComponent::PortalContainer>& containers,
0163     Acts::Logging::Level logLevel = Acts::Logging::INFO);
0164 
0165 /// @brief Helper method to extract r,z,phi boundaries for
0166 /// eventual grid volume search
0167 ///
0168 /// @tparam volume_container_t the type of the container
0169 ///
0170 /// @param gctx the geometry context of the call
0171 /// @param volumes the volumes at input
0172 /// @param precision the precision to be used for (optionally)
0173 /// @param logLevel is the screen logging level
0174 ///
0175 /// @return extracted boundary values
0176 template <typename volume_container_t>
0177 std::array<std::vector<double>, 3u> rzphiBoundaries(
0178     const GeometryContext& gctx, const volume_container_t& volumes,
0179     double precision = 0.,
0180     Acts::Logging::Level logLevel = Acts::Logging::INFO) {
0181   // The local logger
0182   ACTS_LOCAL_LOGGER(getDefaultLogger("CylindricalDetectorHelper", logLevel));
0183 
0184   ACTS_DEBUG("Estimate R/z/phi boundaries of  " << volumes.size()
0185                                                 << " volumes.");
0186 
0187   // The return boundaries
0188   std::array<std::set<double>, 3u> uniqueBoundaries;
0189   auto insertWithPrecision = [&](std::size_t is, double value) -> void {
0190     if (precision == 0.) {
0191       uniqueBoundaries[is].insert(value);
0192       return;
0193     }
0194     uniqueBoundaries[is].insert(std::round(value / precision) * precision);
0195   };
0196 
0197   // Loop over the volumes and collect boundaries
0198   for (const auto& v : volumes) {
0199     if (v->volumeBounds().type() == VolumeBounds::BoundsType::eCylinder) {
0200       const auto& bValues = v->volumeBounds().values();
0201       // The min/max values
0202       double rMin = bValues[CylinderVolumeBounds::BoundValues::eMinR];
0203       double rMax = bValues[CylinderVolumeBounds::BoundValues::eMaxR];
0204       double zCenter = v->transform(gctx).translation().z();
0205       double zHalfLength =
0206           bValues[CylinderVolumeBounds::BoundValues::eHalfLengthZ];
0207       double zMin = zCenter - zHalfLength;
0208       double zMax = zCenter + zHalfLength;
0209       double phiCenter =
0210           bValues[CylinderVolumeBounds::BoundValues::eAveragePhi];
0211       double phiSector =
0212           bValues[CylinderVolumeBounds::BoundValues::eHalfPhiSector];
0213       double phiMin = phiCenter - phiSector;
0214       double phiMax = phiCenter + phiSector;
0215       // Fill the sets
0216       insertWithPrecision(0u, rMin);
0217       insertWithPrecision(0u, rMax);
0218       insertWithPrecision(1u, zMin);
0219       insertWithPrecision(1u, zMax);
0220       insertWithPrecision(2u, phiMin);
0221       insertWithPrecision(2u, phiMax);
0222     }
0223   }
0224 
0225   ACTS_VERBOSE("- did yield " << uniqueBoundaries[0u].size()
0226                               << " boundaries in R.");
0227   ACTS_VERBOSE("- did yield " << uniqueBoundaries[1u].size()
0228                               << " boundaries in z.");
0229   ACTS_VERBOSE("- did yield " << uniqueBoundaries[2u].size()
0230                               << " boundaries in phi.");
0231 
0232   return {{std::vector<double>(uniqueBoundaries[0].begin(),
0233                                uniqueBoundaries[0].end()),
0234            std::vector<double>(uniqueBoundaries[1].begin(),
0235                                uniqueBoundaries[1].end()),
0236            std::vector<double>(uniqueBoundaries[2].begin(),
0237                                uniqueBoundaries[2].end())}};
0238 }
0239 
0240 }  // namespace detail::CylindricalDetectorHelper
0241 }  // namespace Acts::Experimental