Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-15 08:04:58

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