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
LinearInterpolatingFunction.cc
1
4//
5// This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6//
7// MARLEY is free software: you can redistribute it and/or modify it under the
8// terms of version 3 of the GNU General Public License as published by the
9// Free Software Foundation.
10//
11// For the full text of the license please see COPYING or
12// visit http://opensource.org/licenses/GPL-3.0
13//
14// Please respect the MCnet academic usage guidelines. See GUIDELINES
15// or visit https://www.montecarlonet.org/GUIDELINES for details.
16
17// Standard library includes
18#include <algorithm>
19#include <cmath>
20#include <iostream>
21#include <limits>
22
23// MARLEY includes
24#include "marley/LinearInterpolatingFunction.hh"
25
26marley::LinearInterpolatingFunction::LinearInterpolatingFunction(
27 const std::function<double(double)>& func, double x_min, double x_max,
28 size_t N )
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<
49}