MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
marley::LinearInterpolatingFunction Class Reference

Approximates a 1D function using linear interpolation on a grid of regularly-spaced points. More...

#include <LinearInterpolatingFunction.hh>

Inheritance diagram for marley::LinearInterpolatingFunction:
marley::InterpolatingFunction

Public Member Functions

 LinearInterpolatingFunction (const std::function< double(double) > &func, double x_min, double x_max, size_t N=DEFAULT_N_LINEAR)
 
double evaluate (double x) const override
 Returns an approximate value of the represented function.
 
int N () const
 
- Public Member Functions inherited from marley::InterpolatingFunction
 InterpolatingFunction (double x_min, double x_max)
 

Protected Attributes

std::shared_ptr< InterpolationGrid< double, double > > interp_grid_
 
- Protected Attributes inherited from marley::InterpolatingFunction
double x_max_
 Upper bound of the interpolation range.
 
double x_min_
 Lower bound of the interpolation range.
 

Additional Inherited Members

- Protected Member Functions inherited from marley::InterpolatingFunction
 InterpolatingFunction ()
 Allows construction by derived classes without immediately defining the bounds of the interpolation range.
 

Detailed Description

Approximates a 1D function using linear interpolation on a grid of regularly-spaced points.

Definition at line 31 of file LinearInterpolatingFunction.hh.

Constructor & Destructor Documentation

◆ LinearInterpolatingFunction()

marley::LinearInterpolatingFunction::LinearInterpolatingFunction ( const std::function< double(double) > & func,
double x_min,
double x_max,
size_t N = DEFAULT_N_LINEAR )

Definition at line 26 of file LinearInterpolatingFunction.cc.

29 : marley::InterpolatingFunction( x_min, x_max )
30{
31 // Force at least two points to be used
32 // TODO: add error handling here
33 if ( N < 2u ) N = 2u;
34
35 std::vector< double > x_vec;
36 std::vector< double > y_vec;
37
38 double dx = ( x_max - x_min ) / ( N - 1 );
39 for ( size_t s = 0u; s < N; ++s ) {
40 double x = x_min + s*dx;
41 double y = func( x );
42
43 x_vec.push_back( x );
44 y_vec.push_back( y );
45 }
46
47 interp_grid_ = std::make_shared<
48 marley::InterpolationGrid< double, double > >( x_vec, y_vec );
49}

Member Function Documentation

◆ evaluate()

double marley::LinearInterpolatingFunction::evaluate ( double x) const
inlineoverridevirtual

Returns an approximate value of the represented function.

Implements marley::InterpolatingFunction.

Definition at line 38 of file LinearInterpolatingFunction.hh.

38 {
39 return interp_grid_->interpolate( x );
40 }

Referenced by marley::CachedOpticalModel::transmission_coefficient().

◆ N()

int marley::LinearInterpolatingFunction::N ( ) const
inline

Definition at line 42 of file LinearInterpolatingFunction.hh.

42{ return interp_grid_->size(); }

Member Data Documentation

◆ interp_grid_

std::shared_ptr< InterpolationGrid<double, double> > marley::LinearInterpolatingFunction::interp_grid_
protected

Definition at line 46 of file LinearInterpolatingFunction.hh.


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