LHAPDF  6.5.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
PDFSet.h
1 // -*- C++ -*-
2 //
3 // This file is part of LHAPDF
4 // Copyright (C) 2012-2022 The LHAPDF collaboration (see AUTHORS for details)
5 //
6 #pragma once
7 #ifndef LHAPDF_PDFSet_H
8 #define LHAPDF_PDFSet_H
9 
10 #include "LHAPDF/Info.h"
11 #include "LHAPDF/Factories.h"
12 #include "LHAPDF/Version.h"
13 #include "LHAPDF/Config.h"
14 #include "LHAPDF/Utils.h"
15 
16 namespace LHAPDF {
17 
19  const double CL1SIGMA = 100*erf(1/sqrt(2));
20 
21 
22  // Forward declaration
23  class PDF;
24 
25 
30 
31 
35  struct PDFUncertainty {
36  using ErrPairs = std::vector<std::pair<double,double>>;
37 
39  PDFUncertainty(double cent=0, double eplus=0, double eminus=0, double esymm=0, double scalefactor=1,
40  double eplus_pdf=0, double eminus_pdf=0, double esymm_pdf=0,
41  double eplus_par=0, double eminus_par=0, double esymm_par=0)
42  : central(cent), errplus(eplus), errminus(eminus), errsymm(esymm), scale(scalefactor),
43  errplus_pdf(eplus_pdf), errminus_pdf(eminus_pdf), errsymm_pdf(esymm_pdf),
44  errplus_par(eplus_par), errminus_par(eminus_par), errsymm_par(esymm_par)
45  { }
46 
48  double central, errplus, errminus, errsymm, scale;
49 
51  double errplus_pdf, errminus_pdf, errsymm_pdf;
52  double errplus_par, errminus_par, errsymm_par;
53  double err_par;
54 
56  ErrPairs errparts;
57  };
58 
59 
60 
62  struct PDFErrInfo {
63  using EnvPart = std::pair<std::string, size_t>;
64  using EnvParts = std::vector<EnvPart>;
65  using QuadParts = std::vector<EnvParts>;
66 
68  PDFErrInfo(QuadParts parts, double cl, const std::string& errtypestr="")
69  : qparts(parts), conflevel(cl), errtype(errtypestr)
70  { }
71 
74 
76  QuadParts qparts;
77 
79  double conflevel;
80 
82  std::string errtype;
83 
85  std::string coreType() const { return qpartName(0); }
86 
88  std::string qpartName(size_t iq) const;
90  std::vector<std::string> qpartNames() const;
91 
93  size_t nmemCore() const;
95  size_t nmemPar() const;
96 
97  };
98 
100 
101 
102 
104  class PDFSet : public Info {
105  public:
106 
109  PDFSet() { }
110 
113  PDFSet(const std::string& setname);
114 
115 
118 
122  std::string name() const {
123  return _setname;
124  }
125 
127  std::string description() const {
128  return get_entry("SetDesc");
129  }
130 
132  int lhapdfID() const {
133  return get_entry_as<int>("SetIndex", -1);
134  }
135 
137  int dataversion() const {
138  return get_entry_as<int>("DataVersion", -1);
139  }
140 
142  std::string errorType() const {
143  return to_lower(get_entry("ErrorType", "UNKNOWN"));
144  }
145 
147  PDFErrInfo errorInfo() const;
148 
153  double errorConfLevel() const;
154 
156  // int numMembers() const {
157  // return get_entry_as<int>("NumMembers");
158  // }
159  size_t size() const {
160  return get_entry_as<unsigned int>("NumMembers");
161  }
162 
166  size_t errSize() const {
167  return size()-1;
168  }
169 
171 
172 
174  void print(std::ostream& os=std::cout, int verbosity=1) const;
175 
176 
179 
185  PDF* mkPDF(int member) const {
186  return LHAPDF::mkPDF(name(), member);
187  }
188 
189 
210  //
212  template <typename PTR>
213  void mkPDFs(std::vector<PTR>& pdfs) const {
214  const int v = verbosity();
215  if (v > 0) {
216  std::cout << "LHAPDF " << version() << " loading all " << size() << " PDFs in set " << name() << std::endl;
217  this->print(std::cout, v);
218  if (this->has_key("Note")) std::cout << get_entry("Note") << std::endl;
219  }
220  pdfs.clear();
221  pdfs.reserve(size());
222  if (v < 2) setVerbosity(0); //< Disable every-member printout unless verbosity level is high
223  for (size_t i = 0; i < size(); ++i) {
225  pdfs.push_back( PTR(mkPDF(i)) );
226  }
227  setVerbosity(v);
228  }
229 
235  std::vector<PDF*> mkPDFs() const {
236  std::vector<PDF*> rtn;
237  mkPDFs(rtn);
238  return rtn;
239  }
240 
242  // template <typename PTR=PDF*>
243  template <typename PTR>
244  std::vector<PTR> mkPDFs() const {
245  std::vector<PTR> rtn;
246  mkPDFs(rtn);
247  return rtn;
248  }
249 
251 
252 
254 
255 
258 
260  bool has_key(const std::string& key) const {
261  return has_key_local(key) || getConfig().has_key(key);
262  }
263 
265  const std::string& get_entry(const std::string& key) const {
266  if (has_key_local(key)) return get_entry_local(key); //< value is defined locally
267  return getConfig().get_entry(key); //< fall back to the global config
268  }
269 
271  const std::string& get_entry(const std::string& key, const std::string& fallback) const {
272  return Info::get_entry(key, fallback);
273  }
274 
276 
277 
282 
314  PDFUncertainty uncertainty(const std::vector<double>& values,
315  double cl=CL1SIGMA, bool alternative=false) const {
316  PDFUncertainty rtn;
317  uncertainty(rtn, values, cl, alternative);
318  return rtn;
319  }
320 
321 
322  // // Trick to ensure no calls with implicit type conversion
323  // template <typename T1, typename T2>
324  // void uncertainty(const std::vector<double>& values, T1, T2) const = delete;
325 
326  // /// Alternative form allowing the alternative computation with default CL
327  // PDFUncertainty uncertainty(const std::vector<double>& values,
328  // bool alternative, double cl=CL1SIGMA) const {
329  // return uncertainty(values, cl, alternative);
330  // }
331 
332 
340  void uncertainty(PDFUncertainty& rtn,
341  const std::vector<double>& values,
342  double cl=CL1SIGMA, bool alternative=false) const;
343 
344  // // Trick to ensure no calls with implicit type conversion
345  // template <typename T1, typename T2>
346  // void uncertainty(PDFUncertainty& rtn, const std::vector<double>& values, T1, T2) const = delete;
347 
348  // /// Alternative form allowing the alternative computation with default CL
349  // void uncertainty(PDFUncertainty& rtn,
350  // const std::vector<double>& values,
351  // bool alternative, double cl=CL1SIGMA) const {
352  // uncertainty(rtn, values, cl, alternative);
353  // }
354 
355 
368  std::vector<PDFUncertainty> uncertainties(const std::vector<std::vector<double>>& observables_values,
369  double cl=CL1SIGMA, bool alternative=false) const {
370  std::vector<PDFUncertainty> rtn;
371  uncertainties(rtn, observables_values, cl, alternative);
372  return rtn;
373  }
374 
375 
380  void uncertainties(std::vector<PDFUncertainty>& rtn,
381  const std::vector<std::vector<double>>& observables_values,
382  double cl=CL1SIGMA, bool alternative=false) const;
383 
384 
393  double correlation(const std::vector<double>& valuesA, const std::vector<double>& valuesB) const;
394 
419  double randomValueFromHessian(const std::vector<double>& values, const std::vector<double>& randoms, bool symmetrise=true) const;
420 
421 
427  void _checkPdfType(const std::vector<string>& pdftypes) const;
428 
430 
431 
432  private:
433 
435  std::string _setname;
436 
439 
440  };
441 
442 
443 }
444 #endif
double errplus_pdf
Variables for separate PDF and parameter variation errors with combined sets.
Definition: PDFSet.h:51
std::string version()
Get the LHAPDF library version code (as a string)
Definition: Version.h:33
size_t nmemCore() const
Number of core-set members.
PDF is the general interface for access to parton density information.
Definition: PDF.h:40
std::vector< PTR > mkPDFs() const
Definition: PDFSet.h:244
double central
Variables for the central value, +ve, -ve &amp; symmetrised errors, and a CL scalefactor.
Definition: PDFSet.h:48
int verbosity()
Definition: Config.h:56
PDFUncertainty(double cent=0, double eplus=0, double eminus=0, double esymm=0, double scalefactor=1, double eplus_pdf=0, double eminus_pdf=0, double esymm_pdf=0, double eplus_par=0, double eminus_par=0, double esymm_par=0)
Constructor.
Definition: PDFSet.h:39
size_t size() const
Number of members in this set.
Definition: PDFSet.h:159
std::string _setname
Name of this set.
Definition: PDFSet.h:435
virtual const std::string & get_entry(const std::string &key) const
Definition: Info.h:102
const std::string & get_entry_local(const std::string &key) const
Retrieve a metadata string by key name, as defined on this specific object.
Definition: Info.h:89
const double CL1SIGMA
CL percentage for a Gaussian 1-sigma.
Definition: PDFSet.h:19
std::string description() const
Description of the set.
Definition: PDFSet.h:127
size_t errSize() const
Definition: PDFSet.h:166
QuadParts qparts
Error-set quadrature parts.
Definition: PDFSet.h:76
std::vector< std::string > qpartNames() const
Calculated names of all quadrature parts.
PDFErrInfo _errinfo
Cached PDF error-info breakdown struct.
Definition: PDFSet.h:438
size_t nmemPar() const
Number of par-set members.
Info & getConfig()
ErrPairs errparts
Full error-breakdown of all quadrature uncertainty components, as (+,-) pairs.
Definition: PDFSet.h:56
PDF * mkPDF(int member) const
Definition: PDFSet.h:185
PDFSet()
Definition: PDFSet.h:109
PDF * mkPDF(const std::string &setname, int member)
bool has_key(const std::string &key) const
Can this Info object return a value for the given key? (it may be defined non-locally) ...
Definition: PDFSet.h:260
void mkPDFs(std::vector< PTR > &pdfs) const
Definition: PDFSet.h:213
Structure encoding the structure of the PDF error-set.
Definition: PDFSet.h:62
std::string qpartName(size_t iq) const
Calculated name of a quadrature part.
PDFUncertainty uncertainty(const std::vector< double > &values, double cl=CL1SIGMA, bool alternative=false) const
Calculate the central value and PDF uncertainty on an observable.
Definition: PDFSet.h:314
double err_par
Definition: PDFSet.h:53
std::string to_lower(const std::string &s)
Convert a string to lower-case (not in-place)
Definition: Utils.h:138
PDFErrInfo(QuadParts parts, double cl, const std::string &errtypestr="")
Constructor.
Definition: PDFSet.h:68
std::string errorType() const
Get the type of PDF errors in this set (replicas, symmhessian, hessian, custom, etc.)
Definition: PDFSet.h:142
void print(std::ostream &os=std::cout, int verbosity=1) const
Summary printout.
std::string name() const
PDF set name.
Definition: PDFSet.h:122
std::vector< PDFUncertainty > uncertainties(const std::vector< std::vector< double >> &observables_values, double cl=CL1SIGMA, bool alternative=false) const
Calculate PDF uncertainties on multiple observables at once.
Definition: PDFSet.h:368
void setVerbosity(int v)
Definition: Config.h:65
Class for PDF-set metadata and manipulation.
Definition: PDFSet.h:104
void _checkPdfType(const std::vector< string > &pdftypes) const
const std::string & get_entry(const std::string &key) const
Retrieve a metadata string by key name.
Definition: PDFSet.h:265
virtual bool has_key(const std::string &key) const
Definition: Info.h:83
int dataversion() const
Version of this PDF set&#39;s data files.
Definition: PDFSet.h:137
std::string coreType() const
Calculated name of a quadrature part.
Definition: PDFSet.h:85
PDFErrInfo errorInfo() const
Get the structured decomposition of the error-type string.
double errorConfLevel() const
Get the confidence level of the Hessian eigenvectors, in percent.
const std::string & get_entry(const std::string &key, const std::string &fallback) const
Retrieve a metadata string by key name, with a fallback.
Definition: PDFSet.h:271
Metadata base class for PDFs, PDF sets, or global configuration.
Definition: Info.h:29
bool has_key_local(const std::string &key) const
Is a value defined for the given key on this specific object?
Definition: Info.h:71
Structure for storage of uncertainty info calculated over a PDF error set.
Definition: PDFSet.h:35
std::vector< PDF * > mkPDFs() const
Definition: PDFSet.h:235
int lhapdfID() const
First LHAPDF global index in this PDF set.
Definition: PDFSet.h:132
std::string errtype
Error-type annotation.
Definition: PDFSet.h:82
double randomValueFromHessian(const std::vector< double > &values, const std::vector< double > &randoms, bool symmetrise=true) const
Generate a random value from Hessian values and Gaussian random numbers.
double conflevel
Default confidence-level.
Definition: PDFSet.h:79
double correlation(const std::vector< double > &valuesA, const std::vector< double > &valuesB) const
Calculate the PDF correlation between valuesA and valuesB using appropriate formulae for this set...
PDFErrInfo()
Default constructor (for STL, Cython, etc.)
Definition: PDFSet.h:73