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::ResponseTable Class Reference

A table of nuclear responses for computing inclusive cross sections. More...

#include <ResponseTable.hh>

Public Member Functions

 ResponseTable (std::shared_ptr< std::vector< double > > &wvec, std::shared_ptr< std::vector< double > > &qvec, std::shared_ptr< std::vector< NuclearResponses > > &resp)
 
const std::vector< NuclearResponses > & get_responses () const
 Access the nuclear responses.
 
NuclearResponses interpolate (double w, double q) const
 
const std::vector< double > & q_grid () const
 Access the 3-momentum transfer grid points.
 
double q_max () const
 Retrieve the maximum q value.
 
double q_min () const
 Retrieve the minimum q value.
 
size_t response_index (size_t iw, size_t iq) const
 
const std::vector< double > & w_grid () const
 Access the energy transfer grid points.
 
double w_max () const
 Retrieve the maximum ω value.
 
double w_min () const
 Retrieve the minimum ω value.
 

Protected Member Functions

bool get_neighbor_indices (const std::vector< double > &vec, double val, size_t &lower_index, size_t &upper_index) const
 

Protected Attributes

std::shared_ptr< std::vector< double > > qvec_
 Grid points along the q-axis.
 
std::shared_ptr< std::vector< NuclearResponses > > responses_
 Sets of nuclear responses evaluated at each grid point.
 
std::shared_ptr< std::vector< double > > wvec_
 Grid points along the w-axis.
 

Detailed Description

A table of nuclear responses for computing inclusive cross sections.

Definition at line 32 of file ResponseTable.hh.

Constructor & Destructor Documentation

◆ ResponseTable() [1/2]

marley::ResponseTable::ResponseTable ( )
inline

Definition at line 35 of file ResponseTable.hh.

35{}

◆ ResponseTable() [2/2]

marley::ResponseTable::ResponseTable ( std::shared_ptr< std::vector< double > > & wvec,
std::shared_ptr< std::vector< double > > & qvec,
std::shared_ptr< std::vector< NuclearResponses > > & resp )
inline

Definition at line 37 of file ResponseTable.hh.

40 : wvec_( wvec ), qvec_( qvec ), responses_( resp ) {}
std::shared_ptr< std::vector< double > > wvec_
Grid points along the w-axis.
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.

Member Function Documentation

◆ get_neighbor_indices()

bool marley::ResponseTable::get_neighbor_indices ( const std::vector< double > & vec,
double val,
size_t & lower_index,
size_t & upper_index ) const
protected

Determines the indices for the two gridpoints surrounding a requested one-dimensional coordinate. If the coordinate is outside of the grid, then this function returns the two closest grid points.

Parameters
[in]vecA vector of grid point coordinates
[in]valThe requested x or y coordinate
[out]lower_indexThe index of the closest grid point less than or equal to the requested value, or the lower of the two nearest grid points if the value falls outside of the grid
[out]upper_indexThe index of the closest grid point greater than the requested value, or the higher of the two nearest grid points if the value falls outside of the grid
Returns
true if the requested value is within the grid, or false otherwise

Definition at line 61 of file ResponseTable.cc.

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}

Referenced by interpolate().

◆ get_responses()

const std::vector< NuclearResponses > & marley::ResponseTable::get_responses ( ) const
inline

Access the nuclear responses.

Definition at line 61 of file ResponseTable.hh.

62 { return *responses_; }

References responses_.

◆ interpolate()

marley::NuclearResponses marley::ResponseTable::interpolate ( double w,
double q ) const

Use simple bilinear interpolation to compute a set of nuclear responses

Definition at line 20 of file ResponseTable.cc.

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()" );
29 return marley::NuclearResponses();
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}
double q_max() const
Retrieve the maximum q value.
double w_max() const
Retrieve the maximum ω value.
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
double w_min() const
Retrieve the minimum ω value.
double q_min() const
Retrieve the minimum q value.

References get_neighbor_indices(), q_max(), q_min(), qvec_, response_index(), responses_, w_max(), w_min(), and wvec_.

◆ q_grid()

const std::vector< double > & marley::ResponseTable::q_grid ( ) const
inline

Access the 3-momentum transfer grid points.

Definition at line 58 of file ResponseTable.hh.

58{ return *qvec_; }

References qvec_.

◆ q_max()

double marley::ResponseTable::q_max ( ) const
inline

Retrieve the maximum q value.

Definition at line 52 of file ResponseTable.hh.

52{ return qvec_->back(); }

References qvec_.

Referenced by interpolate().

◆ q_min()

double marley::ResponseTable::q_min ( ) const
inline

Retrieve the minimum q value.

Definition at line 49 of file ResponseTable.hh.

49{ return qvec_->front(); }

References qvec_.

Referenced by interpolate().

◆ response_index()

size_t marley::ResponseTable::response_index ( size_t iw,
size_t iq ) const
inline

Calculates the index in the vector of responses that corresponds to a given set of ω and q indices

Parameters
[in]iwIndex of the desired grid point on the ω axis
[in]iqIndex of the desired grid point on the q axis

Definition at line 68 of file ResponseTable.hh.

68 {
69 size_t num_q_points = qvec_->size();
70 size_t r_idx = ( num_q_points * iw ) + iq;
71 return r_idx;
72 }

References qvec_.

Referenced by interpolate().

◆ w_grid()

const std::vector< double > & marley::ResponseTable::w_grid ( ) const
inline

Access the energy transfer grid points.

Definition at line 55 of file ResponseTable.hh.

55{ return *wvec_; }

References wvec_.

◆ w_max()

double marley::ResponseTable::w_max ( ) const
inline

Retrieve the maximum ω value.

Definition at line 46 of file ResponseTable.hh.

46{ return wvec_->back(); }

References wvec_.

Referenced by interpolate().

◆ w_min()

double marley::ResponseTable::w_min ( ) const
inline

Retrieve the minimum ω value.

Definition at line 43 of file ResponseTable.hh.

43{ return wvec_->front(); }

References wvec_.

Referenced by interpolate().

Member Data Documentation

◆ qvec_

std::shared_ptr< std::vector<double> > marley::ResponseTable::qvec_
protected

Grid points along the q-axis.

Definition at line 84 of file ResponseTable.hh.

Referenced by interpolate(), q_grid(), q_max(), q_min(), and response_index().

◆ responses_

std::shared_ptr< std::vector<NuclearResponses> > marley::ResponseTable::responses_
protected

Sets of nuclear responses evaluated at each grid point.

Definition at line 87 of file ResponseTable.hh.

Referenced by get_responses(), and interpolate().

◆ wvec_

std::shared_ptr< std::vector<double> > marley::ResponseTable::wvec_
protected

Grid points along the w-axis.

Definition at line 81 of file ResponseTable.hh.

Referenced by interpolate(), w_grid(), w_max(), and w_min().


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