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
errorsfield is optional in serialized form. If omitted, it is interpreted as an array of zeros with the same length ascontents. 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
errorsproperty.If provided,
errorsmust have the same length ascontents.
- 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. IfNone, errors are implicitly treated as zeros and omitted from serialization.data (
Any)
- Raises:
ValueError – If
contentsanderrorsare both provided and have different lengths.
Fields¶ Field
Type
Required
Default
Alias
Yes
No
NoneerrorsValidators¶ Validator
Mode
Fields
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.
Ensure contents and errors have same length.
Attributes
- 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.
- SampleData.set_default_and_validate()[source]¶
Ensure contents and errors have same length.
- Return type:
- 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
errorsfield was omitted during initialization (e.g. in HS3 JSON where missing errors imply zeros), this returns a zero-filled list.
- SampleData.contents¶
- SampleData.v_errors¶