Back to home page

EIC code displayed by LXR

 
 

    


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

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 include(s)
0010 #include "detray/builders/homogeneous_volume_material_builder.hpp"
0011 
0012 #include "detray/builders/surface_factory.hpp"
0013 #include "detray/core/detector.hpp"
0014 #include "detray/definitions/indexing.hpp"
0015 #include "detray/geometry/shapes/rectangle2D.hpp"
0016 #include "detray/material/predefined_materials.hpp"
0017 
0018 // Detray test include(s)
0019 #include "detray/test/framework/types.hpp"
0020 
0021 // Vecmem include(s)
0022 #include <vecmem/memory/host_memory_resource.hpp>
0023 
0024 // GTest include(s)
0025 #include <gtest/gtest.h>
0026 
0027 // System include(s)
0028 #include <limits>
0029 #include <memory>
0030 #include <vector>
0031 
0032 using namespace detray;
0033 
0034 using scalar = detray::test::scalar;
0035 using point3 = test::point3;
0036 
0037 /// Unittest: Test the construction of a collection of materials
0038 TEST(detray_builders, homogeneous_volume_material_builder) {
0039   using metadata_t = test::default_metadata;
0040   using detector_t = detector<metadata_t>;
0041   using transform3 = typename detector_t::transform3_type;
0042 
0043   constexpr auto material_id{detector_t::material::id::e_raw_material};
0044 
0045   vecmem::host_memory_resource host_mr;
0046   detector_t d(host_mr);
0047 
0048   EXPECT_TRUE(d.material_store().template empty<material_id>());
0049 
0050   // Add material to a new volume
0051   auto vbuilder =
0052       std::make_unique<volume_builder<detector_t>>(volume_id::e_cylinder);
0053   auto mat_builder =
0054       homogeneous_volume_material_builder<detector_t>{std::move(vbuilder)};
0055 
0056   // Add some surfaces
0057   using rectangle_factory = surface_factory<detector_t, rectangle2D>;
0058   auto sf_factory = std::make_shared<rectangle_factory>();
0059   sf_factory->push_back({surface_id::e_sensitive,
0060                          transform3(point3{0.f, 0.f, -1.f}), 1u,
0061                          std::vector<scalar>{10.f, 8.f}});
0062   mat_builder.add_surfaces(sf_factory);
0063 
0064   // Set volume material
0065   mat_builder.set_material(argon_liquid<scalar>{});
0066 
0067   // Add the volume to the detector
0068   mat_builder.build(d);
0069 
0070   // Test the material data
0071   EXPECT_EQ(d.volumes().size(), 1u);
0072   const auto &vol_desc = d.volumes().at(0);
0073   EXPECT_EQ(vol_desc.material().id(), material_id);
0074   EXPECT_EQ(vol_desc.material().index(), 0u);
0075   EXPECT_EQ(d.material_store().template size<material_id>(), 1u);
0076   EXPECT_EQ(d.material_store().template get<material_id>()[0],
0077             argon_liquid<scalar>{});
0078 }