def make_val_plots(self, sample_sets, bin_var, prefix, outdirpath): val_histo_summary = [] var = Var(bin_var, self.settings.channel) for sample_set in sample_sets: val_histo = self.get_histo_for_val(sample_set, var) val_histo_summary.append(val_histo) descriptions = { "plottype": "ProjectWork", "xaxis": var.tex, "channel": self.settings.channel, "CoM": "13", "lumi": "35.87", "title": "ANTIISO1" } outfilepath = "{0}/{1}_{2}_val_{3}_{4}.png".format( outdirpath, self.settings.channel, prefix, sample_set.name, bin_var) self.create_plot(val_histo, descriptions, outfilepath) descriptions = { "plottype": "ProjectWork", "xaxis": var.tex, "channel": self.settings.channel, "CoM": "13", "lumi": "35.87", "title": "ANTIISO1" } outfileprefix = "{0}/{1}_{2}_val_{3}_{4}".format( outdirpath, self.settings.channel, prefix, "inclusive", bin_var)
def make_classification_plots(self, sample_sets, bin_var, prefix, outdirpath, inclusive=False): fraction_histo_summary = {} var = Var(bin_var, self.settings.channel) for sample_set in sample_sets: histos = self.get_histos_for_classification(sample_set, var) fraction_histo_summary[sample_set.name] = histos descriptions = { "plottype": "Project Work", "xaxis": var.tex, "channel": self.settings.channel, "CoM": "13", "lumi": "41.5", "title": "", "yaxis": "Background Fractions (Classification)" } newoutpath = os.path.join(outdirpath, "classification") try: if not os.path.exists(newoutpath): os.makedirs(newoutpath) except OSError as e: if e.errno != errno.EEXIST: raise outfile = "{0}/{1}_{2}_frac_{3}_{4}".format( newoutpath, self.settings.channel, prefix, sample_set.name, bin_var) self.create_plot(histos, descriptions, "{0}.png".format(outfile)) self.create_normalized_plot(histos, descriptions, "{0}_norm.png".format(outfile)) descriptions = { "plottype": "Project Work", "xaxis": var.tex, "channel": self.settings.channel, "CoM": "13", "lumi": "41.5", "title": "", "yaxis": "Background Fractions (Classification)" } outfileprefix = "{0}/{1}_{2}_frac_{3}_{4}".format( newoutpath, self.settings.channel, prefix, "inclusive", bin_var) if inclusive: inclusive_histos = self.get_inclusive(var, fraction_histo_summary) self.create_normalized_plot(inclusive_histos, descriptions, "{0}_norm.png".format(outfileprefix)) self.create_plot(inclusive_histos, descriptions, "{0}.png".format(outfileprefix))
def make_distribution_plots(self, sample_sets, bin_var, prefix, outdirpath, inclusive=False, ylabel="NN Distribution"): fraction_histo_summary = {} var = Var(bin_var, self.settings.channel) for sample_set in sample_sets: histo = self.get_histo_for_distribution(sample_set, var) fraction_histo_summary[sample_set.name] = histo descriptions = { "plottype": "Project Work", "xaxis": var.tex, "channel": self.settings.channel, "CoM": "13", "lumi": "41.5", "title": "", "yaxis": "Background Fractions (Classification)" } newoutpath = os.path.join(outdirpath, "distribution") try: if not os.path.exists(newoutpath): os.makedirs(newoutpath) except OSError as e: if e.errno != errno.EEXIST: raise #outfile = "{0}/{1}_{2}_frac_{3}_{4}".format(newoutpath, self.settings.channel, prefix, sample_set.name, bin_var) #self.create_plot(histos, descriptions, "{0}.png".format(outfile)) #self.create_normalized_plot(histos, descriptions, "{0}_norm.png".format(outfile)) descriptions = { "plottype": "Project Work", "xaxis": var.tex, "channel": self.settings.channel, "CoM": "13", "lumi": "41.5", "title": "", "yaxis": "Normalized Event Count" } outfileprefix = "{0}/{1}_{2}_frac_{3}_{4}".format( newoutpath, self.settings.channel, prefix, "inclusive", bin_var) new_histos = {} for histname in fraction_histo_summary: new_histos[get_pretty_name( histname)] = fraction_histo_summary[histname] if inclusive: #inclusive_histos = self.get_inclusive(var, fraction_histo_summary) self.create_normalized_plot2(new_histos, descriptions, "{0}_norm.png".format(outfileprefix), applyFracColors=True, constrainLegend=False, legendWidthMultiplier=2) descriptions["yaxis"] = "Event Count" self.create_plot2(new_histos, descriptions, "{0}.png".format(outfileprefix), legend="outer", applyFracColors=True, constrainLegend=False, legendWidthMultiplier=2) merged_histos = self.merge_histos(new_histos) self.create_plot2(merged_histos, descriptions, "{0}_merge.png".format(outfileprefix), legend="inner", applyFracColors=True, constrainLegend=True, legendWidthMultiplier=3) descriptions["yaxis"] = "Normalized Event Count" norm_yield_histos = self.normalize_yields(merged_histos) self.create_plot2(norm_yield_histos, descriptions, "{0}_merge_norm.png".format(outfileprefix), legend="inner", applyFracColors=True, constrainLegend=True, legendWidthMultiplier=3) self.create_transparent_plot( norm_yield_histos, descriptions, "{0}_merge_norm_tr.png".format(outfileprefix), legend="inner", applyFracColors=True, constrainLegend=True, legendWidthMultiplier=3)
def makePlot(channel, variable, indir, era, dir, args, outdir="", syst=False): var = Var(variable) overlay = True plottype = args.type if plottype == "postfit": plottype = "postfit_sb" if "2016" in era: lumi = "35.9" if "2017" in era: lumi = "41.5" print "indir: {0}".format(indir) print "outdir: {0}".format(outdir) if indir and syst: root_datacard = "/".join( [indir, "2017_datacard_shapes_{0}.root".format(plottype)]) elif indir: root_datacard = "/".join([ indir, "htt_{0}.inputs-sm-Run{1}-{2}.root".format(channel, era, var.name) ]) else: root_datacard = "{0}/htt_{1}.inputs-sm-Run{2}-{3}.root".format( "_".join([era, "datacards"]), channel, era, var.name) file = R.TFile(root_datacard) for category in file.GetListOfKeys(): cat = category.GetName() interesting_ones = {} for h in [ "W", "VVT", "VVL", "VVJ", "TTT", "TTL", "TTJ", "ZTT", "ZL", "ZJ", "QCD", "jetFakes", "jetFakes_W", "jetFakes_TT", "jetFakes_QCD", "EMB", "data_obs", "ggH", "qqH" ]: if h == "data_obs": interesting_ones["data"] = copy.deepcopy( file.Get("{0}/{1}".format(cat, h))) else: interesting_ones[h] = copy.deepcopy( file.Get("{0}/{1}".format(cat, h))) plots = [ ("_def", [ "W", "VVT", "VVL", "VVJ", "TTT", "TTL", "TTJ", "ZTT", "ZL", "ZJ", "QCD", "data" ]), ("_def_EMB", [ "W", "VVL", "VVJ", "TTL", "TTJ", "EMB", "ZL", "ZJ", "QCD", "data" ]), ("_ff", ["VVT", "VVL", "TTT", "TTL", "ZTT", "ZL", "jetFakes", "data"]), ("_ff_split", [ "VVT", "VVL", "TTT", "TTL", "ZTT", "ZL", "jetFakes_W", "jetFakes_TT", "jetFakes_QCD", "data" ]), ("_ff_EMB_split", [ "VVL", "TTL", "ZL", "EMB", "jetFakes_W", "jetFakes_TT", "jetFakes_QCD", "data" ]), ("_ff_EMB", ["VVL", "TTL", "EMB", "ZL", "jetFakes", "data"]) ] print "indir: {0}".format(indir) print "outdir: {0}".format(outdir) for p in plots: histos = {} plot = True for h in p[1]: if type(interesting_ones[h]) == R.TObject: plot = False histos[h] = interesting_ones[h] if not outdir: outdir = "_".join([era, "plots/"]) if plot and overlay: textlines = collect(dir, args, plottype) pl.plot(histos, canvas="linear", signal=[], descriptions={ "plottype": "Project Work", "xaxis": var.tex, "channel": channel, "CoM": "13", "lumi": lumi }, outfile=outdir + "/" + cat + "_" + var.name + p[0] + ".png", era=era, overlay=textlines) pl.plot(histos, canvas="log", signal=[], descriptions={ "plottype": "Project Work", "xaxis": var.tex, "channel": channel, "CoM": "13", "lumi": lumi }, outfile=outdir + "/" + cat + "_" + var.name + p[0] + ".png", era=era, overlay=textlines) pl.plot(histos, canvas="semi", signal=[], descriptions={ "plottype": "Project Work", "xaxis": var.tex, "channel": channel, "CoM": "13", "lumi": lumi }, outfile=outdir + "/" + cat + "_" + var.name + p[0] + ".png", era=era, overlay=textlines) elif plot: pl.plot(histos, canvas="linear", signal=[], descriptions={ "plottype": "Project Work", "xaxis": var.tex, "channel": channel, "CoM": "13", "lumi": lumi }, outfile=outdir + "/" + cat + "_" + var.name + p[0] + ".png", era=era) pl.plot(histos, canvas="log", signal=[], descriptions={ "plottype": "Project Work", "xaxis": var.tex, "channel": channel, "CoM": "13", "lumi": lumi }, outfile=outdir + "/" + cat + "_" + var.name + p[0] + ".png", era=era) pl.plot(histos, canvas="semi", signal=[], descriptions={ "plottype": "Project Work", "xaxis": var.tex, "channel": channel, "CoM": "13", "lumi": lumi }, outfile=outdir + "/" + cat + "_" + var.name + p[0] + ".png", era=era) # if plot and overlay: # textlines = collect(dir, args, plottype) # pl.plot(histos, canvas="linear", signal = [], descriptions = {"plottype": "Project Work", "xaxis":var.tex, "channel":channel,"CoM": "13", "lumi":lumi }, outfile = outdir +"/"+ cat+"_"+var.name + p[0] +".png") # pl.plot(histos, canvas="log", signal = [], descriptions = {"plottype": "ProjectWork", "xaxis":var.tex, "channel":channel,"CoM": "13", "lumi":lumi }, outfile = outdir +"/"+ cat+"_"+var.name + p[0] +".png") # pl.plot(histos, canvas="semi", signal = [], descriptions = {"plottype": "ProjectWork", "xaxis":var.tex, "channel":channel,"CoM": "13", "lumi":lumi }, outfile = outdir +"/"+ cat+"_"+var.name + p[0] +".png") # elif plot: # pl.plot(histos, canvas="linear", signal = [], descriptions = {"plottype": "Project Work", "xaxis":var.tex, "channel":channel,"CoM": "13", "lumi":lumi }, outfile = outdir +"/"+ cat+"_"+var.name + p[0] +".png") # pl.plot(histos, canvas="log", signal = [], descriptions = {"plottype": "ProjectWork", "xaxis":var.tex, "channel":channel,"CoM": "13", "lumi":lumi }, outfile = outdir +"/"+ cat+"_"+var.name + p[0] +".png") # pl.plot(histos, canvas="semi", signal = [], descriptions = {"plottype": "ProjectWork", "xaxis":var.tex, "channel":channel,"CoM": "13", "lumi":lumi }, outfile = outdir +"/"+ cat+"_"+var.name + p[0] +".png") file.Close()