File indexing completed on 2025-12-16 09:25:29
0001
0002
0003
0004
0005
0006
0007
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
0031
0032 struct MockMakeChildren {
0033 template <typename generator_t>
0034 std::array<ActsFatras::Particle, 4> operator()(
0035 generator_t & , const MaterialSlab & ,
0036 ActsFatras::Particle & ) const {
0037
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
0048 struct MockEverything {
0049 bool operator()(const Particle & ) const { return true; }
0050 };
0051
0052
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
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
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
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
0093 f.parent.setAbsoluteMomentum(2_GeV);
0094 BOOST_CHECK(!process(f.generator, f.slab, f.parent, f.children));
0095
0096 BOOST_CHECK_EQUAL(f.children.size(), 8u);
0097 }
0098
0099 BOOST_AUTO_TEST_CASE(WithOutputSelector) {
0100 Fixture f;
0101
0102 ContinuousProcess<MockMakeChildren, MockEverything, MockHighP, MockEverything>
0103 process;
0104 process.selectOutputParticle.minP = 10_GeV;
0105
0106
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
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
0115 f.parent.setAbsoluteMomentum(2_GeV);
0116 BOOST_CHECK(process(f.generator, f.slab, f.parent, f.children));
0117
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
0128
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
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
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
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 }