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/definitions/algebra.hpp"
0011 #include "detray/definitions/units.hpp"
0012 #include "detray/geometry/mask.hpp"
0013 #include "detray/geometry/shapes/annulus2D.hpp"
0014 
0015 // Detray IO include(s)
0016 #include "detray/io/backend/geometry_writer.hpp"
0017 #include "detray/io/backend/homogeneous_material_writer.hpp"
0018 #include "detray/io/backend/material_map_writer.hpp"
0019 #include "detray/io/backend/surface_grid_writer.hpp"
0020 #include "detray/io/frontend/detector_writer.hpp"
0021 #include "detray/io/json/json_converter.hpp"
0022 
0023 // Detray test include(s)
0024 #include "detray/test/common/build_telescope_detector.hpp"
0025 #include "detray/test/common/build_toy_detector.hpp"
0026 #include "detray/test/common/build_wire_chamber.hpp"
0027 #include "detray/test/framework/types.hpp"
0028 
0029 // Vecmem include(s)
0030 #include <vecmem/memory/host_memory_resource.hpp>
0031 
0032 // GTest include(s)
0033 #include <gtest/gtest.h>
0034 
0035 // System include(s)
0036 #include <ios>
0037 
0038 using namespace detray;
0039 
0040 namespace {
0041 
0042 using test_algebra = test::algebra;
0043 using scalar = test::scalar;
0044 
0045 // Use stereo annulus surfaces
0046 constexpr scalar minR{7.2f * unit<scalar>::mm};
0047 constexpr scalar maxR{12.0f * unit<scalar>::mm};
0048 constexpr scalar minPhi{0.74195f};
0049 constexpr scalar maxPhi{1.33970f};
0050 constexpr scalar offset_x{-2.f * unit<scalar>::mm};
0051 constexpr scalar offset_y{-2.f * unit<scalar>::mm};
0052 mask<annulus2D, test_algebra> ann2{0u,     minR,     maxR,     minPhi,
0053                                    maxPhi, offset_x, offset_y, 0.f};
0054 
0055 // Surface positions
0056 std::vector<scalar> positions = {0.f,   50.f,  100.f, 150.f, 200.f, 250.f,
0057                                  300.f, 350.f, 400.f, 450.f, 500.f};
0058 
0059 tel_det_config tel_cfg{ann2};
0060 
0061 }  // anonymous namespace
0062 
0063 /// Test the writing of a telescope detector geometry to json
0064 GTEST_TEST(io, json_telescope_geometry_writer) {
0065   using detector_t = detector<telescope_metadata<test_algebra, annulus2D>>;
0066 
0067   // Telescope detector
0068   vecmem::host_memory_resource host_mr;
0069   auto [det, names] = build_telescope_detector<test_algebra>(
0070       host_mr, tel_cfg.positions(positions));
0071 
0072   io::json_converter<detector_t, io::geometry_writer> geo_writer;
0073   geo_writer.write(det, names);
0074 }
0075 
0076 /// Test the writing of the toy detector material to json
0077 GTEST_TEST(io, json_telescope_material_writer) {
0078   using detector_t = detector<telescope_metadata<test_algebra, annulus2D>>;
0079 
0080   // Telescope detector
0081   vecmem::host_memory_resource host_mr;
0082 
0083   auto [det, names] = build_telescope_detector<test_algebra>(
0084       host_mr, tel_cfg.positions(positions));
0085 
0086   io::json_converter<detector_t, io::homogeneous_material_writer> mat_writer;
0087   mat_writer.write(det, names);
0088 }
0089 
0090 /// Test the writing of the toy detector grids to json
0091 GTEST_TEST(io, json_toy_material_maps_writer) {
0092   using detector_t = detector<test::toy_metadata>;
0093 
0094   // Toy detector
0095   vecmem::host_memory_resource host_mr;
0096   toy_det_config<scalar> toy_cfg{};
0097   toy_cfg.use_material_maps(true);
0098   auto [det, names] = build_toy_detector<test_algebra>(host_mr, toy_cfg);
0099 
0100   io::json_converter<detector_t, io::material_map_writer> map_writer;
0101   map_writer.write(det, names,
0102                    std::ios::out | std::ios::binary | std::ios::trunc);
0103 }
0104 
0105 /// Test the writing of the toy detector grids to json
0106 GTEST_TEST(io, json_toy_grid_writer) {
0107   using detector_t = detector<test::toy_metadata>;
0108 
0109   // Toy detector
0110   vecmem::host_memory_resource host_mr;
0111   auto [det, names] = build_toy_detector<test_algebra>(host_mr);
0112 
0113   io::json_converter<detector_t, io::surface_grid_writer> grid_writer;
0114   grid_writer.write(det, names,
0115                     std::ios::out | std::ios::binary | std::ios::trunc);
0116 }
0117 
0118 /// Test the writing of the entire toy detector to json
0119 GTEST_TEST(io, json_toy_detector_writer) {
0120   // Toy detector
0121   vecmem::host_memory_resource host_mr;
0122   toy_det_config<scalar> toy_cfg{};
0123   toy_cfg.use_material_maps(true);
0124   const auto [det, names] = build_toy_detector<test_algebra>(host_mr, toy_cfg);
0125 
0126   auto writer_cfg =
0127       io::detector_writer_config{}.format(io::format::json).replace_files(true);
0128   io::write_detector(det, names, writer_cfg);
0129 }
0130 
0131 /// Test the writing of the entire wire chamber to json
0132 GTEST_TEST(io, json_wire_chamber_writer) {
0133   // Wire chamber
0134   vecmem::host_memory_resource host_mr;
0135   wire_chamber_config<scalar> wire_cfg{};
0136   auto [det, names] = build_wire_chamber<test_algebra>(host_mr, wire_cfg);
0137 
0138   auto writer_cfg =
0139       io::detector_writer_config{}.format(io::format::json).replace_files(true);
0140   io::write_detector(det, names, writer_cfg);
0141 }