PDFxTMDLib  1.0.0
AllFlavorsShape.h
Go to the documentation of this file.
1 #pragma once
3 #include <algorithm>
4 #include <array>
5 #include <cmath>
6 #include <iostream>
7 #include <map>
8 #include <set>
9 #include <unordered_map>
10 #include <vector>
12 
13 namespace PDFxTMD
14 {
15 
16 inline bool isBlockSeparator(std::string &line)
17 {
18  trim(line);
19  return line == "---";
20 }
21 
22 inline bool isComment(const std::string &line)
23 {
24  return !line.empty() && line[0] == '#';
25 }
26 
27 int findPidInPids(int pid, const std::vector<int> &pids);
28 
30 {
32  {
33  grids_flat.reserve(1024);
34  _lookup.fill(-1);
35  }
36 
37  alignas(64) std::vector<double> log_x_vec;
38  alignas(64) std::vector<double> log_mu2_vec;
39  alignas(64) std::vector<double> x_vec;
40  alignas(64) std::vector<double> mu2_vec;
41  size_t n_xs = 0;
42  size_t n_mu2s = 0;
43  size_t n_flavors = 0;
44  alignas(64) std::vector<double> dlogx; // Differences between consecutive log_x_vec
45  alignas(64) std::vector<double> dlogq; // Differences between consecutive log_mu2_vec
46  alignas(64) std::vector<double> coefficients_flat;
47 
48  // Precomputed strides for fast indexing
49  size_t stride_ix = 0;
50  size_t stride_iq2 = 0;
51 
52  std::vector<int> _shape;
53  const double &coeff(int ix, int iq2, int flavorId, int in) const;
55  void finalizeXP2();
56  void initPidLookup();
57  std::unordered_map<PartonFlavor, std::vector<double>> grids;
58  double getGridFromMap(PartonFlavor flavor, int ix, int iq2) const;
59  // Removed grids map; use grids_flat only for speed
60  alignas(64) std::vector<double> grids_flat;
61 
62  inline double xf(int ix, int iq2, int flavorId) const
63  {
64  // Use precomputed strides to avoid multiplications
65  return grids_flat[ix * stride_ix + iq2 * stride_iq2 + flavorId];
66  }
67 
68  inline int get_pid(int id) const
69  {
70  // hardcoded lookup table for particle ids
71  // -6,...,-1,21/0,1,...,6,22
72  // if id outside of this range, search in list of ids
73  if (-6 <= id && id <= 6)
74  return _lookup[id + 6];
75  else if (id == 21)
76  return _lookup[0 + 6];
77  else if (id == 22)
78  return _lookup[13];
79  else
80  return findPidInPids(id, _pids);
81  }
82 
83  std::vector<int> _pids;
84 
85  private:
86  double _ddxBicubic(size_t ix, size_t iq2, int flavorId);
87  void _computePolynomialCoefficients();
88  std::array<int, 29> _lookup; // Fixed-size lookup for -6 to 22
89 };
90 
92 {
94  alignas(64) std::vector<double> log_kt2_vec;
95  alignas(64) std::vector<double> kt2_vec;
97 };
98 
99 } // namespace PDFxTMD
Definition: AllFlavorsShape.h:14
bool isBlockSeparator(std::string &line)
Definition: AllFlavorsShape.h:16
PartonFlavor
Definition: PartonUtils.h:58
bool isComment(const std::string &line)
Definition: AllFlavorsShape.h:22
void trim(std::string &s)
Definition: StringUtils.h:21
int findPidInPids(int pid, const std::vector< int > &pids)
Definition: AllFlavorsShape.h:30
std::unordered_map< PartonFlavor, std::vector< double > > grids
Definition: AllFlavorsShape.h:57
std::vector< int > _pids
Definition: AllFlavorsShape.h:83
size_t n_flavors
Definition: AllFlavorsShape.h:43
std::vector< double > dlogx
Definition: AllFlavorsShape.h:44
int get_pid(int id) const
Definition: AllFlavorsShape.h:68
std::vector< double > coefficients_flat
Definition: AllFlavorsShape.h:46
size_t stride_iq2
Definition: AllFlavorsShape.h:50
std::vector< double > grids_flat
Definition: AllFlavorsShape.h:60
const double & coeff(int ix, int iq2, int flavorId, int in) const
size_t n_mu2s
Definition: AllFlavorsShape.h:42
size_t n_xs
Definition: AllFlavorsShape.h:41
std::vector< double > log_mu2_vec
Definition: AllFlavorsShape.h:38
std::vector< int > _shape
Definition: AllFlavorsShape.h:52
std::vector< double > dlogq
Definition: AllFlavorsShape.h:45
std::vector< double > mu2_vec
Definition: AllFlavorsShape.h:40
std::vector< double > log_x_vec
Definition: AllFlavorsShape.h:37
std::vector< double > x_vec
Definition: AllFlavorsShape.h:39
DefaultAllFlavorShape()
Definition: AllFlavorsShape.h:31
size_t stride_ix
Definition: AllFlavorsShape.h:49
double xf(int ix, int iq2, int flavorId) const
Definition: AllFlavorsShape.h:62
double getGridFromMap(PartonFlavor flavor, int ix, int iq2) const
Definition: AllFlavorsShape.h:92
std::vector< double > log_kt2_vec
Definition: AllFlavorsShape.h:94
std::vector< double > kt2_vec
Definition: AllFlavorsShape.h:95