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/ScintOffloadExecutor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "celeritas/global/CoreTrackView.hh"
0012 
0013 #include "../OffloadData.hh"
0014 #include "../ScintillationOffload.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 // LAUNCHER
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Generate optical distribution data.
0025  *
0026  * Note that the track may be inactive! TODO: we could add a `user_start`
0027  * action to clear distribution data rather than applying it to inactive tracks
0028  * at every step.
0029  */
0030 struct ScintOffloadExecutor
0031 {
0032     inline CELER_FUNCTION void
0033     operator()(celeritas::CoreTrackView const& track);
0034 
0035     NativeCRef<celeritas::optical::MaterialParamsData> const material;
0036     NativeCRef<ScintillationData> const scint;
0037     NativeRef<GeneratorStateData> const offload;
0038     NativeRef<OffloadStepStateData> const steps;
0039     size_type buffer_size;
0040 };
0041 
0042 //---------------------------------------------------------------------------//
0043 // INLINE DEFINITIONS
0044 //---------------------------------------------------------------------------//
0045 /*!
0046  * Generate optical distribution data.
0047  */
0048 CELER_FUNCTION void ScintOffloadExecutor::operator()(CoreTrackView const& track)
0049 {
0050     CELER_EXPECT(scint);
0051     CELER_EXPECT(offload);
0052     CELER_EXPECT(steps);
0053 
0054     using DistId = ItemId<GeneratorDistributionData>;
0055 
0056     auto tsid = track.track_slot_id();
0057     CELER_ASSERT(buffer_size + tsid.get() < offload.distributions.size());
0058     auto& dist = offload.distributions[DistId(buffer_size + tsid.get())];
0059 
0060     // Clear distribution data
0061     dist = {};
0062 
0063     auto sim = track.sim();
0064     auto const& step = steps.step[tsid];
0065 
0066     if (!step || sim.status() == TrackStatus::inactive)
0067     {
0068         // Inactive tracks, materials with no optical properties, or particles
0069         // that started the step with zero energy (e.g. a stopped positron)
0070         return;
0071     }
0072 
0073     Real3 const& pos = track.geometry().pos();
0074     auto edep = track.physics_step().energy_deposition();
0075     auto particle = track.particle();
0076     auto rng = track.rng();
0077 
0078     // Get the distribution data used to generate scintillation optical photons
0079     dist = ScintillationOffload(particle, sim, pos, edep, scint, step)(rng);
0080 }
0081 
0082 //---------------------------------------------------------------------------//
0083 }  // namespace detail
0084 }  // namespace celeritas