Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:12:00

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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     // Construct the DetectorVolume
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     // Fill the portal container
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& /*cache*/,
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& /*cache*/,
0094       Acts::Experimental::Portal& /*portal*/) const final {}
0095 
0096   void assignGeometryId(
0097       Acts::Experimental::IGeometryIdGenerator::GeoIdCache& /*cache*/,
0098       Acts::Surface& /*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   // Detector builder
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   // Detector builder with sensitives but no assigned geometry ids to them
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   // Detector builder
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   // Detector builder
0150   Acts::Experimental::DetectorBuilder::Config dCfg;
0151   dCfg.auxiliary = "*** Test : Detector ***";
0152   dCfg.name = "TestDetectorWithSurfaces";
0153   dCfg.builder = std::make_shared<CompBuilder>();
0154 
0155   // Test detector with surfaces
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()