Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/celeritas/user/detail/SimpleCaloExecutor.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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