Skip to content

feat: Implement Barlow-Beeston lite for staterror modifier#191

Draft
kratsg wants to merge 1 commit into
mainfrom
feat/bblite
Draft

feat: Implement Barlow-Beeston lite for staterror modifier#191
kratsg wants to merge 1 commit into
mainfrom
feat/bblite

Conversation

@kratsg
Copy link
Copy Markdown
Contributor

@kratsg kratsg commented Mar 14, 2026

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

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
Copy link
Copy Markdown

codecov Bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 26.31579% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.18%. Comparing base (66bb6f6) to head (7136718).
⚠️ Report is 5 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/pyhs3/distributions/histfactory/__init__.py 25.00% 35 Missing and 4 partials ⚠️
src/pyhs3/distributions/histfactory/modifiers.py 40.00% 2 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters are also optional for the StatErrorModifier() of a Poisson constraint
parameters: list[str] -> parameters: list[str] | None = None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants