File indexing completed on 2025-12-16 10:11:32
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <cmath>
0010
0011 #include "corecel/Assert.hh"
0012 #include "corecel/Macros.hh"
0013 #include "corecel/Types.hh"
0014 #include "corecel/math/Algorithms.hh"
0015 #include "corecel/random/distribution/GammaDistribution.hh"
0016
0017 #include "EnergyLossHelper.hh"
0018
0019 namespace celeritas
0020 {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 class EnergyLossGammaDistribution
0034 {
0035 public:
0036
0037
0038 using Energy = units::MevEnergy;
0039 using EnergySq = RealQuantity<UnitProduct<units::Mev, units::Mev>>;
0040
0041
0042 public:
0043
0044 inline CELER_FUNCTION
0045 EnergyLossGammaDistribution(Energy mean_loss, EnergySq bohr_var);
0046
0047
0048 explicit inline CELER_FUNCTION
0049 EnergyLossGammaDistribution(EnergyLossHelper const& helper);
0050
0051
0052 template<class Generator>
0053 CELER_FUNCTION Energy operator()(Generator& rng)
0054 {
0055 return Energy{sample_gamma_(rng)};
0056 }
0057
0058 private:
0059 using GammaDist = GammaDistribution<real_type>;
0060
0061 GammaDist sample_gamma_;
0062
0063 static inline CELER_FUNCTION GammaDist build_gamma(real_type mean,
0064 real_type stddev);
0065 };
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 CELER_FUNCTION
0078 EnergyLossGammaDistribution::EnergyLossGammaDistribution(Energy mean_loss,
0079 EnergySq bohr_var)
0080 : sample_gamma_(EnergyLossGammaDistribution::build_gamma(mean_loss.value(),
0081 bohr_var.value()))
0082 {
0083 CELER_EXPECT(mean_loss > zero_quantity());
0084 CELER_EXPECT(bohr_var > zero_quantity());
0085 }
0086
0087
0088
0089
0090
0091 CELER_FUNCTION EnergyLossGammaDistribution::EnergyLossGammaDistribution(
0092 EnergyLossHelper const& helper)
0093 : EnergyLossGammaDistribution(helper.mean_loss(), helper.bohr_variance())
0094 {
0095 CELER_ASSERT(helper.model() == EnergyLossFluctuationModel::gamma);
0096 }
0097
0098
0099
0100
0101
0102 CELER_FUNCTION auto
0103 EnergyLossGammaDistribution::build_gamma(real_type mean,
0104 real_type var) -> GammaDist
0105 {
0106 real_type k = ipow<2>(mean) / var;
0107 return GammaDist{k, mean / k};
0108 }
0109
0110
0111 }