LHAPDF  6.4.0
PDFSet.h
1 // -*- C++ -*-
2 //
3 // This file is part of LHAPDF
4 // Copyright (C) 2012-2021 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 
18 
19  // Forward declaration
20  class PDF;
21 
22 
27 
31  struct PDFUncertainty {
33  PDFUncertainty(double cent=0, double eplus=0, double eminus=0, double esymm=0, double scalefactor=1,
34  double eplus_pdf=0, double eminus_pdf=0, double esymm_pdf=0, double e_par=0)
35  : central(cent), errplus(eplus), errminus(eminus), errsymm(esymm), scale(scalefactor),
36  errplus_pdf(eplus_pdf), errminus_pdf(eminus_pdf), errsymm_pdf(esymm_pdf), err_par(e_par)
37  { }
39  double central, errplus, errminus, errsymm, scale;
41  double errplus_pdf, errminus_pdf, errsymm_pdf, err_par;
42  };
43 
45 
46 
48  class PDFSet : public Info {
49  public:
50 
53  PDFSet() { }
54 
57  PDFSet(const std::string& setname);
58 
59 
62 
66  std::string name() const {
67  return _setname;
68  }
69 
71  std::string description() const {
72  return get_entry("SetDesc");
73  }
74 
76  int lhapdfID() const {
77  return get_entry_as<int>("SetIndex", -1);
78  }
79 
81  int dataversion() const {
82  return get_entry_as<int>("DataVersion", -1);
83  }
84 
86  std::string errorType() const {
87  return to_lower(get_entry("ErrorType", "UNKNOWN"));
88  }
89 
94  double errorConfLevel() const;
95 
97  // int numMembers() const {
98  // return get_entry_as<int>("NumMembers");
99  // }
100  size_t size() const {
101  return get_entry_as<unsigned int>("NumMembers");
102  }
103 
105 
106 
108  void print(std::ostream& os=std::cout, int verbosity=1) const;
109 
110 
113 
119  PDF* mkPDF(int member) const {
120  return LHAPDF::mkPDF(name(), member);
121  }
122 
123 
144  //
146  template <typename PTR>
147  void mkPDFs(std::vector<PTR>& pdfs) const {
148  const int v = verbosity();
149  if (v > 0) {
150  std::cout << "LHAPDF " << version() << " loading all " << size() << " PDFs in set " << name() << std::endl;
151  this->print(std::cout, v);
152  if (this->has_key("Note")) std::cout << get_entry("Note") << std::endl;
153  }
154  pdfs.clear();
155  pdfs.reserve(size());
156  if (v < 2) setVerbosity(0); //< Disable every-member printout unless verbosity level is high
157  for (size_t i = 0; i < size(); ++i) {
159  pdfs.push_back( PTR(mkPDF(i)) );
160  }
161  setVerbosity(v);
162  }
163 
169  std::vector<PDF*> mkPDFs() const {
170  std::vector<PDF*> rtn;
171  mkPDFs(rtn);
172  return rtn;
173  }
174 
176  // template <typename PTR=PDF*>
177  template <typename PTR>
178  std::vector<PTR> mkPDFs() const {
179  std::vector<PTR> rtn;
180  mkPDFs(rtn);
181  return rtn;
182  }
183 
185 
186 
188 
189 
192 
194  bool has_key(const std::string& key) const {
195  return has_key_local(key) || getConfig().has_key(key);
196  }
197 
199  const std::string& get_entry(const std::string& key) const {
200  if (has_key_local(key)) return get_entry_local(key); //< value is defined locally
201  return getConfig().get_entry(key); //< fall back to the global config
202  }
203 
205  const std::string& get_entry(const std::string& key, const std::string& fallback) const {
206  return Info::get_entry(key, fallback);
207  }
208 
210 
211 
216 
248  PDFUncertainty uncertainty(const std::vector<double>& values,
249  double cl=100*erf(1/sqrt(2)), bool alternative=false) const;
250 
259  const std::vector<double>& values,
260  double cl=100*erf(1/sqrt(2)), bool alternative=false) const {
261  rtn = uncertainty(values, cl, alternative);
262  }
263 
272  double correlation(const std::vector<double>& valuesA, const std::vector<double>& valuesB) const;
273 
298  double randomValueFromHessian(const std::vector<double>& values, const std::vector<double>& randoms, bool symmetrise=true) const;
299 
300 
305  void _checkPdfType(const std::vector<string>& pdftypes) const;
306 
308 
309 
310  private:
311 
313  std::string _setname;
314 
315  };
316 
317 
318 }
319 #endif
Metadata base class for PDFs, PDF sets, or global configuration.
Definition: Info.h:29
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
virtual const std::string & get_entry(const std::string &key) const
Definition: Info.h:102
virtual bool has_key(const std::string &key) const
Definition: Info.h:83
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
Class for PDF set metadata and manipulation.
Definition: PDFSet.h:48
size_t size() const
Number of members in this set.
Definition: PDFSet.h:100
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:205
PDF * mkPDF(int member) const
Definition: PDFSet.h:119
double errorConfLevel() const
Get the confidence level of the Hessian eigenvectors, in percent.
PDFSet(const std::string &setname)
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:194
int dataversion() const
Version of this PDF set's data files.
Definition: PDFSet.h:81
std::vector< PTR > mkPDFs() const
Definition: PDFSet.h:178
PDFUncertainty uncertainty(const std::vector< double > &values, double cl=100 *erf(1/sqrt(2)), bool alternative=false) const
Calculate central value and error from vector values with appropriate formulae for this set.
void print(std::ostream &os=std::cout, int verbosity=1) const
Summary printout.
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.
void _checkPdfType(const std::vector< string > &pdftypes) const
void uncertainty(PDFUncertainty &rtn, const std::vector< double > &values, double cl=100 *erf(1/sqrt(2)), bool alternative=false) const
Calculate PDF uncertainties (as above), with efficient no-copy return to the rtn argument.
Definition: PDFSet.h:258
int lhapdfID() const
First LHAPDF global index in this PDF set.
Definition: PDFSet.h:76
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.
std::string name() const
PDF set name.
Definition: PDFSet.h:66
std::string errorType() const
Get the type of PDF errors in this set (replicas, symmhessian, hessian, custom, etc....
Definition: PDFSet.h:86
PDFSet()
Definition: PDFSet.h:53
std::vector< PDF * > mkPDFs() const
Definition: PDFSet.h:169
std::string description() const
Description of the set.
Definition: PDFSet.h:71
std::string _setname
Name of this set.
Definition: PDFSet.h:313
const std::string & get_entry(const std::string &key) const
Retrieve a metadata string by key name.
Definition: PDFSet.h:199
void mkPDFs(std::vector< PTR > &pdfs) const
Definition: PDFSet.h:147
PDF is the general interface for access to parton density information.
Definition: PDF.h:40
Info & getConfig()
PDF * mkPDF(const std::string &setname, int member)
std::string to_lower(const std::string &s)
Convert a string to lower-case (not in-place)
Definition: Utils.h:138
int verbosity()
Definition: Config.h:54
void setVerbosity(int v)
Definition: Config.h:61
Namespace for all LHAPDF functions and classes.
Definition: AlphaS.h:14
std::string version()
Get the LHAPDF library version code (as a string)
Definition: Version.h:33
Structure for storage of uncertainty info calculated over a PDF error set.
Definition: PDFSet.h:31
double central
Variables for the central value, +ve, -ve & symmetrised errors, and a CL scalefactor.
Definition: PDFSet.h:39
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 e_par=0)
Constructor.
Definition: PDFSet.h:33
double errplus_pdf
Add extra variables for separate PDF and parameter variation errors with combined sets.
Definition: PDFSet.h:41