slophep.Fitting.CostFuncMath

slophep.Fitting.CostFuncMath.cash_statistic(k: ndarray, lam: ndarray) ndarray[source]

Cash statistic, as defined in in 10.1140/epjc/s10052-022-11019-z

Parameters:
  • k (np.ndarray) – Argument.

  • lam (np.ndarray) – Argument.

Returns:

c – Bin-wise cash statistic

Return type:

np.ndarray

slophep.Fitting.CostFuncMath.chi2_template_DA(n: ndarray, nvar: ndarray, mu: ndarray, muvar: ndarray) float[source]

Implements the figure of merit as per Eq. (24) in 10.1140/epjc/s10052-022-11019-z

NOTE: As is stated in the paper, this method is particularly sensitive to bins with few simulation entries. In the cases where this is an issue (e.g. with several q2 bins), this FoM is not good.

Parameters:
  • n (np.ndarray) – Observed counts - sum of weights

  • nvar (np.ndarray) – Variance of observed counts (NOT error) - sum of weights square

  • mu (np.ndarray) – Expected counts

  • muvar (np.ndarray) – Variance of expected counts (NOT error)

Returns:

q – The figure of merit - should be chi2-like

Return type:

float

slophep.Fitting.CostFuncMath.log_or_zero(x: ndarray) ndarray[source]

Evaluate to log(x) for x > 0 and to 0 otherwise.

Parameters:

x (np.ndarray) – Argument.

Returns:

logx – Elementwise contains log(x) for x > 0 and zero otherwise.

Return type:

np.ndarray

slophep.Fitting.CostFuncMath.nll_gaussian(x: float, mu: float, sigma: float) float[source]

Returns -2ln(Gaussian). Meant for gaussian constraints in likelihoods.

NOTE: The constant terms -0.5*ln(2pi) and -ln(sigma) are neglected

Parameters:
  • x (float) – Point to evaluate at

  • mu (float) – Guassian mean

  • sigma (float) – Standard deviation

Returns:

-2ln(Gaussian(x ; mu, sigma))

Return type:

float

slophep.Fitting.CostFuncMath.poisson_chi2(n: ndarray, mu: ndarray) float[source]

Compute asymptotically chi2-distributed cost for Poisson-distributed data.

See Baker & Cousins, NIM 221 (1984) 437-442.

Parameters:
  • n (np.ndarray) – Observed counts.

  • mu (np.ndarray) – Expected counts per bin.

Returns:

nll – Cost function value.

Return type:

float

slophep.Fitting.CostFuncMath.poisson_chi2_W2(n: ndarray, mu: ndarray, scalefactorW2: ndarray) float[source]

Likelihood using scaling (error * error) / yield, implemented as in RooFit (https://github.com/root-project/root/blob/master/math/mathcore/src/FitUtil.cxx#L1434) L1566-1586

This is to be used solely to compute the covariance matrix which should follow the SumW2Error approach (https://root.cern/doc/master/classRooAbsPdf.html#RooAbsPdf:fitTo)

Parameters:
  • n (np.ndarray) – Observed counts.

  • mu (np.ndarray) – Expected counts per bin.

  • scalefactorW2 (np.ndarray) – Bin-wise (error * error) / yield

Returns:

nllw2 – Cost function value

Return type:

float