LHAPDF  6.3.0
PDF.h
1 // -*- C++ -*-
2 //
3 // This file is part of LHAPDF
4 // Copyright (C) 2012-2020 The LHAPDF collaboration (see AUTHORS for details)
5 //
6 #pragma once
7 #ifndef LHAPDF_PDF_H
8 #define LHAPDF_PDF_H
9 
10 #include "LHAPDF/PDFInfo.h"
11 #include "LHAPDF/PDFIndex.h"
12 #include "LHAPDF/Factories.h"
13 #include "LHAPDF/AlphaS.h"
14 #include "LHAPDF/Utils.h"
15 #include "LHAPDF/Paths.h"
16 #include "LHAPDF/Exceptions.h"
17 #include "LHAPDF/Version.h"
18 #include "LHAPDF/Config.h"
19 
20 namespace LHAPDF {
21 
22 
26  class PDF {
27  protected: //< These constructors should only be called by subclasses
28 
30  typedef unique_ptr<AlphaS> AlphaSPtr;
31 
33  PDF() : _forcePos(0) { }
34 
35 
36  public:
37 
39  virtual ~PDF() { }
40 
41 
42  protected:
43 
44 
47 
48  void _loadInfo(const std::string& mempath);
49 
50  void _loadInfo(const std::string& setname, int member) {
51  const string searchpath = findpdfmempath(setname, member);
52  if (searchpath.empty())
53  throw UserError("Can't find a valid PDF " + setname + "/" + to_str(member));
54  _loadInfo(searchpath);
55  }
56 
57  void _loadInfo(int lhaid) {
58  const pair<string,int> setname_memid = lookupPDF(lhaid);
59  if (setname_memid.second == -1)
60  throw IndexError("Can't find a PDF with LHAPDF ID = " + to_str(lhaid));
61  _loadInfo(setname_memid.first, setname_memid.second);
62  }
63 
65 
66 
67  public:
68 
71 
81  double xfxQ2(int id, double x, double q2) const;
82 
83 
94  double xfxQ(int id, double x, double q) const {
95  return xfxQ2(id, x, q*q);
96  }
97 
98 
107  void xfxQ2(double x, double q2, std::map<int, double>& rtn) const;
108 
109 
118  void xfxQ(double x, double q, std::map<int, double>& rtn) const {
119  xfxQ2(x, q*q, rtn);
120  }
121 
122 
135  void xfxQ2(double x, double q2, std::vector<double>& rtn) const;
136 
149  void xfxQ(double x, double q, std::vector<double>& rtn) const {
150  xfxQ2(x, q*q, rtn);
151  }
152 
153 
162  std::map<int, double> xfxQ2(double x, double q2) const;
163 
176  std::map<int, double> xfxQ(double x, double q) const {
177  return xfxQ2(x, q*q);
178  }
179 
180 
181  protected:
182 
195  virtual double _xfxQ2(int id, double x, double q2) const = 0;
196 
198 
199 
200  public:
201 
204 
206  virtual double xMin() {
207  if (info().has_key("XMin"))
208  return info().get_entry_as<double>("XMin");
209  return numeric_limits<double>::epsilon();
210  }
211 
213  virtual double xMax() {
214  if (info().has_key("XMax"))
215  return info().get_entry_as<double>("XMax");
216  return 1.0;
217  }
218 
221  virtual double qMin() {
222  return info().get_entry_as<double>("QMin", 0);
223  }
224 
227  virtual double qMax() {
228  return info().get_entry_as<double>("QMax", numeric_limits<double>::max());
229  }
230 
232  virtual double q2Min() {
233  return sqr(this->qMin());
234  }
235 
237  virtual double q2Max() {
238  // Explicitly re-access this from the info, to avoid an overflow from squaring double_max
239  return (info().has_key("QMax")) ? sqr(info().get_entry_as<double>("QMax")) : numeric_limits<double>::max();
240  }
241 
242 
248  int forcePositive() const {
249  if (_forcePos < 0) //< Caching
250  _forcePos = info().get_entry_as<unsigned int>("ForcePositive", 0);
251  return _forcePos;
252  }
254  void setForcePositive(int mode) {
255  _forcePos = mode;
256  }
257 
258 
263  bool inPhysicalRangeX(double x) const {
264  return x >= 0.0 && x <= 1.0;
265  }
266 
270  bool inPhysicalRangeQ2(double q2) const {
271  return q2 >= 0.0;
272  }
273 
277  bool inPhysicalRangeQ(double q) const {
278  return inPhysicalRangeQ2(q*q);
279  }
280 
282  bool inPhysicalRangeXQ2(double x, double q2) const {
283  return inPhysicalRangeX(x) && inPhysicalRangeQ2(q2);
284  }
285 
287  bool inPhysicalRangeXQ(double x, double q) const {
288  return inPhysicalRangeX(x) && inPhysicalRangeQ(q);
289  }
290 
298  virtual bool inRangeQ(double q) const {
299  return inRangeQ2(q*q);
300  }
301 
308  virtual bool inRangeQ2(double q2) const = 0;
309 
316  virtual bool inRangeX(double x) const = 0;
317 
319  virtual bool inRangeXQ(double x, double q) const {
320  return inRangeX(x) && inRangeQ(q);
321  }
322 
324  bool inRangeXQ2(double x, double q2) const {
325  return inRangeX(x) && inRangeQ2(q2);
326  }
327 
329 
330 
333 
335  PDFInfo& info() { return _info; }
336 
338  const PDFInfo& info() const { return _info; }
339 
343  PDFSet& set() const {
344  return getPDFSet(_setname());
345  }
346 
348 
349 
352 
356  int memberID() const {
357  const string memname = file_stem(_mempath);
358  assert(memname.length() > 5); // There must be more to the filename stem than just the _nnnn suffix
359  const int memid = lexical_cast<int>(memname.substr(memname.length()-4)); //< Last 4 chars should be the member number
360  return memid;
361  }
362 
366  int lhapdfID() const;
367 
369  std::string description() const {
370  return info().get_entry("PdfDesc", "");
371  }
372 
374  int dataversion() const {
375  return info().get_entry_as<int>("DataVersion", -1);
376  }
377 
379  std::string type() const {
380  return to_lower(info().get_entry("PdfType"));
381  }
382 
384 
385 
387  void print(std::ostream& os=std::cout, int verbosity=1) const;
388 
389 
392 
401  virtual const std::vector<int>& flavors() const {
402  if (_flavors.empty()) {
403  _flavors = info().get_entry_as< vector<int> >("Flavors");
404  sort(_flavors.begin(), _flavors.end());
405  }
406  return _flavors;
407  }
408 
412  void setFlavors(std::vector<int> const& flavors) {
413  _flavors = flavors;
414  sort(_flavors.begin(), _flavors.end());
415  }
416 
418  bool hasFlavor(int id) const;
419 
427  int orderQCD() const {
428  return info().get_entry_as<int>("OrderQCD");
429  }
431  int qcdOrder() const { return orderQCD(); }
432 
439  double quarkMass(int id) const;
440 
446  double quarkThreshold(int id) const;
447 
449 
450 
453 
459  void setAlphaS(AlphaS* alphas) {
460  _alphas.reset(alphas);
461  }
462 
464  void setAlphaS(AlphaSPtr alphas) {
465  _alphas = std::move(alphas);
466  }
467 
469  bool hasAlphaS() const {
470  return bool(_alphas);
471  }
472 
475  return *_alphas;
476  }
477 
479  const AlphaS& alphaS() const {
480  return *_alphas;
481  }
482 
487  double alphasQ(double q) const {
488  return alphasQ2(q*q);
489  }
490 
495  double alphasQ2(double q2) const {
496  if (!hasAlphaS()) throw Exception("No AlphaS pointer has been set");
497  return _alphas->alphasQ2(q2);
498  }
499 
501 
502 
503  protected:
504 
505  void _loadAlphaS() {
506  _alphas.reset( mkAlphaS(info()) );
507  }
508 
510  std::string _setname() const {
511  return basename(dirname(_mempath));
512  }
513 
515  std::string _mempath;
516 
519 
521  mutable vector<int> _flavors;
522 
525 
531  mutable int _forcePos;
532 
533  };
534 
535 
536 }
537 #endif
Calculator interface for computing alpha_s(Q2) in various ways.
Definition: AlphaS.h:24
Generic unspecialised LHAPDF runtime error.
Definition: Exceptions.h:22
T get_entry_as(const std::string &key) const
Definition: Info.h:122
Metadata class for PDF members.
Definition: PDFInfo.h:18
const std::string & get_entry(const std::string &key) const
Retrieve a metadata string by key name.
Class for PDF set metadata and manipulation.
Definition: PDFSet.h:48
PDF is the general interface for access to parton density information.
Definition: PDF.h:26
bool inPhysicalRangeQ2(double q2) const
Check whether the given Q2 is physically valid.
Definition: PDF.h:270
virtual const std::vector< int > & flavors() const
List of flavours defined by this PDF set.
Definition: PDF.h:401
bool inRangeXQ2(double x, double q2) const
Combined range check for x and Q2.
Definition: PDF.h:324
double xfxQ(int id, double x, double q) const
Get the PDF xf(x) value at (x,q) for the given PID.
Definition: PDF.h:94
double xfxQ2(int id, double x, double q2) const
Get the PDF xf(x) value at (x,q2) for the given PID.
int forcePositive() const
Check whether the PDF is set to only return positive (definite) values or not.
Definition: PDF.h:248
std::string _setname() const
Get the set name from the member data file path (for internal use only)
Definition: PDF.h:510
std::string type() const
Get the type of PDF member that this object represents (central, error)
Definition: PDF.h:379
AlphaSPtr _alphas
Optionally loaded AlphaS object (mutable for laziness/caching)
Definition: PDF.h:524
unique_ptr< AlphaS > AlphaSPtr
Internal convenience typedef for the AlphaS object handle.
Definition: PDF.h:30
virtual double xMin()
Minimum valid x value for this PDF.
Definition: PDF.h:206
int orderQCD() const
Order of QCD at which this PDF has been constructed.
Definition: PDF.h:427
void setAlphaS(AlphaSPtr alphas)
Set the AlphaS calculator by smart pointer.
Definition: PDF.h:464
std::map< int, double > xfxQ2(double x, double q2) const
Get the PDF xf(x) value at (x,q2) for all supported PIDs.
void setFlavors(std::vector< int > const &flavors)
Manually set/override the list of flavours defined by this PDF set.
Definition: PDF.h:412
std::string _mempath
Member data file path.
Definition: PDF.h:515
bool inPhysicalRangeXQ(double x, double q) const
Check whether the given (x,Q) is physically valid.
Definition: PDF.h:287
int dataversion() const
Version of this PDF's data file.
Definition: PDF.h:374
void xfxQ2(double x, double q2, std::vector< double > &rtn) const
Get the PDF xf(x) value at (x,q2) for "standard" PIDs.
int lhapdfID() const
PDF member global LHAPDF ID number.
double quarkThreshold(int id) const
Get a flavor scale threshold in GeV by PDG code (|PID| = 1-6 only) Convenience interface to the Mass*...
virtual double _xfxQ2(int id, double x, double q2) const =0
Calculate the PDF xf(x) value at (x,q2) for the given PID.
double alphasQ2(double q2) const
Value of alpha_s(Q2) used by this PDF.
Definition: PDF.h:495
void print(std::ostream &os=std::cout, int verbosity=1) const
Summary printout.
void xfxQ2(double x, double q2, std::map< int, double > &rtn) const
Get the PDF xf(x) value at (x,q2) for all supported PIDs.
void xfxQ(double x, double q, std::map< int, double > &rtn) const
Get the PDF xf(x) value at (x,q) for all supported PIDs.
Definition: PDF.h:118
virtual bool inRangeQ2(double q2) const =0
Grid range check for Q2.
virtual ~PDF()
Virtual destructor, to allow unfettered inheritance.
Definition: PDF.h:39
void setForcePositive(int mode)
Set whether the PDF will only return positive (definite) values or not.
Definition: PDF.h:254
virtual bool inRangeQ(double q) const
Grid range check for Q.
Definition: PDF.h:298
void setAlphaS(AlphaS *alphas)
Set the AlphaS calculator by pointer.
Definition: PDF.h:459
vector< int > _flavors
Locally cached list of supported PIDs (mutable for laziness/caching)
Definition: PDF.h:521
virtual double q2Min()
Minimum valid Q2 value for this PDF (in GeV2).
Definition: PDF.h:232
double alphasQ(double q) const
Value of alpha_s(Q2) used by this PDF.
Definition: PDF.h:487
virtual double qMax()
Maximum valid Q value for this PDF (in GeV).
Definition: PDF.h:227
PDFSet & set() const
Get the PDF set of which this is a member.
Definition: PDF.h:343
virtual double q2Max()
Maximum valid Q2 value for this PDF (in GeV2).
Definition: PDF.h:237
PDFInfo & info()
Get the info class that actually stores and handles the metadata.
Definition: PDF.h:335
const AlphaS & alphaS() const
Retrieve the AlphaS object for this PDF (const)
Definition: PDF.h:479
bool inPhysicalRangeX(double x) const
Check whether the given x is physically valid.
Definition: PDF.h:263
std::string description() const
Description of this PDF member.
Definition: PDF.h:369
void xfxQ(double x, double q, std::vector< double > &rtn) const
Get the PDF xf(x) value at (x,q) for "standard" PIDs.
Definition: PDF.h:149
bool inPhysicalRangeXQ2(double x, double q2) const
Check whether the given (x,Q2) is physically valid.
Definition: PDF.h:282
std::map< int, double > xfxQ(double x, double q) const
Get the PDF xf(x) value at (x,q) for all supported PIDs.
Definition: PDF.h:176
virtual double xMax()
Maximum valid x value for this PDF.
Definition: PDF.h:213
bool hasFlavor(int id) const
Checks whether id is a valid parton for this PDF.
int _forcePos
Cached flag for whether to return only positive (or positive definite) PDF values.
Definition: PDF.h:531
int qcdOrder() const
Definition: PDF.h:431
virtual double qMin()
Definition: PDF.h:221
virtual bool inRangeXQ(double x, double q) const
Combined range check for x and Q.
Definition: PDF.h:319
bool inPhysicalRangeQ(double q) const
Check whether the given Q is physically valid.
Definition: PDF.h:277
PDF()
Force initialization of the only non-class member.
Definition: PDF.h:33
AlphaS & alphaS()
Retrieve the AlphaS object for this PDF.
Definition: PDF.h:474
int memberID() const
PDF member local ID number.
Definition: PDF.h:356
PDFInfo _info
Metadata container.
Definition: PDF.h:518
virtual bool inRangeX(double x) const =0
Grid range check for x.
double quarkMass(int id) const
Get a quark mass in GeV by PDG code (|PID| = 1-6 only)
const PDFInfo & info() const
Get the info class that actually stores and handles the metadata (const version)
Definition: PDF.h:338
bool hasAlphaS() const
Check if an AlphaS calculator is set.
Definition: PDF.h:469
Problem exists between keyboard and chair.
Definition: Exceptions.h:110
AlphaS * mkAlphaS(const Info &info)
Make an AlphaS object from an Info object.
PDFSet & getPDFSet(const std::string &setname)
std::pair< std::string, int > lookupPDF(int lhaid)
bool has_key(const std::map< K, T > &container, const K &key)
Does the map<K,T> container have a key K key?
Definition: Utils.h:251
std::string to_str(const T &val)
Make a string representation of val.
Definition: Utils.h:61
std::string basename(const std::string &p)
Get the basename (i.e. terminal file name) from a path p.
Definition: Utils.h:175
N sqr(const N &x)
Convenience function for squaring (of any type)
Definition: Utils.h:208
std::string dirname(const std::string &p)
Get the dirname (i.e. path to the penultimate directory) from a path p.
Definition: Utils.h:181
std::string file_stem(const std::string &f)
Get the stem (i.e. part without a file extension) from a filename f.
Definition: Utils.h:187
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
Namespace for all LHAPDF functions and classes.
Definition: AlphaS.h:14