Skip to content

Commit

Permalink
Fix several assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Jan 26, 2025
1 parent 03c8f8e commit 17571ed
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ detray-build/bin/detray_detector_validation \
```
In case of failures, this command will give a detailed debug output in the form of a log file, as well as an SVG representation of the failed tracks. The grid file is optional, but will trigger the use of spacial grids as acceleration structures during the navigation run.

Note: The `search_window` option defines the size of lookup area of the grid acceleration struction and is therefore detector dependent! Use `--search_window 3 3` (or larger) for the *toy detector* and *wire chamber* example detectors and `--search_window 0 0` otherwise.
Note: The `search_window` option defines the size of lookup area of the grid acceleration structure and is therefore detector dependent! Use `--search_window 3 3` (or larger) for the *toy detector* and *wire chamber* example detectors and `--search_window 0 0` otherwise.

### Material Validation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct relativistic_quantities {

// 1/p = q/(qp) = (q/p)/q
const scalar_type mOverP{
mass * ((q == 0.f) ? math::fabs(qOverP / q) : math::fabs(qOverP))};
mass * ((q != 0.f) ? math::fabs(qOverP / q) : math::fabs(qOverP))};
const scalar_type pOverM{1.f / mOverP};
// beta² = p²/E² = p²/(m² + p²) = 1/(1 + (m/p)²)
m_beta2 = 1.f / (1.f + mOverP * mOverP);
Expand Down
2 changes: 2 additions & 0 deletions core/include/detray/navigation/navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,14 @@ class navigator {
/// @returns next object that we want to reach (current target)
DETRAY_HOST_DEVICE
inline auto target() -> candidate_t & {
assert(static_cast<std::size_t>(m_next) < m_candidates.size());
return m_candidates[static_cast<std::size_t>(m_next)];
}

/// @returns last valid candidate (by position in the cache)
DETRAY_HOST_DEVICE
inline auto last() -> candidate_t & {
assert(static_cast<std::size_t>(m_last) < m_candidates.size());
return m_candidates[static_cast<std::size_t>(m_last)];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct pointwise_material_interactor : actor {
const auto mat = detail::material_accessor::get(
material_group, mat_index, bound_params.bound_local());

// return early in case of zero thickness
// Return early in case of zero thickness
if (mat.thickness() <=
std::numeric_limits<scalar_type>::epsilon()) {
return false;
Expand Down
34 changes: 24 additions & 10 deletions tests/include/detray/test/cpu/material_scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class material_scan : public test::fixture_base<> {
/// Run the ray scan
void TestBody() override {

using nav_link_t = typename detector_t::surface_type::navigation_link;
using material_record_t = material_validator::material_record<scalar_t>;

std::size_t n_tracks{0u};
Expand Down Expand Up @@ -138,15 +137,30 @@ class material_scan : public test::fixture_base<> {
for (const auto &[i, record] :
detray::views::enumerate(intersection_record)) {

// Prevent double counting of material on adjacent portals
if ((i < intersection_record.size() + 1) &&
(((intersection_record[i + 1].intersection ==
record.intersection) &&
intersection_record[i + 1]
.intersection.sf_desc.is_portal() &&
record.intersection.sf_desc.is_portal()) ||
(record.intersection.volume_link ==
detail::invalid_value<nav_link_t>()))) {
// Check whether this record has a successor
if (i < intersection_record.size() - 1) {

const auto &current_intr = record.intersection;
const auto &next_intr =
intersection_record[i + 1].intersection;

const bool is_same_intrs{next_intr == current_intr};
const bool current_is_pt{current_intr.sf_desc.is_portal()};
const bool next_is_pt{next_intr.sf_desc.is_portal()};

const bool is_dummy_record{i == 0};

// Prevent double counting of material on adjacent portals
// (the navigator automatically skips the exit portal)
if ((is_same_intrs && next_is_pt && current_is_pt) ||
is_dummy_record) {
continue;
}
}

// Don't count the last portal, because navigation terminates
// before the material is counted
if (detail::is_invalid_value(record.intersection.volume_link)) {
continue;
}

Expand Down
7 changes: 5 additions & 2 deletions tests/include/detray/test/utils/inspectors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,12 @@ struct print_inspector {
}

debug_stream << "distance to next\t\t";
if (math::fabs(state()) <
static_cast<decltype(math::fabs(state()))>(cfg.path_tolerance)) {
if (!state.is_exhausted() &&
math::fabs(state()) < static_cast<decltype(math::fabs(state()))>(
cfg.path_tolerance)) {
debug_stream << "on obj (within tol)" << std::endl;
} else if (state.is_exhausted()) {
debug_stream << "no target" << std::endl;
} else {
debug_stream << state() << std::endl;
}
Expand Down
10 changes: 9 additions & 1 deletion tests/include/detray/test/validation/detector_scanner.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2022-2024 CERN for the benefit of the ACTS project
* (c) 2022-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand All @@ -22,6 +22,8 @@

// System include(s)
#include <algorithm>
#include <sstream>
#include <stdexcept>
#include <type_traits>

namespace detray {
Expand Down Expand Up @@ -107,6 +109,12 @@ struct brute_force_scan {
intersections.clear();
}

// Need to have at least an exit portal
if (intersection_trace.empty()) {
std::stringstream stream;
stream << "No intersections found for traj: " << traj << std::endl;
throw std::runtime_error(stream.str());
}
// Save initial track position as dummy intersection record
const auto &first_record = intersection_trace.front();
intersection_t start_intersection{};
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/cpu/utils/grids/populators.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2022-2024 CERN for the benefit of the ACTS project
* (c) 2022-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -56,7 +56,7 @@ GTEST_TEST(detray_grid, replace_populator) {

// Create some bin data
dvector<bins::single<dindex>> bin_data{};
bin_data.reserve(50);
bin_data.resize(50);
std::ranges::generate_n(bin_data.begin(), 50,
bin_content_sequence<bins::single<dindex>>());

Expand Down Expand Up @@ -102,7 +102,7 @@ GTEST_TEST(detray_grid, complete_populator) {

// Create some bin data
dvector<bins::static_array<dindex, 4>> bin_data{};
bin_data.reserve(50);
bin_data.resize(50);
std::ranges::generate_n(
bin_data.begin(), 50,
bin_content_sequence<bins::static_array<dindex, 4>>());
Expand Down Expand Up @@ -173,7 +173,7 @@ GTEST_TEST(detray_grid, regular_attach_populator) {

// Create some bin data
dvector<bins::static_array<dindex, 4>> bin_data{};
bin_data.reserve(50);
bin_data.resize(50);
std::ranges::generate_n(
bin_data.begin(), 50,
bin_content_sequence<bins::static_array<dindex, 4>>());
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/device/cuda/utils_ranges_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ TEST(utils_ranges_cuda, pick) {
}
}

// This tests the convenience enumeration function
// This tests the detray join range
TEST(utils_ranges_cuda, join) {

// Helper object for performing memory copies.
Expand Down Expand Up @@ -261,7 +261,7 @@ TEST(utils_ranges_cuda, join) {
ASSERT_EQ(seq_1[i].ui, value_vec[i]);
}
// Second sequence
for (std::size_t i = 0u; i < seq_1.size(); i++) {
for (std::size_t i = 0u; i < seq_2.size(); i++) {
ASSERT_EQ(seq_2[i].ui, value_vec[i + seq_1.size()]);
}
}
Expand Down

0 comments on commit 17571ed

Please sign in to comment.