Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:40

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/CylindricalContainerBuilder.hpp"
0013 #include "Acts/Detector/Detector.hpp"
0014 #include "Acts/Detector/DetectorBuilder.hpp"
0015 #include "Acts/Detector/DetectorComponents.hpp"
0016 #include "Acts/Detector/DetectorVolume.hpp"
0017 #include "Acts/Detector/GeometryIdGenerator.hpp"
0018 #include "Acts/Detector/PortalGenerators.hpp"
0019 #include "Acts/Detector/interface/IDetectorComponentBuilder.hpp"
0020 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0021 #include "Acts/Geometry/GeometryContext.hpp"
0022 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0023 #include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp"
0024 #include "Acts/Plugins/ActSVG/DetectorSvgConverter.hpp"
0025 #include "Acts/Surfaces/CylinderBounds.hpp"
0026 #include "Acts/Surfaces/CylinderSurface.hpp"
0027 #include "Acts/Surfaces/DiscSurface.hpp"
0028 #include "Acts/Surfaces/RadialBounds.hpp"
0029 #include "Acts/Surfaces/Surface.hpp"
0030 #include "Acts/Utilities/BinningType.hpp"
0031 #include "Acts/Utilities/Enumerate.hpp"
0032 #include "Acts/Utilities/Logger.hpp"
0033 
0034 #include <fstream>
0035 #include <memory>
0036 #include <vector>
0037 
0038 using namespace Acts;
0039 using namespace Acts::Experimental;
0040 
0041 GeometryContext tContext;
0042 
0043 /// @brief A mockup volume builder, it generates volumes with
0044 /// a single surface filled in in order to use the CylindricalContainerBuilder
0045 /// infrastructure.
0046 template <typename surface_type, typename surface_bounds_type>
0047 class CylindricalVolumeBuilder : public IDetectorComponentBuilder {
0048  public:
0049   CylindricalVolumeBuilder(const Transform3& transform,
0050                            const CylinderVolumeBounds& vBounds,
0051                            const surface_bounds_type& sBounds,
0052                            const std::string& vName)
0053       : IDetectorComponentBuilder(),
0054         m_transform(transform),
0055         m_volumeBounds(vBounds),
0056         m_surfaceBounds(sBounds),
0057         m_name(vName) {}
0058 
0059   DetectorComponent construct(
0060       [[maybe_unused]] const GeometryContext& gctx) const final {
0061     // The outgoing root volumes
0062     std::vector<std::shared_ptr<DetectorVolume>> rootVolumes;
0063 
0064     // Ingredients
0065     auto surface = Surface::makeShared<surface_type>(
0066         (m_transform), std::make_shared<surface_bounds_type>(m_surfaceBounds));
0067 
0068     auto bounds = std::make_unique<CylinderVolumeBounds>(m_volumeBounds);
0069     auto portalGenerator = defaultPortalGenerator();
0070     auto volume = DetectorVolumeFactory::construct(
0071         portalGenerator, tContext, m_name, m_transform, std::move(bounds),
0072         {surface}, {}, tryNoVolumes(), tryAllPortalsAndSurfaces());
0073 
0074     // Add to the roots
0075     rootVolumes.push_back(volume);
0076 
0077     DetectorComponent::PortalContainer dContainer;
0078     for (auto [ip, p] : enumerate(volume->portalPtrs())) {
0079       dContainer[ip] = p;
0080     }
0081     return DetectorComponent{
0082         {volume},
0083         dContainer,
0084         RootDetectorVolumes{rootVolumes, tryRootVolumes()}};
0085   }
0086 
0087  private:
0088   Transform3 m_transform;
0089   CylinderVolumeBounds m_volumeBounds;
0090   surface_bounds_type m_surfaceBounds;
0091   std::string m_name;
0092 };
0093 
0094 BOOST_AUTO_TEST_SUITE(ActSvg)
0095 
0096 BOOST_AUTO_TEST_CASE(CylindricalDetector) {
0097   // Declare a barrel sub builder
0098   auto beampipe = std::make_shared<
0099       CylindricalVolumeBuilder<CylinderSurface, CylinderBounds>>(
0100       Transform3::Identity(), CylinderVolumeBounds(0., 50., 400.),
0101       CylinderBounds(25., 380.), "BeamPipe");
0102 
0103   // Declare a negative disc builder
0104   Transform3 negZ = Transform3::Identity();
0105   negZ.pretranslate(Vector3(0., 0., -300.));
0106   auto endcapN =
0107       std::make_shared<CylindricalVolumeBuilder<DiscSurface, RadialBounds>>(
0108           negZ, CylinderVolumeBounds(50., 140., 100.), RadialBounds(60., 120.),
0109           "NegativeEndcap");
0110 
0111   // Declare a barrel sub builder
0112   auto barrel0 = std::make_shared<
0113       CylindricalVolumeBuilder<CylinderSurface, CylinderBounds>>(
0114       Transform3::Identity(), CylinderVolumeBounds(50., 80., 200.),
0115       CylinderBounds(65., 180.), "Barrel0");
0116 
0117   // Declare a barrel sub builder
0118   auto barrel1 = std::make_shared<
0119       CylindricalVolumeBuilder<CylinderSurface, CylinderBounds>>(
0120       Transform3::Identity(), CylinderVolumeBounds(80., 110., 200.),
0121       CylinderBounds(95., 180.), "Barrel1");
0122 
0123   // Declare a barrel sub builder
0124   auto barrel2 = std::make_shared<
0125       CylindricalVolumeBuilder<CylinderSurface, CylinderBounds>>(
0126       Transform3::Identity(), CylinderVolumeBounds(110., 140., 200.),
0127       CylinderBounds(125., 180.), "Barrel2");
0128 
0129   // Create the barrel container builder
0130   CylindricalContainerBuilder::Config barrelRCfg;
0131   barrelRCfg.builders = {barrel0, barrel1, barrel2};
0132   barrelRCfg.binning = {binR};
0133 
0134   auto barrel = std::make_shared<CylindricalContainerBuilder>(
0135       barrelRCfg, getDefaultLogger("BarrelBuilderR", Logging::VERBOSE));
0136 
0137   Transform3 posZ = Transform3::Identity();
0138   posZ.pretranslate(Vector3(0., 0., 300.));
0139   auto endcapP =
0140       std::make_shared<CylindricalVolumeBuilder<DiscSurface, RadialBounds>>(
0141           posZ, CylinderVolumeBounds(50., 140., 100.), RadialBounds(60., 120.),
0142           "PositiveEndcap");
0143 
0144   // Create the barrel container builder
0145   CylindricalContainerBuilder::Config barrelEndcapCfg;
0146   barrelEndcapCfg.builders = {endcapN, barrel, endcapP};
0147   barrelEndcapCfg.binning = {binZ};
0148 
0149   auto barrelEndcap = std::make_shared<CylindricalContainerBuilder>(
0150       barrelEndcapCfg,
0151       getDefaultLogger("BarrelEndcapBuilder", Logging::VERBOSE));
0152 
0153   // Create the barrel container builder
0154   CylindricalContainerBuilder::Config detectorCfg;
0155   detectorCfg.builders = {beampipe, barrelEndcap};
0156   detectorCfg.binning = {binR};
0157 
0158   auto containerBuilder = std::make_shared<CylindricalContainerBuilder>(
0159       detectorCfg, getDefaultLogger("DetectorBuilder", Logging::VERBOSE));
0160 
0161   // Detector builder
0162   auto gigConfig = GeometryIdGenerator::Config();
0163   auto gig = std::make_shared<GeometryIdGenerator>(gigConfig);
0164 
0165   Acts::Experimental::DetectorBuilder::Config dCfg;
0166   dCfg.auxiliary = "*** Test : Cylindrical Detector ***";
0167   dCfg.name = "CylindricalDetector";
0168   dCfg.builder = containerBuilder;
0169   dCfg.geoIdGenerator = gig;
0170 
0171   auto detector = DetectorBuilder(dCfg).construct(tContext);
0172 
0173   Acts::Svg::DetectorConverter::Options detectorOptions;
0174   auto pDetector = Acts::Svg::DetectorConverter::convert(tContext, *detector,
0175                                                          detectorOptions);
0176   pDetector._name = detector->name();
0177 
0178   // Colorize in blue
0179   actsvg::style::color gray({{155, 155, 155}});
0180   actsvg::style::color pink({{255, 153, 255}});
0181   actsvg::style::color brown({{153, 102, 51}});
0182   actsvg::style::color red({{255, 0, 0}});
0183   actsvg::style::color green({{0, 255, 0}});
0184   actsvg::style::color blue({{0, 0, 255}});
0185   std::vector<actsvg::style::color> colors = {gray, pink,  brown,
0186                                               red,  green, blue};
0187   for (auto& c : colors) {
0188     c._opacity = 0.1;
0189   }
0190 
0191   pDetector.colorize(colors);
0192 
0193   // As sheet
0194   auto dv_zr = Acts::Svg::View::zr(pDetector, pDetector._name);
0195   Acts::Svg::toFile({dv_zr}, pDetector._name + "_zr.svg");
0196 }
0197 
0198 BOOST_AUTO_TEST_SUITE_END()