LHAPDF  6.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
PDF.h
1 // -*- C++ -*-
2 //
3 // This file is part of LHAPDF
4 // Copyright (C) 2012-2016 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 
31  // typedef unique_ptr<AlphaS> AlphaSPtr;
32  typedef AlphaS* AlphaSPtr;
33 
36  PDF() : _alphas(0), _forcePos(0) { }
37 
38 
39  public:
40 
42  virtual ~PDF() {
44  delete _alphas;
45  }
46 
48 
49 
50  protected:
51 
52 
54 
55 
56  void _loadInfo(const std::string& mempath);
57 
58  void _loadInfo(const std::string& setname, int member) {
59  const string searchpath = findpdfmempath(setname, member);
60  if (searchpath.empty())
61  throw UserError("Can't find a valid PDF " + setname + "/" + to_str(member));
62  _loadInfo(searchpath);
63  }
64 
65  void _loadInfo(int lhaid) {
66  const pair<string,int> setname_memid = lookupPDF(lhaid);
67  if (setname_memid.second == -1)
68  throw IndexError("Can't find a PDF with LHAPDF ID = " + to_str(lhaid));
69  _loadInfo(setname_memid.first, setname_memid.second);
70  }
71 
73 
74 
75  public:
76 
78 
79 
89  double xfxQ2(int id, double x, double q2) const;
90 
91 
102  double xfxQ(int id, double x, double q) const {
103  return xfxQ2(id, x, q*q);
104  }
105 
106 
115  void xfxQ2(double x, double q2, std::map<int, double>& rtn) const;
116 
117 
126  void xfxQ(double x, double q, std::map<int, double>& rtn) const {
127  xfxQ2(x, q*q, rtn);
128  }
129 
130 
143  void xfxQ2(double x, double q2, std::vector<double>& rtn) const;
144 
157  void xfxQ(double x, double q, std::vector<double>& rtn) const {
158  xfxQ2(x, q*q, rtn);
159  }
160 
161 
170  std::map<int, double> xfxQ2(double x, double q2) const;
171 
184  std::map<int, double> xfxQ(double x, double q) const {
185  return xfxQ2(x, q*q);
186  }
187 
188 
189  protected:
190 
203  virtual double _xfxQ2(int id, double x, double q2) const = 0;
204 
206 
207 
208  public:
209 
211 
212 
214  virtual double xMin() {
215  if (info().has_key("XMin"))
216  return info().get_entry_as<double>("XMin");
217  return numeric_limits<double>::epsilon();
218  }
219 
221  virtual double xMax() {
222  if (info().has_key("XMax"))
223  return info().get_entry_as<double>("XMax");
224  return 1.0;
225  }
226 
229  virtual double qMin() {
230  return info().get_entry_as<double>("QMin", 0);
231  }
232 
235  virtual double qMax() {
236  return info().get_entry_as<double>("QMax", numeric_limits<double>::max());
237  }
238 
240  virtual double q2Min() {
241  return sqr(this->qMin());
242  }
243 
245  virtual double q2Max() {
246  // Explicitly re-access this from the info, to avoid an overflow from squaring double_max
247  return (info().has_key("QMax")) ? sqr(info().get_entry_as<double>("QMax")) : numeric_limits<double>::max();
248  }
249 
255  int forcePositive() const {
256  if (_forcePos < 0) //< Caching
257  _forcePos = info().get_entry_as<unsigned int>("ForcePositive", 0);
258  return _forcePos;
259  }
260 
265  bool inPhysicalRangeX(double x) const {
266  return x >= 0.0 && x <= 1.0;
267  }
268 
272  bool inPhysicalRangeQ2(double q2) const {
273  return q2 >= 0.0;
274  }
275 
279  bool inPhysicalRangeQ(double q) const {
280  return inPhysicalRangeQ2(q*q);
281  }
282 
284  bool inPhysicalRangeXQ2(double x, double q2) const {
285  return inPhysicalRangeX(x) && inPhysicalRangeQ2(q2);
286  }
287 
289  bool inPhysicalRangeXQ(double x, double q) const {
290  return inPhysicalRangeX(x) && inPhysicalRangeQ(q);
291  }
292 
300  virtual bool inRangeQ(double q) const {
301  return inRangeQ2(q*q);
302  }
303 
310  virtual bool inRangeQ2(double q2) const = 0;
311 
318  virtual bool inRangeX(double x) const = 0;
319 
321  virtual bool inRangeXQ(double x, double q) const {
322  return inRangeX(x) && inRangeQ(q);
323  }
324 
326  bool inRangeXQ2(double x, double q2) const {
327  return inRangeX(x) && inRangeQ2(q2);
328  }
329 
331 
332 
334 
335 
337  PDFInfo& info() { return _info; }
338 
340  const PDFInfo& info() const { return _info; }
341 
345  PDFSet& set() const {
346  return getPDFSet(_setname());
347  }
348 
350 
351 
353 
354 
358  int memberID() const {
359  const string memname = file_stem(_mempath);
360  assert(memname.length() > 5); // There must be more to the filename stem than just the _nnnn suffix
361  const int memid = lexical_cast<int>(memname.substr(memname.length()-4)); //< Last 4 chars should be the member number
362  return memid;
363  }
364 
368  int lhapdfID() const;
369 
371  std::string description() const {
372  return info().get_entry("PdfDesc", "");
373  }
374 
376  int dataversion() const {
377  return info().get_entry_as<int>("DataVersion", -1);
378  }
379 
381  std::string type() const {
382  return to_lower(info().get_entry("PdfType"));
383  }
384 
386 
387 
389  void print(std::ostream& os=std::cout, int verbosity=1) const;
390 
391 
393 
394 
403  virtual const std::vector<int>& flavors() const {
404  if (_flavors.empty()) {
405  _flavors = info().get_entry_as< vector<int> >("Flavors");
406  sort(_flavors.begin(), _flavors.end());
407  }
408  return _flavors;
409  }
410 
412  bool hasFlavor(int id) const;
413 
419  int orderQCD() const {
420  return info().get_entry_as<int>("OrderQCD");
421  }
423  int qcdOrder() const { return orderQCD(); }
424 
429  double quarkMass(int id) const;
430 
434  double quarkThreshold(int id) const;
435 
437 
438 
440 
441 
447  void setAlphaS(AlphaS* alphas) {
448  // _alphas.reset(alphas);
449  }
450 
452  bool hasAlphaS() const {
453  return _alphas;
454  }
455 
458  return *_alphas;
459  }
460 
462  const AlphaS& alphaS() const {
463  return *_alphas;
464  }
465 
470  double alphasQ(double q) const {
471  return alphasQ2(q*q);
472  }
473 
478  double alphasQ2(double q2) const {
479  if (!hasAlphaS()) throw Exception("No AlphaS pointer has been set");
480  return _alphas->alphasQ2(q2);
481  }
482 
484 
485 
486  protected:
487 
488  void _loadAlphaS() {
489  // _alphas.reset( mkAlphaS(info()) );
490  if (hasAlphaS()) delete _alphas;
491  _alphas = mkAlphaS(info());
492  }
493 
495  std::string _setname() const {
496  return basename(dirname(_mempath));
497  }
498 
500  std::string _mempath;
501 
504 
506  mutable vector<int> _flavors;
507 
510 
516  mutable int _forcePos;
517 
518  };
519 
520 
521 }
522 #endif
int memberID() const
PDF member local ID number.
Definition: PDF.h:358
PDF is the general interface for access to parton density information.
Definition: PDF.h:26
virtual double xMin()
Minimum valid x value for this PDF.
Definition: PDF.h:214
int forcePositive() const
Check whether PDF is set to only return positive (definite) values or not.
Definition: PDF.h:255
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:102
std::string to_str(const T &val)
Make a string representation of val.
Definition: Utils.h:60
int lhapdfID() const
PDF member global LHAPDF ID number.
virtual double qMin()
Definition: PDF.h:229
double quarkMass(int id) const
Get a quark mass in GeV by PDG code (|PID| = 1-6 only)
Generic unspecialised LHAPDF runtime error.
Definition: Exceptions.h:22
bool inPhysicalRangeXQ2(double x, double q2) const
Check whether the given (x,Q2) is physically valid.
Definition: PDF.h:284
virtual ~PDF()
Virtual destructor, to allow unfettered inheritance.
Definition: PDF.h:42
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 xfxQ2(int id, double x, double q2) const
Get the PDF xf(x) value at (x,q2) for the given PID.
virtual bool inRangeQ2(double q2) const =0
Grid range check for Q2.
PDFSet & set() const
Get the PDF set of which this is a member.
Definition: PDF.h:345
std::pair< std::string, int > lookupPDF(int lhaid)
std::string _setname() const
Get the set name from the member data file path (for internal use only)
Definition: PDF.h:495
virtual double q2Max()
Maximum valid Q2 value for this PDF (in GeV2).
Definition: PDF.h:245
int dataversion() const
Version of this PDF&#39;s data file.
Definition: PDF.h:376
vector< int > _flavors
Locally cached list of supported PIDs.
Definition: PDF.h:506
bool inRangeXQ2(double x, double q2) const
Combined range check for x and Q2.
Definition: PDF.h:326
double alphasQ(double q) const
Value of alpha_s(Q2) used by this PDF.
Definition: PDF.h:470
virtual double xMax()
Maximum valid x value for this PDF.
Definition: PDF.h:221
bool hasAlphaS() const
Check if an AlphaS calculator is set.
Definition: PDF.h:452
bool inPhysicalRangeQ2(double q2) const
Check whether the given Q2 is physically valid.
Definition: PDF.h:272
std::string description() const
Description of this PDF member.
Definition: PDF.h:371
PDFSet & getPDFSet(const std::string &setname)
T lexical_cast(const U &in)
Convert between any types via stringstream.
Definition: Utils.h:46
std::string basename(const std::string &p)
Get the basename (i.e. terminal file name) from a path p.
Definition: Utils.h:183
virtual bool inRangeXQ(double x, double q) const
Combined range check for x and Q.
Definition: PDF.h:321
virtual bool inRangeX(double x) const =0
Grid range check for x.
bool hasFlavor(int id) const
Checks whether id is a valid parton for this PDF.
AlphaS & alphaS()
Retrieve the AlphaS object for this PDF.
Definition: PDF.h:457
virtual const std::vector< int > & flavors() const
List of flavours defined by this PDF set.
Definition: PDF.h:403
PDFInfo & info()
Get the info class that actually stores and handles the metadata.
Definition: PDF.h:337
virtual bool inRangeQ(double q) const
Grid range check for Q.
Definition: PDF.h:300
const PDFInfo & info() const
Get the info class that actually stores and handles the metadata (const version)
Definition: PDF.h:340
N sqr(const N &x)
Convenience function for squaring (of any type)
Definition: Utils.h:216
virtual double alphasQ2(double q2) const =0
AlphaS * mkAlphaS(const Info &info)
Make an AlphaS object from an Info object.
T get_entry_as(const std::string &key) const
Definition: Info.h:128
AlphaS * AlphaSPtr
Definition: PDF.h:32
std::string to_lower(const std::string &s)
Convert a string to lower-case (not in-place)
Definition: Utils.h:137
bool inPhysicalRangeQ(double q) const
Check whether the given Q is physically valid.
Definition: PDF.h:279
std::string dirname(const std::string &p)
Get the dirname (i.e. path to the penultimate directory) from a path p.
Definition: Utils.h:189
double alphasQ2(double q2) const
Value of alpha_s(Q2) used by this PDF.
Definition: PDF.h:478
Class for PDF set metadata and manipulation.
Definition: PDFSet.h:39
PDF()
Definition: PDF.h:36
int qcdOrder() const
Definition: PDF.h:423
int verbosity()
Definition: Config.h:65
Metadata class for PDF members.
Definition: PDFInfo.h:18
PDFInfo _info
Metadata container.
Definition: PDF.h:503
std::string type() const
Get the type of PDF member that this object represents (central, error)
Definition: PDF.h:381
int orderQCD() const
Order of QCD at which this PDF has been constructed.
Definition: PDF.h:419
Calculator interface for computing alpha_s(Q2) in various ways.
Definition: AlphaS.h:23
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:195
bool has_key(const std::map< K, T > &container, const K &key)
Does the map&lt;K,T&gt; container have a key K key?
Definition: Utils.h:259
void print(std::ostream &os=std::cout, int verbosity=1) const
Summary printout.
int _forcePos
Cached flag for whether to return only positive (or postive definite) PDF values. ...
Definition: PDF.h:516
void setAlphaS(AlphaS *alphas)
Set the AlphaS calculator by pointer.
Definition: PDF.h:447
void xfxQ(double x, double q, std::vector< double > &rtn) const
Get the PDF xf(x) value at (x,q) for &quot;standard&quot; PIDs.
Definition: PDF.h:157
std::string _mempath
Member data file path.
Definition: PDF.h:500
bool inPhysicalRangeX(double x) const
Check whether the given x is physically valid.
Definition: PDF.h:265
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:184
double quarkThreshold(int id) const
Get a flavor scale threshold in GeV by PDG code (|PID| = 1-6 only) Convenience interface to the Mass*...
bool inPhysicalRangeXQ(double x, double q) const
Check whether the given (x,Q) is physically valid.
Definition: PDF.h:289
const AlphaS & alphaS() const
Retrieve the AlphaS object for this PDF (const)
Definition: PDF.h:462
virtual double q2Min()
Minimum valid Q2 value for this PDF (in GeV2).
Definition: PDF.h:240
virtual double qMax()
Maximum valid Q value for this PDF (in GeV).
Definition: PDF.h:235
Problem exists between keyboard and chair.
Definition: Exceptions.h:110
const std::string & get_entry(const std::string &key) const
Retrieve a metadata string by key name.
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:126
AlphaSPtr _alphas
Optionally loaded AlphaS object.
Definition: PDF.h:509