Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-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/user/detail/SimpleCaloExecutor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <type_traits>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/math/Atomics.hh"
0014 
0015 #include "../SimpleCaloData.hh"
0016 #include "../StepData.hh"
0017 
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 // LAUNCHER
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Help gather detector hits in parallel.
0027  *
0028  * We do not remap any threads, so the track slot ID should be the thread ID.
0029  */
0030 struct SimpleCaloExecutor
0031 {
0032     NativeRef<StepStateData> const step;
0033     NativeRef<SimpleCaloStateData> calo;
0034 
0035     inline CELER_FUNCTION void operator()(TrackSlotId tid);
0036     CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid)
0037     {
0038         return (*this)(TrackSlotId{tid.unchecked_get()});
0039     }
0040 };
0041 
0042 //---------------------------------------------------------------------------//
0043 // INLINE DEFINITIONS
0044 //---------------------------------------------------------------------------//
0045 /*!
0046  * Accumulate detector hits on each thread.
0047  */
0048 CELER_FUNCTION void SimpleCaloExecutor::operator()(TrackSlotId tid)
0049 {
0050     CELER_EXPECT(tid < step.data.detector.size());
0051     CELER_EXPECT(!step.data.energy_deposition.empty());
0052 
0053     DetectorId det = step.data.detector[tid];
0054     if (!det)
0055     {
0056         // No energy deposition or inactive track
0057         return;
0058     }
0059 
0060     static_assert(
0061         std::is_same_v<NativeRef<StepStateDataImpl>::Energy::unit_type,
0062                        NativeRef<SimpleCaloStateData>::EnergyUnits>);
0063     real_type edep = step.data.energy_deposition[tid].value();
0064     CELER_ASSERT(edep > 0);
0065     CELER_ASSERT(det < calo.energy_deposition.size());
0066     atomic_add(&calo.energy_deposition[det], edep);
0067 }
0068 
0069 //---------------------------------------------------------------------------//
0070 }  // namespace detail
0071 }  // namespace celeritas