7#ifndef LHAPDF_KnotArray_H
8#define LHAPDF_KnotArray_H
10#include "LHAPDF/Exceptions.h"
11#include "LHAPDF/Utils.h"
21 inline size_t indexbelow(
double value,
const std::vector<
double>& knots) {
22 const size_t n = knots.size();
23 const double* b = knots.data();
24 const double* e = b + n;
26 size_t i = std::upper_bound(b, e, value) - b;
27 if (i >= n) i = n - 1;
31 int findPidInPids(
int pid,
const std::vector<
int>& pids) {
32 std::vector<
int>::const_iterator it = std::find(pids.begin(), pids.end(), pid);
37 return static_cast<
int>(std::distance(pids.begin(), it));
64 bool empty()
const {
return _grid.empty(); }
73 double xf(
int ix,
int iq2,
int ipid)
const {
74 return _grid[ix*_shape[2]*_shape[1] + iq2*_shape[2] + ipid];
80 const double&
coeff(
int ix,
int iq2,
int pid,
int in)
const {
81 return _coeffs[ix*(_shape[1])*_shape[2]*4 + iq2*_shape[2]*4 + pid*4 + in];
85 int lookUpPid(size_t id)
const {
return _lookup[id]; }
88 double xs(size_t id)
const {
return _xs[id]; }
91 double logxs(size_t id)
const {
return _logxs[id]; }
94 double q2s(size_t id)
const {
return _q2s[id]; }
97 double logq2s(size_t id)
const {
return _logq2s[id]; }
106 if (x < _xs.front())
return false;
107 if (x > _xs.back())
return false;
113 if (q2 < _q2s.front())
return false;
114 if (q2 > _q2s.back())
return false;
123 if (-6 <= id && id <= 6)
return _lookup[id + 6];
124 else if (id == 21)
return _lookup[0 + 6];
125 else if (id == 22)
return _lookup[13];
126 else return findPidInPids(id, _pids);
144 const std::vector<
double>& xs()
const {
return _xs; }
146 const std::vector<
double>& logxs()
const {
return _logxs; }
148 const std::vector<
double>& q2s()
const {
return _q2s; }
150 const std::vector<
double>& logq2s()
const {
return _logq2s; }
158 std::vector<
double>& setCoeffs() {
return _coeffs; }
160 std::vector<
double>& setGrid() {
return _grid; }
162 std::vector<
double>& setxknots() {
return _xs; }
164 std::vector<
double>& setq2knots() {
return _q2s; }
166 std::vector<size_t>& setShape() {
return _shape; }
168 std::vector<
int>& setPids() {
return _pids; }
188 std::vector<
int> _lookup;
192 std::vector<
double> _xs;
193 std::vector<
double> _q2s;
194 std::vector<
double> _logxs;
195 std::vector<
double> _logq2s;
212 AlphaSArray(
const std::vector<
double>& q2knots,
const std::vector<
double>& as)
235 if (q2 < q2s().front())
throw AlphaSError(
"Q2 value " + to_str(q2) +
" is lower than lowest-Q2 grid point at " + to_str(q2s().front()));
236 if (q2 > q2s().back())
throw AlphaSError(
"Q2 value " + to_str(q2) +
" is higher than highest-Q2 grid point at " + to_str(q2s().back()));
238 size_t i = upper_bound(q2s().begin(), q2s().end(), q2) - q2s().begin();
239 if (i == q2s().size()) i -= 1;
249 if (logq2 < logq2s().front())
throw GridError(
"logQ2 value " + to_str(logq2) +
" is lower than lowest-logQ2 grid point at " + to_str(logq2s().front()));
250 if (logq2 > logq2s().back())
throw GridError(
"logQ2 value " + to_str(logq2) +
" is higher than highest-logQ2 grid point at " + to_str(logq2s().back()));
252 size_t i = upper_bound(logq2s().begin(), logq2s().end(), logq2) - logq2s().begin();
253 if (i == logq2s().size()) i -= 1;
279 return (alphas()[i+1] - alphas()[i]) / (logq2s()[i+1] - logq2s()[i]);
284 return (alphas()[i] - alphas()[i-1]) / (logq2s()[i] - logq2s()[i-1]);
289 return 0.5 * (ddlogq_forward(i) + ddlogq_backward(i));
299 _logq2s.resize(_q2s.size());
300 for (size_t i = 0; i < _q2s.size(); ++i) _logq2s[i] = log(_q2s[i]);
Internal storage class for alpha_s interpolation grids.
Definition KnotArray.h:202
size_t iq2below(double q2) const
Definition KnotArray.h:233
const std::vector< double > & logq2s() const
log(Q2) knot vector accessor
Definition KnotArray.h:228
std::vector< double > _as
List of alpha_s values across the knot array.
Definition KnotArray.h:308
AlphaSArray(const std::vector< double > &q2knots, const std::vector< double > &as)
Constructor from Q2 knot values and alpha_s values.
Definition KnotArray.h:212
std::vector< double > _logq2s
List of log(Q2) knots.
Definition KnotArray.h:306
AlphaSArray()
Default constructor just for std::map insertability.
Definition KnotArray.h:209
double ddlogq_forward(size_t i) const
Forward derivative w.r.t. logQ2.
Definition KnotArray.h:278
std::vector< double > _q2s
List of Q2 knots.
Definition KnotArray.h:304
void _syncq2s()
Synchronise the log(Q2) array from the Q2 one.
Definition KnotArray.h:298
const std::vector< double > & q2s() const
Q2 knot vector accessor.
Definition KnotArray.h:225
double ddlogq_backward(size_t i) const
Backward derivative w.r.t. logQ2.
Definition KnotArray.h:283
size_t ilogq2below(double logq2) const
Definition KnotArray.h:247
double ddlogq_central(size_t i) const
Central (avg of forward and backward) derivative w.r.t. logQ2.
Definition KnotArray.h:288
const std::vector< double > & alphas() const
alpha_s value accessor (const)
Definition KnotArray.h:265
Internal storage class for PDF data point grids.
Definition KnotArray.h:49
std::vector< int > _pids
Order the PIDs are filled in.
Definition KnotArray.h:187
size_t ixbelow(double x) const
Find the largest grid index below given x, such that xknots[index] < x.
Definition KnotArray.h:67
const double & coeff(int ix, int iq2, int pid, int in) const
Convenient accessor to the polynomial coefficients.
Definition KnotArray.h:80
size_t q2size() const
How many q2 knots are there.
Definition KnotArray.h:61
int lookUpPid(size_t id) const
Accessor to the internal 'lookup table' for the pid's.
Definition KnotArray.h:85
double logxs(size_t id) const
Set of log10(x) knots.
Definition KnotArray.h:91
size_t shape(size_t id) const
Shape of the interpolation grid.
Definition KnotArray.h:102
bool inRangeX(double x) const
Check if value within the boundaries of xknots.
Definition KnotArray.h:105
double xs(size_t id) const
Set of x knots.
Definition KnotArray.h:88
double logq2s(size_t id) const
Set of log10(Q2) knots.
Definition KnotArray.h:97
std::vector< size_t > _shape
Shape of the interpolation grid.
Definition KnotArray.h:178
size_t numflavs() const
How many flavours are stored in the grid.
Definition KnotArray.h:55
double q2s(size_t id) const
Set of Q2 knots.
Definition KnotArray.h:94
std::vector< double > _coeffs
Storage for the precomputed polynomial coefficients.
Definition KnotArray.h:184
double xf(int ix, int iq2, int ipid) const
Convenient accessor to the grid values.
Definition KnotArray.h:73
int get_pid(int id) const
Definition KnotArray.h:119
bool inRangeQ2(double q2) const
Check if value within the boundaries of q2knots.
Definition KnotArray.h:112
std::vector< double > _grid
Grid values.
Definition KnotArray.h:181
size_t xsize() const
How many x knots are there.
Definition KnotArray.h:58
size_t size() const
How many flavours are stored in the grid.
Definition KnotArray.h:53
bool has_pid(int id) const
Definition KnotArray.h:130
size_t iq2below(double q2) const
Find the largest grid index below given q2, such that q2knots[index] < q2.
Definition KnotArray.h:70
bool empty() const
Is this container empty?
Definition KnotArray.h:64
Namespace for all LHAPDF functions and classes.
Definition AlphaS.h:14