Skip to content

Commit

Permalink
Merge pull request #164 from dlanci/main
Browse files Browse the repository at this point in the history
Update sweights.py
  • Loading branch information
jonas-eschle authored Oct 17, 2024
2 parents dc97d67 + a935ce0 commit 53d23b5
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit 53d23b5

Please sign in to comment.