PDFxTMDLib 2.0.0
Loading...
Searching...
No Matches
SPDF/ICPDF.h
Go to the documentation of this file.
1#pragma once
2#include "PDFxTMDLib/Common/PartonUtils.h"
3#include <array>
4#include <cstddef>
5#include <cstdlib>
6#include <memory>
7#include <type_traits>
8#include <utility>
9
10namespace PDFxTMD
11{
20class ICPDF
21{
22 public:
23 template <typename CPDFApproachT>
24 explicit ICPDF(CPDFApproachT pdfApproach)
25 : pimpl_(new OwningModel<CPDFApproachT>(std::move(pdfApproach)),
26 [](void *pdfApproachBytes) {
27 using Model = OwningModel<CPDFApproachT>;
28 auto *const model = static_cast<Model *>(pdfApproachBytes);
29 delete model;
30 }),
31 pdfOperation_(
32 [](void *pdfApproachBytes, PartonFlavor flavor, double x, double mu2) -> double {
33 using Model = OwningModel<CPDFApproachT>;
34 auto *const model = static_cast<Model *>(pdfApproachBytes);
35 return model->pdf(flavor, x, mu2); // fixed the pdf method call
36 }),
37 pdfOperation1_([](void *pdfApproachBytes, double x, double mu2,
38 std::array<double, 13> &output) -> void {
39 using Model = OwningModel<CPDFApproachT>;
40 auto *const model = static_cast<Model *>(pdfApproachBytes);
41 return model->pdf(x, mu2, output); // fixed the pdf method call
42 }),
43 clone_([](void *pdfApproachBytes) -> void * {
44 using Model = OwningModel<CPDFApproachT>;
45 auto *const model = static_cast<Model *>(pdfApproachBytes);
46 return new Model(*model);
47 })
48 {
49 }
50
61 double pdf(PartonFlavor parton, double x, double mu2) const
62 {
63 return pdfOperation_(pimpl_.get(), parton, x, mu2);
64 }
77 void pdf(double x, double mu2, std::array<double, 13> &output) const
78 {
79 pdfOperation1_(pimpl_.get(), x, mu2, output);
80 }
88 ICPDF(const ICPDF &other)
89 : pimpl_(other.clone_(other.pimpl_.get()), other.pimpl_.get_deleter()),
90 clone_(other.clone_), pdfOperation_(other.pdfOperation_),
91 pdfOperation1_(other.pdfOperation1_)
92
93 {
94 }
95
104 ICPDF &operator=(ICPDF const &other)
105 {
106 using std::swap;
107 ICPDF copy(other);
108 swap(pimpl_, copy.pimpl_);
109 swap(clone_, copy.clone_);
110 swap(pdfOperation_, copy.pdfOperation_);
111 swap(pdfOperation1_, copy.pdfOperation1_);
112 return *this;
113 }
114
115 ICPDF(ICPDF &&other) noexcept = default;
116 ~ICPDF() = default;
117 ICPDF &operator=(ICPDF &&other) = default;
118
119 private:
120 template <typename CPDFApproachT> struct OwningModel
121 {
122 OwningModel(CPDFApproachT pdfApproach) : pdfApproach_(std::move(pdfApproach))
123 {
124 }
125
126 double pdf(PartonFlavor flavor, double x, double mu2)
127 {
128 return pdfApproach_.pdf(flavor, x, mu2);
129 }
130 void pdf(double x, double mu2, std::array<double, 13> &output)
131 {
132 return pdfApproach_.pdf(x, mu2, output);
133 }
134 CPDFApproachT pdfApproach_;
135 };
136
137 using DestroyOperation = void(void *);
138 using CloneOperation = void *(void *);
139 using CPDFOperation = double(void *, PartonFlavor, double, double);
140 using CPDFOperation1 = void(void *, double, double, std::array<double, 13> &);
141
142 std::unique_ptr<void, DestroyOperation *> pimpl_;
143 CloneOperation *clone_{nullptr};
144 CPDFOperation *pdfOperation_{nullptr};
145 CPDFOperation1 *pdfOperation1_{nullptr};
146};
147} // namespace PDFxTMD
Interface for Collinear Parton Distribution Functions (CPDFs).
Definition ICPDF.h:21
ICPDF(ICPDF &&other) noexcept=default
~ICPDF()=default
ICPDF(const ICPDF &other)
Copy constructor for ICPDF objects.
Definition SPDF/ICPDF.h:88
double pdf(PartonFlavor parton, double x, double mu2) const
Evaluate the CPDF for a specific flavor.
Definition SPDF/ICPDF.h:61
ICPDF & operator=(ICPDF &&other)=default
ICPDF(CPDFApproachT pdfApproach)
Definition SPDF/ICPDF.h:24
ICPDF & operator=(ICPDF const &other)
Assignment operator for ICPDF objects.
Definition SPDF/ICPDF.h:104
void pdf(double x, double mu2, std::array< double, 13 > &output) const
Evaluate the array of Collinear PDF values for {tbar, bbar, cbar, sbar, ubar, dbar,...
Definition SPDF/ICPDF.h:77
Definition Factory.h:9