def chic_ratio_cs(gfile): """chic cross section ratio plot""" leg = setup_legend(0.6, 0.7, 0.88, 0.78) can = mkplot(scale_graph(r.TGraph(gfile.Get('chic_ratio_cs_full')), B_CHIC2_JPSI / B_CHIC1_JPSI), drawOpt='L', attr=[{ 'color': 1, 'line': 1, 'width': 2 }], yRange=[0, 1], xRange=[2, 10], xLabel=PTM_LABEL, yLabel='ratio', leg=leg, legEntries=['model'], legOpt='L') mkplot(scale_graph(gfile.Get('chic_ratio_CMS_cs'), B_CHIC2_JPSI / B_CHIC1_JPSI), drawOpt='PE same', can=can, attr=[{ 'color': COL[0], 'marker': 20, 'size': 1.8 }], leg=leg, legEntries=['B #chi_{c2} / B #chi_{c1} CMS']) return can
def make_plot(lth_g, dlth_g, lth2_g): """ Make the plot as a function of pT/M according to Carlos specifications """ lth_g = scale_graph_x(lth_g, 1 / m_psiPDG) dlth_g = scale_graph_x(dlth_g, 1 / m_psiPDG) lth2_g = scale_graph_x(lth2_g, 1 / m_psiPDG) lth2_g = shift_graph_horizontal(lth2_g, 0.1) leg = setup_legend(0.675, 0.74, 0.88, 0.88) can = mkplot([lth_g], drawOpt='P', attr=[ATTR['lth']], xRange=XRANGE, xLabel=PTMLABEL, yRange=YRANGE, yLabel='#lambda', leg=leg, legEntries=[YLABELS['lth']]) mkplot([dlth_g, lth2_g], drawOpt='samePE', can=can, attr=[ATTR['dlth'], ATTR['lth2']], leg=leg, legEntries=[YLABELS['dlth'], YLABELS['lth2']]) add_auxiliary_info(can, 2012, prelim=True, pos='left') return can
def plot_all_sdcs(sdcdir, order, outdir): """Plot all sdcs that are present in the sdcdir""" all_sdcs = glob.glob(f'{sdcdir}/*.txt') for fn in all_sdcs: name = os.path.basename(fn).replace('.txt', '') s = sdc.read_from_file(fn, order) s.scale_support(1 / r.ccbarMassSDCs) # rescale to pT/M can = mkplot(s.asTGraph(), drawOpt='P', xRange=XRANGE, xLabel='p_{T}/M', yLabel=name) can.SaveAs(f'{outdir}/{name}.pdf') graphs = [g for g in s.asAlwaysPositiveGraphs() if g.GetN() > 0] can = mkplot(graphs, drawOpt='P', logy=True, xRange=XRANGE, xLabel='p_{T}/M', legOpt='P', legPos=(0.75, 0.8, 0.88, 0.88), legEntries=('original', 'flipped'), ydscale=0.1, yLabel=f'{name} (negative values flipped)') can.SaveAs(f'{outdir}/{name}_log_positive.pdf')
def psi_pol(gfile): """psi(2S) and J/psi polarization plot""" leg = setup_legend(0.6, 0.2, 0.88, 0.36) can = mkplot([gfile.Get(n) for n in ['psip_pol_direct', 'jpsi_pol_full']], drawOpt='L', colors=[PSI_COL, JPSI_COL], leg=leg, legEntries=['#psi(2S) model', 'J/#psi model'], legOpt='L', xRange=[2, 30], xLabel=PTM_LABEL, yLabel=POL_LABEL, yRange=[-1, 1]) mkplot([gfile.Get(n) for n in ['psi2S_CMS_pol', 'jpsi_CMS_pol']], attr=[{ 'color': PSI_COL, 'marker': 20, 'size': 0.75 }, { 'color': JPSI_COL, 'marker': 21, 'size': 0.75 }], can=can, drawOpt='PE same', leg=leg, legEntries=['#psi(2S) CMS', 'J/#psi CMS']) return can
def make_ratio_plot(ratio, analytic_scens, variable): """ Make the comparison plot of the ratio and the analytical scenarios """ can = mkplot(ratio, drawOpt='PE', attr=[{ 'color': 1, 'size': 1, 'marker': 20 }], yLabel=YLABELS.get('r_chic2_chic1'), yRange=[0, 0.75], **VAR_PLOT[variable]) chi2_ndfs = get_chi2_ndf(ratio, analytic_scens) leg = setup_legend(0.2, 0.15, 0.65, 0.3) mkplot(analytic_scens.values(), drawOpt='sameL', can=can, attr=ANALYTIC_ATTRS, leg=leg, legEntries=analytic_scens.keys(), legOpt='L') add_auxiliary_info(can, 2012, prelim=True) return can
def psi2S_cs(gfile): """psi(2S) cross section plot""" names = ['psi2S_CMS_cs', 'psi2S_ATLAS_cs'] leg_entries = [ '#psi(2S) #rightarrow #mu#mu CMS', '#psi(2S) #rightarrow J/#psi #pi#pi ATLAS' ] graphs, leg_entries = _get_present(gfile, names, leg_entries) leg = setup_legend(0.5, 0.7, 0.88, 0.86) can = mkplot(graphs, drawOpt='PE', logy=True, logx=True, attr=DATA_ATTR, leg=leg, legEntries=leg_entries, xRange=CS_RANGE, xLabel=PTM_LABEL, yLabel=CS_LABEL) mkplot(gfile.Get('psip_cs_direct'), can=can, drawOpt='Lsame', leg=leg, legEntries=['best fit'], legOpt='L') return can
def _rel_diff_plot(graphs, model, **kwargs): """Make a plot with the relative differences""" # first assign the model values as uncertainties to the graphs delta_graphs = [] for g in graphs: x_vals = np.array(g.GetX()) y_vals = np.array(g.GetY()) fy_vals = np.array([model.Eval(x) for x in x_vals]) dy_vals = (y_vals - fy_vals) delta_graphs.append(divide_func(shift_graph(g, -fy_vals), model)) # delta_graphs.append(type(g)(len(x_vals), x_vals, dy_vals, *get_errors(g))) can = mkplot(delta_graphs, drawOpt='PE', xRange=CS_RANGE, xLabel='p_{T}/M', logx=True, yRange=[-0.5, 0.5], yLabel='(data - model) / model', **kwargs) mkplot(r.TLine(CS_RANGE[0], 0, CS_RANGE[1], 0), can=can, drawOpt='L same', attr=[{ 'color': 12, 'line': 1, 'width': 2 }]) return can
def costh_ratios(gfile): """Make the costh ratio plots""" graphs = [ gfile.Get(n) for n in list_obj(gfile, 'TGraph', 'chic_CMS_pol_ptM') ] cans = [] for graph in graphs: ptm_s = graph.GetName().split('_')[-1] ptm = float(ptm_s.replace('p', '.')) leg = setup_legend(0.55, 0.7, 0.88, 0.78) can = mkplot(graph, drawOpt='PE', attr=DATA_ATTR, leg=leg, legEntries=['CMS @ p_{{T}} / M = {:.2f}'.format(ptm)], xRange=[0, 1], xLabel=CTH_LABEL, yRange=[0.2, 0.6], yLabel='#chi_{c2} / #chi_{c1}') model = gfile.Get('chic_pol_ptM_{}'.format(ptm_s)) mkplot(model, can=can, drawOpt='Lsame', leg=leg, legEntries=['model'], legOpt='L') cans.append((ptm_s, can)) return cans
def _pull_plot(graphs, model, **kwargs): """Make the pull plot""" pull_graphs = [pull_graph(g, model) for g in graphs] can = mkplot([r.TLine(CS_RANGE[0], v, CS_RANGE[1], v) for v in [0, 2, -2]], drawOpt='L', attr=[{ 'color': 12, 'line': 1, 'width': 2 }, { 'color': 12, 'line': 7, 'width': 2 }, { 'color': 12, 'line': 7, 'width': 2 }], xRange=CS_RANGE, xLabel=PTM_LABEL, yRange=[-4, 4], logx=True, yLabel='(data - model) / data uncertainty') mkplot(pull_graphs, drawOpt='P same', can=can, **kwargs) return can
def _plot_tot_long_signs(state): index = getattr(state_enum, f's{state}') sdc_long, sdc_tot = sdcs.lng[index], sdcs.tot[index] leg = setup_legend(0.75, 0.8, 0.93, 0.94) can = mkplot( [g for g in sdc_tot.asAlwaysPositiveGraphs() if g.GetN() > 0], drawOpt='P', logy=True, attr=ATTRS_LT[:2], xRange=XRANGE, xLabel='p_{T}/M', legOpt='P', leg=leg, legEntries=('tot +', 'tot -'), ydscale=0.1, yLabel=f'{state} SDCs') return mkplot( [g for g in sdc_long.asAlwaysPositiveGraphs() if g.GetN() > 0], can=can, drawOpt='P same', attr=ATTRS_LT[2:], legOpt='P', leg=leg, legEntries=('long +', 'long -'))
def make_var_split_plot(rfile, var, savename, sum_dist=False, leg=False, **kwargs): """ Generate and save a gen_splitted plot TODO """ chic1_h, chic2_h = get_gen_splitted_hists(rfile, var, [select_trigger(), base_selection()]) x_label, y_label = kwargs.pop('xlabel', ''), kwargs.pop('ylabel', '') set_labels(chic1_h, x_label, y_label) set_labels(chic2_h, x_label, y_label) plot_hists = [chic1_h, chic2_h] leg_entries = ['#chi_{c1}', '#chi_{c2}'] if sum_dist: sum_h = chic1_h.Clone(chic1_h.GetName().replace('chic1', 'sum')) sum_h.Add(chic2_h) plot_hists = [sum_h] + plot_hists leg_entries = ['sum'] + leg_entries if leg: legend = r.TLegend(0.6, 0.91, 0.9, 0.95) legend.SetNColumns(3) legend.SetBorderSize(0) can = mkplot(plot_hists, leg=legend, legEntries=leg_entries, yRange=[0, None], **kwargs) else: can = mkplot(plot_hists, yRange=[0, None], **kwargs) can.SaveAs(savename)
def make_state_prob_plot(rfile, state, var): """ Make a plot comparing (the normalized) state probability distributions in all the bins """ hist_base = r'^{}_JpsiPt_0_{}_([0-9]+)_state_prob$'.format(state, var) hists = [rfile.Get(n) for n in list_obj(rfile, 'TH1D', hist_base)] [h.Scale(1.0 / h.Integral()) for h in hists] can = mkplot(hists, drawOpt='hist', xRange=[0, 1.25], xLabel=get_xlab(state), legPos=[0.83, 0.2, 0.94, 0.2 + 0.04 * len(hists)], legOpt='l', legEntries=['bin {}'.format(i) for i in xrange(len(hists))], yLabel='normalized distributions', logy=True, yRange=[0.0003, None]) mkplot(r.TLine(1, 0, 1, get_y_max(hists) * 1.1), can=can, drawOpt='same', attr=[{ 'color': 12, 'line': 7, 'width': 2 }]) return can
def make_limit_plot(graphs, variable): """ Make a limit plot """ leg = setup_legend(0.675, 0.74, 0.88, 0.88) can = mkplot(graphs.values(), xRange=[8, 30], xLabel=PTLABEL, drawOpt='PE', yRange=[-0.5, 1.1], yLabel=YLABELS[variable], leg=leg, legOpt='L', legEntries=['{} % C.L.'.format(v) for v in graphs.keys()]) mkplot(r.TLine(8, -0.33333, 30, -0.33333), can=can, drawOpt='same', attr=[{ 'color': 12, 'line': 7, 'linewidth': 2 }]) add_auxiliary_info(can, 2012, prelim=True, pos='left') return can
def make_rej_evs_w_state_prob_plot(rfile, state, var): """ Make a plot showing the state probability of the rejected events in all the bins """ hist_base = r'{}_JpsiPt_0_{}_([0-9]+)_state_prob_rej_ev'.format(state, var) hists = [rfile.Get(n) for n in list_obj(rfile, 'TH1D', hist_base)] can = mkplot(hists, drawOpt='PEX0', xRange=[0, 1.25], xLabel=get_xlab(state), legPos=[0.83, 0.2, 0.94, 0.2 + 0.04 * len(hists)], legEntries=['bin {}'.format(i) for i in xrange(len(hists))], yLabel='rejected events', logy=True, yRange=[0.1, None]) mkplot(r.TLine(1, 0, 1, get_y_max(hists) * 1.1), can=can, drawOpt='same', attr=[{ 'color': 12, 'line': 7, 'width': 2 }]) return can
def main(args): """Main""" set_TDR_style() cntfile = r.TFile.Open(args.centralfile) # Open correction maps here, to keep histos alive chi1_cf = r.TFile.Open(args.chi1corrfile) chi2_cf = r.TFile.Open(args.chi2corrfile) var = args.direction corrmap = get_correction_map(var, chi1_cf, chi2_cf) graph = get_graph(cntfile, corrmap, not args.uncorr, args.direction) can = make_plot_comp_ana_shapes(graph, var, args.mc) if args.compgraph is not None: cmpfile = r.TFile.Open(args.compgraph) cmpgraph = get_graph(cmpfile, corrmap, not args.uncorr, args.direction) mkplot(cmpgraph, can=can, drawOpt='samePE', attr=RATIO_ATTR[1:]) can.SaveAs(args.outfile) if args.saveto is not None: outfile = r.TFile(args.saveto, 'recreate') outfile.cd() graph.SetName(RATIO_NAME.format(args.direction)) graph.Write() outfile.Close()
def make_plot_comp_ana_shapes(graph, variable, is_mc=False): """ Make the comparison plot with the analytical shapes """ ana_shapes = get_analytic_scenarios(variable) fit_res = OrderedDict() for scen, shape in ana_shapes.iteritems(): fit_res[scen] = fit_to_dist(shape, graph) can = mkplot(graph, drawOpt='PE', attr=RATIO_ATTR, xRange=XRANGES[variable], xLabel=XLABELS[variable], yRange=[0, 1.2] if is_mc else [0, 0.75], yLabel=YLABEL) mkplot(ana_shapes.values(), can=can, drawOpt='same', attr=SCEN_ATTR, legPos=LEG_POS[variable], legEntries=get_legend_keys(fit_res), legOpt='L') add_auxiliary_info(can, [YEAR], prelim=True, mc=is_mc) return can
def make_ratio_plot(uncorr_ratio, corr_ratio, variable): """ Make the comparison plot of corrected and uncorrected graphs """ leg = setup_legend(*LEGEND_POS[variable]) leg.SetTextSize(0.03) can = mkplot(corr_ratio, drawOpt='PE', attr=[{ 'color': 1, 'size': 1, 'marker': 20 }], yLabel=YLABELS.get('r_chic2_chic1'), yRange=[0, 0.75], leg=leg, legEntries=['corrected'], **VAR_PLOT[variable]) shift = HORIZONTAL_SHIFT[variable] mkplot([ shift_graph_horizontal(rescale_graph(uncorr_ratio, corr_ratio), shift), shift_graph_horizontal(uncorr_ratio, -shift) ], can=can, drawOpt='samePE', attr=default_attributes(open_markers=True), leg=leg, legEntries=['fitted (scaled)', 'fitted']) add_auxiliary_info(can, 2012, prelim=True) return can
def make_ratio_plot(can, hists, leg, legentries, **kwargs): """ Wrapper around """ if legentries: mkplot(hists, can=can, leg=leg, legEntries=legentries, **kwargs) else: mkplot(hists, can=can, **kwargs)
def make_plot(contours, best_fits, leg_keys, **kwargs): """Make the plot and return the canvas""" conts = contours.values() conf_levels = contours.keys() leg_coords = (0.2, 0.6, 0.4, 0.8) if len(conf_levels) > 1: leg_coords = (0.2, 0.6, 0.4, 0.84) leg = setup_legend(*leg_coords) can = mkplot(conts[0], drawOpt='L', leg=leg, legEntries=leg_keys, attr=CONT_ATTRS[0], legOpt='L', **kwargs) if len(conts) > 1: leg_graphs = [r.TGraph(1, np.array([-1000]), np.array([-10000])) for _ in conf_levels] mkplot(leg_graphs, drawOpt='Lsame', can=can, attr=LEG_C_ATTR, leg=leg, legEntries=['{:.1f}% CL'.format(v) for v in conf_levels], legOpt='L') for i in range(1, len(contours)): mkplot(conts[i], can=can, drawOpt='Lsame', attr=CONT_ATTRS[i]) # best fit points mkplot(best_fits, drawOpt='Psame', can=can, attr=BF_ATTRS) leg_graph = r.TGraph(1, np.array([-1000]), np.array([-10000])) mkplot(leg_graph, drawOpt='Psame', can=can, leg=leg, legEntries=['best fit'], attr=LEG_BF_ATTR, legOpt='P') return can
def make_lth_plot(hfile): """ Make the lambda1 plot """ ppd = get_scaled_ppd(hfile, 'lth', 100) ppdmax = get_y_max(ppd) can = plot_lth(ppd) mkplot(r.TLine(-0.3333, 0, -0.3333, ppdmax * 1.1, ), can=can, drawOpt='same', attr=[{'color': 12, 'line': 7, 'width': 2}]) make_nice(can) return can
def make_lph_plot(hfile): """ Make the lambda_phi 1 plot """ ppd = get_scaled_ppd(hfile, 'lph', 50) ppdmax = get_y_max(ppd) can = plot_lph(ppd) mkplot([r.TLine(v, 0, v, ppdmax * 1.1) for v in [-1./3, 1./3]], can=can, drawOpt='same', attr=[{'color': 12, 'line': 7, 'width': 2}]) make_nice(can) return can
def main(args): """Main""" mcdata = get_dataframe(args.mcfile, columns=MC_VARIABLES) chi1data = get_dataframe(args.chic1file, 'tr', columns=TOY_VARIABLES) chi2data = get_dataframe(args.chic2file, 'tr', columns=TOY_VARIABLES) mc_ratios = OrderedDict() toy_ratios = OrderedDict() for name in SELECTIONS_TOY: toy_ratios[name] = OrderedDict() mc_ratios[name] = OrderedDict() toy_sel = SELECTIONS_TOY[name] mc_sel = SELECTIONS_MC[name] for var in VARIABLES: hist_sett = VARIABLES[var]['sett'] toy_ratios[name][var] = get_ratio(chi1data, chi2data, VARIABLES[var]['var'], toy_sel, hist_sett, get_weight_func()) mc_ratios[name][var] = get_ratio_mc(mcdata, VARIABLES[var]['var'], mc_sel, hist_sett) set_TDR_style() for name in SELECTIONS_TOY: for var in VARIABLES: leg = setup_legend(*LEGPOS[var]) can = mkplot(mc_ratios[name][var], attr=[PLOT_ATTRIBUTES[name]['mc']], drawOpt='E2', legOpt='F', xLabel=LABELS[var], yLabel='#chi_{c2} / #chi_{c1}', leg=leg, legEntries=['real mc']) can = mkplot(toy_ratios[name][var], attr=[PLOT_ATTRIBUTES[name]['toy']], drawOpt='E1same', legOpt='PLE', can=can, xLabel=LABELS[var], yLabel='#chi_{c2} / #chi_{c1}', leg=leg, legEntries=['toy mc']) latex = setup_latex() can.add_tobject(latex) put_on_latex(latex, [(0.18, 0.96, name)]) savename = '_'.join(['comp_real_toy', name, var]).replace(' + ', '_') can.SaveAs(savename + '.pdf')
def make_dlph_plot(hfile): """ Make the dlph plot """ ppd = get_scaled_ppd(hfile, 'dlph', 800) can = plot_dlph(ppd) ppdmax = get_y_max(ppd) mkplot([r.TLine(v, 0, v, ppdmax * 1.1) for v in [-0.78, 0.78]], can=can, drawOpt='same', attr=[{'color': 12, 'line': 7, 'width': 2}]) make_nice(can) return can
def make_debug_plot(comb_ppd, inputfiles, var): """ Make a plot overlaying the combined ppd and the input ppds """ can = PLOT_FUNCTIONS[var](rebin(comb_ppd, [(0, 200)])) set_color(can.pltables[1], 1) # make the combined ppd black ppds = [get_scaled_ppd(f, var, 200) for f in inputfiles] mkplot(ppds, can=can, drawOpt='samehist', attr=default_attributes(linewidth=1)) return can
def make_quantile_ratio_plots(rfile, var, state, quantile_pairs, savename_base, **kwargs): """ Make ratio plots w.r.t. no selection and quantile selection TODO """ mass_hist = get_histogram(rfile, 'chicMass', state, combine_cuts([select_trigger(), base_selection()])) # get the mass values for the quantiles q_masses = [get_quantiles(mass_hist, q) for q in quantile_pairs] mass_cuts = [var_selection('chicMass', q[0], q[1]) for q in q_masses] leg_entries = ['[{}, {}]'.format(*q) for q in quantile_pairs] mass_cut_hists = get_mass_cut_hists(rfile, var, state, mass_cuts, combine_cuts([base_selection(), select_trigger()])) # get the baseline histogram as well as the full histogram (w/o cuts # apart from trigger) base_hist = get_histogram(rfile, var, state, combine_cuts([base_selection(), select_trigger()])) full_hist = get_histogram(rfile, var, state, select_trigger()) x_label, y_label = kwargs.pop('x_label', ''), kwargs.pop('y_label', '') for h in mass_cut_hists + [full_hist, base_hist]: set_labels(h, x_label, y_label) leg = r.TLegend(0.1, 0.91, 0.9, 0.95) leg.SetNColumns(len(quantile_pairs) + 2) leg.SetBorderSize(0) can = mkplot(mass_cut_hists + [full_hist, base_hist], leg=leg, legEntries=leg_entries + ['no cut', 'baseline'], yRange=[0, None]) can.SaveAs(savename_base + '_dists.pdf') full_ratios = get_ratio_hists(mass_cut_hists, full_hist) leg.Clear() leg.SetNColumns(len(quantile_pairs)) can = mkplot(full_ratios, leg=leg, legEntries=leg_entries, yRange=[0, None]) can.SaveAs(savename_base + '_ratio_full.pdf') base_ratios = get_ratio_hists(mass_cut_hists, base_hist) leg.Clear() can = mkplot(base_ratios, leg=leg, legEntries=leg_entries, yRange=[0, None]) can.SaveAs(savename_base + '_ratio_base.pdf')
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 make_2d_contour_plot(input_files, var_pair): """Make one plot of all input_files""" varx, vary = var_pair graphs = [ f.Get('corr_2d_{}_{}_1sigma'.format(varx, vary)) for f in input_files.values() ] # These are possibly stored in reversed order so the axis have to be # flipped if var_pair == ('r_chic1_jpsi', 'r_chic2_jpsi'): # try to get them the other way around graphs_2 = [ f.Get('corr_2d_{}_{}_1sigma'.format(vary, varx)) for f in input_files.values() ] # Check which graphs are not present and replace them with the flipped axis version for i, g in enumerate(graphs): if not g: graphs[i] = flip_axis(graphs_2[i]) if len(graphs) == 1: leg = None leg_entries = None else: leg = setup_legend(0.75, 0.8, 0.92, 0.8 + len(graphs) * 0.035) leg_entries = input_files.keys() can = mkplot(graphs, drawOpt='L', attr=default_attributes(line=1), leg=leg, legEntries=leg_entries, legOpt='L', yLabel=get_label(vary), yRange=get_range(vary), xLabel=get_label(varx), xRange=get_range(varx)) return can
def store_hist(hist, out_dir, formats, draw_opt, **kwargs): """Store one hist""" for axis in 'xyz': ax_range = kwargs.pop(axis + 'range', None) if ax_range is not None: range_vals = [float(v) for v in ax_range.split(',')] haxis = getattr(hist, 'Get' + axis.upper() + 'axis')() haxis.SetRangeUser(*range_vals) hist_cmd = kwargs.pop('hist_cmd', None) if hist_cmd is not None: if hasattr(hist, hist_cmd): hist = getattr(hist, hist_cmd)() if not isinstance(hist, (r.TH1, r.TGraph, r.TF1)): logging.fatal( 'Result of \'{}\' is not a plotable object'.format( hist_cmd)) sys.exit(1) else: logging.error( 'Cannot call \'{}\' on histogram object.'.format(hist_cmd)) hist.SetStats(0) can = mkplot(hist, drawOpt=draw_opt) name = '/'.join([out_dir, hist.GetName()]) for form in formats: can.SaveAs('.'.join([name, form]))
def make_mass_quantile_plot(hist, quantile_pairs, color, savename): """ Quantile plots for one state. TODO: """ y_range = [0, hist.GetMaximum() * 1.05] set_range_hists([hist], y_range=y_range) can = mkplot([hist], colors=[color], drawOpt='H') leg = r.TLegend(0.1, 0.91, 0.9, 0.95) leg.SetNColumns(len(quantile_pairs)) leg.SetBorderSize(0) line_styles = [2, 3, 5, 6] # store all lines in this list so that they live long enough to be plotted lines = [] for i, pair in enumerate(quantile_pairs): quantiles = get_quantiles(hist, pair) qline_1, qline_2 = get_quantile_lines(quantiles, y_range, default_colors()[0], line_styles[i]) qline_2.Draw() qline_1.Draw() leg.AddEntry(qline_1, '[{}, {}]'.format(*pair), 'l') lines.append(qline_1) lines.append(qline_2) leg.Draw() can.Draw() can.SaveAs(savename)
def _plot_total_sdc(state, **kwargs): index = getattr(state_enum, f's{state}') sdc_tot = sdcs.tot[index] sdc_tot = scale_sdc(SCALE_FACTORS[state], sdc_tot) graphs = [g for g in sdc_tot.asAlwaysPositiveGraphs() if g.GetN() > 0] can = mkplot(graphs[0], attr=ATTRS[state], legEntries=[state], legOpt='L', **kwargs) if len(graphs) > 1: can = mkplot(graphs[1], can=can, drawOpt=kwargs.get('drawOpt', 'C') + 'same', attr=ATTRS[state]) return can