Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-24 09:28:44

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/PdgParticle.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/Material/Interactions.hpp"
0015 #include "Acts/Material/Material.hpp"
0016 #include "Acts/Material/MaterialSlab.hpp"
0017 #include "ActsTests/CommonHelpers/PredefinedMaterials.hpp"
0018 
0019 #include <utility>
0020 
0021 namespace data = boost::unit_test::data;
0022 
0023 using namespace Acts;
0024 using namespace Acts::UnitLiterals;
0025 
0026 namespace ActsTests {
0027 
0028 // fixed material
0029 static const Material material = makeSilicon();
0030 // variable values for other parameters
0031 // thickness
0032 static const double valuesThickness[] = {200_um, 1_mm};
0033 static auto thickness = data::make(valuesThickness);
0034 // particle type, mass, and charge
0035 static const PdgParticle pdg[] = {eElectron, eMuon, ePionPlus, eProton};
0036 static const double mass[] = {511_keV, 105.7_MeV, 139.6_MeV, 938.3_MeV};
0037 static const double charge[] = {-1_e, -1_e, 1_e, 1_e};
0038 static const auto particle =
0039     data::make(pdg) ^ data::make(mass) ^ data::make(charge);
0040 // momentum range
0041 static const auto momentum_low = data::xrange(100_MeV, 10_GeV, 100_MeV);
0042 static const auto momentum_med = data::xrange(10_GeV, 100_GeV, 10_GeV);
0043 static const auto momentum_high = data::xrange(100_GeV, 10_TeV, 100_GeV);
0044 static const auto momentum = momentum_low + momentum_med + momentum_high;
0045 
0046 BOOST_AUTO_TEST_SUITE(interactions)
0047 
0048 // Check the derivatives against the functions they differentiate, including
0049 // non-relativistic beta and either side of the density correction threshold.
0050 BOOST_AUTO_TEST_CASE(energy_loss_derivatives) {
0051   const MaterialSlab slab(material, 1_mm);
0052   for (float m : {105.7_MeV, 938.3_MeV}) {
0053     for (float betaGamma : {0.5f, 2.f, 5.f, 20.f, 100.f}) {
0054       for (float q : {-2.f, -1.f, 1.f, 2.f}) {
0055         const float qop = q / (m * betaGamma);
0056         const float absQ = std::abs(q);
0057         const float delta = std::abs(qop) * 1e-3f;
0058         const auto check = [&](auto value, auto derivative) {
0059           const double numerical =
0060               (value(qop + delta) - value(qop - delta)) / (2 * delta);
0061           // The material functions use float; scale the tolerance by the
0062           // loss rather than by a derivative that can vanish at the minimum.
0063           BOOST_CHECK_SMALL((derivative(qop) - numerical) * qop,
0064                             3e-4 * std::abs(value(qop)));
0065         };
0066         check([&](float l) { return computeEnergyLossBethe(slab, m, l, absQ); },
0067               [&](float l) {
0068                 return deriveEnergyLossBetheQOverP(slab, m, l, absQ);
0069               });
0070         check(
0071             [&](float l) { return computeEnergyLossLandau(slab, m, l, absQ); },
0072             [&](float l) {
0073               return deriveEnergyLossLandauQOverP(slab, m, l, absQ);
0074             });
0075         check(
0076             [&](float l) {
0077               return computeEnergyLossMean(slab, eMuon, m, l, absQ);
0078             },
0079             [&](float l) {
0080               return deriveEnergyLossMeanQOverP(slab, eMuon, m, l, absQ);
0081             });
0082         check(
0083             [&](float l) {
0084               return computeEnergyLossMode(slab, eMuon, m, l, absQ);
0085             },
0086             [&](float l) {
0087               return deriveEnergyLossModeQOverP(slab, eMuon, m, l, absQ);
0088             });
0089       }
0090     }
0091   }
0092 }
0093 
0094 // consistency checks for the energy loss values
0095 BOOST_DATA_TEST_CASE(energy_loss_consistency, thickness * particle * momentum,
0096                      x, i, m, q, p) {
0097   const auto slab = MaterialSlab(material, x);
0098   const auto qOverP = q / p;
0099   const auto absQ = std::abs(q);
0100   const auto absPdg = makeAbsolutePdgParticle(i);
0101 
0102   auto dEBethe = computeEnergyLossBethe(slab, m, qOverP, absQ);
0103   auto dELandau = computeEnergyLossLandau(slab, m, qOverP, absQ);
0104   auto dELandauSigma = computeEnergyLossLandauSigma(slab, m, qOverP, absQ);
0105   auto dELandauSigmaQOverP =
0106       computeEnergyLossLandauSigmaQOverP(slab, m, qOverP, absQ);
0107   auto dERad = computeEnergyLossRadiative(slab, absPdg, m, qOverP, absQ);
0108   auto dEMean = computeEnergyLossMean(slab, absPdg, m, qOverP, absQ);
0109   auto dEMode = computeEnergyLossMode(slab, absPdg, m, qOverP, absQ);
0110 
0111   BOOST_CHECK_LT(0, dEBethe);
0112   BOOST_CHECK_LT(0, dELandau);
0113   BOOST_CHECK_LT(0, dELandauSigma);
0114   BOOST_CHECK_LT(0, dELandauSigmaQOverP);
0115   BOOST_CHECK_LE(dELandauSigma, dEBethe);
0116   // radiative terms only kick above some threshold -> can be zero
0117   BOOST_CHECK_LE(0, dERad);
0118   BOOST_CHECK_LT(0, dEMean);
0119   BOOST_CHECK_LT(0, dEMode);
0120   BOOST_CHECK_LE((dEBethe + dERad), dEMean);
0121   // TODO verify mode/mean relation for full energy loss
0122   // BOOST_CHECK_LE(dEMode, dEMean);
0123 }
0124 
0125 // consistency checks for multiple scattering
0126 BOOST_DATA_TEST_CASE(multiple_scattering_consistency,
0127                      thickness * particle * momentum, x, i, m, q, p) {
0128   const auto slab = MaterialSlab(material, x);
0129   const auto slabDoubled = MaterialSlab(material, 2 * x);
0130   const auto qOverP = q / p;
0131   const auto qOver2P = q / (2 * p);
0132   const auto absQ = std::abs(q);
0133   const auto absPdg = makeAbsolutePdgParticle(i);
0134 
0135   auto t0 = computeMultipleScatteringTheta0(slab, absPdg, m, qOverP, absQ);
0136   BOOST_CHECK_LT(0, t0);
0137   // use the anti-particle -> same scattering
0138   auto tanti = computeMultipleScatteringTheta0(slab, absPdg, m, -qOverP, absQ);
0139   BOOST_CHECK_LT(0, tanti);
0140   BOOST_CHECK_EQUAL(t0, tanti);
0141   // double the material -> more scattering
0142   auto t2x =
0143       computeMultipleScatteringTheta0(slabDoubled, absPdg, m, qOverP, absQ);
0144   BOOST_CHECK_LT(0, t2x);
0145   BOOST_CHECK_LT(t0, t2x);
0146   // double the momentum -> less scattering
0147   auto t2p = computeMultipleScatteringTheta0(slab, absPdg, m, qOver2P, absQ);
0148   BOOST_CHECK_LT(0, t2p);
0149   BOOST_CHECK_LT(t2p, t0);
0150 }
0151 
0152 // no material -> no interactions
0153 BOOST_DATA_TEST_CASE(vacuum, thickness * particle * momentum, x, i, m, q, p) {
0154   const auto vacuum = MaterialSlab::Vacuum(x);
0155   const auto qOverP = q / p;
0156   const auto absQ = std::abs(q);
0157   const auto absPdg = makeAbsolutePdgParticle(i);
0158 
0159   BOOST_CHECK_EQUAL(computeEnergyLossBethe(vacuum, m, qOverP, absQ), 0);
0160   BOOST_CHECK_EQUAL(computeEnergyLossLandau(vacuum, m, qOverP, absQ), 0);
0161   BOOST_CHECK_EQUAL(computeEnergyLossLandauSigma(vacuum, m, qOverP, absQ), 0);
0162   BOOST_CHECK_EQUAL(computeEnergyLossLandauSigmaQOverP(vacuum, m, qOverP, absQ),
0163                     0);
0164   BOOST_CHECK_EQUAL(computeEnergyLossRadiative(vacuum, absPdg, m, qOverP, absQ),
0165                     0);
0166   BOOST_CHECK_EQUAL(computeEnergyLossMean(vacuum, absPdg, m, qOverP, absQ), 0);
0167   BOOST_CHECK_EQUAL(computeEnergyLossMode(vacuum, absPdg, m, qOverP, absQ), 0);
0168   BOOST_CHECK_EQUAL(
0169       computeMultipleScatteringTheta0(vacuum, absPdg, m, qOverP, absQ), 0);
0170 }
0171 
0172 // Silicon Bethe Energy Loss Validation
0173 // PDG value from https://pdg.lbl.gov/2022/AtomicNuclearProperties
0174 static const double momentum[] = {0.1003_GeV, 1.101_GeV, 10.11_GeV, 100.1_GeV};
0175 static const double energy_loss[] = {2.608, 1.803, 2.177, 2.451};
0176 
0177 BOOST_DATA_TEST_CASE(silicon_energy_loss,
0178                      data::make(momentum) ^ data::make(energy_loss), p, loss) {
0179   const Material silicon = makeSilicon();
0180   const auto thickness = 1_cm;
0181   const auto slab = MaterialSlab(silicon, thickness);
0182   const auto m = 105.7_MeV;
0183   const auto q = -1_e;
0184   const auto qOverP = q / p;
0185   const auto absQ = std::abs(q);
0186 
0187   // Difference is within 5% from PDG value
0188   BOOST_CHECK_CLOSE(computeEnergyLossBethe(slab, m, qOverP, absQ) / thickness /
0189                         slab.material().massDensity() / (1_MeV * 1_cm2 / 1_g),
0190                     loss, 5.);
0191 }
0192 
0193 // Silicon Landau Energy Loss Validation
0194 BOOST_AUTO_TEST_CASE(silicon_landau) {
0195   const Material silicon = makeSilicon();
0196   const auto thickness = 0.17_cm;
0197   const auto slab = MaterialSlab(silicon, thickness);
0198   const float m = 105.7_MeV;
0199   const float q = -1_e;
0200   const float qOverP = q / 10_GeV;
0201   const float absQ = std::abs(q);
0202 
0203   // Difference is within 5% from PDG value
0204   const auto dE = computeEnergyLossLandau(slab, m, qOverP, absQ) / 1_MeV;
0205   BOOST_CHECK_CLOSE(dE, 0.525, 5.);
0206 
0207   // Difference is within 10% from PDG value
0208   const auto fwhm = computeEnergyLossLandauFwhm(slab, m, qOverP, absQ) / 1_MeV;
0209   BOOST_CHECK_CLOSE(fwhm, 0.13, 10.);
0210 }
0211 
0212 BOOST_AUTO_TEST_SUITE_END()
0213 
0214 }  // namespace ActsTests