Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
beomki-yeo committed Dec 9, 2024
1 parent cefce90 commit 1a0680a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,15 @@ struct pointwise_material_interactor : actor {

if (interactor_state.do_covariance_transport) {

update_qop_variance(covariance, interactor_state.sigma_qop,
nav_dir);
update_qop_variance(covariance, interactor_state.sigma_qop);
}
}

if (interactor_state.do_covariance_transport) {

update_angle_variance(
covariance, bound_params.dir(),
interactor_state.projected_scattering_angle, nav_dir);
interactor_state.projected_scattering_angle);
}
}
}
Expand Down Expand Up @@ -226,13 +225,12 @@ struct pointwise_material_interactor : actor {
/// @param[in] sigma_qop variance of q over p
/// @param[in] sign navigation direction
DETRAY_HOST_DEVICE inline void update_qop_variance(
bound_matrix_type &covariance, const scalar_type sigma_qop,
const int sign) const {
bound_matrix_type &covariance, const scalar_type sigma_qop) const {

const scalar_type variance_qop{sigma_qop * sigma_qop};

getter::element(covariance, e_bound_qoverp, e_bound_qoverp) +=
math::copysign(variance_qop, static_cast<scalar_type>(sign));
variance_qop;
}

/// @brief Update the variance of phi and theta of bound track parameter
Expand All @@ -243,18 +241,29 @@ struct pointwise_material_interactor : actor {
/// @param[in] sign navigation direction
DETRAY_HOST_DEVICE inline void update_angle_variance(
bound_matrix_type &covariance, const vector3_type &dir,
const scalar_type projected_scattering_angle, const int sign) const {
const scalar_type projected_scattering_angle) const {

// variance of projected scattering angle
const scalar_type var_scattering_angle{math::copysign(
projected_scattering_angle * projected_scattering_angle,
static_cast<scalar_type>(sign))};
const scalar_type var_scattering_angle{projected_scattering_angle *
projected_scattering_angle};

constexpr auto inv{detail::invalid_value<scalar_type>()};

/*
std::cout << var_scattering_angle / (1.f - dir[2] * dir[2]) << " "
<< var_scattering_angle << " " << dir[2] << std::endl;
*/

const auto prev_phi =
getter::element(covariance, e_bound_phi, e_bound_phi);

getter::element(covariance, e_bound_phi, e_bound_phi) +=
(dir[2] == 1.f) ? inv
: var_scattering_angle / (1.f - dir[2] * dir[2]);

std::cout << "Phi cov: " << prev_phi << " "
<< getter::element(covariance, e_bound_phi, e_bound_phi)
<< std::endl;

getter::element(covariance, e_bound_theta, e_bound_theta) +=
var_scattering_angle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ GTEST_TEST(detray_material, telescope_geometry_scattering_angle) {
if (i == 0u) {
pointwise_material_interactor<algebra_t>{}.update_angle_variance(
bound_cov, traj.dir(),
simulator_state.projected_scattering_angle, 1);
simulator_state.projected_scattering_angle);
}

phis.push_back(final_param.phi());
Expand Down
27 changes: 11 additions & 16 deletions tests/integration_tests/cpu/propagator/backward_propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@ TEST_P(BackwardPropagation, backward_propagation) {
const auto bound_cov1 = bound_param1.covariance();
const auto bound_cov2 = bound_param2.covariance();

// Check covaraince
for (unsigned int i = 0u; i < e_bound_size; i++) {
for (unsigned int j = 0u; j < e_bound_size; j++) {
EXPECT_NEAR(getter::element(bound_cov0, i, j),
getter::element(bound_cov2, i, j), tol)
<< "i: " << i << "\nj: " << j << "\n"
<< bound_param2;
}
}

// Some sanity checks
EXPECT_TRUE(bound_param0.p(ptc.charge()) > bound_param1.p(ptc.charge()));
EXPECT_TRUE(bound_param2.p(ptc.charge()) > bound_param1.p(ptc.charge()));
Expand All @@ -177,12 +167,17 @@ TEST_P(BackwardPropagation, backward_propagation) {
EXPECT_TRUE(getter::element(bound_cov1, e_bound_phi, e_bound_phi) >
getter::element(bound_cov0, e_bound_phi, e_bound_phi));

EXPECT_TRUE(getter::element(bound_cov1, e_bound_qoverp, e_bound_qoverp) >
getter::element(bound_cov2, e_bound_qoverp, e_bound_qoverp));
EXPECT_TRUE(getter::element(bound_cov1, e_bound_theta, e_bound_theta) >
getter::element(bound_cov2, e_bound_theta, e_bound_theta));
EXPECT_TRUE(getter::element(bound_cov1, e_bound_phi, e_bound_phi) >
getter::element(bound_cov2, e_bound_phi, e_bound_phi));
EXPECT_TRUE(getter::element(bound_cov2, e_bound_qoverp, e_bound_qoverp) >
getter::element(bound_cov1, e_bound_qoverp, e_bound_qoverp));
EXPECT_TRUE(getter::element(bound_cov2, e_bound_theta, e_bound_theta) >
getter::element(bound_cov1, e_bound_theta, e_bound_theta));

std::cout << getter::element(bound_cov2, e_bound_phi, e_bound_phi) << " "
<< getter::element(bound_cov1, e_bound_phi, e_bound_phi)
<< std::endl;

EXPECT_TRUE(getter::element(bound_cov2, e_bound_phi, e_bound_phi) >
getter::element(bound_cov1, e_bound_phi, e_bound_phi));
}

INSTANTIATE_TEST_SUITE_P(
Expand Down
5 changes: 1 addition & 4 deletions tests/unit_tests/cpu/simulation/scattering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ GTEST_TEST(detray_simulation, angle_update) {
// Projected scattering angle (Tests will fail with relatively large angles)
const scalar_t projected_scattering_angle{0.01f};

// Navigation in forward direction
const int direction_sign = 1;

// Initial bound covariance
auto bound_cov = matrix::zero<
typename bound_track_parameters<algebra_t>::covariance_type>();
Expand All @@ -108,7 +105,7 @@ GTEST_TEST(detray_simulation, angle_update) {

// Update the bound covariance with projected scattering angle
pointwise_material_interactor<algebra_t>().update_angle_variance(
bound_cov, dir, projected_scattering_angle, direction_sign);
bound_cov, dir, projected_scattering_angle);

// Get the samples of phi and theta after the random scattering
std::vector<scalar_t> phis;
Expand Down

0 comments on commit 1a0680a

Please sign in to comment.