PDFxTMDLib  1.0.0
PartonUtils.h
Go to the documentation of this file.
1 #pragma once
2 #include <algorithm>
3 #include <array>
4 #include <cmath>
5 #include <exception>
6 #include <filesystem>
7 #include <map>
8 #include <optional>
9 #include <sstream>
10 #include <string>
11 #include <vector>
13 
14 #define FOLDER_SEP "/"
15 #define STD_PDF_INFO_EXTENSION ".info"
16 #define STD_PDF_DATA_EXTENSION ".dat"
17 #define DEFAULT_TOTAL_PDFS 13
18 #define DEFULT_NUM_FLAVORS 5
19 #define DOWN_DEFAULT_MASS 0.005
20 #define UP_DEFAULT_MASS 0.002
21 #define STRANGE_DEFAULT_MASS 0.10
22 #define CHARM_DEFAULT_MASS 1.29
23 #define BOTTOM_DEFAULT_MASS 4.19
24 #define TOP_DEFAULT_MASS 172.9
25 #define SQR(x) ((x) * (x))
26 #define NO_REQUESTED_CONFIDENCE_LEVEL -1
27 namespace PDFxTMD
28 {
29 // https://www.modernescpp.com/index.php/from-variadic-templates-to-fold-expressions/
30 template <typename... Args> bool all(Args... args)
31 {
32  return (... && args);
33 }
35 {
36  X,
37  Kt2,
38  Q2
39 };
40 
41 enum class ErrorType
42 {
43  None, // No error
44  CONFIG_KeyNotFound, // The key does not exist
45  CONFIG_ConversionFailed, // Conversion to the desired type
46  // failed,
47  FILE_NOT_FOUND = 10,
48 };
49 enum class OrderQCD
50 {
51  LO,
52  NLO,
53  N2LO,
54  N3LO,
55  N4LO
56 };
58 {
59  tbar = -6,
60  bbar = -5,
61  cbar = -4,
62  sbar = -3,
63  dbar = -1,
64  ubar = -2,
65  gNS = 0, // non-standard g
66  u = 2,
67  d = 1,
68  s = 3,
69  c = 4,
70  b = 5,
71  t = 6,
72  g = 21,
73  photon = 22,
74  // Non stadard ew partciles
75  z0 = 100,
78  higgs
79 };
80 constexpr std::array<PartonFlavor, DEFAULT_TOTAL_PDFS> standardPartonFlavors = {
85 
86 std::vector<std::string> splitPaths(const std::string &paths);
87 bool hasWriteAccess(const std::string &path);
88 double _extrapolateLinear(double x, double xl, double xh, double yl, double yh);
89 std::string StandardPDFNaming(const std::string &pdfName, int set);
90 std::vector<std::string> GetPDFxTMDPathsAsVector();
91 std::vector<std::string> GetPDFxTMDPathsFromYaml();
92 bool AddPathToEnvironment(const std::string &newPath);
93 std::vector<std::string> split(const std::string &str, char delimiter);
96 std::string to_str_zeropad(int val, size_t nchars = 4);
97 std::pair<std::optional<std::string>, ErrorType> StandardInfoFilePath(
98  const std::string &pdfSetName);
99 std::pair<std::optional<std::string>, ErrorType> StandardPDFSetPath(const std::string &pdfSetName,
100  int set);
101 // taken from the lhapdf
102 inline size_t indexbelow(double value, const std::vector<double> &knots)
103 {
104  size_t i = std::upper_bound(knots.begin(), knots.end(), value) - knots.begin();
105  if (i == knots.size())
106  i -= 1; // can't return the last knot index
107  i -= 1; // step back to get the knot <= x behaviour
108  return i;
109 }
111 inline int in_range(double x, double low, double high)
112 {
113  return x >= low && x < high;
114 }
115 } // namespace PDFxTMD
Definition: AllFlavorsShape.h:14
ErrorType
Definition: PartonUtils.h:42
bool AddPathToEnvironment(const std::string &newPath)
OrderQCD
Definition: PartonUtils.h:50
size_t indexbelow(double value, const std::vector< double > &knots)
Definition: PartonUtils.h:102
PartonFlavor
Definition: PartonUtils.h:58
@ t
Definition: PartonUtils.h:71
@ s
Definition: PartonUtils.h:68
@ u
Definition: PartonUtils.h:66
@ dbar
Definition: PartonUtils.h:63
@ higgs
Definition: PartonUtils.h:78
@ ubar
Definition: PartonUtils.h:64
@ wplus
Definition: PartonUtils.h:76
@ b
Definition: PartonUtils.h:70
@ c
Definition: PartonUtils.h:69
@ cbar
Definition: PartonUtils.h:61
@ photon
Definition: PartonUtils.h:73
@ bbar
Definition: PartonUtils.h:60
@ tbar
Definition: PartonUtils.h:59
@ gNS
Definition: PartonUtils.h:65
@ d
Definition: PartonUtils.h:67
@ g
Definition: PartonUtils.h:72
@ sbar
Definition: PartonUtils.h:62
@ wminus
Definition: PartonUtils.h:77
@ z0
Definition: PartonUtils.h:75
bool all(Args... args)
Definition: PartonUtils.h:30
PhaseSpaceComponent
Definition: PartonUtils.h:35
std::string to_str_zeropad(int val, size_t nchars=4)
Format an integer val as a zero-padded string of length nchars.
std::vector< std::string > GetPDFxTMDPathsFromYaml()
std::pair< std::optional< std::string >, ErrorType > StandardPDFSetPath(const std::string &pdfSetName, int set)
std::vector< std::string > GetPDFxTMDPathsAsVector()
int in_range(double x, double low, double high)
Check if a number is in a range (closed-open) (from lhapdf)
Definition: PartonUtils.h:111
double _extrapolateLinear(double x, double xl, double xh, double yl, double yh)
std::pair< std::optional< std::string >, ErrorType > StandardInfoFilePath(const std::string &pdfSetName)
std::string StandardPDFNaming(const std::string &pdfName, int set)
constexpr std::array< PartonFlavor, DEFAULT_TOTAL_PDFS > standardPartonFlavors
Definition: PartonUtils.h:80
std::vector< std::string > split(const std::string &str, char delimiter)
std::vector< std::string > splitPaths(const std::string &paths)
bool hasWriteAccess(const std::string &path)