Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-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/global/alongstep/detail/MeanELoss.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "celeritas/global/CoreTrackView.hh"
0012 #include "celeritas/phys/PhysicsStepUtils.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Calculate energy loss (*without* fluctuations) to a track.
0021  */
0022 class MeanELoss
0023 {
0024   public:
0025     //!@{
0026     //! \name Type aliases
0027     using Energy = ParticleTrackView::Energy;
0028     //!@}
0029 
0030   public:
0031     // Whether energy loss is used for this track
0032     inline CELER_FUNCTION bool is_applicable(CoreTrackView const&) const;
0033 
0034     // Apply to the track
0035     inline CELER_FUNCTION Energy calc_eloss(CoreTrackView const& track,
0036                                             real_type step,
0037                                             bool apply_cut);
0038 
0039     //! Particle will slow down to zero only if range limited
0040     static CELER_CONSTEXPR_FUNCTION bool imprecise_range() { return false; }
0041 };
0042 
0043 //---------------------------------------------------------------------------//
0044 // INLINE DEFINITIONS
0045 //---------------------------------------------------------------------------//
0046 /*!
0047  * Whether energy loss is used for this track.
0048  */
0049 CELER_FUNCTION bool MeanELoss::is_applicable(CoreTrackView const& track) const
0050 {
0051     // The track can be marked as `errored` *within* the along-step kernel,
0052     // during propagation
0053     if (track.make_sim_view().status() == TrackStatus::errored)
0054         return false;
0055 
0056     // Energy loss grid ID will be 'false' if inapplicable
0057     auto ppid = track.make_physics_view().eloss_ppid();
0058     return static_cast<bool>(ppid);
0059 }
0060 
0061 //---------------------------------------------------------------------------//
0062 /*!
0063  * Apply energy loss to the given track.
0064  */
0065 CELER_FUNCTION auto MeanELoss::calc_eloss(CoreTrackView const& track,
0066                                           real_type step,
0067                                           bool apply_cut) -> Energy
0068 {
0069     CELER_EXPECT(step > 0);
0070 
0071     auto particle = track.make_particle_view();
0072     auto phys = track.make_physics_view();
0073 
0074     if (apply_cut && particle.energy() < phys.scalars().lowest_electron_energy)
0075     {
0076         // Deposit all energy when we start below the tracking cut
0077         return particle.energy();
0078     }
0079 
0080     // Calculate the mean energy loss
0081     Energy eloss = calc_mean_energy_loss(particle, phys, step);
0082 
0083     if (apply_cut
0084         && (particle.energy() - eloss <= phys.scalars().lowest_electron_energy))
0085     {
0086         // Deposit all energy when we end below the tracking cut
0087         return particle.energy();
0088     }
0089 
0090     CELER_ENSURE(eloss <= particle.energy());
0091     CELER_ENSURE(eloss != particle.energy()
0092                  || track.make_sim_view().post_step_action()
0093                         == phys.scalars().range_action());
0094     return eloss;
0095 }
0096 
0097 //---------------------------------------------------------------------------//
0098 }  // namespace detail
0099 }  // namespace celeritas