File indexing completed on 2026-11-16 09:26:14
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/tools/old/interface.hpp>
0011 #include <boost/test/unit_test.hpp>
0012 #include <boost/test/unit_test_suite.hpp>
0013
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/Geometry/Blueprint.hpp"
0016 #include "Acts/Geometry/BlueprintNode.hpp"
0017 #include "Acts/Geometry/ContainerBlueprintNode.hpp"
0018 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0019 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0020 #include "Acts/Geometry/GeometryContext.hpp"
0021 #include "Acts/Geometry/GeometryIdentifierBlueprintNode.hpp"
0022 #include "Acts/Geometry/LayerBlueprintNode.hpp"
0023 #include "Acts/Geometry/MaterialDesignatorBlueprintNode.hpp"
0024 #include "Acts/Geometry/PadBlueprintNode.hpp"
0025 #include "Acts/Geometry/StaticBlueprintNode.hpp"
0026 #include "Acts/Geometry/TrackingVolume.hpp"
0027 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0028 #include "Acts/Geometry/VolumeAttachmentStrategy.hpp"
0029 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0030 #include "Acts/Material/Material.hpp"
0031 #include "Acts/Material/MaterialSlab.hpp"
0032 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
0033 #include "Acts/Surfaces/RectangleBounds.hpp"
0034 #include "Acts/Utilities/AxisDefinitions.hpp"
0035 #include "Acts/Utilities/AxisSpec.hpp"
0036 #include "Acts/Utilities/Diagnostics.hpp"
0037 #include "Acts/Utilities/Logger.hpp"
0038 #include "Acts/Utilities/ProtoAxis.hpp"
0039 #include "ActsTests/CommonHelpers/DetectorElementStub.hpp"
0040
0041 #include <memory>
0042 #include <stdexcept>
0043 #include <vector>
0044
0045 using namespace Acts;
0046 using namespace Acts::UnitLiterals;
0047 using Acts::Blueprint;
0048 using Acts::BlueprintNode;
0049 using Acts::BlueprintOptions;
0050 using Acts::LayerBlueprintNode;
0051 using Acts::MaterialDesignatorBlueprintNode;
0052 using Acts::PadBlueprintNode;
0053 using Acts::StaticBlueprintNode;
0054
0055 namespace ActsTests {
0056
0057 auto logger = getDefaultLogger("UnitTests", Logging::VERBOSE);
0058
0059 auto gctx = GeometryContext::dangerouslyDefaultConstruct();
0060
0061 auto nameLookup(const TrackingGeometry& geo) {
0062 return [&](const std::string& name) -> const TrackingVolume& {
0063 const TrackingVolume* volume = nullptr;
0064
0065 geo.visitVolumes([&](const TrackingVolume* v) {
0066 if (v->volumeName() == name) {
0067 volume = v;
0068 }
0069 });
0070
0071 if (volume == nullptr) {
0072 throw std::runtime_error("Volume not found: " + name);
0073 }
0074 return *volume;
0075 };
0076 }
0077
0078 std::size_t countVolumes(const TrackingGeometry& geo) {
0079 std::size_t nVolumes = 0;
0080 geo.visitVolumes([&](const TrackingVolume* ) { nVolumes++; });
0081 return nVolumes;
0082 }
0083
0084 BOOST_AUTO_TEST_SUITE(GeometrySuite);
0085
0086 BOOST_AUTO_TEST_CASE(InvalidRoot) {
0087 Logging::ScopedFailureThreshold threshold{Logging::Level::FATAL};
0088
0089 Blueprint::Config cfg;
0090 Blueprint root{cfg};
0091 BOOST_CHECK_THROW(root.construct({}, gctx, *logger), std::logic_error);
0092
0093
0094 auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0095 root.addChild(
0096 std::make_unique<StaticBlueprintNode>(std::make_unique<TrackingVolume>(
0097 Transform3::Identity(), cylBounds, "child1")));
0098 root.addChild(
0099 std::make_unique<StaticBlueprintNode>(std::make_unique<TrackingVolume>(
0100 Transform3::Identity(), cylBounds, "child2")));
0101
0102 BOOST_CHECK_THROW(root.construct({}, gctx, *logger), std::logic_error);
0103 }
0104
0105 class DummyNode : public BlueprintNode {
0106 public:
0107 explicit DummyNode(const std::string& name) : m_name(name) {}
0108
0109 const std::string& name() const override { return m_name; }
0110
0111 Volume& build(const BlueprintOptions& ,
0112 const GeometryContext& ,
0113 const Logger& ) override {
0114 throw std::logic_error("Not implemented");
0115 }
0116
0117 PortalShellBase& connect(const BlueprintOptions& ,
0118 const GeometryContext& ,
0119 const Logger& ) override {
0120 throw std::logic_error("Not implemented");
0121 }
0122
0123 void finalize(const BlueprintOptions& ,
0124 const GeometryContext& , TrackingVolume& ,
0125 const Logger& ) override {
0126 throw std::logic_error("Not implemented");
0127 }
0128
0129 private:
0130 std::string m_name;
0131 };
0132
0133 BOOST_AUTO_TEST_CASE(RootCannotBeChild) {
0134 auto node = std::make_shared<DummyNode>("node");
0135 Blueprint::Config cfg;
0136 auto root = std::make_shared<Blueprint>(cfg);
0137
0138 BOOST_CHECK_THROW(node->addChild(root), std::invalid_argument);
0139 }
0140
0141 BOOST_AUTO_TEST_CASE(AddChildInvalid) {
0142 auto node = std::make_shared<DummyNode>("node");
0143
0144
0145 BOOST_CHECK_THROW(node->addChild(node), std::invalid_argument);
0146
0147
0148 BOOST_CHECK_THROW(node->addChild(nullptr), std::invalid_argument);
0149
0150 auto nodeB = std::make_shared<DummyNode>("nodeB");
0151 auto nodeC = std::make_shared<DummyNode>("nodeC");
0152
0153 node->addChild(nodeB);
0154 nodeB->addChild(nodeC);
0155 BOOST_CHECK_THROW(nodeC->addChild(node), std::invalid_argument);
0156
0157
0158 BOOST_CHECK_THROW(node->addChild(nodeC), std::invalid_argument);
0159 }
0160
0161 BOOST_AUTO_TEST_CASE(Depth) {
0162 auto node1 = std::make_shared<DummyNode>("node1");
0163 auto node2 = std::make_shared<DummyNode>("node2");
0164 auto node3 = std::make_shared<DummyNode>("node3");
0165
0166 BOOST_CHECK_EQUAL(node1->depth(), 0);
0167 BOOST_CHECK_EQUAL(node2->depth(), 0);
0168 BOOST_CHECK_EQUAL(node3->depth(), 0);
0169
0170 node2->addChild(node3);
0171 BOOST_CHECK_EQUAL(node2->depth(), 0);
0172 BOOST_CHECK_EQUAL(node3->depth(), 1);
0173
0174 node1->addChild(node2);
0175 BOOST_CHECK_EQUAL(node1->depth(), 0);
0176 BOOST_CHECK_EQUAL(node2->depth(), 1);
0177 BOOST_CHECK_EQUAL(node3->depth(), 2);
0178 }
0179
0180 BOOST_AUTO_TEST_CASE(Static) {
0181 Blueprint::Config cfg;
0182 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0183 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
0184 Blueprint root{cfg};
0185
0186 double hlZ = 30_mm;
0187 auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, hlZ);
0188 auto cyl = std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds,
0189 "child");
0190
0191 root.addStaticVolume(std::move(cyl));
0192
0193 BOOST_CHECK_EQUAL(root.children().size(), 1);
0194
0195 auto tGeometry = root.construct({}, gctx, *logger);
0196
0197 BOOST_REQUIRE(tGeometry);
0198
0199 BOOST_CHECK(tGeometry->geometryVersion() ==
0200 TrackingGeometry::GeometryVersion::Gen3);
0201
0202 BOOST_CHECK_EQUAL(tGeometry->highestTrackingVolume()->volumes().size(), 1);
0203
0204 BOOST_CHECK_EQUAL(countVolumes(*tGeometry), 2);
0205
0206 auto lookup = nameLookup(*tGeometry);
0207 BOOST_CHECK_EQUAL(lookup("child").volumeBounds().type(),
0208 VolumeBounds::BoundsType::eCylinder);
0209 auto actCyl =
0210 dynamic_cast<const CylinderVolumeBounds&>(lookup("child").volumeBounds());
0211
0212 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMinR), 10_mm);
0213 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMaxR), 20_mm);
0214 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eHalfLengthZ), hlZ);
0215
0216 BOOST_CHECK_EQUAL(lookup("World").volumeBounds().type(),
0217 VolumeBounds::BoundsType::eCylinder);
0218 auto worldCyl =
0219 dynamic_cast<const CylinderVolumeBounds&>(lookup("World").volumeBounds());
0220 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 9_mm);
0221 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 22_mm);
0222 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ),
0223 hlZ + 20_mm);
0224
0225 BOOST_CHECK_EQUAL(lookup("World").portals().size(), 8);
0226 }
0227
0228 BOOST_AUTO_TEST_CASE(CylinderContainer) {
0229 Blueprint::Config cfg;
0230 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0231 cfg.envelope[AxisDirection::AxisR] = {2_mm, 20_mm};
0232 auto root = std::make_unique<Blueprint>(cfg);
0233
0234 auto& cyl = root->addCylinderContainer("Container", AxisDirection::AxisZ);
0235 cyl.setAttachmentStrategy(VolumeAttachmentStrategy::Gap);
0236
0237 double z0 = -200_mm;
0238 double hlZ = 30_mm;
0239 auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, hlZ);
0240 for (std::size_t i = 0; i < 3; i++) {
0241 auto childCyl = std::make_unique<TrackingVolume>(
0242 Transform3::Identity() *
0243 Translation3{Vector3{0, 0, z0 + i * 2 * hlZ * 1.2}},
0244 cylBounds, "child" + std::to_string(i));
0245 cyl.addStaticVolume(std::move(childCyl));
0246 }
0247
0248 auto tGeometry = root->construct({}, gctx, *logger);
0249 BOOST_CHECK(tGeometry->geometryVersion() ==
0250 TrackingGeometry::GeometryVersion::Gen3);
0251
0252
0253 BOOST_CHECK_EQUAL(countVolumes(*tGeometry), 6);
0254
0255 auto lookup = nameLookup(*tGeometry);
0256 BOOST_CHECK_EQUAL(lookup("World").volumeBounds().type(),
0257 VolumeBounds::BoundsType::eCylinder);
0258 auto worldCyl =
0259 dynamic_cast<const CylinderVolumeBounds&>(lookup("World").volumeBounds());
0260 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 8_mm);
0261 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 40_mm);
0262 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ), 122_mm);
0263
0264 BOOST_CHECK_EQUAL(lookup("World").portals().size(), 8);
0265
0266 for (std::size_t i = 0; i < 3; i++) {
0267 const auto& vol{lookup("child" + std::to_string(i))};
0268 BOOST_CHECK_EQUAL(vol.volumeBounds().type(),
0269 VolumeBounds::BoundsType::eCylinder);
0270 auto actCyl = dynamic_cast<const CylinderVolumeBounds&>(vol.volumeBounds());
0271 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMinR), 10_mm);
0272 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMaxR), 20_mm);
0273 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eHalfLengthZ), hlZ);
0274 }
0275
0276 for (std::size_t i = 0; i < 2; i++) {
0277 const auto& vol{lookup("Container::Gap" + std::to_string(i + 1))};
0278 BOOST_CHECK_EQUAL(vol.volumeBounds().type(),
0279 VolumeBounds::BoundsType::eCylinder);
0280 auto gapCyl = dynamic_cast<const CylinderVolumeBounds&>(vol.volumeBounds());
0281 BOOST_CHECK_EQUAL(gapCyl.get(CylinderVolumeBounds::eMinR), 10_mm);
0282 BOOST_CHECK_EQUAL(gapCyl.get(CylinderVolumeBounds::eMaxR), 20_mm);
0283 BOOST_CHECK_EQUAL(gapCyl.get(CylinderVolumeBounds::eHalfLengthZ), 6_mm);
0284 }
0285 }
0286
0287 BOOST_AUTO_TEST_CASE(Confined) {
0288 Transform3 base{Transform3::Identity()};
0289
0290 Blueprint::Config cfg;
0291 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0292 cfg.envelope[AxisDirection::AxisR] = {2_mm, 20_mm};
0293 auto root = std::make_unique<Blueprint>(cfg);
0294
0295 root->addStaticVolume(
0296 base, std::make_shared<CylinderVolumeBounds>(50_mm, 400_mm, 1000_mm),
0297 "PixelWrapper", [&](auto& wrap) {
0298 double rMin = 100_mm;
0299 double rMax = 350_mm;
0300 double hlZ = 100_mm;
0301
0302 wrap.addStaticVolume(
0303 base * Translation3{Vector3{0, 0, -600_mm}},
0304 std::make_shared<CylinderVolumeBounds>(rMin, rMax, hlZ),
0305 "PixelNeg1");
0306
0307 wrap.addStaticVolume(
0308 base * Translation3{Vector3{0, 0, -200_mm}},
0309 std::make_shared<CylinderVolumeBounds>(rMin, rMax, hlZ),
0310 "PixelNeg2");
0311
0312 wrap.addStaticVolume(
0313 base * Translation3{Vector3{0, 0, 200_mm}},
0314 std::make_shared<CylinderVolumeBounds>(rMin, rMax, hlZ),
0315 "PixelPos1");
0316
0317 wrap.addStaticVolume(
0318 base * Translation3{Vector3{0, 0, 600_mm}},
0319 std::make_shared<CylinderVolumeBounds>(rMin, rMax, hlZ),
0320 "PixelPos2");
0321 });
0322
0323 auto trackingGeometry = root->construct({}, gctx, *logger);
0324
0325
0326 auto lookup = nameLookup(*trackingGeometry);
0327
0328 BOOST_CHECK_EQUAL(lookup("World").volumeBounds().type(),
0329 VolumeBounds::BoundsType::eCylinder);
0330 auto worldCyl =
0331 dynamic_cast<const CylinderVolumeBounds&>(lookup("World").volumeBounds());
0332 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 48_mm);
0333 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 420_mm);
0334 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ), 1020_mm);
0335
0336
0337 BOOST_CHECK_EQUAL(lookup("World").portals().size(), 8);
0338 BOOST_CHECK_EQUAL(lookup("World").volumes().size(), 1);
0339
0340 BOOST_CHECK_EQUAL(lookup("PixelWrapper").volumeBounds().type(),
0341 VolumeBounds::BoundsType::eCylinder);
0342
0343 auto wrapperCyl = dynamic_cast<const CylinderVolumeBounds&>(
0344 lookup("PixelWrapper").volumeBounds());
0345 BOOST_CHECK_EQUAL(wrapperCyl.get(CylinderVolumeBounds::eMinR), 50_mm);
0346 BOOST_CHECK_EQUAL(wrapperCyl.get(CylinderVolumeBounds::eMaxR), 400_mm);
0347 BOOST_CHECK_EQUAL(wrapperCyl.get(CylinderVolumeBounds::eHalfLengthZ),
0348 1000_mm);
0349 BOOST_CHECK_EQUAL(lookup("PixelWrapper").portals().size(), 4 + 4 * 4);
0350 BOOST_CHECK_EQUAL(lookup("PixelWrapper").volumes().size(), 4);
0351
0352 for (const auto& name :
0353 {"PixelNeg1", "PixelNeg2", "PixelPos1", "PixelPos2"}) {
0354 BOOST_CHECK_EQUAL(lookup(name).volumeBounds().type(),
0355 VolumeBounds::BoundsType::eCylinder);
0356 auto actCyl =
0357 dynamic_cast<const CylinderVolumeBounds&>(lookup(name).volumeBounds());
0358 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMinR), 100_mm);
0359 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMaxR), 350_mm);
0360 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eHalfLengthZ), 100_mm);
0361 BOOST_CHECK_EQUAL(lookup(name).portals().size(), 4);
0362 }
0363 }
0364
0365 BOOST_AUTO_TEST_CASE(ConfinedWithShared) {
0366 Transform3 base{Transform3::Identity()};
0367
0368 constexpr double rMin = 100_mm;
0369 constexpr double rMax = 350_mm;
0370 constexpr double hlZ = 100_mm;
0371
0372 auto sharedBounds = std::make_shared<CylinderVolumeBounds>(rMin, rMax, hlZ);
0373 Blueprint::Config cfg;
0374 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0375 cfg.envelope[AxisDirection::AxisR] = {2_mm, 20_mm};
0376 auto root = std::make_unique<Blueprint>(cfg);
0377
0378 root->addCylinderContainer(
0379 "PixelWrapper", AxisDirection::AxisZ, [&](auto& wrap) {
0380 wrap.addStaticVolume(base * Translation3{Vector3{0, 0, -750_mm}},
0381 sharedBounds, "PixelNeg1");
0382
0383 wrap.addStaticVolume(base * Translation3{Vector3{0, 0, -200_mm}},
0384 sharedBounds, "PixelNeg2");
0385
0386 wrap.addStaticVolume(base * Translation3{Vector3{0, 0, 200_mm}},
0387 sharedBounds, "PixelPos1");
0388
0389 wrap.addStaticVolume(base * Translation3{Vector3{0, 0, 975_mm}},
0390 sharedBounds, "PixelPos2");
0391 });
0392 auto trackingGeometry = root->construct({}, gctx, *logger);
0393
0394 auto lookup = nameLookup(*trackingGeometry);
0395 BOOST_CHECK_EQUAL(lookup("World").volumeBounds().type(),
0396 VolumeBounds::BoundsType::eCylinder);
0397 auto worldCyl =
0398 dynamic_cast<const CylinderVolumeBounds&>(lookup("World").volumeBounds());
0399 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 98_mm);
0400 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 370_mm);
0401 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ), 982.5_mm);
0402
0403 BOOST_CHECK_EQUAL(lookup("World").portals().size(), 8);
0404 BOOST_CHECK_EQUAL(lookup("World").volumes().size(), 4);
0405
0406 constexpr std::array<double, 4> expHalfL{187.5_mm, 237.5_mm, 293.75_mm,
0407 243.75_mm};
0408 const std::array<std::string, 4> volNames{"PixelNeg1", "PixelNeg2",
0409 "PixelPos1", "PixelPos2"};
0410 for (std::size_t v = 0; v < 4; ++v) {
0411 const auto& testMe{lookup(volNames[v])};
0412 BOOST_CHECK_EQUAL(testMe.volumeBounds().type(),
0413 VolumeBounds::BoundsType::eCylinder);
0414 BOOST_CHECK_EQUAL(testMe.volumeBoundsPtr() != sharedBounds, true);
0415
0416 auto actCyl =
0417 dynamic_cast<const CylinderVolumeBounds&>(testMe.volumeBounds());
0418 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMinR), 100_mm);
0419 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eMaxR), 350_mm);
0420 BOOST_CHECK_EQUAL(actCyl.get(CylinderVolumeBounds::eHalfLengthZ),
0421 expHalfL[v]);
0422 BOOST_CHECK_EQUAL(testMe.portals().size(), 4);
0423 if (v + 1 == 4) {
0424 break;
0425 }
0426 const auto& nextVol = lookup(volNames[(v + 1)]);
0427 const Vector3 outside =
0428 testMe.localToGlobalTransform(gctx).translation() +
0429 Vector3{150_mm, 0.,
0430 actCyl.get(CylinderVolumeBounds::eHalfLengthZ) - 0.5_mm};
0431 BOOST_CHECK_EQUAL(nextVol.inside(gctx, outside), false);
0432 const Vector3 inside =
0433 testMe.localToGlobalTransform(gctx).translation() +
0434 Vector3{150_mm, 0.,
0435 actCyl.get(CylinderVolumeBounds::eHalfLengthZ) + 0.5_mm};
0436 BOOST_CHECK_EQUAL(nextVol.inside(gctx, inside), true);
0437 }
0438 }
0439
0440 BOOST_AUTO_TEST_CASE(DiscLayer) {
0441 double yrot = 45_degree;
0442 Transform3 base = Transform3::Identity() * AngleAxis3{yrot, Vector3::UnitY()};
0443
0444 std::vector<std::shared_ptr<Surface>> surfaces;
0445 std::vector<std::unique_ptr<SurfacePlacementBase>> elements;
0446 double r = 300_mm;
0447 std::size_t nSensors = 8;
0448 double thickness = 2.5_mm;
0449 auto recBounds = std::make_shared<RectangleBounds>(40_mm, 60_mm);
0450
0451 double deltaPhi = 2 * std::numbers::pi / nSensors;
0452 for (std::size_t i = 0; i < nSensors; i++) {
0453
0454
0455 Transform3 trf = base * AngleAxis3{deltaPhi * i, Vector3::UnitZ()} *
0456 Translation3(Vector3::UnitX() * r);
0457
0458 if (i % 2 == 0) {
0459 trf = trf * Translation3{Vector3::UnitZ() * 5_mm};
0460 }
0461
0462 auto& element = elements.emplace_back(
0463 std::make_unique<DetectorElementStub>(trf, recBounds, thickness));
0464
0465 element->surface().assignSurfacePlacement(*element);
0466
0467 surfaces.push_back(element->surface().getSharedPtr());
0468 }
0469
0470 std::function<void(LayerBlueprintNode&)> withSurfaces =
0471 [&surfaces, &base](LayerBlueprintNode& layer) {
0472 layer.setSurfaces(surfaces)
0473 .setLayerType(LayerBlueprintNode::LayerType::Disc)
0474 .setEnvelope(ExtentEnvelope{{
0475 .z = {0.1_mm, 0.1_mm},
0476 .r = {1_mm, 1_mm},
0477 }})
0478 .setTransform(base);
0479 };
0480
0481 std::function<void(LayerBlueprintNode&)> withProtoLayer =
0482 [&surfaces, &base](LayerBlueprintNode& layer) {
0483 MutableProtoLayer protoLayer{gctx, surfaces, base.inverse()};
0484 layer.setProtoLayer(protoLayer)
0485 .setLayerType(LayerBlueprintNode::LayerType::Disc)
0486 .setEnvelope(ExtentEnvelope{{
0487 .z = {0.1_mm, 0.1_mm},
0488 .r = {1_mm, 1_mm},
0489 }});
0490 };
0491
0492 for (const auto& func : {withSurfaces, withProtoLayer}) {
0493 Blueprint root{{.envelope = ExtentEnvelope{{
0494 .z = {2_mm, 2_mm},
0495 .r = {3_mm, 5_mm},
0496 }}}};
0497
0498 root.addLayer("Layer0", [&](auto& layer) { func(layer); });
0499
0500 auto trackingGeometry = root.construct({}, gctx, *logger);
0501
0502 std::size_t nSurfaces = 0;
0503
0504 trackingGeometry->visitSurfaces([&](const Surface* surface) {
0505 if (surface->isSensitive()) {
0506 nSurfaces++;
0507 }
0508 });
0509
0510 BOOST_CHECK_EQUAL(nSurfaces, surfaces.size());
0511 BOOST_CHECK_EQUAL(countVolumes(*trackingGeometry), 2);
0512 auto lookup = nameLookup(*trackingGeometry);
0513
0514 BOOST_CHECK_EQUAL(lookup("Layer0").volumeBounds().type(),
0515 VolumeBounds::BoundsType::eCylinder);
0516 auto layerCyl = dynamic_cast<const CylinderVolumeBounds&>(
0517 lookup("Layer0").volumeBounds());
0518 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMinR), 258.9999999_mm,
0519 1e-6);
0520 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMaxR),
0521 346.25353003_mm, 1e-6);
0522 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eHalfLengthZ), 3.85_mm,
0523 1e-6);
0524 }
0525 }
0526
0527 BOOST_AUTO_TEST_CASE(CylinderLayer) {
0528 double yrot = 0_degree;
0529 Transform3 base = Transform3::Identity() * AngleAxis3{yrot, Vector3::UnitY()};
0530
0531 std::vector<std::shared_ptr<Surface>> surfaces;
0532 std::vector<std::unique_ptr<SurfacePlacementBase>> elements;
0533
0534 double r = 300_mm;
0535 std::size_t nStaves = 10;
0536 int nSensorsPerStave = 8;
0537 double thickness = 0;
0538 double hlPhi = 40_mm;
0539 double hlZ = 60_mm;
0540 auto recBounds = std::make_shared<RectangleBounds>(hlPhi, hlZ);
0541
0542 double deltaPhi = 2 * std::numbers::pi / nStaves;
0543
0544 for (std::size_t istave = 0; istave < nStaves; istave++) {
0545 for (int isensor = -nSensorsPerStave; isensor <= nSensorsPerStave;
0546 isensor++) {
0547 double z = isensor * (2 * hlZ + 5_mm);
0548
0549 Transform3 trf = base * Translation3(Vector3::UnitZ() * z) *
0550 AngleAxis3{deltaPhi * istave, Vector3::UnitZ()} *
0551 Translation3(Vector3::UnitX() * r) *
0552 AngleAxis3{10_degree, Vector3::UnitZ()} *
0553 AngleAxis3{90_degree, Vector3::UnitY()} *
0554 AngleAxis3{90_degree, Vector3::UnitZ()};
0555 auto& element = elements.emplace_back(
0556 std::make_unique<DetectorElementStub>(trf, recBounds, thickness));
0557 element->surface().assignSurfacePlacement(*element);
0558 surfaces.push_back(element->surface().getSharedPtr());
0559 }
0560 }
0561
0562 std::function<void(LayerBlueprintNode&)> withSurfaces =
0563 [&surfaces, &base](LayerBlueprintNode& layer) {
0564 layer.setSurfaces(surfaces)
0565 .setLayerType(LayerBlueprintNode::LayerType::Cylinder)
0566 .setEnvelope(ExtentEnvelope{{
0567 .z = {10_mm, 10_mm},
0568 .r = {20_mm, 10_mm},
0569 }})
0570 .setTransform(base);
0571 };
0572
0573 std::function<void(LayerBlueprintNode&)> withProtoLayer =
0574 [&surfaces, &base](LayerBlueprintNode& layer) {
0575 MutableProtoLayer protoLayer{gctx, surfaces, base.inverse()};
0576 layer.setProtoLayer(protoLayer)
0577 .setLayerType(LayerBlueprintNode::LayerType::Cylinder)
0578 .setEnvelope(ExtentEnvelope{{
0579 .z = {10_mm, 10_mm},
0580 .r = {20_mm, 10_mm},
0581 }});
0582 };
0583
0584 for (const auto& func : {withSurfaces, withProtoLayer}) {
0585 Blueprint root{{.envelope = ExtentEnvelope{{
0586 .z = {2_mm, 2_mm},
0587 .r = {3_mm, 5_mm},
0588 }}}};
0589
0590 root.addLayer("Layer0", [&](auto& layer) { func(layer); });
0591
0592 auto trackingGeometry = root.construct({}, gctx, *logger);
0593
0594 std::size_t nSurfaces = 0;
0595
0596 trackingGeometry->visitSurfaces([&](const Surface* surface) {
0597 if (surface->isSensitive()) {
0598 nSurfaces++;
0599 }
0600 });
0601
0602 BOOST_CHECK_EQUAL(nSurfaces, surfaces.size());
0603 BOOST_CHECK_EQUAL(countVolumes(*trackingGeometry), 2);
0604 auto lookup = nameLookup(*trackingGeometry);
0605
0606 BOOST_CHECK_EQUAL(lookup("Layer0").volumeBounds().type(),
0607 VolumeBounds::BoundsType::eCylinder);
0608 auto layerCyl = dynamic_cast<const CylinderVolumeBounds&>(
0609 lookup("Layer0").volumeBounds());
0610 BOOST_CHECK_EQUAL(lookup("Layer0").portals().size(), 4);
0611 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMinR), 275.6897761_mm,
0612 1e-6);
0613 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMaxR), 319.4633358_mm,
0614 1e-6);
0615 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eHalfLengthZ), 1070_mm,
0616 1e-6);
0617 }
0618 }
0619
0620 BOOST_AUTO_TEST_CASE(MaterialTesting) {
0621 Blueprint::Config cfg;
0622 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0623 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
0624 Blueprint root{cfg};
0625
0626 double hlZ = 30_mm;
0627 auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, hlZ);
0628 auto cyl = std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds,
0629 "child");
0630
0631 using enum AxisDirection;
0632 using enum CylinderVolumeBounds::Face;
0633 using enum AxisBoundaryType;
0634
0635 root.addMaterial("Material", [&](auto& mat) {
0636 mat.configureFace(NegativeDisc, AxisSpec::DeferredEquidistant(5, AxisR),
0637 AxisSpec::DeferredEquidistant(10, AxisPhi));
0638 mat.configureFace(PositiveDisc, AxisSpec::DeferredEquidistant(15, AxisR),
0639 AxisSpec::DeferredEquidistant(20, AxisPhi));
0640 mat.configureFace(OuterCylinder,
0641 AxisSpec::DeferredEquidistant(25, AxisRPhi),
0642 AxisSpec::DeferredEquidistant(30, AxisZ), "barrel/outer");
0643
0644 mat.addStaticVolume(std::move(cyl));
0645 });
0646
0647 auto trackingGeometry = root.construct({}, gctx, *logger);
0648
0649 BOOST_CHECK_EQUAL(countVolumes(*trackingGeometry), 2);
0650 auto lookup = nameLookup(*trackingGeometry);
0651 auto& child = lookup("child");
0652
0653
0654 const auto* negDisc = child.portals()
0655 .at(static_cast<std::size_t>(NegativeDisc))
0656 .surface()
0657 .surfaceMaterial();
0658 BOOST_REQUIRE_NE(negDisc, nullptr);
0659 const auto& negDiscMat =
0660 dynamic_cast<const ProtoGridSurfaceMaterial&>(*negDisc);
0661
0662 const auto* posDisc = child.portals()
0663 .at(static_cast<std::size_t>(PositiveDisc))
0664 .surface()
0665 .surfaceMaterial();
0666 BOOST_REQUIRE_NE(posDisc, nullptr);
0667 const auto& posDiscMat =
0668 dynamic_cast<const ProtoGridSurfaceMaterial&>(*posDisc);
0669
0670 BOOST_CHECK_EQUAL(negDiscMat.binning().axisSpec(0).nBins(), 5);
0671 BOOST_CHECK_EQUAL(negDiscMat.binning().axisSpec(1).nBins(), 10);
0672 BOOST_CHECK_EQUAL(posDiscMat.binning().axisSpec(0).nBins(), 15);
0673 BOOST_CHECK_EQUAL(posDiscMat.binning().axisSpec(1).nBins(), 20);
0674
0675
0676 const auto* outerCyl = child.portals()
0677 .at(static_cast<std::size_t>(OuterCylinder))
0678 .surface()
0679 .surfaceMaterial();
0680 BOOST_REQUIRE_NE(outerCyl, nullptr);
0681 const auto& outerCylMat =
0682 dynamic_cast<const ProtoGridSurfaceMaterial&>(*outerCyl);
0683 BOOST_REQUIRE(outerCylMat.materialKey());
0684 BOOST_CHECK_EQUAL(*outerCylMat.materialKey(), "barrel/outer");
0685 BOOST_CHECK_EQUAL(outerCylMat.binning().axisSpec(0).nBins(), 25);
0686 BOOST_CHECK_EQUAL(outerCylMat.binning().axisSpec(1).nBins(), 30);
0687
0688
0689 for (std::size_t i = 0; i < child.portals().size(); i++) {
0690 if (i != static_cast<std::size_t>(NegativeDisc) &&
0691 i != static_cast<std::size_t>(PositiveDisc) &&
0692 i != static_cast<std::size_t>(OuterCylinder)) {
0693 BOOST_CHECK_EQUAL(child.portals().at(i).surface().surfaceMaterial(),
0694 nullptr);
0695 }
0696 }
0697 }
0698
0699 BOOST_AUTO_TEST_CASE(MaterialKeysAndDuplicateFaces) {
0700 MaterialDesignatorBlueprintNode node("material");
0701 auto axis = AxisSpec::DeferredEquidistant(3);
0702 node.configureFace(CylinderVolumeBounds::Face::OuterCylinder, axis, axis,
0703 "barrel/outer");
0704 BOOST_CHECK_THROW(
0705 node.configureFace(CylinderVolumeBounds::Face::OuterCylinder, axis, axis,
0706 "other"),
0707 std::invalid_argument);
0708 BOOST_CHECK_THROW(node.configureFace(CylinderVolumeBounds::Face::NegativeDisc,
0709 axis, axis, ""),
0710 std::invalid_argument);
0711 BOOST_CHECK_NO_THROW(
0712 node.configureFace(CylinderVolumeBounds::Face::PositiveDisc, axis, axis));
0713 }
0714
0715 BOOST_AUTO_TEST_CASE(MaterialInvalidAxisDirections) {
0716 Blueprint::Config cfg;
0717 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0718 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
0719 Blueprint root{cfg};
0720
0721 using enum AxisDirection;
0722 using enum AxisBoundaryType;
0723
0724
0725 BOOST_CHECK_THROW(
0726 root.addMaterial("Material",
0727 [&](auto& mat) {
0728 mat.configureFace(
0729 CylinderVolumeBounds::Face::NegativeDisc,
0730 AxisSpec::DeferredEquidistant(5, AxisZ),
0731 AxisSpec::DeferredEquidistant(10, AxisPhi));
0732 }),
0733 std::invalid_argument);
0734
0735 BOOST_CHECK_THROW(
0736 root.addMaterial("Material",
0737 [&](auto& mat) {
0738 mat.configureFace(
0739 CylinderVolumeBounds::Face::OuterCylinder,
0740 AxisSpec::DeferredEquidistant(5, AxisR),
0741 AxisSpec::DeferredEquidistant(10, AxisR));
0742 }),
0743 std::invalid_argument);
0744
0745
0746 BOOST_CHECK_THROW(
0747 root.addMaterial("Material",
0748 [&](auto& mat) {
0749 mat.configureFace(
0750 CuboidVolumeBounds::Face::NegativeXFace,
0751 AxisSpec::DeferredEquidistant(5, AxisX),
0752 AxisSpec::DeferredEquidistant(10, AxisZ));
0753 }),
0754 std::invalid_argument);
0755
0756 BOOST_CHECK_THROW(
0757 root.addMaterial("Material",
0758 [&](auto& mat) {
0759 mat.configureFace(
0760 CuboidVolumeBounds::Face::PositiveYFace,
0761 AxisSpec::DeferredEquidistant(5, AxisY),
0762 AxisSpec::DeferredEquidistant(10, AxisX));
0763 }),
0764 std::invalid_argument);
0765
0766 BOOST_CHECK_THROW(
0767 root.addMaterial("Material",
0768 [&](auto& mat) {
0769 mat.configureFace(
0770 CuboidVolumeBounds::Face::NegativeZFace,
0771 AxisSpec::DeferredEquidistant(5, AxisZ),
0772 AxisSpec::DeferredEquidistant(10, AxisY));
0773 }),
0774 std::invalid_argument);
0775 }
0776
0777 BOOST_AUTO_TEST_CASE(MaterialAxisValidation) {
0778 Blueprint::Config cfg;
0779 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0780 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
0781 Blueprint root{cfg};
0782
0783 using enum AxisDirection;
0784 using enum AxisBoundaryType;
0785 using enum CylinderVolumeBounds::Face;
0786
0787
0788 BOOST_CHECK_THROW(
0789 root.addMaterial("Material",
0790 [&](auto& mat) {
0791 mat.configureFace(
0792 NegativeDisc,
0793 AxisSpec::Equidistant(5, 0., 1., Bound, AxisR),
0794 AxisSpec::DeferredEquidistant(10, AxisPhi));
0795 }),
0796 std::invalid_argument);
0797
0798
0799 BOOST_CHECK_NO_THROW(root.addMaterial("Material", [&](auto& mat) {
0800 mat.configureFace(NegativeDisc, AxisSpec::DeferredEquidistant(5),
0801 AxisSpec::DeferredEquidistant(10));
0802 }));
0803
0804
0805 ACTS_PUSH_IGNORE_DEPRECATED()
0806 BOOST_CHECK_NO_THROW(root.addMaterial("Material", [&](auto& mat) {
0807 mat.configureFace(PositiveDisc, DirectedProtoAxis(AxisR, Bound, 5),
0808 DirectedProtoAxis(AxisPhi, Bound, 0., 1., 10));
0809 }));
0810 ACTS_POP_IGNORE_DEPRECATED()
0811 }
0812
0813 BOOST_AUTO_TEST_CASE(MaterialMixedVolumeTypes) {
0814 Blueprint::Config cfg;
0815 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0816 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
0817 Blueprint root{cfg};
0818
0819 using enum AxisDirection;
0820 using enum AxisBoundaryType;
0821
0822
0823 BOOST_CHECK_THROW(
0824 root.addMaterial(
0825 "Material",
0826 [&](auto& mat) {
0827 mat.configureFace(CylinderVolumeBounds::Face::NegativeDisc,
0828 AxisSpec::DeferredEquidistant(5, AxisR),
0829 AxisSpec::DeferredEquidistant(10, AxisPhi));
0830 mat.configureFace(CuboidVolumeBounds::Face::NegativeXFace,
0831 AxisSpec::DeferredEquidistant(5, AxisX),
0832 AxisSpec::DeferredEquidistant(10, AxisY));
0833 }),
0834 std::runtime_error);
0835
0836
0837 BOOST_CHECK_THROW(
0838 root.addMaterial(
0839 "Material",
0840 [&](auto& mat) {
0841 mat.configureFace(CuboidVolumeBounds::Face::NegativeXFace,
0842 AxisSpec::DeferredEquidistant(5, AxisX),
0843 AxisSpec::DeferredEquidistant(10, AxisY));
0844 mat.configureFace(CylinderVolumeBounds::Face::NegativeDisc,
0845 AxisSpec::DeferredEquidistant(5, AxisR),
0846 AxisSpec::DeferredEquidistant(10, AxisPhi));
0847 }),
0848 std::runtime_error);
0849 }
0850
0851 BOOST_AUTO_TEST_CASE(MaterialCuboid) {
0852 Blueprint::Config cfg;
0853 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0854 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
0855 Blueprint root{cfg};
0856
0857 using enum AxisDirection;
0858 using enum AxisBoundaryType;
0859 using enum CuboidVolumeBounds::Face;
0860
0861 double hlX = 30_mm;
0862 double hlY = 40_mm;
0863 double hlZ = 50_mm;
0864 auto cuboidBounds = std::make_shared<CuboidVolumeBounds>(hlX, hlY, hlZ);
0865 auto cuboid = std::make_unique<TrackingVolume>(Transform3::Identity(),
0866 cuboidBounds, "child");
0867
0868 auto mat = std::make_shared<MaterialDesignatorBlueprintNode>("Material");
0869
0870
0871 mat->configureFace(NegativeXFace, AxisSpec::DeferredEquidistant(5, AxisX),
0872 AxisSpec::DeferredEquidistant(10, AxisY));
0873 mat->configureFace(PositiveXFace, AxisSpec::DeferredEquidistant(15, AxisX),
0874 AxisSpec::DeferredEquidistant(20, AxisY));
0875 mat->configureFace(NegativeYFace, AxisSpec::DeferredEquidistant(25, AxisX),
0876 AxisSpec::DeferredEquidistant(30, AxisY));
0877 mat->configureFace(PositiveYFace, AxisSpec::DeferredEquidistant(35, AxisX),
0878 AxisSpec::DeferredEquidistant(40, AxisY));
0879 mat->configureFace(NegativeZFace, AxisSpec::DeferredEquidistant(45, AxisX),
0880 AxisSpec::DeferredEquidistant(50, AxisY));
0881 mat->configureFace(PositiveZFace, AxisSpec::DeferredEquidistant(55, AxisX),
0882 AxisSpec::DeferredEquidistant(60, AxisY));
0883
0884 mat->addChild(std::make_shared<StaticBlueprintNode>(std::move(cuboid)));
0885
0886 root.addChild(mat);
0887
0888 auto trackingGeometry =
0889 root.construct({}, gctx, *logger->clone(std::nullopt, Logging::VERBOSE));
0890
0891 BOOST_REQUIRE(trackingGeometry);
0892
0893 auto lookup = nameLookup(*trackingGeometry);
0894 auto& child = lookup("child");
0895
0896
0897 for (std::size_t i = 0; i < child.portals().size(); i++) {
0898 const auto* material = child.portals().at(i).surface().surfaceMaterial();
0899 BOOST_REQUIRE_NE(material, nullptr);
0900
0901 const auto& gridMaterial =
0902 dynamic_cast<const ProtoGridSurfaceMaterial&>(*material);
0903
0904
0905 CuboidVolumeBounds::Face face = static_cast<CuboidVolumeBounds::Face>(i);
0906 switch (face) {
0907 case NegativeXFace:
0908 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(0).nBins(), 5);
0909 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(1).nBins(), 10);
0910 break;
0911 case PositiveXFace:
0912 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(0).nBins(), 15);
0913 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(1).nBins(), 20);
0914 break;
0915 case NegativeYFace:
0916 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(0).nBins(), 25);
0917 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(1).nBins(), 30);
0918 break;
0919 case PositiveYFace:
0920 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(0).nBins(), 35);
0921 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(1).nBins(), 40);
0922 break;
0923 case NegativeZFace:
0924 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(0).nBins(), 45);
0925 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(1).nBins(), 50);
0926 break;
0927 case PositiveZFace:
0928 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(0).nBins(), 55);
0929 BOOST_CHECK_EQUAL(gridMaterial.binning().axisSpec(1).nBins(), 60);
0930 break;
0931 }
0932 }
0933 }
0934
0935 BOOST_AUTO_TEST_CASE(HomogeneousMaterialCylinder) {
0936 Blueprint::Config cfg;
0937 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
0938 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
0939 Blueprint root{cfg};
0940
0941 double hlZ = 30_mm;
0942 auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, hlZ);
0943 auto cyl = std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds,
0944 "child");
0945
0946 using enum CylinderVolumeBounds::Face;
0947
0948
0949 auto testMaterial = Material::fromMolarDensity(
0950 9.370_cm, 46.52_cm, 28.0855, 14, (2.329 / 28.0855) * 1_mol / 1_cm3);
0951
0952 auto negDiscMat = std::make_shared<HomogeneousSurfaceMaterial>(
0953 MaterialSlab(testMaterial, 0.1_mm));
0954 auto posDiscMat = std::make_shared<HomogeneousSurfaceMaterial>(
0955 MaterialSlab(testMaterial, 0.2_mm));
0956 auto outerCylMat = std::make_shared<HomogeneousSurfaceMaterial>(
0957 MaterialSlab(testMaterial, 0.3_mm));
0958
0959 root.addMaterial("Material", [&](auto& mat) {
0960 mat.configureFace(NegativeDisc, negDiscMat);
0961 mat.configureFace(PositiveDisc, posDiscMat);
0962 mat.configureFace(OuterCylinder, outerCylMat);
0963
0964 mat.addStaticVolume(std::move(cyl));
0965 });
0966
0967 auto trackingGeometry = root.construct({}, gctx, *logger);
0968
0969 BOOST_CHECK_EQUAL(countVolumes(*trackingGeometry), 2);
0970 auto lookup = nameLookup(*trackingGeometry);
0971 auto& child = lookup("child");
0972
0973
0974 const auto* negDisc = child.portals()
0975 .at(static_cast<std::size_t>(NegativeDisc))
0976 .surface()
0977 .surfaceMaterial();
0978 BOOST_REQUIRE_NE(negDisc, nullptr);
0979 BOOST_CHECK_EQUAL(negDisc, negDiscMat.get());
0980
0981
0982 const auto* posDisc = child.portals()
0983 .at(static_cast<std::size_t>(PositiveDisc))
0984 .surface()
0985 .surfaceMaterial();
0986 BOOST_REQUIRE_NE(posDisc, nullptr);
0987 BOOST_CHECK_EQUAL(posDisc, posDiscMat.get());
0988
0989
0990 const auto* outerCyl = child.portals()
0991 .at(static_cast<std::size_t>(OuterCylinder))
0992 .surface()
0993 .surfaceMaterial();
0994 BOOST_REQUIRE_NE(outerCyl, nullptr);
0995 BOOST_CHECK_EQUAL(outerCyl, outerCylMat.get());
0996
0997
0998 for (std::size_t i = 0; i < child.portals().size(); i++) {
0999 if (i != static_cast<std::size_t>(NegativeDisc) &&
1000 i != static_cast<std::size_t>(PositiveDisc) &&
1001 i != static_cast<std::size_t>(OuterCylinder)) {
1002 BOOST_CHECK_EQUAL(child.portals().at(i).surface().surfaceMaterial(),
1003 nullptr);
1004 }
1005 }
1006 }
1007
1008 BOOST_AUTO_TEST_CASE(HomogeneousMaterialCuboid) {
1009 Blueprint::Config cfg;
1010 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1011 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1012 Blueprint root{cfg};
1013
1014 using enum CuboidVolumeBounds::Face;
1015
1016 double hlX = 30_mm;
1017 double hlY = 40_mm;
1018 double hlZ = 50_mm;
1019 auto cuboidBounds = std::make_shared<CuboidVolumeBounds>(hlX, hlY, hlZ);
1020 auto cuboid = std::make_unique<TrackingVolume>(Transform3::Identity(),
1021 cuboidBounds, "child");
1022
1023
1024 auto testMaterial = Material::fromMolarDensity(
1025 9.370_cm, 46.52_cm, 28.0855, 14, (2.329 / 28.0855) * 1_mol / 1_cm3);
1026
1027 auto negXMat = std::make_shared<HomogeneousSurfaceMaterial>(
1028 MaterialSlab(testMaterial, 0.1_mm));
1029 auto posXMat = std::make_shared<HomogeneousSurfaceMaterial>(
1030 MaterialSlab(testMaterial, 0.2_mm));
1031 auto negYMat = std::make_shared<HomogeneousSurfaceMaterial>(
1032 MaterialSlab(testMaterial, 0.3_mm));
1033 auto posYMat = std::make_shared<HomogeneousSurfaceMaterial>(
1034 MaterialSlab(testMaterial, 0.4_mm));
1035 auto negZMat = std::make_shared<HomogeneousSurfaceMaterial>(
1036 MaterialSlab(testMaterial, 0.5_mm));
1037 auto posZMat = std::make_shared<HomogeneousSurfaceMaterial>(
1038 MaterialSlab(testMaterial, 0.6_mm));
1039
1040 root.addMaterial("Material", [&](auto& mat) {
1041 mat.configureFace(NegativeXFace, negXMat);
1042 mat.configureFace(PositiveXFace, posXMat);
1043 mat.configureFace(NegativeYFace, negYMat);
1044 mat.configureFace(PositiveYFace, posYMat);
1045 mat.configureFace(NegativeZFace, negZMat);
1046 mat.configureFace(PositiveZFace, posZMat);
1047
1048 mat.addStaticVolume(std::move(cuboid));
1049 });
1050
1051 auto trackingGeometry = root.construct({}, gctx, *logger);
1052
1053 BOOST_REQUIRE(trackingGeometry);
1054
1055 auto lookup = nameLookup(*trackingGeometry);
1056 auto& child = lookup("child");
1057
1058
1059 for (std::size_t i = 0; i < child.portals().size(); i++) {
1060 const auto* material = child.portals().at(i).surface().surfaceMaterial();
1061 BOOST_REQUIRE_NE(material, nullptr);
1062
1063 const auto* homMaterial =
1064 dynamic_cast<const HomogeneousSurfaceMaterial*>(material);
1065 BOOST_REQUIRE_NE(homMaterial, nullptr);
1066
1067
1068 CuboidVolumeBounds::Face face = static_cast<CuboidVolumeBounds::Face>(i);
1069 switch (face) {
1070 case NegativeXFace:
1071 BOOST_CHECK_EQUAL(homMaterial, negXMat.get());
1072 break;
1073 case PositiveXFace:
1074 BOOST_CHECK_EQUAL(homMaterial, posXMat.get());
1075 break;
1076 case NegativeYFace:
1077 BOOST_CHECK_EQUAL(homMaterial, negYMat.get());
1078 break;
1079 case PositiveYFace:
1080 BOOST_CHECK_EQUAL(homMaterial, posYMat.get());
1081 break;
1082 case NegativeZFace:
1083 BOOST_CHECK_EQUAL(homMaterial, negZMat.get());
1084 break;
1085 case PositiveZFace:
1086 BOOST_CHECK_EQUAL(homMaterial, posZMat.get());
1087 break;
1088 }
1089 }
1090 }
1091
1092 BOOST_AUTO_TEST_CASE(HomogeneousMaterialMixedVolumeTypes) {
1093 Blueprint::Config cfg;
1094 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1095 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1096 Blueprint root{cfg};
1097
1098 auto testMaterial = Material::fromMolarDensity(
1099 9.370_cm, 46.52_cm, 28.0855, 14, (2.329 / 28.0855) * 1_mol / 1_cm3);
1100
1101 auto material = std::make_shared<HomogeneousSurfaceMaterial>(
1102 MaterialSlab(testMaterial, 0.1_mm));
1103
1104
1105 BOOST_CHECK_THROW(
1106 root.addMaterial("Material",
1107 [&](auto& mat) {
1108 mat.configureFace(
1109 CylinderVolumeBounds::Face::NegativeDisc,
1110 material);
1111 mat.configureFace(
1112 CuboidVolumeBounds::Face::NegativeXFace, material);
1113 }),
1114 std::runtime_error);
1115
1116
1117 BOOST_CHECK_THROW(
1118 root.addMaterial("Material",
1119 [&](auto& mat) {
1120 mat.configureFace(
1121 CuboidVolumeBounds::Face::NegativeXFace, material);
1122 mat.configureFace(
1123 CylinderVolumeBounds::Face::NegativeDisc,
1124 material);
1125 }),
1126 std::runtime_error);
1127 }
1128
1129 BOOST_AUTO_TEST_CASE(LayerCenterOfGravity) {
1130
1131 {
1132 double yrot = 45_degree;
1133 Transform3 base =
1134 Transform3::Identity() * AngleAxis3{yrot, Vector3::UnitY()};
1135
1136 std::vector<std::shared_ptr<Surface>> surfaces;
1137 std::vector<std::unique_ptr<SurfacePlacementBase>> elements;
1138 double r = 300_mm;
1139 std::size_t nSensors = 8;
1140 double thickness = 2.5_mm;
1141 auto recBounds = std::make_shared<RectangleBounds>(40_mm, 60_mm);
1142
1143 double deltaPhi = 2 * std::numbers::pi / nSensors;
1144 for (std::size_t i = 0; i < nSensors; i++) {
1145 Transform3 trf = base * AngleAxis3{deltaPhi * i, Vector3::UnitZ()} *
1146 Translation3(Vector3::UnitX() * r);
1147
1148 if (i % 2 == 0) {
1149 trf = trf * Translation3{Vector3::UnitZ() * 5_mm};
1150 }
1151
1152 auto& element = elements.emplace_back(
1153 std::make_unique<DetectorElementStub>(trf, recBounds, thickness));
1154
1155 element->surface().assignSurfacePlacement(*element);
1156 surfaces.push_back(element->surface().getSharedPtr());
1157 }
1158
1159 Blueprint root{{.envelope = ExtentEnvelope{{
1160 .z = {2_mm, 2_mm},
1161 .r = {3_mm, 5_mm},
1162 }}}};
1163
1164 root.addLayer("Layer0", [&](auto& layer) {
1165 layer.setSurfaces(surfaces)
1166 .setLayerType(LayerBlueprintNode::LayerType::Disc)
1167 .setEnvelope(ExtentEnvelope{{
1168 .z = {0.1_mm, 0.1_mm},
1169 .r = {1_mm, 1_mm},
1170 }})
1171 .setTransform(base)
1172 .setUseCenterOfGravity(false, false, false);
1173 });
1174
1175 auto trackingGeometry = root.construct({}, gctx, *logger);
1176 auto lookup = nameLookup(*trackingGeometry);
1177
1178 BOOST_CHECK_EQUAL(lookup("Layer0").volumeBounds().type(),
1179 VolumeBounds::BoundsType::eCylinder);
1180
1181 auto layerCyl = dynamic_cast<const CylinderVolumeBounds&>(
1182 lookup("Layer0").volumeBounds());
1183
1184
1185 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMinR), 258.9999999_mm,
1186 1e-6);
1187 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMaxR),
1188 346.25353003_mm, 1e-6);
1189 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eHalfLengthZ), 3.85_mm,
1190 1e-6);
1191 }
1192
1193
1194 {
1195 double yrot = 0_degree;
1196 Transform3 base =
1197 Transform3::Identity() * AngleAxis3{yrot, Vector3::UnitY()};
1198
1199 std::vector<std::shared_ptr<Surface>> surfaces;
1200 std::vector<std::unique_ptr<SurfacePlacementBase>> elements;
1201
1202 double r = 300_mm;
1203 std::size_t nStaves = 10;
1204 int nSensorsPerStave = 8;
1205 double thickness = 0;
1206 double hlPhi = 40_mm;
1207 double hlZ = 60_mm;
1208 auto recBounds = std::make_shared<RectangleBounds>(hlPhi, hlZ);
1209
1210 double deltaPhi = 2 * std::numbers::pi / nStaves;
1211
1212 for (std::size_t istave = 0; istave < nStaves; istave++) {
1213 for (int isensor = -nSensorsPerStave; isensor <= nSensorsPerStave;
1214 isensor++) {
1215 double z = isensor * (2 * hlZ + 5_mm);
1216
1217 Transform3 trf = base * Translation3(Vector3::UnitZ() * z) *
1218 AngleAxis3{deltaPhi * istave, Vector3::UnitZ()} *
1219 Translation3(Vector3::UnitX() * r) *
1220 AngleAxis3{10_degree, Vector3::UnitZ()} *
1221 AngleAxis3{90_degree, Vector3::UnitY()} *
1222 AngleAxis3{90_degree, Vector3::UnitZ()};
1223 auto& element = elements.emplace_back(
1224 std::make_unique<DetectorElementStub>(trf, recBounds, thickness));
1225 element->surface().assignSurfacePlacement(*element);
1226 surfaces.push_back(element->surface().getSharedPtr());
1227 }
1228 }
1229
1230 Blueprint root{{.envelope = ExtentEnvelope{{
1231 .z = {2_mm, 2_mm},
1232 .r = {3_mm, 5_mm},
1233 }}}};
1234
1235 root.addLayer("Layer0", [&](auto& layer) {
1236 layer.setSurfaces(surfaces)
1237 .setLayerType(LayerBlueprintNode::LayerType::Cylinder)
1238 .setEnvelope(ExtentEnvelope{{
1239 .z = {10_mm, 10_mm},
1240 .r = {20_mm, 10_mm},
1241 }})
1242 .setTransform(base)
1243 .setUseCenterOfGravity(false, false, false);
1244 });
1245
1246 auto trackingGeometry = root.construct({}, gctx, *logger);
1247 auto lookup = nameLookup(*trackingGeometry);
1248 BOOST_CHECK_EQUAL(lookup("Layer0").volumeBounds().type(),
1249 VolumeBounds::BoundsType::eCylinder);
1250
1251 auto layerCyl = dynamic_cast<const CylinderVolumeBounds&>(
1252 lookup("Layer0").volumeBounds());
1253
1254
1255 BOOST_CHECK_EQUAL(lookup("Layer0").portals().size(), 4);
1256 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMinR), 275.6897761_mm,
1257 1e-6);
1258 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eMaxR), 319.4633358_mm,
1259 1e-6);
1260 BOOST_CHECK_CLOSE(layerCyl.get(CylinderVolumeBounds::eHalfLengthZ), 1070_mm,
1261 1e-6);
1262 }
1263 }
1264
1265 BOOST_AUTO_TEST_CASE(GeometryIdnetifiersForPortals) {
1266 Blueprint::Config cfg;
1267 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1268 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1269 Blueprint root{cfg};
1270
1271 auto& cubcontainer =
1272 root.addCuboidContainer("CuboidContainer", AxisDirection::AxisX);
1273 auto parentBounds = std::make_shared<CuboidVolumeBounds>(1_m, 20_mm, 20_mm);
1274 auto parentVol = std::make_unique<TrackingVolume>(Transform3::Identity(),
1275 parentBounds, "parent");
1276 parentVol->assignGeometryId(GeometryIdentifier{}.withVolume(1));
1277 auto parentNode = std::make_shared<StaticBlueprintNode>(std::move(parentVol));
1278 std::size_t nChambers = 50;
1279
1280 double startX = -1000. + 3. + 0.5;
1281 Transform3 trf = Transform3(Translation3(startX, 0, 0));
1282 auto tbounds =
1283 std::make_shared<TrapezoidVolumeBounds>(3_mm, 3_mm, 10_mm, 15_mm);
1284
1285 for (std::size_t i = 0; i < nChambers; i++) {
1286
1287 trf.translation() += Vector3::UnitX() * i * 7_mm;
1288
1289 auto childVol = std::make_unique<TrackingVolume>(
1290 trf, tbounds, "child" + std::to_string(i));
1291 childVol->assignGeometryId(
1292 GeometryIdentifier{}.withVolume(1).withLayer(i + 1));
1293 auto childNode = std::make_shared<StaticBlueprintNode>(std::move(childVol));
1294 parentNode->addChild(std::move(childNode));
1295 }
1296
1297 cubcontainer.addChild(std::move(parentNode));
1298
1299 auto trackingGeometry = root.construct({}, gctx, *logger);
1300 }
1301
1302 BOOST_AUTO_TEST_CASE(PadBlueprintNodeCylinder) {
1303 Blueprint::Config cfg;
1304 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1305 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1306
1307 PadBlueprintNode pad("World", cfg.envelope);
1308
1309 auto child = std::make_unique<TrackingVolume>(
1310 Transform3::Identity(),
1311 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child");
1312 const TrackingVolume* childVol = child.get();
1313 pad.addStaticVolume(std::move(child));
1314
1315 BlueprintOptions options;
1316
1317 auto& world =
1318 dynamic_cast<TrackingVolume&>(pad.build(options, gctx, *logger));
1319
1320
1321 const auto& childCyl =
1322 dynamic_cast<const CylinderVolumeBounds&>(childVol->volumeBounds());
1323 BOOST_CHECK_EQUAL(childCyl.get(CylinderVolumeBounds::eMinR), 10_mm);
1324 BOOST_CHECK_EQUAL(childCyl.get(CylinderVolumeBounds::eMaxR), 20_mm);
1325 BOOST_CHECK_EQUAL(childCyl.get(CylinderVolumeBounds::eHalfLengthZ), 30_mm);
1326
1327 BOOST_CHECK_EQUAL(world.volumeName(), "World");
1328 BOOST_CHECK_EQUAL(world.volumeBounds().type(),
1329 VolumeBounds::BoundsType::eCylinder);
1330
1331 const auto& worldCyl =
1332 dynamic_cast<const CylinderVolumeBounds&>(world.volumeBounds());
1333 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 10_mm - 1_mm);
1334 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 20_mm + 2_mm);
1335 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ),
1336 30_mm + 20_mm);
1337 }
1338
1339 BOOST_AUTO_TEST_CASE(PadBlueprintNodeLegacyPaddedOverload) {
1340 Blueprint::Config cfg;
1341 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1342 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1343
1344 Volume child(Transform3::Identity(),
1345 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm));
1346
1347
1348
1349 ACTS_PUSH_IGNORE_DEPRECATED()
1350 auto world =
1351 PadBlueprintNode::padded(gctx, child, cfg.envelope, "World", *logger);
1352 ACTS_POP_IGNORE_DEPRECATED()
1353
1354 BOOST_CHECK_EQUAL(world->volumeName(), "World");
1355 const auto& worldCyl =
1356 dynamic_cast<const CylinderVolumeBounds&>(world->volumeBounds());
1357 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 10_mm - 1_mm);
1358 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 20_mm + 2_mm);
1359 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ),
1360 30_mm + 20_mm);
1361 BOOST_CHECK_SMALL(world->center(gctx).norm(), 1e-9);
1362 }
1363
1364 BOOST_AUTO_TEST_CASE(PadBlueprintNodeCuboid) {
1365 Blueprint::Config cfg;
1366 cfg.envelope[AxisDirection::AxisX] = {3_mm, 3_mm};
1367 cfg.envelope[AxisDirection::AxisY] = {5_mm, 5_mm};
1368 cfg.envelope[AxisDirection::AxisZ] = {7_mm, 7_mm};
1369
1370 PadBlueprintNode pad("World", cfg.envelope);
1371 auto child = std::make_unique<TrackingVolume>(
1372 Transform3::Identity(),
1373 std::make_shared<CuboidVolumeBounds>(10_mm, 20_mm, 30_mm), "child");
1374 const TrackingVolume* childVol = child.get();
1375 pad.addStaticVolume(std::move(child));
1376
1377 BlueprintOptions options;
1378
1379 auto& world =
1380 dynamic_cast<TrackingVolume&>(pad.build(options, gctx, *logger));
1381
1382
1383 const auto& childBox =
1384 dynamic_cast<const CuboidVolumeBounds&>(childVol->volumeBounds());
1385 BOOST_CHECK_EQUAL(childBox.get(CuboidVolumeBounds::eHalfLengthX), 10_mm);
1386 BOOST_CHECK_EQUAL(childBox.get(CuboidVolumeBounds::eHalfLengthY), 20_mm);
1387 BOOST_CHECK_EQUAL(childBox.get(CuboidVolumeBounds::eHalfLengthZ), 30_mm);
1388
1389 BOOST_CHECK_EQUAL(world.volumeName(), "World");
1390 BOOST_CHECK_EQUAL(world.volumeBounds().type(),
1391 VolumeBounds::BoundsType::eCuboid);
1392
1393 const auto& worldBox =
1394 dynamic_cast<const CuboidVolumeBounds&>(world.volumeBounds());
1395 BOOST_CHECK_EQUAL(worldBox.get(CuboidVolumeBounds::eHalfLengthX),
1396 10_mm + 3_mm);
1397 BOOST_CHECK_EQUAL(worldBox.get(CuboidVolumeBounds::eHalfLengthY),
1398 20_mm + 5_mm);
1399 BOOST_CHECK_EQUAL(worldBox.get(CuboidVolumeBounds::eHalfLengthZ),
1400 30_mm + 7_mm);
1401
1402
1403 BOOST_CHECK_EQUAL(world.portals().size(), 0);
1404 }
1405
1406 BOOST_AUTO_TEST_CASE(PadBlueprintNodeRotatedCylinder) {
1407 Blueprint::Config cfg;
1408 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1409 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1410
1411 PadBlueprintNode pad("World", cfg.envelope);
1412
1413 Transform3 childTrf =
1414 Transform3::Identity() * AngleAxis3{45_degree, Vector3::UnitY()};
1415
1416 pad.addStaticVolume(std::make_unique<TrackingVolume>(
1417 childTrf, std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm),
1418 "child"));
1419
1420 BlueprintOptions options;
1421 auto& world =
1422 dynamic_cast<TrackingVolume&>(pad.build(options, gctx, *logger));
1423
1424 BOOST_CHECK_EQUAL(world.volumeName(), "World");
1425 BOOST_CHECK_EQUAL(world.volumeBounds().type(),
1426 VolumeBounds::BoundsType::eCylinder);
1427
1428
1429 const auto& worldCyl =
1430 dynamic_cast<const CylinderVolumeBounds&>(world.volumeBounds());
1431 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 10_mm - 1_mm);
1432 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 20_mm + 2_mm);
1433 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ),
1434 30_mm + 20_mm);
1435
1436
1437 BOOST_CHECK(world.localToGlobalTransform(gctx).isApprox(childTrf));
1438 }
1439
1440 BOOST_AUTO_TEST_CASE(PadBlueprintNodeNestedInContainer) {
1441 Blueprint::Config cfg;
1442 cfg.envelope[AxisDirection::AxisZ] = {5_mm, 5_mm};
1443 cfg.envelope[AxisDirection::AxisR] = {5_mm, 5_mm};
1444 Blueprint root{cfg};
1445
1446 auto& container =
1447 root.addCylinderContainer("Container", AxisDirection::AxisZ);
1448
1449 ExtentEnvelope padEnvelope = ExtentEnvelope::Zero();
1450 padEnvelope[AxisDirection::AxisZ] = {10_mm, 10_mm};
1451 padEnvelope[AxisDirection::AxisR] = {1_mm, 10_mm};
1452 auto pad = std::make_shared<PadBlueprintNode>("Pad", padEnvelope);
1453
1454 pad->addStaticVolume(std::make_unique<TrackingVolume>(
1455 Transform3::Identity(),
1456 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child"));
1457
1458 container.addChild(pad);
1459
1460 auto trackingGeometry = root.construct({}, gctx, *logger);
1461 auto lookup = nameLookup(*trackingGeometry);
1462
1463
1464
1465 const auto& padCyl =
1466 dynamic_cast<const CylinderVolumeBounds&>(lookup("Pad").volumeBounds());
1467 BOOST_CHECK_EQUAL(padCyl.get(CylinderVolumeBounds::eMinR), 10_mm - 1_mm);
1468 BOOST_CHECK_EQUAL(padCyl.get(CylinderVolumeBounds::eMaxR), 20_mm + 10_mm);
1469 BOOST_CHECK_EQUAL(padCyl.get(CylinderVolumeBounds::eHalfLengthZ),
1470 30_mm + 10_mm);
1471
1472
1473
1474
1475 const auto& worldCyl =
1476 dynamic_cast<const CylinderVolumeBounds&>(lookup("World").volumeBounds());
1477 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR),
1478 padCyl.get(CylinderVolumeBounds::eMinR) - 5_mm);
1479 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR),
1480 padCyl.get(CylinderVolumeBounds::eMaxR) + 5_mm);
1481 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ),
1482 padCyl.get(CylinderVolumeBounds::eHalfLengthZ) + 5_mm);
1483 }
1484
1485 BOOST_DATA_TEST_CASE(GeometryIdentifierWrappingPadBlueprintNode,
1486 boost::unit_test::data::make({false, true}),
1487 distinguishChild) {
1488 Blueprint::Config cfg;
1489 cfg.envelope[AxisDirection::AxisZ] = {5_mm, 5_mm};
1490 cfg.envelope[AxisDirection::AxisR] = {5_mm, 5_mm};
1491 Blueprint root{cfg};
1492
1493
1494 auto& geometryId = root.withGeometryIdentifier();
1495 geometryId.setAllVolumeIdsTo(42);
1496
1497 ExtentEnvelope padEnvelope = ExtentEnvelope::Zero();
1498 padEnvelope[AxisDirection::AxisZ] = {10_mm, 10_mm};
1499 padEnvelope[AxisDirection::AxisR] = {1_mm, 10_mm};
1500 auto pad = std::make_shared<PadBlueprintNode>("Pad", padEnvelope);
1501 geometryId.addChild(pad);
1502
1503 BlueprintNode* childParent = pad.get();
1504 if (distinguishChild) {
1505
1506 childParent = &pad->withGeometryIdentifier().setLayerIdTo(1);
1507 }
1508 childParent->addStaticVolume(std::make_unique<TrackingVolume>(
1509 Transform3::Identity(),
1510 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child"));
1511
1512 if (!distinguishChild) {
1513
1514
1515
1516 Logging::ScopedFailureThreshold threshold{Logging::Level::FATAL};
1517 BOOST_CHECK_EXCEPTION(
1518 root.construct({}, gctx, *logger), std::invalid_argument,
1519 [](const std::invalid_argument& error) {
1520 return std::string{error.what()}.find("Duplicate portal ID:") !=
1521 std::string::npos;
1522 });
1523 return;
1524 }
1525
1526 auto trackingGeometry = root.construct({}, gctx, *logger);
1527 auto lookup = nameLookup(*trackingGeometry);
1528
1529 BOOST_CHECK_EQUAL(countVolumes(*trackingGeometry), 3u);
1530 BOOST_CHECK_EQUAL(lookup("Pad").geometryId(),
1531 GeometryIdentifier{}.withVolume(42));
1532 BOOST_CHECK_EQUAL(lookup("child").geometryId(),
1533 GeometryIdentifier{}.withVolume(42).withLayer(1));
1534 BOOST_CHECK_NE(lookup("World").geometryId().volume(), 42u);
1535 }
1536
1537 BOOST_DATA_TEST_CASE(DirectChildVolumeIdWrappingPadBlueprintNode,
1538 boost::unit_test::data::make({false, true}),
1539 assignChildId) {
1540 Blueprint::Config cfg;
1541 cfg.envelope[AxisDirection::AxisZ] = {5_mm, 5_mm};
1542 cfg.envelope[AxisDirection::AxisR] = {5_mm, 5_mm};
1543 Blueprint root{cfg};
1544
1545 auto& geometryId = root.withGeometryIdentifier();
1546 geometryId.setLayerIdTo(3).setDirectChildVolumeIdTo(42);
1547
1548 ExtentEnvelope padEnvelope = ExtentEnvelope::Zero();
1549 padEnvelope[AxisDirection::AxisZ] = {10_mm, 10_mm};
1550 padEnvelope[AxisDirection::AxisR] = {1_mm, 10_mm};
1551 auto pad = std::make_shared<PadBlueprintNode>("Pad", padEnvelope);
1552 geometryId.addChild(pad);
1553
1554 auto child = std::make_unique<TrackingVolume>(
1555 Transform3::Identity(),
1556 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child");
1557 if (assignChildId) {
1558 child->assignGeometryId(GeometryIdentifier{}.withVolume(43).withLayer(7));
1559 }
1560 pad->addStaticVolume(std::move(child));
1561
1562 auto trackingGeometry = root.construct({}, gctx, *logger);
1563 auto lookup = nameLookup(*trackingGeometry);
1564 BOOST_CHECK_EQUAL(countVolumes(*trackingGeometry), 3u);
1565 BOOST_CHECK_EQUAL(lookup("Pad").geometryId(),
1566 GeometryIdentifier{}.withVolume(42).withLayer(3));
1567 if (assignChildId) {
1568 BOOST_CHECK_EQUAL(lookup("child").geometryId(),
1569 GeometryIdentifier{}.withVolume(43).withLayer(7));
1570 } else {
1571 BOOST_CHECK_NE(lookup("child").geometryId().volume(), 0u);
1572 BOOST_CHECK_NE(lookup("child").geometryId().volume(), 42u);
1573 BOOST_CHECK_EQUAL(lookup("child").geometryId().layer(), 0u);
1574 }
1575 BOOST_CHECK_NE(lookup("World").geometryId().volume(), 42u);
1576 }
1577
1578 BOOST_AUTO_TEST_CASE(DirectChildVolumeIdRejectsExistingVolumeId) {
1579 Logging::ScopedFailureThreshold threshold{Logging::Level::FATAL};
1580 Blueprint root{Blueprint::Config{}};
1581 auto& geometryId = root.withGeometryIdentifier();
1582 geometryId.setDirectChildVolumeIdTo(42);
1583 auto child = std::make_unique<TrackingVolume>(
1584 Transform3::Identity(),
1585 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child");
1586 child->assignGeometryId(GeometryIdentifier{}.withVolume(43));
1587 geometryId.addStaticVolume(std::move(child));
1588
1589 BOOST_CHECK_EXCEPTION(root.construct({}, gctx, *logger), std::logic_error,
1590 [](const std::logic_error& error) {
1591 return std::string{error.what()} ==
1592 "Volume already has a volume ID";
1593 });
1594 }
1595
1596 BOOST_AUTO_TEST_CASE(PadBlueprintNodeReferenceAxisBounds) {
1597 Blueprint::Config cfg;
1598 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1599 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1600
1601
1602 PadBlueprintNode pad("World", cfg.envelope);
1603 pad.setReferenceAxis(Transform3::Identity());
1604
1605 const double offsetX = 50_mm;
1606 auto child = std::make_unique<TrackingVolume>(
1607 Transform3::Identity() * Translation3{Vector3{offsetX, 0, 0}},
1608 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child");
1609 const TrackingVolume* childVol = child.get();
1610 pad.addStaticVolume(std::move(child));
1611
1612 BlueprintOptions options;
1613 auto& world =
1614 dynamic_cast<TrackingVolume&>(pad.build(options, gctx, *logger));
1615
1616
1617 BOOST_CHECK_CLOSE(childVol->center(gctx)[eX], offsetX, 1e-9);
1618
1619 BOOST_CHECK_EQUAL(world.volumeName(), "World");
1620 BOOST_CHECK_EQUAL(world.volumeBounds().type(),
1621 VolumeBounds::BoundsType::eCylinder);
1622
1623
1624 BOOST_CHECK_SMALL(world.center(gctx)[eX], 1e-9);
1625 BOOST_CHECK_SMALL(world.center(gctx)[eY], 1e-9);
1626
1627
1628
1629
1630
1631 const auto& worldCyl =
1632 dynamic_cast<const CylinderVolumeBounds&>(world.volumeBounds());
1633 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 29_mm);
1634 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 72_mm);
1635 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ),
1636 30_mm + 20_mm);
1637 }
1638
1639 BOOST_AUTO_TEST_CASE(PadBlueprintNodeReferenceAxisRejectsCuboid) {
1640
1641
1642 Logging::ScopedFailureThreshold threshold{Logging::Level::FATAL};
1643
1644 Blueprint::Config cfg;
1645 cfg.envelope[AxisDirection::AxisX] = {1_mm, 1_mm};
1646 cfg.envelope[AxisDirection::AxisY] = {1_mm, 1_mm};
1647 cfg.envelope[AxisDirection::AxisZ] = {1_mm, 1_mm};
1648
1649 PadBlueprintNode pad("World", cfg.envelope);
1650 pad.setReferenceAxis(Transform3::Identity());
1651 pad.addStaticVolume(std::make_unique<TrackingVolume>(
1652 Transform3::Identity(),
1653 std::make_shared<CuboidVolumeBounds>(10_mm, 20_mm, 30_mm), "child"));
1654
1655 BlueprintOptions options;
1656 BOOST_CHECK_THROW(pad.build(options, gctx, *logger), std::logic_error);
1657 }
1658
1659 BOOST_AUTO_TEST_CASE(PadBlueprintNodeReferenceAxisInCylinderHierarchy) {
1660 Blueprint::Config cfg;
1661 cfg.envelope[AxisDirection::AxisZ] = {20_mm, 20_mm};
1662 cfg.envelope[AxisDirection::AxisR] = {2_mm, 20_mm};
1663 auto root = std::make_unique<Blueprint>(cfg);
1664
1665 std::vector<std::unique_ptr<SurfacePlacementBase>> elements;
1666 std::vector<std::shared_ptr<Surface>> b0SensitiveSurfaces;
1667
1668
1669
1670 auto makeB0Layer = [&](std::size_t layer) -> std::unique_ptr<TrackingVolume> {
1671 const double offsetX = -160_mm;
1672 const double z = 6250_mm + layer * 100_mm;
1673 auto layerVolume = std::make_unique<TrackingVolume>(
1674 Transform3::Identity() * Translation3{Vector3{offsetX, 0., z}},
1675 std::make_shared<CylinderVolumeBounds>(35_mm, 150_mm, 20_mm),
1676 "B0Layer" + std::to_string(layer));
1677
1678 const std::size_t nModules = 6;
1679 const double moduleR = 90_mm;
1680 const auto moduleBounds = std::make_shared<RectangleBounds>(8_mm, 15_mm);
1681 for (std::size_t i = 0; i < nModules; ++i) {
1682 const double phi = 2. * std::numbers::pi * static_cast<double>(i) /
1683 static_cast<double>(nModules);
1684 Transform3 moduleTransform = Transform3::Identity() *
1685 Translation3{Vector3{offsetX, 0., z}} *
1686 AngleAxis3{phi, Vector3::UnitZ()} *
1687 Translation3{Vector3::UnitX() * moduleR} *
1688 AngleAxis3{90_degree, Vector3::UnitY()} *
1689 AngleAxis3{90_degree, Vector3::UnitZ()};
1690
1691 auto& element =
1692 elements.emplace_back(std::make_unique<DetectorElementStub>(
1693 moduleTransform, moduleBounds, 0.));
1694 element->surface().assignSurfacePlacement(*element);
1695 auto surface = element->surface().getSharedPtr();
1696 layerVolume->addSurface(surface);
1697 b0SensitiveSurfaces.push_back(std::move(surface));
1698 }
1699
1700 return layerVolume;
1701 };
1702
1703 root->addCylinderContainer("Detector", AxisDirection::AxisZ, [&](auto& det) {
1704 det.addStaticVolume(
1705 Transform3::Identity(),
1706 std::make_shared<CylinderVolumeBounds>(20_mm, 400_mm, 1000_mm),
1707 "MainTracker");
1708
1709
1710
1711 ExtentEnvelope padEnvelope = ExtentEnvelope::Zero();
1712 padEnvelope[AxisDirection::AxisZ] = {2_mm, 2_mm};
1713 padEnvelope[AxisDirection::AxisR] = {2_mm, 2_mm};
1714 auto pad = std::make_shared<PadBlueprintNode>("B0Envelope", padEnvelope);
1715 pad->setReferenceAxis(Transform3::Identity());
1716 pad->addCylinderContainer("B0", AxisDirection::AxisZ, [&](auto& b0) {
1717 b0.addStaticVolume(makeB0Layer(0));
1718 b0.addStaticVolume(makeB0Layer(1));
1719 });
1720 det.addChild(pad);
1721 });
1722
1723 auto trackingGeometry = root->construct({}, gctx, *logger);
1724 BOOST_REQUIRE(trackingGeometry != nullptr);
1725 BOOST_CHECK(trackingGeometry->geometryVersion() ==
1726 TrackingGeometry::GeometryVersion::Gen3);
1727
1728
1729 const auto* envelope = trackingGeometry->findVolumeByName("B0Envelope");
1730 BOOST_REQUIRE(envelope != nullptr);
1731 BOOST_CHECK_SMALL(envelope->center(gctx)[eX], 1e-9);
1732 BOOST_CHECK_SMALL(envelope->center(gctx)[eY], 1e-9);
1733
1734
1735 const auto* b0Layer0 = trackingGeometry->findVolumeByName("B0Layer0");
1736 BOOST_REQUIRE(b0Layer0 != nullptr);
1737 BOOST_CHECK_CLOSE(b0Layer0->center(gctx)[eX], -160_mm, 1e-8);
1738
1739
1740
1741 std::size_t found = 0;
1742 for (const auto& surface : b0SensitiveSurfaces) {
1743 const auto id = surface->geometryId();
1744 BOOST_CHECK_NE(id.sensitive(), 0u);
1745 BOOST_REQUIRE(trackingGeometry->findSurface(id) != nullptr);
1746 found++;
1747 }
1748 BOOST_CHECK_EQUAL(found, b0SensitiveSurfaces.size());
1749 }
1750
1751 BOOST_AUTO_TEST_CASE(PadBlueprintNodeCenteredRejectsAsymmetricZ) {
1752
1753
1754
1755 Logging::ScopedFailureThreshold threshold{Logging::Level::FATAL};
1756
1757 Blueprint::Config cfg;
1758 cfg.envelope[AxisDirection::AxisZ] = {10_mm, 40_mm};
1759 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1760
1761 PadBlueprintNode pad("World", cfg.envelope);
1762 pad.addStaticVolume(std::make_unique<TrackingVolume>(
1763 Transform3::Identity(),
1764 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child"));
1765
1766 BlueprintOptions options;
1767 BOOST_CHECK_THROW(pad.build(options, gctx, *logger), std::logic_error);
1768 }
1769
1770 BOOST_AUTO_TEST_CASE(PadBlueprintNodeFitBoundsCylinder) {
1771
1772
1773 Blueprint::Config cfg;
1774 cfg.envelope[AxisDirection::AxisZ] = {10_mm, 40_mm};
1775 cfg.envelope[AxisDirection::AxisR] = {1_mm, 2_mm};
1776
1777 PadBlueprintNode pad("World", cfg.envelope);
1778 pad.setCentering(PadBlueprintNode::Centering::FitBounds);
1779 pad.addStaticVolume(std::make_unique<TrackingVolume>(
1780 Transform3::Identity(),
1781 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 30_mm), "child"));
1782
1783 BlueprintOptions options;
1784 auto& world =
1785 dynamic_cast<TrackingVolume&>(pad.build(options, gctx, *logger));
1786
1787 const auto& worldCyl =
1788 dynamic_cast<const CylinderVolumeBounds&>(world.volumeBounds());
1789
1790 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eHalfLengthZ), 55_mm);
1791 BOOST_CHECK_CLOSE(world.center(gctx)[eZ], 15_mm, 1e-9);
1792
1793 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMinR), 9_mm);
1794 BOOST_CHECK_EQUAL(worldCyl.get(CylinderVolumeBounds::eMaxR), 22_mm);
1795 }
1796
1797 BOOST_AUTO_TEST_CASE(PadBlueprintNodeFitBoundsCuboid) {
1798
1799 Blueprint::Config cfg;
1800 cfg.envelope[AxisDirection::AxisX] = {2_mm, 6_mm};
1801 cfg.envelope[AxisDirection::AxisY] = {3_mm, 3_mm};
1802 cfg.envelope[AxisDirection::AxisZ] = {0_mm, 0_mm};
1803
1804 PadBlueprintNode pad("World", cfg.envelope);
1805 pad.setCentering(PadBlueprintNode::Centering::FitBounds);
1806 pad.addStaticVolume(std::make_unique<TrackingVolume>(
1807 Transform3::Identity(),
1808 std::make_shared<CuboidVolumeBounds>(10_mm, 20_mm, 30_mm), "child"));
1809
1810 BlueprintOptions options;
1811 auto& world =
1812 dynamic_cast<TrackingVolume&>(pad.build(options, gctx, *logger));
1813
1814 const auto& worldBox =
1815 dynamic_cast<const CuboidVolumeBounds&>(world.volumeBounds());
1816 BOOST_CHECK_EQUAL(worldBox.get(CuboidVolumeBounds::eHalfLengthX), 14_mm);
1817 BOOST_CHECK_EQUAL(worldBox.get(CuboidVolumeBounds::eHalfLengthY), 23_mm);
1818 BOOST_CHECK_EQUAL(worldBox.get(CuboidVolumeBounds::eHalfLengthZ), 30_mm);
1819 BOOST_CHECK_CLOSE(world.center(gctx)[eX], 2_mm, 1e-9);
1820 BOOST_CHECK_SMALL(world.center(gctx)[eY], 1e-9);
1821 BOOST_CHECK_SMALL(world.center(gctx)[eZ], 1e-9);
1822 }
1823
1824 BOOST_AUTO_TEST_SUITE_END();
1825
1826 }