Back to home page

EIC code displayed by LXR

 
 

    


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

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 // detray core
0010 #include "detray/utils/grid/serializers.hpp"
0011 
0012 #include "detray/definitions/indexing.hpp"
0013 #include "detray/geometry/coordinates/cylindrical3D.hpp"
0014 #include "detray/geometry/coordinates/polar2D.hpp"
0015 #include "detray/geometry/mask.hpp"
0016 #include "detray/utils/grid/axis.hpp"
0017 
0018 // Detray test include(s)
0019 #include "detray/test/framework/types.hpp"
0020 
0021 // vecmem include(s)
0022 #include <vecmem/containers/vector.hpp>
0023 
0024 // GTest include(s)
0025 #include <gtest/gtest.h>
0026 
0027 // System include(s)
0028 #include <climits>
0029 
0030 using namespace detray;
0031 using namespace detray::axis;
0032 
0033 using test_algebra = test::algebra;
0034 using scalar = test::scalar;
0035 
0036 namespace {
0037 
0038 // Axes types to be serialized
0039 
0040 // polar coordinate system with regular binning on both axes
0041 using polar_axes = multi_axis<
0042     true, polar2D<test_algebra>,
0043     single_axis<closed<label::e_r>, regular<scalar, host_container_types>>,
0044     single_axis<circular<label::e_phi>, regular<scalar, host_container_types>>>;
0045 // 3-dim cylindrical coordinate system with regular binning
0046 using cylinder_axes = multi_axis<
0047     true, cylindrical3D<test_algebra>,
0048     single_axis<closed<label::e_r>, regular<scalar, host_container_types>>,
0049     single_axis<circular<label::e_phi>, regular<scalar, host_container_types>>,
0050     single_axis<closed<label::e_z>, regular<scalar, host_container_types>>>;
0051 
0052 }  // anonymous namespace
0053 
0054 GTEST_TEST(detray_grid, serializer2D) {
0055   // Offsets into edges container and #bins for all axes
0056   vecmem::vector<dsized_index_range> edge_ranges = {{0u, 6u}, {2u, 12u}};
0057   // Not needed for serializer test
0058   vecmem::vector<scalar> bin_edges{};
0059 
0060   polar_axes axes(std::move(edge_ranges), std::move(bin_edges));
0061 
0062   simple_serializer<2> serializer{};
0063 
0064   // Serializing
0065   multi_bin<2> mbin{0u, 0u};
0066   EXPECT_EQ(serializer(axes, mbin), 0u);
0067   mbin = {5u, 0u};
0068   EXPECT_EQ(serializer(axes, mbin), 5u);
0069   mbin = {0u, 1u};
0070   EXPECT_EQ(serializer(axes, mbin), 6u);
0071   mbin = {5u, 2u};
0072   EXPECT_EQ(serializer(axes, mbin), 17u);
0073 
0074   // Deserialize
0075   multi_bin<2> expected_mbin{0u, 0u};
0076   EXPECT_EQ(serializer(axes, 0u), expected_mbin);
0077   expected_mbin = {5u, 0u};
0078   EXPECT_EQ(serializer(axes, 5u), expected_mbin);
0079   expected_mbin = {0u, 1u};
0080   EXPECT_EQ(serializer(axes, 6u), expected_mbin);
0081   expected_mbin = {5u, 2u};
0082   EXPECT_EQ(serializer(axes, 17u), expected_mbin);
0083 }
0084 
0085 GTEST_TEST(detray_grid, serializer3D) {
0086   // Offsets into edges container and #bins for all axes
0087   vecmem::vector<dsized_index_range> edge_ranges = {
0088       {0u, 4u}, {2u, 2u}, {4u, 2u}};
0089   // Not needed for serializer test
0090   vecmem::vector<scalar> bin_edges{};
0091 
0092   cylinder_axes axes(std::move(edge_ranges), std::move(bin_edges));
0093 
0094   simple_serializer<3> serializer{};
0095 
0096   // Serializing
0097   multi_bin<3> mbin{0u, 0u, 0u};
0098   EXPECT_EQ(serializer(axes, mbin), 0u);
0099   mbin = {2u, 1u, 0u};
0100   EXPECT_EQ(serializer(axes, mbin), 6u);
0101   mbin = {3u, 0u, 1u};
0102   EXPECT_EQ(serializer(axes, mbin), 11u);
0103   mbin = {1u, 1u, 1u};
0104   EXPECT_EQ(serializer(axes, mbin), 13u);
0105 
0106   // Deserialize
0107   multi_bin<3> expected_mbin{0u, 0u, 0u};
0108   EXPECT_EQ(serializer(axes, 0u), expected_mbin);
0109   expected_mbin = {2u, 1u, 0u};
0110   EXPECT_EQ(serializer(axes, 6u), expected_mbin);
0111   expected_mbin = {3u, 0u, 1u};
0112   EXPECT_EQ(serializer(axes, 11u), expected_mbin);
0113   expected_mbin = {1u, 1u, 1u};
0114   EXPECT_EQ(serializer(axes, 13u), expected_mbin);
0115 }