# Program to find measure of expected significance as a function # of a cut value x_cut applied to measured variable x # by Monte Carlo simulation of the likelihood ratio statistic. # G. Cowan / RHUL Physics / December 2022 # Full version containing exercise solutions import numpy as np import scipy.stats as stats import matplotlib import matplotlib.pyplot as plt plt.rcParams["font.size"] = 14 # Define pdfs and likelihood-ratio statisic s_tot = 10. b_tot = 100. ps = s_tot/(s_tot+b_tot) def f_s(x): return 3.*(1.-x)**2 def f_b(x): return 3.*x**2 def q(x): return -2.*np.log(1. + (s_tot/b_tot)*f_s(x)/f_b(x)) # Generate data under b and s+b hypotheses qb = [] qsb = [] numExp = 1000000 np.random.seed(seed=1234567) # fix random seed for i in range(numExp): n = np.random.poisson(b_tot) # first b only r = np.random.uniform(0., 1., n) xb = r**(1./3.) qb.append(np.sum(q(xb))) n = np.random.poisson(s_tot+b_tot) # then s+b r1 = np.random.uniform(0., 1., n) r2 = np.random.uniform(0., 1., n) xsb = [1. - r1[j]**(1./3.) if r2[j]