PDFxTMDLib  1.0.0
TTrilinearInterpolator.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
10 #include "PDFxTMDLib/external/mlinterp/mlinterp.hpp"
11 
12 namespace PDFxTMD
13 {
14 template <class ReaderType>
15 class TTrilinearInterpolator : public ITMDInterpolator<TTrilinearInterpolator<ReaderType>, ReaderType>
16 {
17  public:
18  explicit TTrilinearInterpolator() = default;
19  void initialize(const IReader<ReaderType> *reader)
20  {
21  m_reader = reader;
22  m_tmdShape = reader->getData();
23  m_dimensions = {static_cast<int>(m_tmdShape.x_vec.size()),
24  static_cast<int>(m_tmdShape.kt2_vec.size()),
25  static_cast<int>(m_tmdShape.mu2_vec.size())};
26  }
27  double interpolate(PartonFlavor flavor, double x, double kt2, double mu2) const
28  {
29  using namespace mlinterp;
30  double *selectedPdf = &m_tmdShape.grids[flavor][0];
31  double output[1];
32  double logX = std::log(x);
33  double logkt2 = std::log(kt2);
34  double logMu2 = std::log(mu2);
35  interp(m_dimensions.data(), 1, selectedPdf, output, m_tmdShape.log_x_vec.data(), &logX, m_tmdShape.log_kt2_vec.data(), &logkt2
36  , m_tmdShape.log_mu2_vec.data(), &logMu2);
37 
38  return output[0] < 0 ? 0 : output[0] / kt2;
39  }
40  void interpolate(double x, double kt2, double mu2,
41  std::array<double, DEFAULT_TOTAL_PDFS> &output) const
42  {
43  using namespace mlinterp;
44  double output_[1];
45  double logX = std::log(x);
46  double logkt2 = std::log(kt2);
47  double logMu2 = std::log(mu2);
48 
49  for (int i = 0; i < DEFAULT_TOTAL_PDFS; i++)
50  {
51  double *selectedPdf = &m_tmdShape.grids[standardPartonFlavors[i]][0];
52  interp(m_dimensions.data(), 1, selectedPdf, output_, m_tmdShape.log_x_vec.data(), &logX,
53  m_tmdShape.log_kt2_vec.data(), &logkt2, m_tmdShape.log_mu2_vec.data(), &logMu2);
54 
55  output[i] = (output_[0] < 0 ? 0 : output_[0] / kt2);
56  }
57  }
59  {
60  return m_reader;
61  }
62 
63  private:
64  const IReader<ReaderType> *m_reader;
65  std::array<int, 3> m_dimensions;
66  mutable DefaultAllFlavorTMDShape m_tmdShape;
67 };
68 
69 } // namespace PDFxTMD
#define DEFAULT_TOTAL_PDFS
Definition: PartonUtils.h:17
auto getData() const
Definition: IReader.h:18
Definition: IInterpolator.h:37
Definition: TTrilinearInterpolator.h:16
const IReader< ReaderType > * getReader() const
Definition: TTrilinearInterpolator.h:58
double interpolate(PartonFlavor flavor, double x, double kt2, double mu2) const
Definition: TTrilinearInterpolator.h:27
void initialize(const IReader< ReaderType > *reader)
Definition: TTrilinearInterpolator.h:19
void interpolate(double x, double kt2, double mu2, std::array< double, DEFAULT_TOTAL_PDFS > &output) const
Definition: TTrilinearInterpolator.h:40
Definition: AllFlavorsShape.h:14
PartonFlavor
Definition: PartonUtils.h:58
constexpr std::array< PartonFlavor, DEFAULT_TOTAL_PDFS > standardPartonFlavors
Definition: PartonUtils.h:80
int mu2
Definition: pdfset_tutorial.py:14
int kt2
Definition: pdfset_tutorial.py:15
std::vector< double > mu2_vec
Definition: AllFlavorsShape.h:40
std::vector< double > x_vec
Definition: AllFlavorsShape.h:39
Definition: AllFlavorsShape.h:92
std::vector< double > kt2_vec
Definition: AllFlavorsShape.h:95