Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-13 07:52:04

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/DetectorVolume.hpp"
0013 #include "Acts/Detector/PortalGenerators.hpp"
0014 #include "Acts/Detector/detail/CylindricalDetectorHelper.hpp"
0015 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0016 #include "Acts/Navigation/InternalNavigation.hpp"
0017 #include "Acts/Plugins/ActSVG/PortalSvgConverter.hpp"
0018 #include "Acts/Plugins/ActSVG/SvgUtils.hpp"
0019 #include "Acts/Utilities/Enumerate.hpp"
0020 
0021 #include <algorithm>
0022 #include <fstream>
0023 #include <memory>
0024 #include <ranges>
0025 #include <vector>
0026 
0027 Acts::GeometryContext tContext;
0028 
0029 BOOST_AUTO_TEST_SUITE(ActSvg)
0030 
0031 BOOST_AUTO_TEST_CASE(CylinderPortalsSvg) {
0032   //  Some style parameteers
0033   Acts::Svg::Style portalStyle;
0034   portalStyle.fillColor = {255, 255, 255};
0035   portalStyle.fillOpacity = 0.;
0036   portalStyle.highlightColor = {255, 255, 255};
0037   portalStyle.highlights = {};
0038   portalStyle.strokeColor = {25, 25, 25};
0039   portalStyle.strokeWidth = 0.5;
0040   portalStyle.quarterSegments = 72u;
0041 
0042   double rInner = 10.;
0043   double rOuter = 100.;
0044   double zHalfL = 200.;
0045 
0046   Acts::Transform3 nominal = Acts::Transform3::Identity();
0047 
0048   auto cylinderBounds =
0049       std::make_unique<Acts::CylinderVolumeBounds>(rInner, rOuter, zHalfL);
0050 
0051   auto portalGenerator = Acts::Experimental::defaultPortalGenerator();
0052 
0053   auto cylinderVolume = Acts::Experimental::DetectorVolumeFactory::construct(
0054       portalGenerator, tContext, "CylinderVolume", nominal,
0055       std::move(cylinderBounds), Acts::Experimental::tryAllPortals());
0056 
0057   Acts::Svg::PortalConverter::Options portalOptions;
0058   portalOptions.volumeIndices[cylinderVolume.get()] = 0;
0059   Acts::Svg::SurfaceConverter::Options surfaceOptions;
0060   surfaceOptions.style = portalStyle;
0061   portalOptions.surfaceOptions = surfaceOptions;
0062 
0063   std::vector<Acts::Svg::ProtoPortal> protoPortals;
0064 
0065   std::ranges::for_each(cylinderVolume->portals(), [&](const auto& p) {
0066     protoPortals.push_back(
0067         Acts::Svg::PortalConverter::convert(tContext, *p, portalOptions));
0068   });
0069 
0070   // rz view
0071   std::vector<actsvg::svg::object> zrPortals;
0072   std::size_t ip = 0;
0073   std::ranges::for_each(protoPortals, [&](const auto& p) {
0074     zrPortals.push_back(
0075         Acts::Svg::View::zr(p, "Portal_zr" + std::to_string(ip++)));
0076   });
0077   Acts::Svg::toFile(zrPortals, "SimpleCylinderPortals_ZR.svg");
0078 
0079   // xy view
0080   std::vector<actsvg::svg::object> xyPortals;
0081   ip = 0;
0082   std::ranges::for_each(protoPortals, [&](const auto& p) {
0083     xyPortals.push_back(
0084         Acts::Svg::View::xy(p, "Portal_xy" + std::to_string(ip++)));
0085   });
0086   Acts::Svg::toFile(xyPortals, "SimpleCylinderPortals_XY.svg");
0087 }
0088 
0089 BOOST_AUTO_TEST_CASE(CylinderContainerPortalsSvg) {
0090   //  Some style parameteers
0091   Acts::Svg::Style portalStyle;
0092   portalStyle.fillColor = {255, 255, 255};
0093   portalStyle.fillOpacity = 0.;
0094   portalStyle.highlightColor = {255, 255, 255};
0095   portalStyle.highlights = {};
0096   portalStyle.strokeColor = {25, 25, 25};
0097   portalStyle.strokeWidth = 0.5;
0098   portalStyle.quarterSegments = 72u;
0099 
0100   double rInner = 10.;
0101   double rMiddle = 100.;
0102   double rOuter = 300.;
0103   double zHalfL = 200.;
0104 
0105   Acts::Transform3 nominal = Acts::Transform3::Identity();
0106 
0107   auto portalGenerator = Acts::Experimental::defaultPortalGenerator();
0108 
0109   auto cylinderBoundsI =
0110       std::make_unique<Acts::CylinderVolumeBounds>(rInner, rMiddle, zHalfL);
0111 
0112   auto cylinderBoundsO =
0113       std::make_unique<Acts::CylinderVolumeBounds>(rMiddle, rOuter, zHalfL);
0114 
0115   auto cylinderVolumeI = Acts::Experimental::DetectorVolumeFactory::construct(
0116       portalGenerator, tContext, "CylinderVolumeI", nominal,
0117       std::move(cylinderBoundsI), Acts::Experimental::tryAllPortals());
0118 
0119   auto cylinderVolumeO = Acts::Experimental::DetectorVolumeFactory::construct(
0120       portalGenerator, tContext, "CylinderVolumeO", nominal,
0121       std::move(cylinderBoundsO), Acts::Experimental::tryAllPortals());
0122 
0123   std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> rVolumes = {
0124       cylinderVolumeI, cylinderVolumeO};
0125 
0126   Acts::Experimental::detail::CylindricalDetectorHelper::connectInR(
0127       tContext, rVolumes, {});
0128 
0129   std::set<const Acts::Experimental::Portal*> portals;
0130   for (auto& v : rVolumes) {
0131     for (auto& p : v->portals()) {
0132       portals.insert(p);
0133     }
0134   }
0135   std::vector<Acts::Svg::ProtoPortal> protoPortals;
0136 
0137   Acts::Svg::PortalConverter::Options portalOptions;
0138   portalOptions.volumeIndices[cylinderVolumeI.get()] = 0;
0139   portalOptions.volumeIndices[cylinderVolumeO.get()] = 1;
0140 
0141   Acts::Svg::SurfaceConverter::Options surfaceOptions;
0142   surfaceOptions.style = portalStyle;
0143   portalOptions.surfaceOptions = surfaceOptions;
0144 
0145   for (const auto& portal : portals) {
0146     protoPortals.push_back(
0147         Acts::Svg::PortalConverter::convert(tContext, *portal, portalOptions));
0148   }
0149   // rz view
0150   std::vector<actsvg::svg::object> zrPortals;
0151   std::size_t ip = 0;
0152   std::ranges::for_each(protoPortals, [&](const auto& p) {
0153     zrPortals.push_back(
0154         Acts::Svg::View::zr(p, "Portal_zr" + std::to_string(ip++)));
0155   });
0156   Acts::Svg::toFile(zrPortals, "CylinderContainerPortals_ZR.svg");
0157 }
0158 
0159 BOOST_AUTO_TEST_SUITE_END()