Python Tutorial
This tutorial introduces the Python interface for PDFxTMDLib, which mirrors the C++ API and supports both high-level and low-level access to PDF and TMD calculations.
Installation
The Python bindings can be installed easily via pip:
pip install pdfxtmd
High-Level Interface
The high-level interface is centered around the CPDFSet
and TMDSet
classes.
Collinear PDFs
Here is an example demonstrating the usage of the CPDFSet
class:
import pdfxtmd
# Create a CPDFSet object for the CT18NLO PDF set
cpdf_set = pdfxtmd.CPDFSet("CT18NLO")
# Access structured metadata
std_info = cpdf_set.getStdPDFInfo()
print(f"Description: {std_info.SetDesc}")
print(f"Number of Members: {std_info.NumMembers}")
# Define kinematics
x = 0.01
mu2 = 100
# Access the central PDF member
central_cpdf = cpdf_set[0]
up_pdf_central = central_cpdf.pdf(pdfxtmd.PartonFlavor.u, x, mu2)
print(f"Central Up Quark PDF at x={x}, mu2={mu2}: {up_pdf_central:.6f}")
# Calculate PDF uncertainty at 68% confidence level
uncertainty = cpdf_set.Uncertainty(pdfxtmd.PartonFlavor.u, x, mu2, cl=68.0)
print(f"Uncertainty: {uncertainty.central} +{uncertainty.errplus} -{uncertainty.errminus}")
TMD PDFs
For TMD PDFs, the TMDSet
class offers similar functionality.
Low-Level Interface
The low-level interface allows direct access to individual PDF members using factory classes.
# Create a factory and a single CPDF member
cpdf_factory = pdfxtmd.GenericCPDFFactory()
cpdf_member = cpdf_factory.mkCPDF("CT18NLO", 0)
# Evaluate the PDF for a specific flavor
up_pdf = cpdf_member.pdf(pdfxtmd.PartonFlavor.u, x, mu2)
print(f"Up quark PDF: {up_pdf}")
Strong Coupling Constant
The Python interface also supports calculating the strong coupling constant $\alpha_s$.
alpha_s = cpdf_set.alphasQ2(mu2)
A comprehensive tutorial is available in the project’s GitHub repository: tutorial.py.