LHAPDF 6.5.6
Loading...
Searching...
No Matches
Interpolator.h
1// -*- C++ -*-
2//
3// This file is part of LHAPDF
4// Copyright (C) 2012-2024 The LHAPDF collaboration (see AUTHORS for details)
5//
6#pragma once
7#ifndef LHAPDF_Interpolator_H
8#define LHAPDF_Interpolator_H
9
10#include "LHAPDF/Utils.h"
11#include "LHAPDF/KnotArray.h"
12
13namespace LHAPDF {
14
15
16 // Forward declaration
17 class GridPDF;
18
19
20 /// The general interface for interpolating between grid points
22 public:
23
24 /// Destructor to allow inheritance
25 virtual ~Interpolator() { }
26
27
28 /// @name Binding to a PDF object
29 ///@{
30
31 /// Bind to a GridPDF
32 void bind(const GridPDF* pdf) { _pdf = pdf; }
33
34 /// Unbind from GridPDF
35 void unbind() { _pdf = 0; }
36
37 /// Identify whether this Interpolator has an associated PDF
38 bool hasPDF() { return _pdf != 0; }
39
40 /// Get the associated GridPDF
41 const GridPDF& pdf() const { return *_pdf; }
42
43 ///@}
44
45
46 /// @name Interpolation methods
47 ///@{
48
49 /// Interpolate a single-point in (x,Q)
50 double interpolateXQ(int id, double x, double q) const {
51 return interpolateXQ2(id, x, q*q);
52 }
53
54 /// Interpolate a single-point in (x,Q2)
55 double interpolateXQ2(int id, double x, double q2) const;
56
57 void interpolateXQ2(double x, double q2, std::vector<double>& ret) const;
58
59 /// @todo Make an all-PID version of interpolateQ and Q2?
60
61 ///@}
62
63 /// The name of this type of interpolator
64 ///
65 /// @todo Would name() or scheme() be a better name? "Type" maybe confuses with the language type-system
66 std::string type() const {
67 return _type;
68 }
69
70 /// Set the interpolation type
71 void setType(std::string t) {
72 _type = t;
73 }
74
75
76 protected:
77
78 /// @brief Interpolate a single-point in (x,Q2), given x/Q2 values and subgrid indices.
79 ///
80 /// The key function to be overridden in derived classes: the subgrid and
81 /// x/Q2 index lookup (and their caching) are done centrally in the
82 /// Interpolator base class so do not need to be re-implemented in each
83 /// flavour of interpolator.
84 virtual double _interpolateXQ2(const KnotArray& grid, double x, size_t ix, double q2, size_t iq2, int id) const = 0;
85
86 /// @brief Interpolate a single-point in (x,Q2), given x/Q2 values and subgrid indices, for all 11 standard flavours at once.
87 ///
88 /// This can be overridden in derived classes for a more
89 /// CPU-efficient implementation than the default looping over all
90 /// flavours: often the grid coefficients for the point can be
91 /// efficiently reused for each flavour.
92 virtual void _interpolateXQ2(const KnotArray& grid, double x, size_t ix, double q2, size_t iq2, std::vector<double>& ret) const {
93 ret.clear();
94 ret.reserve(11);
95 for (int pid = -6; pid < 6; pid++) {
96 ret.push_back(_interpolateXQ2(grid, x, ix, q2, iq2, pid));
97 }
98 }
99
100
101 private:
102 const GridPDF* _pdf;
103 std::string _type;
104 };
105
106
107}
108
109#endif
A PDF defined via an interpolation grid.
Definition GridPDF.h:19
The general interface for interpolating between grid points.
Definition Interpolator.h:21
double interpolateXQ2(int id, double x, double q2) const
Interpolate a single-point in (x,Q2).
virtual void _interpolateXQ2(const KnotArray &grid, double x, size_t ix, double q2, size_t iq2, std::vector< double > &ret) const
Interpolate a single-point in (x,Q2), given x/Q2 values and subgrid indices, for all 11 standard flav...
Definition Interpolator.h:92
virtual double _interpolateXQ2(const KnotArray &grid, double x, size_t ix, double q2, size_t iq2, int id) const =0
Interpolate a single-point in (x,Q2), given x/Q2 values and subgrid indices.
void setType(std::string t)
Set the interpolation type.
Definition Interpolator.h:71
std::string type() const
Definition Interpolator.h:66
void unbind()
Unbind from GridPDF.
Definition Interpolator.h:35
bool hasPDF()
Identify whether this Interpolator has an associated PDF.
Definition Interpolator.h:38
void bind(const GridPDF *pdf)
Bind to a GridPDF.
Definition Interpolator.h:32
virtual ~Interpolator()
Destructor to allow inheritance.
Definition Interpolator.h:25
double interpolateXQ(int id, double x, double q) const
Interpolate a single-point in (x,Q).
Definition Interpolator.h:50
const GridPDF & pdf() const
Get the associated GridPDF.
Definition Interpolator.h:41
Namespace for all LHAPDF functions and classes.
Definition AlphaS.h:14