def load_reweighter(): mode = gcm() # Hard coded check here: Use the RS mode if WS is supplied. Also get a new # mode object to remove possible MC flags. # Just recreate the mode here to get rid of potential MC flags mode = get_mode(mode.polarity, mode.year, mode.mode_short) if mode.mode == config.D0ToKpipipi_WS: mode = get_mode(mode.polarity, mode.year, 'RS') if mode.mode == config.D0ToKpipipi_2tag_WS: mode = get_mode(mode.polarity, mode.year, '2tag_RS') outfile = mode.get_output_path('effs') + 'reweighter.p' return helpers.load(outfile)
def load_classifiers(comb_bkg=False): mode = gcm() if comb_bkg: bdt_folder = 'bdt_comb_bkg' else: bdt_folder = 'bdt_rand_spi' # Hard coded check here: Use the RS mode if WS is supplied. Also get a new # mode object to remove possible MC flags. # Just recreate the mode here to get rid of potential MC flags mode = get_mode(mode.polarity, mode.year, mode.mode_short) if mode.mode == config.D0ToKpipipi_WS: mode = get_mode(mode.polarity, mode.year, 'RS') if mode.mode == config.D0ToKpipipi_2tag_WS: mode = get_mode(mode.polarity, mode.year, '2tag_RS') outfile = mode.get_output_path(bdt_folder) + 'classifiers.p' return helpers.load(outfile)
def load_workspace(mode): import ROOT outfile = mode.get_output_path('sweight_fit') + 'mass_fit.p' return helpers.load(outfile)
def dependence_study(use_efficiencies=False): extra_vars = [ gcm().ltime_var ] all_vars = gcm().phsp_vars + extra_vars # Current mode stuff data = gcm().get_data([f.var for f in extra_vars]) add_variables.append_phsp(data) df_sel = final_selection.get_final_selection() df_sel &= selection.delta_mass_signal_region() gen = get_model() if use_efficiencies: outfile = gcm().get_output_path('effs') + 'Gen_DATA_Eff_dep_eff.pdf' gen['weight'] = get_efficiency_gen() else: outfile = gcm().get_output_path('effs') + 'Gen_DATA_Eff_dep.pdf' gen['weight'] = 1. lim_file = gcm().get_output_path('effs') + 'limits_for_eff.p' with PdfPages(outfile) as pdf: for selected, plotted in permutations(all_vars, 2): log.info('Plotting {} in intervals of {}'.format( plotted.var, selected.var)) percentiles = np.arange(0, 1.1, 0.2) boundaries = helpers.weighted_quantile( data[selected.var][df_sel], percentiles) fig, ax = plt.subplots(figsize=(10, 10)) for low, high in zip(boundaries[:-1], boundaries[1:]): num_sel = (data[selected.var] > low) & (data[selected.var] < high) # NOQA den_sel = (gen[selected.var] > low) & (gen[selected.var] < high) denominator = gen[plotted.var][den_sel] numerator = data[plotted.var][df_sel & num_sel] weight_d = gen['weight'][den_sel] weight_d /= np.sum(weight_d) weight_n = np.ones(numerator.index.size)*1./numerator.index.size # NOQA x, y, x_err, y_err = helpers.make_efficiency( numerator, denominator, 50, weight_n, weight_d, independent=True) # NOQA options = dict( fmt='o', markersize=5, capthick=1, capsize=0, elinewidth=2, alpha=1) rlow, prec = helpers.rounder(low, boundaries) rhigh, _ = helpers.rounder(high, boundaries) spec = '{{:.{}f}}'.format(prec) label = r'${} <$ {} $ < {}$'.format( spec.format(rlow), selected.xlabel, spec.format(rhigh)) ax.errorbar(x, y, y_err, x_err, label=label, **options) ax.set_xlabel(plotted.xlabel) ax.set_ylabel('Relative efficiency') try: limits = load(lim_file) except: log.info('Creating new limits file') limits = {} if limits is None: log.info('Creating new limits file') limits = {} if (plotted.var, selected.var) not in limits or use_efficiencies is False: # NOQA plot_utils.y_margin_scaler(ax, hf=0.4) limits[(plotted.var, selected.var)] = ax.get_ylim() else: log.info('Applying limits') lim = limits[(plotted.var, selected.var)] ax.set_ylim(lim) dump(limits, lim_file) ax.legend() pdf.savefig(plt.gcf()) plt.close()
def load_bdt(mode=None): if mode is None: mode = gcm() outfile = mode.get_output_path('bdt') + 'bdt.p' return helpers.load(outfile)