Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:48

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/user/detail/StepDiagnosticExecutor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/math/Algorithms.hh"
0012 #include "corecel/math/Atomics.hh"
0013 #include "celeritas/global/CoreTrackView.hh"
0014 
0015 #include "../ParticleTallyData.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021 //---------------------------------------------------------------------------//
0022 struct StepDiagnosticExecutor
0023 {
0024     inline CELER_FUNCTION void
0025     operator()(celeritas::CoreTrackView const& track);
0026 
0027     NativeCRef<ParticleTallyParamsData> const params;
0028     NativeRef<ParticleTallyStateData> const state;
0029 };
0030 
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Collect distribution of steps per track for each particle type.
0034  */
0035 CELER_FUNCTION void
0036 StepDiagnosticExecutor::operator()(CoreTrackView const& track)
0037 {
0038     CELER_EXPECT(params);
0039     CELER_EXPECT(state);
0040 
0041     using BinId = ItemId<size_type>;
0042 
0043     // Tally the number of steps if the track was killed
0044     auto sim = track.sim();
0045     if (sim.status() == TrackStatus::killed)
0046     {
0047         // TODO: Add an ndarray-type class?
0048         auto get = [this](size_type i, size_type j) -> size_type& {
0049             size_type index = i * params.num_bins + j;
0050             CELER_ENSURE(index < state.counts.size());
0051             return state.counts[BinId(index)];
0052         };
0053 
0054         size_type num_steps
0055             = celeritas::min(sim.num_steps(), params.num_bins - 1);
0056         auto particle = track.particle().particle_id();
0057 
0058         // Increment the bin corresponding to the given particle and step count
0059         auto& bin = get(particle.get(), num_steps);
0060         atomic_add(&bin, size_type{1});
0061     }
0062 }
0063 
0064 //---------------------------------------------------------------------------//
0065 }  // namespace detail
0066 }  // namespace celeritas