#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(0., T2BetaDecay::E0_T)), y_distribution_(std::uniform_real_distribution( 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; } MaxwellBoltzmann::MaxwellBoltzmann(double temperature_K) : distribution_(std::gamma_distribution( 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_; }