LHAPDF  6.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
GridPDF.h
1 // -*- C++ -*-
2 //
3 // This file is part of LHAPDF
4 // Copyright (C) 2012-2020 The LHAPDF collaboration (see AUTHORS for details)
5 //
6 #pragma once
7 #ifndef LHAPDF_GridPDF_H
8 #define LHAPDF_GridPDF_H
9 
10 #include "LHAPDF/PDF.h"
11 #include "LHAPDF/Interpolator.h"
12 #include "LHAPDF/Extrapolator.h"
13 #include "LHAPDF/KnotArray.h"
14 
15 namespace LHAPDF {
16 
17 
19  class GridPDF : public PDF {
20  public:
21 
23  GridPDF() {
24  _mempath = "";
25  _info = PDFInfo();
26  _forcePos = -1;
27  }
28 
36  GridPDF(const std::string& path) {
37  _loadInfo(path); // Sets _mempath
38  _loadPlugins();
40  _forcePos = -1;
41  }
42 
44  GridPDF(const std::string& setname, int member) {
45  _loadInfo(setname, member); // Sets _mempath
46  _loadPlugins();
48  _forcePos = -1;
49  }
50 
52  GridPDF(int lhaid) {
53  _loadInfo(lhaid); // Sets _mempath
54  _loadPlugins();
56  _forcePos = -1;
57  }
58 
60  virtual ~GridPDF() { }
61 
62 
63  protected:
64 
66  void _loadInterpolator();
67 
69  void _loadExtrapolator();
70 
72  void _loadPlugins() {
73  _loadAlphaS();
76  }
77 
79  void _loadData(const std::string& mempath);
80 
81 
82  public:
83 
86 
92  void setInterpolator(Interpolator* ipol);
93 
100  template <typename INTERPOLATOR>
101  void setInterpolator(INTERPOLATOR ipol) {
102  setInterpolator(new INTERPOLATOR(ipol));
103  }
104 
109  void setInterpolator(const std::string& ipolname);
110 
112  bool hasInterpolator() const { return bool(_interpolator); }
113 
115  const Interpolator& interpolator() const;
116 
117 
123  void setExtrapolator(Extrapolator* xpol);
124 
131  template <typename EXTRAPOLATOR>
132  void setExtrapolator(EXTRAPOLATOR xpol) {
133  setExtrapolator(new EXTRAPOLATOR(xpol));
134  }
135 
140  void setExtrapolator(const std::string& xpolname);
141 
143  bool hasExtrapolator() const { return bool(_extrapolator); }
144 
146  const Extrapolator& extrapolator() const;
147 
149 
150 
151  protected:
152 
154  double _xfxQ2(int id, double x, double q2) const;
155 
156 
157  public:
158 
161 
163  std::map<double, KnotArrayNF>& knotarrays() {
164  return _knotarrays;
165  }
166 
168  const KnotArrayNF& subgrid(double q2) const;
169 
171  const KnotArray1F& subgrid(int id, double q2) const {
172  return subgrid(q2).get_pid(id);
173  }
174 
178  const vector<double>& xKnots() const {
179  const KnotArrayNF& subgrid1 = _knotarrays.begin()->second;
180  const KnotArray1F& grid1 = subgrid1.get_first();
181  return grid1.xs();
182  }
183 
187  const vector<double>& q2Knots() const;
188 
189  public:
190 
192  bool inRangeX(double x) const {
193  assert(!xKnots().empty());
194  if (x < xKnots().front()) return false;
195  if (x > xKnots().back()) return false;
196  return true;
197  }
198 
200  bool inRangeQ2(double q2) const {
201  assert(!q2Knots().empty());
202  if (q2 < q2Knots().front()) return false;
203  if (q2 > q2Knots().back()) return false;
204  return true;
205  }
206 
208 
209 
210  private:
211 
213  std::map<double, KnotArrayNF> _knotarrays;
214 
215  // /// Caching vector of x knot values
216  // mutable std::vector<double> _xknots;
217 
219  mutable std::vector<double> _q2knots;
220 
222  typedef unique_ptr<Interpolator> InterpolatorPtr;
223 
225  typedef unique_ptr<Extrapolator> ExtrapolatorPtr;
226 
229 
232 
233  };
234 
235 
236 }
237 #endif
const KnotArray1F & subgrid(int id, double q2) const
Get the 1-flavour subgrid for PID=id containing Q2 = q2.
Definition: GridPDF.h:171
PDF is the general interface for access to parton density information.
Definition: PDF.h:26
const vector< double > & xKnots() const
Return a representative list of interpolation knots in x.
Definition: GridPDF.h:178
const KnotArrayNF & subgrid(double q2) const
Get the N-flavour subgrid containing Q2 = q2.
void _loadExtrapolator()
Load the PDF grid data block, based on current metadata.
unique_ptr< Extrapolator > ExtrapolatorPtr
Typedef of smart pointer for xpol memory handling.
Definition: GridPDF.h:225
InterpolatorPtr _interpolator
Associated interpolator (mutable to allow laziness)
Definition: GridPDF.h:228
const std::vector< double > & xs() const
x knot accessor
Definition: KnotArray.h:62
A collection of {KnotArray1F}s accessed by PID code.
Definition: KnotArray.h:194
const vector< double > & q2Knots() const
Return a representative list of interpolation knots in Q2.
void _loadData(const std::string &mempath)
Load the PDF grid data block (not the metadata) from the given PDF member file.
const Interpolator & interpolator() const
Get the current interpolator.
bool hasInterpolator() const
Find whether an extrapolator has been set on this PDF.
Definition: GridPDF.h:112
void _loadPlugins()
Load the alphaS, interpolator, and extrapolator based on current metadata.
Definition: GridPDF.h:72
A PDF defined via an interpolation grid.
Definition: GridPDF.h:19
void setInterpolator(Interpolator *ipol)
Set the interpolator by pointer.
GridPDF(int lhaid)
Constructor from an LHAPDF ID.
Definition: GridPDF.h:52
const KnotArray1F & get_first() const
Convenience accessor for any valid subgrid, to get access to the x/Q2/etc. arrays.
Definition: KnotArray.h:215
std::vector< double > _q2knots
Caching vector of Q2 knot values.
Definition: GridPDF.h:219
const KnotArray1F & get_pid(int id) const
Get the KnotArray1F for PID code id.
Definition: KnotArray.h:209
GridPDF(const std::string &setname, int member)
Constructor from a set name and member ID.
Definition: GridPDF.h:44
void _loadInterpolator()
Load the interpolator, based on current metadata.
const Extrapolator & extrapolator() const
Get the current extrapolator.
void setExtrapolator(Extrapolator *xpol)
Set the extrapolator by pointer.
void setExtrapolator(EXTRAPOLATOR xpol)
Set the extrapolator by value.
Definition: GridPDF.h:132
virtual ~GridPDF()
Virtual destructor to allow inheritance.
Definition: GridPDF.h:60
std::map< double, KnotArrayNF > _knotarrays
Map of multi-flavour KnotArrays &quot;binned&quot; for lookup by low edge in Q2.
Definition: GridPDF.h:213
Metadata class for PDF members.
Definition: PDFInfo.h:18
PDFInfo _info
Metadata container.
Definition: PDF.h:518
GridPDF(const std::string &path)
Constructor from a file path.
Definition: GridPDF.h:36
bool inRangeQ2(double q2) const
Check if q2 is in the grid range.
Definition: GridPDF.h:200
The general interface for interpolating between grid points.
Definition: Interpolator.h:21
bool hasExtrapolator() const
Find whether an extrapolator has been set on this PDF.
Definition: GridPDF.h:143
std::map< double, KnotArrayNF > & knotarrays()
Directly access the knot arrays in non-const mode, for programmatic filling.
Definition: GridPDF.h:163
void setInterpolator(INTERPOLATOR ipol)
Set the interpolator by value.
Definition: GridPDF.h:101
double _xfxQ2(int id, double x, double q2) const
Get PDF xf(x,Q2) value (via grid inter/extrapolators)
int _forcePos
Cached flag for whether to return only positive (or positive definite) PDF values.
Definition: PDF.h:531
std::string _mempath
Member data file path.
Definition: PDF.h:515
ExtrapolatorPtr _extrapolator
Associated extrapolator (mutable to allow laziness)
Definition: GridPDF.h:231
Internal storage class for PDF data point grids.
Definition: KnotArray.h:20
bool inRangeX(double x) const
Check if x is in the grid range.
Definition: GridPDF.h:192
unique_ptr< Interpolator > InterpolatorPtr
Typedef of smart pointer for ipol memory handling.
Definition: GridPDF.h:222
The general interface for extrapolating beyond grid boundaries.
Definition: Extrapolator.h:20
GridPDF()
Default constructor, making an empty PDF to be populated by hand.
Definition: GridPDF.h:23