lhapdf is hosted by Hepforge, IPPP Durham
LHAPDF 6.5.4
Loading...
Searching...
No Matches
PDF.h
1// -*- C++ -*-
2//
3// This file is part of LHAPDF
4// Copyright (C) 2012-2023 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
20namespace LHAPDF {
21
22
26 namespace PIDs { //< for scoping to avoid conflicts, e.g. PID::GLUON rather than just GLUON
27 enum PIDCode {
28 ATOP = -6, ABOTTOM = -5, ACHARM = -4, ASTRANGE = -3, AUP = -2, ADOWN = -1,
29 GLUON = 0, // equivalent to 21
30 DOWN = 1, UP = 2, STRANGE = 3, CHARM = 4, BOTTOM = 5, TOP = 6
31 };
32 }
34
35
36
40 class PDF {
41 protected: //< These constructors should only be called by subclasses
42
44 typedef unique_ptr<AlphaS> AlphaSPtr;
45
47 PDF() : _forcePos(0) { }
48
49
50 public:
51
53 virtual ~PDF() { }
54
55
56 protected:
57
58
61
62 void _loadInfo(const std::string& mempath);
63
64 void _loadInfo(const std::string& setname, int member) {
65 const string searchpath = findpdfmempath(setname, member);
66 if (searchpath.empty())
67 throw UserError("Can't find a valid PDF " + setname + "/" + to_str(member));
68 _loadInfo(searchpath);
69 }
70
71 void _loadInfo(int lhaid) {
72 const pair<string,int> setname_memid = lookupPDF(lhaid);
73 if (setname_memid.second == -1)
74 throw IndexError("Can't find a PDF with LHAPDF ID = " + to_str(lhaid));
75 _loadInfo(setname_memid.first, setname_memid.second);
76 }
77
79
80
81 public:
82
85
95 double xfxQ2(int id, double x, double q2) const;
96
97
108 double xfxQ(int id, double x, double q) const {
109 return xfxQ2(id, x, q*q);
110 }
111
112
121 void xfxQ2(double x, double q2, std::map<int, double>& rtn) const;
122
123
132 void xfxQ(double x, double q, std::map<int, double>& rtn) const {
133 xfxQ2(x, q*q, rtn);
134 }
135
136
149 void xfxQ2(double x, double q2, std::vector<double>& rtn) const;
150
151
164 void xfxQ(double x, double q, std::vector<double>& rtn) const {
165 xfxQ2(x, q*q, rtn);
166 }
167
168
177 std::map<int, double> xfxQ2(double x, double q2) const;
178
191 std::map<int, double> xfxQ(double x, double q) const {
192 return xfxQ2(x, q*q);
193 }
194
195
196 protected:
197
210 virtual double _xfxQ2(int id, double x, double q2) const = 0;
211
212 virtual void _xfxQ2(double x, double q2, std::vector<double>& ret) const = 0;
213
215
216
217 public:
218
221
223 virtual double xMin() {
224 if (info().has_key("XMin"))
225 return info().get_entry_as<double>("XMin");
226 return numeric_limits<double>::epsilon();
227 }
228
230 virtual double xMax() {
231 if (info().has_key("XMax"))
232 return info().get_entry_as<double>("XMax");
233 return 1.0;
234 }
235
238 virtual double qMin() {
239 return info().get_entry_as<double>("QMin", 0);
240 }
241
244 virtual double qMax() {
245 return info().get_entry_as<double>("QMax", numeric_limits<double>::max());
246 }
247
249 virtual double q2Min() {
250 return sqr(this->qMin());
251 }
252
254 virtual double q2Max() {
255 // Explicitly re-access this from the info, to avoid an overflow from squaring double_max
256 return (info().has_key("QMax")) ? sqr(info().get_entry_as<double>("QMax")) : numeric_limits<double>::max();
257 }
258
259
265 int forcePositive() const {
266 if (_forcePos < 0) //< Caching
267 _forcePos = info().get_entry_as<unsigned int>("ForcePositive", 0);
268 return _forcePos;
269 }
271 void setForcePositive(int mode) {
272 _forcePos = mode;
273 }
274
275
280 bool inPhysicalRangeX(double x) const {
281 return x >= 0.0 && x <= 1.0;
282 }
283
287 bool inPhysicalRangeQ2(double q2) const {
288 return q2 >= 0.0;
289 }
290
294 bool inPhysicalRangeQ(double q) const {
295 return inPhysicalRangeQ2(q*q);
296 }
297
299 bool inPhysicalRangeXQ2(double x, double q2) const {
300 return inPhysicalRangeX(x) && inPhysicalRangeQ2(q2);
301 }
302
304 bool inPhysicalRangeXQ(double x, double q) const {
305 return inPhysicalRangeX(x) && inPhysicalRangeQ(q);
306 }
307
315 virtual bool inRangeQ(double q) const {
316 return inRangeQ2(q*q);
317 }
318
325 virtual bool inRangeQ2(double q2) const = 0;
326
333 virtual bool inRangeX(double x) const = 0;
334
336 virtual bool inRangeXQ(double x, double q) const {
337 return inRangeX(x) && inRangeQ(q);
338 }
339
341 bool inRangeXQ2(double x, double q2) const {
342 return inRangeX(x) && inRangeQ2(q2);
343 }
344
346
347
350
352 PDFInfo& info() { return _info; }
353
355 const PDFInfo& info() const { return _info; }
356
360 PDFSet& set() const {
361 return getPDFSet(_setname());
362 }
363
365
366
369
373 int memberID() const {
374 const string memname = file_stem(_mempath);
375 assert(memname.length() > 5); // There must be more to the filename stem than just the _nnnn suffix
376 const int memid = lexical_cast<int>(memname.substr(memname.length()-4)); //< Last 4 chars should be the member number
377 return memid;
378 }
379
383 int lhapdfID() const;
384
386 std::string description() const {
387 return info().get_entry("MemDesc", info().get_entry("PdfDesc", ""));
388 }
389
391 int dataversion() const {
392 return info().get_entry_as<int>("DataVersion", -1);
393 }
394
396 std::string type() const {
397 return to_lower(info().get_entry("MemType", info().get_entry("PdfType")));
398 }
399
401
402
404 void print(std::ostream& os=std::cout, int verbosity=1) const;
405
406
409
418 virtual const std::vector<int>& flavors() const {
419 if (_flavors.empty()) {
420 _flavors = info().get_entry_as< vector<int> >("Flavors");
421 sort(_flavors.begin(), _flavors.end());
422 }
423 return _flavors;
424 }
425
429 void setFlavors(std::vector<int> const& flavors) {
431 sort(_flavors.begin(), _flavors.end());
432 }
433
435 bool hasFlavor(int id) const;
436
444 int orderQCD() const {
445 return info().get_entry_as<int>("OrderQCD");
446 }
448 int qcdOrder() const { return orderQCD(); }
449
456 double quarkMass(int id) const;
457
463 double quarkThreshold(int id) const;
464
466
467
470
476 void setAlphaS(AlphaS* alphas) {
477 _alphas.reset(alphas);
478 }
479
481 void setAlphaS(AlphaSPtr alphas) {
482 _alphas = std::move(alphas);
483 }
484
486 bool hasAlphaS() const {
487 return bool(_alphas);
488 }
489
492 return *_alphas;
493 }
494
496 const AlphaS& alphaS() const {
497 return *_alphas;
498 }
499
504 double alphasQ(double q) const {
505 return alphasQ2(q*q);
506 }
507
512 double alphasQ2(double q2) const {
513 if (!hasAlphaS()) throw Exception("No AlphaS pointer has been set");
514 return _alphas->alphasQ2(q2);
515 }
516
518
519
520 protected:
521
522 void _loadAlphaS() {
523 _alphas.reset( mkAlphaS(info()) );
524 }
525
527 std::string _setname() const {
528 return basename(dirname(_mempath));
529 }
530
532 std::string _mempath;
533
536
538 mutable vector<int> _flavors;
539
542
548 mutable int _forcePos;
549
550 };
551
552
553}
554#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:139
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:105
PDF is the general interface for access to parton density information.
Definition PDF.h:40
bool inPhysicalRangeQ2(double q2) const
Check whether the given Q2 is physically valid.
Definition PDF.h:287
unique_ptr< AlphaS > AlphaSPtr
Internal convenience typedef for the AlphaS object handle.
Definition PDF.h:44
bool inRangeXQ2(double x, double q2) const
Combined range check for x and Q2.
Definition PDF.h:341
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:108
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:265
std::string _setname() const
Get the set name from the member data file path (for internal use only)
Definition PDF.h:527
std::string type() const
Get the type of PDF member that this object represents (central, error)
Definition PDF.h:396
AlphaSPtr _alphas
Optionally loaded AlphaS object (mutable for laziness/caching)
Definition PDF.h:541
virtual double xMin()
Minimum valid x value for this PDF.
Definition PDF.h:223
int orderQCD() const
Order of QCD at which this PDF has been constructed.
Definition PDF.h:444
void setAlphaS(AlphaSPtr alphas)
Set the AlphaS calculator by smart pointer.
Definition PDF.h:481
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:429
std::string _mempath
Member data file path.
Definition PDF.h:532
bool inPhysicalRangeXQ(double x, double q) const
Check whether the given (x,Q) is physically valid.
Definition PDF.h:304
int dataversion() const
Version of this PDF's data file.
Definition PDF.h:391
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*...
AlphaS & alphaS()
Retrieve the AlphaS object for this PDF.
Definition PDF.h:491
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:512
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:132
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:360
virtual ~PDF()
Virtual destructor, to allow unfettered inheritance.
Definition PDF.h:53
void setForcePositive(int mode)
Set whether the PDF will only return positive (definite) values or not.
Definition PDF.h:271
virtual bool inRangeQ(double q) const
Grid range check for Q.
Definition PDF.h:315
virtual const std::vector< int > & flavors() const
List of flavours defined by this PDF set.
Definition PDF.h:418
void setAlphaS(AlphaS *alphas)
Set the AlphaS calculator by pointer.
Definition PDF.h:476
vector< int > _flavors
Locally cached list of supported PIDs (mutable for laziness/caching)
Definition PDF.h:538
virtual double q2Min()
Minimum valid Q2 value for this PDF (in GeV2).
Definition PDF.h:249
double alphasQ(double q) const
Value of alpha_s(Q2) used by this PDF.
Definition PDF.h:504
const AlphaS & alphaS() const
Retrieve the AlphaS object for this PDF (const)
Definition PDF.h:496
virtual double qMax()
Maximum valid Q value for this PDF (in GeV).
Definition PDF.h:244
virtual double q2Max()
Maximum valid Q2 value for this PDF (in GeV2).
Definition PDF.h:254
const PDFInfo & info() const
Get the info class that actually stores and handles the metadata (const version)
Definition PDF.h:355
bool inPhysicalRangeX(double x) const
Check whether the given x is physically valid.
Definition PDF.h:280
std::string description() const
Description of this PDF member.
Definition PDF.h:386
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:164
bool inPhysicalRangeXQ2(double x, double q2) const
Check whether the given (x,Q2) is physically valid.
Definition PDF.h:299
virtual double xMax()
Maximum valid x value for this PDF.
Definition PDF.h:230
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:548
int qcdOrder() const
Definition PDF.h:448
virtual double qMin()
Definition PDF.h:238
virtual bool inRangeXQ(double x, double q) const
Combined range check for x and Q.
Definition PDF.h:336
bool inPhysicalRangeQ(double q) const
Check whether the given Q is physically valid.
Definition PDF.h:294
PDF()
Force initialization of the only non-class member.
Definition PDF.h:47
PDFInfo & info()
Get the info class that actually stores and handles the metadata.
Definition PDF.h:352
int memberID() const
PDF member local ID number.
Definition PDF.h:373
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:191
PDFInfo _info
Metadata container.
Definition PDF.h:535
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)
bool hasAlphaS() const
Check if an AlphaS calculator is set.
Definition PDF.h:486
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)
std::string findpdfmempath(const std::string &setname, int member)
Find a PDF member-data file path in the search paths.
Definition Paths.h:74
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
T lexical_cast(const U &in)
Convert between types via stringstream.
Definition Utils.h:47
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:56
Namespace for all LHAPDF functions and classes.
Definition AlphaS.h:14