File indexing completed on 2025-07-11 07:51:08
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/Tests/CommonHelpers/DetectorElementStub.hpp"
0022 #include "Acts/Utilities/Enumerate.hpp"
0023 #include "Acts/Utilities/Logger.hpp"
0024
0025 #include <iostream>
0026 #include <memory>
0027 #include <vector>
0028
0029 using namespace Acts;
0030 using namespace Acts::Experimental;
0031
0032 GeometryContext tContext;
0033
0034 namespace {
0035
0036 std::vector<std::shared_ptr<DetectorVolume>> createVolumes(
0037 std::vector<std::shared_ptr<Test::DetectorElementStub>>& 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<Test::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
0081 struct GeoIdIncrementer : public IGeometryIdGenerator {
0082 struct Cache {};
0083
0084
0085
0086 IGeometryIdGenerator::GeoIdCache generateCache() const final {
0087
0088 return Cache{};
0089 }
0090
0091
0092
0093
0094
0095 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0096 DetectorVolume& dVolume) const final {
0097 auto vgid = dVolume.geometryId();
0098 dVolume.assignGeometryId(
0099 dVolume.geometryId().withVolume(vgid.volume() + 1));
0100 }
0101
0102
0103
0104
0105
0106 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0107 Portal& portal) const final {
0108 auto pgid = portal.surface().geometryId();
0109 portal.surface().assignGeometryId(pgid.withBoundary(pgid.boundary() + 1));
0110 }
0111
0112
0113
0114
0115
0116 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0117 Surface& surface) const final {
0118 auto sgid = surface.geometryId();
0119 if (sgid.sensitive() != 0u) {
0120 sgid = sgid.withSensitive(sgid.sensitive() + 1);
0121 } else {
0122 sgid = sgid.withPassive(sgid.passive() + 1);
0123 }
0124 surface.assignGeometryId(sgid);
0125 }
0126 };
0127
0128 BOOST_AUTO_TEST_SUITE(Detector)
0129
0130 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorReset) {
0131 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0132
0133 auto volumes = createVolumes(detectorStore);
0134
0135 GeometryIdGenerator::Config cfg;
0136 GeometryIdGenerator generator(
0137 cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
0138
0139 auto cache = generator.generateCache();
0140 for (auto& volume : volumes) {
0141 generator.assignGeometryId(cache, *volume);
0142 }
0143
0144
0145 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 1);
0146 for (auto [ip, p] : enumerate(volumes[0]->portals())) {
0147 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0148 }
0149
0150 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 2);
0151 for (auto [ip, p] : enumerate(volumes[1]->portals())) {
0152 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0153 }
0154 for (auto [is, s] : enumerate(volumes[1]->surfaces())) {
0155 if (is < 4u) {
0156 BOOST_CHECK_EQUAL(s->geometryId().sensitive(), is + 1);
0157 } else {
0158 BOOST_CHECK_EQUAL(s->geometryId().passive(), is - 3);
0159 }
0160 }
0161
0162 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 3);
0163 for (auto [ip, p] : enumerate(volumes[2]->portals())) {
0164 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0165 }
0166 }
0167
0168 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorNoReset) {
0169 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0170
0171 auto volumes = createVolumes(detectorStore);
0172
0173 GeometryIdGenerator::Config cfg;
0174 cfg.resetSubCounters = false;
0175 GeometryIdGenerator generator(
0176 cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
0177
0178 auto cache = generator.generateCache();
0179 for (auto& volume : volumes) {
0180 generator.assignGeometryId(cache, *volume);
0181 }
0182
0183
0184 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 1);
0185 unsigned int portalCounter = 1;
0186 for (auto [ip, p] : enumerate(volumes[0]->portals())) {
0187 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0188 }
0189
0190 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 2);
0191 for (auto [ip, p] : enumerate(volumes[1]->portals())) {
0192 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0193 }
0194
0195 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 3);
0196 for (auto [ip, p] : enumerate(volumes[2]->portals())) {
0197 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0198 }
0199 }
0200
0201 BOOST_AUTO_TEST_CASE(ContainerGeoIdGenerator) {
0202 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0203
0204 auto volumes = createVolumes(detectorStore);
0205
0206 GeometryIdGenerator::Config cfg;
0207 cfg.containerMode = true;
0208 cfg.containerId = 15;
0209 GeometryIdGenerator generator(
0210 cfg, getDefaultLogger("ContainerIdGenerator", Logging::VERBOSE));
0211
0212 auto cache = generator.generateCache();
0213 for (auto& volume : volumes) {
0214 generator.assignGeometryId(cache, *volume);
0215 }
0216
0217 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 15);
0218 BOOST_CHECK_EQUAL(volumes[0]->geometryId().layer(), 1);
0219 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 15);
0220 BOOST_CHECK_EQUAL(volumes[1]->geometryId().layer(), 2);
0221 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 15);
0222 BOOST_CHECK_EQUAL(volumes[2]->geometryId().layer(), 3);
0223 }
0224
0225 BOOST_AUTO_TEST_CASE(ChainedGeoIdGenerator) {
0226 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0227
0228 auto volumes = createVolumes(detectorStore);
0229
0230 GeometryIdGenerator::Config cfg;
0231
0232 cfg.containerMode = true;
0233 cfg.containerId = 15;
0234 auto cgenerator = std::make_shared<GeometryIdGenerator>(
0235 cfg, getDefaultLogger("ContainerIdGenerator", Logging::VERBOSE));
0236
0237 auto igenerator = std::make_shared<GeoIdIncrementer>();
0238
0239 std::tuple<std::shared_ptr<const GeometryIdGenerator>,
0240 std::shared_ptr<const GeoIdIncrementer>>
0241 geoGenerators = {cgenerator, igenerator};
0242
0243 ChainedGeometryIdGenerator<std::shared_ptr<const GeometryIdGenerator>,
0244 std::shared_ptr<const GeoIdIncrementer>>
0245 generator(std::move(geoGenerators));
0246
0247 auto cache = generator.generateCache();
0248 for (auto& volume : volumes) {
0249 generator.assignGeometryId(cache, *volume);
0250 }
0251
0252 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 16);
0253 BOOST_CHECK_EQUAL(volumes[0]->geometryId().layer(), 1);
0254 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 16);
0255 BOOST_CHECK_EQUAL(volumes[1]->geometryId().layer(), 2);
0256 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 16);
0257 BOOST_CHECK_EQUAL(volumes[2]->geometryId().layer(), 3);
0258 }
0259
0260 BOOST_AUTO_TEST_SUITE_END()