SystematicsCalculator

class SystematicsCalculator

Computes LHEF weight variations (scale and PDF systematics) of combined, already-generated events.

The PDFs and alpha_s are evaluated with the regular batched madspace functions (PartonDensity, RunningCoupling) on context (a CPU context; one is created when none is given): the grids of the nominal PDF and of every varied member are registered as globals of that context under a private prefix. Built once per run from a SystematicsConfig, then reused for every combined event via compute.

Public Functions

SystematicsCalculator(const SystematicsConfig &config, const std::vector<SubprocessSystArgs> &subproc_args, const std::optional<PdfGrid> &nominal_pdf, const std::optional<AlphaSGrid> &nominal_alpha_s, ContextPtr context = nullptr, const std::vector<std::optional<MatrixElement>> &matrix_elements = {}, const nested_vector2<me_int_t> &me_flavor_remap = {}, const std::optional<PdfGrid> &nominal_pdf2 = std::nullopt)
Parameters:
  • config – The scale and PDF variations to compute.

  • subproc_args – Per-subprocess bookkeeping needed to reweight its events; indexed like the subprocess index passed to compute.

  • nominal_pdf – The PDF the events were generated with; nullopt for leptonic beams.

  • nominal_alpha_s – The alpha_s grid the events were generated with.

  • context – Context the PDF and alpha_s runtimes are built on; a private CPU context if nullptr.

  • matrix_elements – One matrix element per subprocess (may be empty or nullopt), enabling the exact renormalization-scale variation of subprocesses whose |M|^2 mixes several powers of alpha_s (qcd_power == -1): it is re-evaluated at the varied alpha_s on context. Must take (momenta, alpha_s, flavor) and return the matrix element only.

  • me_flavor_remap – me_flavor_remap[subprocess][flavor_index] is the flavor passed to that subprocess’s matrix element.

  • nominal_pdf2 – PDF of the second beam when its set differs from nominal_pdf (which is then the first beam’s). PDF member variations are then dropped with a warning; the scale variations use both sets.

inline const SystematicsConfig &config() const

The configuration passed to the constructor.

inline const std::vector<Variation> &variations() const

Every variation to compute, in weight order.

inline std::size_t weight_count() const

Number of variations, i.e. weights per event.

std::vector<int> weight_ids() const

LHEF <weight> ids, in the order of variations.

inline const std::vector<PdfMemberSpec> &members() const

PDF members actually used (the nominal set’s member 0 first, when it is part of a group).

inline const std::vector<std::string> &warnings() const

Warnings emitted while building the variation list.

std::vector<std::size_t> scale_variation_indices() const

Indices into variations of the scale variations (the envelope group).

std::vector<PdfGroupInfo> pdf_groups() const

The PDF groups, one per set with members among variations.

void compute(EventBuffer &buffer, std::vector<double> &weights) const

Compute the weights of every variation for the events of buffer.

buffer must carry the combined-event layout (weight, subprocess index, event data, momenta and the partial weight columns). weights is resized to event_count * weight_count(), row-major per event, and holds the varied event weights, not the ratios to the nominal weight. Thread-safe.

LOReweightInfo reweight_info(EventBuffer &buffer, std::size_t event_index) const

The reweighting inputs of one event of buffer.

void accumulate(EventBuffer &buffer, const std::vector<double> &weights)

Accumulate the cross sections of every variation over buffer’s events and their weights.

Thread-safe.

std::string initrwgt() const

<initrwgt> header content (without the enclosing tag), following the conventions of systematics.py (weight groups and attributes).

nlohmann::json summary() const

JSON description of the variations and, once events were accumulated, the per-variation cross sections and the scale/PDF uncertainties.

Public Static Functions

static std::tuple<double, double, double> pdf_uncertainty(const std::string &error_type, std::optional<double> central, const std::vector<std::pair<int, double>> &member_values)

Combined PDF uncertainty for the given LHAPDF error_type.

Parameters:
  • error_type – LHAPDF ErrorType (replicas, hessian, …).

  • central – Central value; used when member 0 is absent from member_values.

  • member_values – (member number, value) pairs; member 0 is the central member.

Returns:

(central, up, down); NaN entries when they cannot be computed.

static double dynamical_scale(int dyn, const std::vector<std::array<double, 4>> &momenta)

Dynamical scale dyn (1-4; see SystematicsConfig::dyn_scales) of an event from its momenta (momenta[particle][component], E px py pz, incoming particles first).

static std::string dyn_scale_name(int dyn)

Human-readable name of dynamical scale choice dyn.

static std::string format_number(double value)

value formatted for LHEF text output.