예제 #1
0
def DoPlots(datasetsMgr, histoName):
    analysisType = "Inverted"

    # Get the Inclusive (Data, EWK)
    p1 = plots.ComparisonPlot(*getHistos(datasetsMgr, histoName, analysisType))
    p1.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    # Get histos
    inverted_Data = p1.histoMgr.getHisto("Data").getRootHisto().Clone(
        "Inverted-Data")
    inverted_EWK = p1.histoMgr.getHisto("EWK").getRootHisto().Clone(
        "Inverted-EWK")
    inverted_QCD = p1.histoMgr.getHisto("Data").getRootHisto().Clone(
        "Inverted-QCD")

    # Normalize histograms to unit area
    inverted_Data.Scale(1.0 / inverted_QCD.Integral())
    inverted_QCD.Scale(1.0 / inverted_QCD.Integral())
    inverted_EWK.Scale(1.0 / inverted_EWK.Integral())

    # Create the final plot object (Cannot subtract EWK from Data since the trigger in the MC samples is NOT prescaled. In data it is)
    p = plots.ComparisonManyPlot(inverted_Data, [inverted_EWK], saveFormats=[])
    #p = plots.PlotBase([inverted_Data], saveFormats=[])

    # Apply styles
    p.histoMgr.forHisto("Inverted-Data", styles.getDataStyle())
    #p.histoMgr.forHisto("Inverted-QCD"  , styles.getInvertedLineStyle() )
    p.histoMgr.forHisto("Inverted-EWK", styles.getAltEWKStyle())

    # Set draw style
    p.histoMgr.setHistoDrawStyle("Inverted-Data", "AP")
    #p.histoMgr.setHistoDrawStyle("Inverted-QCD" , "HIST")
    p.histoMgr.setHistoDrawStyle("Inverted-EWK", "AP")

    # Set legend style
    p.histoMgr.setHistoLegendStyle("Inverted-Data", "P")
    #p.histoMgr.setHistoLegendStyle("Inverted-QCD" , "L")
    p.histoMgr.setHistoLegendStyle("Inverted-EWK", "P")

    # Set legend labels
    p.histoMgr.setHistoLegendLabelMany({
        "Inverted-Data": "Data",
        "Inverted-EWK": "EWK",
        #"Inverted-QCD" : "QCD=Data-EWK",
    })

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    #_opts   = {"ymin": 1e-4, "ymaxfactor": 2.0}
    _opts = {"ymin": 1e-4, "ymax": 1e-1}
    _xlabel = None
    _units = "GeV/c^{2}"
    _xlabel = "m_{jjb} (%s)" % _units
    _ylabel = "Arbitrary Units / %0.0f %s " % (inverted_QCD.GetBinWidth(0),
                                               _units)
    _cutBox = {
        "cutValue": 173.21,
        "fillColor": 16,
        "box": False,
        "line": True,
        "greaterThan": True
    }
    _opts["xmax"] = 1500.0

    # Complains (SysError in <TFile::TFile>: file ...)
    if 0:
        plots.drawPlot(p,
                       histoName,
                       xlabel=_xlabel,
                       ylabel=_ylabel,
                       log=True,
                       rebinX=_rebinX,
                       cmsExtraText="Preliminary",
                       createLegend={
                           "x1": 0.62,
                           "y1": 0.78,
                           "x2": 0.92,
                           "y2": 0.92
                       },
                       opts=_opts)

    if 1:
        plots.drawPlot(
            p,
            histoName,
            xlabel=_xlabel,
            ylabel=_ylabel,
            log=True,
            rebinX=_rebinX,
            cmsExtraText="Preliminary",
            createLegend={
                "x1": 0.62,
                "y1": 0.78,
                "x2": 0.92,
                "y2": 0.92
            },
            opts=_opts,
            opts2={
                "ymin": 0.0,
                "ymax": 2.0
            },
            ratio=True,
            ratioInvert=False,
            ratioYlabel="Ratio",
            cutBox=_cutBox,
        )
    # Save to ROOT file
    inverted_QCD.SaveAs("Inverted_QCD.root")

    # Save plot in all formats
    SavePlot(p, histoName, os.path.join(opts.saveDir, "Test", opts.optMode))
    return
def DoPlots(datasetsMgr, histoName, analysisType="Inverted", bType="GenuineB"):

    # Sanity checks
    IsBaselineOrInverted(analysisType)
    IsGenuineOrFake(bType)

    # Definitions
    defaultFolder = ""
    if "FakeBPurity" in histoName:
        defaultFolder = "FakeBPurity"
    elif "ForFakeBMeasurement" + histoName:
        defaultFolder = "ForFakeBMeasurement"
    else:
        raise Exception("This should never happen")

    # Define folders for inclusive/genuine/fakes
    inclusiveFolder = defaultFolder
    genuineFolder = defaultFolder + "EWKGenuineB"
    fakeFolder = defaultFolder + "EWKFakeB"
    inclusiveHisto = histoName.replace(defaultFolder, inclusiveFolder)
    genuineHisto = histoName.replace(defaultFolder, genuineFolder)
    fakeHisto = histoName.replace(defaultFolder, fakeFolder)

    # Get the inclusive histograms
    p0 = plots.DataMCPlot(datasetsMgr, inclusiveHisto)
    Data = p0.histoMgr.getHisto("Data").getRootHisto().Clone("Data")

    # Get the genuine-b histograms
    p1 = plots.DataMCPlot(datasetsMgr, genuineHisto)
    EWKGenuineB = p1.histoMgr.getHisto("EWK").getRootHisto().Clone(
        "EWKGenuineB")
    QCDGenuineB = p1.histoMgr.getHisto("QCD").getRootHisto().Clone(
        "QCDGenuineB")

    # Get the fake-b histograms
    p2 = plots.DataMCPlot(datasetsMgr, fakeHisto)
    EWKFakeB = p2.histoMgr.getHisto("EWK").getRootHisto().Clone("EWKFakeB")
    QCDFakeB = p2.histoMgr.getHisto("QCD").getRootHisto().Clone("QCDFakeB")

    # Normalize histograms to unit area
    if 0:
        Data.Scale(1.0 / Data.Integral())
        EWKGenuineB.Scale(1.0 / EWKGenuineB.Integral())
        EWKFakeB.Scale(1.0 / EWKFakeB.Integral())
        QCDGenuineB.Scale(1.0 / QCDGenuineB.Integral())
        QCDFakeB.Scale(1.0 / EWKFakeB.Integral())

    # Create the final plot object
    comparisonList = [EWKGenuineB, QCDGenuineB, EWKFakeB, QCDFakeB]
    p = plots.ComparisonManyPlot(Data, comparisonList, saveFormats=[])
    p.setLuminosity(GetLumi(datasetsMgr))

    # Apply styles
    p.histoMgr.forHisto("Data", styles.getDataStyle())
    p.histoMgr.forHisto("EWKGenuineB",
                        styles.getAltEWKStyle())  #GenuineBStyle()
    p.histoMgr.forHisto("QCDGenuineB", styles.getQCDStyle())
    p.histoMgr.forHisto("EWKFakeB", styles.getGenuineBStyle())
    p.histoMgr.forHisto("QCDFakeB", styles.getFakeBStyle())

    # Set draw style
    p.histoMgr.setHistoDrawStyle("Data", "AP")
    p.histoMgr.setHistoDrawStyle("EWKGenuineB", "AP")
    p.histoMgr.setHistoDrawStyle("QCDGenuineB", "AP")
    p.histoMgr.setHistoDrawStyle("EWKFakeB", "AP")
    p.histoMgr.setHistoDrawStyle("QCDFakeB", "AP")

    # Set legend style
    p.histoMgr.setHistoLegendStyle("Data", "P")
    p.histoMgr.setHistoLegendStyle("EWKGenuineB", "P")
    p.histoMgr.setHistoLegendStyle("QCDGenuineB", "P")
    p.histoMgr.setHistoLegendStyle("EWKFakeB", "P")
    p.histoMgr.setHistoLegendStyle("QCDFakeB", "P")
    # p.histoMgr.setHistoLegendStyleAll("LP")

    # Set legend labels
    p.histoMgr.setHistoLegendLabelMany({
        "Data": "Data",
        "EWKGenuineB": "EWK-GenuineB",
        "QCDGenuineB": "QCD-GenuineB",
        "EWKFakeB": "EWK-FakeB",
        "QCDFakeB": "QCD-FakeB",
        #"Data"       : "Data (%s)"         % (analysisType),
        #"EWKGenuineB": "EWK-GenuineB (%s)" % (analysisType),
        #"QCDGenuineB": "QCD-GenuineB (%s)" % (analysisType),
        #"EWKFakeB"   : "EWK-FakeB (%s)"    % (analysisType),
        #"QCDFakeB"   : "QCD-FakeB (%s)"    % (analysisType),
    })

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _opts = {"ymin": 1e0, "ymaxfactor": 2.0}
    _format = "%0.0f"
    _xlabel = None

    if "dijetm" in histoName.lower():
        _rebinX = 2
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jj} (%s)" % (_units)
        _cutBox = {
            "cutValue": 80.399,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 400.0
    if "trijetm" in histoName.lower():
        _rebinX = 5
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {
            "cutValue": 173.21,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 1500.0
    if "pt" in histoName.lower():
        _rebinX = 2
        _format = "%0.0f GeV/c"
    if "eta" in histoName.lower():
        _format = "%0.2f"
        _cutBox = {
            "cutValue": 0.,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmin"] = -3.0
        _opts["xmax"] = +3.0
    if "deltaeta" in histoName.lower():
        _format = "%0.2f"
        _opts["xmin"] = 0.0
        _opts["xmax"] = 6.0
    if "bdisc" in histoName.lower():
        _format = "%0.2f"
    if "tetrajetm" in histoName.lower():
        _rebinX = 10
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjjb} (%s)" % (_units)
        _opts["xmax"] = 3500.0
    if "ancestry" in histoName.lower():
        _rebinX = 1
        _units = ""
        _format = "%0.0f " + _units
        _opts["xmax"] = 32.0
    plots.drawPlot(
        p,
        histoName,
        xlabel=_xlabel,
        ylabel="Arbitrary Units / %s" % (_format),
        log=True,
        rebinX=_rebinX,
        cmsExtraText="Preliminary",
        createLegend={
            "x1": 0.62,
            "y1": 0.72,
            "x2": 0.92,
            "y2": 0.92
        },
        opts=_opts,
        opts2={
            "ymin": 0.0,
            "ymax": 1.5
        },  #{"ymin": 0.6, "ymax": 1.4},
        ratio=True,
        ratioInvert=False,
        ratioYlabel="Ratio",
        cutBox=_cutBox,
    )
    # Save plot in all formats
    SavePlot(p, histoName,
             os.path.join(opts.saveDir, "GenuineVsFake", opts.optMode))
    return
예제 #3
0
def PlotTemplates(datasetsMgr, histoName):
    Verbose("Plotting EWK Vs QCD unity-normalised histograms")

    # FIXME - First pseudo-multicrab had the Fake/Genuine boolean REVERSED
    # FIXME - First pseudo-multicrab had the Fake/Genuine boolean REVERSED
    # FIXME - First pseudo-multicrab had the Fake/Genuine boolean REVERSED
    # FIXME - First pseudo-multicrab had the Fake/Genuine boolean REVERSED
    defaultFolder = "ForFakeBMeasurement"
    genuineBFolder = "ForFakeBMeasurementEWKFakeB"
    fakeBFolder = "ForFakeBMeasurementEWKGenuineB"

    # Create comparison plot
    p1 = plots.ComparisonPlot(
        getHisto(datasetsMgr, "Data", "%s" % histoName, "Baseline"),
        getHisto(datasetsMgr, "EWK",
                 "%s" % histoName.replace(defaultFolder, genuineBFolder),
                 "Baseline"))
    p1.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    p2 = plots.ComparisonPlot(
        getHisto(datasetsMgr, "Data", "%s" % histoName, "Inverted"),
        getHisto(datasetsMgr, "EWK",
                 "%s" % histoName.replace(defaultFolder, genuineBFolder),
                 "Inverted"))
    p2.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    p3 = plots.ComparisonPlot(
        getHisto(datasetsMgr, "Data", "%s" % histoName, "Baseline"),
        getHisto(datasetsMgr, "EWK",
                 "%s" % histoName.replace(defaultFolder, fakeBFolder),
                 "Baseline"))
    p3.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    p4 = plots.ComparisonPlot(
        getHisto(datasetsMgr, "Data", "%s" % histoName, "Inverted"),
        getHisto(datasetsMgr, "EWK",
                 "%s" % histoName.replace(defaultFolder, fakeBFolder),
                 "Inverted"))
    p4.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    # Get EWK histos
    EWKGenuineB_baseline = p1.histoMgr.getHisto(
        "Baseline-EWK").getRootHisto().Clone("Baseline-EWKGenuineB")
    EWKGenuineB_inverted = p2.histoMgr.getHisto(
        "Inverted-EWK").getRootHisto().Clone("Inverted-EWKGenuineB")
    EWKFakeB_baseline = p3.histoMgr.getHisto(
        "Baseline-EWK").getRootHisto().Clone("Baseline-EWKFakeB")
    EWKFakeB_inverted = p4.histoMgr.getHisto(
        "Inverted-EWK").getRootHisto().Clone("Inverted-EWKFakeB")

    # Data histos
    Data_baseline = p1.histoMgr.getHisto("Baseline-Data").getRootHisto().Clone(
        "Baseline-Data")
    Data_inverted = p2.histoMgr.getHisto("Inverted-Data").getRootHisto().Clone(
        "Inverted-Data")

    # Create FakeB (Data-EWK_GenuineB) histos
    FakeB_baseline = p1.histoMgr.getHisto(
        "Baseline-Data").getRootHisto().Clone("Baseline-FakeB")
    FakeB_inverted = p2.histoMgr.getHisto(
        "Inverted-Data").getRootHisto().Clone("Inverted-FakeB")
    FakeB_baseline.Add(EWKGenuineB_baseline, -1)
    FakeB_inverted.Add(EWKGenuineB_inverted, -1)

    # Normalize histograms to unit area
    if 1:
        Data_baseline.Scale(1.0 / Data_baseline.Integral())
        Data_inverted.Scale(1.0 / Data_inverted.Integral())
        EWKGenuineB_baseline.Scale(1.0 / EWKGenuineB_baseline.Integral())
        EWKGenuineB_inverted.Scale(1.0 / EWKGenuineB_inverted.Integral())
        EWKFakeB_baseline.Scale(1.0 / EWKFakeB_baseline.Integral())
        EWKFakeB_inverted.Scale(1.0 / EWKFakeB_inverted.Integral())
        FakeB_baseline.Scale(1.0 / FakeB_baseline.Integral())
        FakeB_inverted.Scale(1.0 / FakeB_inverted.Integral())

    # Create the final plot object
    compareHistos = [EWKGenuineB_baseline]
    # compareHistos = [EWKGenuineB_baseline, EWKGenuineB_inverted, EWKFakeB_inverted, Data_inverted]
    # compareHistos = [EWKGenuineB_inverted, EWKFakeB_inverted, Data_inverted]
    # compareHistos = [EWKGenuineB_baseline, EWKFakeB_baseline, EWKGenuineB_inverted, EWKFakeB_inverted]
    # compareHistos = [FakeB_baseline, EWKGenuineB_baseline, EWKFakeB_baseline, EWKGenuineB_inverted, EWKFakeB_inverted]
    p = plots.ComparisonManyPlot(FakeB_inverted, compareHistos, saveFormats=[])
    p.setLuminosity(GetLumi(datasetsMgr))

    # Apply styles
    p.histoMgr.forHisto("Inverted-FakeB", styles.getInvertedLineStyle())
    p.histoMgr.forHisto("Baseline-EWKGenuineB", styles.getBaselineLineStyle())
    if 0:
        p.histoMgr.forHisto("Baseline-FakeB", styles.getInvertedLineStyle())
        p.histoMgr.forHisto("Baseline-EWKFakeB", styles.getFakeBStyle())
        p.histoMgr.forHisto("Inverted-EWKGenuineB", styles.getGenuineBStyle())
        p.histoMgr.forHisto("Inverted-EWKFakeB", styles.getFakeBLineStyle())
        p.histoMgr.forHisto("Inverted-Data", styles.getDataStyle())

    # Set draw style
    p.histoMgr.setHistoDrawStyle("Inverted-FakeB", "HIST")
    p.histoMgr.setHistoDrawStyle("Baseline-EWKGenuineB", "HIST")
    if 0:
        p.histoMgr.setHistoDrawStyle("Baseline-FakeB", "AP")
        p.histoMgr.setHistoDrawStyle("Baseline-EWKFakeB", "HIST")
        p.histoMgr.setHistoDrawStyle("Inverted-EWKGenuineB", "AP")
        p.histoMgr.setHistoDrawStyle("Inverted-EWKFakeB", "HIST")
        p.histoMgr.setHistoDrawStyle("Inverted-Data", "AP")

    # Set legend style
    p.histoMgr.setHistoLegendStyle("Inverted-FakeB", "L")
    p.histoMgr.setHistoLegendStyle("Baseline-EWKGenuineB", "L")
    if 0:
        p.histoMgr.setHistoLegendStyle("Baseline-FakeB", "P")
        p.histoMgr.setHistoLegendStyle("Baseline-EWKFakeB", "FL")
        p.histoMgr.setHistoLegendStyle("Inverted-EWKGenuineB", "P")
        p.histoMgr.setHistoLegendStyle("Inverted-EWKFakeB", "L")
        p.histoMgr.setHistoLegendStyle("Inverted-Data", "LP")

    # Set legend labels
    p.histoMgr.setHistoLegendLabelMany({
        "Inverted-FakeB":
        "FakeB (Inverted)",  # (I)",
        #"Inverted-Data"       : "Data (I)",
        "Baseline-EWKGenuineB":
        "EWK (Baseline)",  #-GenuineB (B)",
        #"Baseline-FakeB"      : "FakeB",
        #"Baseline-EWKFakeB"   : "EWK-FakeB (B)",
        #"Inverted-EWKGenuineB": "EWK-GenuineB (I)",
        #"Inverted-EWKFakeB"   : "EWK-FakeB (I)",
    })

    # Append analysisType to histogram name
    saveName = histoName

    # Draw the histograms #alex
    plots.drawPlot(p, saveName,
                   **GetHistoKwargs(histoName))  #the "**" unpacks the kwargs_

    # Add text
    text = opts.optMode.replace("OptChiSqrCutValue", "#chi^{2} #leq ")
    histograms.addText(0.21, 0.85, text)

    # Save plot in all formats
    saveDir = os.path.join(opts.saveDir, "Test", opts.optMode)
    SavePlot(p, saveName, saveDir, saveFormats=[".png"])
    return
예제 #4
0
def DataEwkQcd(datasetsMgr, histoName, analysisType):
    '''
    Create plots with "Data", "QCD=Data-EWK", and "EWK" on the same canvas
    Mostly for sanity checks and visualisation purposes
    '''
    Verbose(
        "Plotting histogram %s for Data, EWK, QCD for %s" %
        (histoName, analysisType), True)

    # Sanity check
    IsBaselineOrInverted(analysisType)

    # Define histogram names (full path)
    h1 = "topSelection_Baseline/%s" % (histoName)
    h2 = "topSelection_Inverted/%s" % (histoName)

    # Create plot object for Data
    p1 = plots.ComparisonPlot(*getHistos(datasetsMgr, "Data", h1, h2))
    p1.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())
    # Create plot object for EWK
    p2 = plots.ComparisonPlot(*getHistos(datasetsMgr, "EWK", h1, h2))
    p2.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    # Get Data and EWK histos
    Data = p1.histoMgr.getHisto(analysisType +
                                "-Data").getRootHisto().Clone(analysisType +
                                                              "-Data")
    EWK = p2.histoMgr.getHisto(analysisType +
                               "-EWK").getRootHisto().Clone(analysisType +
                                                            "-EWK")

    # Create QCD histo: QCD = Data-EWK
    QCD = p1.histoMgr.getHisto(analysisType +
                               "-Data").getRootHisto().Clone(analysisType +
                                                             "-QCD")
    QCD.Add(EWK, -1)

    # Create the final plot object. The Data is treated as the reference histo.
    # All other histograms are compared with respect to that.
    p = plots.ComparisonManyPlot(Data, [QCD, EWK], saveFormats=[])
    p.setLuminosity(GetLumi(datasetsMgr))

    # Apply histo styles
    p.histoMgr.forHisto(analysisType + "-Data", styles.getDataStyle())
    p.histoMgr.forHisto(analysisType + "-QCD", styles.getQCDLineStyle())
    p.histoMgr.forHisto(analysisType + "-EWK", styles.getAltEWKStyle())

    # Set draw style
    p.histoMgr.setHistoDrawStyle(analysisType + "-Data", "P")
    p.histoMgr.setHistoLegendStyle(analysisType + "-Data", "P")
    p.histoMgr.setHistoDrawStyle(analysisType + "-QCD", "LP")
    p.histoMgr.setHistoLegendStyle(analysisType + "-QCD", "LP")
    p.histoMgr.setHistoDrawStyle(analysisType + "-EWK", "HIST")
    p.histoMgr.setHistoLegendStyle(analysisType + "-EWK", "LFP")
    # p.histoMgr.setHistoLegendStyleAll("LP")

    # Set legend labels
    p.histoMgr.setHistoLegendLabelMany({
        analysisType + "-Data": "Data",
        analysisType + "-QCD": "QCD",  #=Data-EWK",
        analysisType + "-EWK": "EWK",
        # analysisType + "-Data": "%s (Data)" % (analysisType),
        # analysisType + "-QCD" : "%s (QCD)"  % (analysisType),
        # analysisType + "-EWK" : "%s (EWK)"  % (analysisType),
    })

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _opts = {"ymin": 1e0, "ymaxfactor": 10}
    _format = "%0.0f"

    if "mass" in histoName.lower():
        _rebinX = 2
        _format = "%0.0f GeV/c^{2}"
        if "TrijetMass" in histoName:
            _cutBox = {
                "cutValue": 173.21,
                "fillColor": 16,
                "box": False,
                "line": True,
                "greaterThan": True
            }
        if "DijetMass" in histoName:
            _cutBox = {
                "cutValue": 80.399,
                "fillColor": 16,
                "box": False,
                "line": True,
                "greaterThan": True
            }
    if "pt" in histoName.lower():
        _rebinX = 2
        _format = "%0.0f GeV/c"
    if "eta" in histoName.lower():
        _rebinX = 2
        _format = "%0.2f"
        _cutBox = {
            "cutValue": 0.,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
    if "bdisc" in histoName.lower():
        _format = "%0.2f"
        _rebinX = 1
    if "chisqr" in histoName.lower():
        _format = "%0.0f"
        _rebinX = 10
        if "after" in histoName.lower():
            _rebinX = 1
            _opts["xmax"] = 20.0
    if "tetrajet" in histoName.lower():
        if "mass" in histoName.lower():
            _rebinX = 10
            _opts["xmax"] = 3500.0

    else:
        pass

    histoName += "_" + analysisType
    plots.drawPlot(
        p,
        histoName,
        ylabel="Events /  %s" % (_format),
        log=True,
        rebinX=_rebinX,
        cmsExtraText="Preliminary",
        createLegend={
            "x1": 0.75,
            "y1": 0.76,
            "x2": 0.92,
            "y2": 0.92
        },
        opts=_opts,
        opts2={
            "ymin": 1e-5,
            "ymax": 1e0
        },
        ratio=True,
        ratioInvert=False,
        ratioYlabel="Ratio",
        cutBox=_cutBox,
    )

    # Save plot in all formats
    SavePlot(p,
             histoName,
             os.path.join(opts.saveDir, "DataEwkQcd"),
             saveFormats=[".png"])
    return
예제 #5
0
def QCDVsInvertedComparison(datasetsMgr, histoName):
    
    p1 = plots.ComparisonPlot(*getHistos(datasetsMgr, "Data", "topSelection_Baseline/%s" % histoName, "topSelection_Inverted/%s" % histoName))
    p1.histoMgr.normalizeMCToLuminosity(datasetsMgr.getDataset("Data").getLuminosity())

    p2 = plots.ComparisonPlot(*getHistos(datasetsMgr, "EWK", "topSelection_Baseline/%s" % histoName, "topSelection_Inverted/%s" % histoName) )
    p2.histoMgr.normalizeMCToLuminosity(datasetsMgr.getDataset("Data").getLuminosity())

    p3 = plots.ComparisonPlot(*getHistos(datasetsMgr, "QCD", "topSelection_Baseline/%s" % histoName, "topSelection_Inverted/%s" % histoName))
    p3.histoMgr.normalizeMCToLuminosity(datasetsMgr.getDataset("Data").getLuminosity())

    # Get Data histos    
    baseline_Data = p1.histoMgr.getHisto("Baseline-Data").getRootHisto().Clone("Baseline-Data")
    inverted_Data = p1.histoMgr.getHisto("Inverted-Data").getRootHisto().Clone("Inverted-Data")

    # Get EWK histos
    baseline_EWK = p2.histoMgr.getHisto("Baseline-EWK").getRootHisto().Clone("Baseline-EWK")
    inverted_EWK = p2.histoMgr.getHisto("Inverted-EWK").getRootHisto().Clone("Inverted-EWK")

    # Get QCD (MC) Histos
    baseline_QCDMC = p3.histoMgr.getHisto("Baseline-QCD").getRootHisto().Clone("Baseline-QCDMC")
    inverted_QCDMC = p3.histoMgr.getHisto("Inverted-QCD").getRootHisto().Clone("Inverted-QCDMC")

    # Create QCD histos (QCD = Data-EWK)
    baseline_QCD = p1.histoMgr.getHisto("Baseline-Data").getRootHisto().Clone("Baseline-QCD")
    inverted_QCD = p1.histoMgr.getHisto("Inverted-Data").getRootHisto().Clone("Inverted-QCD")
    baseline_QCD.Add(baseline_EWK, -1)
    inverted_QCD.Add(inverted_EWK, -1)

    # Normalize histograms to unit area
    baseline_QCD.Scale(1.0/baseline_QCD.Integral())
    inverted_QCD.Scale(1.0/inverted_QCD.Integral())
    baseline_QCDMC.Scale(1.0/baseline_QCDMC.Integral())
    inverted_QCDMC.Scale(1.0/inverted_QCDMC.Integral())

    # Create the final plot object
    comparisonList = [baseline_QCDMC, inverted_QCD, inverted_QCDMC]
    p = plots.ComparisonManyPlot(baseline_QCD, comparisonList, saveFormats=[])
    p.setLuminosity(GetLumi(datasetsMgr))
        
    # Apply styles
    p.histoMgr.forHisto("Baseline-QCD"  , styles.getDataStyle() ) #getBaselineStyle()
    p.histoMgr.forHisto("Baseline-QCDMC", styles.getBaselineLineStyle() ) #getBaselineLineStyle()
    p.histoMgr.forHisto("Inverted-QCDMC", styles.getAltQCDStyle() ) #getQCDLineStyle
    p.histoMgr.forHisto("Inverted-QCD"  , styles.getInvertedStyle() )

    # Set draw style
    p.histoMgr.setHistoDrawStyle("Baseline-QCD", "P")
    p.histoMgr.setHistoLegendStyle("Baseline-QCD", "P")
    p.histoMgr.setHistoDrawStyle("Baseline-QCDMC", "HIST")
    p.histoMgr.setHistoLegendStyle("Baseline-QCDMC", "L")
    p.histoMgr.setHistoDrawStyle("Inverted-QCDMC", "HIST")
    p.histoMgr.setHistoLegendStyle("Inverted-QCDMC", "F")
    p.histoMgr.setHistoDrawStyle("Inverted-QCD", "P")
    p.histoMgr.setHistoLegendStyle("Inverted-QCD", "LP")
    # p.histoMgr.setHistoLegendStyleAll("LP")

    # Set legend labels
    p.histoMgr.setHistoLegendLabelMany({
            "Baseline-QCD"  : "Baseline (QCD)",
            "Baseline-QCDMC": "Baseline (QCD MC)",
            "Inverted-QCD"  : "Inverted (QCD)",
            "Inverted-QCDMC": "Inverted (QCD MC)",
            })

    # Draw the histograms
    _rebinX = 1
    _cutBox = None
    _opts   = {"ymin": 1e-6, "ymaxfactor": 2.0}

    if "Pt_" in histoName:
        _format = "%0.f GeV/c"
        _rebinX = 5
        if "tetrajet" in histoName.lower():
            _rebinX = 5
            
    if "ChiSqr" in histoName:
        _format = "%0.1f"
        _rebinX = 10
        if "After" in histoName:
            _rebinX = 1
            _opts["xmax"] = 20.0
    if "Mass" in histoName:
        _format = "%0.0f GeV/c^{2}"
        _rebinX = 5
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        if "tetrajet" in histoName.lower():
            _rebinX = 10
            _opts["xmax"] = 3000.0
    if "BDisc" in histoName:
        _format = "%0.2f"
        _rebinX = 2
        _opts["xmax"] = 1.01
    if "Eta" in histoName:
        _format = "%0.2f"
    if "dijetmass" in histoName.lower():
        _cutBox = {"cutValue": 80.399, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
    if "TetrajetMass" in histoName:
        _opts   = {"ymin": 8e-5, "ymaxfactor": 2.0, "xmax": 3000.0}
                
    plots.drawPlot(p, histoName,  
                   ylabel       = "Arbitrary Units / %s" % (_format),
                   log          = True, 
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", 
                   createLegend = {"x1": 0.60, "y1": 0.75, "x2": 0.92, "y2": 0.92},
                   opts         = _opts,
                   opts2        = {"ymin": 0.6, "ymax": 1.4},
                   ratio        = True,
                   ratioInvert  = False, 
                   ratioYlabel  = "Ratio",
                   cutBox       = _cutBox,
                   )
    # Save plot in all formats
    SavePlot(p, histoName, os.path.join(opts.saveDir, "QCDVsInverted") ) 
    return