def pedestal(x, mu_p, sigma_p, p, A, mu, sigma): """ The pedestal part of a SPE charge spectrum """ return fit.gauss(x, mu_p, sigma_p, 1)
def pedestal_fit(filename, nbins, fig=None): """ Fit a pedestal to measured waveform data One shot function for * integrating the charges * making a histogram * fitting a simple gaussian to the pedestal * calculating mu P(hit) = (N_hit/N_all) = exp(QExCExLY) where P is the probability for a hit, QE is quantum efficiency, CE is the collection efficiency and LY the (unknown) light yield Args: filename (str): Name of the file with waveform data nbins (int): number of bins for the underlaying charge histogram """ head, wf = tools.load_waveform(filename) charges = -1e12 * tools.integrate_wf(head, wf) plt.plot_waveform(head, tools.average_wf(wf)) p.savefig(filename.replace(".npy", ".wf.pdf")) one_gauss = lambda x, n, y, z: n * gauss(x, y, z, 1) ped_mod = Model(one_gauss, (1000, -.1, 1)) ped_mod.add_data(charges, nbins, create_distribution=True, normalize=False) ped_mod.fit_to_data(silent=True) fig = ped_mod.plot_result(add_parameter_text=((r"$\mu_{{ped}}$& {:4.2e}\\", 1), \ (r"$\sigma_{{ped}}$& {:4.2e}\\", 2)), \ xlabel=r"$Q$ [pC]", ymin=1, xmax=8, model_alpha=.2, fig=fig, ylabel="events") ax = fig.gca() n_hit = abs(ped_mod._distribution.bincontent - ped_mod.prediction(ped_mod.xs)).sum() ax.grid(1) bins = np.linspace(min(charges), max(charges), nbins) data = d.factory.hist1d(charges, bins) n_pedestal = ped_mod._distribution.stats.nentries - n_hit mu = -1 * np.log(n_pedestal / ped_mod._distribution.stats.nentries) print("==============") print("All waveforms: {:4.2f}".format(ped_mod._distribution.stats.nentries)) print("HIt waveforms: {:4.2f}".format(n_hit)) print("NoHit waveforms: {:4.2f}".format(n_pedestal)) print("mu = -ln(N_PED/N_TRIG) = {:4.2e}".format(mu)) ax.fill_between(ped_mod.xs, 1e-4, ped_mod.prediction(ped_mod.xs),\ facecolor=PALETTE[2], alpha=.2) p.savefig(filename.replace(".npy", ".pdf")) return ped_mod
def single_PE_response(x, mu_p, sigma_p, p, A, mu, sigma): """ The SPE charge response """ # I am not sure here, according to the paper it would be sqrt(sigma) # however, how this is defined it makes no sense here # What about erf then? Is it wrong? spe_0 = fit.gauss((x - (mu_p * np.ones(len(x)))), mu, sigma, 1) #spe_0 = (1/np.sqrt(2*sigma*np.pi)) spe_0 *= (1 - p) / (0.5 * (1 + erf(mu / (np.sqrt(2) * sigma)))) # only use in the case of no folding #result[x <= mu_p] = 0 return spe_0
def get_n_hit(charges, nbins=200): """ Identify how many events are in the pedestal of a charge response spectrum. Args: charges (np.ndarray): The measured charges nbins (int): number of bins to use Returns: tuple (n_hit, n_all) """ one_gauss = lambda x, n, y, z: n * gauss(x, y, z, 1) ped_mod = Model(one_gauss, (1000, -.1, 1)) ped_mod.add_data(charges, nbins=nbins, normalize=False, create_distribution=True) ped_mod.fit_to_data(silent=True) n_hit = abs(ped_mod.data - ped_mod.prediction(ped_mod.xs)).sum() n_pedestal = ped_mod._distribution.stats.nentries - n_hit n_all = ped_mod._distribution.stats.nentries return n_hit, n_all
def m_i(x, mu_p, sigma_p, p, A, mu, sigma): # no fit here mu_m = ((1 - p) * mu) + (p * A) sigma_m = ((1 - p) * (sigma**2 + mu**2)) + (2 * p * (A**2)) - (mu_m**2) response = fit.gauss(x - mu_p, mu_m, sigma_m, n) return response