File indexing completed on 2025-10-27 07:56:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/DetectorVolume.hpp"
0013 #include "Acts/Detector/GeometryIdGenerator.hpp"
0014 #include "Acts/Detector/Portal.hpp"
0015 #include "Acts/Detector/PortalGenerators.hpp"
0016 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0017 #include "Acts/Geometry/GeometryContext.hpp"
0018 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0019 #include "Acts/Navigation/InternalNavigation.hpp"
0020 #include "Acts/Surfaces/CylinderSurface.hpp"
0021 #include "Acts/Utilities/Enumerate.hpp"
0022 #include "Acts/Utilities/Logger.hpp"
0023 #include "ActsTests/CommonHelpers/DetectorElementStub.hpp"
0024
0025 #include <memory>
0026 #include <vector>
0027
0028 using namespace Acts;
0029 using namespace Acts::Experimental;
0030
0031 GeometryContext tContext;
0032
0033 namespace ActsTests {
0034
0035 std::vector<std::shared_ptr<DetectorVolume>> createVolumes(
0036 std::vector<std::shared_ptr<ActsTests::DetectorElementStub>>&
0037 detectorStore) {
0038 auto portalGenerator = defaultPortalGenerator();
0039
0040 auto gap0VoumeBounds = std::make_unique<CylinderVolumeBounds>(0, 80, 200);
0041
0042 auto gap0Volume = DetectorVolumeFactory::construct(
0043 portalGenerator, tContext, "Gap0Volume", Transform3::Identity(),
0044 std::move(gap0VoumeBounds), {}, {}, tryNoVolumes(), tryAllPortals());
0045
0046 std::vector<double> layer0Radii = {100, 102, 104, 106, 108, 110};
0047 auto layer0VolumeBounds =
0048 std::make_unique<CylinderVolumeBounds>(80, 130, 200);
0049 std::vector<std::shared_ptr<Surface>> layer0Surfaces = {};
0050 for (const auto [ir, r] : enumerate(layer0Radii)) {
0051
0052 if (ir < 4u) {
0053 auto detElement = std::make_shared<ActsTests::DetectorElementStub>(
0054 Transform3::Identity(), std::make_shared<CylinderBounds>(r, 190),
0055 0.1);
0056 detectorStore.push_back(detElement);
0057 layer0Surfaces.push_back(detElement->surface().getSharedPtr());
0058 } else {
0059
0060 layer0Surfaces.push_back(Surface::makeShared<CylinderSurface>(
0061 Transform3::Identity(), std::make_shared<CylinderBounds>(r, 190)));
0062 }
0063 }
0064
0065 auto layer0Volume = DetectorVolumeFactory::construct(
0066 portalGenerator, tContext, "CylinderVolume", Transform3::Identity(),
0067 std::move(layer0VolumeBounds), layer0Surfaces, {}, tryNoVolumes(),
0068 tryAllPortalsAndSurfaces());
0069
0070 auto gap1VoumeBounds = std::make_unique<CylinderVolumeBounds>(130, 200, 200);
0071
0072 auto gap1Volume = DetectorVolumeFactory::construct(
0073 portalGenerator, tContext, "Gap1Volume", Transform3::Identity(),
0074 std::move(gap1VoumeBounds), {}, {}, tryNoVolumes(), tryAllPortals());
0075
0076 return {gap0Volume, layer0Volume, gap1Volume};
0077 }
0078
0079
0080 struct GeoIdIncrementer : public IGeometryIdGenerator {
0081 struct Cache {};
0082
0083
0084
0085 IGeometryIdGenerator::GeoIdCache generateCache() const final {
0086
0087 return Cache{};
0088 }
0089
0090
0091
0092
0093
0094 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0095 DetectorVolume& dVolume) const final {
0096 auto vgid = dVolume.geometryId();
0097 dVolume.assignGeometryId(
0098 dVolume.geometryId().withVolume(vgid.volume() + 1));
0099 }
0100
0101
0102
0103
0104
0105 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0106 Acts::Experimental::Portal& portal) const final {
0107 auto pgid = portal.surface().geometryId();
0108 portal.surface().assignGeometryId(pgid.withBoundary(pgid.boundary() + 1));
0109 }
0110
0111
0112
0113
0114
0115 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0116 Surface& surface) const final {
0117 auto sgid = surface.geometryId();
0118 if (sgid.sensitive() != 0u) {
0119 sgid = sgid.withSensitive(sgid.sensitive() + 1);
0120 } else {
0121 sgid = sgid.withPassive(sgid.passive() + 1);
0122 }
0123 surface.assignGeometryId(sgid);
0124 }
0125 };
0126
0127 BOOST_AUTO_TEST_SUITE(DetectorSuite)
0128
0129 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorReset) {
0130 std::vector<std::shared_ptr<ActsTests::DetectorElementStub>> detectorStore;
0131
0132 auto volumes = createVolumes(detectorStore);
0133
0134 GeometryIdGenerator::Config cfg;
0135 GeometryIdGenerator generator(
0136 cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
0137
0138 auto cache = generator.generateCache();
0139 for (auto& volume : volumes) {
0140 generator.assignGeometryId(cache, *volume);
0141 }
0142
0143
0144 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 1);
0145 for (auto [ip, p] : enumerate(volumes[0]->portals())) {
0146 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0147 }
0148
0149 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 2);
0150 for (auto [ip, p] : enumerate(volumes[1]->portals())) {
0151 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0152 }
0153 for (auto [is, s] : enumerate(volumes[1]->surfaces())) {
0154 if (is < 4u) {
0155 BOOST_CHECK_EQUAL(s->geometryId().sensitive(), is + 1);
0156 } else {
0157 BOOST_CHECK_EQUAL(s->geometryId().passive(), is - 3);
0158 }
0159 }
0160
0161 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 3);
0162 for (auto [ip, p] : enumerate(volumes[2]->portals())) {
0163 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0164 }
0165 }
0166
0167 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorNoReset) {
0168 std::vector<std::shared_ptr<ActsTests::DetectorElementStub>> detectorStore;
0169
0170 auto volumes = createVolumes(detectorStore);
0171
0172 GeometryIdGenerator::Config cfg;
0173 cfg.resetSubCounters = false;
0174 GeometryIdGenerator generator(
0175 cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
0176
0177 auto cache = generator.generateCache();
0178 for (auto& volume : volumes) {
0179 generator.assignGeometryId(cache, *volume);
0180 }
0181
0182
0183 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 1);
0184 unsigned int portalCounter = 1;
0185 for (auto [ip, p] : enumerate(volumes[0]->portals())) {
0186 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0187 }
0188
0189 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 2);
0190 for (auto [ip, p] : enumerate(volumes[1]->portals())) {
0191 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0192 }
0193
0194 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 3);
0195 for (auto [ip, p] : enumerate(volumes[2]->portals())) {
0196 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0197 }
0198 }
0199
0200 BOOST_AUTO_TEST_CASE(ContainerGeoIdGenerator) {
0201 std::vector<std::shared_ptr<ActsTests::DetectorElementStub>> detectorStore;
0202
0203 auto volumes = createVolumes(detectorStore);
0204
0205 GeometryIdGenerator::Config cfg;
0206 cfg.containerMode = true;
0207 cfg.containerId = 15;
0208 GeometryIdGenerator generator(
0209 cfg, getDefaultLogger("ContainerIdGenerator", Logging::VERBOSE));
0210
0211 auto cache = generator.generateCache();
0212 for (auto& volume : volumes) {
0213 generator.assignGeometryId(cache, *volume);
0214 }
0215
0216 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 15);
0217 BOOST_CHECK_EQUAL(volumes[0]->geometryId().layer(), 1);
0218 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 15);
0219 BOOST_CHECK_EQUAL(volumes[1]->geometryId().layer(), 2);
0220 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 15);
0221 BOOST_CHECK_EQUAL(volumes[2]->geometryId().layer(), 3);
0222 }
0223
0224 BOOST_AUTO_TEST_CASE(ChainedGeoIdGenerator) {
0225 std::vector<std::shared_ptr<ActsTests::DetectorElementStub>> detectorStore;
0226
0227 auto volumes = createVolumes(detectorStore);
0228
0229 GeometryIdGenerator::Config cfg;
0230
0231 cfg.containerMode = true;
0232 cfg.containerId = 15;
0233 auto cgenerator = std::make_shared<GeometryIdGenerator>(
0234 cfg, getDefaultLogger("ContainerIdGenerator", Logging::VERBOSE));
0235
0236 auto igenerator = std::make_shared<GeoIdIncrementer>();
0237
0238 std::tuple<std::shared_ptr<const GeometryIdGenerator>,
0239 std::shared_ptr<const GeoIdIncrementer>>
0240 geoGenerators = {cgenerator, igenerator};
0241
0242 ChainedGeometryIdGenerator<std::shared_ptr<const GeometryIdGenerator>,
0243 std::shared_ptr<const GeoIdIncrementer>>
0244 generator(std::move(geoGenerators));
0245
0246 auto cache = generator.generateCache();
0247 for (auto& volume : volumes) {
0248 generator.assignGeometryId(cache, *volume);
0249 }
0250
0251 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 16);
0252 BOOST_CHECK_EQUAL(volumes[0]->geometryId().layer(), 1);
0253 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 16);
0254 BOOST_CHECK_EQUAL(volumes[1]->geometryId().layer(), 2);
0255 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 16);
0256 BOOST_CHECK_EQUAL(volumes[2]->geometryId().layer(), 3);
0257 }
0258
0259 BOOST_AUTO_TEST_SUITE_END()
0260
0261 }