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/tracks/trajectories.hpp"
0011 
0012 #include "detray/core/detector.hpp"
0013 #include "detray/definitions/units.hpp"
0014 
0015 // Detray plugin include(s)
0016 #include "detray/plugins/svgtools/illustrator.hpp"
0017 #include "detray/plugins/svgtools/writer.hpp"
0018 
0019 // Detray test include(s)
0020 #include "detray/test/common/build_toy_detector.hpp"
0021 #include "detray/test/framework/types.hpp"
0022 #include "detray/test/validation/detector_scanner.hpp"
0023 #include "detray/test/validation/svg_display.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, trajectories) {
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   // Creating the 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::x_y 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   using detector_t = decltype(det);
0058 
0059   detector_t::geometry_context gctx{};
0060 
0061   // Creating the illustrator.
0062   const detray::svgtools::illustrator il{det, names};
0063 
0064   // Show the relevant volumes in the detector.
0065   const auto [svg_volumes, _] =
0066       il.draw_volumes(std::vector{7u, 9u, 11u, 13u}, view);
0067 
0068   // Creating a ray.
0069   using test_algebra = typename detector_t::algebra_type;
0070   using scalar = detray::dscalar<test_algebra>;
0071   using vector3 = detray::dvector3D<test_algebra>;
0072 
0073   const typename detector_t::point3_type ori{0.f, 0.f, 80.f};
0074   const typename detector_t::point3_type dir{0, 1.f, 1.f};
0075 
0076   const detray::detail::ray<test_algebra> ray(ori, 0.f, dir, 0.f);
0077   const auto ray_ir =
0078       detray::detector_scanner::run<detray::ray_scan>(gctx, det, ray);
0079 
0080   // Draw the trajectory.
0081   const auto svg_ray = il.draw_trajectory("trajectory", ray, 500.f, view);
0082 
0083   // Draw the intersections.
0084   auto ray_intersections = detray::detail::transcribe_intersections(ray_ir);
0085   const auto svg_ray_ir =
0086       il.draw_intersections("record", ray_intersections, ray.dir(), view);
0087 
0088   detray::svgtools::write_svg("test_svgtools_ray",
0089                               {svg_volumes, svg_ray, svg_ray_ir});
0090 
0091   // Creating a helix trajectory.
0092 
0093   // Constant magnetic field
0094   vector3 B{0.f * detray::unit<scalar>::T, 0.f * detray::unit<scalar>::T,
0095             1.f * detray::unit<scalar>::T};
0096 
0097   const detray::detail::helix<test_algebra> helix(
0098       ori, 0.f, detray::vector::normalize(dir), -8.f, B);
0099   const auto helix_ir =
0100       detray::detector_scanner::run<detray::helix_scan>(gctx, det, helix);
0101 
0102   // Draw the trajectory.
0103   const auto svg_helix = il.draw_trajectory("trajectory", helix, 500.f, view);
0104 
0105   // Draw the intersections.
0106   auto helix_intersections = detray::detail::transcribe_intersections(helix_ir);
0107   const auto svg_helix_ir =
0108       il.draw_intersections("record", helix_intersections, helix.dir(), view);
0109 
0110   detray::svgtools::write_svg("test_svgtools_helix",
0111                               {svg_volumes, svg_helix, svg_helix_ir});
0112 }