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 #include "detray/tracks/ray.hpp"
0012 
0013 // Detray plugin include(s)
0014 #include "detray/plugins/svgtools/illustrator.hpp"
0015 #include "detray/plugins/svgtools/writer.hpp"
0016 
0017 // Detray test include(s)
0018 #include "detray/test/common/build_toy_detector.hpp"
0019 #include "detray/test/common/track_generators.hpp"
0020 #include "detray/test/framework/types.hpp"
0021 #include "detray/test/validation/detector_scanner.hpp"
0022 #include "detray/test/validation/svg_display.hpp"
0023 #include "detray/tracks/tracks.hpp"
0024 
0025 // Vecmem include(s)
0026 #include <vecmem/memory/host_memory_resource.hpp>
0027 
0028 // Actsvg include(s)
0029 #include <actsvg/core.hpp>
0030 
0031 // GTest include(s).
0032 #include <gtest/gtest.h>
0033 
0034 // System include(s)
0035 #include <array>
0036 #include <string>
0037 
0038 GTEST_TEST(svgtools, intersections) {
0039   // This test creates the visualization using the illustrator class.
0040   // However, for full control over the process, it is also possible to use
0041   // the tools in svgstools::conversion, svgstools::display, and
0042   // actsvg::display by converting the object to a proto object, optionally
0043   // styling it, and then displaying it.
0044 
0045   // Axes.
0046   const auto axes =
0047       actsvg::draw::x_y_axes("axes", {-250, 250}, {-250, 250},
0048                              actsvg::style::stroke(), "axis1", "axis2");
0049 
0050   // Creating the view.
0051   const actsvg::views::z_r view;
0052 
0053   // Creating the detector and geomentry context.
0054   vecmem::host_memory_resource host_mr;
0055   const auto [det, names] =
0056       detray::build_toy_detector<detray::test::algebra>(host_mr);
0057 
0058   using detector_t = decltype(det);
0059   using test_algebra = typename detector_t::algebra_type;
0060 
0061   detector_t::geometry_context gctx{};
0062 
0063   // Creating the illustrator.
0064   const detray::svgtools::illustrator il{det, names};
0065 
0066   // Drawing the detector.
0067   const auto svg_det = il.draw_detector(view);
0068 
0069   // Creating the rays.
0070   using generator_t =
0071       detray::uniform_track_generator<detray::detail::ray<test_algebra>>;
0072   auto trk_gen_cfg = generator_t::configuration{};
0073   trk_gen_cfg.origin(0.f, 0.f, 100.f).phi_steps(10u).theta_steps(10u);
0074 
0075   std::size_t index = 0;
0076   // Iterate through uniformly distributed momentum directions with ray
0077   for (const auto test_ray : generator_t{trk_gen_cfg}) {
0078     // Record all intersections and objects along the ray
0079     const auto intersection_record =
0080         detray::detector_scanner::run<detray::ray_scan>(gctx, det, test_ray);
0081 
0082     const std::string name =
0083         "test_svgtools_intersection_record" + std::to_string(index);
0084 
0085     // Drawing the intersections.
0086     auto intersections =
0087         detray::detail::transcribe_intersections(intersection_record);
0088     const auto svg_ir =
0089         il.draw_intersections(name, intersections, test_ray.dir(), view);
0090 
0091     detray::svgtools::write_svg(name, {axes, svg_det, svg_ir});
0092 
0093     index++;
0094   }
0095 }