Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-28 07:12:10

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 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0013 #include "Acts/Propagator/ActorList.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015 #include "Acts/Utilities/Result.hpp"
0016 #include "ActsFatras/EventData/Particle.hpp"
0017 #include "ActsFatras/Kernel/SingleParticleSimulationResult.hpp"
0018 #include "ActsFatras/Kernel/detail/SimulationActor.hpp"
0019 
0020 #include <algorithm>
0021 #include <cassert>
0022 #include <memory>
0023 
0024 namespace ActsFatras {
0025 
0026 /// Single particle simulation with fixed propagator, interactions, and decay.
0027 ///
0028 /// @tparam generator_t random number generator
0029 /// @tparam interactions_t interaction list
0030 /// @tparam hit_surface_selector_t selector for hit surfaces
0031 /// @tparam decay_t decay module
0032 template <typename propagator_t, typename interactions_t,
0033           typename hit_surface_selector_t, typename decay_t>
0034 struct SingleParticleSimulation {
0035   /// How and within which geometry to propagate the particle.
0036   propagator_t propagator;
0037   /// Absolute maximum step size
0038   double maxStepSize = std::numeric_limits<double>::max();
0039   /// Absolute maximum path length
0040   double pathLimit = std::numeric_limits<double>::max();
0041   /// Decay module.
0042   decay_t decay;
0043   /// Interaction list containing the simulated interactions.
0044   interactions_t interactions;
0045   /// Selector for surfaces that should generate hits.
0046   hit_surface_selector_t selectHitSurface;
0047   /// Logger for debug output.
0048   std::unique_ptr<const Acts::Logger> logger;
0049 
0050   /// Alternatively construct the simulator with an external logger.
0051   /// @param propagator_ Propagator to use for particle simulation
0052   /// @param _logger Logger instance for debug output
0053   SingleParticleSimulation(propagator_t &&propagator_,
0054                            std::unique_ptr<const Acts::Logger> _logger)
0055       : propagator(propagator_), logger(std::move(_logger)) {}
0056 
0057   /// Simulate a single particle without secondaries.
0058   ///
0059   /// @tparam generator_t is the type of the random number generator
0060   ///
0061   /// @param geoCtx is the geometry context to access surface geometries
0062   /// @param magCtx is the magnetic field context to access field values
0063   /// @param generator is the random number generator
0064   /// @param particle is the initial particle state
0065   /// @returns Simulated particle state, hits, and generated particles.
0066   template <typename generator_t>
0067   Acts::Result<SingleParticleSimulationResult> simulate(
0068       const Acts::GeometryContext &geoCtx,
0069       const Acts::MagneticFieldContext &magCtx, generator_t &generator,
0070       const Particle &particle) const {
0071     // propagator-related additional types
0072     using Actor = detail::SimulationActor<generator_t, decay_t, interactions_t,
0073                                           hit_surface_selector_t>;
0074     using Result = typename Actor::result_type;
0075     using ActorList = Acts::ActorList<Actor>;
0076     using PropagatorOptions =
0077         typename propagator_t::template Options<ActorList>;
0078 
0079     // Construct per-call options.
0080     PropagatorOptions options(geoCtx, magCtx);
0081     options.stepping.maxStepSize = maxStepSize;
0082     options.pathLimit = pathLimit;
0083     // setup the interactor as part of the propagator options
0084     auto &actor = options.actorList.template get<Actor>();
0085     actor.generator = &generator;
0086     actor.decay = decay;
0087     actor.interactions = interactions;
0088     actor.selectHitSurface = selectHitSurface;
0089     actor.initialParticle = particle;
0090 
0091     if (particle.hasReferenceSurface()) {
0092       auto result = propagator.propagate(
0093           particle.boundParameters(geoCtx).value(), options);
0094       if (!result.ok()) {
0095         return result.error();
0096       }
0097       auto &value = result.value().template get<Result>();
0098       return std::move(value);
0099     }
0100 
0101     auto result =
0102         propagator.propagate(particle.curvilinearParameters(), options);
0103     if (!result.ok()) {
0104       return result.error();
0105     }
0106     auto &value = result.value().template get<Result>();
0107     return std::move(value);
0108   }
0109 };
0110 
0111 }  // namespace ActsFatras