Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:12

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/phys/detail/TrackingCutExecutor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "celeritas/Types.hh"
0011 #include "celeritas/geo/GeoTrackView.hh"
0012 #include "celeritas/global/CoreTrackView.hh"
0013 #include "celeritas/track/SimTrackView.hh"
0014 
0015 #include "../ParticleTrackView.hh"
0016 
0017 #if !CELER_DEVICE_COMPILE
0018 #    include "corecel/io/Logger.hh"
0019 #    include "celeritas/global/Debug.hh"
0020 #endif
0021 
0022 namespace celeritas
0023 {
0024 namespace detail
0025 {
0026 //---------------------------------------------------------------------------//
0027 /*!
0028  * Kill the current track and deposit its energy.
0029  *
0030  * This is called to kill a track due to "user cuts" (i.e., minimum energy,
0031  * maximum number of steps, maximum lab-frame time) and due to geometry errors
0032  * (i.e.  initialization, boundary crossing). It deposits the track's energy
0033  * plus, if an anitiparticle, the annihilation energy as well.
0034  *
0035  * If the track has an "error" status and the track is on the host, a message
0036  * will be printed.
0037  *
0038  * TODO: we could use a stack allocator to perform a reduction in this kernel
0039  * so that the host can print out warning messages (or print at the end of the
0040  * simulation).
0041  */
0042 struct TrackingCutExecutor
0043 {
0044     inline CELER_FUNCTION void operator()(celeritas::CoreTrackView& track);
0045 };
0046 
0047 //---------------------------------------------------------------------------//
0048 CELER_FUNCTION void
0049 TrackingCutExecutor::operator()(celeritas::CoreTrackView& track)
0050 {
0051     using Energy = ParticleTrackView::Energy;
0052 
0053     auto particle = track.particle();
0054     auto sim = track.sim();
0055 
0056     // Deposit the remaining energy locally
0057     auto deposited = particle.energy().value();
0058     if (particle.is_antiparticle())
0059     {
0060         // Energy conservation for killed positrons
0061         deposited += 2 * particle.mass().value();
0062     }
0063 
0064 #if !CELER_DEVICE_COMPILE
0065     {
0066         // Print a debug message if track is just being cut; error message if
0067         // an error occurred
0068         auto const geo = track.geometry();
0069         auto msg = self_logger()(CELER_CODE_PROVENANCE,
0070                                  sim.status() == TrackStatus::errored
0071                                      ? LogLevel::error
0072                                      : LogLevel::debug);
0073         msg << "Killing track " << StreamableTrack{track} << ": "
0074             << (geo.is_outside() ? "depositing" : "lost") << ' ' << deposited
0075             << ' ' << Energy::unit_type::label();
0076     }
0077 #endif
0078 
0079     track.physics_step().deposit_energy(Energy{deposited});
0080     particle.subtract_energy(particle.energy());
0081 
0082     sim.status(TrackStatus::killed);
0083 }
0084 
0085 //---------------------------------------------------------------------------//
0086 }  // namespace detail
0087 }  // namespace celeritas