File indexing completed on 2025-01-18 09:12:33
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 vgid.setVolume(vgid.volume() + 1);
0099 dVolume.assignGeometryId(vgid);
0100 }
0101
0102
0103
0104
0105
0106 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0107 Portal& portal) const final {
0108 auto pgid = portal.surface().geometryId();
0109 pgid.setBoundary(pgid.boundary() + 1);
0110 portal.surface().assignGeometryId(pgid);
0111 }
0112
0113
0114
0115
0116
0117 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& ,
0118 Surface& surface) const final {
0119 auto sgid = surface.geometryId();
0120 if (sgid.sensitive() != 0u) {
0121 sgid.setSensitive(sgid.sensitive() + 1);
0122 } else {
0123 sgid.setPassive(sgid.passive() + 1);
0124 }
0125 surface.assignGeometryId(sgid);
0126 }
0127 };
0128
0129 BOOST_AUTO_TEST_SUITE(Detector)
0130
0131 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorReset) {
0132 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0133
0134 auto volumes = createVolumes(detectorStore);
0135
0136 GeometryIdGenerator::Config cfg;
0137 GeometryIdGenerator generator(
0138 cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
0139
0140 auto cache = generator.generateCache();
0141 for (auto& volume : volumes) {
0142 generator.assignGeometryId(cache, *volume);
0143 }
0144
0145
0146 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 1);
0147 for (auto [ip, p] : enumerate(volumes[0]->portals())) {
0148 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0149 }
0150
0151 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 2);
0152 for (auto [ip, p] : enumerate(volumes[1]->portals())) {
0153 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0154 }
0155 for (auto [is, s] : enumerate(volumes[1]->surfaces())) {
0156 if (is < 4u) {
0157 BOOST_CHECK_EQUAL(s->geometryId().sensitive(), is + 1);
0158 } else {
0159 BOOST_CHECK_EQUAL(s->geometryId().passive(), is - 3);
0160 }
0161 }
0162
0163 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 3);
0164 for (auto [ip, p] : enumerate(volumes[2]->portals())) {
0165 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), ip + 1);
0166 }
0167 }
0168
0169 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorNoReset) {
0170 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0171
0172 auto volumes = createVolumes(detectorStore);
0173
0174 GeometryIdGenerator::Config cfg;
0175 cfg.resetSubCounters = false;
0176 GeometryIdGenerator generator(
0177 cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
0178
0179 auto cache = generator.generateCache();
0180 for (auto& volume : volumes) {
0181 generator.assignGeometryId(cache, *volume);
0182 }
0183
0184
0185 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 1);
0186 unsigned int portalCounter = 1;
0187 for (auto [ip, p] : enumerate(volumes[0]->portals())) {
0188 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0189 }
0190
0191 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 2);
0192 for (auto [ip, p] : enumerate(volumes[1]->portals())) {
0193 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0194 }
0195
0196 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 3);
0197 for (auto [ip, p] : enumerate(volumes[2]->portals())) {
0198 BOOST_CHECK_EQUAL(p->surface().geometryId().boundary(), portalCounter++);
0199 }
0200 }
0201
0202 BOOST_AUTO_TEST_CASE(ContainerGeoIdGenerator) {
0203 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0204
0205 auto volumes = createVolumes(detectorStore);
0206
0207 GeometryIdGenerator::Config cfg;
0208 cfg.containerMode = true;
0209 cfg.containerId = 15;
0210 GeometryIdGenerator generator(
0211 cfg, getDefaultLogger("ContainerIdGenerator", Logging::VERBOSE));
0212
0213 auto cache = generator.generateCache();
0214 for (auto& volume : volumes) {
0215 generator.assignGeometryId(cache, *volume);
0216 }
0217
0218 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 15);
0219 BOOST_CHECK_EQUAL(volumes[0]->geometryId().layer(), 1);
0220 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 15);
0221 BOOST_CHECK_EQUAL(volumes[1]->geometryId().layer(), 2);
0222 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 15);
0223 BOOST_CHECK_EQUAL(volumes[2]->geometryId().layer(), 3);
0224 }
0225
0226 BOOST_AUTO_TEST_CASE(ChainedGeoIdGenerator) {
0227 std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
0228
0229 auto volumes = createVolumes(detectorStore);
0230
0231 GeometryIdGenerator::Config cfg;
0232
0233 cfg.containerMode = true;
0234 cfg.containerId = 15;
0235 auto cgenerator = std::make_shared<GeometryIdGenerator>(
0236 cfg, getDefaultLogger("ContainerIdGenerator", Logging::VERBOSE));
0237
0238 auto igenerator = std::make_shared<GeoIdIncrementer>();
0239
0240 std::tuple<std::shared_ptr<const GeometryIdGenerator>,
0241 std::shared_ptr<const GeoIdIncrementer>>
0242 geoGenerators = {cgenerator, igenerator};
0243
0244 ChainedGeometryIdGenerator<std::shared_ptr<const GeometryIdGenerator>,
0245 std::shared_ptr<const GeoIdIncrementer>>
0246 generator(std::move(geoGenerators));
0247
0248 auto cache = generator.generateCache();
0249 for (auto& volume : volumes) {
0250 generator.assignGeometryId(cache, *volume);
0251 }
0252
0253 BOOST_CHECK_EQUAL(volumes[0]->geometryId().volume(), 16);
0254 BOOST_CHECK_EQUAL(volumes[0]->geometryId().layer(), 1);
0255 BOOST_CHECK_EQUAL(volumes[1]->geometryId().volume(), 16);
0256 BOOST_CHECK_EQUAL(volumes[1]->geometryId().layer(), 2);
0257 BOOST_CHECK_EQUAL(volumes[2]->geometryId().volume(), 16);
0258 BOOST_CHECK_EQUAL(volumes[2]->geometryId().layer(), 3);
0259 }
0260
0261 BOOST_AUTO_TEST_SUITE_END()