Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24: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 "ActsPlugins/ActSVG/LayerSvgConverter.hpp"
0010 
0011 #include "Acts/Geometry/Layer.hpp"
0012 #include "Acts/Surfaces/SurfaceArray.hpp"
0013 #include "ActsPlugins/ActSVG/SurfaceArraySvgConverter.hpp"
0014 #include "ActsPlugins/ActSVG/SurfaceSvgConverter.hpp"
0015 
0016 using namespace Acts;
0017 
0018 std::vector<actsvg::svg::object> ActsPlugins::Svg::LayerConverter::convert(
0019     const GeometryContext& gctx, const Layer& layer,
0020     const LayerConverter::Options& cOptions) {
0021   // The sheets
0022   std::vector<actsvg::svg::object> sheets;
0023 
0024   // The volume
0025   ActsPlugins::Svg::ProtoVolume volume;
0026   volume._name = cOptions.name;
0027 
0028   /// Convert the surface array into proto surfaces and a grid structure
0029   if (layer.surfaceArray() != nullptr) {
0030     SurfaceArrayConverter::Options sacOptions;
0031     sacOptions.surfaceStyles = cOptions.surfaceStyles;
0032     auto [surfaces, grid, associations] = SurfaceArrayConverter::convert(
0033         gctx, *(layer.surfaceArray()), sacOptions);
0034     volume._surfaces = {surfaces};
0035     volume._surface_grid = grid;
0036     volume._grid_associations = {associations};
0037   }
0038 
0039   // The sheet
0040   actsvg::svg::object module_sheet;
0041   actsvg::svg::object grid_sheet;
0042   actsvg::svg::object xy_layer;
0043   actsvg::svg::object zr_layer;
0044 
0045   // The module / grid information
0046   const auto& layerSurface = layer.surfaceRepresentation();
0047   if (layerSurface.type() == Surface::Disc) {
0048     if (cOptions.moduleInfo) {
0049       module_sheet = actsvg::display::endcap_sheet(
0050           cOptions.name + "_modules", volume, {800, 800},
0051           actsvg::display::e_module_info);
0052     }
0053     if (cOptions.gridInfo) {
0054       grid_sheet = actsvg::display::endcap_sheet(cOptions.name + "_grid",
0055                                                  volume, {800, 800},
0056                                                  actsvg::display::e_grid_info);
0057     }
0058   } else if (layerSurface.type() == Surface::Cylinder) {
0059     if (cOptions.moduleInfo) {
0060       module_sheet = actsvg::display::barrel_sheet(
0061           cOptions.name + "_modules", volume, {800, 800},
0062           actsvg::display::e_module_info);
0063     }
0064     if (cOptions.gridInfo) {
0065       grid_sheet = actsvg::display::barrel_sheet(cOptions.name + "_grid",
0066                                                  volume, {800, 800},
0067                                                  actsvg::display::e_grid_info);
0068     }
0069   }
0070 
0071   // The z_r view of things
0072   actsvg::views::z_r z_r_view;
0073   actsvg::views::x_y x_y_view;
0074 
0075   if (layer.surfaceArray() != nullptr) {
0076     // The x_y view of things
0077     xy_layer._tag = "g";
0078     xy_layer._id = cOptions.name + "_xy_view";
0079     // The x_r view of things
0080     zr_layer._tag = "g";
0081     zr_layer._id = cOptions.name + "_zr_view";
0082     unsigned int m = 0;
0083     // Potential labels
0084     double avgRadius = 0.;
0085 
0086     for (const auto& sf : layer.surfaceArray()->surfaces()) {
0087       // Surface center
0088       const Vector3 rCenter = sf->referencePosition(gctx, AxisDirection::AxisR);
0089       const Vector3 sfCenter = sf->center(gctx);
0090       double radius = VectorHelpers::perp(rCenter);
0091       double phi = VectorHelpers::phi(rCenter);
0092       double z = sfCenter.z();
0093       // Get the average radius
0094       avgRadius += radius;
0095       // Raw display surfaces for projections
0096       actsvg::proto::surface<std::vector<Vector3>> projSurface;
0097       projSurface._vertices = sf->polyhedronRepresentation(gctx, 1u).vertices;
0098       // Draw only if they fall into the range restriction - for phi
0099       if (phi >= cOptions.phiRange[0] && phi <= cOptions.phiRange[1]) {
0100         std::string m_zr_id = std::string("zr_") + std::to_string(m++);
0101         zr_layer.add_object(ActsPlugins::Svg::View::zr(projSurface, m_zr_id));
0102       }
0103       // for z
0104       if (z >= cOptions.zRange[0] && z <= cOptions.zRange[1]) {
0105         std::string m_xy_id = std::string("xy_") + std::to_string(m++);
0106         xy_layer.add_object(ActsPlugins::Svg::View::xy(projSurface, m_xy_id));
0107       }
0108     }
0109     // Do the average
0110     avgRadius /= layer.surfaceArray()->surfaces().size();
0111 
0112     // Add a measure iuf requested
0113     if (cOptions.labelProjection) {
0114       double xEnd = avgRadius * std::cos(cOptions.labelGauge);
0115       double yEnd = avgRadius * std::sin(cOptions.labelGauge);
0116       xy_layer.add_object(measure(0., 0., xEnd, yEnd, "r", avgRadius, "mm"));
0117     }
0118   }
0119 
0120   // Register according to the enums
0121   sheets.push_back(module_sheet);
0122   sheets.push_back(grid_sheet);
0123   sheets.push_back(xy_layer);
0124   sheets.push_back(zr_layer);
0125 
0126   // Return the created sheets
0127   return sheets;
0128 }