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