Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
def ComparisonPlot(datasetsMgr, json):
    Verbose("Creating MC plot")
        
    # Create the MC Plot with selected normalization ("normalizeToOne", "normalizeByCrossSection", "normalizeToLumi")
    legendDict = {}
    kwargs     = {}
    ylabel_    = json["ylabel"]
    cutBox_    = {"cutValue": json["cutValue"] , "fillColor": json["cutFillColour"],
                  "box": json["cutBox"]=="True", "line": json["cutLine"]=="True",
                  "greaterThan": json["cutGreaterThan"]=="True"}
    normToOne_ = json["normalizationToOne"]=="True"
    if normToOne_:
        ylabel_ = ylabel_.replace(json["ylabel"].split(" /")[0], "Arbitrary Units")

    # Get the reference histo and the list of histos to compare
    histoReference = getHisto(datasetsMgr, json['sample'], json['histograms'][0])
    histoCompares  = getHistos(datasetsMgr, json['sample'], json['histograms'])
    p = plots.ComparisonManyPlot(histoReference, histoCompares, saveFormats=[])
    
    # Set universal histo styles
    p.histoMgr.setHistoDrawStyleAll(json["drawStyle"])
    p.histoMgr.setHistoLegendStyleAll(json["legendStyle"])

    # Set individual styles
    for i in range(0, len(histoCompares)+1):
        hName = "h%s-%s" % (i, json["sample"])
        legendDict[hName] = styles.getCaloLegend(i)
        p.histoMgr.forHisto(hName, styles.getCaloStyle(i) )
        if 0:
            p.histoMgr.setHistoDrawStyle(hName, "L")
            p.histoMgr.setHistoLegendStyle(hName, "LP")
        if json["drawStyle"]=="HIST":
            p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetFillStyle(0))
            #p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetMarkerSize(0.0))

    # Set legend labels
    p.histoMgr.setHistoLegendLabelMany(legendDict)
    
    # Draw a customised plot
    saveName = os.path.join(json["saveDir"], json["title"])    

    # Create the customised plot
    plots.drawPlot(p, 
                   saveName,                  
                   xlabel            = json["xlabel"], 
                   ylabel            = ylabel_,
                   rebinX            = json["rebinX"],
                   stackMCHistograms = json["stackMCHistograms"]=="True", 
                   addCmsText        = json["addCmsText"]=="True",
                   cmsExtraText      = json["cmsExtraText"],
                   opts              = json["opts"],
                   opts2             = json["opts2"],
                   log               = json["logY"]=="True", 
                   moveLegend        = json["moveLegend"],
                   cutBox            = cutBox_,
                   ratio             = json["ratio"]=="True",
                   ratioInvert       = json["ratioInvert"]=="True",
                   ratioYlabel       = json["ratioYlabel"],
                   )
    
    # Remove legend?
    if json["removeLegend"] == "True":
        p.removeLegend()

    # Additional text
    histograms.addText(json["extraText"].get("x"), json["extraText"].get("y"), json["extraText"].get("text"), json["extraText"].get("size") )

    # Save in all formats chosen by user
    saveFormats = json["saveFormats"]
    for i, ext in enumerate(saveFormats):
        Print("%s" % saveName + ext, i==0)
    p.saveAs(saveName, formats=saveFormats)
    return