C++ Tutorial

This tutorial demonstrates how to use the PDFxTMDLib API to calculate collinear and TMD PDFs, perform uncertainty analysis, and access set metadata.

High-Level Interface: The PDFSet Class

The PDFSet class is the primary interface for all standard operations. It is a template class that is specialized for either collinear (CollinearPDFTag) or TMD (TMDPDFTag) distributions.

PDF and TMD Calculation

An instance of PDFSet is created by providing the name of the desired PDF set.

Collinear PDF:

// Instantiate a PDFSet for a collinear PDF
PDFxTMD::PDFSet<PDFxTMD::CollinearPDFTag> cpdfSet("MSHT20nlo_as120");

// Access the central member PDF (index 0)
auto central_pdf = cpdfSet[0];

// Define kinematics and evaluate the PDF
double x = 0.1, mu2 = 10000;
double gluon_pdf = central_pdf->pdf(PDFxTMD::PartonFlavor::g, x, mu2);
std::cout << "Central gluon PDF: " << gluon_pdf << std::endl;

TMD PDF:

// Instantiate a PDFSet for a TMD PDF
PDFxTMD::PDFSet<PDFxTMD::TMDPDFTag> tmdSet("PB-NLO-HERAI+II-2018-set2");

// Access the central member TMD (index 0)
auto central_tmd = tmdSet[0];

// Define kinematics and evaluate the TMD
double x = 0.01, kt2 = 10, mu2 = 100;
double up_tmd = central_tmd->tmd(PDFxTMD::PartonFlavor::u, x, kt2, mu2);
std::cout << "Central up-quark TMD: " << up_tmd << std.endl;

Uncertainty and Correlation Analysis

The PDFSet class has built-in support for uncertainty and correlation calculations.

// Calculate PDF uncertainty at the set's default confidence level
PDFxTMD::PDFUncertainty uncertainty = cpdfSet.Uncertainty(PDFxTMD::PartonFlavor::g, x, mu2);
std::cout << "xg = " << uncertainty.central << " + " << uncertainty.errplus
<< " - " << uncertainty.errminus << std::endl;

// Calculate the correlation between two PDF values
double correlation = cpdfSet.Correlation(PDFxTMD::PartonFlavor::g, x, mu2, 
PDFxTMD::PartonFlavor::u, x, mu2);
std::cout << "Correlation between g and u: " << correlation << std::endl;

Accessing Metadata

Access structured metadata about the set.

// Get structured standard info
PDFxTMD::YamlStandardPDFInfo std_info = cpdfSet.getStdPDFInfo();
std::cout << "Description: " << std_info.SetDesc << std::endl;
std::cout << "Num Members: " << std_info.NumMembers << std::endl;

Low-Level and Advanced Usage

Factory Interface

The factory functions mkCPDF and mkTMD can be used to create individual PDF members.

auto cpdf_factory = PDFxTMD::GenericCPDFFactory();
auto cpdf = cpdf_factory.mkCPDF("MMHT2014lo68cl", 0);
double gluon_pdf = cpdf.pdf(PDFxTMD::PartonFlavor::g, 0.001, 100);

Custom PDF Implementations

Users can create custom PDF objects by specializing the GenericPDF template.

// Define a custom PDF type with specific components
using ExtrapolatorType = PDFxTMD::CErrExtrapolator;
using ReaderType = PDFxTMD::CDefaultLHAPDFFileReader;
using InterpolatorType = PDFxTMD::CLHAPDFBilinearInterpolator;
using CustomPDF = PDFxTMD::GenericPDF<PDFxTMD::CollinearPDFTag, 
ReaderType, InterpolatorType, ExtrapolatorType>;

// Instantiate and use the custom PDF
CustomPDF pdf("MMHT2014lo68cl", 0);
double custom_gluon_pdf = pdf.pdf(PDFxTMD::PartonFlavor::g, 0.001, 100);

Strong Coupling Constant

Calculate the strong coupling constant, $\alpha_s(\mu^2)$.

// Method 1: From a PDFSet (recommended for consistency)
double alpha_s_from_set = cpdfSet.alphasQ2(10000);

// Method 2: Standalone factory
auto coupling_factory = PDFxTMD::CouplingFactory();
auto coupling = coupling_factory.mkCoupling("MMHT2014lo68cl");
double alpha_s_from_factory = coupling.AlphaQCDMu2(10000);

The complete example can be found in the project’s GitHub repository: tutorial.cpp.