Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:27

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/optical/detail/ScintOffloadExecutor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "celeritas/global/CoreTrackView.hh"
0013 #include "celeritas/optical/OffloadData.hh"
0014 #include "celeritas/optical/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::ScintillationData> const scintillation;
0036     NativeRef<OffloadStateData> const state;
0037     OffloadBufferSize size;
0038 };
0039 
0040 //---------------------------------------------------------------------------//
0041 // INLINE DEFINITIONS
0042 //---------------------------------------------------------------------------//
0043 /*!
0044  * Generate optical distribution data.
0045  */
0046 CELER_FUNCTION void ScintOffloadExecutor::operator()(CoreTrackView const& track)
0047 {
0048     CELER_EXPECT(state);
0049 
0050     using DistId = ItemId<celeritas::optical::GeneratorDistributionData>;
0051 
0052     auto tsid = track.track_slot_id();
0053     CELER_ASSERT(size.scintillation + tsid.get() < state.scintillation.size());
0054     auto& scintillation_dist
0055         = state.scintillation[DistId(size.scintillation + tsid.get())];
0056 
0057     // Clear distribution data
0058     scintillation_dist = {};
0059 
0060     auto sim = track.make_sim_view();
0061     auto const& step = state.step[tsid];
0062 
0063     if (!step || sim.status() == TrackStatus::inactive)
0064     {
0065         // Inactive tracks, materials with no optical properties, or particles
0066         // that started the step with zero energy (e.g. a stopped positron)
0067         return;
0068     }
0069 
0070     Real3 const& pos = track.make_geo_view().pos();
0071     auto edep = track.make_physics_step_view().energy_deposition();
0072     auto particle = track.make_particle_view();
0073     auto rng = track.make_rng_engine();
0074 
0075     // Get the distribution data used to generate scintillation optical photons
0076     ScintillationOffload generate(
0077         particle, sim, pos, edep, scintillation, step);
0078     scintillation_dist = generate(rng);
0079 }
0080 
0081 //---------------------------------------------------------------------------//
0082 }  // namespace detail
0083 }  // namespace celeritas