Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:05

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/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 /// 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::array<ActsFatras::Particle, 4> operator()(
0034       generator_t & /*generator*/, const Acts::MaterialSlab & /*slab*/,
0035       ActsFatras::Particle & /*particle*/) const {
0036     // create daughter particles
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 /// Mock particle selector that selects everything
0047 struct MockEverything {
0048   bool operator()(const Particle & /*particle*/) const { return true; }
0049 };
0050 
0051 /// Mock particle selector for particles with momenta equal or above 10GeV.
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 }  // namespace
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   // process should not abort
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   // above threshold should not abort
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   // on threshold should still not abort
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   // below threshold should abort and not run the process at all
0094   f.parent.setAbsoluteMomentum(2_GeV);
0095   BOOST_CHECK(!process(f.generator, f.slab, f.parent, f.children));
0096   // process did not run -> no new children
0097   BOOST_CHECK_EQUAL(f.children.size(), 8u);
0098 }
0099 
0100 BOOST_AUTO_TEST_CASE(WithOutputSelector) {
0101   Fixture f;
0102   // explicit child selector so it does not default to the output selector
0103   ContinuousProcess<MockMakeChildren, MockEverything, MockHighP, MockEverything>
0104       process;
0105   process.selectOutputParticle.minP = 10_GeV;
0106 
0107   // above threshold should not abort
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   // on threshold should still not abort
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   // below threshold should abort but only after running the process
0116   f.parent.setAbsoluteMomentum(2_GeV);
0117   BOOST_CHECK(process(f.generator, f.slab, f.parent, f.children));
0118   // process did still run -> new children
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   // all process should not abort regardless of child selection
0129   // select no daughters
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   // select highest daughter
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   // select all but the lowest daughter
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   // select all daughters
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()