probfit

probfit is a set of functions that helps you construct a complex fit. It is intended to be used with iminuit. The tool includes Binned/Unbinned Likelihood estimator, \(\chi^2\) regression, binned \(\chi^2\) estimator and Simultaneous fit estimator. Normalization and convolution with cache are also included. Various builtin functions used in B physics are also provided.

In a nutshell:

import numpy as np
from iminuit import Minuit
from probfit import UnbinnedLH, gaussian
data = np.random.randn(10000)
unbinned_likelihood = UnbinnedLH(gaussian, data)
minuit = Minuit(unbinned_likelihood, mean=0.1, sigma=1.1)
minuit.migrad()
unbinned_likelihood.draw(minuit)

Probfit was created by Piti Ongmongkolkul (piti118@gmail.com). It is currently maintained by the Scikit-HEP community.

Download & Install

From pip:

pip install probfit

or get the latest development from github:

pip install git+https://github.com/scikit-hep/probfit.git

Tutorial

The tutorial consists of an IPython notebook in the tutorial directory. You can view it online too.

Commonly used API

Refer to Full API Documentation for complete reference.

Cost Functions

Refer to Cost Function.

UnbinnedLH(f, data[, weights, extended, …])

Construct -log(unbinned likelihood) from callable f and data points data.

BinnedLH(f, data[, bins, weights, …])

Create a Poisson Binned Likelihood object from given PDF f and data (raw points not histogram).

Chi2Regression(f, x, y[, error, weights])

Create \(\chi^2\) regression object.

BinnedChi2(f, data[, bins, weights, bound, …])

Create Binned Chi2 Object.

SimultaneousFit([factors, prefix, skip_prefix])

Construct simultaneous fit from given cost functions.

Functors

Refer to Functor

Normalized(f, bound[, nint, warnfloat])

Transformed PDF in to a normalized version.

Extended(f[, extname])

Transformed given f into extended from.

Convolve(f, g, gbound[, nbins])

Make convolution from supplied f and g.

AddPdf([prefix, factors, skip_prefix])

Directly add PDF without normalization nor factor.

AddPdfNorm([facname, prefix, skip_prefix])

Add PDF with normalization factor.

rename(f, newarg)

Rename function parameters.

And corresponding decorator

normalized(bound[, nint])

Normalized decorator

extended([extname])

Extended decorator

Builtin Functions

Refer to Builtin PDF. This list can grow: implement your favorite function and send us pull request.

gaussian(double x, double mean, double sigma)

Normalized gaussian.

crystalball(double x, double alpha, …)

Unnormalized crystal ball function.

doublecrystalball(double x, double alpha, …)

Unnormalized double crystal ball function A gaussian core with two power tails

cruijff(double x, double m_0, …)

Unnormalized cruijff function

cauchy(double x, double m, double gamma)

Cauchy distribution aka non-relativistic Breit-Wigner

rtv_breitwigner(double x, double m, double gamma)

Normalized Relativistic Breit-Wigner

doublegaussian(double x, double mean, …)

Unnormalized double gaussian

johnsonSU

_JohnsonSU(xname=’x’)

argus(double x, double c, double chi, double p)

Unnormalized argus distribution

linear

_Linear()

poly2(double x, double a, double b, double c)

Parabola

poly3(double x, double a, double b, …)

Polynomial of third order

novosibirsk(double x, double width, …)

Unnormalized Novosibirsk

HistogramPdf(hy, binedges[, xname])

A histogram PDF.

Polynomial(order[, xname])

Polynomial.

Useful utility

You may find these functions useful in interactive environment.

vector_apply(f, x, *arg)

Apply f to array x with given arguments fast.

draw_pdf(f, arg, bound[, bins, scale, …])

draw pdf with given argument and bounds.

draw_compare_hist(f, arg, data[, bins, …])

draw histogram of data with poisson error bar and f(x,*arg).

Cookbook

Cookbook recipies are at Cookbook.

Development

If you’d like to develop with the probfit source code, see the Development section.