Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:43

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/track/Utils.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/OpaqueId.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/math/Atomics.hh"
0014 #include "corecel/sys/ThreadId.hh"
0015 #include "celeritas/global/CoreTrackData.hh"
0016 #include "celeritas/phys/ParticleView.hh"
0017 
0018 #include "TrackInitData.hh"
0019 
0020 namespace celeritas
0021 {
0022 //---------------------------------------------------------------------------//
0023 //! Predicate for sorting charged from neutral tracks
0024 struct IsNeutral
0025 {
0026     using ParamsPtr = CRefPtr<CoreParamsData, MemSpace::native>;
0027 
0028     ParamsPtr params;
0029 
0030     CELER_FUNCTION bool operator()(TrackInitializer const& ti) const
0031     {
0032         return ParticleView(params->particles, ti.particle.particle_id).charge()
0033                == zero_quantity();
0034     }
0035 };
0036 
0037 //---------------------------------------------------------------------------//
0038 //! Get an initializer index where thread 0 has the last valid element
0039 CELER_FORCEINLINE_FUNCTION size_type index_before(size_type size, ThreadId tid)
0040 {
0041     CELER_EXPECT(tid.get() + 1 <= size);
0042     return size - tid.unchecked_get() - 1;
0043 }
0044 
0045 //---------------------------------------------------------------------------//
0046 /*!
0047  * Create a unique track ID for the given event.
0048  *
0049  * \todo This is nondeterministic; we need to calculate the track ID in a
0050  * reproducible way.
0051  */
0052 inline CELER_FUNCTION TrackId make_track_id(
0053     NativeCRef<TrackInitParamsData> const&,
0054     NativeRef<TrackInitStateData>& state,
0055     EventId event)
0056 {
0057     CELER_EXPECT(event < state.track_counters.size());
0058     auto result
0059         = atomic_add(&state.track_counters[event], TrackId::size_type{1});
0060     return TrackId{result};
0061 }
0062 
0063 //---------------------------------------------------------------------------//
0064 }  // namespace celeritas