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/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 /// 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::pair<double, double> generatePathLimits(
0035       generator_t& /*generator*/, const Particle& /*particle*/) const {
0036     return {0., 0.};
0037   }
0038 
0039   template <class generator_t>
0040   bool run(generator_t& /*generator*/, Particle& /*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 /// Mock particle selector that selects everything
0052 struct MockEverything {
0053   bool operator()(const Particle& /*particle*/) const { return true; }
0054 };
0055 
0056 /// Mock particle selector for particles with momenta equal or above 10GeV.
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 }  // namespace
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   // process should not abort
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   // above threshold should not abort
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   // on threshold should still not abort
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   // below threshold should abort and not run the process at all
0101   f.parent.setAbsoluteMomentum(2_GeV);
0102   BOOST_CHECK(!process.run(f.generator, f.parent, f.children));
0103   // process did not run -> no new children
0104   BOOST_CHECK_EQUAL(f.children.size(), 8u);
0105 }
0106 
0107 BOOST_AUTO_TEST_CASE(WithOutputSelector) {
0108   Fixture f;
0109   // explicit child selector so it does not default to the output selector
0110   PointLikeProcess<MockMakeChildren, MockEverything, MockHighP, MockEverything>
0111       process;
0112   process.selectOutputParticle.minP = 10_GeV;
0113 
0114   // above threshold should not abort
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   // on threshold should still not abort
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   // below threshold should abort but only after running the process
0123   f.parent.setAbsoluteMomentum(2_GeV);
0124   BOOST_CHECK(process.run(f.generator, f.parent, f.children));
0125   // process did still run -> new children
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   // all process should not abort regardless of child selection
0136   // select no daughters
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   // select highest daughter
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   // select all but the lowest daughter
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   // select all daughters
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 }  // namespace ActsTests