|
| 1 | +/** Detray library, part of the ACTS project (R&D line) |
| 2 | + * |
| 3 | + * (c) 2024 CERN for the benefit of the ACTS project |
| 4 | + * |
| 5 | + * Mozilla Public License Version 2.0 |
| 6 | + */ |
| 7 | + |
| 8 | +// Project include(s). |
| 9 | +#include "detray/materials/interaction.hpp" |
| 10 | +#include "detray/materials/material.hpp" |
| 11 | +#include "detray/materials/predefined_materials.hpp" |
| 12 | + |
| 13 | +// Detray test include(s) |
| 14 | +#include "detray/test/utils/types.hpp" |
| 15 | + |
| 16 | +// GTest include(s). |
| 17 | +#include <gtest/gtest.h> |
| 18 | + |
| 19 | +using namespace detray; |
| 20 | + |
| 21 | +// Test class for the stopping power |
| 22 | +// Input tuple: < material, particle type, kinetic energy, expected output > |
| 23 | +class StoppingPowerValidation |
| 24 | + : public ::testing::TestWithParam< |
| 25 | + std::tuple<material<test::scalar>, pdg_particle<test::scalar>, |
| 26 | + test::scalar, test::scalar>> {}; |
| 27 | + |
| 28 | +TEST_P(StoppingPowerValidation, stopping_power) { |
| 29 | + |
| 30 | + // Interaction object |
| 31 | + interaction<test::scalar> I; |
| 32 | + |
| 33 | + // Material |
| 34 | + material<test::scalar> mat = std::get<0>(GetParam()); |
| 35 | + |
| 36 | + // Particle |
| 37 | + pdg_particle<test::scalar> ptc = std::get<1>(GetParam()); |
| 38 | + |
| 39 | + // Kinetic energy |
| 40 | + const test::scalar T = std::get<2>(GetParam()); |
| 41 | + |
| 42 | + // Total energy |
| 43 | + const test::scalar E = T + ptc.mass(); |
| 44 | + |
| 45 | + // Momentum |
| 46 | + const test::scalar p = math::sqrt(E * E - ptc.mass() * ptc.mass()); |
| 47 | + |
| 48 | + // qoverp |
| 49 | + const test::scalar qop{ptc.charge() / p}; |
| 50 | + |
| 51 | + // Stopping power in MeV * cm^2 / g |
| 52 | + const test::scalar dEdx{I.compute_stopping_power(mat, ptc, {ptc, qop}) / |
| 53 | + mat.mass_density() / |
| 54 | + (unit<test::scalar>::MeV * unit<test::scalar>::cm2 / |
| 55 | + unit<test::scalar>::g)}; |
| 56 | + |
| 57 | + const test::scalar expected_dEdx = std::get<3>(GetParam()); |
| 58 | + |
| 59 | + // Check if difference is within 8% error |
| 60 | + EXPECT_NEAR((expected_dEdx - dEdx) / dEdx, 0.f, 0.08f); |
| 61 | +} |
| 62 | + |
| 63 | +/****************** |
| 64 | + * Muon tests |
| 65 | + ******************/ |
| 66 | + |
| 67 | +// From https://pdg.lbl.gov/2024/AtomicNuclearProperties/index.html |
| 68 | +// Note 1: that we took the PDG value only from Ionization loss (Radiative loss |
| 69 | +// is ignored) Note 2: assumes that the stopping powers of muon and antimuon are |
| 70 | +// the same Note 3: Test fails with He Gas and 1 GeV muons (18 % difference) |
| 71 | +INSTANTIATE_TEST_SUITE_P( |
| 72 | + muon_stopping_power_He, StoppingPowerValidation, |
| 73 | + ::testing::Values( |
| 74 | + std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(), |
| 75 | + 100.0f * unit<test::scalar>::MeV, 2.165f), |
| 76 | + // std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(), |
| 77 | + // 1.f * unit<test::scalar>::GeV, 2.133f), |
| 78 | + std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(), |
| 79 | + 10.0f * unit<test::scalar>::GeV, 2.768f), |
| 80 | + std::make_tuple(helium_gas<test::scalar>(), muon<test::scalar>(), |
| 81 | + 100.0f * unit<test::scalar>::GeV, 3.188f))); |
| 82 | + |
| 83 | +INSTANTIATE_TEST_SUITE_P( |
| 84 | + muon_stopping_power_Si, StoppingPowerValidation, |
| 85 | + ::testing::Values( |
| 86 | + std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(), |
| 87 | + 100.0f * unit<test::scalar>::MeV, 1.849f), |
| 88 | + std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(), |
| 89 | + 1.f * unit<test::scalar>::GeV, 1.803f), |
| 90 | + std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(), |
| 91 | + 10.0f * unit<test::scalar>::GeV, 2.177f), |
| 92 | + std::make_tuple(silicon<test::scalar>(), muon<test::scalar>(), |
| 93 | + 100.0f * unit<test::scalar>::GeV, 2.451f))); |
| 94 | + |
| 95 | +INSTANTIATE_TEST_SUITE_P( |
| 96 | + anti_muon_stopping_power_He, StoppingPowerValidation, |
| 97 | + ::testing::Values( |
| 98 | + std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(), |
| 99 | + 100.0f * unit<test::scalar>::MeV, 2.165f), |
| 100 | + // std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(), |
| 101 | + // 1.f * unit<test::scalar>::GeV, 2.133f), |
| 102 | + std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(), |
| 103 | + 10.0f * unit<test::scalar>::GeV, 2.768f), |
| 104 | + std::make_tuple(helium_gas<test::scalar>(), antimuon<test::scalar>(), |
| 105 | + 100.0f * unit<test::scalar>::GeV, 3.188f))); |
| 106 | + |
| 107 | +INSTANTIATE_TEST_SUITE_P( |
| 108 | + anti_muon_stopping_power_Si, StoppingPowerValidation, |
| 109 | + ::testing::Values( |
| 110 | + std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(), |
| 111 | + 100.0f * unit<test::scalar>::MeV, 1.849f), |
| 112 | + std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(), |
| 113 | + 1.f * unit<test::scalar>::GeV, 1.803f), |
| 114 | + std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(), |
| 115 | + 10.0f * unit<test::scalar>::GeV, 2.177f), |
| 116 | + std::make_tuple(silicon<test::scalar>(), antimuon<test::scalar>(), |
| 117 | + 100.0f * unit<test::scalar>::GeV, 2.451f))); |
| 118 | + |
| 119 | +/********************* |
| 120 | + * Electron tests |
| 121 | + *********************/ |
| 122 | + |
| 123 | +// From https://physics.nist.gov/PhysRefData/Star/Text/ESTAR.html |
| 124 | +// Assumes that the stopping powers of electron and positron are the same |
| 125 | +INSTANTIATE_TEST_SUITE_P( |
| 126 | + electron_stopping_power_He, StoppingPowerValidation, |
| 127 | + ::testing::Values(std::make_tuple(helium_gas<test::scalar>(), |
| 128 | + electron<test::scalar>(), |
| 129 | + 100.0f * unit<test::scalar>::MeV, 3.532f), |
| 130 | + std::make_tuple(helium_gas<test::scalar>(), |
| 131 | + electron<test::scalar>(), |
| 132 | + 1.f * unit<test::scalar>::GeV, 13.14f))); |
| 133 | + |
| 134 | +INSTANTIATE_TEST_SUITE_P( |
| 135 | + electron_stopping_power_Si, StoppingPowerValidation, |
| 136 | + ::testing::Values(std::make_tuple(silicon<test::scalar>(), |
| 137 | + electron<test::scalar>(), |
| 138 | + 100.0f * unit<test::scalar>::MeV, 6.017f), |
| 139 | + std::make_tuple(silicon<test::scalar>(), |
| 140 | + electron<test::scalar>(), |
| 141 | + 1.f * unit<test::scalar>::GeV, 46.69f))); |
| 142 | + |
| 143 | +INSTANTIATE_TEST_SUITE_P( |
| 144 | + positron_stopping_power_He, StoppingPowerValidation, |
| 145 | + ::testing::Values(std::make_tuple(helium_gas<test::scalar>(), |
| 146 | + positron<test::scalar>(), |
| 147 | + 100.0f * unit<test::scalar>::MeV, 3.532f), |
| 148 | + std::make_tuple(helium_gas<test::scalar>(), |
| 149 | + positron<test::scalar>(), |
| 150 | + 1.f * unit<test::scalar>::GeV, 13.14f))); |
| 151 | + |
| 152 | +INSTANTIATE_TEST_SUITE_P( |
| 153 | + positron_stopping_power_Si, StoppingPowerValidation, |
| 154 | + ::testing::Values(std::make_tuple(silicon<test::scalar>(), |
| 155 | + positron<test::scalar>(), |
| 156 | + 100.0f * unit<test::scalar>::MeV, 6.017f), |
| 157 | + std::make_tuple(silicon<test::scalar>(), |
| 158 | + positron<test::scalar>(), |
| 159 | + 1.f * unit<test::scalar>::GeV, 46.69f))); |
0 commit comments