Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:06

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/Algebra.hpp"
0013 #include "Acts/Definitions/Common.hpp"
0014 #include "Acts/Definitions/PdgParticle.hpp"
0015 #include "Acts/Definitions/Units.hpp"
0016 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0017 #include "ActsFatras/EventData/Particle.hpp"
0018 #include "ActsFatras/Physics/ElectroMagnetic/PhotonConversion.hpp"
0019 
0020 #include <cmath>
0021 #include <limits>
0022 #include <memory>
0023 #include <random>
0024 #include <utility>
0025 #include <vector>
0026 
0027 #include "Dataset.hpp"
0028 
0029 using Generator = std::ranlux48;
0030 
0031 BOOST_AUTO_TEST_SUITE(FatrasPhotonConversion)
0032 
0033 BOOST_DATA_TEST_CASE(NoPhoton, Dataset::parametersPhotonConversion, phi, theta,
0034                      seed) {
0035   using namespace Acts::UnitLiterals;
0036 
0037   Generator gen(seed);
0038 
0039   /// Produce not a photon
0040   ActsFatras::Particle particle =
0041       Dataset::makeParticle(Acts::PdgParticle::eElectron, phi, theta, 1_GeV);
0042   ActsFatras::Particle particleInit = particle;
0043 
0044   ActsFatras::PhotonConversion pc;
0045 
0046   // No limits should be set
0047   std::pair<double, double> limits;
0048   limits = pc.generatePathLimits(gen, particle);
0049   BOOST_CHECK_EQUAL(limits.first, std::numeric_limits<double>::infinity());
0050   BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<double>::infinity());
0051 
0052   // No particles should be generated
0053   std::vector<ActsFatras::Particle> generated;
0054   BOOST_CHECK(!pc.run(gen, particle, generated));
0055   BOOST_CHECK(generated.empty());
0056   // Particle shouldn't be modified
0057   BOOST_CHECK_EQUAL(particle.fourPosition(), particleInit.fourPosition());
0058   BOOST_CHECK_EQUAL(particle.fourMomentum(), particleInit.fourMomentum());
0059   BOOST_CHECK_EQUAL(particle.process(), particleInit.process());
0060   BOOST_CHECK_EQUAL(particle.properTime(), particleInit.properTime());
0061   BOOST_CHECK_EQUAL(particle.pathInX0(), particleInit.pathInX0());
0062   BOOST_CHECK_EQUAL(particle.pathInL0(), particleInit.pathInL0());
0063 }
0064 
0065 BOOST_DATA_TEST_CASE(DeadPhoton, Dataset::parametersPhotonConversion, phi,
0066                      theta, seed) {
0067   using namespace Acts::UnitLiterals;
0068 
0069   Generator gen(seed);
0070 
0071   /// Produce a dead photon
0072   ActsFatras::Particle particle =
0073       Dataset::makeParticle(Acts::PdgParticle::eGamma, phi, theta, 0);
0074   ActsFatras::Particle particleInit = particle;
0075 
0076   ActsFatras::PhotonConversion pc;
0077 
0078   // No limits should be set - momentum too low
0079   std::pair<double, double> limits = pc.generatePathLimits(gen, particle);
0080   BOOST_CHECK_EQUAL(limits.first, std::numeric_limits<double>::infinity());
0081   BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<double>::infinity());
0082 
0083   // No particles should be generated - momentum too low
0084   std::vector<ActsFatras::Particle> generated;
0085   BOOST_CHECK(!pc.run(gen, particle, generated));
0086   BOOST_CHECK(generated.empty());
0087   // Particle shouldn't be modified
0088   BOOST_CHECK_EQUAL(particle.fourPosition(), particleInit.fourPosition());
0089   BOOST_CHECK_EQUAL(particle.fourMomentum(), particleInit.fourMomentum());
0090   BOOST_CHECK_EQUAL(particle.process(), particleInit.process());
0091   BOOST_CHECK_EQUAL(particle.properTime(), particleInit.properTime());
0092   BOOST_CHECK_EQUAL(particle.pathInX0(), particleInit.pathInX0());
0093   BOOST_CHECK_EQUAL(particle.pathInL0(), particleInit.pathInL0());
0094 }
0095 
0096 BOOST_DATA_TEST_CASE(LowMomentumPhoton, Dataset::parametersPhotonConversion,
0097                      phi, theta, seed) {
0098   using namespace Acts::UnitLiterals;
0099 
0100   Generator gen(seed);
0101 
0102   /// Produce a low momentum photon
0103   ActsFatras::Particle particle =
0104       Dataset::makeParticle(Acts::PdgParticle::eGamma, phi, theta, 1_keV);
0105   ActsFatras::Particle particleInit = particle;
0106 
0107   ActsFatras::PhotonConversion pc;
0108 
0109   // No limits should be set - momentum too low
0110   std::pair<double, double> limits = pc.generatePathLimits(gen, particle);
0111   BOOST_CHECK_EQUAL(limits.first, std::numeric_limits<double>::infinity());
0112   BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<double>::infinity());
0113 
0114   // No particles should be generated - momentum too low
0115   std::vector<ActsFatras::Particle> generated;
0116   BOOST_CHECK(!pc.run(gen, particle, generated));
0117   BOOST_CHECK(generated.empty());
0118   // Particle shouldn't be modified
0119   BOOST_CHECK_EQUAL(particle.fourPosition(), particleInit.fourPosition());
0120   BOOST_CHECK_EQUAL(particle.fourMomentum(), particleInit.fourMomentum());
0121   BOOST_CHECK_EQUAL(particle.process(), particleInit.process());
0122   BOOST_CHECK_EQUAL(particle.properTime(), particleInit.properTime());
0123   BOOST_CHECK_EQUAL(particle.pathInX0(), particleInit.pathInX0());
0124   BOOST_CHECK_EQUAL(particle.pathInL0(), particleInit.pathInL0());
0125 }
0126 
0127 BOOST_DATA_TEST_CASE(HighMomentumPhoton, Dataset::parametersPhotonConversion,
0128                      phi, theta, seed) {
0129   using namespace Acts::UnitLiterals;
0130 
0131   Generator gen(seed);
0132 
0133   /// Produce a high momentum photon
0134   ActsFatras::Particle particle =
0135       Dataset::makeParticle(Acts::PdgParticle::eGamma, phi, theta, 1_GeV);
0136   ActsFatras::Particle particleInit = particle;
0137 
0138   ActsFatras::PhotonConversion pc;
0139 
0140   // No limits should be set - momentum too low
0141   std::pair<double, double> limits = pc.generatePathLimits(gen, particle);
0142   BOOST_CHECK_NE(limits.first, std::numeric_limits<double>::infinity());
0143   BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<double>::infinity());
0144 
0145   // No particles should be generated - momentum too low
0146   std::vector<ActsFatras::Particle> generated;
0147   BOOST_CHECK(pc.run(gen, particle, generated));
0148   BOOST_CHECK_EQUAL(generated.size(), 2);
0149 
0150   // Test the children
0151   BOOST_CHECK((generated[0].pdg() == Acts::PdgParticle::eElectron) ||
0152               (generated[0].pdg() == Acts::PdgParticle::ePositron));
0153   BOOST_CHECK((generated[1].pdg() == Acts::PdgParticle::eElectron) ||
0154               (generated[1].pdg() == Acts::PdgParticle::ePositron));
0155   BOOST_CHECK_NE(generated[0].pdg(), generated[1].pdg());
0156   BOOST_CHECK_NE(generated[0].fourMomentum(), Acts::Vector4::Zero());
0157   BOOST_CHECK_NE(generated[1].fourMomentum(), Acts::Vector4::Zero());
0158 
0159   // Test for similar invariant masses
0160   Acts::Vector4 momSum =
0161       generated[0].fourMomentum() + generated[1].fourMomentum();
0162   Acts::Vector3 momVector = momSum.template segment<3>(Acts::eMom0);
0163   double sSum = momSum[Acts::eEnergy] * momSum[Acts::eEnergy] -
0164                 momVector.norm() * momVector.norm();
0165   BOOST_CHECK(std::isfinite(sSum));
0166 
0167   double sParticle =
0168       particleInit.energy() * particleInit.energy() -
0169       particleInit.absoluteMomentum() * particleInit.absoluteMomentum();
0170   BOOST_CHECK(std::isfinite(sParticle));
0171   CHECK_CLOSE_OR_SMALL(sSum, sParticle, 1e-2, 1e-2);
0172 }
0173 
0174 BOOST_AUTO_TEST_SUITE_END()