PDFxTMDLib  1.0.0
ITMD.h
Go to the documentation of this file.
1 #pragma once
3 #include <array>
4 #include <cstddef>
5 #include <cstdlib>
6 #include <memory>
7 #include <type_traits>
8 #include <utility>
9 #include <vector>
10 
11 namespace PDFxTMD
12 {
22 class ITMD
23 {
24  public:
25  template <typename TMDApproachT>
26  explicit ITMD(TMDApproachT tmdApproach)
27  : pimpl_(new OwningModel<TMDApproachT>(std::move(tmdApproach)),
28  [](void *tmdfApproachBytes) {
29  using Model = OwningModel<TMDApproachT>;
30  auto *const model = static_cast<Model *>(tmdfApproachBytes);
31  delete model;
32  }),
33  tmdOperation_([](void *tmdfApproachBytes, PartonFlavor flavor, double x, double kt2,
34  double mu2) -> double {
35  using Model = OwningModel<TMDApproachT>;
36  auto *const model = static_cast<Model *>(tmdfApproachBytes);
37  return model->tmd(flavor, x, kt2, mu2);
38  }),
39  tmdOperation1_([](void *tmdfApproachBytes, double x, double kt2, double mu2,
40  std::array<double, DEFAULT_TOTAL_PDFS> &output) -> void {
41  using Model = OwningModel<TMDApproachT>;
42  auto *const model = static_cast<Model *>(tmdfApproachBytes);
43  model->tmd(x, kt2, mu2, output);
44  }),
45  clone_([](void *tmdfApproachBytes) -> void * {
46  using Model = OwningModel<TMDApproachT>;
47  auto *const model = static_cast<Model *>(tmdfApproachBytes);
48  return new Model(*model);
49  })
50  {
51  }
52 
64  double tmd(PartonFlavor flavor, double x, double kt2, double mu2) const
65  {
66  return tmdOperation_(pimpl_.get(), flavor, x, kt2, mu2);
67  }
68 
80  void tmd(double x, double kt2, double mu2, std::array<double, DEFAULT_TOTAL_PDFS> &output) const
81  {
82  return tmdOperation1_(pimpl_.get(), x, kt2, mu2, output);
83  }
84 
92  ITMD(const ITMD &other)
93  : pimpl_(other.clone_(other.pimpl_.get()), other.pimpl_.get_deleter()),
94  clone_(other.clone_), tmdOperation_(other.tmdOperation_),
95  tmdOperation1_(other.tmdOperation1_)
96  {
97  }
98 
107  ITMD &operator=(ITMD const &other)
108  {
109  using std::swap;
110  ITMD copy(other);
111  swap(pimpl_, copy.pimpl_);
112  swap(clone_, copy.clone_);
113  swap(tmdOperation_, copy.tmdOperation_);
114  swap(tmdOperation1_, copy.tmdOperation1_);
115  return *this;
116  }
117 
118  ITMD(ITMD &&other) noexcept = default;
119  ~ITMD() = default;
120  ITMD &operator=(ITMD &&other) = default;
121 
122  private:
123  template <typename TMDApproachT> struct OwningModel
124  {
125  OwningModel(TMDApproachT tmdApproach) : m_tmdApproach(std::move(tmdApproach))
126  {
127  }
140  double tmd(PartonFlavor flavor, double x, double kt2, double mu2)
141  {
142  return m_tmdApproach.tmd(flavor, x, kt2, mu2);
143  }
155  void tmd(double x, double kt2, double mu2, std::array<double, DEFAULT_TOTAL_PDFS> &output)
156  {
157  return m_tmdApproach.tmd(x, kt2, mu2, output);
158  }
159  TMDApproachT m_tmdApproach;
160  };
161 
162  using DestroyOperation = void(void *);
163  using CloneOperation = void *(void *);
164  using TMDOperation = double(void *, PartonFlavor, double, double, double);
165  using TMDOperation1 = void(void *, double, double, double,
166  std::array<double, DEFAULT_TOTAL_PDFS> &output);
167 
168  std::unique_ptr<void, DestroyOperation *> pimpl_;
169  CloneOperation *clone_{nullptr};
170  TMDOperation *tmdOperation_{nullptr};
171  TMDOperation1 *tmdOperation1_{nullptr};
172 };
173 } // namespace PDFxTMD
Interface for Transverse Momentum Dependent (TMD) parton distribution functions.
Definition: ITMD.h:23
~ITMD()=default
ITMD & operator=(ITMD const &other)
Assignment operator for ITMD objects.
Definition: ITMD.h:107
ITMD(const ITMD &other)
Copy constructor for ITMD objects.
Definition: ITMD.h:92
ITMD(ITMD &&other) noexcept=default
ITMD(TMDApproachT tmdApproach)
Definition: ITMD.h:26
void tmd(double x, double kt2, double mu2, std::array< double, DEFAULT_TOTAL_PDFS > &output) const
Evaluate the TMD PDF for all flavors.
Definition: ITMD.h:80
ITMD & operator=(ITMD &&other)=default
double tmd(PartonFlavor flavor, double x, double kt2, double mu2) const
Evaluate the TMD PDF for a specific flavor.
Definition: ITMD.h:64
Definition: AllFlavorsShape.h:14
PartonFlavor
Definition: PartonUtils.h:58
int mu2
Definition: pdfset_tutorial.py:14
int kt2
Definition: pdfset_tutorial.py:15