20
20
21
21
// System include(s)
22
22
#include < iostream>
23
+ #include < limits>
23
24
#include < stdexcept>
24
25
#include < string>
25
26
#include < string_view>
@@ -132,6 +133,7 @@ class material_validation_impl : public test::fixture_base<> {
132
133
133
134
// Collect some statistics
134
135
std::size_t n_tracks{0u };
136
+ const scalar_t rel_error{m_cfg.relative_error ()};
135
137
for (std::size_t i = 0u ; i < mat_records.size (); ++i) {
136
138
137
139
if (n_tracks >= m_cfg.n_tracks ()) {
@@ -141,14 +143,36 @@ class material_validation_impl : public test::fixture_base<> {
141
143
const auto &truth_mat = truth_mat_records[i];
142
144
const auto &recorded_mat = mat_records[i];
143
145
144
- EXPECT_NEAR (truth_mat.sX0 , recorded_mat.sX0 , m_cfg.tol ())
145
- << " Track " << n_tracks << " (X0 / path)" ;
146
- EXPECT_NEAR (truth_mat.tX0 , recorded_mat.tX0 , m_cfg.tol ())
147
- << " Track " << n_tracks << " (X0 / thickness)" ;
148
- EXPECT_NEAR (truth_mat.sL0 , recorded_mat.sL0 , m_cfg.tol ())
149
- << " Track " << n_tracks << " (L0 / path)" ;
150
- EXPECT_NEAR (truth_mat.tL0 , recorded_mat.tL0 , m_cfg.tol ())
151
- << " Track " << n_tracks << " (L0 / thickness)" ;
146
+ auto get_rel_error = [](const scalar_t truth, const scalar_t rec) {
147
+ constexpr scalar_t e{std::numeric_limits<scalar_t >::epsilon ()};
148
+
149
+ if (truth <= e && rec <= e) {
150
+ // No material for this ray => valid
151
+ return scalar_t {0 .f };
152
+ } else if (truth <= e) {
153
+ // Material found where none should be
154
+ return detail::invalid_value<scalar_t >();
155
+ } else {
156
+ return math::fabs (truth - rec) / truth;
157
+ }
158
+ };
159
+
160
+ EXPECT_TRUE (get_rel_error (truth_mat.sX0 , recorded_mat.sX0 ) <
161
+ rel_error)
162
+ << " Track " << n_tracks << " (X0 / path): Truth "
163
+ << truth_mat.sX0 << " , Nav. " << recorded_mat.sX0 ;
164
+ EXPECT_TRUE (get_rel_error (truth_mat.tX0 , recorded_mat.tX0 ) <
165
+ rel_error)
166
+ << " Track " << n_tracks << " (X0 / thickness): Truth "
167
+ << truth_mat.tX0 << " , Nav. " << recorded_mat.tX0 ;
168
+ EXPECT_TRUE (get_rel_error (truth_mat.sL0 , recorded_mat.sL0 ) <
169
+ rel_error)
170
+ << " Track " << n_tracks << " (L0 / path): Truth "
171
+ << truth_mat.sL0 << " , Nav. " << recorded_mat.sL0 ;
172
+ EXPECT_TRUE (get_rel_error (truth_mat.tL0 , recorded_mat.tL0 ) <
173
+ rel_error)
174
+ << " Track " << n_tracks << " (L0 / thickness): Truth "
175
+ << truth_mat.tL0 << " , Nav. " << recorded_mat.tL0 ;
152
176
153
177
++n_tracks;
154
178
}
0 commit comments