def plot_landau(source_scan_filename, tdc_hists, target_threshold, fit_range=(13000, 30000)): with tb.open_file(tdc_hists, 'r') as in_file_h5: x, count, count_error = in_file_h5.root.HistTdcCalibratedCondition_2[:]['charge'], in_file_h5.root.HistTdcCalibratedCondition_2[:]['count'], in_file_h5.root.HistTdcCalibratedCondition_2[:]['count_error'] charge = plsr_dac_to_charge(source_scan_filename, x) target_threshold_charge = plsr_dac_to_charge(source_scan_filename, target_threshold) plt.clf() plt.grid() x_fit_range = np.logical_and(charge > fit_range[0], charge < fit_range[1]) coeff, err = fit_landau_bootstrap(charge[x_fit_range], count[x_fit_range], p0 = (7000, np.std(charge[x_fit_range]), 150, np.amax(count[x_fit_range])), yerr=count_error[x_fit_range], n_iterations=100) plt.bar(charge, count, width=charge[1] - charge[0], color='blue', label='data') plt.plot(charge[x_fit_range], landau.langau(charge[x_fit_range], *coeff), 'r-') plt.plot([target_threshold_charge, target_threshold_charge], [plt.ylim()[0], plt.ylim()[1]], 'b--', linewidth=2, label='Threshold $%d$ e' % target_threshold_charge) plt.plot([coeff[0], coeff[0]], [plt.ylim()[0], plt.ylim()[1]], 'r--', linewidth=2, label='MPV $%d\pm%d$ e' % (coeff[0], err[0])) plt.title('Landau, -30 C') plt.legend(loc=0) plt.show()
def plot_landau(source_scan_filename, tdc_hists, target_threshold, fit_range=(13000, 30000)): with tb.open_file(tdc_hists, 'r') as in_file_h5: x, count, count_error = in_file_h5.root.HistTdcCalibratedCondition_2[:][ 'charge'], in_file_h5.root.HistTdcCalibratedCondition_2[:][ 'count'], in_file_h5.root.HistTdcCalibratedCondition_2[:][ 'count_error'] charge = plsr_dac_to_charge(source_scan_filename, x) target_threshold_charge = plsr_dac_to_charge(source_scan_filename, target_threshold) plt.clf() plt.grid() x_fit_range = np.logical_and(charge > fit_range[0], charge < fit_range[1]) coeff, err = fit_landau_bootstrap(charge[x_fit_range], count[x_fit_range], p0=(7000, np.std(charge[x_fit_range]), 150, np.amax(count[x_fit_range])), yerr=count_error[x_fit_range], n_iterations=100) plt.bar(charge, count, width=charge[1] - charge[0], color='blue', label='data') plt.plot(charge[x_fit_range], landau.langau(charge[x_fit_range], *coeff), 'r-') plt.plot([target_threshold_charge, target_threshold_charge], [plt.ylim()[0], plt.ylim()[1]], 'b--', linewidth=2, label='Threshold $%d$ e' % target_threshold_charge) plt.plot([coeff[0], coeff[0]], [plt.ylim()[0], plt.ylim()[1]], 'r--', linewidth=2, label='MPV $%d\pm%d$ e' % (coeff[0], err[0])) plt.title('Landau, -30 C') plt.legend(loc=0) plt.show()
def errfunc(p, x, y): # langau errorfunktion to minimize in fit return landau.langau(x, *p) - y