Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:54:47

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/optical/OpticalCollector.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include "corecel/data/AuxInterface.hh"
0012 #include "celeritas/Types.hh"
0013 
0014 #include "Model.hh"
0015 #include "OffloadData.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 class ActionRegistry;
0021 class AuxStateVec;
0022 class CoreParams;
0023 
0024 namespace optical
0025 {
0026 class CherenkovParams;
0027 class MaterialParams;
0028 class ScintillationParams;
0029 }  // namespace optical
0030 
0031 namespace detail
0032 {
0033 class CherenkovOffloadAction;
0034 class CherenkovGeneratorAction;
0035 class OffloadGatherAction;
0036 class OpticalLaunchAction;
0037 class OffloadParams;
0038 class ScintOffloadAction;
0039 class ScintGeneratorAction;
0040 }  // namespace detail
0041 
0042 //---------------------------------------------------------------------------//
0043 /*!
0044  * Generate and track optical photons.
0045  *
0046  * This class is the interface between the main stepping loop and the photon
0047  * stepping loop and constructs kernel actions for:
0048  * - gathering the pre-step data needed to generate the optical distributions,
0049  * - generating the scintillation and Cherenkov optical distributions at the
0050  *   end of the step, and
0051  * - launching the photon stepping loop.
0052  *
0053  * The photon stepping loop will then generate optical primaries.
0054  *
0055  * The "collector" (TODO: rename?) will "own" the optical state data and
0056  * optical params since it's the only thing that launches the optical stepping
0057  * loop.
0058  *
0059  * \todo This doesn't do anything but set up the optical tracking loop: move to
0060  * \c setup namespace
0061  */
0062 class OpticalCollector
0063 {
0064   public:
0065     //!@{
0066     //! \name Type aliases
0067     using SPConstCherenkov = std::shared_ptr<optical::CherenkovParams const>;
0068     using SPConstMaterial = std::shared_ptr<optical::MaterialParams const>;
0069     using SPConstScintillation
0070         = std::shared_ptr<optical::ScintillationParams const>;
0071     using OpticalBufferSize = OpticalOffloadCounters<size_type>;
0072     //!@}
0073 
0074     struct Input
0075     {
0076         //! Optical physics models
0077         std::vector<optical::Model::ModelBuilder> model_builders;
0078 
0079         //! Optical physics material for materials
0080         SPConstMaterial material;
0081         SPConstCherenkov cherenkov;
0082         SPConstScintillation scintillation;
0083 
0084         //! Number track slots in the optical loop
0085         size_type num_track_slots{};
0086 
0087         //! Number of steps that have created optical particles
0088         size_type buffer_capacity{};
0089 
0090         //! Maximum number of buffered initializers in optical tracking loop
0091         size_type initializer_capacity{};
0092 
0093         //! Threshold number of initializers for launching optical loop
0094         size_type auto_flush{};
0095 
0096         //! True if all input is assigned and valid
0097         explicit operator bool() const
0098         {
0099             return material && (scintillation || cherenkov)
0100                    && num_track_slots > 0 && buffer_capacity > 0
0101                    && initializer_capacity > 0 && auto_flush > 0
0102                    && !model_builders.empty();
0103         }
0104     };
0105 
0106   public:
0107     // Construct with core data and optical params
0108     OpticalCollector(CoreParams const&, Input&&);
0109 
0110     // Aux ID for optical offload data
0111     AuxId offload_aux_id() const;
0112 
0113     // Aux ID for optical state data
0114     AuxId optical_aux_id() const;
0115 
0116     // Get and reset cumulative statistics on optical tracks from a state
0117     OpticalAccumStats exchange_counters(AuxStateVec& aux) const;
0118 
0119     // Get queued buffer sizes
0120     OpticalBufferSize const& buffer_counts(AuxStateVec const& aux) const;
0121 
0122   private:
0123     //// TYPES ////
0124 
0125     using SPOffloadParams = std::shared_ptr<detail::OffloadParams>;
0126     using SPCherenkovAction = std::shared_ptr<detail::CherenkovOffloadAction>;
0127     using SPScintAction = std::shared_ptr<detail::ScintOffloadAction>;
0128     using SPGatherAction = std::shared_ptr<detail::OffloadGatherAction>;
0129     using SPCherenkovGenAction
0130         = std::shared_ptr<detail::CherenkovGeneratorAction>;
0131     using SPScintGenAction = std::shared_ptr<detail::ScintGeneratorAction>;
0132     using SPLaunchAction = std::shared_ptr<detail::OpticalLaunchAction>;
0133 
0134     //// DATA ////
0135 
0136     SPOffloadParams offload_params_;
0137 
0138     SPGatherAction gather_action_;
0139     SPCherenkovAction cherenkov_action_;
0140     SPScintAction scint_action_;
0141     SPCherenkovGenAction cherenkov_gen_action_;
0142     SPScintGenAction scint_gen_action_;
0143     SPLaunchAction launch_action_;
0144 };
0145 
0146 //---------------------------------------------------------------------------//
0147 }  // namespace celeritas