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
LHAPDF::PDF::type
std::string type() const
Get the type of PDF member that this object represents (central, error)
Definition: PDF.h:379
LHAPDF::sqr
N sqr(const N &x)
Convenience function for squaring (of any type)
Definition: Utils.h:208
LHAPDF::PDF::_mempath
std::string _mempath
Member data file path.
Definition: PDF.h:515
LHAPDF::PDF::print
void print(std::ostream &os=std::cout, int verbosity=1) const
Summary printout.
LHAPDF::Exception
Generic unspecialised LHAPDF runtime error.
Definition: Exceptions.h:22
LHAPDF::PDF::set
PDFSet & set() const
Get the PDF set of which this is a member.
Definition: PDF.h:343
LHAPDF::PDF::xMin
virtual double xMin()
Minimum valid x value for this PDF.
Definition: PDF.h:206
LHAPDF::PDF::_forcePos
int _forcePos
Cached flag for whether to return only positive (or positive definite) PDF values.
Definition: PDF.h:531
LHAPDF::PDF::quarkThreshold
double quarkThreshold(int id) const
Get a flavor scale threshold in GeV by PDG code (|PID| = 1-6 only) Convenience interface to the Mass*...
LHAPDF::PDF::alphaS
const AlphaS & alphaS() const
Retrieve the AlphaS object for this PDF (const)
Definition: PDF.h:479
LHAPDF::PDF::xMax
virtual double xMax()
Maximum valid x value for this PDF.
Definition: PDF.h:213
LHAPDF::PDF::~PDF
virtual ~PDF()
Virtual destructor, to allow unfettered inheritance.
Definition: PDF.h:39
LHAPDF::PDF::hasAlphaS
bool hasAlphaS() const
Check if an AlphaS calculator is set.
Definition: PDF.h:469
LHAPDF::PDF::xfxQ2
void xfxQ2(double x, double q2, std::vector< double > &rtn) const
Get the PDF xf(x) value at (x,q2) for "standard" PIDs.
LHAPDF::PDF::xfxQ2
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.
LHAPDF::PDF::inPhysicalRangeX
bool inPhysicalRangeX(double x) const
Check whether the given x is physically valid.
Definition: PDF.h:263
LHAPDF::PDFInfo
Metadata class for PDF members.
Definition: PDFInfo.h:18
LHAPDF::PDF::xfxQ
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
LHAPDF::PDF::_xfxQ2
virtual double _xfxQ2(int id, double x, double q2) const =0
Calculate the PDF xf(x) value at (x,q2) for the given PID.
LHAPDF::PDF::forcePositive
int forcePositive() const
Check whether the PDF is set to only return positive (definite) values or not.
Definition: PDF.h:248
LHAPDF::PDFInfo::get_entry
const std::string & get_entry(const std::string &key) const
Retrieve a metadata string by key name.
LHAPDF::PDF::AlphaSPtr
unique_ptr< AlphaS > AlphaSPtr
Internal convenience typedef for the AlphaS object handle.
Definition: PDF.h:30
LHAPDF::PDF::inPhysicalRangeXQ2
bool inPhysicalRangeXQ2(double x, double q2) const
Check whether the given (x,Q2) is physically valid.
Definition: PDF.h:282
LHAPDF::PDF::quarkMass
double quarkMass(int id) const
Get a quark mass in GeV by PDG code (|PID| = 1-6 only)
LHAPDF::PDF::inRangeXQ2
bool inRangeXQ2(double x, double q2) const
Combined range check for x and Q2.
Definition: PDF.h:324
LHAPDF::PDF::qcdOrder
int qcdOrder() const
Definition: PDF.h:431
LHAPDF::lookupPDF
std::pair< std::string, int > lookupPDF(int lhaid)
LHAPDF::PDF::alphaS
AlphaS & alphaS()
Retrieve the AlphaS object for this PDF.
Definition: PDF.h:474
LHAPDF::PDF::setAlphaS
void setAlphaS(AlphaSPtr alphas)
Set the AlphaS calculator by smart pointer.
Definition: PDF.h:464
LHAPDF::PDF::inPhysicalRangeXQ
bool inPhysicalRangeXQ(double x, double q) const
Check whether the given (x,Q) is physically valid.
Definition: PDF.h:287
LHAPDF::PDF::inRangeQ
virtual bool inRangeQ(double q) const
Grid range check for Q.
Definition: PDF.h:298
LHAPDF::PDF::inPhysicalRangeQ
bool inPhysicalRangeQ(double q) const
Check whether the given Q is physically valid.
Definition: PDF.h:277
LHAPDF::PDF::xfxQ
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
LHAPDF::Info::get_entry_as
T get_entry_as(const std::string &key) const
Definition: Info.h:122
LHAPDF::PDF::qMin
virtual double qMin()
Definition: PDF.h:221
LHAPDF::PDF::info
const PDFInfo & info() const
Get the info class that actually stores and handles the metadata (const version)
Definition: PDF.h:338
LHAPDF::PDF::alphasQ
double alphasQ(double q) const
Value of alpha_s(Q2) used by this PDF.
Definition: PDF.h:487
LHAPDF::PDF::_setname
std::string _setname() const
Get the set name from the member data file path (for internal use only)
Definition: PDF.h:510
LHAPDF::PDF::q2Min
virtual double q2Min()
Minimum valid Q2 value for this PDF (in GeV2).
Definition: PDF.h:232
LHAPDF::PDF::xfxQ
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
LHAPDF::getPDFSet
PDFSet & getPDFSet(const std::string &setname)
LHAPDF::PDF::_info
PDFInfo _info
Metadata container.
Definition: PDF.h:518
LHAPDF::PDF::setFlavors
void setFlavors(std::vector< int > const &flavors)
Manually set/override the list of flavours defined by this PDF set.
Definition: PDF.h:412
LHAPDF::PDF::flavors
virtual const std::vector< int > & flavors() const
List of flavours defined by this PDF set.
Definition: PDF.h:401
LHAPDF::dirname
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
LHAPDF::has_key
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
LHAPDF::to_lower
std::string to_lower(const std::string &s)
Convert a string to lower-case (not in-place)
Definition: Utils.h:138
LHAPDF::PDF::lhapdfID
int lhapdfID() const
PDF member global LHAPDF ID number.
LHAPDF::PDF::inPhysicalRangeQ2
bool inPhysicalRangeQ2(double q2) const
Check whether the given Q2 is physically valid.
Definition: PDF.h:270
LHAPDF::PDF::_alphas
AlphaSPtr _alphas
Optionally loaded AlphaS object (mutable for laziness/caching)
Definition: PDF.h:524
LHAPDF::basename
std::string basename(const std::string &p)
Get the basename (i.e. terminal file name) from a path p.
Definition: Utils.h:175
LHAPDF::PDFSet
Class for PDF set metadata and manipulation.
Definition: PDFSet.h:48
LHAPDF::PDF::orderQCD
int orderQCD() const
Order of QCD at which this PDF has been constructed.
Definition: PDF.h:427
LHAPDF::PDF::alphasQ2
double alphasQ2(double q2) const
Value of alpha_s(Q2) used by this PDF.
Definition: PDF.h:495
LHAPDF::PDF::info
PDFInfo & info()
Get the info class that actually stores and handles the metadata.
Definition: PDF.h:335
LHAPDF::PDF::xfxQ2
std::map< int, double > xfxQ2(double x, double q2) const
Get the PDF xf(x) value at (x,q2) for all supported PIDs.
LHAPDF::PDF
PDF is the general interface for access to parton density information.
Definition: PDF.h:26
LHAPDF::PDF::dataversion
int dataversion() const
Version of this PDF's data file.
Definition: PDF.h:374
LHAPDF::PDF::inRangeX
virtual bool inRangeX(double x) const =0
Grid range check for x.
LHAPDF::PDF::q2Max
virtual double q2Max()
Maximum valid Q2 value for this PDF (in GeV2).
Definition: PDF.h:237
LHAPDF::PDF::memberID
int memberID() const
PDF member local ID number.
Definition: PDF.h:356
LHAPDF::PDF::xfxQ
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
LHAPDF::to_str
std::string to_str(const T &val)
Make a string representation of val.
Definition: Utils.h:61
LHAPDF::PDF::PDF
PDF()
Force initialization of the only non-class member.
Definition: PDF.h:33
LHAPDF::PDF::inRangeXQ
virtual bool inRangeXQ(double x, double q) const
Combined range check for x and Q.
Definition: PDF.h:319
LHAPDF::PDF::setForcePositive
void setForcePositive(int mode)
Set whether the PDF will only return positive (definite) values or not.
Definition: PDF.h:254
LHAPDF::PDF::_flavors
vector< int > _flavors
Locally cached list of supported PIDs (mutable for laziness/caching)
Definition: PDF.h:521
LHAPDF
Namespace for all LHAPDF functions and classes.
Definition: AlphaS.h:14
LHAPDF::mkAlphaS
AlphaS * mkAlphaS(const Info &info)
Make an AlphaS object from an Info object.
LHAPDF::PDF::qMax
virtual double qMax()
Maximum valid Q value for this PDF (in GeV).
Definition: PDF.h:227
LHAPDF::UserError
Problem exists between keyboard and chair.
Definition: Exceptions.h:110
LHAPDF::PDF::inRangeQ2
virtual bool inRangeQ2(double q2) const =0
Grid range check for Q2.
LHAPDF::PDF::hasFlavor
bool hasFlavor(int id) const
Checks whether id is a valid parton for this PDF.
LHAPDF::PDF::setAlphaS
void setAlphaS(AlphaS *alphas)
Set the AlphaS calculator by pointer.
Definition: PDF.h:459
LHAPDF::file_stem
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
LHAPDF::AlphaS
Calculator interface for computing alpha_s(Q2) in various ways.
Definition: AlphaS.h:24
LHAPDF::verbosity
int verbosity()
Definition: Config.h:54
LHAPDF::PDF::description
std::string description() const
Description of this PDF member.
Definition: PDF.h:369
LHAPDF::PDF::xfxQ2
double xfxQ2(int id, double x, double q2) const
Get the PDF xf(x) value at (x,q2) for the given PID.