PDFxTMDLib  1.0.0
CNearestPointExtrapolator.h
Go to the documentation of this file.
1 // This file is based on the LHAPDF code
2 
3 #pragma once
4 
7 #include <cmath>
8 
9 namespace PDFxTMD
10 {
11 // Return the value in the given list that best matches the
12 // target value
13 inline double _findClosestMatch(const std::vector<double> &cands, double target)
14 {
15  auto it = std::lower_bound(cands.begin(), cands.end(), target);
16  const double upper = *it;
17  const double lower =
18  (it == cands.begin()) ? upper : *(--it); //< Avoid decrementing the first entry
20  if (std::fabs(target - upper) < std::fabs(target - lower))
21  return upper;
22  return lower;
23 }
24 
25 template <typename Interpolator>
27  : public IcAdvancedPDFExtrapolator<CNearestPointExtrapolator<Interpolator>>
28 {
29  public:
30  void setInterpolator(const Interpolator *interpolator)
31  {
32  m_interpolator = interpolator;
33  }
34  double extrapolate(PartonFlavor flavor, double x, double mu2) const
35  {
39  const auto *reader = m_interpolator->getReader();
40  auto xVals = reader->getValues(PhaseSpaceComponent::X);
41  auto q2Vals = reader->getValues(PhaseSpaceComponent::Q2);
42 
43  const double closestX = (isInRangeX(*reader, x)) ? x : _findClosestMatch(xVals, x);
44  const double closestQ2 = (isInRangeQ2(*reader, mu2)) ? mu2 : _findClosestMatch(q2Vals, mu2);
45  return this->m_interpolator->interpolate(flavor, closestX, closestQ2);
46  }
47 
48  void extrapolate(double x, double mu2, std::array<double, DEFAULT_TOTAL_PDFS> &output) const
49  {
53  const auto *reader = m_interpolator->getReader();
54  auto xVals = reader->getValues(PhaseSpaceComponent::X);
55  auto q2Vals = reader->getValues(PhaseSpaceComponent::Q2);
56 
57  const double closestX = (isInRangeX(*reader, x)) ? x : _findClosestMatch(xVals, x);
58  const double closestQ2 = (isInRangeQ2(*reader, mu2)) ? mu2 : _findClosestMatch(q2Vals, mu2);
59  for (int i = 0; i < DEFAULT_TOTAL_PDFS; i++)
60  {
61  output[i] =
62  this->m_interpolator->interpolate(standardPartonFlavors[i], closestX, closestQ2);
63  }
64  }
65 
66  private:
67  const Interpolator *m_interpolator = nullptr;
68 };
69 } // namespace PDFxTMD
#define DEFAULT_TOTAL_PDFS
Definition: PartonUtils.h:17
Definition: CNearestPointExtrapolator.h:28
void setInterpolator(const Interpolator *interpolator)
Definition: CNearestPointExtrapolator.h:30
double extrapolate(PartonFlavor flavor, double x, double mu2) const
Definition: CNearestPointExtrapolator.h:34
void extrapolate(double x, double mu2, std::array< double, DEFAULT_TOTAL_PDFS > &output) const
Definition: CNearestPointExtrapolator.h:48
Definition: IExtrapolator.h:39
Definition: AllFlavorsShape.h:14
bool isInRangeX(const Reader &reader, double x)
Definition: PDFUtils.h:6
PartonFlavor
Definition: PartonUtils.h:58
double _findClosestMatch(const std::vector< double > &cands, double target)
Definition: CNearestPointExtrapolator.h:13
constexpr std::array< PartonFlavor, DEFAULT_TOTAL_PDFS > standardPartonFlavors
Definition: PartonUtils.h:80
bool isInRangeQ2(const Reader &reader, double q2)
Definition: PDFUtils.h:11
int mu2
Definition: pdfset_tutorial.py:14