From fac39dce975fa66d36fde15fcba2f1f8618f1af7 Mon Sep 17 00:00:00 2001 From: Iason Krommydas Date: Tue, 19 Mar 2024 17:17:17 +0100 Subject: [PATCH] refactor Co-authored-by: Jonas Eschle --- zfit_physics/models/pdf_cruijff.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/zfit_physics/models/pdf_cruijff.py b/zfit_physics/models/pdf_cruijff.py index 8818239..43149c0 100644 --- a/zfit_physics/models/pdf_cruijff.py +++ b/zfit_physics/models/pdf_cruijff.py @@ -26,12 +26,17 @@ def cruijff_pdf_func(x, mu, sigmal, alphal, sigmar, alphar): """ cond = znp.less(x, mu) - func = znp.where( - cond, - znp.exp(-0.5 * znp.square((x - mu) / sigmal) / (1 + alphal * znp.square((x - mu) / sigmal))), - znp.exp(-0.5 * znp.square((x - mu) / sigmar) / (1 + alphar * znp.square((x - mu) / sigmar))), - ) - return func +# compute only once (in graph this _may_ be optimized anyways, but surely not in eager) +xminmu = (x - mu) +tleft = znp.square(xminmu / sigmal) +tright = znp.square(xminmu / sigmar) +exponent = znp.where( + cond, + tleft / (1 + alphal * tleft), + tright / (1 + alphar * tright), +) +value = znp.exp(-0.5 * exponent) + return value class Cruijff(zfit.pdf.BasePDF):