lhapdf is hosted by Hepforge, IPPP Durham
LHAPDF 6.5.4
Loading...
Searching...
No Matches
/tests/testgrid.cc
// Example program to test PDF grid format reading and interpolation
#include "LHAPDF/GridPDF.h"
#include <iostream>
#include <fstream>
#ifdef HAVE_MPI
#include <mpi.h>
#endif
using namespace std;
void safeprint(const LHAPDF::PDF& pdf, const string& key) {
if (pdf.info().has_key(key))
cout << key << " = " << pdf.info().get_entry(key) << endl;
}
int main(int argc, char* argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
#endif
if (argc < 2) {
cout << "Usage: testgrid <PDFNAME=CT10nlo>" << endl;
//exit(1);
}
const string setname = (argc < 2) ? "CT10nlo" : argv[1];
const LHAPDF::PDF* basepdf = LHAPDF::mkPDF(setname);
const LHAPDF::GridPDF& pdf = * dynamic_cast<const LHAPDF::GridPDF*>(basepdf);
for (const string& p : LHAPDF::paths()) cout << p << " : ";
cout << endl;
safeprint(pdf, "Verbosity");
safeprint(pdf, "PdfDesc");
safeprint(pdf, "SetDesc");
cout << "Flavors (str) = " << pdf.info().get_entry("Flavors") << endl;
vector<int> pids = pdf.info().get_entry_as< vector<int> >("Flavors");
cout << "Flavors (ints) = ";
for (int f : pids) cout << f << " ";
cout << endl;
cout << "Flavors (vec<int>) = " << LHAPDF::to_str(pids) << endl;
cout << "x0, Q0 = " << pdf.knotarray().xf(21, 0, 0) << endl;
cout << "x1, Q0 = " << pdf.knotarray().xf(21, 1, 0) << endl;
cout << "x0, Q1 = " << pdf.knotarray().xf(21, 0, 1) << endl;
cout << "x1, Q1 = " << pdf.knotarray().xf(21, 1, 1) << endl;
cout << pdf.xfxQ(21, 0.7, 10.0) << endl;
cout << pdf.xfxQ(21, 0.2, 126) << endl;
for (int pid : pdf.flavors()) {
cout << pid << " = " << pdf.xfxQ(pid, 0.2, 124) << endl;
}
ofstream f("pdf.dat");
for (double x = 0; x <= 1; x += 0.02) {
for (double log10q2 = 1; log10q2 < 5; log10q2 += 0.05) {
f << x << " " << log10q2 << " " << pdf.xfxQ2(21, x, pow(10, log10q2)) << endl;
}
}
f.close();
cout << endl;
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return 0;
}
A PDF defined via an interpolation grid.
Definition GridPDF.h:19
T get_entry_as(const std::string &key) const
Definition Info.h:139
double xf(int ix, int iq2, int ipid) const
convenient accessor to the grid values
Definition KnotArray.h:68
const std::string & get_entry(const std::string &key) const
Retrieve a metadata string by key name.
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)
PDF is the general interface for access to parton density information.
Definition PDF.h:40
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.
virtual const std::vector< int > & flavors() const
List of flavours defined by this PDF set.
Definition PDF.h:418
PDFInfo & info()
Get the info class that actually stores and handles the metadata.
Definition PDF.h:352
PDF * mkPDF(const std::string &setname, size_t member)
std::vector< std::string > paths()
Get the ordered list of search paths, from $LHAPDF_DATA_PATH and the install location.
std::string to_str(const T &val)
Make a string representation of val.
Definition Utils.h:61