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
ResponseTable.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#include "marley/Error.hh"
18#include "marley/ResponseTable.hh"
19
21 double q ) const
22{
23 // Return a dummy value if the point lies outside the grid boundaries
24 if ( w < this->w_min() || w > this->w_max()
25 || q < this->q_min() || q > this->q_max() )
26 {
27 throw marley::Error( "Outside of grid bounds in marley::ResponseTable::"
28 "interpolate()" );
30 }
31
32 // Find the indices of the grid points on either side of the desired w and
33 // q values.
34 size_t iw_low, iw_hi, iq_low, iq_high;
35 this->get_neighbor_indices( *wvec_, w, iw_low, iw_hi );
36 this->get_neighbor_indices( *qvec_, q, iq_low, iq_high );
37
38 // Get the w and q values corresponding to the nearest-neighbor grid
39 // points found above
40 double w1 = wvec_->at( iw_low );
41 double w2 = wvec_->at( iw_hi );
42 double q1 = qvec_->at( iq_low );
43 double q2 = qvec_->at( iq_high );
44
45 // Retrieve the nuclear responses at each of the four grid points of
46 // interest
47 const auto& r11 = responses_->at( this->response_index(iw_low, iq_low) );
48 const auto& r21 = responses_->at( this->response_index(iw_hi, iq_low) );
49 const auto& r12 = responses_->at( this->response_index(iw_low, iq_high) );
50 const auto& r22 = responses_->at( this->response_index(iw_hi, iq_high) );
51
52 // Perform the interpolation (first q, then w)
53 NuclearResponses r1 = r11 * (q2 - q)/(q2 - q1) + r12 * (q - q1)/(q2 - q1);
54 NuclearResponses r2 = r21 * (q2 - q)/(q2 - q1) + r22 * (q - q1)/(q2 - q1);
55 NuclearResponses r = r1 * (w2 - w)/(w2 - w1) + r2 * (w - w1)/(w2 - w1);
56
57 // Return the result
58 return r;
59}
60
62 const std::vector<double>& vec, double val, size_t& lower_index,
63 size_t& upper_index ) const
64{
65 if ( vec.size() < 2u ) {
66 throw marley::Error( "Vector with fewer than two entries passed to"
67 " marley::ResponseTable::get_neighbor_indices()" );
68 }
69
70 bool within = true;
71
72 auto begin = vec.cbegin();
73 auto end = vec.cend();
74
75 // std::lower_bound returns an iterator to the first element of the
76 // container which is not less than the supplied value
77 auto not_less_point = std::lower_bound( begin, end, val );
78
79 decltype( begin ) lower_point;
80
81 // Check whether the requested grid point is within the grid limits
82 if ( not_less_point == begin ) {
83 lower_point = begin;
84 // first element of vec > val
85 if ( *begin != val ) within = false;
86 }
87 else if ( not_less_point == end ) {
88 // last element of vec < val
89 within = false;
90 lower_point = end - 2;
91 }
92 else {
93 // x is within the grid limits
94 lower_point = not_less_point - 1;
95 }
96
97 lower_index = std::distance( begin, lower_point );
98 upper_index = lower_index + 1;
99
100 return within;
101}
Base class for all exceptions thrown by MARLEY functions.
Definition Error.hh:26
double q_max() const
Retrieve the maximum q value.
double w_max() const
Retrieve the maximum ω value.
std::shared_ptr< std::vector< double > > wvec_
Grid points along the w-axis.
size_t response_index(size_t iw, size_t iq) const
bool get_neighbor_indices(const std::vector< double > &vec, double val, size_t &lower_index, size_t &upper_index) const
std::shared_ptr< std::vector< NuclearResponses > > responses_
Sets of nuclear responses evaluated at each grid point.
std::shared_ptr< std::vector< double > > qvec_
Grid points along the q-axis.
double w_min() const
Retrieve the minimum ω value.
NuclearResponses interpolate(double w, double q) const
double q_min() const
Retrieve the minimum q value.