Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:07

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