Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:18

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::for_each(dVolume.portalPtrs().begin(), dVolume.portalPtrs().end(),
0035                 [&](auto& portal) { assignGeometryId(cache, *portal); });
0036 
0037   // Surfaces
0038   std::for_each(dVolume.surfacePtrs().begin(), dVolume.surfacePtrs().end(),
0039                 [&](auto& surface) { assignGeometryId(cache, *surface); });
0040 
0041   if (m_cfg.resetSubCounters) {
0042     ccache.portalCount = 0u;
0043     ccache.sensitiveCount = 0u;
0044     ccache.passiveCount = 0u;
0045   }
0046 
0047   // Sub volumes
0048   std::for_each(dVolume.volumePtrs().begin(), dVolume.volumePtrs().end(),
0049                 [&](auto& volume) { assignGeometryId(cache, *volume); });
0050 }
0051 
0052 void Acts::Experimental::GeometryIdGenerator::assignGeometryId(
0053     IGeometryIdGenerator::GeoIdCache& cache, Portal& portal) const {
0054   auto& ccache = std::any_cast<Cache&>(cache);
0055 
0056   auto& pSurface = portal.surface();
0057   if (pSurface.geometryId().boundary() == 0 || m_cfg.overrideExistingIds) {
0058     GeometryIdentifier geoID = volumeId(ccache, false);
0059     geoID.setBoundary(++ccache.portalCount);
0060     ACTS_VERBOSE("Assigning portal id " << ccache.portalCount);
0061     pSurface.assignGeometryId(geoID);
0062   }
0063 }
0064 
0065 void Acts::Experimental::GeometryIdGenerator::assignGeometryId(
0066     IGeometryIdGenerator::GeoIdCache& cache, Surface& surface) const {
0067   auto& ccache = std::any_cast<Cache&>(cache);
0068 
0069   auto rGeoID = surface.geometryId();
0070   auto geoID = volumeId(ccache, false);
0071   if (!m_cfg.overrideExistingIds && rGeoID.value() != 0) {
0072     return;
0073   } else if ((rGeoID.sensitive() == 0 && rGeoID.passive() == 0) ||
0074              m_cfg.overrideExistingIds) {
0075     if (surface.associatedDetectorElement() != nullptr) {
0076       geoID.setSensitive(++ccache.sensitiveCount);
0077       ACTS_VERBOSE("Assigning sensitive id " << ccache.sensitiveCount);
0078     } else {
0079       ACTS_VERBOSE("Assigning passive id " << ccache.passiveCount);
0080       geoID.setPassive(++ccache.passiveCount);
0081     }
0082     surface.assignGeometryId(geoID);
0083   } else if (rGeoID.sensitive() != 0 || rGeoID.passive() != 0) {
0084     ACTS_VERBOSE(
0085         "Surface already has a geometry id, only setting volume and layer id.");
0086     rGeoID.setVolume(geoID.volume());
0087     rGeoID.setLayer(geoID.layer());
0088     surface.assignGeometryId(rGeoID);
0089   }
0090 }
0091 
0092 Acts::GeometryIdentifier Acts::Experimental::GeometryIdGenerator::volumeId(
0093     Cache& cache, bool incrementLayer) const {
0094   GeometryIdentifier geoID(0u);
0095   if (!m_cfg.containerMode) {
0096     geoID.setVolume(cache.volumeCount);
0097   } else {
0098     geoID.setVolume(m_cfg.containerId);
0099     if (incrementLayer) {
0100       ++cache.layerCount;
0101     }
0102     geoID.setLayer(cache.layerCount);
0103     ACTS_VERBOSE("Container mode: assigning volume id "
0104                  << m_cfg.containerId << ", layer id " << cache.layerCount);
0105   }
0106   return geoID;
0107 }