Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:32

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   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     Acts::GeometryIdentifier geoID;
0064     geoID.setVolume(1);
0065     dVolume->assignGeometryId(geoID);
0066 
0067     return Acts::Experimental::DetectorComponent{
0068         {dVolume},
0069         portalContainer,
0070         {{dVolume}, Acts::Experimental::tryRootVolumes()}};
0071   }
0072 
0073  private:
0074   std::vector<std::shared_ptr<Acts::Surface>> m_sensitives;
0075 };
0076 
0077 class SurfaceGeoIdGenerator : public Acts::Experimental::IGeometryIdGenerator {
0078  public:
0079   Acts::Experimental::IGeometryIdGenerator::GeoIdCache generateCache()
0080       const final {
0081     return std::any();
0082   }
0083 
0084   void assignGeometryId(
0085       Acts::Experimental::IGeometryIdGenerator::GeoIdCache& /*cache*/,
0086       Acts::Experimental::DetectorVolume& dVolume) const final {
0087     for (auto [is, s] : Acts::enumerate(dVolume.surfacePtrs())) {
0088       Acts::GeometryIdentifier geoID;
0089       geoID.setSensitive(is + 1);
0090       s->assignGeometryId(geoID);
0091     }
0092   }
0093 
0094   void assignGeometryId(
0095       Acts::Experimental::IGeometryIdGenerator::GeoIdCache& /*cache*/,
0096       Acts::Experimental::Portal& /*portal*/) const final {}
0097 
0098   void assignGeometryId(
0099       Acts::Experimental::IGeometryIdGenerator::GeoIdCache& /*cache*/,
0100       Acts::Surface& /*surface*/) const final {}
0101 };
0102 
0103 Acts::GeometryContext tContext;
0104 
0105 BOOST_AUTO_TEST_SUITE(Detector)
0106 
0107 BOOST_AUTO_TEST_CASE(DetectorBuilder_Misconfigured) {
0108   // Detector builder
0109   Acts::Experimental::DetectorBuilder::Config dCfg;
0110   dCfg.auxiliary = "*** Test X * Misconfigued ***";
0111   dCfg.name = "EmptyCylinder";
0112   dCfg.builder = nullptr;
0113 
0114   BOOST_CHECK_THROW(auto a = Acts::Experimental::DetectorBuilder(dCfg),
0115                     std::invalid_argument);
0116 
0117   // Detector builder with sensitives but no assigned geometry ids to them
0118   Acts::Test::DetectorElementStub detElement0(
0119       Acts::Transform3::Identity(),
0120       std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0121   Acts::Test::DetectorElementStub detElement1(
0122       Acts::Transform3::Identity(),
0123       std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0124 
0125   std::vector<std::shared_ptr<Acts::Surface>> sensitives;
0126   sensitives.push_back(detElement0.surface().getSharedPtr());
0127   sensitives.push_back(detElement1.surface().getSharedPtr());
0128   dCfg.builder = std::make_shared<CompBuilder>(sensitives);
0129 
0130   BOOST_CHECK_THROW(
0131       Acts::Experimental::DetectorBuilder(dCfg).construct(tContext),
0132       std::invalid_argument);
0133 }
0134 
0135 BOOST_AUTO_TEST_CASE(DetectorBuilder_test) {
0136   // Detector builder
0137   Acts::Experimental::DetectorBuilder::Config dCfg;
0138   dCfg.auxiliary = "*** Test : Detector ***";
0139   dCfg.name = "TestDetector";
0140   dCfg.builder = std::make_shared<CompBuilder>();
0141 
0142   BOOST_CHECK_NO_THROW(auto a = Acts::Experimental::DetectorBuilder(dCfg));
0143 
0144   auto detector = Acts::Experimental::DetectorBuilder(dCfg).construct(tContext);
0145 
0146   BOOST_CHECK_EQUAL(detector->name(), "TestDetector");
0147   BOOST_CHECK_EQUAL(detector->rootVolumes().size(), 1);
0148 }
0149 
0150 BOOST_AUTO_TEST_CASE(DetectorBuilder_testWithSurfaces) {
0151   // Detector builder
0152   Acts::Experimental::DetectorBuilder::Config dCfg;
0153   dCfg.auxiliary = "*** Test : Detector ***";
0154   dCfg.name = "TestDetectorWithSurfaces";
0155   dCfg.builder = std::make_shared<CompBuilder>();
0156 
0157   // Test detector with surfaces
0158   Acts::Test::DetectorElementStub detElement0(
0159       Acts::Transform3::Identity(),
0160       std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0161   Acts::Test::DetectorElementStub detElement1(
0162       Acts::Transform3::Identity(),
0163       std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
0164 
0165   std::vector<std::shared_ptr<Acts::Surface>> sensitives;
0166   sensitives.push_back(detElement0.surface().getSharedPtr());
0167   sensitives.push_back(detElement1.surface().getSharedPtr());
0168   dCfg.builder = std::make_shared<CompBuilder>(sensitives);
0169   dCfg.geoIdGenerator = std::make_shared<SurfaceGeoIdGenerator>();
0170 
0171   auto detector = Acts::Experimental::DetectorBuilder(dCfg).construct(tContext);
0172   BOOST_CHECK_EQUAL(detector->name(), "TestDetectorWithSurfaces");
0173   BOOST_CHECK_EQUAL(
0174       detector->volumes()[0]->surfaces()[0]->geometryId().sensitive(), 1);
0175   BOOST_CHECK_EQUAL(
0176       detector->volumes()[0]->surfaces()[1]->geometryId().sensitive(), 2);
0177 }
0178 
0179 BOOST_AUTO_TEST_SUITE_END()