Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-01 09:22:16

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/Material/Interactions.hpp"
0014 #include "ActsFatras/EventData/Particle.hpp"
0015 #include "ActsFatras/Physics/ElectroMagnetic/Scattering.hpp"
0016 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0017 #include "ActsTests/CommonHelpers/PredefinedMaterials.hpp"
0018 
0019 #include <algorithm>
0020 #include <cmath>
0021 #include <cstdint>
0022 #include <limits>
0023 #include <numbers>
0024 #include <random>
0025 
0026 #include "Dataset.hpp"
0027 
0028 namespace ActsTests {
0029 
0030 constexpr auto eps = std::numeric_limits<double>::epsilon();
0031 
0032 double rms(const std::vector<double>& values, double mean) {
0033   return std::sqrt(std::accumulate(values.begin(), values.end(), 0.0,
0034                                    [mean](double sum, double value) {
0035                                      return sum +
0036                                             (value - mean) * (value - mean);
0037                                    }) /
0038                    values.size());
0039 }
0040 
0041 // Common test method that will be instantiated for each scattering model.
0042 template <typename Scattering>
0043 void test(const Scattering& scattering, std::uint32_t seed,
0044           const ActsFatras::Particle& before) {
0045   std::ranlux48 gen(seed);
0046   ActsFatras::Particle after = before;
0047 
0048   const auto outgoing = scattering(gen, makePercentSlab(), after);
0049   // scattering leaves absolute energy/momentum unchanged
0050   CHECK_CLOSE_REL(after.absoluteMomentum(), before.absoluteMomentum(), eps);
0051   CHECK_CLOSE_REL(after.energy(), before.energy(), eps);
0052   // Compare directions directly: the cosine of a tiny scattering angle can
0053   // round to one even when the directions differ.
0054   BOOST_CHECK_GT((before.direction() - after.direction()).norm(), 0.0);
0055   // scattering creates no new particles
0056   BOOST_CHECK(outgoing.empty());
0057 }
0058 
0059 BOOST_AUTO_TEST_SUITE(PhysicsSuite)
0060 
0061 BOOST_DATA_TEST_CASE(GeneralMixture, Dataset::parameters, pdg, phi, theta, p,
0062                      seed) {
0063   test(ActsFatras::GeneralMixtureScattering(), seed,
0064        Dataset::makeParticle(pdg, phi, theta, p));
0065 }
0066 
0067 BOOST_DATA_TEST_CASE(GaussianMixture, Dataset::parameters, pdg, phi, theta, p,
0068                      seed) {
0069   test(ActsFatras::GaussianMixtureScattering(), seed,
0070        Dataset::makeParticle(pdg, phi, theta, p));
0071 }
0072 
0073 BOOST_DATA_TEST_CASE(Highland, Dataset::parameters, pdg, phi, theta, p, seed) {
0074   test(ActsFatras::HighlandScattering(), seed,
0075        Dataset::makeParticle(pdg, phi, theta, p));
0076 }
0077 
0078 BOOST_AUTO_TEST_CASE(HighlandRms) {
0079   auto scattering = ActsFatras::HighlandScattering();
0080   auto particle = Dataset::makeParticle(Acts::PdgParticle::eMuon, 0, 0, 1);
0081   auto materialSlab = makePercentSlab();
0082 
0083   auto theta0 = Acts::computeMultipleScatteringTheta0(
0084       materialSlab, particle.absolutePdg(), particle.mass(), particle.qOverP(),
0085       particle.absoluteCharge());
0086 
0087   std::ranlux48 gen(0);
0088 
0089   std::vector<double> thetaYZs;
0090   std::vector<double> theta3Ds;
0091 
0092   for (std::size_t i = 0; i < 10000; i++) {
0093     auto newParticle = particle;
0094     scattering(gen, materialSlab, newParticle);
0095 
0096     double thetaYZ =
0097         std::atan2(newParticle.direction().y(), newParticle.direction().z());
0098     double theta3d =
0099         std::acos(newParticle.direction().dot(particle.direction()));
0100 
0101     thetaYZs.push_back(thetaYZ);
0102     theta3Ds.push_back(theta3d);
0103   }
0104 
0105   double rmsThetaYZ = rms(thetaYZs, 0);
0106   double rmsTheta3D = rms(theta3Ds, 0);
0107 
0108   CHECK_CLOSE_REL(rmsThetaYZ, theta0, 0.02);
0109   CHECK_CLOSE_REL(rmsTheta3D, std::numbers::sqrt2 * theta0, 0.02);
0110 }
0111 
0112 BOOST_AUTO_TEST_CASE(GeneralMixtureCoreWidth) {
0113   auto scattering = ActsFatras::GeneralMixtureScattering();
0114   auto particle = Dataset::makeParticle(Acts::PdgParticle::eMuon, 0, 0, 1);
0115   auto materialSlab = makePercentSlab();
0116 
0117   auto theta0 = Acts::computeMultipleScatteringTheta0(
0118       materialSlab, particle.absolutePdg(), particle.mass(), particle.qOverP(),
0119       particle.absoluteCharge());
0120 
0121   std::ranlux48 gen(0);
0122 
0123   std::vector<double> thetaYZs;
0124   for (std::size_t i = 0; i < 10000; i++) {
0125     auto newParticle = particle;
0126     scattering(gen, materialSlab, newParticle);
0127     thetaYZs.push_back(
0128         std::atan2(newParticle.direction().y(), newParticle.direction().z()));
0129   }
0130 
0131   // the mixture has non-Gaussian tails, so compare the width of the central
0132   // 68 % of the projected angle to the Highland width
0133   std::ranges::sort(thetaYZs);
0134   double q68 = 0.5 * (thetaYZs[static_cast<std::size_t>(0.8413 * 10000)] -
0135                       thetaYZs[static_cast<std::size_t>(0.1587 * 10000)]);
0136 
0137   CHECK_CLOSE_REL(q68, theta0, 0.2);
0138 }
0139 
0140 BOOST_AUTO_TEST_SUITE_END()
0141 
0142 }  // namespace ActsTests