Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sweights.py #164

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/hepstats/splot/sweights.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def is_sum_of_extended_pdfs(model) -> bool:
return all(m.is_extended for m in model.get_models()) and model.is_extended


def compute_sweights(model, x: np.ndarray) -> dict[Any, np.ndarray]:
def compute_sweights(model, x: np.ndarray, *, atol_exceptions: float | None = None) -> dict[Any, np.ndarray]:
"""Computes sWeights from probability density functions for different components/species in a fit model
(for instance signal and background) fitted on some data `x`.

Expand All @@ -35,6 +35,9 @@ def compute_sweights(model, x: np.ndarray) -> dict[Any, np.ndarray]:
Args:
model: sum of extended pdfs.
x: data on which `model` is fitted
atol_exceptions: absolute tolerance to check if the Maximum Likelihood Sum Rule sanity check,
described in equation 17 of arXiv:physics/0402083, failed. Sum of yields should be 1 with
an absolute tolerance of `atol_exceptions`.

Returns:
dictionary with yield parameters as keys, and sWeights for correspoind species as values.
Expand Down Expand Up @@ -108,7 +111,8 @@ def compute_sweights(model, x: np.ndarray) -> dict[Any, np.ndarray]:

MLSR = pN.sum(axis=0)
atol_warning = 5e-3
atol_exceptions = 5e-2
if atol_exceptions is None:
atol_exceptions = 5e-2

def msg_fn(tolerance):
msg = (
Expand Down
Loading