def fit(config="config.yml", init_params="init_params.json", method="BFGS"): """ simple fit script """ # load config.yml config = ConfigLoader(config) # set initial parameters if have try: config.set_params(init_params) print("using {}".format(init_params)) except Exception as e: if str(e) != "[Errno 2] No such file or directory: 'init_params.json'": print(e) print("\nusing RANDOM parameters", flush=True) # print("\n########### initial parameters") # json_print(config.get_params()) # fit data, phsp, bg, inmc = config.get_all_data() try: fit_result = config.fit(batch=65000, method=method) except KeyboardInterrupt: config.save_params("break_params.json") raise except Exception as e: print(e) config.save_params("break_params.json") raise json_print(fit_result.params) fit_result.save_as("final_params.json") # calculate parameters error fit_error = config.get_params_error(fit_result, batch=13000) fit_result.set_error(fit_error) fit_result.save_as("final_params.json") pprint(fit_error) print("\n########## fit results:") for k, v in config.get_params().items(): print(k, error_print(v, fit_error.get(k, None))) # plot partial wave distribution config.plot_partial_wave(fit_result, plot_pull=True) # calculate fit fractions phsp_noeff = config.get_phsp_noeff() fit_frac, err_frac = config.cal_fitfractions({}, phsp_noeff) print("########## fit fractions") fit_frac_string = "" for i in fit_frac: if isinstance(i, tuple): name = "{}x{}".format(*i) else: name = i fit_frac_string += "{} {}\n".format( name, error_print(fit_frac[i], err_frac.get(i, None))) print(fit_frac_string)
def main(): Nbins = 64 config = ConfigLoader("config.yml") # config = MultiConfig(["config.yml"]).configs[0] config.set_params("final_params.json") name = "R_BC" idx = config.get_data_index("mass", "R_BC") # idx_costheta = (*config.get_data_index("angle", "DstD/D*"), "beta") datas, phsps, bgs, _ = config.get_all_data() amp = config.get_amplitude() get_data = lambda x: data_index(x, idx).numpy() # get_data = lambda x: np.cos(data_index(x, idx_costheta).numpy()) plot_mass(amp, datas, bgs, phsps, get_data, name, Nbins)
def cached_data(config_dict): config = ConfigLoader(config_dict) data, phsp, bg = config.get_all_data()[:3] return data, phsp, bg
def cached_data(config_dict): config = ConfigLoader(config_dict) data = config.get_all_data() return data