Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 10:05: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/gen/detail/PrimaryGeneratorExecutor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "celeritas/optical/CoreTrackView.hh"
0012 #include "celeritas/track/CoreStateCounters.hh"
0013 #include "celeritas/track/detail/Utils.hh"
0014 
0015 #include "../GeneratorData.hh"
0016 #include "../OpticalPrimaryGenerator.hh"
0017 
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 // LAUNCHER
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Generate primary optical photons from distributions.
0027  */
0028 struct PrimaryGeneratorExecutor
0029 {
0030     //// DATA ////
0031 
0032     CRefPtr<celeritas::optical::CoreParamsData, MemSpace::native> params;
0033     RefPtr<celeritas::optical::CoreStateData, MemSpace::native> state;
0034     PrimaryDistributionData data;
0035     CoreStateCounters counters;
0036 
0037     //// FUNCTIONS ////
0038 
0039     // Generate optical photons
0040     inline CELER_FUNCTION void operator()(TrackSlotId tid) const;
0041     CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0042     {
0043         return (*this)(TrackSlotId{tid.unchecked_get()});
0044     }
0045 };
0046 
0047 //---------------------------------------------------------------------------//
0048 // INLINE DEFINITIONS
0049 //---------------------------------------------------------------------------//
0050 /*!
0051  * Generate photons from optical distribution data.
0052  */
0053 CELER_FUNCTION void PrimaryGeneratorExecutor::operator()(TrackSlotId tid) const
0054 {
0055     CELER_EXPECT(params);
0056     CELER_EXPECT(state);
0057     CELER_EXPECT(data);
0058 
0059     celeritas::optical::CoreTrackView track(*params, *state, tid);
0060 
0061     // Create the view to the new track to be initialized
0062     celeritas::optical::CoreTrackView vacancy{
0063         *params, *state, [&] {
0064             // Get the vacancy from the back in case there are more vacancies
0065             // than photons left to generate
0066             TrackSlotId idx{
0067                 index_before(counters.num_vacancies, ThreadId(tid.get()))};
0068             return state->init.vacancies[idx];
0069         }()};
0070 
0071     // Generate one primary from the distribution
0072     auto rng = track.rng();
0073     vacancy = OpticalPrimaryGenerator(data)(rng);
0074 }
0075 
0076 //---------------------------------------------------------------------------//
0077 }  // namespace detail
0078 }  // namespace celeritas