File indexing completed on 2025-02-22 10:31:17
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <cmath>
0011
0012 #include "corecel/Macros.hh"
0013 #include "corecel/Types.hh"
0014 #include "corecel/data/StackAllocator.hh"
0015 #include "corecel/math/Algorithms.hh"
0016 #include "corecel/math/ArrayUtils.hh"
0017 #include "celeritas/Constants.hh"
0018 #include "celeritas/Quantities.hh"
0019 #include "celeritas/em/data/MollerBhabhaData.hh"
0020 #include "celeritas/em/distribution/BhabhaEnergyDistribution.hh"
0021 #include "celeritas/em/distribution/MollerEnergyDistribution.hh"
0022 #include "celeritas/phys/CutoffView.hh"
0023 #include "celeritas/phys/Interaction.hh"
0024 #include "celeritas/phys/ParticleTrackView.hh"
0025 #include "celeritas/phys/Secondary.hh"
0026
0027 #include "detail/IoniFinalStateHelper.hh"
0028
0029 namespace celeritas
0030 {
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 class MollerBhabhaInteractor
0043 {
0044 public:
0045
0046
0047 using Mass = units::MevMass;
0048 using Energy = units::MevEnergy;
0049 using Momentum = units::MevMomentum;
0050
0051
0052 public:
0053
0054 inline CELER_FUNCTION
0055 MollerBhabhaInteractor(MollerBhabhaData const& shared,
0056 ParticleTrackView const& particle,
0057 CutoffView const& cutoffs,
0058 Real3 const& inc_direction,
0059 StackAllocator<Secondary>& allocate);
0060
0061
0062 template<class Engine>
0063 inline CELER_FUNCTION Interaction operator()(Engine& rng);
0064
0065 private:
0066
0067 MollerBhabhaData const& shared_;
0068
0069 Energy inc_energy_;
0070
0071 Momentum inc_momentum_;
0072
0073 Real3 const& inc_direction_;
0074
0075 Energy electron_cutoff_;
0076
0077 StackAllocator<Secondary>& allocate_;
0078
0079 bool const inc_particle_is_electron_;
0080 };
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 CELER_FUNCTION MollerBhabhaInteractor::MollerBhabhaInteractor(
0092 MollerBhabhaData const& shared,
0093 ParticleTrackView const& particle,
0094 CutoffView const& cutoffs,
0095 Real3 const& inc_direction,
0096 StackAllocator<Secondary>& allocate)
0097 : shared_(shared)
0098 , inc_energy_(particle.energy())
0099 , inc_momentum_(particle.momentum())
0100 , inc_direction_(inc_direction)
0101 , electron_cutoff_(cutoffs.energy(shared_.ids.electron))
0102 , allocate_(allocate)
0103 , inc_particle_is_electron_(particle.particle_id() == shared_.ids.electron)
0104 {
0105 CELER_EXPECT(particle.particle_id() == shared_.ids.electron
0106 || particle.particle_id() == shared_.ids.positron);
0107 CELER_EXPECT(inc_energy_
0108 > (inc_particle_is_electron_ ? 2 : 1) * electron_cutoff_);
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118 template<class Engine>
0119 CELER_FUNCTION Interaction MollerBhabhaInteractor::operator()(Engine& rng)
0120 {
0121
0122 Secondary* electron_secondary = allocate_(1);
0123
0124 if (electron_secondary == nullptr)
0125 {
0126
0127 return Interaction::from_failure();
0128 }
0129
0130
0131 Energy secondary_energy = inc_energy_ * [this, &rng] {
0132 if (inc_particle_is_electron_)
0133 {
0134 return MollerEnergyDistribution(
0135 shared_.electron_mass, electron_cutoff_, inc_energy_)(rng);
0136 }
0137 return BhabhaEnergyDistribution(
0138 shared_.electron_mass, electron_cutoff_, inc_energy_)(rng);
0139 }();
0140 CELER_ASSERT(secondary_energy >= electron_cutoff_);
0141
0142
0143 detail::IoniFinalStateHelper sample_interaction(inc_energy_,
0144 inc_direction_,
0145 inc_momentum_,
0146 shared_.electron_mass,
0147 secondary_energy,
0148 shared_.electron_mass,
0149 shared_.ids.electron,
0150 electron_secondary);
0151
0152
0153 return sample_interaction(rng);
0154 }
0155
0156
0157 }