Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ContinuousProcessTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ContinuousProcessTests.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 
17 
18 #include <algorithm>
19 #include <array>
20 #include <iterator>
21 #include <random>
22 #include <vector>
23 
24 using namespace Acts::UnitLiterals;
25 using namespace ActsFatras;
26 
27 namespace {
28 
31 struct MockMakeChildren {
32  template <typename generator_t>
33  std::array<ActsFatras::Particle, 4> operator()(
34  generator_t & /*generator*/, const Acts::MaterialSlab & /*slab*/,
35  ActsFatras::Particle & /*particle*/) const {
36  // create daughter particles
37  return {
42  };
43  }
44 };
45 
47 struct MockEverything {
48  bool operator()(const Particle & /*particle*/) const { return true; }
49 };
50 
52 struct MockHighP {
53  double minP = 10_GeV;
54 
55  bool operator()(const ActsFatras::Particle &particle) const {
56  return (minP <= particle.absoluteMomentum());
57  }
58 };
59 
60 struct Fixture {
61  std::default_random_engine generator;
63  Particle parent = Particle().setAbsoluteMomentum(10_GeV);
64  std::vector<Particle> children;
65 };
66 
67 } // namespace
68 
69 BOOST_AUTO_TEST_SUITE(FatrasContinuousProcess)
70 
71 BOOST_AUTO_TEST_CASE(NoSelectors) {
72  Fixture f;
74 
75  // process should not abort
76  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
77  BOOST_CHECK_EQUAL(f.children.size(), 4u);
78 }
79 
80 BOOST_AUTO_TEST_CASE(WithInputSelector) {
81  Fixture f;
83  process.selectInputParticle.minP = 10_GeV;
84 
85  // above threshold should not abort
86  f.parent.setAbsoluteMomentum(20_GeV);
87  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
88  BOOST_CHECK_EQUAL(f.children.size(), 4u);
89  // on threshold should still not abort
90  f.parent.setAbsoluteMomentum(10_GeV);
91  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
92  BOOST_CHECK_EQUAL(f.children.size(), 8u);
93  // below threshold should abort and not run the process at all
94  f.parent.setAbsoluteMomentum(2_GeV);
95  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
96  // process did not run -> no new children
97  BOOST_CHECK_EQUAL(f.children.size(), 8u);
98 }
99 
100 BOOST_AUTO_TEST_CASE(WithOutputSelector) {
101  Fixture f;
102  // explicit child selector so it does not default to the output selector
104  process;
105  process.selectOutputParticle.minP = 10_GeV;
106 
107  // above threshold should not abort
108  f.parent.setAbsoluteMomentum(20_GeV);
109  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
110  BOOST_CHECK_EQUAL(f.children.size(), 4u);
111  // on threshold should still not abort
112  f.parent.setAbsoluteMomentum(10_GeV);
113  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
114  BOOST_CHECK_EQUAL(f.children.size(), 8u);
115  // below threshold should abort but only after running the process
116  f.parent.setAbsoluteMomentum(2_GeV);
117  BOOST_CHECK(process(f.generator, f.slab, f.parent, f.children));
118  // process did still run -> new children
119  BOOST_CHECK_EQUAL(f.children.size(), 12u);
120 }
121 
122 BOOST_AUTO_TEST_CASE(WithChildSelector) {
123  Fixture f;
125  process;
126  process.selectChildParticle.minP = 10_GeV;
127 
128  // all process should not abort regardless of child selection
129  // select no daughters
130  process.selectChildParticle.minP = 5_GeV;
131  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
132  BOOST_CHECK_EQUAL(f.children.size(), 0u);
133  // select highest daughter
134  process.selectChildParticle.minP = 3.5_GeV;
135  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
136  BOOST_CHECK_EQUAL(f.children.size(), 1u);
137  // select all but the lowest daughter
138  process.selectChildParticle.minP = 1.5_GeV;
139  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
140  BOOST_CHECK_EQUAL(f.children.size(), 4u);
141  // select all daughters
142  process.selectChildParticle.minP = 0.5_GeV;
143  BOOST_CHECK(not process(f.generator, f.slab, f.parent, f.children));
144  BOOST_CHECK_EQUAL(f.children.size(), 8u);
145 }
146 
147 BOOST_AUTO_TEST_SUITE_END()