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(hists, savename, reference, doleg=False): """ Make plot """ set_TDR_style() can = r.TCanvas(create_random_str(16), '', 50, 50, 600, 600) can.cd() # preliminary collect them and delete entries if necessary legentries = [] with_ref = False if reference is not None: ref_hist = hists[reference] with_ref = True rest_hists = [hists[k] for k in hists if k != reference] pull_hists = [do_ratio(ref_hist, h) for h in rest_hists] legentries = [reference] + [n for n in hists if n != reference] else: rest_hists = hists.values() legentries = hists.keys() if doleg: for i, entry in enumerate(legentries): legentries[i] = entry.replace('jpsi_kin_sel', '').replace('__', '_') else: legentries = [] y_max = get_y_max(hists.values()) * 1.1 leg=setup_legend() if with_ref: pad = r.TPad('ratio_pad', 'ratio_pad', 0, 0.3, 1, 1) r.SetOwnership(pad, False) pad.Draw() pad.cd() # passing all legentries here, since indexing doesn't work with an empty # list and mkplot picks only the first in this case make_ratio_plot(pad, [ref_hist], leg, legentries, yRange=[0, y_max], attr=gen_attributes, drawOpt='E2', legOpt='F') make_ratio_plot(pad, rest_hists, leg, legentries[1:], yRange=[0, y_max], attr=comp_attributes, drawOpt='sameE1', legOpt='PLE') can.cd() pull_pad = r.TPad('pull_pad', 'pull_pad', 0, 0, 1, 0.3) r.SetOwnership(pull_pad, False) pull_pad.Draw() pull_pad.cd() make_ratio_plot(pull_pad, pull_hists, None, [], yRange=[None, None], attr=comp_attributes) else: make_ratio_plot(can, rest_hists, leg, legentries, yRange=[0, y_max], attr=comp_attributes) can.SaveAs(savename)
def main(): """Main""" set_TDR_style() r.gStyle.SetPadRightMargin(r.gStyle.GetPadRightMargin() + 0.01) data = apply_selections(get_dataframe(INFILE, columns=collect_requirements(SELECTIONS)), SELECTIONS) can = make_photon_pt_dist_plot(data) can.SaveAs(os.path.join(OUTDIR, 'photon_pt_dist.pdf'))
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 main(args): """Main""" set_TDR_style() ucfile = r.TFile.Open(args.uncorrfile) uncorr_g = get_graph(ucfile, 'r_chic2_chic1', args.variable) cfile = r.TFile.Open(args.corrfile) corr_g = get_graph(cfile, 'r_chic2_chic1', args.variable) can = make_ratio_plot(uncorr_g, corr_g, args.variable) cond_mkdir(args.outdir) can.SaveAs('{}/r_chic2_chic1_v_{}_comp_corr_uncorr.pdf'.format( args.outdir, args.variable))
def make_plot(data_graph, mc_graphs, pdfname, canvas_sett): """ Make plot and save """ mc_attributes = [{ 'color': default_colors()[0], 'marker': 25, 'size': 1.5, 'fillalpha': (default_colors()[0], 0.5) }, { 'color': default_colors()[1], 'marker': 26, 'size': 1.5, 'fillalpha': (default_colors()[1], 0.5) }, { 'color': default_colors()[2], 'marker': 27, 'size': 1.5, 'fillalpha': (default_colors()[2], 0.5) }] data_attributes = [{'color': 1, 'marker': 20, 'size': 1.5}] set_TDR_style() can = r.TCanvas('rcan', 'rcan', 50, 50, 600, 600) frame = can.DrawFrame(*canvas_sett['range']) frame.SetXTitle(canvas_sett['xtitle']) frame.SetYTitle(canvas_sett['ytitle']) leg = setup_legend() mc_rescaled = rescale_MC_graphs(data_graph, mc_graphs.values(), SCALE_FUNC) plot_on_canvas(can, mc_rescaled, drawOpt='P2', leg=leg, legOpt='PF', legEntries=mc_graphs.keys(), attr=mc_attributes) plot_on_canvas(can, [data_graph], drawOpt='samePE', leg=leg, legEntries=['data'], attr=data_attributes) can.SaveAs(pdfname)
def main(args): """Main""" set_TDR_style() files = parse_inputs(args.input, enforce_keys=True) var_x = 'lambda_1' var_y = 'lambda_2' contours = get_all_contours(files, args.conf_levels, var_x, var_y) best_fits = get_best_fits(files, var_x, var_y) can = make_plot(contours, best_fits, files.keys(), xRange=[-2, 2], yRange=[-2, 2], xLabel='#lambda_{#vartheta}^{#chi_{c1}}', yLabel='#lambda_{#vartheta}^{#chi_{c2}}') can.SaveAs(args.outfile)
def main(args): """Main""" set_TDR_style() graphfile = r.TFile.Open(args.graphfile) g_lth = get_graph(graphfile, 'lth') g_dlth = get_graph(graphfile, 'dlth') g_lth2 = get_graph(graphfile, 'lth2') if args.systematics is not None: syst_file = r.TFile.Open(args.systematics) syst_graph = syst_file.Get('dlth_v_pt_syst') g_dlth = get_combined_graph(g_dlth, syst_graph) g_lth2 = get_combined_graph(g_lth2, syst_graph) can = make_plot(g_lth, g_dlth, g_lth2) can.SaveAs(args.output)
def main(): """Main""" set_TDR_style() cond_mkdir(OUTDIR) data = apply_selections(get_dataframe(INFILE), SELECTIONS) r.gStyle.SetPadRightMargin(0.129) r.gStyle.SetPadLeftMargin(r.gStyle.GetPadLeftMargin() - 0.007) can = make_costh_phi_plot(data, 'HX') can.SaveAs(os.path.join(OUTDIR, 'costh_phi_fold_HX_pt_12_18_all.pdf')) can = make_costh_phi_plot(data, 'CS') can.SaveAs(os.path.join(OUTDIR, 'costh_phi_fold_CS_pt_12_18_all.pdf')) set_TDR_style() can = make_costh_mu_pt_plot(data) can.SaveAs(os.path.join(OUTDIR, 'costh_HX_comp_mu_pt_jpsipt_12_18_all.pdf'))
def main(): """Main""" set_TDR_style() r.gStyle.SetPadTopMargin(r.gStyle.GetPadTopMargin() + 0.005) ppd_files = open_ppd_files('costh') can = make_lth_plot(ppd_files) can.SaveAs(os.path.join(OUTDIR, 'ppd_lth_w_lower_lim_90_combined.pdf')) can = make_dlth_plot(ppd_files) can.SaveAs(os.path.join(OUTDIR, 'ppd_dlth_combined.pdf')) ppd_files = open_ppd_files('phi') can = make_lph_plot(ppd_files) can.SaveAs(os.path.join(OUTDIR, 'ppd_lph_combined.pdf')) can = make_dlph_plot(ppd_files) can.SaveAs(os.path.join(OUTDIR, 'ppd_dlph_combined.pdf'))
def main(args): """Main""" set_TDR_style() ppd_file = r.TFile.Open(args.ppdfile) # Only now do we know the shift, so put it here PLOT_FUNCTIONS['dlth'] = lambda f: _make_dlth_plot(f, args.shift_by) plot_vars = [] if 'costh' in args.variables: plot_vars.extend(['lth', 'dlth', 'norm_costh']) if 'phi' in args.variables: plot_vars.extend(['lph', 'dlph', 'norm_phi']) if '_' in args.variables: plot_vars.extend(['ltilde', 'dltilde']) for var in plot_vars: func = PLOT_FUNCTIONS[var] can = func(ppd_file) can.SaveAs('ppd_{}.pdf'.format(var))
def main(args): """Main""" with open(args.configfile, 'r') as configfile: config = json.load(configfile) model = BinnedFitModel(config) ffile = r.TFile.Open(args.fitfile) wsp = ffile.Get('ws_mass_fit') if args.outdir is None: outdir = dirname(args.fitfile) else: outdir = args.outdir cond_mkdir(outdir) if args.publication: set_TDR_style() # Saving the plots if not args.no_plots: cans = model.plot(wsp, verbose=args.verbose, publication=args.publication, preliminary=args.preliminary) canp = model.plot_fit_params(wsp) for bin_name in model.bins: plotname = '/'.join([outdir, bin_name+'_massfit.pdf']) if args.publication: add_auxiliary_info(cans[bin_name], 2012, prelim=True) cans[bin_name].SaveAs(plotname) parname = '/'.join([outdir, bin_name+'_massfit_res.pdf']) canp[bin_name].SaveAs(parname) if args.graphs: outfile = '/'.join([outdir, 'proto_param_graphs.root']) store_proto_pars(wsp, model, outfile, args.symmetric)
def main(args): """Main""" set_TDR_style() graphfile = r.TFile.Open(args.graphfile) var, graphs = get_graphs(graphfile) if args.systematics is None: can = make_plot(graphs, var, args.sigmas.split(',')) else: syst_file = r.TFile.Open(args.systematics) can = make_plot_with_syst(graphs, var, syst_file, args.fit, args.pt_over_m) comb_gr = can.pltables[1] comb_gr.SetName(graphs.values()[0].GetName()) outfile = r.TFile( '{}/comb_graph_{}_v_pt.root'.format(args.outdir, var), 'recreate') outfile.cd() comb_gr.Write() outfile.Close() cond_mkdir(args.outdir) can.SaveAs('{}/{}_v_pt.pdf'.format(args.outdir, var))
def main(args): """Main""" set_TDR_style() rfile = r.TFile.Open(args.ratiofile) ratio = get_graph(rfile, 'r_chic2_chic1', args.variable) if args.variable == 'costh': analytic_scens = get_analytic_scenarios_costh(args.delta_lambda, args.lambda1, args.lambda2, args.no_extremes) else: # not implemented currently for phi direction analytic_scens = OrderedDict() if args.pull_plot: can = make_ratio_pull_plot(ratio, analytic_scens, args.variable) else: can = make_ratio_plot(ratio, analytic_scens, args.variable) cond_mkdir_file(args.outfile) can.SaveAs(args.outfile)
def main(args): """Main""" set_TDR_style() fitfile = r.TFile.Open(args.fitfile) cont_1sigma = get_contour(fitfile.Get('chi2_scan_contour_1sigma')) cont_2sigma = get_contour(fitfile.Get('chi2_scan_contour_2sigma')) cont_3sigma = get_contour(fitfile.Get('chi2_scan_contour_3sigma')) leg = setup_legend(0.5, 0.78, 0.8, 0.94) leg.SetTextSize(0.035) leg.SetEntrySeparation(0.005) leg.SetFillStyle(1001) can = mkplot([cont_1sigma, cont_2sigma, cont_3sigma], drawOpt='L', xRange=[-1, 1.6], xLabel='#lambda_{#vartheta}^{#chi_{c1}}', yRange=[-1.2, 1.6], yLabel='#lambda_{#vartheta}^{#chi_{c2}}', attr=CONT_ATTR, leg=leg, legEntries=['{} % CL'.format(v) for v in [68, 95, 99]], legOpt='L') mkplot(get_phys_region(), can=can, drawOpt='same', attr=[{ 'color': r.kRed, 'line': 7, 'width': 3 }]) mkplot([r.TLine(0, -1.2, 0, 1.6), r.TLine(-1, 0, 1.6, 0)], can=can, drawOpt='same', attr=[{ 'color': 12, 'line': 7, 'width': 2 }]) mkplot(r.TGraph(1, np.array([0]), np.array([0])), can=can, drawOpt='Psame', attr=[{ 'color': 1, 'marker': 24, 'size': 2.75 }]) mkplot(get_jz_graph(), can=can, drawOpt='Psame', attr=[{ 'color': 1, 'marker': 30, 'size': 3 }]) ltx = setup_latex() ltx.SetTextSize(0.04) put_on_latex(ltx, [(-0.4, 1.3, 'J_{z}'), (-0.4, 1.1, '#pm1'), (0.975, 1.1, '0'), (-0.54, 0.95, '#pm2'), (-0.54, -0.38, '#pm1'), (-0.47, -0.65, '0')], ndc=False) add_auxiliary_info(can, 2012, 'left') can.SaveAs(args.outfile)
def main(args): """Main""" # need PlotServer here, to keep the root file open pserver = PlotServer(args.histfile) norm_mode = 'at0' if args.normalize_at_zero else 'nsignal' year_trg_ids, leg_entries = get_trigger_year_info(args.input) hists = get_plot_hists(pserver, year_trg_ids, args.ratio, args.variable, args.frame, args.ptbin, state=args.state, norm_mode=norm_mode, norm_ratio=args.norm_ratio) # split into data and mc hist due to different plotting styles for the two data_hists = {k: hists[k] for k in hists if 'data' in k} mc_hists = {k: hists[k] for k in hists if 'mc' in k} leg = None data_leg = [] mc_leg = [] if args.legend: leg = setup_legend(args.frame, args.ratio) if args.ratio: data_leg = [leg_entries[(k[0], k[1]), ] for k in data_hists] mc_leg = [leg_entries[(k[0], k[1]), ] for k in mc_hists] else: data_leg = [ ', '.join([leg_entries[(k[0], k[1]), ], k[2]]) for k in data_hists ] data_leg = nice_leg_entries(data_leg) mc_leg = [ ', '.join([leg_entries[(k[0], k[1]), ], k[2]]) for k in mc_hists ] mc_leg = nice_leg_entries(mc_leg) dpl_attr = [get_plot_attributes(*k) for k in data_hists] mpl_attr = [get_plot_attributes(*k) for k in mc_hists] y_label = get_ylabel(not args.ratio, args.normalize_at_zero, args.norm_ratio) if args.state == 'chib': y_label = re.sub(r'c(\d)', r'b\1', y_label) x_label = get_xlabel(args.variable, args.frame) # to have same y-range for everything, have to do it manually, as # mkplot can't handle it in two different calls y_max = get_y_max(data_hists.values() + mc_hists.values()) * 1.1 set_TDR_style() can = None # declare here to be able to switch the two calls below can = mkplot(mc_hists.values(), yRange=[0, y_max], drawOpt='E2', attr=mpl_attr, can=can, leg=leg, legEntries=mc_leg, legOpt='F', xLabel=x_label, yLabel=y_label) can = mkplot(data_hists.values(), yRange=[0, y_max], drawOpt='E1', attr=dpl_attr, can=can, leg=leg, legEntries=data_leg, legOpt='PLE', xLabel=x_label, yLabel=y_label) lumi_text = get_lumi_text(year_trg_ids) add_lumi_info(can, lumi_text) can.SaveAs(args.output)