### LHAPDF v5/v6 Compatibility Example Source: https://lhapdf.hepforge.org/_2examples_2compatibility_8cc-example.html This example demonstrates how to use LHAPDF to retrieve parton density information, with conditional compilation for LHAPDF v5 and v6. It requires the LHAPDF library to be installed. ```cpp // -*- C++ -*- // LHAPDFv5/v6 compatibility example #include "LHAPDF/LHAPDF.h" #include int main() { const double x = 1e-3, Q = 200; #if LHAPDF_MAJOR_VERSION == 6 LHAPDF::PDF* pdf = LHAPDF::mkPDF("CT10nlo", 0); std::cout << "xf_g = " << pdf->xfxQ(21, x, Q) << std::endl; delete pdf; #else LHAPDF::initPDFSet("CT10nlo", LHAPDF::LHGRID, 0); std::cout << "xf_g = " << LHAPDF::xfx(x, Q, 0) << std::endl; #endif return 0; } ``` -------------------------------- ### Fortran Example: Using PDFs Source: https://lhapdf.hepforge.org/codeexamples.html An example Fortran program demonstrating how to initialize PDF sets by name, retrieve PDF information (like xmin, xmax, Q2min, Q2max), and evolve PDFs at different x and Q values. ```APIDOC ## Using PDFs in Fortran This example demonstrates the usage of LHAPDF in Fortran. ### Program Structure - Initializes PDF sets by name. - Retrieves information about available PDF sets. - Gets range information (xmin, xmax, Q2min, Q2max) for each set. - Evolves PDFs for various partons (up, down, gluon, etc.) at specified x and Q values. - Handles sets with and without photon PDFs. ### Key Functions Used: - `initpdfsetbyname(name)`: Initializes a PDF set using its name. - `numberpdf()`: Returns the number of available PDF sets. - `initpdf(i)`: Initializes the i-th PDF set. - `getxmin(i, xmin)`: Gets the minimum x value for PDF set i. - `getxmax(i, xmax)`: Gets the maximum x value for PDF set i. - `getq2min(i, q2min)`: Gets the minimum Q^2 value for PDF set i. - `getq2max(i, q2max)`: Gets the maximum Q^2 value for PDF set i. - `getminmax(i, xmin, xmax, q2min, q2max)`: Gets all range information for PDF set i. - `alphaspdf(qmz)`: Calculates alpha_s at a given scale. - `getlam4m(1, i, xlam4)`: Retrieves lambda_4 for PDF set i. - `getlam5m(1, i, xlam5)`: Retrieves lambda_5 for PDF set i. - `evolvepdf(x, q, f)`: Evolves PDFs for a given x and Q. - `evolvepdfphoton(x, q, f, photon)`: Evolves PDFs including the photon component. - `has_photon()`: Checks if the current PDF set includes a photon. ### Example Snippet: ```fortran program example1 implicit double precision (a-h,o-z) character name*64 double precision f(-6:6) character*20 lparm logical has_photon dimension z(10), xx(10) Data (z(i), i=1,10) /.05, .1, .2, .3, .4, .5, .6, .7, .8, .9/ Do i = 1, 10 xx(i) = z(i) **3 EndDo name='CT10nlo.LHgrid' call initpdfsetbyname(name) qmz=91.18d0 call numberpdf(n) print *,'There are ',n,' PDF sets' do i=0,n call initpdf(i) write(*,*) 'PDF set ',i call getminmax(i,xmin,xmax,q2min,q2max) print *,'xmin=',xmin,' xmax=',xmax,' Q2min=',q2min,' Q2max=',q2max write(*,*) a=alphaspdf(qmz) write(*,*) 'alpha_S(M_Z) = ',a call getlam5m(1,i,xlam5) print *,' lambda5: ',xlam5 write(*,*) write(*,*) 'x*up' write(*,*) ' x Q=10 GeV Q=100 GeV Q=1000 GeV' q = 50.0d0 print *,q do ix=1,10 x = xx(ix) if(has_photon()) then print *,"This set has a photon" call evolvepdfphoton(x,q,f,photon) else call evolvepdf(x,q,f) endif g = f(0) u = f(2) d = f(1) write(*,'(F7.4,13(1pE10.3))') x,u,d,g enddo enddo end program example1 ``` ``` -------------------------------- ### Configure Runtime Environment Variables Source: https://lhapdf.hepforge.org/install.html Example of setting PATH, LD_LIBRARY_PATH, and PYTHONPATH to point to a custom LHAPDF installation directory. ```bash export PATH=$PATH:/foo/lhapdf/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/foo/lhapdf/lib export PYTHONPATH=$PYTHONPATH:/foo/lhapdf/lib/python3.9/site-packages ``` -------------------------------- ### Build and Install LHAPDF from Source Source: https://lhapdf.hepforge.org/install.html Standard sequence of commands to download, configure, and install the LHAPDF library on a system with a C++11 compiler. ```bash wget https://lhapdf.hepforge.org/downloads/?f=LHAPDF-6.X.Y.tar.gz -O LHAPDF-6.X.Y.tar.gz # ^ or use a web browser to download, which will get the filename correct tar xf LHAPDF-6.X.Y.tar.gz cd LHAPDF-6.X.Y ./configure --prefix=/path/for/installation make make install ``` -------------------------------- ### Install via Fedora dnf Source: https://lhapdf.hepforge.org/install.html Install LHAPDF and development headers using dnf. ```bash sudo dnf install lhapdf lhapdf-devel python3-lhapdf ``` -------------------------------- ### AnalyticPDF Example Source: https://lhapdf.hepforge.org/codeexamples.html Example of creating a custom PDF subclass in C++. ```APIDOC ## AnalyticPDF C++ Example ### Description This example demonstrates how to create a custom PDF subclass named `AnalyticPDF` by inheriting from `LHAPDF::PDF` and implementing the necessary virtual functions. ### Code Structure ```cpp #include "LHAPDF/PDF.h" #include struct AnalyticPDF : public LHAPDF::PDF { AnalyticPDF() { info().set_entry("Flavors", "-5,-4,-3,-2,-1,21,1,2,3,4,5"); } double _xfxQ2(int id, double x, double q2) const override { if (abs(id) > 5 && id != 21) return 0; return 0.15 * sin(20.0*x) * sin(20.0*q2); } void _xfxQ2(double x, double q2, std::vector& ret) const override { for (int id(-5); id<5; ++id) _xfxQ2(id,x,q2); } bool inRangeX(double x) const override { return true; } bool inRangeQ2(double q2) const override { return true; } }; int main(int argc, const char* argv[]) { AnalyticPDF apdf; LHAPDF::PDF& pdf = apdf; for (double x = 0; x < 1.0; x += 0.1) { for (double logq2 = 1; logq2 < 6; logq2 += 0.5) { const double q2 = pow(10, logq2); std::cout << x << " " << q2 << " " << pdf.xfxQ2(21, x, q2) << std::endl; } } return 0; } ``` ### Usage Compile and run the C++ code. The `main` function iterates through various `x` and `q2` values, calculating and printing the PDF value for the gluon (id=21) using the custom `AnalyticPDF` implementation. ``` -------------------------------- ### Install via OpenSUSE zypper Source: https://lhapdf.hepforge.org/install.html Install LHAPDF using the OpenSUSE package manager. ```bash sudo zypper install lhapdf ``` -------------------------------- ### Install via Gentoo emerge Source: https://lhapdf.hepforge.org/install.html Install LHAPDF using the Gentoo package manager. ```bash sudo emerge --ask lhapdf ``` -------------------------------- ### Configure LHAPDF build Source: https://lhapdf.hepforge.org/install.html Set up the build environment by specifying the installation prefix. ```bash ./configure --prefix=$HOME/local ``` -------------------------------- ### Check LHAPDF Version and Data Directory via LCG Source: https://lhapdf.hepforge.org/install.html After sourcing the LCG setup script, verify the installed LHAPDF version and query the default data directory using `lhapdf --version` and `lhapdf-config --datadir`. ```bash ~ $ lhapdf --version 6.5.3 ~ $ lhapdf-config --datadir /cvmfs/sft.cern.ch/lcg/releases/MCGenerators/lhapdf/6.5.3-642a8/x86_64-ubuntu2004-gcc9-opt/share/LHAPDF ``` -------------------------------- ### AnalyticPDF Example Implementation Source: https://lhapdf.hepforge.org/_2examples_2analyticpdf_8cc-example.html An example implementation of an analytic PDF using the LHAPDF::PDF interface. ```APIDOC ## struct AnalyticPDF : public LHAPDF::PDF ### Description An example implementation of an analytic PDF that inherits from `LHAPDF::PDF`. ### Constructor `AnalyticPDF()` Initializes the PDF with specific flavor information. ### Methods #### `double _xfxQ2(int id, double x, double q2) const` Calculates the PDF xf(x) value at (x,q2) for the given PID using an analytic formula. #### `void _xfxQ2(double x, double q2, std::vector& ret) const` Calculates PDF values for multiple PIDs at a given (x,q2). #### `bool inRangeX(double x) const` Always returns true, indicating x is always in range. #### `bool inRangeQ2(double q2) const` Always returns true, indicating Q2 is always in range. ### Example Usage ```cpp #include "LHAPDF/PDF.h" #include struct AnalyticPDF : public LHAPDF::PDF { AnalyticPDF() { info().set_entry("Flavors", "-5,-4,-3,-2,-1,21,1,2,3,4,5"); } double _xfxQ2(int id, double x, double q2) const { if (abs(id) > 5 && id != 21) return 0; return 0.15 * sin(20.0*x) * sin(20.0*q2); } void _xfxQ2(double x, double q2, std::vector& ret) const { for (int id(-5); id<5; ++id) _xfxQ2(id,x,q2); } bool inRangeX(double x) const { return true; } bool inRangeQ2(double q2) const { return true; } }; int main(int argc, const char* argv[]) { AnalyticPDF apdf; LHAPDF::PDF& pdf = apdf; for (double x = 0; x < 1.0; x += 0.1) { for (double logq2 = 1; logq2 < 6; logq2 += 0.5) { const double q2 = pow(10, logq2); std::cout << x << " " << q2 << " " << pdf.xfxQ2(21, x, q2) << std::endl; } } return 0; } ``` ``` -------------------------------- ### Get Ordered List of Search Paths Source: https://lhapdf.hepforge.org/Paths_8h_source.html Retrieves the ordered list of search paths, which includes the $LHAPDF_DATA_PATH environment variable and the default install location. The install prefix is appended unless $LHAPDF_DATA_PATH ends with '::'. ```cpp #include "LHAPDF/Utils.h" namespace LHAPDF { /// @brief Get the ordered list of search paths, from $LHAPDF_DATA_PATH and the install location /// @note The install prefix will be appended *unless* $LHAPDF_DATA_PATH ends with a double colon, i.e. '::' std::vector paths(); } ``` -------------------------------- ### Install via Homebrew on macOS Source: https://lhapdf.hepforge.org/install.html Add the homebrew-hep tap and install LHAPDF. ```bash brew tap davidchall/hep brew install lhapdf ``` -------------------------------- ### Install via Arch Linux pacman Source: https://lhapdf.hepforge.org/install.html Install the required dependencies using the Arch Linux package manager. ```bash sudo pacman -Syu hepmc ``` -------------------------------- ### Calculate alpha_s and manage PDF resources Source: https://lhapdf.hepforge.org/_2tests_2testalphas_8cc-example.html Example usage of alpha_s calculation methods and cleanup of PDF objects. ```cpp << " num flavs = " << as_ode.numFlavorsQ(q) << endl; fo << q << " " << as_ode_q << endl; // const double as_ipol_q = as_ipol.alphasQ(q); // cout << "Interpolated solution: " << setprecision(3) << setw(6) << ( (as_ipol_q > 2) ? inf : as_ipol_q ) << endl; // fi << q << " " << as_ipol_q << endl; // const double as_ct10_q = pdf->alphasQ(q); // cout << "CT10 solution: " << setprecision(3) << setw(6) << as_ct10_q << endl; // fc << q << " " << as_ct10_q << endl; // const double as_ct10_q_2 = pdf->alphaS().alphasQ(q); // cout << "CT10 AlphaS solution: " << setprecision(3) << setw(6) << as_ct10_q_2 // << " agrees = " << boolalpha << (as_ct10_q == as_ct10_q_2) << endl; // cout << endl; } fa.close(); fo.close(); fi.close(); fc.close(); delete pdf; #ifdef HAVE_MPI MPI_Finalize(); #endif return 0; } ``` -------------------------------- ### Test LHAPDF Info System Source: https://lhapdf.hepforge.org/_2tests_2testinfo_8cc-example.html Example program demonstrating how to access global configuration, PDF set metadata, and individual PDF member information. ```cpp // Example program for testing the info system #include "LHAPDF/Info.h" #include "LHAPDF/Config.h" #include "LHAPDF/PDFInfo.h" #include "LHAPDF/PDFSet.h" #include "LHAPDF/Factories.h" #include #ifdef HAVE_MPI #include #endif using namespace std; int main(int argc, char* argv[]) { #ifdef HAVE_MPI MPI_Init(&argc, &argv); #endif LHAPDF::Info& cfg = LHAPDF::getConfig(); // cout << "UndefFlavorAction: " << cfg.get_entry("UndefFlavorAction") << endl; cout << "Verbosity: " << cfg.get_entry("Verbosity") << endl; cfg.set_entry("Verbosity", 5); const LHAPDF::Info& cfg2 = LHAPDF::getConfig(); cout << "New Verbosity from second Config: " << cfg2.get_entry("Verbosity") << endl; const LHAPDF::PDFSet set("CT10nlo"); cout << "SetDesc: " << set.get_entry("SetDesc") << endl; cout << "Verbosity from set: " << set.get_entry("Verbosity") << endl; const LHAPDF::PDFInfo info("CT10nlo", 2); if (info.has_key("PdfDesc")) cout << "PdfDesc: " << info.get_entry("PdfDesc") << endl; cout << "PdfType: " << info.get_entry("PdfType") << endl; cout << "Verbosity from PDF: " << info.get_entry("Verbosity") << endl; vector pids = info.get_entry_as< vector >("Flavors"); cout << "PIDs (1): "; for (int f : pids) { cout << f << " "; } cout << endl; cout << "PIDs (2): " << LHAPDF::to_str(pids) << endl; // Now test loading of all central PDFs for (const string& name : LHAPDF::availablePDFSets()) { cout << "Testing PDFInfo for " << name << endl; LHAPDF::PDFInfo* i = LHAPDF::mkPDFInfo(name, 0); i->has_key("Foo"); // < Force loading of all info levels delete i; } #ifdef HAVE_MPI MPI_Finalize(); #endif return 0; } ``` -------------------------------- ### Initialize and Query PDF Sets Source: https://lhapdf.hepforge.org/_2examples_2pythonexample_8py-example.html Demonstrates loading PDF sets, querying xfx values, and iterating over flavors. ```python #! /usr/bin/env python import lhapdf p = lhapdf.mkPDF("CT10nlo", 0) p = lhapdf.mkPDF("CT10nlo/0") print(p.xfxQ2(21, 1e-3, 1e4)) for pid in p.flavors(): print(p.xfxQ(pid, 0.01, 91.2)) # TODO: demonstrate looping over PDF set members pset = lhapdf.getPDFSet("CT10nlo") print(pset.description) pcentral = pset.mkPDF(0) pdfs1 = pset.mkPDFs() pdfs2 = lhapdf.mkPDFs("CT10nlo") # a direct way to get all the set's PDFs import numpy as np xs = [x for x in np.logspace(-7, 0, 5)] qs = [q for q in np.logspace(1, 4, 4)] gluon_xfs = np.empty([len(xs), len(qs)]) for ix, x in enumerate(xs): for iq, q in enumerate(qs): gluon_xfs[ix,iq] = p.xfxQ(21, x, q) print(gluon_xfs) print(lhapdf.version()) print(lhapdf.__version__) lhapdf.pathsPrepend("/path/to/extra/pdfsets") print(lhapdf.paths()) # ... ``` -------------------------------- ### Initialize and Evolve PDFs in Fortran Source: https://lhapdf.hepforge.org/codeexamples.html Demonstrates loading a PDF set by name, iterating through members, and evolving the PDF to obtain parton distributions at specific x and Q values. ```Fortran program example1 implicit double precision (a-h,o-z) character name*64 double precision f(-6:6) character*20 lparm logical has_photon dimension z(10), xx(10) Data (z(i), i=1,10) /.05, .1, .2, .3, .4, .5, .6, .7, .8, .9/ Do i = 1, 10 xx(i) = z(i) **3 EndDo name='CT10nlo.LHgrid' ! name='cteq6.LHgrid' ! name='cteq65.LHgrid' ! name='cteq66.LHgrid' ! name='MRST2006nnlo.LHgrid' ! name='MRST2001E.LHgrid' ! name='H12000ms.LHgrid' call initpdfsetbyname(name) qmz=91.18d0 write(*,*) call numberpdf(n) print *,'There are ',n,' PDF sets' do i=0,n write(*,*) '---------------------------------------------' call initpdf(i) write(*,*) 'PDF set ',i call getxmin(i,xmin) call getxmax(i,xmax) call getq2min(i,q2min) call getq2max(i,q2max) print *,'xmin=',xmin,' xmax=',xmax,' Q2min=',q2min,' Q2max=',q2max call getminmax(i,xmin,xmax,q2min,q2max) print *,'xmin=',xmin,' xmax=',xmax,' Q2min=',q2min,' Q2max=',q2max call setlhaparm('EXTRAPOLATE') !< These work, but have no effect call getlhaparm(18,lparm) !< These work, but have no effect print *,'lhaparm(18)=',lparm write(*,*) a=alphaspdf(qmz) write(*,*) 'alpha_S(M_Z) = ',a call getlam4m(1,i,xlam4) call getlam5m(1,i,xlam5) print *,' lambda5: ',xlam5, ' lambda4: ',xlam4 write(*,*) write(*,*) 'x*up' write(*,*) ' x Q=10 GeV Q=100 GeV Q=1000 GeV' ! q2 = 10.0d0 ! q = dsqrt(q2) q = 50.0d0 print *,q do ix=1,10 ! x = (ix-0.5d0)/10.0d0 x = xx(ix) ! x = z(ix) if(has_photon()) then print *,"This set has a photon" call evolvepdfphoton(x,q,f,photon) else call evolvepdf(x,q,f) endif g = f(0) u = f(2) d = f(1) s = f(3) c = f(4) b = f(5) ubar = f(-2) dbar = f(-1) sbar = f(-3) cbar = f(-4) bbar = f(-5) write(*,'(F7.4,13(1pE10.3))') x,u,d,ubar,dbar,s,sbar,c,cbar,b,bbar,g,photon enddo enddo end program example1 ``` -------------------------------- ### Testing the path searching system in C++ Source: https://lhapdf.hepforge.org/codeexamples.html Demonstrates how to list configured search paths, find specific files, and list available PDF sets. ```cpp // Test program for path searching machinery #include "LHAPDF/Paths.h" #include using namespace std; #ifdef HAVE_MPI #include #endif int main(int argc, char* argv[]) { #ifdef HAVE_MPI MPI_Init(&argc, &argv); #endif for (const string& p : LHAPDF::paths()) cout << p << endl; cout << "@" << LHAPDF::findFile("lhapdf.conf") << "@" << endl; cout << "List of available PDFs:" << endl; for (const string& s : LHAPDF::availablePDFSets()) cout << " " << s << endl; #ifdef HAVE_MPI MPI_Finalize(); #endif return 0; } ``` -------------------------------- ### Query and Configure PDFs in Python Source: https://lhapdf.hepforge.org/codeexamples.html Shows how to instantiate PDF objects, query values using xfxQ, and manage PDF search paths. ```Python #! /usr/bin/env python import lhapdf p = lhapdf.mkPDF("CT10nlo", 0) p = lhapdf.mkPDF("CT10nlo/0") print(p.xfxQ2(21, 1e-3, 1e4)) for pid in p.flavors(): print(p.xfxQ(pid, 0.01, 91.2)) # TODO: demonstrate looping over PDF set members pset = lhapdf.getPDFSet("CT10nlo") print(pset.description) pcentral = pset.mkPDF(0) pdfs1 = pset.mkPDFs() pdfs2 = lhapdf.mkPDFs("CT10nlo") # a direct way to get all the set's PDFs import numpy as np xs = [x for x in np.logspace(-7, 0, 5)] qs = [q for q in np.logspace(1, 4, 4)] gluon_xfs = np.empty([len(xs), len(qs)]) for ix, x in enumerate(xs): for iq, q in enumerate(qs): gluon_xfs[ix,iq] = p.xfxQ(21, x, q) print(gluon_xfs) print(lhapdf.version()) print(lhapdf.__version__) lhapdf.pathsPrepend("/path/to/extra/pdfsets") print(lhapdf.paths()) ``` -------------------------------- ### Setup and Test AlphaS Solvers Source: https://lhapdf.hepforge.org/codeexamples.html Initializes and configures three AlphaS solvers: AlphaS_Analytic, AlphaS_ODE, and AlphaS_Ipol. Demonstrates setting QCD order, quark masses, and lambda values for each solver. This snippet is useful for understanding the basic configuration of these solvers. ```C++ #include "LHAPDF/LHAPDF.h" #include #include #include #ifdef HAVE_MPI #include #endif using namespace LHAPDF; using namespace std; int main(int argc, char* argv[]) { #ifdef HAVE_MPI MPI_Init(&argc, &argv); #endif // Set up three standalone AlphaS solvers: AlphaS_Analytic as_ana; // Can set order of QCD (up to 4) // 0 returns a constant value -- needs to be set by as_ana.setAlphaSMZ(double value); as_ana.setOrderQCD(4); // Set quark masses for evolution (both transition points and gradients by default) as_ana.setQuarkMass(1, 0.0017); as_ana.setQuarkMass(2, 0.0041); as_ana.setQuarkMass(3, 0.1); as_ana.setQuarkMass(4, 1.29); as_ana.setQuarkMass(5, 4.1); as_ana.setQuarkMass(6, 172.5); as_ana.setLambda(3, 0.339); as_ana.setLambda(4, 0.296); as_ana.setLambda(5, 0.213); // Can override quark masses for Nf transitions thresholds by setting them explicitly // You can't mix the two: if you set one flavor threshold explicitly you need to set all of them. //as_ode.setQuarkThreshold(6, 650); //as_ode.setQuarkThreshold(5, 10); //as_ode.setQuarkThreshold(4, 2); //as_ode.setQuarkThreshold(3, 0.3); //as_ode.setQuarkThreshold(2, 0.1); //as_ode.setQuarkThreshold(1, 0.08); // Uncomment to use fixed flavor scheme for analytic solver // as_ana.setFlavorScheme(AlphaS::FIXED, 5); AlphaS_ODE as_ode; // As above: order = 0 returns // constant value set by // as_ode.setAlphaSMZ(double value); as_ode.setOrderQCD(5); as_ode.setMZ(91); as_ode.setAlphaSMZ(0.118); // as_ode.setMassReference(4.1); // as_ode.setAlphaSReference(0.21); as_ode.setQuarkMass(1, 0.0017); as_ode.setQuarkMass(2, 0.0041); as_ode.setQuarkMass(3, 0.1); as_ode.setQuarkMass(4, 1.29); as_ode.setQuarkMass(5, 4.1); as_ode.setQuarkMass(6, 172.5); // Can override quark masses for Nf transitions thresholds by setting them explicitly // You can't mix the two: if you set one flavor threshold explicitly you need to set all of them. // as_ode.setQuarkThreshold(6, 650); // as_ode.setQuarkThreshold(5, 10); // as_ode.setQuarkThreshold(4, 2); // as_ode.setQuarkThreshold(3, 0.3); // as_ode.setQuarkThreshold(2, 0.1); // as_ode.setQuarkThreshold(1, 0.08); // Uncomment to use fixed flavor scheme for ODE solver // as_ode.setFlavorScheme(AlphaS::FIXED, 4); AlphaS_Ipol as_ipol; vector qs = { 1.300000e+00, 1.300000e+00, 1.560453e+00, 1.873087e+00, 2.248357e+00, 2.698811e+00, 3.239513e+00, 3.888544e+00, 4.667607e+00, 5.602754e+00, 6.725257e+00, 8.072650e+00, 9.689992e+00, 1.163137e+01, 1.396169e+01, 1.675889e+01, 2.011651e+01, 2.414681e+01, 2.898459e+01, 3.479160e+01, 4.176203e+01, 5.012899e+01, 6.017224e+01, 7.222765e+01, 8.669834e+01, 1.040682e+02, 1.249181e+02, 1.499452e+02, 1.799865e+02, 2.160465e+02, 2.593310e+02, 3.112875e+02, 3.736534e+02, 4.485143e+02, 5.383733e+02, 6.462355e+02, 7.757077e+02, 9.311194e+02, 1.117668e+03, 1.341590e+03, 1.610376e+03, 1.933012e+03, 2.320287e+03, 2.785153e+03, 3.343154e+03, 4.012949e+03, 4.816936e+03, 4.816936e+03 }; vector alphas = { 4.189466e-01, 4.189466e-01, 3.803532e-01, 3.482705e-01, 3.211791e-01, 2.979983e-01, 2.779383e-01, 2.604087e-01, 2.451922e-01, 2.324903e-01, 2.210397e-01, 2.106640e-01, 2.012187e-01, 1.925841e-01, 1.846600e-01, 1.773623e-01, 1.706194e-01, 1.643704e-01, 1.585630e-01, 1.531520e-01, 1.480981e-01, 1.433671e-01, 1.389290e-01, 1.347574e-01, 1.308290e-01, 1.271232e-01, 1.236215e-01, 1.203076e-01, 1.171667e-01, 1.141857e-01, 1.113525e-01, 1.086566e-01, 1.060881e-01, 1.036382e-01, 1.012990e-01, 9.906295e-02, 9.692353e-02, 9.487457e-02, 9.291044e-02, 9.102599e-02, 8.921646e-02, 8.747747e-02, 8.580498e-02, 8.419524e-02, 8.264479e-02, 8.115040e-02, 7.970910e-02, 7.970910e-02 }; as_ipol.setQValues(qs); as_ipol.setAlphaSValues(alphas); // Can interpolate ODE with given knots in Q // as_ode.setQValues(qs); // Test these solvers and the CT10nlo PDF's default behaviours: PDF* pdf = mkPDF("CT10", 0); const double inf = numeric_limits::infinity(); ofstream fa("alphas_ana.dat"), fo("alphas_ode.dat"), fi("alphas_ipol.dat"), fc("alphas_ct10nlo.dat"); cout << endl; for (double log10q = -0.5; log10q < 3; log10q += 0.05) { const double q = pow(10, log10q); const double as_ana_q = as_ana.alphasQ(q); cout << fixed; cout << "Q = " << setprecision(3) << q << " GeV" << endl; cout << "Analytical solution: " << setprecision(3) << setw(6) << ( (as_ana_q > 2) ? inf : as_ana_q ) << " num flavs = " << as_ana.numFlavorsQ(q) << endl; fa << q << " " << as_ana_q << endl; const double as_ode_q = as_ode.alphasQ(q); cout << "ODE solution: " << setprecision(3) << setw(6) << ( (as_ode_q > 2) ? inf : as_ode_q ) << " num flavs = " << as_ode.numFlavorsQ(q) << endl; fo << q << " " << as_ode_q << endl; // const double as_ipol_q = as_ipol.alphasQ(q); // cout << "Interpolated solution: " << setprecision(3) << setw(6) << ( (as_ipol_q > 2) ? inf : as_ipol_q ) << endl; // fi << q << " " << as_ipol_q << endl; } ``` -------------------------------- ### Print Set Summary Source: https://lhapdf.hepforge.org/PDFSet_8h_source.html Prints a summary of the set configuration. ```cpp void print(std::ostream& os=std::cout, int verbosity=1) const; ``` -------------------------------- ### C++ Example: Test PDF Grid Reading and Interpolation Source: https://lhapdf.hepforge.org/codeexamples.html This program tests PDF grid format reading and interpolation. It loads a specified PDF set, accesses its metadata, and demonstrates interpolation using xfxQ and xfxQ2 functions. It also writes interpolated data to 'pdf.dat'. ```cpp #include "LHAPDF/GridPDF.h" #include #include #ifdef HAVE_MPI #include #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 " << endl; //exit(1); } const string setname = (argc < 2) ? "CT10nlo" : argv[1]; const LHAPDF::PDF* basepdf = LHAPDF::mkPDF(setname); const LHAPDF::GridPDF& pdf = * dynamic_cast(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 pids = pdf.info().get_entry_as< vector >("Flavors"); cout << "Flavors (ints) = "; for (int f : pids) cout << f << " "; cout << endl; cout << "Flavors (vec) = " << 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; } ``` -------------------------------- ### Create PDF Grids with creategrids Source: https://lhapdf.hepforge.org/migration.html Use this command to create .info and .lha files for a given PDF set. Ensure LHAPDF5 is installed with its Python module. ```bash ./creategrids CT10.LHgrid ``` -------------------------------- ### LHAPDF::Extrapolator::pdf Source: https://lhapdf.hepforge.org/Extrapolator_8h_source.html Get the associated GridPDF. ```APIDOC ## LHAPDF::Extrapolator::pdf ### Description Get the associated GridPDF. ### Method const GridPDF& pdf() const ### Definition Extrapolator.h:40 ``` -------------------------------- ### LHAPDF::PDF::set Source: https://lhapdf.hepforge.org/PDF_8h_source.html Gets the PDF set of which this PDF is a member. ```APIDOC ## GET /api/pdf/set ### Description Get the PDF set of which this is a member. ### Method GET ### Endpoint /api/pdf/set ### Response #### Success Response (200) - **pdf_set** (PDFSet&) - Reference to the PDFSet object. #### Response Example ```json { "pdf_set": "" } ``` ``` -------------------------------- ### LHAPDF::PDF::orderQCD Source: https://lhapdf.hepforge.org/PDF_8h_source.html Gets the order of QCD at which this PDF was constructed. ```APIDOC ## GET /api/pdf/orderQCD ### Description Order of QCD at which this PDF has been constructed. ### Method GET ### Endpoint /api/pdf/orderQCD ### Response #### Success Response (200) - **order** (int) - The order of QCD. #### Response Example ```json { "order": 2 } ``` ``` -------------------------------- ### GET /LHAPDF/version Source: https://lhapdf.hepforge.org/Version_8h_source.html Retrieves the current version string of the LHAPDF library. ```APIDOC ## GET /LHAPDF/version ### Description Returns the current version of the LHAPDF library as a string. ### Method GET ### Response #### Success Response (200) - **version** (string) - The version string of the library (e.g., "6.5.5"). #### Response Example "6.5.5" ``` -------------------------------- ### GET /LHAPDF/verbosity Source: https://lhapdf.hepforge.org/Config_8h_source.html Retrieves the current verbosity level of the LHAPDF system. ```APIDOC ## GET /LHAPDF/verbosity ### Description Returns the current verbosity level. Levels are defined as: 0=silent, 1=standard, 2=debug. ### Method GET ### Endpoint LHAPDF::verbosity() ### Response #### Success Response (200) - **level** (int) - The current verbosity level (0, 1, or 2). ``` -------------------------------- ### Initialize EESSI Environment and Load LHAPDF Source: https://lhapdf.hepforge.org/install.html Source the EESSI environment script to set up the necessary paths and modules, then load the LHAPDF package. This prepares your shell to use LHAPDF from the EESSI repository. ```bash ~ $ source /cvmfs/software.eessi.io/versions/2023.06/init/bash Found EESSI repo @ /cvmfs/software.eessi.io/versions/2023.06! archdetect says x86_64/intel/haswell Using x86_64/intel/haswell as software subdirectory. Using /cvmfs/software.eessi.io/versions/2023.06/software/linux/x86_64/intel/haswell/modules/all as the directory to be added to MODULEPATH. Found Lmod configuration file at /cvmfs/software.eessi.io/versions/2023.06/software/linux/x86_64/intel/haswell/.lmod/lmodrc.lua Initializing Lmod... Prepending /cvmfs/software.eessi.io/versions/2023.06/software/linux/x86_64/intel/haswell/modules/all to $MODULEPATH... Environment set up to use EESSI (2023.06), have fun! {EESSI 2023.06} ~ $ module load LHAPDF ```