RooFit#

ROOT provides with the RooFit library a toolkit for modeling the expected distribution of events in a physics analysis. It can be connected with zfit, currently by providing a loss function that can be minimized by a zfit minimizer.

This requires the ROOT framework to be installed and available in the python environment. For example via conda:

$ mamba install -c conda-forge root

Import the module with:

import zfit_physics.roofit as zroofit

this will enable the RooFit functionality in zfit and allow to automatically minimize the function using a zfit minimimzer as

RooFit_nll = RooFit_gauss.createNLL(RooFit_data)
[#1] INFO:Fitting -- RooAbsPdf::fitTo(gauss_over_gauss_Int[x]) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2

We can create a RooFit NLL as RooFit_nll and use it as a loss function in zfit. For example, with a Gaussian model RooFit_gauss and a dataset RooFit_data, both created with RooFit:

result = minimizer.minimize(loss=RooFit_nll)
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_gauss_over_gauss_Int[x]_data) Summation contains a RooNLLVar, using its error level

More explicitly, the loss function can be created with

nll = zroofit.loss.nll_from_roofit(RooFit_nll)
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_gauss_over_gauss_Int[x]_data) Summation contains a RooNLLVar, using its error level

Variables#

zfit_physics.roofit.variables.roo2z_param(v)[source]#

Converts a RooFit RooRealVar to a zfit parameter.

Parameters:

v (RooRealVar) – RooFit RooRealVar to convert.

Return type:

Parameter

Returns:

A zfit.Parameter object with properties copied from the RooFit variable.

Loss#

zfit_physics.roofit.loss.nll_from_roofit(nll, params=None)[source]#

Converts a RooFit NLL (negative log-likelihood) to a Zfit loss object.

Parameters:
  • nll (RooAbsReal) – The RooFit NLL object to be converted.

  • params (ZfitParameter | Iterable[ZfitParameter]) – The zfit.Parameter to be used in the loss. If None, all parameters in the NLL will be used

Returns:

The converted Zfit loss object.

Return type:

zfit.loss.SimpleLoss

Raises:

TypeError – If the provided RooFit loss does not have an error level.