feat: Implement Barlow-Beeston lite for staterror modifier#191
Conversation
Implements BB-lite for the staterror modifier in pyhs3's HistFactory distribution. BB-lite uses shared gamma parameters across samples with a channel-level constraint built from combined MC statistical uncertainties. Key changes: - Add barlow_beeston_method field to HistFactoryDistChannel (defaults to lite) - Make StatErrorModifier.data optional (None for lite mode) - Allow constraint: Poisson in addition to Gauss for staterror - Implement _make_barlow_beeston_lite_constraint() supporting both Poisson and Gaussian - Modify extended_likelihood() to skip per-sample constraints in lite mode - Add comprehensive test suite (12 tests) for BB-lite functionality BB-lite vs BB-full: - BB-lite (default): Shared gamma params, channel-level constraint from combined uncertainties - BB-full: Per-sample gamma params, per-sample Gaussian constraints (original behavior) Tests validate: - Combined uncertainties: sigma = sqrt(sum(errors^2)) - Poisson constraint: Poisson(tau | gamma * tau) where tau = (nu/sigma)^2 - Gaussian constraint: N(1.0 | gamma, relerr) where relerr = sigma/nu - Shared gamma parameters correctly modify all sample rates - Backward compatibility with BB-full mode Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #191 +/- ##
===========================================
- Coverage 100.00% 98.18% -1.82%
===========================================
Files 37 37
Lines 2257 2311 +54
Branches 234 249 +15
===========================================
+ Hits 2257 2269 +12
- Misses 0 37 +37
- Partials 0 5 +5 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Parameters are also optional for the StatErrorModifier() of a Poisson constraint
parameters: list[str] -> parameters: list[str] | None = None
There was a problem hiding this comment.
hep-statistics-serialization-standard/hep-statistics-serialization-standard#68
I don’t think anything related to parameter naming should be optional. Makes it harder because then you can’t handle correlations
There was a problem hiding this comment.
I found some already published HS3 JSON files on HEPData, where the Poisson staterror modifier boils down to:
{
"constraint": "Poisson",
"name": "staterror",
"type": "staterror"
}These workspaces raise errors during input validation if parameters are required.
There was a problem hiding this comment.
Yes, but they need to create a parameter of some name, and the name isn't dictated by the HS3 spec, and if it's left up to implementation, you're stuck trying to ascertain how to name the parameter associated with the staterror. It should be explicit.
Implements BB-lite for the staterror modifier in pyhs3's HistFactory
distribution. BB-lite uses shared gamma parameters across samples with
a channel-level constraint built from combined MC statistical uncertainties.
Key changes:
BB-lite vs BB-full:
Tests validate: