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, volumes) {
0034   // This test creates the visualization using the illustrator class.
0035   // However, for full control over the process, it is also possible to use
0036   // the tools in svgstools::conversion, svgstools::display, and
0037   // actsvg::display by converting the object to a proto object, optionally
0038   // styling it, and then displaying it.
0039 
0040   // Axes.
0041   const auto axes = actsvg::draw::x_y_axes("axes", {-250, 250}, {-250, 250},
0042                                            actsvg::style::stroke());
0043 
0044   // Creating the views.
0045   const actsvg::views::x_y xy;
0046   const actsvg::views::z_r zr;
0047 
0048   // Creating the detector and geomentry context.
0049   vecmem::host_memory_resource host_mr;
0050   const auto [det, names] =
0051       detray::build_toy_detector<detray::test::algebra>(host_mr);
0052 
0053   // Creating the svg generator for the detector.
0054   detray::svgtools::illustrator il{det, names};
0055   // Only test volume conversion here
0056   il.hide_grids(true);
0057 
0058   // Indexes of the volumes in the detector to be visualized.
0059   std::array indices{0u,  1u,  2u,  3u,  4u,  5u,  6u,  7u,  8u,  9u,
0060                      10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u};
0061 
0062   for (detray::dindex i : indices) {
0063     // Visualization of volume i:
0064     const auto [vol_svg_xy, xy_grid] = il.draw_volume(i, xy);
0065     detray::svgtools::write_svg("test_svgtools_" + vol_svg_xy._id,
0066                                 {axes, vol_svg_xy});
0067 
0068     const auto [vol_svg_zr, zr_grid] = il.draw_volume(i, zr);
0069     detray::svgtools::write_svg("test_svgtools_" + vol_svg_zr._id,
0070                                 {axes, vol_svg_zr});
0071   }
0072 
0073   // Names of volumes to be visualized
0074   std::array vol_names{"beampipe_0", "gap_14", "endcap_1", "connector_gap_2",
0075                        "barrel_7"};
0076 
0077   for (std::string_view name : vol_names) {
0078     // Visualization of volume i:
0079     const auto [vol_svg_xy, xy_grid] = il.draw_volume(name, xy);
0080     detray::svgtools::write_svg(
0081         "test_svgtools_" + vol_svg_xy._id + "_fetched_by_name",
0082         {axes, vol_svg_xy});
0083 
0084     const auto [vol_svg_zr, zr_grid] = il.draw_volume(name, zr);
0085     detray::svgtools::write_svg(
0086         "test_svgtools_" + vol_svg_zr._id + "_fetched_by_name",
0087         {axes, vol_svg_zr});
0088   }
0089 }