File indexing completed on 2025-02-22 10:31:17
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/data/StackAllocator.hh"
0013 #include "corecel/math/Algorithms.hh"
0014 #include "corecel/math/ArrayUtils.hh"
0015 #include "celeritas/Constants.hh"
0016 #include "celeritas/Quantities.hh"
0017 #include "celeritas/Types.hh"
0018 #include "celeritas/em/data/CombinedBremData.hh"
0019 #include "celeritas/em/distribution/TsaiUrbanDistribution.hh"
0020 #include "celeritas/mat/ElementView.hh"
0021 #include "celeritas/mat/MaterialView.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/BremFinalStateHelper.hh"
0028 #include "detail/PhysicsConstants.hh"
0029 #include "detail/RBEnergySampler.hh"
0030 #include "detail/SBEnergySampler.hh"
0031
0032 namespace celeritas
0033 {
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 class CombinedBremInteractor
0046 {
0047
0048
0049 using Energy = units::MevEnergy;
0050 using Momentum = units::MevMomentum;
0051 using ElementData = RelBremElementData;
0052 using ItemIdT = celeritas::ItemId<unsigned int>;
0053
0054
0055 public:
0056
0057 inline CELER_FUNCTION
0058 CombinedBremInteractor(CombinedBremRef const& shared,
0059 ParticleTrackView const& particle,
0060 Real3 const& direction,
0061 CutoffView const& cutoffs,
0062 StackAllocator<Secondary>& allocate,
0063 MaterialView const& material,
0064 ElementComponentId const& elcomp_id);
0065
0066
0067 template<class Engine>
0068 inline CELER_FUNCTION Interaction operator()(Engine& rng);
0069
0070 private:
0071
0072
0073
0074 CombinedBremRef const& shared_;
0075
0076 ParticleTrackView const& particle_;
0077
0078 Real3 const& inc_direction_;
0079
0080 CutoffView const& cutoffs_;
0081
0082 Energy const gamma_cutoff_;
0083
0084 StackAllocator<Secondary>& allocate_;
0085
0086 MaterialView const& material_;
0087
0088 ElementComponentId const elcomp_id_;
0089
0090 TsaiUrbanDistribution sample_costheta_;
0091 };
0092
0093
0094
0095
0096
0097
0098
0099 CELER_FUNCTION
0100 CombinedBremInteractor::CombinedBremInteractor(
0101 CombinedBremRef const& shared,
0102 ParticleTrackView const& particle,
0103 Real3 const& direction,
0104 CutoffView const& cutoffs,
0105 StackAllocator<Secondary>& allocate,
0106 MaterialView const& material,
0107 ElementComponentId const& elcomp_id)
0108 : shared_(shared)
0109 , particle_(particle)
0110 , inc_direction_(direction)
0111 , cutoffs_(cutoffs)
0112 , gamma_cutoff_(cutoffs.energy(shared.rb_data.ids.gamma))
0113 , allocate_(allocate)
0114 , material_(material)
0115 , elcomp_id_(elcomp_id)
0116 , sample_costheta_(particle.energy(), particle.mass())
0117 {
0118 CELER_EXPECT(particle.particle_id() == shared.rb_data.ids.electron
0119 || particle.particle_id() == shared.rb_data.ids.positron);
0120 CELER_EXPECT(gamma_cutoff_ > zero_quantity());
0121 CELER_EXPECT(particle_.energy() > gamma_cutoff_);
0122 }
0123
0124
0125
0126
0127
0128 template<class Engine>
0129 CELER_FUNCTION Interaction CombinedBremInteractor::operator()(Engine& rng)
0130 {
0131
0132 Secondary* secondaries = allocate_(1);
0133 if (secondaries == nullptr)
0134 {
0135
0136 return Interaction::from_failure();
0137 }
0138
0139
0140 Energy gamma_energy;
0141 if (particle_.energy() >= detail::seltzer_berger_upper_limit())
0142 {
0143 detail::RBEnergySampler sample_energy{
0144 shared_.rb_data, particle_, cutoffs_, material_, elcomp_id_};
0145 gamma_energy = sample_energy(rng);
0146 }
0147 else
0148 {
0149 detail::SBEnergySampler sample_energy{
0150 shared_.sb_differential_xs,
0151 particle_,
0152 gamma_cutoff_,
0153 material_,
0154 elcomp_id_,
0155 particle_.particle_id() == shared_.rb_data.ids.electron};
0156 gamma_energy = sample_energy(rng);
0157 }
0158
0159
0160 return detail::BremFinalStateHelper(particle_.energy(),
0161 inc_direction_,
0162 particle_.momentum(),
0163 shared_.rb_data.ids.gamma,
0164 gamma_energy,
0165 sample_costheta_(rng),
0166 secondaries)(rng);
0167 }
0168
0169
0170 }