This problem is based on the example of an unbinned maximum likelihood fit from the lecture. Here we consider the case that we have an external Gaussian constraint on the parameter $a$. The likelihood function can then be written as
$$ L(a,b) = \frac{1}{\sqrt{2 \pi} \sigma_{a}} \exp \left( -\frac{(a - a_\mathrm{meas})^2}{2 \sigma_a^2} \right) \prod_{i} f(x_i; a, b)$$The external information on parameter $a$ is $a_\mathrm{meas} = 0.5 \pm 0.01$. Perform a unbinned maximum likelihood fit for this likelihood function.
import numpy as np
import matplotlib.pyplot as plt
from iminuit import Minuit
x = np.loadtxt("../data/data_ml_fit.txt")
def f(x, a, b):
"""normalized fit function"""
xmin = -0.95
xmax = 0.95
return (6 * (1 + a * x + b * x * x)) / ((xmax - xmin) * (3 * a * (xmax + xmin) +
2 * (3 + b * (xmax * xmax + xmax * xmin + xmin * xmin))))
# negative_log_likelihood
def nll(a, b):
p = np.log(f(x, a, b))
return -np.sum(p)
a) Define the negative_log_likelihood with Gaussian constraint on parameter a
# negative_log_likelihood with Gaussian constraint on parameter a
a_meas = 0.5
sigma_a_meas = 0.01
# your code here
# def nll_constr(a, b):
# ...
b) Perform the constrained and unconstrained ML fit and compare the fit results and their uncertainties
# your code here
# ...
# m = Minuit(nll, ...)
# m_constr = Minuit(nll_constr, ...)
c) Plot the two fit result along with the data
plt.hist(x, bins=20, density=True, ec="black", histtype='step');
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
plt.xlabel("x", fontsize=18)
plt.ylabel("f(x; a, b)", fontsize=18);
# add fits
# your code here
d) Draw the likelihood contour for a and b for the two fits
# your code here