multifit: simultaneous fitting to multiple data sets.

Copyright (C) 2026 Johannes Sørby Heines

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

class multifit.model.Model(cdf, *, spectrum_params, peak_params, number_of_peaks)

Bases: object

Manage independent and shared parameters.

cdf

Model describing a peak structure

Type:

callable

number_of_peaks

Number pf peak structures to model

Type:

int

independent_params

parameters which are not shared

Type:

set

unique_params

parameters which are shared accross all peaks and spectra.

Type:

set

spectrum_params

parameters which are shared between peaks within, but not accross, spectra.

Type:

set

peak_params

parameters which are shared accross spectra, but are different for each peak number.

Type:

set

from_config(ModelConfig: config) → Self

Build a class instance from a ModelConfig instance.

make_cdf(peak_number, spectrum_number) → callable

Define the cdf with the signature needed by iminuit.

sum_cdfs(spectrum_number) → callable

Combine all cdfs in a spectrum to one function.

match_param(string, peak_numbers, spectrum_numbers) → list[str]

List parameters matching the arguments.

expand_and_list(string) → list:

Expand a parameter name as a list [name, peak, spectrum].

classmethod from_config(config: ModelConfig) → Self

Build a class instance from a ModelConfig instance.

make_cdf(*, peak_number: int, spectrum_number: int) → callable

Return the cdf with the proper signature.

Define a function to be used by iminuit.cost.ExtendedBinnedNLL, with a signature ensuring the correct sharing of parameters.

Parameters:
  • peak_number (int) – number identifying a specific peak. Peaks with the same peak_number will share peak_params.

  • spectrum_number (int) – number identifying a specific spectrum. Peaks with the same spectrum number will share spectrum_params.

Returns:

Cumulative distribution function with parameter names specifying peak and spectrum numbers.

Return type:

callable

sum_cdfs(spectrum_number) → callable

Sum the cdfs for all peaks in a spectrum to a single cdf.

match_param(string, peak_numbers, spectrum_numbers) → list[str]

List parameters matching string given peak and spectrum numbers.

Parameters:
  • string – On the form <name> or <name>_<peak>_<spectrum>, where <peak> and <spectrum> can be numbers or wildcard ‘*’. The input <name> is equivalent to <name>_*_*.

  • peak_numbers – numbers of the peaks against which string is matched.

  • spectrum_numbers – numbers of the spectra against which string is matched.

Returns:

A list of valid parameter names to the function returned by make_cdf for each combination of peak and spectrum number.

Return type:

list[str]

expand_and_list(string) → list

Expand a parameter name as a list [name, peak, spectrum].

Parameters:

string (str) – On the form <name> or <name>_<peak>_<spectrum>, where <peak> and <spectrum> can be numbers or wildcard ‘*’. The input <name> is equivalent to <name>_*_*

Returns:

A list corresponding to the input string, as [

name: str, peak: int | slice(None), spectrum: int | slice(None) ]

Return type:

list