# Determine number of bins
 n_hits_bins_plot = max(run_uncut) - min(run_uncut) + 1
 n_hits_bins_fit = max(run) - min(run) + 1
 # Make histogram
 hist(run_uncut, bins=n_hits_bins_plot, histtype='step')
 norm_const = len(run) # Normalization constant
 # Get PDF
 pdf_nh = Normalized(gaussian, (min(run), max(run)))
 pdf_nh = Extended(pdf_nh)
 # Do fit
 blh_nh = BinnedLH(pdf_nh, run_np, bound=(low_fit_bounds[i], high_fit_bounds[i]), bins=(high_fit_bounds[i] - low_fit_bounds[i] + 1), extended=True)
 m_nh = Minuit(blh_nh, mean=150., sigma= 12., N=400, error_mean=10., error_sigma=1.,limit_sigma=(0.,10000.), error_N=10., limit_mean=(0,800))
 m_nh.set_up(0.5)
 m_nh.migrad()
 nh_means.append(m_nh.values["mean"])
 blh_nh.show(m_nh);
 # Output plot
 title("Number of photons incident on APD, 511 keV gamma " + str(dist[i]) + "cm away from APD")
 xlabel("Number of photons")
 ylabel("Number of events")
 savefig("n_hits" + str(i) + ".pdf")
 figure()
 # Energy. Same procedure as for the number of hits.
 run = energy_all[i]
 run_uncut = energy_all_uncut[i]
 run_np = np.zeros(len(run))
 for j in range(len(run)):
     run_np[j] = run[j]
 energy_bins_plot = 15/(en_high_fit_bounds[i] - en_low_fit_bounds[i]) * (max(run) - min(run))
 hist(run_uncut, bins=energy_bins_plot, histtype='step')
 norm_const = len(run)
# <codecell>

from probfit import Extended, BinnedLH
seed(0)
gdata = randn(10000)

# <codecell>

mypdf = gaussian
describe(mypdf) # just basically N*gaussian(x,mean,sigma)

# <codecell>

blh = BinnedLH(mypdf, gdata, bound=(-3,3))#create cost function
#it can also do extended one if you pass it an extended pdf and pass extended=True to BinnedLH
blh.show(args={'mean':1.0, 'sigma':1.0})

# <codecell>

m = Minuit(blh, mean=1.0, sigma=1)
m.set_up(0.5)
m.migrad()
blh.show(m)

# <markdowncell>

# ####$\chi^2$ Regression
# Some time you just want a simple line fit as opposed to fitting pdf.

# <codecell>
                   bound=(low_fit_bounds[i], high_fit_bounds[i]),
                   bins=(high_fit_bounds[i] - low_fit_bounds[i] + 1),
                   extended=True)
 m_nh = Minuit(blh_nh,
               mean=150.,
               sigma=12.,
               N=400,
               error_mean=10.,
               error_sigma=1.,
               limit_sigma=(0., 10000.),
               error_N=10.,
               limit_mean=(0, 800))
 m_nh.set_up(0.5)
 m_nh.migrad()
 nh_means.append(m_nh.values["mean"])
 blh_nh.show(m_nh)
 # Output plot
 title("Number of photons incident on APD, 511 keV gamma " + str(dist[i]) +
       "cm away from APD")
 xlabel("Number of photons")
 ylabel("Number of events")
 savefig("n_hits" + str(i) + ".pdf")
 figure()
 # Energy. Same procedure as for the number of hits.
 run = energy_all[i]
 run_uncut = energy_all_uncut[i]
 run_np = np.zeros(len(run))
 for j in range(len(run)):
     run_np[j] = run[j]
 energy_bins_plot = 15 / (en_high_fit_bounds[i] -
                          en_low_fit_bounds[i]) * (max(run) - min(run))
# <codecell>

from probfit import Extended, BinnedLH
seed(0)
gdata = randn(10000)

# <codecell>

mypdf = gaussian
describe(mypdf) # just basically N*gaussian(x,mean,sigma)

# <codecell>

blh = BinnedLH(mypdf, gdata, bound=(-3,3))#create cost function
#it can also do extended one if you pass it an extended pdf and pass extended=True to BinnedLH
blh.show(args={'mean':1.0, 'sigma':1.0})

# <codecell>

m = Minuit(blh, mean=1.0, sigma=1)
m.set_up(0.5)
m.migrad()
blh.show(m)

# <markdowncell>

# ####$\chi^2$ Regression
# Some time you just want a simple line fit as opposed to fitting pdf.

# <codecell>
Exemple #5
0
# <codecell>

hist(n_hits_proc_uncut, bins=n_hits_bins_uncut, histtype='step');
# Determine a first guess for the normalization constant
norm_const = len(n_hits_proc_np)
# Get the PDF
pdf_nh = Normalized(gaussian, (min(n_hits_proc_np), max(n_hits_proc_np)))
pdf_nh = Extended(pdf_nh)
# Do the fit
blh_nh = BinnedLH(pdf_nh, n_hits_proc_np, bins=n_hits_bins, extended=True)
m_nh = Minuit(blh_nh, mean=8000., sigma= 1000., N=norm_const, error_mean=100.,
    error_sigma=10.,limit_sigma=(0.,10000.), error_N=100., limit_mean=(0,100000))
m_nh.set_up(0.5)
m_nh.migrad()
blh_nh.show(m_nh);
# Generate and save figure for the number of photons
title("Number of photons detected by APD")
xlabel("Number of photons")
ylabel("Number of events")
savefig("n_ph.pdf")

# <codecell>

# Now repeat the procedure for the energy deposit
# Create a new figure
figure()
# Number of bins for the fit and plot, respectively. The number of bins for the
# fit are determined by scaling the number of bins for the fit by the ranges.
fit_n_bins_en = 30
total_n_bins_en = fit_n_bins_en / (max(energy_proc_np) - min(energy_proc_np)) * (max(energy_proc_uncut - min(energy_proc_uncut)