hist([data1,data2], histtype='step', bins=100);

# <codecell>

#note here that they share the same sigma
g1 = rename(gaussian, ['x','mu1','sigma'])
g2 = rename(gaussian, ['x','mu2','sigma'])
print describe(g1)
print describe(g2)

# <codecell>

#make two likelihood and them up
ulh1 = UnbinnedLH(g1,data1)
ulh2 = UnbinnedLH(g2,data2)
sim = SimultaneousFit(ulh1,ulh2)
print describe(sim) #note the sigma merge

# <codecell>

sim.draw(args=(0.5, 1.5, 10.5))

# <codecell>

m = Minuit(sim, mu1=0.5, sigma=1.5, mu2=10.5)

# <codecell>

m.migrad();

# <codecell>
hist([data1,data2], histtype='step', bins=100);

# <codecell>

#note here that they share the same sigma
g1 = rename(gaussian, ['x','mu1','sigma'])
g2 = rename(gaussian, ['x','mu2','sigma'])
print describe(g1)
print describe(g2)

# <codecell>

#make two likelihood and them up
ulh1 = UnbinnedLH(g1,data1)
ulh2 = UnbinnedLH(g2,data2)
sim = SimultaneousFit(ulh1,ulh2)
print describe(sim) #note the sigma merge

# <codecell>

sim.draw(args=(0.5, 1.5, 10.5))

# <codecell>

m = Minuit(sim, mu1=0.5, sigma=1.5, mu2=10.5)

# <codecell>

m.migrad();

# <codecell>
    ext_bkg_pdf = Extended(nrm_bkg_pdf, extname='Ncomb_%d' % bin)

    ext_sig_pdf = Extended(rename(gaussian, ['x', 'm%d' % bin, "sigma%d" % bin]), extname='Nsig_%d' % bin)
    tot_pdf = AddPdf(ext_bkg_pdf, ext_sig_pdf)
    print('pdf: {}'.format(describe(tot_pdf)))

    return tot_pdf


fit_range = (2900, 3300)

mod_1 = model(fit_range, 1)
lik_1 = UnbinnedLH(mod_1, tot_m, extended=True)
mod_2 = model(fit_range, 2)
lik_2 = UnbinnedLH(mod_2, tot_u, extended=True)
sim_lik = SimultaneousFit(lik_1, lik_2)
describe(sim_lik)

pars = dict(l1=0.002, Ncomb_1=1000, m1=3100, sigma1=10, Nsig_1=1000, l2=0.002, Ncomb_2=1000, m2=3100, sigma2=10,
            Nsig_2=1000)
minuit = Minuit(sim_lik, pedantic=False, print_level=0, **pars)

# In[8]:


if do_probfit:
    start = time.time()
    minuit.migrad()
    time_probfit = time.time() - start

print("starting zfit")
Example #4
0
File: simul.py Project: bks/probfit
from matplotlib import pyplot as plt
from numpy.random import randn, seed

seed(0)
width = 2.
data1 = randn(1000)*width + 1
data2 = randn(1000)*width + 2

#two gaussian with shared width
pdf1 = rename(gaussian, ('x', 'mu_1', 'sigma'))
pdf2 = rename(gaussian, ('x', 'mu_2', 'sigma'))

lh1 = UnbinnedLH(pdf1, data1)
lh2 = UnbinnedLH(pdf2, data2)

simlh = SimultaneousFit(lh1, lh2)

m = Minuit(simlh, mu_1=1.2, mu_2=2.2, sigma=1.5)

plt.figure(figsize=(8, 3))
plt.subplot(211)
simlh.draw(m)
plt.suptitle('Before')

m.migrad() # fit

plt.figure(figsize=(8, 3))
plt.subplot(212)
simlh.draw(m)
plt.suptitle('After')
Example #5
0
from matplotlib import pyplot as plt
from numpy.random import randn, seed

seed(0)
width = 2.
data1 = randn(1000) * width + 1
data2 = randn(1000) * width + 2

#two gaussian with shared width
pdf1 = rename(gaussian, ('x', 'mu_1', 'sigma'))
pdf2 = rename(gaussian, ('x', 'mu_2', 'sigma'))

lh1 = UnbinnedLH(pdf1, data1)
lh2 = UnbinnedLH(pdf2, data2)

simlh = SimultaneousFit(lh1, lh2)

m = Minuit(simlh, mu_1=1.2, mu_2=2.2, sigma=1.5)

plt.figure(figsize=(8, 3))
plt.subplot(211)
simlh.draw(m)
plt.suptitle('Before')

m.migrad()  # fit

plt.figure(figsize=(8, 3))
plt.subplot(212)
simlh.draw(m)
plt.suptitle('After')