pyhs3.distributions.histfactory.data.SampleData

class pyhs3.distributions.histfactory.data.SampleData(**data)[source]

Sample data containing bin contents and optional per-bin uncertainties.

This class represents the binned values for a single sample in a HistFactory- style model, along with optional statistical uncertainties (“errors”) per bin.

Note

  • The errors field is optional in serialized form. If omitted, it is interpreted as an array of zeros with the same length as contents. This follows the convention used in ROOT HistFactory/HS3 workflows, where some samples may not carry explicit bin-by-bin uncertainties (e.g. when BBlight is not applied).

  • Internally, errors are always materialized and accessible via the errors property.

  • If provided, errors must have the same length as contents.

Parameters:
  • contents – list[float] The bin contents (yields) for the sample.

  • errors – list[float] | None Optional serialized representation of per-bin uncertainties. This is aliased to "errors" when exporting. If None, errors are implicitly treated as zeros and omitted from serialization.

  • data (Any)

Raises:

ValueError – If contents and errors are both provided and have different lengths.

Fields

Field

Type

Required

Default

Alias

contents

list[float]

Yes

v_errors

list[float] | None

No

None

errors

Validators

Validator

Mode

Fields

set_default_and_validate

after

model

__init__(**data)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

Methods

model_post_init(context, /)

This function is meant to behave like a BaseModel method to initialise private attributes.

set_default_and_validate()

Ensure contents and errors have same length.

Attributes

errors

Return the per-bin uncertainties for the sample.

contents

v_errors

SampleData.model_post_init(context, /)

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

SampleData.set_default_and_validate()[source]

Ensure contents and errors have same length.

Return type:

SampleData

SampleData.errors

Return the per-bin uncertainties for the sample.

This property always returns a list of the same length as contents.

  • If uncertainties were explicitly provided, they are returned as-is.

  • If the errors field was omitted during initialization (e.g. in HS3 JSON where missing errors imply zeros), this returns a zero-filled list.

Returns:

The per-bin uncertainties corresponding to contents.

Return type:

list[float]

SampleData.contents
SampleData.v_errors