Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-01 10:05:02

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