File indexing completed on 2025-02-22 10:31:22
0001
0002
0003
0004
0005
0006
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
0021
0022 class MeanELoss
0023 {
0024 public:
0025
0026
0027 using Energy = ParticleTrackView::Energy;
0028
0029
0030 public:
0031
0032 inline CELER_FUNCTION bool is_applicable(CoreTrackView const&) const;
0033
0034
0035 inline CELER_FUNCTION Energy calc_eloss(CoreTrackView const& track,
0036 real_type step,
0037 bool apply_cut);
0038
0039
0040 static CELER_CONSTEXPR_FUNCTION bool imprecise_range() { return false; }
0041 };
0042
0043
0044
0045
0046
0047
0048
0049 CELER_FUNCTION bool MeanELoss::is_applicable(CoreTrackView const& track) const
0050 {
0051
0052
0053 if (track.make_sim_view().status() == TrackStatus::errored)
0054 return false;
0055
0056
0057 auto ppid = track.make_physics_view().eloss_ppid();
0058 return static_cast<bool>(ppid);
0059 }
0060
0061
0062
0063
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
0077 return particle.energy();
0078 }
0079
0080
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
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 }
0099 }