ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProcessTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ProcessTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
11 #include <array>
12 #include <random>
13 
16 #include "Acts/Utilities/Units.hpp"
19 
20 using namespace Acts::UnitLiterals;
21 using namespace ActsFatras;
22 
23 namespace {
26 struct MakeChildren {
27  template <typename generator_t>
28  std::array<ActsFatras::Particle, 4> operator()(
29  generator_t &, const Acts::MaterialProperties &,
30  ActsFatras::Particle &) const {
31  // create daughter particles
32  return {
37  };
38  }
39 };
40 
42 struct HighP {
43  double minP = 10_GeV;
44 
45  bool operator()(const ActsFatras::Particle &particle) const {
46  return (minP <= particle.absMomentum());
47  }
48 };
49 
50 struct Fixture {
51  std::default_random_engine generator;
53  Particle parent = Particle().setAbsMomentum(10_GeV);
54  std::vector<Particle> children;
55 };
56 } // namespace
57 
58 BOOST_AUTO_TEST_SUITE(FatrasProcess)
59 
60 BOOST_AUTO_TEST_CASE(NoSelectors) {
61  Fixture f;
62  Process<MakeChildren> process;
63 
64  // process should not abort
65  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
66  BOOST_TEST(f.children.size() == 4u);
67 }
68 
69 BOOST_AUTO_TEST_CASE(WithInputSelector) {
70  Fixture f;
72  process.selectInput.minP = 10_GeV;
73 
74  // above threshold should not abort
75  f.parent.setAbsMomentum(20_GeV);
76  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
77  BOOST_TEST(f.children.size() == 4u);
78  // on threshold should still not abort
79  f.parent.setAbsMomentum(10_GeV);
80  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
81  BOOST_TEST(f.children.size() == 8u);
82  // below threshold should abort and not run the process at all
83  f.parent.setAbsMomentum(2_GeV);
84  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
85  // process did not run -> no new children
86  BOOST_TEST(f.children.size() == 8u);
87 }
88 
89 BOOST_AUTO_TEST_CASE(WithOutputSelector) {
90  Fixture f;
92  process.selectOutputParticle.minP = 10_GeV;
93 
94  // above threshold should not abort
95  f.parent.setAbsMomentum(20_GeV);
96  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
97  BOOST_TEST(f.children.size() == 4u);
98  // on threshold should still not abort
99  f.parent.setAbsMomentum(10_GeV);
100  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
101  BOOST_TEST(f.children.size() == 8u);
102  // below threshold should abort but only after running the process
103  f.parent.setAbsMomentum(2_GeV);
104  BOOST_TEST(process(f.generator, f.slab, f.parent, f.children));
105  // process did still run -> new children
106  BOOST_TEST(f.children.size() == 12u);
107 }
108 
109 BOOST_AUTO_TEST_CASE(WithChildSelector) {
110  Fixture f;
112  process.selectChildParticle.minP = 10_GeV;
113 
114  // all process should not abort regardless of child selection
115  // select no daughters
116  process.selectChildParticle.minP = 5_GeV;
117  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
118  BOOST_TEST(f.children.size() == 0u);
119  // select highest daughter
120  process.selectChildParticle.minP = 3.5_GeV;
121  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
122  BOOST_TEST(f.children.size() == 1u);
123  // select all but the lowest daughter
124  process.selectChildParticle.minP = 1.5_GeV;
125  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
126  BOOST_TEST(f.children.size() == 4u);
127  // select all daughters
128  process.selectChildParticle.minP = 0.5_GeV;
129  BOOST_TEST(not process(f.generator, f.slab, f.parent, f.children));
130  BOOST_TEST(f.children.size() == 8u);
131 }
132 
133 BOOST_AUTO_TEST_SUITE_END()