def debug_plots(basename, rfile, state_prob, corr_w, mass): """ Make some debug plots and store them into a root file so that they can be viewed later """ rfile.cd() prob_h = hist1d(state_prob, min=0, max=1, name=basename + '_state_prob') corr_h = hist1d(corr_w, log=True, name=basename + '_corr_w') w_h = hist1d(state_prob * corr_w, log=True, name=basename + '_final_weight') # Keep the 2d histograms consistent between different bins by setting ranges corr_v_prob = hist2d(state_prob, corr_w, minx=0, maxx=1, miny=1, maxy=1e5, logy=True, y_axis='corr_weight', name=basename + '_corr_w_v_state_prob') w_v_prob = hist2d(state_prob, corr_w * state_prob, minx=0, maxx=1, miny=0.01, maxy=1e4, logy=True, y_axis='final_weight', name=basename + '_final_weight_v_state_prob') mass_h = hist1d(mass, min=3.2, max=3.75, weights=state_prob, name=basename + '_mass_w_state_prob') mass_h_w = hist1d(mass, min=3.2, max=3.75, weights=state_prob * corr_w, name=basename + '_mass_w_final_weight') rej_sp_h = hist1d(state_prob[corr_w == 0], min=0, max=1, name=basename + '_state_prob_rej_ev') for h in [prob_h, corr_h, w_h, corr_v_prob, w_v_prob, mass_h, mass_h_w, rej_sp_h]: h.Write()
def make_plot_good_fit(data, var_x, var_y, tf_x, tf_y): """Make a plot showing whether the fit was successful or not for each point of the scan""" # Remove the minimum since that is in any case valid data = apply_selections(data, lambda d: d.llh != d.llh.min()) trans_f_x = globals()[tf_x] trans_f_y = globals()[tf_y] x_vals = trans_f_x(data.loc[:, var_x]) y_vals = trans_f_y(data.loc[:, var_y]) x_binning = get_variable_binning(x_vals) y_binning = get_variable_binning(y_vals) good_fit = data.goodFit > 0 hist = hist2d(x_vals[good_fit], y_vals[good_fit], x_hist_sett=(len(x_binning) - 1, x_binning), y_hist_sett=(len(y_binning) - 1, y_binning)) can = mkplot(to_bw_hist(hist), drawOpt='colz', xRange=[x_binning[0], x_binning[-1]], yRange=[y_binning[0], y_binning[-1]], xLabel=get_var_name(var_x, tf_x), yLabel=get_var_name(var_y, tf_y)) hist = can.pltables[1] hist.GetZaxis().SetRangeUser(0, 10) remove_color_bar(can) return can
def ppd_2d(data, var1, vfunc1, var2, vfunc2, name_fmt, weights=None): """ Get the 2d ppd histogram for a given variable """ xran = XRANGES.get(var1) yran = XRANGES.get(var2) bounds = { 'minx': xran[0], 'maxx': xran[1], 'nbinsx': NBINS_2D, 'miny': yran[0], 'maxy': yran[1], 'nbinsy': NBINS_2D, 'name': name_fmt.format('_'.join(['2d', var1, var2])) } # TODO: Remove after unblinding vals1, low1, high1 = get_var_shifted(data, vfunc1, name_fmt.format(var1), { 'min': bounds['minx'], 'max': bounds['maxx'] }) bounds['minx'] = low1 bounds['maxx'] = high1 vals2, low2, high2 = get_var_shifted(data, vfunc2, name_fmt.format(var2), { 'min': bounds['miny'], 'max': bounds['maxy'] }) bounds['miny'] = low2 bounds['maxy'] = high2 return hist2d(vals1, vals2, weights=weights, **bounds)
def make_2D_hist(dfr, varx, vary, selection=None, weight=None, **kwargs): """ Make the 2D histogram and return it """ logging.debug('Making histograms for {}:{}'.format(varx, vary)) dfr, weights = get_df_and_weights(dfr, selection, weight) return hist2d(_get_var(dfr, varx), _get_var(dfr, vary), weights=weights, **kwargs)
def get_2d_hist(data, varx, vary, nbinsx=100, nbinsy=100): """Get the 2d distribution of vary vs varx""" # Get rid of very large outliers xmin, xmax = quantile(data.loc[:, varx].values, [0.0001, 0.9999]) ymin, ymax = quantile(data.loc[:, vary].values, [0.0001, 0.9999]) return hist2d(data.loc[:, varx], data.loc[:, vary], minx=xmin, maxx=xmax, miny=ymin, maxy=ymax, nbinsx=nbinsx, nbinsy=nbinsy)
def make_costh_phi_plot(data, frame): """Make costh-phi histogram""" hist = hist2d(_get_var(data, 'costh_{}_fold'.format(frame), np.abs), _get_var(data, 'phi_{}_fold'.format(frame)), nbinsx=24, minx=0, maxx=1, nbinsy=32, miny=0, maxy=90) cth_lab = '|cos#vartheta^{{{}}}|'.format(frame) phi_lab = '#varphi^{{{}}}_{{fold}}'.format(frame) can = mkplot(hist, drawOpt='colz', xRange=[0, 1], xLabel=cth_lab, yRange=[0, 90], yLabel=phi_lab) can.pltables[0].SetNdivisions(505, 'X') can.Update() return can
def make_overlay_plot(pt_map, pt_data, **kwargs): """ Plot the coverage of the pt_data onto the """ amap_x, amap_y = get_binning(pt_map, 0), get_binning(pt_map, 1) if np.min(amap_x) == 0: costh = pt_data.costh_HX_fold.abs() else: costh = pt_data.costh_HX_fold data_dist = hist2d(costh, pt_data.phi_HX_fold, x_hist_sett=(len(amap_x) - 1, amap_x), y_hist_sett=(len(amap_y) - 1, amap_y)) coverage = get_array(data_dist) > 0 cov_graph = get_mask_graph(amap_x, amap_y, coverage) can = mkplot(pt_map, **kwargs) mkplot(cov_graph, can=can, drawOpt='sameE5', attr=[{ 'color': r.kRed, 'fillalpha': (r.kRed, 0), 'marker': 1 }]) mkplot([ r.TLine(v, np.min(amap_y), v, np.max(amap_y)) for v in [-0.625, -0.45, 0.45, 0.625] ], attr=[{ 'color': 12, 'line': 7, 'width': 2 }], can=can, drawOpt='same') return can
def fill_2d(data, frame, weights): """2D histograms""" return hist2d(_get_var(data, 'costh_' + frame), _get_var(data, 'phi_' + frame), hist_sett=(n_costh, -1, 1, n_phi, -180, 180), weights=weights)