MARLEY (Model of Argon Reaction Low Energy Yields)  v1.0.0 A Monte Carlo event generator for tens-of-MeV neutrino-nucleus interactions in liquid argon
marley::InterpolationGrid< FirstNumericType, SecondNumericType > Class Template Reference

One-dimensional function y(x) defined using a grid of ordered pairs (x,y) and an interpolation rule. More...

#include <InterpolationGrid.hh>

## Public Types

enum  ExtrapolationMethod { Zero, Endpoint, Continue, Throw }
Method to use for computing y(x) when the x value lies beyond the grid boundaries. More...

using Grid = std::vector< OrderedPair >

using GridConstIterator = typename std::vector< OrderedPair >::const_iterator

enum  InterpolationMethod {
Constant = 1, LinearLinear = 2, LinearLog = 3, LogLinear = 4,
LogLog = 5
}
Method to use for interpolating between (x,y) grid points. More...

using OrderedPair = std::pair< FirstNumericType, SecondNumericType >

## Public Member Functions

InterpolationGrid (InterpolationMethod interp_method=InterpolationMethod::LinearLinear, ExtrapolationMethod extrap_method=ExtrapolationMethod::Zero)
Create an InterpolationGrid without any grid points.

InterpolationGrid (const Grid &grid, InterpolationMethod interp_method=InterpolationMethod::LinearLinear, ExtrapolationMethod extrap_method=ExtrapolationMethod::Zero)
Create an InterpolationGrid from a vector of ordered pairs. More...

InterpolationGrid (const std::vector< FirstNumericType > &xs, const std::vector< SecondNumericType > &ys, InterpolationMethod interp_method=InterpolationMethod::LinearLinear, ExtrapolationMethod extrap_method=ExtrapolationMethod::Zero)
Create an InterpolationGrid from vectors of x and y values.

OrderedPair & at (size_t j)
Get a reference to the jth ordered pair from the grid.

const OrderedPair & back () const
Returns a reference to the last ordered pair.

void clear ()
Delete all ordered pairs from the grid.

ExtrapolationMethod extrapolation_method () const
Get the ExtrapolationMethod used by this InterpolationGrid.

const OrderedPair & front () const
Returns a reference to the first ordered pair.

std::function
< SecondNumericType(FirstNumericType)>
get_interpolating_function ()
Get a std::function object that represents y(x) for this InterpolationGrid.

void insert (FirstNumericType x, SecondNumericType y)
Add a new ordered pair (x, y) to the grid.

SecondNumericType interpolate (FirstNumericType x) const
Compute y(x) using the current InterpolationMethod.

InterpolationMethod interpolation_method () const
Get the InterpolationMethod used by this InterpolationGrid.

GridConstIterator lower_bound (const GridConstIterator &begin, const GridConstIterator &end, FirstNumericType x) const
Returns a const_iterator to the first element of the grid for which the x value is not less than (i.e. greater than or equal to) x.

void set_interpolationMethod (InterpolationMethod method)
Set the InterpolationMethod to use.

void set_interpolationMethod (ExtrapolationMethod method)
Set the ExtrapolationMethod to use.

size_t size () const
Get the number of ordered pairs on the grid.

GridConstIterator upper_bound (const GridConstIterator &begin, const GridConstIterator &end, FirstNumericType x) const
Returns a const_iterator to the first element of the grid for which the x value is greater than x.

## Detailed Description

### template<typename FirstNumericType, typename SecondNumericType = FirstNumericType> class marley::InterpolationGrid< FirstNumericType, SecondNumericType >

One-dimensional function y(x) defined using a grid of ordered pairs (x,y) and an interpolation rule.

This class implements the one-dimensional interpolation rules described in the ENDF-6 formats manual for a grid of (x,y) pairs.

Template Parameters
 FirstNumericType type for the x values SecondNumericType type for the y values

## Member Enumeration Documentation

template<typename FirstNumericType, typename SecondNumericType = FirstNumericType>

Method to use for computing y(x) when the x value lies beyond the grid boundaries.

The table below describes how y(x) is calculated using each of the allowed ExtrapolationMethod settings. In the notation used below, the lowest x value is called $$x_\text{left}$$, the greatest x value is called $$x_\text{right}$$, and their corresponding y values are called $$y_\text{left}$$ and $$y_\text{right}$$, respectively. The ExtrapolationMethod is only relevant when $$x < x_\text{left}$$ or $$x > x_\text{right}$$.

Extrapolation Methods
MethodDescription
Zero$$y = 0$$
Endpoint$$y = \begin{cases} y_\text{left} & x < x_\text{left} \newline y_\text{right} & x > x_\text{right} \end{cases}$$
ContinueUse the usual InterpolationMethod formula with
$$y = \begin{cases} y_1 = y_\text{left} \text{ and } y_2 = y_{\text{left}+1} & x < x_\text{left} \newline y_1 = y_{\text{right}-1} \text{ and } y_2 = y_\text{right} & x > x_\text{right} \end{cases}$$
where $$y_{\text{left}+1}$$ is the y value corresponding to the second-lowest x value, and $$y_{\text{right}-1}$$ is the y value corresponding to the second-highest x value.
template<typename FirstNumericType, typename SecondNumericType = FirstNumericType>

Method to use for interpolating between (x,y) grid points.

For $$x_1 \leq x < x_2$$, the table below describes how the corresponding y value is calculated using each of the allowed InterpolationMethod settings.

Interpolation Methods
MethodDescription
Constant$$y = y_1$$
LinearLinear$$y = y_1 + \frac{y_2 - y_1}{x_2 - x_1}(x - x_1)$$
LinearLog$$y = \exp\left[\ln(y_1) + \frac{\ln(y_2) - \ln(y_1)}{x_2 - x_1}(x - x_1)\right]$$
LogLinear$$y = y_1 + \frac{y_2 - y_1}{\ln[x_2] - \ln[x_1]}[\ln(x) - \ln(x_1)]$$
LogLog$$y = \exp\left[\ln(y_1) + \frac{\ln(y_2) - \ln(y_1)}{\ln(x_2) - \ln(x_1)}(\ln[x] - \ln[x_1])\right]$$

## Constructor & Destructor Documentation

template<typename FirstNumericType, typename SecondNumericType = FirstNumericType>
 marley::InterpolationGrid< FirstNumericType, SecondNumericType >::InterpolationGrid ( const Grid & grid, InterpolationMethod interp_method = InterpolationMethod::LinearLinear, ExtrapolationMethod extrap_method = ExtrapolationMethod::Zero )
inline

Create an InterpolationGrid from a vector of ordered pairs.

Todo:
Add error checks for the supplied grid

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