Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-05 08:34:08

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 #include <optional>
0011 
0012 #include "corecel/io/Label.hh"
0013 #include "corecel/math/NumericLimits.hh"
0014 #include "celeritas/Types.hh"
0015 #include "celeritas/phys/GeneratorCounters.hh"
0016 #include "celeritas/phys/GeneratorRegistry.hh"
0017 
0018 #include "Model.hh"
0019 #include "gen/OffloadData.hh"
0020 #include "gen/detail/GeneratorTraits.hh"
0021 
0022 namespace celeritas
0023 {
0024 //---------------------------------------------------------------------------//
0025 class ActionRegistry;
0026 class AuxStateVec;
0027 class CherenkovParams;
0028 class CoreParams;
0029 class ScintillationParams;
0030 
0031 namespace optical
0032 {
0033 class MaterialParams;
0034 }  // namespace optical
0035 
0036 namespace detail
0037 {
0038 template<GeneratorType G>
0039 class GeneratorAction;
0040 template<GeneratorType G>
0041 class OffloadAction;
0042 class OffloadGatherAction;
0043 class OpticalLaunchAction;
0044 }  // namespace detail
0045 
0046 //---------------------------------------------------------------------------//
0047 /*!
0048  * Generate and track optical photons.
0049  *
0050  * This class is the interface between the main stepping loop and the photon
0051  * stepping loop and constructs kernel actions for:
0052  * - gathering the pre-step data needed to generate the optical distributions,
0053  * - generating the scintillation and Cherenkov optical distributions at the
0054  *   end of the step, and
0055  * - launching the photon stepping loop.
0056  *
0057  * The photon stepping loop will then generate optical primaries.
0058  *
0059  * The "collector" (TODO: rename?) will "own" the optical state data and
0060  * optical params since it's the only thing that launches the optical stepping
0061  * loop.
0062  *
0063  * \todo This doesn't do anything but set up the optical tracking loop: move to
0064  * \c setup namespace
0065  */
0066 class OpticalCollector
0067 {
0068   public:
0069     //!@{
0070     //! \name Type aliases
0071     using SPConstCherenkov = std::shared_ptr<CherenkovParams const>;
0072     using SPConstMaterial = std::shared_ptr<optical::MaterialParams const>;
0073     using SPConstScintillation = std::shared_ptr<ScintillationParams const>;
0074     using OpticalBufferSize = GeneratorCounters<size_type>;
0075     using SPConstOpticalParams = std::shared_ptr<optical::CoreParams const>;
0076     //!@}
0077 
0078     struct Input
0079     {
0080         //! Optical physics models
0081         std::vector<optical::Model::ModelBuilder> model_builders;
0082 
0083         //! Optical physics material for materials
0084         SPConstMaterial material;
0085         SPConstCherenkov cherenkov;
0086         SPConstScintillation scintillation;
0087 
0088         std::optional<std::vector<Label>> detector_labels;
0089 
0090         //! Number track slots in the optical loop
0091         size_type num_track_slots{};
0092 
0093         //! Number of steps that have created optical particles
0094         size_type buffer_capacity{};
0095 
0096         //! Threshold number of photons for launching optical loop
0097         size_type auto_flush{};
0098 
0099         //! Maximum step iterations before aborting optical loop
0100         size_type max_step_iters{numeric_limits<size_type>::max()};
0101 
0102         //! True if all input is assigned and valid
0103         explicit operator bool() const
0104         {
0105             return material && (scintillation || cherenkov)
0106                    && num_track_slots > 0 && buffer_capacity > 0
0107                    && auto_flush > 0 && !model_builders.empty();
0108         }
0109     };
0110 
0111   public:
0112     // Construct with core data and optical params
0113     OpticalCollector(CoreParams const&, Input&&);
0114 
0115     //// ACCESSORS ////
0116 
0117     //! Access optical params
0118     SPConstOpticalParams const& optical_params() const
0119     {
0120         return optical_params_;
0121     }
0122 
0123     // Access Cherenkov params (may be null)
0124     SPConstCherenkov cherenkov() const;
0125 
0126     // Access scintillation params (may be null)
0127     SPConstScintillation scintillation() const;
0128 
0129     //// GENERATOR MANAGEMENT ////
0130 
0131     // Get the generator registry
0132     GeneratorRegistry const& gen_reg() const;
0133 
0134     // Get and reset cumulative statistics on optical tracks from a state
0135     OpticalAccumStats exchange_counters(AuxStateVec& aux) const;
0136 
0137     // Get queued buffer sizes
0138     OpticalBufferSize buffer_counts(AuxStateVec const& aux) const;
0139 
0140   private:
0141     //// TYPES ////
0142 
0143     using GT = detail::GeneratorType;
0144     template<GT G>
0145     using GeneratorAction = detail::GeneratorAction<G>;
0146     template<GT G>
0147     using OffloadAction = detail::OffloadAction<G>;
0148     using SPCherenkovOffload = std::shared_ptr<OffloadAction<GT::cherenkov>>;
0149     using SPScintOffload = std::shared_ptr<OffloadAction<GT::scintillation>>;
0150     using SPGatherAction = std::shared_ptr<detail::OffloadGatherAction>;
0151     using SPCherenkovGen = std::shared_ptr<GeneratorAction<GT::cherenkov>>;
0152     using SPScintGen = std::shared_ptr<GeneratorAction<GT::scintillation>>;
0153     using SPLaunchAction = std::shared_ptr<detail::OpticalLaunchAction>;
0154 
0155     //// DATA ////
0156 
0157     SPConstOpticalParams optical_params_;
0158     SPGatherAction gather_;
0159     SPCherenkovOffload cherenkov_offload_;
0160     SPScintOffload scint_offload_;
0161     SPCherenkovGen cherenkov_generate_;
0162     SPScintGen scint_generate_;
0163     SPLaunchAction launch_;
0164 };
0165 
0166 //---------------------------------------------------------------------------//
0167 }  // namespace celeritas