MARLEY (Model of Argon Reaction Low Energy Yields)  v1.1.0
A Monte Carlo event generator for tens-of-MeV neutrino-nucleus interactions in liquid argon
 All Classes Functions Variables Enumerations Pages
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.
 
 Generator (uint_fast64_t seed)
 Create a Generator using default settings except for a given initial seed. More...
 
 Generator (marley::ConfigurationFile &cf)
 Create a Generator using a ConfigurationFile object.
 
 Generator (const std::string &filename)
 Create a Generator using a configuration file. More...
 
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, Reaction, and StructureDatabase objects owned by this Generator.
 
double E_pdf (double E)
 Probability density function that describes the distribution of reacting neutrino energies. 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.
 
uint_fast64_t get_seed () const
 Get the seed used to initialize this Generator.
 
const marley::NeutrinoSourceget_source ()
 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 std::array< double, 3 > & neutrino_direction ()
 Gets the direction of the incident neutrinos that is used when generating events.
 
double rejection_sample (std::function< double(double)> f, double xmin, double xmax, 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) This template function.
 
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_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_weight_flux (bool should_we_weight)
 Sets the value of the weight_flux flag. 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.

Constructor & Destructor Documentation

marley::Generator::Generator ( uint_fast64_t  seed)

Create a Generator using default settings except for a given initial seed.

Parameters
seedThe initial seed to use for this Generator
marley::Generator::Generator ( const std::string &  filename)

Create a Generator using a configuration file.

Parameters
filenameName of the configuration file

Member Function Documentation

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
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)
const marley::NeutrinoSource & marley::Generator::get_source ( )

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

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

double marley::Generator::rejection_sample ( std::function< double(double)>  f,
double  xmin,
double  xmax,
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.

Todo:
Check the convergence explanation for the first step.
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
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().

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.
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
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.

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: