Beispiel #1
0
def PlotTemplates(datasetsMgr, histoName, analysisType="Inverted"):                  
    Verbose("Plotting EWK Vs QCD unity-normalised histograms")

    # Create comparison plot
    p1 = plots.ComparisonPlot(
        getHisto(datasetsMgr, "Data", histoName, "Baseline"),
        getHisto(datasetsMgr, "Data", histoName, "Inverted")
        )
    p1.histoMgr.normalizeMCToLuminosity(datasetsMgr.getDataset("Data").getLuminosity())
    
    defaultFolder  = "ForFakeBMeasurement"
    genuineBFolder = defaultFolder + "EWKGenuineB"
    fakeBFolder    = defaultFolder + "EWKFakeB"
    histoNameNew   = histoName.replace( defaultFolder, genuineBFolder)
    p2 = plots.ComparisonPlot(
        getHisto(datasetsMgr, "EWK", histoNameNew, "Baseline"),
        getHisto(datasetsMgr, "EWK", histoNameNew, "Inverted")
        )
    p2.histoMgr.normalizeMCToLuminosity(datasetsMgr.getDataset("Data").getLuminosity())

    # Get EWKGenuineB histos
    EWKGenuineB_baseline = p2.histoMgr.getHisto("Baseline-EWK").getRootHisto().Clone("Baseline-EWKGenuineB")
    EWKGenuineB_inverted = p2.histoMgr.getHisto("Inverted-EWK").getRootHisto().Clone("Inverted-EWKGenuineB")

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

    # Normalize histograms to unit area
    EWKGenuineB_baseline.Scale(1.0/EWKGenuineB_baseline.Integral())    
    EWKGenuineB_inverted.Scale(1.0/EWKGenuineB_inverted.Integral())
    FakeB_baseline.Scale(1.0/FakeB_baseline.Integral())
    FakeB_inverted.Scale(1.0/FakeB_inverted.Integral())
    
    # Create the final plot object
    comparisonList = [EWKGenuineB_baseline]
    p = plots.ComparisonManyPlot(FakeB_inverted, comparisonList, saveFormats=[])
    p.setLuminosity(GetLumi(datasetsMgr))
        
    # Apply styles
    p.histoMgr.forHisto("Baseline-EWKGenuineB", styles.getBaselineStyle() )
    p.histoMgr.forHisto("Inverted-FakeB"      , styles.getInvertedStyle() )

    # Set draw style
    p.histoMgr.setHistoDrawStyle("Baseline-EWKGenuineB", "AP")
    p.histoMgr.setHistoDrawStyle("Inverted-FakeB"      , "HIST")

    # Set legend style
    p.histoMgr.setHistoLegendStyle("Baseline-EWKGenuineB", "LP")
    p.histoMgr.setHistoLegendStyle("Inverted-FakeB"        , "LP")

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

    # Append analysisType to histogram name
    saveName = histoName

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

    # _kwargs = {"lessThan": True}
    # p.addCutBoxAndLine(cutValue=200, fillColor=ROOT.kRed, box=False, line=True, ***_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, "Templates", opts.optMode)
    SavePlot(p, saveName, saveDir, saveFormats = [".C", ".png", ".pdf"])
    return
Beispiel #2
0
def BaselineVsInvertedComparison(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())

    # 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")

    # Create QCD histos: QCD = Data-EWK
    baseline_QCD = p1.histoMgr.getHisto("Baseline-Data").getRootHisto().Clone("Baseline-QCD")
    baseline_QCD.Add(baseline_EWK, -1)
    inverted_QCD = p1.histoMgr.getHisto("Inverted-Data").getRootHisto().Clone("Inverted-QCD")
    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())

    # Create the final plot object
    p = plots.ComparisonManyPlot(baseline_QCD, [inverted_QCD], saveFormats=[]) #[".C", ".png", ".pdf"])
    p.setLuminosity(GetLumi(datasetsMgr))
        
    # Apply styles
    p.histoMgr.forHisto("Baseline-QCD" , styles.getBaselineStyle() )
    p.histoMgr.forHisto("Inverted-QCD" , styles.getInvertedStyle() )

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

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

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

    if "Pt_" in histoName:
        _format = "%0.f GeV/c"
        if "tetrajet" in histoName.lower():
            _rebinX = 2
            
    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 = 2
        if "tetrajet" in histoName.lower():
            _rebinX = 5
            _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 "trijet" in histoName.lower():
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
    if "dijet" 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.62, "y1": 0.78, "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, "BaselineVsInverted") ) 
    return
Beispiel #3
0
def BaselineVsInvertedPlots(datasetsMgr, histoName, analysisType="Inverted"):
    
    # Sanity check
    IsBaselineOrInverted(analysisType)
    
    # Get the Data (Inclusive)
    p1 = plots.ComparisonPlot(*getHistos(datasetsMgr, "Data",  histoName, analysisType))
    p1.histoMgr.normalizeMCToLuminosity(datasetsMgr.getDataset("Data").getLuminosity())

    # Get the EWK (GenuineB)                              
    defaultFolder  = "ForFakeBMeasurement"
    genuineBFolder = defaultFolder + "EWKGenuineB"
    fakeBFolder    = defaultFolder + "EWKFakeB"
    histoNameNew   = histoName.replace( defaultFolder, genuineBFolder)
    p2 = plots.ComparisonPlot(*getHistos(datasetsMgr, "EWK", histoNameNew, analysisType) )
    p2.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_EWKGenuineB = p2.histoMgr.getHisto("Baseline-EWK").getRootHisto().Clone("Baseline-EWKGenuineB")
    inverted_EWKGenuineB = p2.histoMgr.getHisto("Inverted-EWK").getRootHisto().Clone("Inverted-EWKGenuineB")

    # Get FakeB (Baseline): FakeB = Data-EWKGenuineB
    baseline_FakeB = p1.histoMgr.getHisto("Baseline-Data").getRootHisto().Clone("Baseline-FakeB")
    baseline_FakeB.Add(baseline_EWKGenuineB, -1)

    # Get FakeB (Inverted): FakeB = Data-EWKGenuineB
    inverted_FakeB = p1.histoMgr.getHisto("Inverted-Data").getRootHisto().Clone("Inverted-FakeB")
    inverted_FakeB.Add(inverted_EWKGenuineB, -1)

    # Normalize histograms to unit area
    baseline_FakeB.Scale(1.0/baseline_FakeB.Integral())
    inverted_FakeB.Scale(1.0/inverted_FakeB.Integral())

    # Create the final plot object
    p = plots.ComparisonManyPlot(baseline_FakeB, [inverted_FakeB], saveFormats=[]) #[".C", ".png", ".pdf"])
    p.setLuminosity(GetLumi(datasetsMgr))
        
    # Apply styles
    p.histoMgr.forHisto("Baseline-FakeB" , styles.getBaselineStyle() )
    p.histoMgr.forHisto("Inverted-FakeB" , styles.getInvertedStyle() )

    # Set draw style
    p.histoMgr.setHistoDrawStyle("Baseline-FakeB", "AP")
    p.histoMgr.setHistoDrawStyle("Inverted-FakeB", "HIST")

    # Set legend style
    p.histoMgr.setHistoLegendStyle("Baseline-FakeB", "LP")
    p.histoMgr.setHistoLegendStyle("Inverted-FakeB", "F")
    # p.histoMgr.setHistoLegendStyleAll("LP")

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

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _opts   = {"ymin": 1e-4, "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

    plots.drawPlot(p, histoName,  
                   xlabel       = _xlabel,
                   ylabel       = "Arbitrary Units / %s" % (_format),
                   log          = True, 
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", 
                   createLegend = {"x1": 0.62, "y1": 0.78, "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, "BaselineVsInverted", opts.optMode) ) 
    return
Beispiel #4
0
def PlotBaselineVsInverted(datasetsMgr, hBaseline, hInverted):

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

    p2 = plots.ComparisonPlot(
        *getHistos(datasetsMgr, "EWK", hBaseline, hInverted))
    p2.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    if opts.useMC:
        p3 = plots.ComparisonPlot(
            *getHistos(datasetsMgr, "QCD", hBaseline, hInverted))
        p3.histoMgr.normalizeMCToLuminosity(
            datasetsMgr.getDataset("Data").getLuminosity())

    # Get Baseline histos
    baseline_Data = p1.histoMgr.getHisto(
        "Baseline-Data").getRootHisto().Clone()
    baseline_QCD = p1.histoMgr.getHisto("Baseline-Data").getRootHisto().Clone(
        "Baseline-QCD")
    baseline_EWK = p2.histoMgr.getHisto("Baseline-EWK").getRootHisto().Clone()
    if opts.useMC:
        baseline_QCDMC = p3.histoMgr.getHisto(
            "Baseline-QCD").getRootHisto().Clone("Baseline-QCDMC")

    # Get Inverted histos
    inverted_Data = p1.histoMgr.getHisto(
        "Inverted-Data").getRootHisto().Clone()
    inverted_QCD = p1.histoMgr.getHisto("Inverted-Data").getRootHisto().Clone(
        "Inverted-QCD")
    inverted_EWK = p2.histoMgr.getHisto("Inverted-EWK").getRootHisto().Clone()
    if opts.useMC:
        inverted_QCDMC = p3.histoMgr.getHisto(
            "Inverted-QCD").getRootHisto().Clone("Inverted-QCDMC")

    # Subtract EWK from Data to get QCD
    baseline_QCD.Add(baseline_EWK, -1)
    inverted_QCD.Add(inverted_EWK, -1)

    # Option: Use QCD-MC instead of QCD=Data-EWK
    if opts.useMC:
        baseline_QCD = baseline_QCDMC
        inverted_QCD = inverted_QCDMC

    # Normalize histograms to unit area
    if opts.normaliseToOne:
        baseline_Data.Scale(1.0 / baseline_Data.Integral())
        baseline_QCD.Scale(1.0 / baseline_QCD.Integral())
        baseline_EWK.Scale(1.0 / baseline_EWK.Integral())
        inverted_Data.Scale(1.0 / inverted_Data.Integral())
        inverted_QCD.Scale(1.0 / inverted_QCD.Integral())
        inverted_EWK.Scale(1.0 / inverted_EWK.Integral())

    # Create the final plot object
    p = plots.ComparisonManyPlot(baseline_QCD, [inverted_QCD], saveFormats=[])

    # Apply styles
    if opts.useMC:
        p.histoMgr.forHisto("Baseline-QCDMC", styles.getBaselineStyle())
        p.histoMgr.forHisto("Inverted-QCDMC", styles.getInvertedStyle())
    else:
        p.histoMgr.forHisto("Baseline-QCD", styles.getBaselineStyle())
        p.histoMgr.forHisto("Inverted-QCD", styles.getInvertedStyle())

    # Set draw style
    if opts.useMC:
        p.histoMgr.setHistoDrawStyle("Baseline-QCDMC", "AP")
        p.histoMgr.setHistoDrawStyle("Inverted-QCDMC", "HIST")
    else:
        p.histoMgr.setHistoDrawStyle("Baseline-QCD", "AP")
        p.histoMgr.setHistoDrawStyle("Inverted-QCD", "HIST")

    # Set legend style
    if opts.useMC:
        p.histoMgr.setHistoLegendStyle("Baseline-QCDMC", "LP")
        p.histoMgr.setHistoLegendStyle("Inverted-QCDMC", "F")
    else:
        p.histoMgr.setHistoLegendStyle("Baseline-QCD", "LP")
        p.histoMgr.setHistoLegendStyle("Inverted-QCD", "F")

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

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    if opts.normaliseToOne:
        _opts = {"ymin": 3e-4, "ymaxfactor": 2.0}
    else:
        _opts = {"ymin": 1e0, "ymaxfactor": 2.0}
    _format = "%0.0f"
    _xlabel = None

    if "dijetm" in hBaseline.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 "chisqr" in hBaseline.lower():
        _rebinX = 1
        _units = ""
        _format = "%0.1f " + _units
        _xlabel = "#chi^{2}"
        _cutBox = {
            "cutValue": 10.0,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 100.0
    if "ldgdijetpt" in hBaseline.lower():
        _rebinX = 1
        _units = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T} (%s)" % _units
        _cutBox = {
            "cutValue": 40.0,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 800.0
    if "ldgdijetm" in hBaseline.lower():
        _rebinX = 1
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jj} (%s)" % _units
        _cutBox = {
            "cutValue": 80.385,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 300.0
    if "trijetm" in hBaseline.lower():
        _rebinX = 4  #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"] = 1000.0
    if "pt" in hBaseline.lower():
        _rebinX = 2
        _format = "%0.0f GeV/c"
        _cutBox = {
            "cutValue": 40.,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        ROOT.gStyle.SetNdivisions(8, "X")
        _opts["xmax"] = 1000.0
    if "eta" in hBaseline.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 hBaseline.lower():
        _format = "%0.2f"
        _opts["xmin"] = 0.0
        _opts["xmax"] = 6.0
    if "bdisc" in hBaseline.lower():
        _format = "%0.2f"
    if "tetrajetm" in hBaseline.lower():
        _rebinX = 10  #4
        if opts.useMC:
            _rebinX = 10
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _opts["xmax"] = 3000.0
        #_opts["xmax"] = 3500.0

    plots.drawPlot(
        p,
        hBaseline,
        xlabel=_xlabel,
        ylabel="Arbitrary Units / %s" % (_format),
        log=True,
        rebinX=_rebinX,
        cmsExtraText="Preliminary",
        createLegend={
            "x1": 0.62,
            "y1": 0.78,
            "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
    saveName = hBaseline.replace("/", "_")
    saveName = saveName.replace("_Baseline_", "_")
    savePath = os.path.join(opts.saveDir, "BaselineVsInverted", opts.optMode)
    if opts.useMC:
        savePath = os.path.join(opts.saveDir, "BaselineVsInverted", "MC",
                                opts.optMode)
    SavePlot(p, saveName, savePath)
    return
def PlotBaselineVsInvertedTemplates(datasetsMgr,
                                    histoName,
                                    addQcdBaseline=False):
    Verbose("Plotting EWK Vs QCD unity-normalised histograms")

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

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

    # Get EWK histos
    EWK_baseline = p1.histoMgr.getHisto("Baseline-EWK").getRootHisto().Clone(
        "Baseline-EWK")
    EWK_inverted = p2.histoMgr.getHisto("Inverted-EWK").getRootHisto().Clone(
        "Inverted-EWK")
    # Get QCD histos
    QCD_baseline = p1.histoMgr.getHisto("Baseline-Data").getRootHisto().Clone(
        "Baseline-QCD")
    QCD_inverted = p2.histoMgr.getHisto("Inverted-Data").getRootHisto().Clone(
        "Inverted-QCD")

    # Create QCD histos: QCD = Data-EWK
    QCD_baseline.Add(EWK_baseline, -1)
    QCD_inverted.Add(EWK_inverted, -1)

    # Normalize histograms to unit area
    EWK_baseline.Scale(1.0 / EWK_baseline.Integral())
    EWK_inverted.Scale(1.0 / EWK_inverted.Integral())
    QCD_baseline.Scale(1.0 / QCD_baseline.Integral())
    QCD_inverted.Scale(1.0 / QCD_inverted.Integral())

    # Create the final plot object
    if addQcdBaseline:
        compareHistos = [EWK_baseline, QCD_baseline]
    else:
        compareHistos = [EWK_baseline]
    p = plots.ComparisonManyPlot(QCD_inverted, compareHistos, saveFormats=[])
    p.setLuminosity(GetLumi(datasetsMgr))

    # Apply styles
    p.histoMgr.forHisto("Baseline-EWK", styles.getBaselineStyle())
    if addQcdBaseline:
        p.histoMgr.forHisto("Baseline-QCD", styles.getInvertedLineStyle())
    p.histoMgr.forHisto("Inverted-QCD", styles.getInvertedStyle())

    # Set draw style
    p.histoMgr.setHistoDrawStyle("Baseline-EWK", "AP")
    p.histoMgr.setHistoLegendStyle("Baseline-EWK", "LP")
    if addQcdBaseline:
        p.histoMgr.setHistoDrawStyle("Baseline-QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("Baseline-QCD", "FL")
    p.histoMgr.setHistoDrawStyle("Inverted-QCD", "AP")
    p.histoMgr.setHistoLegendStyle("Inverted-QCD", "LP")

    # Set legend labels
    if addQcdBaseline:
        p.histoMgr.setHistoLegendLabelMany({
            "Baseline-EWK": "EWK (Baseline)",
            "Baseline-QCD": "QCD (Baseline)",
            "Inverted-QCD": "QCD (Inverted)",
        })
    else:
        p.histoMgr.setHistoLegendLabelMany({
            "Baseline-EWK": "EWK (Baseline)",
            "Inverted-QCD": "QCD (Inverted)",
        })

    # Append analysisType to histogram name
    saveName = histoName

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

    # _kwargs = {"lessThan": True}
    # p.addCutBoxAndLine(cutValue=200, fillColor=ROOT.kRed, box=False, line=True, ***_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, "Templates", opts.optMode)
    SavePlot(p, saveName, saveDir, saveFormats=[".C", ".png", ".pdf"])
    return
Beispiel #6
0
def BaselineVsInvertedPlots(datasetsMgr, histoName):

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

    p2 = plots.ComparisonPlot(*getHistos(datasetsMgr, histoName, "Inverted"))
    p2.histoMgr.normalizeMCToLuminosity(
        datasetsMgr.getDataset("Data").getLuminosity())

    # Get Baseline histos
    baseline_Data = p1.histoMgr.getHisto("Data").getRootHisto().Clone(
        "Baseline-Data")
    baseline_QCD = p1.histoMgr.getHisto("Data").getRootHisto().Clone(
        "Baseline-QCD")
    baseline_EWK = p1.histoMgr.getHisto("EWK").getRootHisto().Clone(
        "Baseline-EWK")

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

    # Subtract EWK from Data to get QCD
    baseline_QCD.Add(baseline_EWK, -1)
    inverted_QCD.Add(inverted_EWK, -1)

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

    # Create the final plot object
    p = plots.ComparisonManyPlot(baseline_QCD, [inverted_QCD], saveFormats=[])
    #p.setLuminosity(GetLumi(datasetsMgr))

    # Apply styles
    p.histoMgr.forHisto("Baseline-QCD", styles.getBaselineStyle())
    p.histoMgr.forHisto("Inverted-QCD", styles.getInvertedStyle())

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

    # Set legend style
    p.histoMgr.setHistoLegendStyle("Baseline-QCD", "LP")
    p.histoMgr.setHistoLegendStyle("Inverted-QCD", "F")
    # p.histoMgr.setHistoLegendStyleAll("LP")

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

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _opts = {"ymin": 1e-4, "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

    plots.drawPlot(
        p,
        histoName,
        xlabel=_xlabel,
        ylabel="Arbitrary Units / %s" % (_format),
        log=True,
        rebinX=_rebinX,
        cmsExtraText="Preliminary",
        createLegend={
            "x1": 0.62,
            "y1": 0.78,
            "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.replace("<Analysis>_", ""),
             os.path.join(opts.saveDir, "BaselineVsInverted", opts.optMode))
    return