Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:25

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 // Project include(s)
0010 #include "detray/core/detector.hpp"
0011 
0012 // Detray plugin include(s)
0013 #include "detray/plugins/svgtools/illustrator.hpp"
0014 #include "detray/plugins/svgtools/writer.hpp"
0015 
0016 // Detray test include(s)
0017 #include "detray/test/common/build_toy_detector.hpp"
0018 #include "detray/test/framework/types.hpp"
0019 
0020 // Vecmem include(s)
0021 #include <vecmem/memory/host_memory_resource.hpp>
0022 
0023 // Actsvg include(s)
0024 #include <actsvg/core.hpp>
0025 
0026 // GTest include(s).
0027 #include <gtest/gtest.h>
0028 
0029 // System include(s)
0030 #include <array>
0031 #include <string>
0032 
0033 GTEST_TEST(svgtools, material) {
0034   // This test creates the visualization using the illustrator class.
0035 
0036   // Axes.
0037   const auto axes = actsvg::draw::x_y_axes("axes", {-250, 250}, {-250, 250},
0038                                            actsvg::style::stroke());
0039 
0040   // Creating the views.
0041   const actsvg::views::x_y xy;
0042   const actsvg::views::z_r zr;
0043   const actsvg::views::z_phi zphi;
0044 
0045   // Creating the detector and geomentry context.
0046   vecmem::host_memory_resource host_mr;
0047   detray::toy_det_config<detray::test::scalar> toy_cfg{};
0048   toy_cfg.use_material_maps(true).cyl_map_bins(20, 20).disc_map_bins(5, 20);
0049   const auto [det, names] =
0050       detray::build_toy_detector<detray::test::algebra>(host_mr, toy_cfg);
0051 
0052   // Creating the svg generator for the detector.
0053   detray::svgtools::illustrator il{det, names};
0054   il.hide_material(false);
0055 
0056   // Indexes of the surfaces in the detector to be visualized.
0057   std::array indices{0u, 346u, 347u, 578u, 579u, 2992u, 2993u};
0058 
0059   auto& portal_mat_style = il.style()
0060                                ._detector_style._volume_style._portal_style
0061                                ._surface_style._material_style;
0062 
0063   portal_mat_style._gradient_color_scale =
0064       detray::svgtools::styling::colors::gradient::viridis_scale;
0065   for (detray::dindex i : indices) {
0066     std::string name = "test_svgtools_material_" + std::to_string(i);
0067     // Visualization of material map of portal i:
0068     const auto svg_xy = il.draw_surface_material(i, xy);
0069     detray::svgtools::write_svg(name + "_xy", {axes, svg_xy});
0070     const auto svg_zphi = il.draw_surface_material(i, zphi);
0071     detray::svgtools::write_svg(name + "_zphi", {axes, svg_zphi});
0072   }
0073 
0074   // Draw multiple material maps together
0075   portal_mat_style._gradient_color_scale =
0076       detray::svgtools::styling::colors::gradient::plasma_scale;
0077 
0078   std::vector indices2{578u, 579u, 1034u, 1035u, 1770u, 1771u, 2870u, 2871u};
0079   std::string name = "test_svgtools_cyl_materials";
0080 
0081   const auto svg_xy = il.draw_surface_materials(indices2, xy);
0082   detray::svgtools::write_svg(name + "_xy", {axes, svg_xy});
0083 }