Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:04:31

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/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Material/MaterialSlab.hpp"
0013 #include "Acts/Tests/CommonHelpers/PredefinedMaterials.hpp"
0014 #include "ActsFatras/EventData/Barcode.hpp"
0015 #include "ActsFatras/EventData/Particle.hpp"
0016 #include "ActsFatras/Kernel/PointLikeProcess.hpp"
0017 
0018 #include <algorithm>
0019 #include <array>
0020 #include <iterator>
0021 #include <random>
0022 #include <vector>
0023 
0024 using namespace Acts::UnitLiterals;
0025 using namespace ActsFatras;
0026 
0027 namespace {
0028 
0029 /// A mock process that leaves the particle as-is and creates four daughter
0030 /// particles with momenta 1,2,3,4 GeV.
0031 struct MockMakeChildren {
0032   template <typename generator_t>
0033   std::pair<double, double> generatePathLimits(
0034       generator_t& /*generator*/, const Particle& /*particle*/) const {
0035     return {0., 0.};
0036   }
0037 
0038   template <class generator_t>
0039   bool run(generator_t& /*generator*/, Particle& /*particle*/,
0040            std::vector<Particle>& generatedParticles) const {
0041     generatedParticles = {Particle().setAbsoluteMomentum(1_GeV),
0042                           Particle().setAbsoluteMomentum(2_GeV),
0043                           Particle().setAbsoluteMomentum(3_GeV),
0044                           Particle().setAbsoluteMomentum(4_GeV)};
0045 
0046     return true;
0047   }
0048 };
0049 
0050 /// Mock particle selector that selects everything
0051 struct MockEverything {
0052   bool operator()(const Particle& /*particle*/) const { return true; }
0053 };
0054 
0055 /// Mock particle selector for particles with momenta equal or above 10GeV.
0056 struct MockHighP {
0057   double minP = 10_GeV;
0058 
0059   bool operator()(const ActsFatras::Particle& particle) const {
0060     return (minP <= particle.absoluteMomentum());
0061   }
0062 };
0063 
0064 struct Fixture {
0065   std::default_random_engine generator;
0066   Acts::MaterialSlab slab{Acts::Test::makeBeryllium(), 1_mm};
0067   Particle parent = Particle().setAbsoluteMomentum(10_GeV);
0068   std::vector<Particle> children;
0069 };
0070 
0071 }  // namespace
0072 
0073 BOOST_AUTO_TEST_SUITE(FatrasPointLikeProcess)
0074 
0075 BOOST_AUTO_TEST_CASE(NoSelectors) {
0076   Fixture f;
0077   PointLikeProcess<MockMakeChildren, MockEverything, MockEverything> process{};
0078 
0079   // process should not abort
0080   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0081   BOOST_CHECK_EQUAL(f.children.size(), 4u);
0082 }
0083 
0084 BOOST_AUTO_TEST_CASE(WithInputSelector) {
0085   Fixture f;
0086   PointLikeProcess<MockMakeChildren, MockHighP, MockEverything> process;
0087   process.selectInputParticle.minP = 10_GeV;
0088 
0089   // above threshold should not abort
0090   f.parent.setAbsoluteMomentum(20_GeV);
0091   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0092   BOOST_CHECK_EQUAL(f.children.size(), 4u);
0093   // on threshold should still not abort
0094   f.parent.setAbsoluteMomentum(10_GeV);
0095   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0096   BOOST_CHECK_EQUAL(f.children.size(), 8u);
0097   // below threshold should abort and not run the process at all
0098   f.parent.setAbsoluteMomentum(2_GeV);
0099   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0100   // process did not run -> no new children
0101   BOOST_CHECK_EQUAL(f.children.size(), 8u);
0102 }
0103 
0104 BOOST_AUTO_TEST_CASE(WithOutputSelector) {
0105   Fixture f;
0106   // explicit child selector so it does not default to the output selector
0107   PointLikeProcess<MockMakeChildren, MockEverything, MockHighP, MockEverything>
0108       process;
0109   process.selectOutputParticle.minP = 10_GeV;
0110 
0111   // above threshold should not abort
0112   f.parent.setAbsoluteMomentum(20_GeV);
0113   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0114   BOOST_CHECK_EQUAL(f.children.size(), 4u);
0115   // on threshold should still not abort
0116   f.parent.setAbsoluteMomentum(10_GeV);
0117   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0118   BOOST_CHECK_EQUAL(f.children.size(), 8u);
0119   // below threshold should abort but only after running the process
0120   f.parent.setAbsoluteMomentum(2_GeV);
0121   BOOST_CHECK(process.run(f.generator, f.parent, f.children));
0122   // process did still run -> new children
0123   BOOST_CHECK_EQUAL(f.children.size(), 12u);
0124 }
0125 
0126 BOOST_AUTO_TEST_CASE(WithChildSelector) {
0127   Fixture f;
0128   PointLikeProcess<MockMakeChildren, MockEverything, MockEverything, MockHighP>
0129       process;
0130   process.selectChildParticle.minP = 10_GeV;
0131 
0132   // all process should not abort regardless of child selection
0133   // select no daughters
0134   process.selectChildParticle.minP = 5_GeV;
0135   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0136   BOOST_CHECK_EQUAL(f.children.size(), 0u);
0137   // select highest daughter
0138   process.selectChildParticle.minP = 3.5_GeV;
0139   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0140   BOOST_CHECK_EQUAL(f.children.size(), 1u);
0141   // select all but the lowest daughter
0142   process.selectChildParticle.minP = 1.5_GeV;
0143   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0144   BOOST_CHECK_EQUAL(f.children.size(), 4u);
0145   // select all daughters
0146   process.selectChildParticle.minP = 0.5_GeV;
0147   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0148   BOOST_CHECK_EQUAL(f.children.size(), 8u);
0149 }
0150 
0151 BOOST_AUTO_TEST_SUITE_END()