Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryIdGenerator.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeometryIdGenerator.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 
12 #include "Acts/Detector/Portal.hpp"
14 
17  return Cache{};
18 }
19 
21  IGeometryIdGenerator::GeoIdCache& cache, DetectorVolume& dVolume) const {
22  auto& ccache = std::any_cast<Cache&>(cache);
23 
24  ACTS_VERBOSE("Processing volume " << dVolume.name());
25  // Set to the volume itself
26  if (dVolume.geometryId().volume() == 0 or m_cfg.overrideExistingIds) {
27  ++ccache.volumeCount;
28  GeometryIdentifier geoID = volumeId(ccache);
29  ACTS_VERBOSE("Assigning volume id " << geoID.volume());
30  dVolume.assignGeometryId(geoID);
31  }
32 
33  // Portals
34  std::for_each(dVolume.portalPtrs().begin(), dVolume.portalPtrs().end(),
35  [&](auto& portal) { assignGeometryId(cache, *portal); });
36 
37  // Surfaces
38  std::for_each(dVolume.surfacePtrs().begin(), dVolume.surfacePtrs().end(),
39  [&](auto& surface) { assignGeometryId(cache, *surface); });
40 
41  if (m_cfg.resetSubCounters) {
42  ccache.portalCount = 0u;
43  ccache.sensitiveCount = 0u;
44  ccache.passiveCount = 0u;
45  }
46 
47  // Sub volumes
48  std::for_each(dVolume.volumePtrs().begin(), dVolume.volumePtrs().end(),
49  [&](auto& volume) { assignGeometryId(cache, *volume); });
50 }
51 
53  IGeometryIdGenerator::GeoIdCache& cache, Portal& portal) const {
54  auto& ccache = std::any_cast<Cache&>(cache);
55 
56  auto& pSurface = portal.surface();
57  if (pSurface.geometryId().boundary() == 0 or m_cfg.overrideExistingIds) {
58  GeometryIdentifier geoID = volumeId(ccache, false);
59  geoID.setBoundary(++ccache.portalCount);
60  ACTS_VERBOSE("Assigning portal id " << ccache.portalCount);
61  pSurface.assignGeometryId(geoID);
62  }
63 }
64 
67  auto& ccache = std::any_cast<Cache&>(cache);
68 
69  auto rGeoID = surface.geometryId();
70  auto geoID = volumeId(ccache, false);
71  if (not m_cfg.overrideExistingIds and rGeoID.value() != 0) {
72  return;
73  } else if ((rGeoID.sensitive() == 0 and rGeoID.passive() == 0) or
74  m_cfg.overrideExistingIds) {
75  if (surface.associatedDetectorElement() != nullptr) {
76  geoID.setSensitive(++ccache.sensitiveCount);
77  ACTS_VERBOSE("Assigning sensitive id " << ccache.sensitiveCount);
78  } else {
79  ACTS_VERBOSE("Assigning passive id " << ccache.passiveCount);
80  geoID.setPassive(++ccache.passiveCount);
81  }
82  surface.assignGeometryId(geoID);
83  } else if (rGeoID.sensitive() != 0 or rGeoID.passive() != 0) {
85  "Surface already has a geometry id, only setting volume and layer id.");
86  rGeoID.setVolume(geoID.volume());
87  rGeoID.setLayer(geoID.layer());
88  surface.assignGeometryId(rGeoID);
89  }
90 }
91 
93  Cache& cache, bool incrementLayer) const {
94  GeometryIdentifier geoID(0u);
95  if (not m_cfg.containerMode) {
96  geoID.setVolume(cache.volumeCount);
97  } else {
98  geoID.setVolume(m_cfg.containerId);
99  if (incrementLayer) {
100  ++cache.layerCount;
101  }
102  geoID.setLayer(cache.layerCount);
103  ACTS_VERBOSE("Container mode: assigning volume id "
104  << m_cfg.containerId << ", layer id " << cache.layerCount);
105  }
106  return geoID;
107 }