27#include "marley/GammaStrengthFunctionModel.hh"
28#include "marley/InterpolatingFunction.hh"
29#include "marley/NeutrinoSource.hh"
30#include "marley/NuclearReaction.hh"
31#include "marley/LevelDensityModel.hh"
32#include "marley/NuclearFormFactor.hh"
33#include "marley/OpticalModel.hh"
34#include "marley/Parity.hh"
35#include "marley/ProjectileDirectionRotator.hh"
36#include "marley/RotationMatrix.hh"
37#include "marley/StructureDatabase.hh"
38#include "marley/Target.hh"
39#include "marley/marley_utils.hh"
70 bool attach_state =
false );
73 inline uint_fast64_t
get_seed()
const;
76 void reseed(uint_fast64_t seed);
105 double xmin,
double xmax,
double& fmax,
double safety_factor = 1.01,
106 double max_search_tolerance = DEFAULT_REJECTION_SAMPLING_TOLERANCE_);
116 double xmin,
double xmax,
double bisection_tolerance = 1e-12);
125 double xmin,
double xmax,
double bisection_tolerance = 1e-12 );
139 inline const std::vector< std::unique_ptr<marley::Reaction> >&
144 void add_reaction(std::unique_ptr<marley::Reaction> reaction);
163 double E_pdf(
double E);
174 void set_source(std::unique_ptr<marley::NeutrinoSource> source);
179 void set_target(std::unique_ptr<marley::Target> target);
192 template <
class RandomNumberDistribution>
194 ->
decltype( std::declval<RandomNumberDistribution&>().operator()(
195 std::declval<std::mt19937_64&>()) )
197 return rnd(rand_gen_);
204 template <
class RandomNumberDistribution,
typename ParamType>
206 const ParamType& params) ->
decltype(
207 std::declval<RandomNumberDistribution&>().operator()(
208 std::declval<std::mt19937_64&>(), std::declval<const ParamType&>() ) )
210 return rnd(rand_gen_, params);
255 double total_xs(
int pdg_a,
double KEa,
int pdg_atom)
const;
267 double total_xs(
int pdg_a,
double KEa)
const;
282 std::shared_ptr< HepMC3::GenEvent >
create_event(
int pdg_a,
double KEa,
283 int pdg_atom,
const std::array<double, 3>& dir_vec,
284 bool attach_state =
false );
290 inline const std::string& json_config()
const {
return json_config_; }
292 inline const std::shared_ptr< HepMC3::GenRunInfo >& run_info()
const
293 {
return run_info_; }
298 inline void set_run_info(
const std::shared_ptr< HepMC3::GenRunInfo >&
299 run_info ) { run_info_ = run_info; }
310 bool attach_state =
false );
314 {
return *weighter_; }
330 const std::string& state );
341 void normalize_E_pdf();
351 std::mt19937_64 rand_gen_;
354 static constexpr double DEFAULT_REJECTION_SAMPLING_TOLERANCE_ = 1e-8;
360 std::unique_ptr<marley::NeutrinoSource> source_;
364 std::unique_ptr<marley::Target> target_;
368 std::unique_ptr<marley::StructureDatabase> structure_db_;
371 std::vector< std::unique_ptr<marley::Reaction> > reactions_;
377 std::vector<double> total_xs_values_;
380 std::discrete_distribution<size_t> r_index_dist_;
386 bool weight_flux_ =
true;
399 double E_PDF_MAX_DEFAULT_ = marley_utils::UNKNOWN_MAX;
405 inline void set_default_E_pdf_max(
double def_max ) {
406 E_PDF_MAX_DEFAULT_ = def_max;
412 bool dont_normalize_E_pdf_ =
false;
422 bool do_deexcitations_ =
true;
427 std::shared_ptr< HepMC3::GenRunInfo > run_info_;
432 std::string json_config_;
453 double total_xs(
int pdg_a,
double KEa,
int pdg_atom,
454 std::vector<size_t>* index_vec, std::vector<double>* xsec_vec)
const;
461 std::shared_ptr< Weighter > weighter_;
467 inline const std::vector<std::unique_ptr<marley::Reaction> >&
471 {
return rotator_.projectile_direction(); }
474 { do_deexcitations_ = do_them; }
Stores event-related information.
Stores run-related information.
Approximates a 1D function using Chebyshev points.
uint_fast64_t get_seed() const
Get the seed used to initialize this Generator.
const std::array< double, 3 > & neutrino_direction()
Gets the direction of the incident neutrinos that is used when generating events.
void clear_reactions()
Clear the vector of Reaction objects owned by this Generator.
void set_source(std::unique_ptr< marley::NeutrinoSource > source)
Take ownership of a new NeutrinoSource, replacing any existing source owned by this Generator.
double uniform_random_double(double min, double max, bool inclusive)
Sample a random number uniformly on either [min, max) or [min, max].
double inverse_transform_sample(const marley::InterpolatingFunction &cdf, double xmin, double xmax, double bisection_tolerance=1e-12)
Sample from a given 1D cumulative density function cdf(x) on the interval [xmin, xmax] using bisectio...
void set_up_run_info()
Initializes the owned GenRunInfo object that will be used to associate run metadata with the output e...
marley::StructureDatabase & get_structure_db()
Get a reference to the StructureDatabase owned by this Generator.
const marley::NeutrinoSource & get_source() const
Get a const reference to the NeutrinoSource owned by this Generator.
marley::Weighter & get_weighter()
Get a non-const reference to the owned Weighter object.
const marley::Weighter & get_weighter() const
Get a const reference to the owned Weighter object.
double E_pdf(double E)
Probability density function that describes the distribution of reacting neutrino energies.
double sample_decay_time(double partial_width)
Sample a random decay time given a partial decay width.
marley::ProjectileDirectionRotator & get_rotator()
Provides access to the owned ProjectileDirectionRotator.
void add_state_to_event(HepMC3::GenEvent &ev) const
Attach the current random number generator state to the input event as a string attribute.
void set_weighter(std::shared_ptr< marley::Weighter > w)
Replace the owned Weighter object.
void seed_using_state_string(const std::string &state_string)
Use a string to set this Generator's internal state.
double total_xs(int pdg_a, double KEa, int pdg_atom) const
Computes the total cross section at fixed energy for all configured reactions involving a particular ...
double rejection_sample(const std::function< double(double)> &f, double xmin, double xmax, double &fmax, double safety_factor=1.01, double max_search_tolerance=DEFAULT_REJECTION_SAMPLING_TOLERANCE_)
Sample from a given 1D probability density function f(x) on the interval [xmin, xmax] using a simple ...
auto sample_from_distribution(RandomNumberDistribution &rnd, const ParamType ¶ms) -> decltype(std::declval< RandomNumberDistribution & >().operator()(std::declval< std::mt19937_64 & >(), std::declval< const ParamType & >()))
Sample from an arbitrary probability distribution (defined here as any object that implements an oper...
void set_weight_flux(bool should_we_weight)
Sets the value of the weight_flux flag.
const std::vector< std::unique_ptr< marley::Reaction > > & get_reactions() const
Get a const reference to the vector of Reaction objects owned by this Generator.
void reseed(uint_fast64_t seed)
Reseeds the Generator.
Generator()
Create a Generator using default settings.
auto sample_from_distribution(RandomNumberDistribution &rnd) -> decltype(std::declval< RandomNumberDistribution & >().operator()(std::declval< std::mt19937_64 & >()))
Sample from an arbitrary probability distribution (defined here as any object that implements an oper...
marley::Reaction & sample_reaction(double &E)
Sample a Reaction and an energy for the reacting neutrino.
std::shared_ptr< HepMC3::GenEvent > create_event(bool attach_state=false)
Create an Event using the NeutrinoSource, Target, Reaction, and StructureDatabase objects owned by th...
void assign_run_info(HepMC3::GenEvent &event) const
Associates the owned GenRunInfo object with the input event.
void set_target(std::unique_ptr< marley::Target > target)
Take ownership of a new Target, replacing any existing target owned by this Generator.
double flux_averaged_total_xs() const
Computes the flux-averaged total cross section for all enabled neutrino reactions,...
void add_reaction(std::unique_ptr< marley::Reaction > reaction)
Take ownership of a new Reaction.
void finish_event_metadata(HepMC3::GenEvent &ev, bool attach_state=false)
Add final pieces of metadata (e.g., the RNG state) to an otherwise complete event.
const marley::Target & get_target() const
Get a const reference to the Target owned by this Generator.
void set_neutrino_direction(const std::array< double, 3 > &dir_vec)
Sets the direction of the incident neutrinos to use when generating events.
std::string get_state_string() const
Get a string that represents the current internal state of this Generator.
void set_do_deexcitations(bool do_them)
Sets the value of the do_deexcitations flag.
Abstract base class for an approximate representation of a 1D continuous function.
Abstract base class for all objects that describe the incident neutrino energy distribution.
If needed, rotates the coordinate system of a GenEvent so that the projectile 3-momentum lies along a...
Abstract base class that represents a 2 → 2 scattering reaction.
Container for nuclear structure information organized by nuclide.
Description of a macroscopic target for scattering reactions.
EventProcessor that assigns event weights.