Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 07:49:56

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 #include "Acts/Detector/GeometryIdGenerator.hpp"
0010 
0011 #include "Acts/Detector/DetectorVolume.hpp"
0012 #include "Acts/Detector/Portal.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 
0015 Acts::Experimental::IGeometryIdGenerator::GeoIdCache
0016 Acts::Experimental::GeometryIdGenerator::generateCache() const {
0017   return Cache{};
0018 }
0019 
0020 void Acts::Experimental::GeometryIdGenerator::assignGeometryId(
0021     IGeometryIdGenerator::GeoIdCache& cache, DetectorVolume& dVolume) const {
0022   auto& ccache = std::any_cast<Cache&>(cache);
0023 
0024   ACTS_VERBOSE("Processing volume " << dVolume.name());
0025   // Set to the volume itself
0026   if (dVolume.geometryId().volume() == 0 || m_cfg.overrideExistingIds) {
0027     ++ccache.volumeCount;
0028     GeometryIdentifier geoID = volumeId(ccache);
0029     ACTS_VERBOSE("Assigning volume id " << geoID.volume());
0030     dVolume.assignGeometryId(geoID);
0031   }
0032 
0033   // Portals
0034   std::ranges::for_each(dVolume.portalPtrs(), [&](auto& portal) {
0035     assignGeometryId(cache, *portal);
0036   });
0037 
0038   // Surfaces
0039   std::ranges::for_each(dVolume.surfacePtrs(), [&](auto& surface) {
0040     assignGeometryId(cache, *surface);
0041   });
0042 
0043   if (m_cfg.resetSubCounters) {
0044     ccache.portalCount = 0u;
0045     ccache.sensitiveCount = 0u;
0046     ccache.passiveCount = 0u;
0047   }
0048 
0049   // Sub volumes
0050   std::ranges::for_each(dVolume.volumePtrs(), [&](auto& volume) {
0051     assignGeometryId(cache, *volume);
0052   });
0053 }
0054 
0055 void Acts::Experimental::GeometryIdGenerator::assignGeometryId(
0056     IGeometryIdGenerator::GeoIdCache& cache, Portal& portal) const {
0057   auto& ccache = std::any_cast<Cache&>(cache);
0058 
0059   auto& pSurface = portal.surface();
0060   if (pSurface.geometryId().boundary() == 0 || m_cfg.overrideExistingIds) {
0061     GeometryIdentifier geoID = volumeId(ccache, false);
0062     geoID = geoID.withBoundary(++ccache.portalCount);
0063     ACTS_VERBOSE("Assigning portal id " << ccache.portalCount);
0064     pSurface.assignGeometryId(geoID);
0065   }
0066 }
0067 
0068 void Acts::Experimental::GeometryIdGenerator::assignGeometryId(
0069     IGeometryIdGenerator::GeoIdCache& cache, Surface& surface) const {
0070   auto& ccache = std::any_cast<Cache&>(cache);
0071 
0072   auto rGeoID = surface.geometryId();
0073   auto geoID = volumeId(ccache, false);
0074   if (!m_cfg.overrideExistingIds && rGeoID.value() != 0) {
0075     return;
0076   } else if ((rGeoID.sensitive() == 0 && rGeoID.passive() == 0) ||
0077              m_cfg.overrideExistingIds) {
0078     if (surface.associatedDetectorElement() != nullptr) {
0079       geoID = geoID.withSensitive(++ccache.sensitiveCount);
0080       ACTS_VERBOSE("Assigning sensitive id " << ccache.sensitiveCount);
0081     } else {
0082       ACTS_VERBOSE("Assigning passive id " << ccache.passiveCount);
0083       geoID = geoID.withPassive(++ccache.passiveCount);
0084     }
0085     surface.assignGeometryId(geoID);
0086   } else if (rGeoID.sensitive() != 0 || rGeoID.passive() != 0) {
0087     ACTS_VERBOSE(
0088         "Surface already has a geometry id, only setting volume and layer id.");
0089     rGeoID = rGeoID.withVolume(geoID.volume()).withLayer(geoID.layer());
0090     surface.assignGeometryId(rGeoID);
0091   }
0092 }
0093 
0094 Acts::GeometryIdentifier Acts::Experimental::GeometryIdGenerator::volumeId(
0095     Cache& cache, bool incrementLayer) const {
0096   GeometryIdentifier geoID(0u);
0097   if (!m_cfg.containerMode) {
0098     geoID = geoID.withVolume(cache.volumeCount);
0099   } else {
0100     geoID = geoID.withVolume(m_cfg.containerId);
0101     if (incrementLayer) {
0102       ++cache.layerCount;
0103     }
0104     geoID = geoID.withLayer(cache.layerCount);
0105     ACTS_VERBOSE("Container mode: assigning volume id "
0106                  << m_cfg.containerId << ", layer id " << cache.layerCount);
0107   }
0108   return geoID;
0109 }