Back to home page

EIC code displayed by LXR

 
 

    


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

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