def PlotEfficiency(datasetsMgr, histoList, signal, PU): # Get Histogram name and its kwargs taus = "SingleTau" saveName = "Efficiency_%s_%s" % (taus, signal) kwargs = GetHistoKwargs(saveName, opts) hList = [] legDict = {} # For-loop: All tau algorithms count = -1 for i, hName in enumerate(histoList, 0): algo = hName.split("_")[0] if algo == "DiTau": if "TT_" in signal or "GluGlu" in signal: pass else: return taus = "DiTau" algo = hName.split("_")[-1] count += 1 aux.PrintFlushed("Plotting efficiency (%s-%s-%s)" % (algo, taus, signal), False) #count==0) h = datasetsMgr.getDataset(signal).getDatasetRootHisto( hName).getHistogram() h.SetName(hName) legDict[hName] = algo hList.append(h) # Create the rate histograms p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) # Set legend labels for h in p.histoMgr.getHistos(): hName = h.getName() algo = h.getName().split("_")[0] if algo == "DiTau": algo = hName.split("_")[-1] p.histoMgr.forHisto(hName, styles.getTauAlgoStyle(algo)) p.histoMgr.setHistoDrawStyle(hName, "HIST") p.histoMgr.setHistoLegendStyle(hName, "L") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legDict) # Draw and save the plot saveName = "Efficiency_%s_%s" % (taus, signal) plots.drawPlot(p, saveName, **kwargs) # Add additional canvas text histograms.addPileupText("PU=%s" % (PU)) # histograms.addText(0.75, 0.88, taus, 17) histograms.addText(0.60, 0.88, plots._legendLabels[signal], 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) #print return
def PlotRate(datasetsMgr, histoList, bkg, PU): # Get Histogram name and its kwargs taus = "SingleTau" saveName = "Rate_%s_PU%s" % (taus, PU) kwargs = GetHistoKwargs(saveName, opts) hList = [] legDict = {} algos = getAlgos() # For-loop: All tau algorithms for i, hName in enumerate(histoList, 0): algo = hName.split("_")[0] #if algo == "DiTau": # taus = "DiTau" # algo = hName.split("_")[-1] if "ditau" in hName.lower(): return #algo = hName.split("_")[-1] #tau = hName.split("_")[1] #if tau == "DiTau": # taus = "DiTau" # algo = hName.split("_")[-1] aux.PrintFlushed("Plotting rate (%s-%s)" % (algo, taus), False) h = datasetsMgr.getDataset(bkg).getDatasetRootHisto( hName).getHistogram() h.SetName(hName) legDict[hName] = algos[i] #algo hList.append(h) # Create the rate histograms p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) # Set legend labels for i, h in enumerate(p.histoMgr.getHistos(), 0): hName = h.getName() algo = h.getName().split("_")[0] p.histoMgr.forHisto(hName, styles.getTauAlgoStyle(algo)) p.histoMgr.setHistoDrawStyle(hName, "HIST") p.histoMgr.setHistoLegendStyle(hName, "L") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legDict) # Draw and save the plot saveName = "Rate_%s_PU%s" % (taus, PU) plots.drawPlot(p, saveName, **kwargs) # Add additional canvas text histograms.addPileupText("PU=%s" % (PU)) histograms.addText(0.70, 0.88, taus, 17) #histograms.addText(0.75, 0.88, taus, 17) #histograms.addText(0.60, 0.78, plots._legendLabels[bkg], 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) #print return
def PlotTurnOns(datasetsMgr, histoList, signal, PU, saveName=None): # Get Histogram name and its kwargs myRegex = "(?:TurnOn)(.*)" m = re.search(myRegex, histoList[0]) threshold = m.group(1) if saveName==None: #saveName = "TurnOns_%sGeV_%s" % (threshold, signal) saveName = "TurnOns_%s_%s" % (threshold, signal) kwargs = GetHistoKwargs(saveName, opts) hList = [] legDict = {} algos = getAlgos() if "_all" in saveName: algos = ["Inclusive", "1-prong", "3-prong", "#geq 1 #pi^{0}'s", "0 #pi^{0}'s"] # For-loop: All tau algorithms for l, hName in enumerate(histoList, 0): algo = hName.split("_")[0] msg = "Turn-on for \"%s\" algorithm (%s)" % (algo, signal) aux.PrintFlushed(msg, False) #aux.Print(msg, True) h = datasetsMgr.getDataset(signal).getDatasetRootHisto(hName).getHistogram() h.SetName(hName) legDict[hName] = algos[l] hList.append(h) # Create the rate histograms p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) # Set legend labels for i, h in enumerate(p.histoMgr.getHistos(), 0): hName = h.getName() algo = h.getName().split("_")[0] if algo == "DiTau": algo = hName.split("_")[-1] if "_all" in saveName: p.histoMgr.forHisto(hName, styles.getCaloStyle(i)) else: p.histoMgr.forHisto(hName, styles.getTauAlgoStyle(algo)) p.histoMgr.setHistoDrawStyle(hName, "AP") p.histoMgr.setHistoLegendStyle(hName, "P") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legDict) # Draw and save the plot saveName = saveName.replace("TurnOns_", "") plots.drawPlot(p, saveName, **kwargs) # Add additional canvas text histograms.addPileupText("PU=%s" % (PU) ) histograms.addText(0.22, 0.86, plots._legendLabels[signal], 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) return
def PlotTurnOns(datasetsMgr, histoList, signal, PU): # Get Histogram name and its kwargs myRegex = "(?:TurnOn)(.*)" m = re.search(myRegex, histoList[0]) threshold = m.group(1) saveName = "TurnOns_%sGeV_%s" % (threshold, signal) kwargs = GetHistoKwargs(saveName, opts) hList = [] legDict = {} # For-loop: All tau algorithms for l, hName in enumerate(histoList, 0): algo = hName.split("_")[0] aux.PrintFlushed("Turn-on for \"%s\" algorithm (%s)" % (algo, signal), False) #l==0) h = datasetsMgr.getDataset(signal).getDatasetRootHisto( hName).getHistogram() h.SetName(hName) legDict[hName] = algo hList.append(h) # Create the rate histograms p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) # Set legend labels for h in p.histoMgr.getHistos(): hName = h.getName() algo = h.getName().split("_")[0] if algo == "DiTau": algo = hName.split("_")[-1] p.histoMgr.forHisto(hName, styles.getTauAlgoStyle(algo)) p.histoMgr.setHistoDrawStyle(hName, "AP") p.histoMgr.setHistoLegendStyle(hName, "LP") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legDict) # Draw and save the plot plots.drawPlot(p, saveName, **kwargs) # Add additional canvas text histograms.addPileupText("PU=%s" % (PU)) # histograms.addText(0.75, 0.88, taus, 17) histograms.addText(0.60, 0.88 - 0.50, plots._legendLabels[signal], 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) #print return
def PlotRate(datasetsMgr, histoList, bkg, PU, taus): # Get Histogram name and its kwargs saveName = "Rate_%s_PU%s" % ( taus, PU ) # "Rate_" here incuded to apply customisations with kwargs. Drop later kwargs = GetHistoKwargs(saveName, opts) hList = [] legDict = {} algos = getAlgos() # For-loop: All tau algorithms for i, hName in enumerate(histoList, 0): algo = hName.split("_")[0] aux.PrintFlushed("Plotting rate (%s-%s)" % (algo, taus), False) h = datasetsMgr.getDataset(bkg).getDatasetRootHisto( hName).getHistogram() h.SetName(hName) legDict[hName] = algos[i] hList.append(h) # Create the rate histograms p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) # Set legend labels for i, h in enumerate(p.histoMgr.getHistos(), 0): hName = h.getName() algo = h.getName().split("_")[0] p.histoMgr.forHisto(hName, styles.getTauAlgoStyle(algo)) p.histoMgr.setHistoDrawStyle(hName, "HIST") p.histoMgr.setHistoLegendStyle(hName, "L") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legDict) # Draw and save the plot saveName = saveName.replace("Rate_", "") #drop "Rate_" only AFTER getting kwargs plots.drawPlot(p, saveName, **kwargs) # Add additional canvas text histograms.addPileupText("PU=%s" % (PU)) histograms.addText(0.66, 0.86, taus, 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) #print return
def PlotRateVsEff(datasetsMgr, effHistoList, rateHistoList, signal, bkg, PU): # Definitions tgraphs = [] legendDict = {} aux.PrintFlushed("Plotting ROC (%s-%s)" % (bkg, signal), False) #count==0) # Get Histogram name and its kwargs if "ditau" in effHistoList[0].lower(): if "TT_" in signal or "GluGlu" in signal: pass else: return saveName = "RateVsEff_DiTau_%s_PU%s" % (signal.split("_")[0], PU) else: saveName = "RateVsEff_SingleTau_%s_PU%s" % (signal.split("_")[0], PU) kwargs_ = GetHistoKwargs(saveName, opts) for i in range(0, len(effHistoList)): if (i == 0): g0 = convert2RateVsEffTGraph(datasetsMgr, effHistoList[i], rateHistoList[i], signal, bkg) g0.SetName("Calo") elif (i == 1): g1 = convert2RateVsEffTGraph(datasetsMgr, effHistoList[i], rateHistoList[i], signal, bkg) g1.SetName("Tk") elif (i == 2): g2 = convert2RateVsEffTGraph(datasetsMgr, effHistoList[i], rateHistoList[i], signal, bkg) g2.SetName("VtxIso") elif (i == 3): g3 = convert2RateVsEffTGraph(datasetsMgr, effHistoList[i], rateHistoList[i], signal, bkg) g3.SetName("RelIso") elif (i == 4): g4 = convert2RateVsEffTGraph(datasetsMgr, effHistoList[i], rateHistoList[i], signal, bkg) g4.SetName("Iso") # Create the Rate Vs Efficiency TGraphs p = plots.ComparisonManyPlot(g0, [g1, g2, g3, g4], saveFormats=[]) # Set individual styles for index, h in enumerate(p.histoMgr.getHistos()): hName = h.getName() legendDict[hName] = styles.getCaloLegend(index) p.histoMgr.forHisto(hName, styles.getCaloStyle(index)) p.histoMgr.setHistoDrawStyle(h.getName(), "LX") # "X" = Do not draw error bars p.histoMgr.setHistoLegendStyle(h.getName(), "LP") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legendDict) # Draw and save the plot plots.drawPlot(p, saveName, **kwargs_) #the "**" unpacks the kwargs_ dictionary # Draw Error bands for i, g in enumerate([g0, g1, g2, g3, g4]): shapes, min, max = DrawErrorBand(g) for shape in shapes: shape.SetFillColor( p.histoMgr.getHistos()[i].getRootHisto().GetFillColor()) shape.SetFillStyle(3002) shape.Draw("f same") ROOT.gPad.RedrawAxis() histograms.addPileupText("PU=%s" % (PU)) histograms.addText(0.60, 0.38, plots._legendLabels[signal], 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) return
def PlotHistos(datasetsMgr, histoList, signal, PU, saveName=None): # Get Histogram name and its kwargs kwargs = GetHistoKwargs(saveName, opts) hList = [] legDict = {} algos = getAlgos() if "_all" in saveName: algos = ["Inclusive", "1-prong", "3-prong", "#geq 1 #pi^{0}'s", "0 #pi^{0}'s"] if "_cif" in saveName: #algos = ["Inclusive", "Central", "Intermediate", "Forward"] algos = ["Inclusive", "|#eta| < 0.8 (C)", "0.8 < |#eta| < 1.6 (I)", "|#eta| > 1.6 (F)"] # For-loop: All tau algorithms for l, hName in enumerate(histoList, 0): algo = hName.split("_")[0] msg = "Resolution for \"%s\" algorithm (%s)" % (algo, signal) aux.PrintFlushed(msg, False) h = datasetsMgr.getDataset(signal).getDatasetRootHisto(hName).getHistogram() h.SetName(hName) legDict[hName] = algos[l] hList.append(h) # Create the rate histograms if opts.normalizeToOne: p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) norm = True for hist in p.histoMgr.getHistos(): if hist.getRootHisto().Integral() == 0: norm = False break if (norm): p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Scale(1.0/h.getRootHisto().Integral()) ) else: aux.Print("Cannot normalise empty histo \"%s\" for dataset \"%s\"" % (hName, signal), True) else: p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) # Set legend labels for i, h in enumerate(p.histoMgr.getHistos(), 0): hName = h.getName() p.histoMgr.forHisto(hName, styles.getCaloStyle(i)) #p.histoMgr.setHistoDrawStyle(hName, "HIST") #p.histoMgr.setHistoLegendStyle(hName, "L") p.histoMgr.setHistoDrawStyle(hName, "AP") p.histoMgr.setHistoLegendStyle(hName, "P") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legDict) # Draw and save the plot plots.drawPlot(p, saveName, **kwargs) # Add additional canvas text histograms.addPileupText("PU=%s" % (PU) ) histograms.addText(0.22, 0.86, plots._legendLabels[signal], 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) return
def PlotEfficiency(datasetsMgr, histoList, signal, PU, taus): # Get Histogram name and its kwargs saveName = "Efficiency_%s_%s" % (taus, signal) #saveName = "Efficiency_%s_PU%s" % (taus, PU) # "Rate_" here incuded to apply customisations with kwargs. Drop later kwargs = GetHistoKwargs(saveName, opts) hList = [] legDict = {} algos = getAlgos() # For-loop: All tau algorithms count = -1 for i, hName in enumerate(histoList, 0): algo = hName.split("_")[0] if algo == "DiTau": if "TT_" in signal or "GluGlu" in signal: pass else: return algo = hName.split("_")[-1] count += 1 aux.PrintFlushed("Plotting efficiency (%s-%s-%s)" % (algo, taus, signal), False) #count==0) h = datasetsMgr.getDataset(signal).getDatasetRootHisto( hName).getHistogram() h.SetName(hName) legDict[hName] = algos[i] hList.append(h) # Create the rate histograms p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[]) # Set legend labels for h in p.histoMgr.getHistos(): hName = h.getName() algo = h.getName().split("_")[0] if algo == "DiTau": algo = hName.split("_")[-1] p.histoMgr.forHisto(hName, styles.getTauAlgoStyle(algo)) p.histoMgr.setHistoDrawStyle(hName, "HIST") p.histoMgr.setHistoLegendStyle(hName, "L") # Set legend labels p.histoMgr.setHistoLegendLabelMany(legDict) # Draw and save the plot saveName = saveName.replace( "Efficiency_", "") # drop "Efficiency_" only AFTER getting histo kwargs #saveName = "%s_%s_%s" % (taus, algo, signal) # drop "Efficiency_" only AFTER getting histo kwargs plots.drawPlot(p, saveName, **kwargs) # Add additional canvas text histograms.addPileupText("PU=%s" % (PU)) histograms.addText(0.66, 0.86, plots._legendLabels[signal], 17) # Save the plots in custom list of saveFormats aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True) #print return