Skip to content

Commit

Permalink
Replace scalar with test::scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
beomki-yeo committed Dec 2, 2024
1 parent 9dad955 commit 8cba805
Showing 1 changed file with 72 additions and 60 deletions.
132 changes: 72 additions & 60 deletions tests/unit_tests/cpu/material/stopping_power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,39 @@ using namespace detray;
// Input tuple: < material, particle type, kinetic energy, expected output >
class StoppingPowerValidation
: public ::testing::TestWithParam<
std::tuple<material<scalar>, pdg_particle<scalar>, scalar, scalar>> {
};
std::tuple<material<test::scalar>, pdg_particle<test::scalar>,
test::scalar, test::scalar>> {};

TEST_P(StoppingPowerValidation, stopping_power) {

// Interaction object
interaction<test::scalar> I;

// Material
material<scalar> mat = std::get<0>(GetParam());
material<test::scalar> mat = std::get<0>(GetParam());

// Particle
pdg_particle<scalar> ptc = std::get<1>(GetParam());
pdg_particle<test::scalar> ptc = std::get<1>(GetParam());

// Kinetic energy
const scalar T = std::get<2>(GetParam());
const test::scalar T = std::get<2>(GetParam());

// Total energy
const scalar E = T + ptc.mass();
const test::scalar E = T + ptc.mass();

// Momentum
const scalar p = math::sqrt(E * E - ptc.mass() * ptc.mass());
const test::scalar p = math::sqrt(E * E - ptc.mass() * ptc.mass());

// qoverp
const scalar qop{ptc.charge() / p};
const test::scalar qop{ptc.charge() / p};

// Stopping power in MeV * cm^2 / g
const scalar dEdx{
I.compute_stopping_power(mat, ptc, {ptc, qop}) / mat.mass_density() /
(unit<scalar>::MeV * unit<scalar>::cm2 / unit<scalar>::g)};
const test::scalar dEdx{I.compute_stopping_power(mat, ptc, {ptc, qop}) /
mat.mass_density() /
(unit<test::scalar>::MeV * unit<test::scalar>::cm2 /
unit<test::scalar>::g)};

const scalar expected_dEdx = std::get<3>(GetParam());
const test::scalar expected_dEdx = std::get<3>(GetParam());

// Check if difference is within 8% error
EXPECT_NEAR((expected_dEdx - dEdx) / dEdx, 0.f, 0.08f);
Expand All @@ -69,48 +70,51 @@ TEST_P(StoppingPowerValidation, stopping_power) {
// the same Note 3: Test fails with He Gas and 1 GeV muons (18 % difference)
INSTANTIATE_TEST_SUITE_P(
muon_stopping_power_He, StoppingPowerValidation,
::testing::Values(std::make_tuple(helium_gas<scalar>(), muon<scalar>(),
100.0f * unit<scalar>::MeV, 2.165f),
// std::make_tuple(helium_gas<scalar>(), muon<scalar>(),
// 1.f * unit<scalar>::GeV, 2.133f),
std::make_tuple(helium_gas<scalar>(), muon<scalar>(),
10.0f * unit<scalar>::GeV, 2.768f),
std::make_tuple(helium_gas<scalar>(), muon<scalar>(),
100.0f * unit<scalar>::GeV, 3.188f)));
::testing::Values(
std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 2.165f),
// std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(),
// 1.f * unit<test::scalar>::GeV, 2.133f),
std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(),
10.0f * unit<test::scalar>::GeV, 2.768f),
std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(),
100.0f * unit<test::scalar>::GeV, 3.188f)));

INSTANTIATE_TEST_SUITE_P(
muon_stopping_power_Si, StoppingPowerValidation,
::testing::Values(std::make_tuple(silicon<scalar>(), muon<scalar>(),
100.0f * unit<scalar>::MeV, 1.849f),
std::make_tuple(silicon<scalar>(), muon<scalar>(),
1.f * unit<scalar>::GeV, 1.803f),
std::make_tuple(silicon<scalar>(), muon<scalar>(),
10.0f * unit<scalar>::GeV, 2.177f),
std::make_tuple(silicon<scalar>(), muon<scalar>(),
100.0f * unit<scalar>::GeV, 2.451f)));
::testing::Values(
std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 1.849f),
std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(),
1.f * unit<test::scalar>::GeV, 1.803f),
std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(),
10.0f * unit<test::scalar>::GeV, 2.177f),
std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(),
100.0f * unit<test::scalar>::GeV, 2.451f)));

INSTANTIATE_TEST_SUITE_P(
anti_muon_stopping_power_He, StoppingPowerValidation,
::testing::Values(
std::make_tuple(helium_gas<scalar>(), antimuon<scalar>(),
100.0f * unit<scalar>::MeV, 2.165f),
// std::make_tuple(helium_gas<scalar>(), antimuon<scalar>(),
// 1.f * unit<scalar>::GeV, 2.133f),
std::make_tuple(helium_gas<scalar>(), antimuon<scalar>(),
10.0f * unit<scalar>::GeV, 2.768f),
std::make_tuple(helium_gas<scalar>(), antimuon<scalar>(),
100.0f * unit<scalar>::GeV, 3.188f)));
std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 2.165f),
// std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(),
// 1.f * unit<test::scalar>::GeV, 2.133f),
std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(),
10.0f * unit<test::scalar>::GeV, 2.768f),
std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(),
100.0f * unit<test::scalar>::GeV, 3.188f)));

INSTANTIATE_TEST_SUITE_P(
anti_muon_stopping_power_Si, StoppingPowerValidation,
::testing::Values(std::make_tuple(silicon<scalar>(), antimuon<scalar>(),
100.0f * unit<scalar>::MeV, 1.849f),
std::make_tuple(silicon<scalar>(), antimuon<scalar>(),
1.f * unit<scalar>::GeV, 1.803f),
std::make_tuple(silicon<scalar>(), antimuon<scalar>(),
10.0f * unit<scalar>::GeV, 2.177f),
std::make_tuple(silicon<scalar>(), antimuon<scalar>(),
100.0f * unit<scalar>::GeV, 2.451f)));
::testing::Values(
std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 1.849f),
std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(),
1.f * unit<test::scalar>::GeV, 1.803f),
std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(),
10.0f * unit<test::scalar>::GeV, 2.177f),
std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(),
100.0f * unit<test::scalar>::GeV, 2.451f)));

/*********************
* Electron tests
Expand All @@ -120,28 +124,36 @@ INSTANTIATE_TEST_SUITE_P(
// Assumes that the stopping powers of electron and positron are the same
INSTANTIATE_TEST_SUITE_P(
electron_stopping_power_He, StoppingPowerValidation,
::testing::Values(std::make_tuple(helium_gas<scalar>(), electron<scalar>(),
100.0f * unit<scalar>::MeV, 3.532f),
std::make_tuple(helium_gas<scalar>(), electron<scalar>(),
1.f * unit<scalar>::GeV, 13.14f)));
::testing::Values(std::make_tuple(helium_gas<test::scalar>(),
electron<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 3.532f),
std::make_tuple(helium_gas<test::scalar>(),
electron<test::scalar>(),
1.f * unit<test::scalar>::GeV, 13.14f)));

INSTANTIATE_TEST_SUITE_P(
electron_stopping_power_Si, StoppingPowerValidation,
::testing::Values(std::make_tuple(silicon<scalar>(), electron<scalar>(),
100.0f * unit<scalar>::MeV, 6.017f),
std::make_tuple(silicon<scalar>(), electron<scalar>(),
1.f * unit<scalar>::GeV, 46.69f)));
::testing::Values(std::make_tuple(silicon<test::scalar>(),
electron<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 6.017f),
std::make_tuple(silicon<test::scalar>(),
electron<test::scalar>(),
1.f * unit<test::scalar>::GeV, 46.69f)));

INSTANTIATE_TEST_SUITE_P(
positron_stopping_power_He, StoppingPowerValidation,
::testing::Values(std::make_tuple(helium_gas<scalar>(), positron<scalar>(),
100.0f * unit<scalar>::MeV, 3.532f),
std::make_tuple(helium_gas<scalar>(), positron<scalar>(),
1.f * unit<scalar>::GeV, 13.14f)));
::testing::Values(std::make_tuple(helium_gas<test::scalar>(),
positron<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 3.532f),
std::make_tuple(helium_gas<test::scalar>(),
positron<test::scalar>(),
1.f * unit<test::scalar>::GeV, 13.14f)));

INSTANTIATE_TEST_SUITE_P(
positron_stopping_power_Si, StoppingPowerValidation,
::testing::Values(std::make_tuple(silicon<scalar>(), positron<scalar>(),
100.0f * unit<scalar>::MeV, 6.017f),
std::make_tuple(silicon<scalar>(), positron<scalar>(),
1.f * unit<scalar>::GeV, 46.69f)));
::testing::Values(std::make_tuple(silicon<test::scalar>(),
positron<test::scalar>(),
100.0f * unit<test::scalar>::MeV, 6.017f),
std::make_tuple(silicon<test::scalar>(),
positron<test::scalar>(),
1.f * unit<test::scalar>::GeV, 46.69f)));

0 comments on commit 8cba805

Please sign in to comment.