Back to home page

EIC code displayed by LXR

 
 

    


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

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/TrackingGeometrySvgConverter.hpp"
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Geometry/TrackingGeometry.hpp"
0013 #include "Acts/Geometry/TrackingVolume.hpp"
0014 
0015 std::vector<actsvg::svg::object> Acts::Svg::TrackingGeometryConverter::convert(
0016     const GeometryContext& gctx, const TrackingGeometry& tGeometry,
0017     const TrackingGeometryConverter::Options& cOptions) {
0018   // Get the world volume
0019   const TrackingVolume* world = tGeometry.highestTrackingVolume();
0020 
0021   // Initiate the cache
0022   TrackingGeometryConverter::State cState;
0023 
0024   // Run the conversion recursively
0025   convert(gctx, *world, cOptions, cState);
0026 
0027   // Digest the views and globals
0028   std::vector<actsvg::svg::object> finalViews = cState.finalViews;
0029   if (!cState.xyCrossSection.empty()) {
0030     finalViews.push_back(
0031         Acts::Svg::group(cState.xyCrossSection, cOptions.prefix + "layers_xy"));
0032   }
0033   if (!cState.zrCrossSection.empty()) {
0034     finalViews.push_back(
0035         Acts::Svg::group(cState.zrCrossSection, cOptions.prefix + "layers_zr"));
0036   }
0037   // return all final Views
0038   return finalViews;
0039 }
0040 
0041 void Acts::Svg::TrackingGeometryConverter::convert(
0042     const GeometryContext& gctx, const TrackingVolume& tVolume,
0043     const TrackingGeometryConverter::Options& cOptions,
0044     TrackingGeometryConverter::State& cState) {
0045   // Process confined layers first
0046   if (tVolume.confinedLayers() != nullptr) {
0047     for (const auto& layer : tVolume.confinedLayers()->arrayObjects()) {
0048       if (layer->surfaceArray() != nullptr) {
0049         GeometryIdentifier geoID = layer->geometryId();
0050         std::string layerName = cOptions.prefix + "vol_" +
0051                                 std::to_string(geoID.volume()) + "_layer_" +
0052                                 std::to_string(geoID.layer());
0053 
0054         LayerConverter::Options lOptions;
0055         // Search for predefined layer options
0056         auto deflOptions = cOptions.layerOptions.find(geoID);
0057         if (deflOptions != cOptions.layerOptions.end()) {
0058           lOptions = (*deflOptions);
0059           lOptions.name = layerName;
0060         }
0061         // Retrieve the layer sheets
0062         auto layerSheets = LayerConverter::convert(gctx, *layer, lOptions);
0063 
0064         // Record the sheets
0065         for (const auto& lSheet : layerSheets) {
0066           if (lSheet.is_defined()) {
0067             cState.finalViews.push_back(lSheet);
0068           }
0069         }
0070         // Collect the xy views
0071         if (layerSheets[LayerConverter::eCrossSectionXY].is_defined() &&
0072             layer->surfaceRepresentation().type() == Acts::Surface::Cylinder) {
0073           cState.xyCrossSection.push_back(
0074               layerSheets[LayerConverter::eCrossSectionXY]);
0075         }
0076         // Collect the zr views
0077         if (layerSheets[LayerConverter::eCrossSectionZR].is_defined()) {
0078           cState.zrCrossSection.push_back(
0079               layerSheets[LayerConverter::eCrossSectionZR]);
0080         }
0081       }
0082     }
0083   }
0084 
0085   // Run recursively over confined volumes
0086   if (tVolume.confinedVolumes() != nullptr) {
0087     for (const auto& volume : tVolume.confinedVolumes()->arrayObjects()) {
0088       convert(gctx, *volume, cOptions, cState);
0089     }
0090   }
0091 }
0092 
0093 std::array<actsvg::svg::object, 2>
0094 Acts::Svg::TrackingGeometryProjections::convert(
0095     const GeometryContext& gctx, const Acts::TrackingGeometry& tGeometry,
0096     const TrackingGeometryProjections::Options& cOptions) {
0097   // The projections
0098   actsvg::svg::object xyView;
0099   actsvg::svg::object zrView;
0100 
0101   // Get the world volume
0102   const Acts::TrackingVolume* world = tGeometry.highestTrackingVolume();
0103   if (world != nullptr) {
0104     // Initiate the cache
0105     Acts::Svg::TrackingGeometryConverter::State cState;
0106 
0107     // Run the conversion recursively
0108     Acts::Svg::TrackingGeometryConverter::convert(
0109         gctx, *world, cOptions.trackingGeometryOptions, cState);
0110 
0111     xyView = Acts::Svg::group(cState.xyCrossSection,
0112                               cOptions.prefix + "projection_xy");
0113     zrView = Acts::Svg::group(cState.zrCrossSection,
0114                               cOptions.prefix + "projection_zr");
0115   }
0116   return {xyView, zrView};
0117 }