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/PointLikeProcess.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 {
0029
0030
0031
0032 struct MockMakeChildren {
0033 template <typename generator_t>
0034 std::pair<double, double> generatePathLimits(
0035 generator_t& , const Particle& ) const {
0036 return {0., 0.};
0037 }
0038
0039 template <class generator_t>
0040 bool run(generator_t& , Particle& ,
0041 std::vector<Particle>& generatedParticles) const {
0042 generatedParticles = {Particle().setAbsoluteMomentum(1_GeV),
0043 Particle().setAbsoluteMomentum(2_GeV),
0044 Particle().setAbsoluteMomentum(3_GeV),
0045 Particle().setAbsoluteMomentum(4_GeV)};
0046
0047 return true;
0048 }
0049 };
0050
0051
0052 struct MockEverything {
0053 bool operator()(const Particle& ) const { return true; }
0054 };
0055
0056
0057 struct MockHighP {
0058 double minP = 10_GeV;
0059
0060 bool operator()(const ActsFatras::Particle& particle) const {
0061 return (minP <= particle.absoluteMomentum());
0062 }
0063 };
0064
0065 struct Fixture {
0066 std::default_random_engine generator;
0067 MaterialSlab slab{ActsTests::makeBeryllium(), 1_mm};
0068 Particle parent = Particle().setAbsoluteMomentum(10_GeV);
0069 std::vector<Particle> children;
0070 };
0071
0072 }
0073
0074 namespace ActsTests {
0075
0076 BOOST_AUTO_TEST_SUITE(KernelSuite)
0077
0078 BOOST_AUTO_TEST_CASE(NoSelectors) {
0079 Fixture f;
0080 PointLikeProcess<MockMakeChildren, MockEverything, MockEverything> process{};
0081
0082
0083 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0084 BOOST_CHECK_EQUAL(f.children.size(), 4u);
0085 }
0086
0087 BOOST_AUTO_TEST_CASE(WithInputSelector) {
0088 Fixture f;
0089 PointLikeProcess<MockMakeChildren, MockHighP, MockEverything> process;
0090 process.selectInputParticle.minP = 10_GeV;
0091
0092
0093 f.parent.setAbsoluteMomentum(20_GeV);
0094 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0095 BOOST_CHECK_EQUAL(f.children.size(), 4u);
0096
0097 f.parent.setAbsoluteMomentum(10_GeV);
0098 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0099 BOOST_CHECK_EQUAL(f.children.size(), 8u);
0100
0101 f.parent.setAbsoluteMomentum(2_GeV);
0102 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0103
0104 BOOST_CHECK_EQUAL(f.children.size(), 8u);
0105 }
0106
0107 BOOST_AUTO_TEST_CASE(WithOutputSelector) {
0108 Fixture f;
0109
0110 PointLikeProcess<MockMakeChildren, MockEverything, MockHighP, MockEverything>
0111 process;
0112 process.selectOutputParticle.minP = 10_GeV;
0113
0114
0115 f.parent.setAbsoluteMomentum(20_GeV);
0116 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0117 BOOST_CHECK_EQUAL(f.children.size(), 4u);
0118
0119 f.parent.setAbsoluteMomentum(10_GeV);
0120 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0121 BOOST_CHECK_EQUAL(f.children.size(), 8u);
0122
0123 f.parent.setAbsoluteMomentum(2_GeV);
0124 BOOST_CHECK(process.run(f.generator, f.parent, f.children));
0125
0126 BOOST_CHECK_EQUAL(f.children.size(), 12u);
0127 }
0128
0129 BOOST_AUTO_TEST_CASE(WithChildSelector) {
0130 Fixture f;
0131 PointLikeProcess<MockMakeChildren, MockEverything, MockEverything, MockHighP>
0132 process;
0133 process.selectChildParticle.minP = 10_GeV;
0134
0135
0136
0137 process.selectChildParticle.minP = 5_GeV;
0138 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0139 BOOST_CHECK_EQUAL(f.children.size(), 0u);
0140
0141 process.selectChildParticle.minP = 3.5_GeV;
0142 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0143 BOOST_CHECK_EQUAL(f.children.size(), 1u);
0144
0145 process.selectChildParticle.minP = 1.5_GeV;
0146 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0147 BOOST_CHECK_EQUAL(f.children.size(), 4u);
0148
0149 process.selectChildParticle.minP = 0.5_GeV;
0150 BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0151 BOOST_CHECK_EQUAL(f.children.size(), 8u);
0152 }
0153
0154 BOOST_AUTO_TEST_SUITE_END()
0155
0156 }