Files
karl/src/simulation/energy_distribution.cpp
T
csendlinger 32f4703f4e New energy distribution function to better approximate
the energy distribution of the ions created in the T2 beta decay;
Does not take into account the distribution due to angular
distribution nor the fact that that a dissociative decay is possible.
Note: drawing the ion energy also draws a new electron energy, which,
however, is discarded.
2026-02-16 09:02:25 +01:00

81 lines
2.9 KiB
C++
Executable File

#include "simulation/energy_distribution.h"
#include "simulation/errors.h"
#include "constants/T2_beta_decay.h"
#include "constants/physical_constants.h"
#include "simulation/kinematic.h"
#include "simulation/tritium_spectrum.h"
TritiumBetaDecay::TritiumBetaDecay()
: x_distribution_(
std::uniform_real_distribution<double>(0., T2BetaDecay::E0_T)),
y_distribution_(std::uniform_real_distribution<double>(
0.,
T2BetaDecay::spectrum_maximum)),
tritium_spectrum_(tritiumDecayEnergySpectrum(1.)) {}
double TritiumBetaDecay::rollEnergy(std::mt19937* engine) {
double random_number_x;
double random_number_y;
double return_value;
do {
random_number_x = x_distribution_(*engine);
random_number_y = y_distribution_(*engine);
} while (random_number_y > tritium_spectrum_(random_number_x));
return random_number_x;
}
// endpoint_eV is the recoil energy of the target species for an electron
// energy at 18.6keV (i.e. the endpoint energy of the electron distribution)
TritiumBetaDecayIon::TritiumBetaDecayIon(double endpoint_eV)
: x_distribution_(
std::uniform_real_distribution<double>(0., T2BetaDecay::E0_T)),
y_distribution_(std::uniform_real_distribution<double>(
0.,
T2BetaDecay::spectrum_maximum)),
tritium_spectrum_(tritiumDecayEnergySpectrum(1.)),
tritium_spectrum_ion_(tritiumDecayEnergySpectrumIon(endpoint_eV)) {}
// due to not great structure, draw a(nother) electron energy to inject
// the ion at the corresponding (approximated) energy
double TritiumBetaDecayIon::rollEnergy(std::mt19937* engine) {
double random_number_x;
double random_number_y;
double return_value;
do {
random_number_x = x_distribution_(*engine);
random_number_y = y_distribution_(*engine);
} while (random_number_y > tritium_spectrum_(random_number_x));
return tritium_spectrum_ion_(random_number_x);
}
MaxwellBoltzmann::MaxwellBoltzmann(double temperature_K)
: distribution_(std::gamma_distribution<double>(
3. / 2.,
kinematic::thermalEnergy(temperature_K))) {
ASSERT_POSITIVE(
&temperature_K,
"Temperature for MaxwellBoltzmann distribution must be positive.");
}
double MaxwellBoltzmann::rollEnergy(std::mt19937* engine) {
double value = distribution_(*engine);
// this makes (the test case) reproduceable through restart
// but it does impact the efficiency of the drawing (simple test
// resultet in about an increase of 50% for the function call)
// however, i think that that time increse is almost negligible
// compared to the rest of the operations in the simulation
distribution_.reset();
return value;
}
Constant::Constant(double constant_eV) : constant_eV_(constant_eV) {
ASSERT_POSITIVE(&constant_eV,
"The energy for the constant distribution must be positive.");
}
double Constant::rollEnergy(std::mt19937* engine) {
return constant_eV_;
}