File indexing completed on 2025-07-05 08:26:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Material/MaterialSlab.hpp"
0012 #include "ActsFatras/EventData/Particle.hpp"
0013
0014 #include <bitset>
0015 #include <tuple>
0016 #include <type_traits>
0017 #include <utility>
0018
0019 namespace ActsFatras {
0020 namespace detail {
0021
0022
0023
0024
0025 template <class T, class Tuple>
0026 struct TupleIndexOf;
0027 template <class T, class... Types>
0028 struct TupleIndexOf<T, std::tuple<T, Types...>> {
0029 static constexpr std::size_t value = 0u;
0030 };
0031 template <class T, class U, class... Types>
0032 struct TupleIndexOf<T, std::tuple<U, Types...>> {
0033 static constexpr std::size_t value =
0034 1u + TupleIndexOf<T, std::tuple<Types...>>::value;
0035 };
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 template <template <typename> typename predicate_t, typename tuple_t,
0055 std::size_t kCounter, std::size_t... kIndices>
0056 struct TupleFilterImpl {
0057 static constexpr auto kIndex = kCounter - 1u;
0058 static constexpr bool kElementSelection =
0059 predicate_t<std::tuple_element_t<kIndex, tuple_t>>::value;
0060
0061 using SelectElement = typename TupleFilterImpl<predicate_t, tuple_t, kIndex,
0062 kIndex, kIndices...>::Type;
0063
0064 using SkipElement =
0065 typename TupleFilterImpl<predicate_t, tuple_t, kIndex, kIndices...>::Type;
0066
0067 using Type =
0068 std::conditional_t<kElementSelection, SelectElement, SkipElement>;
0069 };
0070 template <template <typename> typename predicate_t, typename tuple_t,
0071 std::size_t... kIndices>
0072 struct TupleFilterImpl<predicate_t, tuple_t, 0u, kIndices...> {
0073 using Type = std::index_sequence<kIndices...>;
0074 };
0075 template <template <typename> typename predicate_t, typename tuple_t>
0076 using TupleFilter = typename TupleFilterImpl<predicate_t, tuple_t,
0077 std::tuple_size_v<tuple_t>>::Type;
0078
0079
0080
0081
0082 template <typename process_t>
0083 concept PointLikeProcessConcept = requires(
0084 const process_t& p, std::uniform_int_distribution<unsigned int>& rng,
0085 const Particle& prt) {
0086 {
0087 p.generatePathLimits(rng, prt)
0088 } -> std::same_as<std::pair<Particle::Scalar, Particle::Scalar>>;
0089 };
0090
0091 template <typename process_t>
0092 concept ContinuousProcessConcept = !PointLikeProcessConcept<process_t>;
0093
0094 template <typename process_t>
0095 struct PointLikeProcessTrait {
0096 static constexpr bool value = PointLikeProcessConcept<process_t>;
0097 };
0098
0099 template <typename process_t>
0100 struct ContinuousProcessTrait {
0101 static constexpr bool value = ContinuousProcessConcept<process_t>;
0102 };
0103
0104 template <typename processes_t>
0105 using ContinuousIndices = TupleFilter<ContinuousProcessTrait, processes_t>;
0106 template <typename processes_t>
0107 using PointLikeIndices = TupleFilter<PointLikeProcessTrait, processes_t>;
0108
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 template <typename... processes_t>
0171 class InteractionList {
0172 using Mask = std::bitset<sizeof...(processes_t)>;
0173 using Processes = std::tuple<processes_t...>;
0174 using ContinuousIndices = detail::ContinuousIndices<Processes>;
0175 using PointLikeIndices = detail::PointLikeIndices<Processes>;
0176
0177 public:
0178
0179 struct Selection {
0180 Particle::Scalar x0Limit =
0181 std::numeric_limits<Particle::Scalar>::infinity();
0182 Particle::Scalar l0Limit =
0183 std::numeric_limits<Particle::Scalar>::infinity();
0184 std::size_t x0Process = std::numeric_limits<std::size_t>::max();
0185 std::size_t l0Process = std::numeric_limits<std::size_t>::max();
0186 };
0187
0188
0189 void disable(std::size_t process) { m_mask.set(process); }
0190
0191
0192
0193
0194 template <typename process_t>
0195 void disable() {
0196 m_mask.set(detail::TupleIndexOf<process_t, Processes>::value);
0197 }
0198
0199
0200 template <std::size_t kProcess>
0201 std::tuple_element_t<kProcess, Processes>& get() {
0202 return std::get<kProcess>(m_processes);
0203 }
0204
0205
0206
0207
0208 template <typename process_t>
0209 process_t& get() {
0210 return std::get<process_t>(m_processes);
0211 }
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221 template <typename generator_t>
0222 bool runContinuous(generator_t& rng, const Acts::MaterialSlab& slab,
0223 Particle& particle,
0224 std::vector<Particle>& generated) const {
0225 return runContinuousImpl(rng, slab, particle, generated,
0226 ContinuousIndices());
0227 }
0228
0229
0230
0231
0232
0233
0234
0235
0236 template <typename generator_t>
0237 Selection armPointLike(generator_t& rng, const Particle& particle) const {
0238 Selection selection;
0239 armPointLikeImpl(rng, particle, selection, PointLikeIndices());
0240 return selection;
0241 }
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255 template <typename generator_t>
0256 bool runPointLike(generator_t& rng, std::size_t processIndex,
0257 Particle& particle,
0258 std::vector<Particle>& generated) const {
0259 return runPointLikeImpl(rng, processIndex, particle, generated,
0260 PointLikeIndices());
0261 }
0262
0263 private:
0264
0265 Mask m_mask;
0266 Processes m_processes;
0267
0268
0269
0270
0271 template <typename generator_t, std::size_t kI0, std::size_t... kIs>
0272 bool runContinuousImpl(generator_t& rng, const Acts::MaterialSlab& slab,
0273 Particle& particle, std::vector<Particle>& generated,
0274 std::index_sequence<kI0, kIs...> ) const {
0275 const auto& process = std::get<kI0>(m_processes);
0276
0277 if (!m_mask[kI0] && process(rng, slab, particle, generated)) {
0278
0279 return true;
0280 }
0281 return runContinuousImpl(rng, slab, particle, generated,
0282 std::index_sequence<kIs...>());
0283 }
0284 template <typename generator_t>
0285 bool runContinuousImpl(generator_t& ,
0286 const Acts::MaterialSlab& ,
0287 Particle& ,
0288 std::vector<Particle>& ,
0289 std::index_sequence<> ) const {
0290 return false;
0291 }
0292
0293
0294
0295
0296 template <typename generator_t, std::size_t kI0, std::size_t... kIs>
0297 void armPointLikeImpl(generator_t& rng, const Particle& particle,
0298 Selection& selection,
0299 std::index_sequence<kI0, kIs...> ) const {
0300
0301 if (!m_mask[kI0]) {
0302 auto [x0Limit, l0Limit] =
0303 std::get<kI0>(m_processes).generatePathLimits(rng, particle);
0304 if (x0Limit < selection.x0Limit) {
0305 selection.x0Limit = x0Limit;
0306 selection.x0Process = kI0;
0307 }
0308 if (l0Limit < selection.l0Limit) {
0309 selection.l0Limit = l0Limit;
0310 selection.l0Process = kI0;
0311 }
0312 }
0313
0314 armPointLikeImpl(rng, particle, selection, std::index_sequence<kIs...>());
0315 }
0316 template <typename generator_t>
0317 void armPointLikeImpl(generator_t& , const Particle& ,
0318 Selection& ,
0319 std::index_sequence<> ) const {}
0320
0321
0322
0323
0324
0325 template <typename generator_t, std::size_t kI0, std::size_t... kIs>
0326 bool runPointLikeImpl(generator_t& rng, std::size_t processIndex,
0327 Particle& particle, std::vector<Particle>& generated,
0328 std::index_sequence<kI0, kIs...> ) const {
0329 if (kI0 == processIndex) {
0330 if (m_mask[kI0]) {
0331
0332
0333 return false;
0334 }
0335 return std::get<kI0>(m_processes).run(rng, particle, generated);
0336 }
0337
0338 return runPointLikeImpl(rng, processIndex, particle, generated,
0339 std::index_sequence<kIs...>());
0340 }
0341 template <typename generator_t>
0342 bool runPointLikeImpl(generator_t& , std::size_t ,
0343 Particle& ,
0344 std::vector<Particle>& ,
0345 std::index_sequence<> ) const {
0346
0347
0348
0349 return false;
0350 }
0351 };
0352
0353 }