Back to home page

EIC code displayed by LXR

 
 

    


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

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 "Acts/Plugins/ActSVG/DetectorVolumeSvgConverter.hpp"
0010 
0011 #include "Acts/Detector/DetectorVolume.hpp"
0012 #include "Acts/Detector/Portal.hpp"
0013 #include "Acts/Geometry/GeometryIdentifier.hpp"
0014 #include "Acts/Geometry/VolumeBounds.hpp"
0015 #include "Acts/Plugins/ActSVG/IndexedSurfacesSvgConverter.hpp"
0016 #include "Acts/Utilities/Enumerate.hpp"
0017 
0018 #include <utility>
0019 
0020 std::tuple<Acts::Svg::ProtoVolume, Acts::Svg::ProtoIndexedSurfaceGrid>
0021 Acts::Svg::DetectorVolumeConverter::convert(
0022     const GeometryContext& gctx, const Experimental::DetectorVolume& dVolume,
0023     const DetectorVolumeConverter::Options& volumeOptions) {
0024   ProtoVolume pVolume;
0025   pVolume._name = dVolume.name();
0026 
0027   auto volumeTransform = dVolume.transform(gctx);
0028 
0029   // The detector volume is of cylindrical shape
0030   const auto& boundValues = dVolume.volumeBounds().values();
0031   if (dVolume.volumeBounds().type() == Acts::VolumeBounds::eCylinder) {
0032     // we keep 6 for the moment
0033     for (unsigned int ib = 0; ib < 2u; ++ib) {
0034       pVolume._bound_values.push_back(
0035           static_cast<actsvg::scalar>(boundValues[ib]));
0036     }
0037     pVolume._bound_values.push_back(
0038         static_cast<actsvg::scalar>(volumeTransform.translation().z()));
0039     for (unsigned int ib = 2u; ib < 5u; ++ib) {
0040       pVolume._bound_values.push_back(
0041           static_cast<actsvg::scalar>(boundValues[ib]));
0042     }
0043   }
0044 
0045   // Adding the portals to the lot
0046   for (auto [ip, p] : enumerate(dVolume.portals())) {
0047     auto pPortal =
0048         PortalConverter::convert(gctx, *p, volumeOptions.portalOptions);
0049     auto pPortalCandidate = volumeOptions.portalIndices.find(p);
0050     if (pPortalCandidate != volumeOptions.portalIndices.end()) {
0051       pPortal._name = "portal_" + std::to_string(pPortalCandidate->second);
0052     } else {
0053       pPortal._name = dVolume.name() + "_portal_" + std::to_string(ip);
0054     }
0055     pVolume._portals.push_back(pPortal);
0056   }
0057 
0058   // Adding the surfaces to the volume
0059   std::vector<ProtoSurface> pSurfaces;
0060   for (auto [is, s] : enumerate(dVolume.surfaces())) {
0061     auto pSurface =
0062         SurfaceConverter::convert(gctx, *s, volumeOptions.surfaceOptions);
0063     pSurface._name = dVolume.name() + "_surface_" + std::to_string(is);
0064     pSurfaces.push_back(pSurface);
0065   }
0066   pVolume._v_surfaces = pSurfaces;
0067 
0068   // Make dedicated surface grid sheets
0069   const auto& internalNavigationDelegate = dVolume.internalNavigation();
0070 
0071   IndexedSurfacesConverter::Options isOptions =
0072       volumeOptions.indexedSurfacesOptions;
0073   // Use or transfer the surface style
0074   if (isOptions.surfaceStyles.empty()) {
0075     std::pair<Acts::GeometryIdentifier, Acts::Svg::Style> style{
0076         dVolume.geometryId(), volumeOptions.surfaceOptions.style};
0077     isOptions.surfaceStyles =
0078         Acts::GeometryHierarchyMap<Acts::Svg::Style>({style});
0079   }
0080 
0081   auto pSurfacesGrid = IndexedSurfacesConverter::convert(
0082       gctx, dVolume.surfaces(), internalNavigationDelegate, isOptions);
0083 
0084   return {pVolume, pSurfacesGrid};
0085 }