def localfit_goodchs(data, linename, goodchs, category=None): elo, ehi = mass.STANDARD_FEATURES[linename] - 50, mass.STANDARD_FEATURES[ linename] + 50 edges = np.arange(elo, ehi, 1) p_energy = [] for ds in data: if not ds.channum in goodchs: continue if category is not None: good = ds.cuts.good(**category) else: good = ds.good() p_energy.extend(ds.p_energy[good]) p_energy = np.asarray(p_energy, dtype=np.float32) counts, _ = np.histogram(p_energy, edges) fitter = mass.getfitter(linename) fitter.fit(counts, edges, plot=False) params = fitter.last_fit_params[:] params[fitter.param_meaning["tail_frac"]] = 0.25 params[fitter.param_meaning["dP_dE"]] = 1 params[fitter.param_meaning["resolution"]] = 6 fitter.fit(counts, edges, params=params, hold=[2], vary_tail=True, plot=False) # hold[2]: fixing dP_dE #print "---------------------------" #print fitter.result_string() #print "---------------------------" return fitter
def linefit(hist, bin_edges, linename): fitter = mass.getfitter(linename) fitter.fit(hist, bin_edges, plot=False) params = fitter.last_fit_params[:] params[fitter.param_meaning["tail_frac"]] = 0.25 params[fitter.param_meaning["dP_dE"]] = 1 params[fitter.param_meaning["resolution"]] = 6 fitter.fit(hist, bin_edges, params, hold=[2], vary_tail=True, plot=False) return fitter
def localfit(ds, linename, category=None): ''' NOTE parameters of MultiLorentzianComplexFitter param_meaning = { "resolution": 0, "peak_ph": 1, "dP_dE": 2, "amplitude": 3, "background": 4, "bg_slope": 5, "tail_frac": 6, "tail_length": 7 } ''' if category is not None: good = ds.cuts.good(**category) else: good = ds.good() elo, ehi = mass.STANDARD_FEATURES[linename] - 50, mass.STANDARD_FEATURES[ linename] + 50 edges = np.arange(elo, ehi, 1) counts, _ = np.histogram(ds.p_energy[good], edges) fitter = mass.getfitter(linename) fitter.fit(counts, edges, plot=False) params = fitter.last_fit_params[:] params[fitter.param_meaning["tail_frac"]] = 0.25 params[fitter.param_meaning["dP_dE"]] = 1 params[fitter.param_meaning["resolution"]] = 6 fitter.fit(counts, edges, params=params, hold=[2], vary_tail=True, plot=False) # hold[2]: fixing dP_dE #print "---------------------------" #print fitter.result_string() #print "---------------------------" return fitter
plt.figure() for fv in fvs: hist, bin_edges = np.histogram(fv[g], nbins, hist_range) plt.hist(fv[g], bin_edges, hist_range, histtype='step') plt.title(title) nbins = 200 hist_range = (6800., 7000.) plt.figure() for ene in enes: hist, bin_edges = np.histogram(ene[g], nbins, hist_range) plt.hist(ene[g], bin_edges, hist_range, histtype='step') plt.title(title) linename = "CoKAlpha" fitter = mass.getfitter(linename) nbins = 100 hist_range = (mass.STANDARD_FEATURES[linename] - 50, mass.STANDARD_FEATURES[linename] + 50) vtail = False plt.figure() ax1 = plt.subplot(311) hist, bin_edges = np.histogram(enes[0][g], bins=nbins, range=hist_range) fitter.fit(hist, bin_edges[0:-1], axis=ax1, color='red', vary_bg=True, vary_bg_slope=False, vary_tail=vtail)