def PlotHistograms(datasetsMgr, histoName):

    # Get Histogram name and its kwargs
    saveName = histoName.rsplit("/")[-1] # histoName.replace("/", "_")
    kwargs_  = GetHistoKwargs(saveName, opts)

    # Create the plotting object
    if "Data" in datasetsMgr.getAllDatasetNames():
        p = plots.DataMCPlot(datasetsMgr, histoName, saveFormats=[])
    else:
        if opts.normalizeToLumi:
            p = plots.MCPlot(datasetsMgr, histoName, normalizeToLumi=opts.intLumi, saveFormats=[])
        elif opts.normalizeByCrossSection:
            p = plots.MCPlot(datasetsMgr, histoName, normalizeByCrossSection=True, saveFormats=[], **{})
        elif opts.normalizeToOne:
            p = plots.MCPlot(datasetsMgr, histoName, normalizeToOne=True, saveFormats=[], **{})
        else:
            raise Exception("One of the options --normalizeToOne, --normalizeByCrossSection, --normalizeToLumi must be enabled (set to \"True\").")


    # Overwite signal style?
    style  = [200, 500, 800, 1000, 2000, 5000]
    lstyle = [ROOT.kSolid, ROOT.kDashed, ROOT.kDashDotted, ROOT.kDotted, ROOT.kDotted, ROOT.kSolid]
    for i, d in enumerate(datasetsMgr.getAllDatasets(), 0):
        p.histoMgr.forHisto(d.getName(), styles.getSignalStyleHToTB_M(style[i]))
    if 1:
        p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    p.histoMgr.setHistoLegendLabelMany({
            #"ChargedHiggs_HplusTB_HplusToTB_M_500_MVA0p30": "H^{+} m_{H^{+}} = 500 GeV (BDT #geq 0.3)",
            "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p30" % (opts.signalMass): "m_{H^{+}}=%s GeV (BDT #geq 0.3)" % (opts.signalMass),
            "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p40" % (opts.signalMass): "m_{H^{+}}=%s GeV (BDT #geq 0.4)" % (opts.signalMass),
            "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p50" % (opts.signalMass): "m_{H^{+}}=%s GeV (BDT #geq 0.5)" % (opts.signalMass),
            "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p60" % (opts.signalMass): "m_{H^{+}}=%s GeV (BDT #geq 0.6)" % (opts.signalMass),
            "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p70" % (opts.signalMass): "m_{H^{+}}=%s GeV (BDT #geq 0.7)" % (opts.signalMass),
            })
    
    # Apply blinding of signal region
    if "blindingRangeString" in kwargs_:
        startBlind = float(kwargs_["blindingRangeString"].split("-")[1])
        endBlind   = float(kwargs_["blindingRangeString"].split("-")[0])
        plots.partiallyBlind(p, maxShownValue=startBlind, minShownValue=endBlind, invert=True, moveBlindedText=kwargs_["moveBlindedText"])

    # Draw and save the plot
    saveName += "_M%s" % (opts.signalMass)
    plots.drawPlot(p, saveName, **kwargs_) #the "**" unpacks the kwargs_ dictionary

    # Save the plots in custom list of saveFormats
    SavePlot(p, saveName, os.path.join(opts.saveDir, opts.optMode, opts.folder), [".png", ".pdf"] )
    return
示例#2
0
def DataMCHistograms(datasetsMgr, qcdDatasetName):
    Verbose("Plotting Data-MC Histograms")

    # Definitions
    histoNames  = []
    saveFormats = [".png"] #[".C", ".png", ".pdf"]

    # Get list of histograms
    dataPath    = "ForDataDrivenCtrlPlots"
    allHistos   = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(dataPath)
    histoList   = [h for h in allHistos if "StandardSelections" in h]
    histoList.extend([h for h in allHistos if "AllSelections" in h])
    histoList   = [h for h in histoList if "_MCEWK" not in h]
    histoList   = [h for h in histoList if "_Purity" not in h]
    histoPaths  = [dataPath + "/" + h for h in histoList]

    # Get histogram<->kwargs dictionary 
    histoKwargs = GetHistoKwargs(histoPaths, opts)

    # For-loop: All histograms in list
    for histoName in histoPaths:

        #if "Mass" not in histoName:
        #    continue

        if "JetEtaPhi" in histoName:
            continue

        if opts.signalMass == 0:
            if "LdgTrijetMass" in histoName:
                continue
            
            if "LdgTetrajetMass" in histoName:
                continue

        if "Vs" in histoName:
            continue

        # Not used in this analysis (yet)
        if "MHT" in histoName:
            continue

        # By definition of the Inverted sample the following histos cannot agree!
        if "NBjets_" in histoName:
            continue
        if "BJetPt_" in histoName:
            continue
        if "_BJetEta_" in histoName:
            continue
        if "_BtagDiscriminator_" in histoName:
            continue

        kwargs_  = histoKwargs[histoName]
        saveName = histoName.replace("/", "_")

        # Create the plotting object
        p = plots.DataMCPlot(datasetsMgr, histoName, saveFormats=[])

        # Apply QCD data-driven style
        if opts.signalMass != 0:
            signal = "ChargedHiggs_HplusTB_HplusToTB_M_%.0f" % opts.signalMass
            mHPlus = "%s" % int(opts.signalMass)
            p.histoMgr.forHisto(signal, styles.getSignalStyleHToTB_M(mHPlus))

        #p.histoMgr.forHisto(opts.signalMass, styles.getSignalStyleHToTB())
        if opts.mcQCD:
            pass
        else:
            p.histoMgr.forHisto(qcdDatasetName, styles.getAltQCDStyle())
            p.histoMgr.setHistoDrawStyle(qcdDatasetName, "HIST")
            p.histoMgr.setHistoLegendStyle(qcdDatasetName, "F")

        if not opts.mcQCD:
            p.histoMgr.setHistoLegendLabelMany({
                    qcdDatasetName: "QCD (Data)",
                    })
        else:
            p.histoMgr.setHistoLegendLabelMany({
                    "QCD": "QCD (MC)",
                    })            

        # Apply blinding of signal region
        if "blindingRangeString" in kwargs_:
            startBlind = float(kwargs_["blindingRangeString"].split("-")[1])
            endBlind   = float(kwargs_["blindingRangeString"].split("-")[0])
            plots.partiallyBlind(p, maxShownValue=startBlind, minShownValue=endBlind, invert=True, moveBlindedText=kwargs_["moveBlindedText"])

        # Draw and save the plot
        plots.drawPlot(p, saveName, **kwargs_) #the "**" unpacks the kwargs_ dictionary
        SavePlot(p, saveName, os.path.join(opts.saveDir, opts.optMode) )
    return
示例#3
0
def PlotHistogram(dsetMgr, histoName, opts):

    # Get kistogram argumetns
    kwargs   = GetHistoKwargs(histoName, opts)
    saveName = histoName.replace(opts.folder + "/", "")

    # Create the plotting object (Data, "FakeB")
    p1 = plots.DataMCPlot(dsetMgr, histoName, saveFormats=[])

    # Copy dataset manager before changing datasets. Keep only EWK (GenuineB) datasets
    datasetMgr = dsetMgr.deepCopy()
    datasetMgr.selectAndReorder(aux.GetListOfEwkDatasets())
        
    # Create the MCPlot for the EWKGenuineB histograms
    if opts.useMC:
        p2 = plots.MCPlot(datasetMgr, histoName, normalizeToLumi=opts.intLumi, saveFormats=[])
    else:
        histoNameGenuineB = histoName.replace(opts.folder, opts.folder + "EWKGenuineB")
        p2 = plots.MCPlot(datasetMgr, histoNameGenuineB, normalizeToLumi=opts.intLumi, saveFormats=[])

    # Add the datasets to be included in the plot
    myStackList = []

    # Data-driven FakeB background
    if not opts.useMC:
        hFakeB  = p1.histoMgr.getHisto("FakeB").getRootHisto()
        hhFakeB = histograms.Histo(hFakeB, "FakeB", legendLabel="Fake-b")
        hhFakeB.setIsDataMC(isData=False, isMC=True)
        myStackList.append(hhFakeB)
    else:
        hQCD  = p1.histoMgr.getHisto("QCD").getRootHisto()
        hhQCD = histograms.Histo(hQCD, "QCD", legendLabel="QCD")
        hhQCD.setIsDataMC(isData=False, isMC=True)
        myStackList.append(hhQCD)

    # EWK GenuineB background (Replace all EWK histos with GenuineB histos)
    ewkHistoList = []
    # For-loop: All EWK datasets 
    for dataset in aux.GetListOfEwkDatasets():
        h = p2.histoMgr.getHisto(dataset).getRootHisto()
        hh = histograms.Histo(h, dataset,  plots._legendLabels[dataset])
        hh.setIsDataMC(isData=False, isMC=True)
        myStackList.append(hh)

    # Collision data
    hData  = p1.histoMgr.getHisto("Data").getRootHisto()
    hhData = histograms.Histo(hData, "Data")
    hhData.setIsDataMC(isData=True, isMC=False)
    myStackList.insert(0, hhData)

    # Signal
    hSignal  = p1.histoMgr.getHisto(opts.signal).getRootHisto()
    hhSignal = histograms.Histo(hSignal, opts.signal, plots._legendLabels[opts.signal])
    hhSignal.setIsDataMC(isData=False, isMC=True)
    myStackList.insert(1, hhSignal)

    # Create the final plot by passing the histogram list
    p3 = plots.DataMCPlot2(myStackList, saveFormats=[])
    p3.setLuminosity(opts.intLumi)
    p3.setDefaultStyles()

    # Apply blinding of data in Signal Region (After creating the plot)
    if "blindingRangeString" in kwargs:
        startBlind = float(kwargs["blindingRangeString"].split("-")[1])
        endBlind   = float(kwargs["blindingRangeString"].split("-")[0])
        plots.partiallyBlind(p3, maxShownValue=startBlind, minShownValue=endBlind, invert=True, moveBlindedText=kwargs["moveBlindedText"])

    # Draw and save the plot
    plots.drawPlot(p3, saveName, **kwargs)
    SavePlot(p3, saveName, os.path.join(opts.saveDir, opts.optMode), saveFormats = [".png", ".pdf"])
    return
示例#4
0
def PlotHistograms(datasetsMgr, histoName):

    # Get Histogram name and its kwargs
    saveName = histoName.rsplit("/")[-1]  # histoName.replace("/", "_")
    kwargs_ = GetHistoKwargs(saveName, opts)

    # Create the plotting object
    if "Data" in datasetsMgr.getAllDatasetNames():
        p = plots.DataMCPlot(datasetsMgr, histoName, saveFormats=[])
    else:
        if opts.normalizeToLumi:
            p = plots.MCPlot(datasetsMgr,
                             histoName,
                             normalizeToLumi=opts.intLumi,
                             saveFormats=[])
        elif opts.normalizeByCrossSection:
            p = plots.MCPlot(datasetsMgr,
                             histoName,
                             normalizeByCrossSection=True,
                             saveFormats=[],
                             **{})
        elif opts.normalizeToOne:
            p = plots.MCPlot(datasetsMgr,
                             histoName,
                             normalizeToOne=True,
                             saveFormats=[],
                             **{})
        else:
            raise Exception(
                "One of the options --normalizeToOne, --normalizeByCrossSection, --normalizeToLumi must be enabled (set to \"True\")."
            )

    # Overwite signal style?
    style = [200, 500, 800, 1000, 2000, 3000, 5000]
    lstyle = [
        ROOT.kSolid, ROOT.kDashed, ROOT.kDashDotted, ROOT.kDotted,
        ROOT.kDotted, ROOT.kSolid
    ]
    for i, d in enumerate(datasetsMgr.getAllDatasets(), 0):
        p.histoMgr.forHisto(d.getName(),
                            styles.getSignalStyleHToTB_M(style[i]))
    if 1:
        p.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    p.histoMgr.setHistoLegendLabelMany({
        #"ChargedHiggs_HplusTB_HplusToTB_M_500_MVA0p30": "H^{+} m_{H^{+}} = 500 GeV (BDT #geq 0.3)",
        "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p30" % (opts.signalMass):
        "m_{H^{+}}=%s GeV (BDT #geq 0.3)" % (opts.signalMass),
        "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p40" % (opts.signalMass):
        "m_{H^{+}}=%s GeV (BDT #geq 0.4)" % (opts.signalMass),
        "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p50" % (opts.signalMass):
        "m_{H^{+}}=%s GeV (BDT #geq 0.5)" % (opts.signalMass),
        "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p60" % (opts.signalMass):
        "m_{H^{+}}=%s GeV (BDT #geq 0.6)" % (opts.signalMass),
        "ChargedHiggs_HplusTB_HplusToTB_M_%s_MVA0p70" % (opts.signalMass):
        "m_{H^{+}}=%s GeV (BDT #geq 0.7)" % (opts.signalMass),
    })

    # Apply blinding of signal region
    if "blindingRangeString" in kwargs_:
        startBlind = float(kwargs_["blindingRangeString"].split("-")[1])
        endBlind = float(kwargs_["blindingRangeString"].split("-")[0])
        plots.partiallyBlind(p,
                             maxShownValue=startBlind,
                             minShownValue=endBlind,
                             invert=True,
                             moveBlindedText=kwargs_["moveBlindedText"])

    # Draw and save the plot
    saveName += "_M%s" % (opts.signalMass)
    plots.drawPlot(p, saveName,
                   **kwargs_)  #the "**" unpacks the kwargs_ dictionary

    # Save the plots in custom list of saveFormats
    SavePlot(p, saveName, os.path.join(opts.saveDir, opts.optMode,
                                       opts.folder), [".png", ".pdf"])
    return
def DataMCHistograms(datasetsMgr, histoName):
    Verbose("Plotting Data-MC Histograms")

    # Skip 2-D plots
    skipStrings = []
    if opts.folder == "topbdtSelection_":
        skipStrings = ["_Vs_", "Vs", "Matched", "MCtruth", "TopQuark", 
                       "RealSelected", "DeltaMVAgt1", "SelectedTop", 
                       "LdgTrijetFake", "LdgTrijetFakeJJB", "TrijetFake",
                       "FakeInTopDir", "LdgTrijetFakeJJB_BDT", "LdgTrijetFake_BDT"]

    if opts.folder == "counters":
        skipStrings = ["weighted"]
    if opts.folder == "eSelection_Veto":
        skipStrings = ["Resolution"]
    if opts.folder == "muSelection_Veto":
        skipStrings = ["Resolution"]
    if opts.folder == "tauSelection_Veto":
        skipStrings = ["riggerMatch", "NprongsMatrix", "Resolution"]
    if opts.folder == "PUDependency":
        skipStrings = ["WithProbabilisticBtag", "AngularCuts", "AntiIsolatedTau", "NvtxTau"]
    if opts.folder == "jetSelection_":
        skipStrings = ["JetMatching"]
    if opts.folder == "bjetSelection_":
        skipStrings = ["MatchDeltaR", "btagSFRelUncert", "_dEta", "_dPhi", "_dPt", "_dR"]
    if opts.folder == "metSelection_":
        skipStrings = [""]
    if opts.folder == "topologySelection_":
        skipStrings = ["_Vs_"]
    if "ForDataDrivenCtrlPlots" in opts.folder:
        skipStrings = ["_Vs_", "JetEtaPhi", "MinDeltaPhiJet", "MaxDeltaPhiJet", "MinDeltaRJet"]

    # Skip histograms if they contain a given string
    for keyword in skipStrings:
        if keyword in histoName:
            return

    # Get Histogram name and its kwargs
    saveName = histoName.rsplit("/")[-1] # histoName.replace("/", "_")
    kwargs_  = GetHistoKwargs(saveName, opts)

    # Create the plotting object
    p = plots.DataMCPlot(datasetsMgr, histoName, saveFormats=[])

    # Overwite signal style?
    if 0:
        if opts.signalMass != 0:
            p.histoMgr.forHisto(opts.signal, styles.getSignalStyleHToTB_M(opts.signalMass))

    if "QCD" in datasetsMgr.getAllDatasetNames():
        p.histoMgr.setHistoLegendLabelMany({
                "QCD": "QCD (MC)",
                })
    
    # Apply blinding of signal region
    if "blindingRangeString" in kwargs_:
        startBlind = float(kwargs_["blindingRangeString"].split("-")[1])
        endBlind   = float(kwargs_["blindingRangeString"].split("-")[0])
        plots.partiallyBlind(p, maxShownValue=startBlind, minShownValue=endBlind, invert=True, moveBlindedText=kwargs_["moveBlindedText"])

    # Draw and save the plot
    plots.drawPlot(p, saveName, **kwargs_) #the "**" unpacks the kwargs_ dictionary

    # Replace bin labels
    if "counter" in opts.folder and "counter" in histoName.split("/")[-1]:
        # p.getFrame().GetXaxis().LabelsOption("v") #vertical orientation of bin labels
        replaceBinLabels(p, saveName)
        #pass

    # Save the plots in custom list of saveFormats
    SavePlot(p, saveName, os.path.join(opts.saveDir, opts.optMode, opts.folder), [".png", ".pdf"] )
    return
示例#6
0
def DataMCHistograms(datasetsMgr, histoName):
    Verbose("Plotting Data-MC Histograms")

    # Skip 2-D plots
    skipStrings = []
    if opts.folder == "topbdtSelection_":
        skipStrings = ["_Vs_", "Vs", "Matched", "MCtruth", "TopQuark", 
                       "RealSelected", "DeltaMVAgt1", "SelectedTop", 
                       "LdgTrijetFake", "LdgTrijetFakeJJB", "TrijetFake",
                       "FakeInTopDir", "LdgTrijetFakeJJB_BDT", "LdgTrijetFake_BDT"]

    if opts.folder == "counters":
        skipStrings = ["weighted"]
    if opts.folder == "eSelection_Veto":
        skipStrings = ["Resolution"]
    if opts.folder == "muSelection_Veto":
        skipStrings = ["Resolution"]
    if opts.folder == "tauSelection_Veto":
        skipStrings = ["riggerMatch", "NprongsMatrix", "Resolution"]
    if opts.folder == "PUDependency":
        skipStrings = ["WithProbabilisticBtag", "AngularCuts", "AntiIsolatedTau", "NvtxTau"]
    if opts.folder == "jetSelection_":
        skipStrings = ["JetMatching"]
    if opts.folder == "bjetSelection_":
        skipStrings = ["MatchDeltaR", "btagSFRelUncert", "_dEta", "_dPhi", "_dPt", "_dR"]
    if opts.folder == "metSelection_":
        skipStrings = [""]
    if opts.folder == "topologySelection_":
        skipStrings = ["_Vs_"]
    if "ForDataDrivenCtrlPlots" in opts.folder:
        skipStrings = ["_Vs_", "JetEtaPhi", "MinDeltaPhiJet", "MaxDeltaPhiJet", "MinDeltaRJet"]

    # Skip histograms if they contain a given string
    for keyword in skipStrings:
        if keyword in histoName:
            return

    # Get Histogram name and its kwargs
    saveName = histoName.rsplit("/")[-1] # histoName.replace("/", "_")
    kwargs_  = GetHistoKwargs(saveName, opts)

    # Create the plotting object
    p = plots.DataMCPlot(datasetsMgr, histoName, saveFormats=[])

    # Overwite signal style?
    if 0:
        if opts.signalMass != 0:
            p.histoMgr.forHisto(opts.signal, styles.getSignalStyleHToTB_M(opts.signalMass))

    if "QCD" in datasetsMgr.getAllDatasetNames():
        p.histoMgr.setHistoLegendLabelMany({
                "QCD": "QCD (MC)",
                })
    
    # Apply blinding of signal region
    if "blindingRangeString" in kwargs_:
        startBlind = float(kwargs_["blindingRangeString"].split("-")[1])
        endBlind   = float(kwargs_["blindingRangeString"].split("-")[0])
        plots.partiallyBlind(p, maxShownValue=startBlind, minShownValue=endBlind, invert=True, moveBlindedText=kwargs_["moveBlindedText"])

    # Draw and save the plot
    plots.drawPlot(p, saveName, **kwargs_) #the "**" unpacks the kwargs_ dictionary

    # Replace bin labels
    if "counter" in opts.folder and "counter" in histoName.split("/")[-1]:
        # p.getFrame().GetXaxis().LabelsOption("v") #vertical orientation of bin labels
        replaceBinLabels(p, saveName)
        #pass

    # Save the plots in custom list of saveFormats
    SavePlot(p, saveName, os.path.join(opts.saveDir, opts.optMode, opts.folder), [".png", ".pdf"] )
    return
def DataMCHistograms(datasetsMgr):
    Verbose("Plotting Data-MC Histograms")

    # Definitions
    histoNames  = []
    saveFormats = [".png"] #[".C", ".png", ".pdf"]

    # Get list of histograms
    dataPath    = "ForDataDrivenCtrlPlots"
    allHistos   = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(dataPath)
    histoList   = [h for h in allHistos if "StandardSelections" in h]
    histoList.extend([h for h in allHistos if "AllSelections" in h])
    histoList   = [h for h in histoList if "_MCEWK" not in h]
    histoList   = [h for h in histoList if "_Purity" not in h]
    histoPaths  = [dataPath + "/" + h for h in histoList]

    # Get histogram<->kwargs dictionary 
    histoKwargs = GetHistoKwargs(histoPaths, opts)

    # For-loop: All histograms in list
    for histoName in histoPaths:

        if "Mass" not in histoName:
        #if "LdgTetrajetMass" not in histoName:
            continue

        if "JetEtaPhi" in histoName:
            continue

        if opts.signalMass == 0:
            if "LdgTrijetMass" in histoName:
                continue
            
            if "LdgTetrajetMass" in histoName:
                continue

        if "Vs" in histoName:
            continue

        # Not used in this analysis (yet)
        if "MHT" in histoName:
            continue

        # By definition of the Inverted sample the following histos cannot agree!
        if "NBjets_" in histoName:
            continue
        if "BJetPt_" in histoName:
            continue
        if "_BJetEta_" in histoName:
            continue
        if "_BtagDiscriminator_" in histoName:
            continue

        kwargs_  = histoKwargs[histoName]
        saveName = histoName.replace("/", "_")

        # Create the plotting object
        p = plots.DataMCPlot(datasetsMgr, histoName, saveFormats=[])

        # Apply QCD data-driven style
        if opts.signalMass != 0:
            signal = "ChargedHiggs_HplusTB_HplusToTB_M_%.0f" % opts.signalMass
            mHPlus = "%s" % int(opts.signalMass)
            p.histoMgr.forHisto(signal, styles.getSignalStyleHToTB_M(mHPlus))

        #p.histoMgr.forHisto(opts.signalMass, styles.getSignalStyleHToTB())
        p.histoMgr.setHistoLegendLabelMany({
                "QCD": "QCD (MC)",
                })            

        # Apply blinding of signal region
        if "blindingRangeString" in kwargs_:
            startBlind = float(kwargs_["blindingRangeString"].split("-")[1])
            endBlind   = float(kwargs_["blindingRangeString"].split("-")[0])
            plots.partiallyBlind(p, maxShownValue=startBlind, minShownValue=endBlind, invert=True, moveBlindedText=kwargs_["moveBlindedText"])

        # Draw and save the plot
        plots.drawPlot(p, saveName, **kwargs_) #the "**" unpacks the kwargs_ dictionary
        SavePlot(p, saveName, os.path.join(opts.saveDir, opts.optMode), [".png"] )
    return