Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:29

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