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/CherenkovOffloadExecutor.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 "../CherenkovOffload.hh"
0014 #include "../OffloadData.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 // LAUNCHER
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Generate optical distribution data.
0025  */
0026 struct CherenkovOffloadExecutor
0027 {
0028     inline CELER_FUNCTION void
0029     operator()(celeritas::CoreTrackView const& track);
0030 
0031     NativeCRef<celeritas::optical::MaterialParamsData> material;
0032     NativeCRef<CherenkovData> cherenkov;
0033     NativeRef<GeneratorStateData> offload;
0034     NativeRef<OffloadStepStateData> steps;
0035     size_type buffer_size;
0036 };
0037 
0038 //---------------------------------------------------------------------------//
0039 // INLINE DEFINITIONS
0040 //---------------------------------------------------------------------------//
0041 /*!
0042  * Generate optical distribution data.
0043  */
0044 CELER_FUNCTION void
0045 CherenkovOffloadExecutor::operator()(CoreTrackView const& track)
0046 {
0047     CELER_EXPECT(material);
0048     CELER_EXPECT(cherenkov);
0049     CELER_EXPECT(offload);
0050     CELER_EXPECT(steps);
0051 
0052     using DistId = ItemId<GeneratorDistributionData>;
0053 
0054     auto tsid = track.track_slot_id();
0055     CELER_ASSERT(buffer_size + tsid.get() < offload.distributions.size());
0056     auto& dist = offload.distributions[DistId(buffer_size + tsid.get())];
0057 
0058     // Clear distribution data
0059     dist = {};
0060 
0061     auto sim = track.sim();
0062     auto const& step = steps.step[tsid];
0063 
0064     if (!step || sim.status() == TrackStatus::inactive)
0065     {
0066         // Inactive tracks, materials with no optical properties, or particles
0067         // that started the step with zero energy (e.g. a stopped positron)
0068         return;
0069     }
0070 
0071     auto particle = track.particle();
0072 
0073     // Get the distribution data used to generate Cherenkov optical photons
0074     if (particle.charge() != zero_quantity())
0075     {
0076         CherenkovOffload sample_dist(
0077             // Pre-step:
0078             step,
0079             optical::MaterialView{material, step.material},
0080             // Post-step:
0081             particle,
0082             sim,
0083             track.geometry().pos(),
0084             cherenkov);
0085         auto rng = track.rng();
0086         dist = sample_dist(rng);
0087     }
0088 }
0089 
0090 //---------------------------------------------------------------------------//
0091 }  // namespace detail
0092 }  // namespace celeritas