Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-23 09:33:26

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 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Plugins/ActSVG/SvgUtils.hpp"
0013 #include "Acts/Utilities/Axis.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015 #include <actsvg/core.hpp>
0016 #include <actsvg/meta.hpp>
0017 
0018 #include <array>
0019 #include <optional>
0020 #include <tuple>
0021 #include <vector>
0022 
0023 namespace Acts {
0024 
0025 class Surface;
0026 
0027 namespace Svg {
0028 
0029 using ProtoGrid = actsvg::proto::grid;
0030 
0031 namespace GridConverter {
0032 
0033 // An optional range and binning value
0034 using AxisBound = std::tuple<std::array<double, 2u>, AxisDirection>;
0035 
0036 /// Nested Options struct
0037 struct Options {
0038   /// A The style for the surfaces
0039   Style style{{150, 150, 150}, 0.5};
0040   /// Optional bound - in case of 1-dim grid
0041   std::optional<AxisBound> optionalBound;
0042 };
0043 
0044 /// Convert an ACTS grid into a actsvg protogrid, it currently works with
0045 ///
0046 /// - 1D: [ AxisX ] , [ AxisY ], [ AxisR ] , [ AxisPhi ]
0047 /// - 2D: [ AxisX, AxisY ], [ AxisZ, AxisPhi ], [ AxisR, AxisPhi ]
0048 ///
0049 /// @tparam grid_type is the type of the grid to be converted
0050 ///
0051 /// @param grid the grid to be converted
0052 /// @param aDirs the axis directions of the grid
0053 /// @param cOptions the conversion options
0054 ///
0055 /// @return an ACTSVG proto grid for displaying
0056 template <typename grid_type>
0057 ProtoGrid convert(const grid_type& grid,
0058                   const std::array<AxisDirection, grid_type::DIM>& aDirs,
0059                   const GridConverter::Options& cOptions) {
0060   // The return object
0061   ProtoGrid pGrid;
0062 
0063   // Grid axes
0064   auto axes = grid.axes();
0065 
0066   // The edge values - these need to follow the ACTSVG convention,
0067   // so there could be swapping when necessary
0068   std::vector<double> edges0;
0069   std::vector<double> edges1;
0070 
0071   // 1D case (more to be filled in later)
0072   if constexpr (grid_type::DIM == 1u) {
0073     if (aDirs[0u] == AxisDirection::AxisPhi &&
0074         axes[0]->getBoundaryType() == AxisBoundaryType::Closed) {
0075       // swap     needed
0076       edges1 = axes[0]->getBinEdges();
0077       pGrid._type = actsvg::proto::grid::e_r_phi;
0078     }
0079     if (cOptions.optionalBound.has_value()) {
0080       auto [boundRange, boundValue] = cOptions.optionalBound.value();
0081       if (boundValue == AxisDirection::AxisR) {
0082         // good - no swap needed
0083         edges0 = {boundRange[0u], boundRange[1u]};
0084       }
0085     }
0086   }
0087   // 2D cases
0088   if constexpr (grid_type::DIM == 2u) {
0089     // Assign
0090     edges0 = axes[0]->getBinEdges();
0091     edges1 = axes[1]->getBinEdges();
0092     if (aDirs[0] == AxisDirection::AxisPhi &&
0093         aDirs[1] == AxisDirection::AxisZ) {
0094       //  swap needed
0095       std::swap(edges0, edges1);
0096       pGrid._type = actsvg::proto::grid::e_z_phi;
0097     } else if (aDirs[0] == AxisDirection::AxisPhi &&
0098                aDirs[1] == AxisDirection::AxisR) {
0099       // swap needed
0100       std::swap(edges0, edges1);
0101       pGrid._type = actsvg::proto::grid::e_r_phi;
0102     } else if (aDirs[0] == AxisDirection::AxisZ &&
0103                aDirs[1] == AxisDirection::AxisPhi) {
0104       // good - no swap needed
0105       pGrid._type = actsvg::proto::grid::e_z_phi;
0106     } else if (aDirs[0] == AxisDirection::AxisR &&
0107                aDirs[1] == AxisDirection::AxisPhi) {
0108       // good - no swap needed
0109       pGrid._type = actsvg::proto::grid::e_r_phi;
0110     } else if (aDirs[0] == AxisDirection::AxisX &&
0111                aDirs[1] == AxisDirection::AxisY) {
0112       // good - no swap needed
0113       pGrid._type = actsvg::proto::grid::e_x_y;
0114     }
0115   }
0116 
0117   // Assign grid edges
0118   pGrid._edges_0 = std::vector<actsvg::scalar>(edges0.begin(), edges0.end());
0119   pGrid._edges_1 = std::vector<actsvg::scalar>(edges1.begin(), edges1.end());
0120 
0121   auto [fill, stroke] = cOptions.style.fillAndStroke();
0122   pGrid._fill = fill;
0123   pGrid._stroke = stroke;
0124 
0125   return pGrid;
0126 }
0127 
0128 }  // namespace GridConverter
0129 }  // namespace Svg
0130 }  // namespace Acts