MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Public Member Functions | List of all members
marley::Generator Class Reference

The MARLEY Event generator. More...

#include <Generator.hh>

Public Member Functions

 Generator ()
 Create a Generator using default settings.
 
void add_reaction (std::unique_ptr< marley::Reaction > reaction)
 Take ownership of a new Reaction. More...
 
void clear_reactions ()
 Clear the vector of Reaction objects owned by this Generator.
 
marley::Event create_event ()
 Create an Event using the NeutrinoSource, Target, Reaction, and StructureDatabase objects owned by this Generator.
 
marley::Event create_event (int pdg_a, double KEa, int pdg_atom, const std::array< double, 3 > &dir_vec)
 Creates an event object for a fixed projectile species, kinetic energy, and atomic target. More...
 
double E_pdf (double E)
 Probability density function that describes the distribution of reacting neutrino energies. More...
 
double flux_averaged_total_xs () const
 Computes the flux-averaged total cross section for all enabled neutrino reactions, taking target atom fractions into account as appropriate. More...
 
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.
 
marley::ProjectileDirectionRotatorget_rotator ()
 Provides access to the owned ProjectileDirectionRotator.
 
uint_fast64_t get_seed () const
 Get the seed used to initialize this Generator.
 
const marley::NeutrinoSourceget_source () const
 Get a const reference to the NeutrinoSource owned by this Generator. More...
 
std::string get_state_string () const
 Get a string that represents the current internal state of this Generator.
 
marley::StructureDatabaseget_structure_db ()
 Get a reference to the StructureDatabase owned by this Generator.
 
const marley::Targetget_target () const
 Get a const reference to the Target owned by this Generator. More...
 
double inverse_transform_sample (const marley::ChebyshevInterpolatingFunction &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 bisection. More...
 
double inverse_transform_sample (const std::function< double(double)> &f, double xmin, double xmax, double bisection_tolerance=1e-12)
 Sample from a given 1D probability density function f(x) on the interval [xmin, xmax] using an inverse transform technique. More...
 
const std::array< double, 3 > & neutrino_direction ()
 Gets the direction of the incident neutrinos that is used when generating events.
 
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 rejection method. More...
 
void reseed (uint_fast64_t seed)
 Reseeds the Generator.
 
template<class RandomNumberDistribution >
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 operator()(std::mt19937_64&) function) @detail This template function is based on https://stackoverflow.com/a/9154394/4081973.
 
template<class RandomNumberDistribution , typename ParamType >
auto sample_from_distribution (RandomNumberDistribution &rnd, const ParamType &params) -> 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 operator()(std::mt19937_64&, const ParamType&) function) using the parameters params.
 
marley::Reactionsample_reaction (double &E)
 Sample a Reaction and an energy for the reacting neutrino. More...
 
void seed_using_state_string (const std::string &state_string)
 Use a string to set this Generator's internal state. More...
 
void set_do_deexcitations (bool do_them)
 Sets the value of the do_deexcitations flag. More...
 
void set_neutrino_direction (const std::array< double, 3 > &dir_vec)
 Sets the direction of the incident neutrinos to use when generating events. More...
 
void set_source (std::unique_ptr< marley::NeutrinoSource > source)
 Take ownership of a new NeutrinoSource, replacing any existing source owned by this Generator. More...
 
void set_target (std::unique_ptr< marley::Target > target)
 Take ownership of a new Target, replacing any existing target owned by this Generator. More...
 
void set_weight_flux (bool should_we_weight)
 Sets the value of the weight_flux flag. More...
 
double total_xs (int pdg_a, double KEa) const
 Computes the abundance-weighted total cross section at fixed energy for all configured reactions. More...
 
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 target atom. More...
 
double uniform_random_double (double min, double max, bool inclusive)
 Sample a random number uniformly on either [min, max) or [min, max]. More...
 

Detailed Description

The MARLEY Event generator.

Member Function Documentation

◆ add_reaction()

void marley::Generator::add_reaction ( std::unique_ptr< marley::Reaction reaction)

Take ownership of a new Reaction.

Parameters
reactionA pointer to the new Reaction to use

◆ create_event()

marley::Event marley::Generator::create_event ( int  pdg_a,
double  KEa,
int  pdg_atom,
const std::array< double, 3 > &  dir_vec 
)

Creates an event object for a fixed projectile species, kinetic energy, and atomic target.

If no energetically-accessible reaction is available for the given input parameters, then a marley::Error will be thrown.

Note
This function is not used as part of the normal MARLEY workflow. It serves as part of an API that enables MARLEY to be interfaced with an external flux driver.
Parameters
pdg_aThe PDG code for the projectile
KEaThe kinetic energy of the projectile (MeV)
pdg_atomThe nuclear PDG code for the atomic target
dir_vecDirection three-vector of the projectile

◆ E_pdf()

double marley::Generator::E_pdf ( double  E)

Probability density function that describes the distribution of reacting neutrino energies.

This function computes the cross-section weighted neutrino flux (normalized to unity between source_->E_min and source_->E_max) including cross-section contributions from all Reactions owned by this Generator. For the distribution of incident neutrino energies, use marley::NeutrinoSource::pdf()

Parameters
ETotal energy of the reacting neutrino
Returns
Probability density (MeV -1)

◆ flux_averaged_total_xs()

double marley::Generator::flux_averaged_total_xs ( ) const

Computes the flux-averaged total cross section for all enabled neutrino reactions, taking target atom fractions into account as appropriate.

If flux weighting is disabled (via a call to set_weight_flux()) then this function will return zero

Returns
Total cross section (MeV -2)

◆ get_source()

const marley::NeutrinoSource & marley::Generator::get_source ( ) const

Get a const reference to the NeutrinoSource owned by this Generator.

Throws a marley::Error if this Generator does not own a NeutrinoSource object.

◆ get_target()

const marley::Target & marley::Generator::get_target ( ) const

Get a const reference to the Target owned by this Generator.

Throws a marley::Error if this Generator does not own a Target object.

◆ inverse_transform_sample() [1/2]

double marley::Generator::inverse_transform_sample ( const marley::ChebyshevInterpolatingFunction 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 bisection.

Parameters
cdfCumulative density function to use for sampling
xminLower bound of the sampling interval
xmaxUpper bound of the sampling interval
Returns
Sampled value of x

◆ inverse_transform_sample() [2/2]

double marley::Generator::inverse_transform_sample ( const std::function< double(double)> &  f,
double  xmin,
double  xmax,
double  bisection_tolerance = 1e-12 
)

Sample from a given 1D probability density function f(x) on the interval [xmin, xmax] using an inverse transform technique.

Parameters
fProbability density function to use for sampling
xminLower bound of the sampling interval
xmaxUpper bound of the sampling interval
Returns
Sampled value of x
Todo:
Remove hard-coded number of points here

◆ rejection_sample()

double marley::Generator::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 rejection method.

Parameters
fProbability density function to use for sampling
xminLower bound of the sampling interval
xmaxUpper bound of the sampling interval
max_search_toleranceTolerance to use when finding the maximum of f(x) using Brent's method
Returns
Sampled value of x

The rejection method used by this function consists of the following steps:

  1. Find the maximum of the function f(x) on [xmin, xmax]
  2. Sample an x value uniformly over f(x)'s domain
  3. Sample a y value uniformly over [0, max(f(x))]
  4. If y <= f(x), accept the sampled x value
  5. If y > f(x), reject the sampled x value, and return to step 2 to try again

Note that f(x) does not need to be normalized, but its range must be nonnegative. In the first step, an iterative method (Brent's method) is used to find the maximum of f(x). The iterations will continue until two successive iterations agree within max_search_tolerance on the location of the maximum of f(x). To avoid problems with functions that yield double values that are small compared to a typical value of max_search_tolerance (say, max_search_tolerance = 1e-8, while many neutrino cross sections of interest for MARLEY are less than 1e-40 cm^2), MARLEY normalizes all probability density functions to unity before using rejection sampling.

◆ sample_reaction()

marley::Reaction & marley::Generator::sample_reaction ( double &  E)

Sample a Reaction and an energy for the reacting neutrino.

Parameters
[out]ETotal energy of the neutrino undergoing the reaction
Returns
Reference to the sampled Reaction owned by this Generator

◆ seed_using_state_string()

void marley::Generator::seed_using_state_string ( const std::string &  state_string)

Use a string to set this Generator's internal state.

This function is typically used to restore a Generator to a state saved using get_state_string().

◆ set_do_deexcitations()

void marley::Generator::set_do_deexcitations ( bool  do_them)
inline

Sets the value of the do_deexcitations flag.

This should almost always be true. Use only if you know what you are doing.

◆ set_neutrino_direction()

void marley::Generator::set_neutrino_direction ( const std::array< double, 3 > &  dir_vec)

Sets the direction of the incident neutrinos to use when generating events.

Parameters
dir_vecVector that points in the direction of the incident neutrinos
Note
The dir_vec passed to this function does not need to be normalized, but it must have at least one nonzero element or a marley::Error will be thrown.

◆ set_source()

void marley::Generator::set_source ( std::unique_ptr< marley::NeutrinoSource source)

Take ownership of a new NeutrinoSource, replacing any existing source owned by this Generator.

Parameters
sourceA pointer to the new NeutrinoSource to use

◆ set_target()

void marley::Generator::set_target ( std::unique_ptr< marley::Target target)

Take ownership of a new Target, replacing any existing target owned by this Generator.

Parameters
sourceA pointer to the new Target to use

◆ set_weight_flux()

void marley::Generator::set_weight_flux ( bool  should_we_weight)

Sets the value of the weight_flux flag.

This is potentially dangerous. Use only if you know what you are doing.

◆ total_xs() [1/2]

double marley::Generator::total_xs ( int  pdg_a,
double  KEa 
) const

Computes the abundance-weighted total cross section at fixed energy for all configured reactions.

Atom fractions in the owned Target are used to perform the weighting by nuclide abundance

Note
This function is not used as part of the normal MARLEY workflow. It exposes the abundance-weighted total cross section for use by the mardumpxs command-line tool (see examples/executables/mardumpxs.cc)
Parameters
pdg_aThe PDG code for the projectile
KEaThe kinetic energy of the projectile (MeV)
Returns
Abundance-weighted total cross section (MeV -2 / atom)

◆ total_xs() [2/2]

double marley::Generator::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 target atom.

Atom fractions in the owned Target are ignored by this function.

Note
This function is not used as part of the normal MARLEY workflow. It serves as part of an API that enables MARLEY to be interfaced with an external flux driver.
Parameters
pdg_aThe PDG code for the projectile
KEaThe kinetic energy of the projectile (MeV)
pdg_atomThe nuclear PDG code for the atomic target
Returns
Total cross section (MeV -2 / atom)

◆ uniform_random_double()

double marley::Generator::uniform_random_double ( double  min,
double  max,
bool  inclusive 
)

Sample a random number uniformly on either [min, max) or [min, max].

Parameters
minLower bound of the sampling interval
maxUpper bound of the sampling interval
inclusiveWhether the upper bound should be included (true) or excluded (false) from the possible sampling outcomes

The documentation for this class was generated from the following files: