From ae999030c1001305fb80eda32239ee79ad2815ad Mon Sep 17 00:00:00 2001 From: Mikael Mieskolainen Date: Thu, 7 Nov 2024 17:04:11 +0000 Subject: [PATCH] peakfit: improve numerical convolution treatment --- configs/peakfit/tune0.yml | 14 +++++++------- configs/peakfit/tune2.yml | 8 ++++---- icefit/icepeak.py | 12 +++++++----- icefit/peakfit.py | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/configs/peakfit/tune0.yml b/configs/peakfit/tune0.yml index 61a5b821..fc4b4b79 100644 --- a/configs/peakfit/tune0.yml +++ b/configs/peakfit/tune0.yml @@ -12,12 +12,12 @@ input_path: './actions-stash/input/icefit/dqcd_2018_test/flat/muon/generalTracks/JPsi' output_name: 'tune0' -years: [2018] #[2016, 2017, 2018] -fitrange: [2.91, 3.29] # Nominal fit window (GeV) +years: [2018] # [2016, 2017, 2018] +fitrange: [2.91, 3.29] # Nominal fit window (GeV) systematics: ['Nominal'] # ['Nominal', 'nVertices_Up', 'nVertices_Down'] # List of systematic variations active -variations: ['DEFAULT'] #, 'SYMMETRIC-SIGNAL_CB_asym_RBW', 'MASS-WINDOW-DOWN', 'MASS-WINDOW-UP'] +variations: ['DEFAULT'] #, 'SYMMETRIC-SIGNAL_CB_asym_RBW', 'MASS-WINDOW-DOWN', 'MASS-WINDOW-UP'] num_cpus: 0 # put 0 for automatic, set manually to 1 if problems (ray not used with 1) @@ -30,9 +30,9 @@ fit: func: 'generic_conv_pdf' args: norm: True - Nmin: 256 # minimum number of function samples for convolution integral - xfactor: 0.2 # extra domain extension factor for convolution integral (0.2 gives 20%) - + Nmin: 128 # minimum number of function samples for convolution integral + xfactor: 0.3 # extra domain extension factor for convolution integral (0.2 gives +-20%) + pdf_pair: ['CB_pdf', 'asym_RBW_pdf'] # name of pdfs to be convoluted par_index: [[0,1,2,3], [0,4,5]] # parameter indices per pdf (use same index for shared parameters) @@ -130,5 +130,5 @@ techno: tol: 0.1 # Default 0.1, https://iminuit.readthedocs.io/en/stable/reference.html#iminuit.Minuit.tol cov_eps: 0.0 # Covariance matrix post-regularization (added to diagonal) (set to 0 for none, can bias!) - + draw_mnmatrix: False # Draw MINOS profile likelihood scan 2D contours (very slow) diff --git a/configs/peakfit/tune2.yml b/configs/peakfit/tune2.yml index 4e6c8e34..e2facc09 100644 --- a/configs/peakfit/tune2.yml +++ b/configs/peakfit/tune2.yml @@ -12,12 +12,12 @@ input_path: './actions-stash/input/icefit/dqcd_2018_test/flat/muon/generalTracks/JPsi' output_name: 'tune2' -years: [2018] #[2016, 2017, 2018] -fitrange: [2.91, 3.29] # Nominal fit window (GeV) +years: [2018] # [2016, 2017, 2018] +fitrange: [2.91, 3.29] # Nominal fit window (GeV) systematics: ['Nominal'] # ['Nominal', 'nVertices_Up', 'nVertices_Down'] # List of systematic variations active -variations: ['DEFAULT'] #, 'MASS-WINDOW-DOWN', 'MASS-WINDOW-UP'] +variations: ['DEFAULT'] #, 'MASS-WINDOW-DOWN', 'MASS-WINDOW-UP'] num_cpus: 0 # put 0 for automatic, set manually to 1 if problems (ray not used with 1) @@ -121,5 +121,5 @@ techno: tol: 0.1 # Default 0.1, https://iminuit.readthedocs.io/en/stable/reference.html#iminuit.Minuit.tol cov_eps: 0.0 # Covariance matrix post-regularization (added to diagonal) (set to 0 for none, can bias!) - + draw_mnmatrix: False # Draw MINOS profile likelihood scan 2D contours (very slow) diff --git a/icefit/icepeak.py b/icefit/icepeak.py index 52c689fb..d952aa24 100644 --- a/icefit/icepeak.py +++ b/icefit/icepeak.py @@ -287,7 +287,9 @@ def generic_conv_pdf(x: np.ndarray, par: np.ndarray, pdf_pair: List[str], xp = highres_x(x=x, xfactor=xfactor, Nmin=Nmin) f0 = func0(x=xp, par=f0_param, norm=False) f1 = func1(x=xp, par=f1_param, norm=False) - yp = np.convolve(a=f0, v=f1, mode='same') + + dx = xp[1] - xp[0] + yp = np.convolve(a=f0, v=f1, mode='same') * dx y = interpolate.interp1d(xp, yp)(x) if norm: @@ -296,14 +298,14 @@ def generic_conv_pdf(x: np.ndarray, par: np.ndarray, pdf_pair: List[str], return y @numba.njit -def highres_x(x: np.ndarray, xfactor: float=0.2, Nmin: int=256): +def highres_x(x: np.ndarray, xfactor: float=0.5, Nmin: int=256): """ Extend range and sampling of x. Args: - x: Array of values. - xfactor: Domain extension factor (default is 0.2). - Nmin: Minimum number of samples (default is 256). + x: Array of values + xfactor: Domain extension factor (e.g. 0.2 gives +- 20%) + Nmin: Minimum number of samples Returns: np.ndarray: Extended high-resolution array. diff --git a/icefit/peakfit.py b/icefit/peakfit.py index 57318fb3..7eb34c0f 100644 --- a/icefit/peakfit.py +++ b/icefit/peakfit.py @@ -38,7 +38,7 @@ import ray -__VERSION__ = 0.06 +__VERSION__ = 0.07 __AUTHOR__ = 'm.mieskolainen@imperial.ac.uk'