File indexing completed on 2025-07-14 08:12:00
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/Detector.hpp"
0013 #include "Acts/Detector/DetectorBuilder.hpp"
0014 #include "Acts/Detector/DetectorComponents.hpp"
0015 #include "Acts/Detector/DetectorVolume.hpp"
0016 #include "Acts/Detector/PortalGenerators.hpp"
0017 #include "Acts/Detector/interface/IDetectorComponentBuilder.hpp"
0018 #include "Acts/Detector/interface/IGeometryIdGenerator.hpp"
0019 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0020 #include "Acts/Geometry/GeometryContext.hpp"
0021 #include "Acts/Geometry/GeometryIdentifier.hpp"
0022 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0023 #include "Acts/Navigation/InternalNavigation.hpp"
0024 #include "Acts/Surfaces/PlaneSurface.hpp"
0025 #include "Acts/Surfaces/RectangleBounds.hpp"
0026 #include "Acts/Surfaces/Surface.hpp"
0027 #include "Acts/Tests/CommonHelpers/DetectorElementStub.hpp"
0028 #include "Acts/Utilities/Enumerate.hpp"
0029
0030 #include <memory>
0031 #include <stdexcept>
0032 #include <vector>
0033
0034 class CompBuilder final : public Acts::Experimental::IDetectorComponentBuilder {
0035 public:
0036 explicit CompBuilder(
0037 const std::vector<std::shared_ptr<Acts::Surface>>& sensitives = {})
0038 : m_sensitives(sensitives) {}
0039
0040 Acts::Experimental::DetectorComponent construct(
0041 const Acts::GeometryContext& gctx) const final {
0042 auto bounds = std::make_unique<Acts::CuboidVolumeBounds>(10., 10., 10.);
0043
0044 auto dVolume =
0045 m_sensitives.empty()
0046 ? Acts::Experimental::DetectorVolumeFactory::construct(
0047 Acts::Experimental::defaultPortalGenerator(), gctx,
0048 "TestVolume", Acts::Transform3::Identity(), std::move(bounds),
0049 Acts::Experimental::tryAllPortals())
0050 : Acts::Experimental::DetectorVolumeFactory::construct(
0051 Acts::Experimental::defaultPortalGenerator(), gctx,
0052 "TestVolumeWithSurfaces", Acts::Transform3::Identity(),
0053 std::move(bounds), m_sensitives, {},
0054 Acts::Experimental::tryNoVolumes(),
0055 Acts::Experimental::tryAllPortalsAndSurfaces());
0056
0057
0058 Acts::Experimental::DetectorComponent::PortalContainer portalContainer;
0059 for (auto [ip, p] : Acts::enumerate(dVolume->portalPtrs())) {
0060 portalContainer[ip] = p;
0061 }
0062
0063 auto geoID = Acts::GeometryIdentifier().withVolume(1);
0064 dVolume->assignGeometryId(geoID);
0065
0066 return Acts::Experimental::DetectorComponent{
0067 {dVolume},
0068 portalContainer,
0069 {{dVolume}, Acts::Experimental::tryRootVolumes()}};
0070 }
0071
0072 private:
0073 std::vector<std::shared_ptr<Acts::Surface>> m_sensitives;
0074 };
0075
0076 class SurfaceGeoIdGenerator : public Acts::Experimental::IGeometryIdGenerator {
0077 public:
0078 Acts::Experimental::IGeometryIdGenerator::GeoIdCache generateCache()
0079 const final {
0080 return std::any();
0081 }
0082
0083 void assignGeometryId(
0084 Acts::Experimental::IGeometryIdGenerator::GeoIdCache& ,
0085 Acts::Experimental::DetectorVolume& dVolume) const final {
0086 for (auto [is, s] : Acts::enumerate(dVolume.surfacePtrs())) {
0087 auto geoID = Acts::GeometryIdentifier().withSensitive(is + 1);
0088 s->assignGeometryId(geoID);
0089 }
0090 }
0091
0092 void assignGeometryId(
0093 Acts::Experimental::IGeometryIdGenerator::GeoIdCache& ,
0094 Acts::Experimental::Portal& ) const final {}
0095
0096 void assignGeometryId(
0097 Acts::Experimental::IGeometryIdGenerator::GeoIdCache& ,
0098 Acts::Surface& ) const final {}
0099 };
0100
0101 Acts::GeometryContext tContext;
0102
0103 BOOST_AUTO_TEST_SUITE(Detector)
0104
0105 BOOST_AUTO_TEST_CASE(DetectorBuilder_Misconfigured) {
0106
0107 Acts::Experimental::DetectorBuilder::Config dCfg;
0108 dCfg.auxiliary = "*** Test X * Misconfigued ***";
0109 dCfg.name = "EmptyCylinder";
0110 dCfg.builder = nullptr;
0111
0112 BOOST_CHECK_THROW(auto a = Acts::Experimental::DetectorBuilder(dCfg),
0113 std::invalid_argument);
0114
0115
0116 Acts::Test::DetectorElementStub detElement0(
0117 Acts::Transform3::Identity(),
0118 std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0119 Acts::Test::DetectorElementStub detElement1(
0120 Acts::Transform3::Identity(),
0121 std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0122
0123 std::vector<std::shared_ptr<Acts::Surface>> sensitives;
0124 sensitives.push_back(detElement0.surface().getSharedPtr());
0125 sensitives.push_back(detElement1.surface().getSharedPtr());
0126 dCfg.builder = std::make_shared<CompBuilder>(sensitives);
0127
0128 BOOST_CHECK_THROW(
0129 Acts::Experimental::DetectorBuilder(dCfg).construct(tContext),
0130 std::invalid_argument);
0131 }
0132
0133 BOOST_AUTO_TEST_CASE(DetectorBuilder_test) {
0134
0135 Acts::Experimental::DetectorBuilder::Config dCfg;
0136 dCfg.auxiliary = "*** Test : Detector ***";
0137 dCfg.name = "TestDetector";
0138 dCfg.builder = std::make_shared<CompBuilder>();
0139
0140 BOOST_CHECK_NO_THROW(auto a = Acts::Experimental::DetectorBuilder(dCfg));
0141
0142 auto detector = Acts::Experimental::DetectorBuilder(dCfg).construct(tContext);
0143
0144 BOOST_CHECK_EQUAL(detector->name(), "TestDetector");
0145 BOOST_CHECK_EQUAL(detector->rootVolumes().size(), 1);
0146 }
0147
0148 BOOST_AUTO_TEST_CASE(DetectorBuilder_testWithSurfaces) {
0149
0150 Acts::Experimental::DetectorBuilder::Config dCfg;
0151 dCfg.auxiliary = "*** Test : Detector ***";
0152 dCfg.name = "TestDetectorWithSurfaces";
0153 dCfg.builder = std::make_shared<CompBuilder>();
0154
0155
0156 Acts::Test::DetectorElementStub detElement0(
0157 Acts::Transform3::Identity(),
0158 std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0159 Acts::Test::DetectorElementStub detElement1(
0160 Acts::Transform3::Identity(),
0161 std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0162
0163 std::vector<std::shared_ptr<Acts::Surface>> sensitives;
0164 sensitives.push_back(detElement0.surface().getSharedPtr());
0165 sensitives.push_back(detElement1.surface().getSharedPtr());
0166 dCfg.builder = std::make_shared<CompBuilder>(sensitives);
0167 dCfg.geoIdGenerator = std::make_shared<SurfaceGeoIdGenerator>();
0168
0169 auto detector = Acts::Experimental::DetectorBuilder(dCfg).construct(tContext);
0170 BOOST_CHECK_EQUAL(detector->name(), "TestDetectorWithSurfaces");
0171 BOOST_CHECK_EQUAL(
0172 detector->volumes()[0]->surfaces()[0]->geometryId().sensitive(), 1);
0173 BOOST_CHECK_EQUAL(
0174 detector->volumes()[0]->surfaces()[1]->geometryId().sensitive(), 2);
0175 }
0176
0177 BOOST_AUTO_TEST_SUITE_END()