Skip to content

Commit

Permalink
Merge pull request #563 from niermann999/fix-assert
Browse files Browse the repository at this point in the history
fix: asserts in detector building
  • Loading branch information
beomki-yeo authored Oct 14, 2023
2 parents 30db3b4 + b1c00e1 commit dd6308d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
7 changes: 4 additions & 3 deletions tests/unit_tests/cpu/core_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ GTEST_TEST(detray_tools, detector_builder) {
auto portal_generator =
std::make_shared<cuboid_portal_generator<detector_t>>(env);

vbuilder2->add_surfaces(trpz_factory, geo_ctx);
vbuilder2->add_surfaces(portal_generator);

// initial checks
Expand Down Expand Up @@ -753,14 +754,14 @@ GTEST_TEST(detray_tools, detector_builder) {

// Check the acceleration data structure link (indirectly)
EXPECT_EQ(vol0.n_max_candidates(), 3u);
EXPECT_EQ(vol1.n_max_candidates(), 6u);
EXPECT_EQ(vol1.n_max_candidates(), 9u);

EXPECT_EQ(d.surface_lookup().size(), 9u);
EXPECT_EQ(d.surface_lookup().size(), 12u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_portal_cylinder2>(), 0u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_portal_ring2>(), 0u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_annulus2>(), 0u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_cylinder2>(), 0u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_rectangle2>(), 3u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_ring2>(), 0u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_trapezoid2>(), 3u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_trapezoid2>(), 6u);
}
30 changes: 26 additions & 4 deletions tests/unit_tests/cpu/tools_material_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,22 @@ GTEST_TEST(detray_tools, decorator_material_builder) {
GTEST_TEST(detray_tools, detector_builder_with_material) {
using namespace detray;

using transform3 = typename detector_t::transform3;
using mask_id = typename detector_t::masks::id;
using material_id = typename detector_t::materials::id;

// Surface factories
using trapezoid_factory = surface_factory<detector_t, trapezoid2D<>>;

// detector builder
detector_builder<default_metadata> det_builder{};
auto geo_ctx = typename detector_t::geometry_context{};

// Vanilla volume builder
auto vbuilder = det_builder.new_volume(volume_id::e_cuboid);
const auto vol_idx{
static_cast<typename detector_t::surface_type::navigation_link>(
vbuilder->vol_index())};

// Add material
auto mv_builder =
Expand All @@ -245,6 +253,18 @@ GTEST_TEST(detray_tools, detector_builder_with_material) {
typename detector_t::point3 t{0.f, 0.f, 20.f};
mv_builder->add_volume_placement(t);

// Add a senstive surface
auto trpz_factory = std::make_unique<trapezoid_factory>();
// Add material to the surface
auto mat_sf_factory =
std::make_shared<material_factory<detector_t>>(std::move(trpz_factory));

mat_sf_factory->push_back({surface_id::e_sensitive,
transform3(point3{0.f, 0.f, 1000.f}), vol_idx,
std::vector<scalar>{1.f, 3.f, 2.f, 0.25f}});
mat_sf_factory->add_material(material_id::e_slab,
{1.f * unit<scalar>::mm, silicon<scalar>()});

// Add a portal box around the cuboid volume with a min distance of 'env'
constexpr auto env{0.1f * unit<detray::scalar>::mm};
auto portal_generator =
Expand All @@ -253,8 +273,6 @@ GTEST_TEST(detray_tools, detector_builder_with_material) {
// Add homogeneous material to every portal
auto mat_portal_factory = std::make_shared<material_factory<detector_t>>(
std::move(portal_generator));
mat_portal_factory->add_material(
material_id::e_slab, {1.f * unit<scalar>::mm, silicon<scalar>()});
mat_portal_factory->add_material(
material_id::e_slab, {2.f * unit<scalar>::mm, silicon<scalar>()});
mat_portal_factory->add_material(
Expand All @@ -265,7 +283,10 @@ GTEST_TEST(detray_tools, detector_builder_with_material) {
material_id::e_slab, {5.f * unit<scalar>::mm, silicon<scalar>()});
mat_portal_factory->add_material(
material_id::e_slab, {6.f * unit<scalar>::mm, silicon<scalar>()});
mat_portal_factory->add_material(
material_id::e_slab, {7.f * unit<scalar>::mm, silicon<scalar>()});

mv_builder->add_surfaces(mat_sf_factory, geo_ctx);
mv_builder->add_surfaces(mat_portal_factory);

//
Expand All @@ -285,9 +306,10 @@ GTEST_TEST(detray_tools, detector_builder_with_material) {
EXPECT_TRUE(vol.transform() == trf);
EXPECT_TRUE(d.transform_store()[0u] == trf);

EXPECT_EQ(d.surface_lookup().size(), 6u);
EXPECT_EQ(d.surface_lookup().size(), 7u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_rectangle2>(), 3u);
EXPECT_EQ(d.material_store().template size<material_id::e_slab>(), 6u);
EXPECT_EQ(d.mask_store().template size<mask_id::e_trapezoid2>(), 1u);
EXPECT_EQ(d.material_store().template size<material_id::e_slab>(), 7u);

// Check the material links
for (const auto [idx, sf_desc] :
Expand Down

0 comments on commit dd6308d

Please sign in to comment.