예제 #1
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    ROOT.gErrorIgnoreLevel = ROOT.kFatal  # [Options: Print, kInfo, kWarning, kError, kBreak, kSysError, kFatal]
    ROOT.gROOT.SetBatch()
    ROOT.gStyle.SetOptStat(0)
    ROOT.gStyle.SetOptTitle(0)
    ROOT.gStyle.SetNdivisions(5, "X")

    # Find GoF directories (generated by GoF.sh script)
    myDirs = []
    for d in os.listdir('.'):
        if not os.path.isdir(d):
            continue
        if "GoF_" in d:
            myDirs.append(d)

    if len(myDirs) < 1:
        raise Exception(
            "No goodness-of-fit directories found. Did your run the GoF.sh script to create them?"
        )
    else:
        Verbose(
            "Found %d GoF directories: %s" % (len(myDirs), ", ".join(myDirs)),
            True)

    # For-loop: All GoF directories
    myAlgos = []
    allowedAlgos = ["saturated", "KS",
                    "AD"]  # KS = Kolmogorov-Smirnov, AD = Anderson-Darling
    for d in myDirs:
        algo = d.split("_")[-1]
        if algo not in allowedAlgos:
            raise Exception(
                "The algorithm \"%s\" is invalid. Expected one of the following: %s"
                % (opts.algorithm, ", ".join(allowedAlgos)))
        else:
            myAlgos.append(algo)

    # For-loop: All GoF algorithms ran
    Print(
        "Found %d GoF algorithm results: %s" %
        (len(myDirs), ", ".join(myAlgos)), True)
    for i, algo in enumerate(myAlgos, 1):

        # Definitions
        opts.algorithm = algo
        opts.inputDir = "%s/GoF_%s" % (os.getcwd(), algo)
        opts.inputfile = "GoF_%s/higgsCombinetoys*.GoodnessOfFit.mH%s.*.root" % (
            algo, opts.mass)
        opts.outputfile = "GoF_%s/GoF_%s_mH%s.root" % (algo, algo, opts.mass)
        doPlots(i, opts)

    Verbose(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)

    return
예제 #2
0
def main():

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    # Enable/Disable grids for axes
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)

    # Enable/Disable logscale for axes
    style.setLogX(opts.logX)
    style.setLogY(opts.logY)

    # Definitions
    savePath = opts.saveDir
    if opts.url:
        savePath = opts.saveDir.replace(
            "/afs/cern.ch/user/a/attikis/public/html",
            "https://cmsdoc.cern.ch/~%s" % getpass.getuser())

    Verbose(
        "Load module for reading the BR limits from JSON file produced by Combine",
        True)

    # Definitions
    resultsList = []
    for i, d in enumerate(opts.dirList, 1):

        dirs = glob.glob(d)
        dirs.sort()
        if len(dirs) == 0:
            raise Exception("No directories for pattern '%s'" % path)
        directory = dirs[-1]

        Verbose("Picked %s" % directory, True)
        resultsList.append(_results.Output(directory, excludePoints=[]))

    # Do comparison plot
    msg = "Creating comparison plots (%d) using the following results directories:%s\n\t%s" % (
        len(opts.dirList), sh_t, "\n\t".join(
            [os.path.basename(d) for d in opts.dirList]))
    Print(msg + sh_n, True)
    if "output" in opts.plotType.lower():
        doOutput(opts.saveName, resultsList)
    elif "efficiency" in opts.plotType.lower():
        doEfficiency(opts.saveName, resultsList)
    elif "significance" in opts.plotType.lower():
        doSignificance(opts.saveName, resultsList)
    elif "roc" in opts.plotType.lower():
        doROC(opts.saveName, resultsList)
    else:
        pass

    # inform user of output location
    Print(
        "Plots saved under directory %s" %
        (sh_s + aux.convertToURL(opts.saveDir, opts.url) + sh_n), True)
    return
예제 #3
0
def doPlot(legList, graphList, saveName, **kwargs):

    # Definitions
    hgList = []
    lList = {}

    # For-loop: All TGraphs
    for i, g in enumerate(graphList, 0):
        if opts.boldText:
            gName = legList[i]
        else:
            gName = "#font[42]{%s}" % legList[i]
        hg = histograms.HistoGraph(graphList[i],
                                   gName,
                                   drawStyle="L",
                                   legendStyle="l")
        hgList.append(hg)

    # Create a plot-base object
    Verbose("Creating the plot-base object", True)
    # plot = plots.PlotBase(hgList, saveFormats=[])
    hgList.insert(0, hgList.pop(opts.refIndex))
    plot = plots.ComparisonManyPlot(hgList[0], hgList[1:], saveFormats=[])
    #plot = plots.ComparisonManyPlot(hgList[-1], hgList[:-1], saveFormats=[])

    # Apply histo style
    Verbose("Applying the histogram styles (generator)", True)
    plot.histoMgr.forEachHisto(styles.generator())

    # plot.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetMarkerSize(1.2))
    # plot.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineWidth(3))

    def sty(h):
        r = h.getRootHisto()
        r.SetLineWidth(3)
        r.SetMarkerSize(1.2)
        return

    # Apply style and set label
    Verbose("Applying the histogram styles (forEachHisto)", True)
    plot.histoMgr.forEachHisto(sty)
    if opts.plotType != "var":
        plot.setLegendHeader("Sequential Model (Keras)")

    # Draw the plot
    Verbose("Drawing the plot", True)
    plots.drawPlot(plot, saveName, **kwargs)
    if opts.removeLegend:
        plot.removeLegend()

    # Save plots and return
    Verbose("Saving the plot as %s" % (saveName), True)
    SavePlot(plot, opts.saveDir, saveName, opts.saveFormats)

    Verbose(
        "Plots saved under directory %s" %
        (sh_s + aux.convertToURL(opts.saveDir, opts.url) + sh_n), True)
    return
예제 #4
0
def SavePlot(plot, plotName, saveDir, saveFormats=[".C", ".png", ".pdf"]):
    if not os.path.exists(saveDir):
        os.makedirs(saveDir)

    # Create the name under which plot will be saved
    saveName = os.path.join(saveDir, plotName.replace("/", "_"))

    # For-loop: All save formats
    for i, ext in enumerate(saveFormats):
        saveNameURL = saveName + ext
        saveNameURL = aux.convertToURL(saveNameURL, opts.url)
        Print(saveNameURL, i == 0)
        plot.saveAs(saveName, formats=saveFormats)
    return
def SavePlot(plot, plotName, saveDir, saveFormats = [".C", ".png", ".pdf"]):
    if not os.path.exists(saveDir):
        os.makedirs(saveDir)

    # Create the name under which plot will be saved
    saveName = os.path.join(saveDir, plotName.replace("/", "_"))

    # For-loop: All save formats
    for i, ext in enumerate(saveFormats):
        saveNameURL = saveName + ext
        saveNameURL = aux.convertToURL(saveNameURL, opts.url)
        Print(saveNameURL, i==0)
        plot.saveAs(saveName, formats=saveFormats)
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(False)
    style.setGridY(False)

    # Setup & configure the dataset manager 
    datasetsMgr = GetDatasetsFromDir(opts, 0)
    datasetsMgr.updateNAllEventsToPUWeighted()
    datasetsMgr.loadLuminosities() # from lumi.json
        
    if opts.verbose:
        datasetsMgr.PrintCrossSections()
        datasetsMgr.PrintLuminosities()

    # Set/Overwrite cross-sections
    for d in datasetsMgr.getAllDatasets():
        if "ChargedHiggs" in d.getName():
            datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)

    # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
    if 1:
        plots.mergeRenameReorderForDataMC(datasetsMgr) 

    # Print datasets info summary
    datasetsMgr.PrintInfo()

    # Define the mapping histograms in numerator->denominator pairs
    VariableList = ["TetrajetMass"]

    counter =  0
    opts.nDatasets = len(datasetsMgr.getAllDatasets())
    nPlots  = len(VariableList)*opts.nDatasets

    # For-loop: All datasets
    for dataset in datasetsMgr.getAllDatasets():
        # For-looop: All variables
        for hName in VariableList:
            hPath = os.path.join(opts.folder, hName)

            counter+=1
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (nPlots), "%s" % (dataset.getName()))
            aux.Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)
        
            PlotHistos(dataset.getName(), hPath) # For each dataset: Plot histos from different multicrabs on same canvas

    aux.Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #7
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    ROOT.gErrorIgnoreLevel = ROOT.kFatal # [Options: Print, kInfo, kWarning, kError, kBreak, kSysError, kFatal]
    ROOT.gROOT.SetBatch()
    ROOT.gStyle.SetOptStat(0)
    ROOT.gStyle.SetOptTitle(0)
    ROOT.gStyle.SetNdivisions(5, "X")

    # Find GoF directories (generated by GoF.sh script)
    myDirs = []
    for d in os.listdir('.'):
        if not os.path.isdir(d):
            continue    
        if "GoF_" in d:
            myDirs.append(d)

    if len(myDirs) < 1:
        raise Exception("No goodness-of-fit directories found. Did your run the GoF.sh script to create them?" )
    else:
        Verbose("Found %d GoF directories: %s" % (len(myDirs), ", ".join(myDirs)), True)


    # For-loop: All GoF directories
    myAlgos = []
    allowedAlgos = ["saturated", "KS", "AD"] # KS = Kolmogorov-Smirnov, AD = Anderson-Darling
    for d in myDirs:
        algo = d.split("_")[-1]
        if algo not in allowedAlgos:
            raise Exception("The algorithm \"%s\" is invalid. Expected one of the following: %s" % (opts.algorithm, ", ".join(allowedAlgos)))
        else:
            myAlgos.append(algo)

    # For-loop: All GoF algorithms ran
    Print("Found %d GoF algorithm results: %s" % (len(myDirs), ", ".join(myAlgos)), True)
    for i, algo in enumerate(myAlgos, 1):

        # Definitions
        opts.algorithm  = algo
        opts.inputDir   = "%s/GoF_%s" % (os.getcwd(), algo)
        opts.inputfile  = "GoF_%s/higgsCombinetoys*.GoodnessOfFit.mH%s.*.root" % (algo, opts.mass)
        opts.outputfile = "GoF_%s/GoF_%s_mH%s.root" % (algo, algo, opts.mass)
        doPlots(i, opts)

    Verbose("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)

    return
def SavePlot(plot, plotName, saveDir, saveFormats = [".pdf", ".png", ".C"]):
    Verbose("Saving the plot in %s formats: %s" % (len(saveFormats), ", ".join(saveFormats) ) )
    
     # Check that path exists
    if not os.path.exists(saveDir):
        os.makedirs(saveDir)

    # Create the name under which plot will be saved
    saveName = os.path.join(saveDir, plotName.replace("/", "_"))

    # For-loop: All save formats
    for i, ext in enumerate(saveFormats):
        saveNameURL = saveName + ext
        saveNameURL = aux.convertToURL(saveNameURL, opts.url)
        Verbose(saveNameURL, i==0)
        plot.saveAs(saveName, formats=saveFormats)
    return
예제 #9
0
def SavePlot(plot, plotName, saveDir, saveFormats = [".C", ".png", ".pdf"]):
    Verbose("Saving the plot in %s formats: %s" % (len(saveFormats), ", ".join(saveFormats) ) )

     # Check that path exists
    if not os.path.exists(saveDir):
        os.makedirs(saveDir)

    # Create the name under which plot will be saved
    saveName = os.path.join(saveDir, plotName.replace("/", "_"))

    # For-loop: All save formats
    for i, ext in enumerate(saveFormats):
        saveNameURL = saveName + ext
        saveNameURL = aux.convertToURL(saveNameURL, opts.url)
        Print(saveNameURL, i==0)
        plot.saveAs(saveName, formats=saveFormats)

    # Something buggy introduced with "except" added in plots.py to fix the error when
    # using "divideByBinWidth" option with "addMCUncertainty" option. Must call exit otherwise hangs
    if opts.fitUncert:
        Print("EXIT!", True)
        os._exit(0) #sys.exit()
    return
예제 #10
0
def SavePlot(plot, plotName, saveDir, saveFormats = [".C", ".png", ".pdf"]):
    Verbose("Saving the plot in %s formats: %s" % (len(saveFormats), ", ".join(saveFormats) ) )

     # Check that path exists
    if not os.path.exists(saveDir):
        os.makedirs(saveDir)

    # Create the name under which plot will be saved
    saveName = os.path.join(saveDir, plotName.replace("/", "_"))

    # For-loop: All save formats
    for i, ext in enumerate(saveFormats):
        saveNameURL = saveName + ext
        saveNameURL = aux.convertToURL(saveNameURL, opts.url)
        Print(saveNameURL, i==0)
        plot.saveAs(saveName, formats=saveFormats)

    # Something buggy introduced with "except" added in plots.py to fix the error when
    # using "divideByBinWidth" option with "addMCUncertainty" option. Must call exit otherwise hangs
    if opts.fitUncert:
        Print("EXIT!", True)
        os._exit(0) #sys.exit()
    return
예제 #11
0
def main(opts):

    optModes = [""]
    if opts.optMode != None:
        optModes = [opts.optMode]

    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities(fname="lumi.json")

        # Get Luminosity
        if opts.intLumi < 0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = datasetsMgr.loadLumi()

        # Set/Overwrite cross-sections
        datasetsToRemove = []
        for d in datasetsMgr.getAllDatasets():
            mass = "M_%s" % (opts.signalMass)
            if mass in d.getName():
                if ("%s" % opts.signalMass) != d.getName().split("M_")[-1]:
                    datasetsMgr.remove(d.getName())
                else:
                    datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)
            else:
                #datasetsToRemove.append(d.getName())
                datasetsMgr.remove(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        #         # Custom Filtering of datasets
        #         for i, d in enumerate(datasetsToRemove, 0):
        #             msg = "Removing dataset %s" % d
        #             Verbose(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0)
        #             datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames()))

        if opts.verbose:
            datasetsMgr.PrintInfo()

        # Merge EWK samples
        if opts.mergeEWK:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Apply TDR style
        style = tdrstyle.TDRStyle()
        style.setOptStat(True)
        style.setGridX(opts.gridX)
        style.setGridY(opts.gridY)

        # Do Data-MC histograms with DataDriven QCD
        folder = opts.folder
        histoList = datasetsMgr.getDataset(
            datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths = [os.path.join(folder, h) for h in histoList]
        keepList = ["LdgTetrajetMass_AfterAllSelections"]
        #keepList   = ["LdgTetrajetMass_AfterStandardSelections"]
        myHistos = []
        for h in histoPaths:
            if h.split("/")[-1] not in keepList:
                continue
            else:
                myHistos.append(h)

        for i, h in enumerate(myHistos, 1):
            PlotHistograms(datasetsMgr, h)

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
예제 #12
0
def main(opts):
    
    # Suppress warnings about weight being re-applied
    ROOT.gErrorIgnoreLevel = ROOT.kError 

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()
    
    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    opts.optMode = ""
    mcrabName    = opts.mcrab
    RunEra       = mcrabName.split("_")[1]

    # Setup ROOT and style
    ROOT.gROOT.SetBatch(opts.batchMode)
    style = tdrstyle.TDRStyle()
    style.setOptStat(True)
    style.setGridX(True)
    style.setGridY(True)
    
    # Setup & configure the dataset manager
    datasetsMgr = GetDatasetsFromDir(opts)

    # Remove some QCD samples (the cross sections of these samples are not calculated)
    if 0:
        msg = "Removing following samples:"
        Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(), True)
        for d in getDatasetsToExclude():
            Print(d, False)
            datasetsMgr.remove(d)

    # Get run-range 
    minRunRange, maxRunRange, runRange = GetRunRange(datasetsMgr)

    # Get int lumi
    intLumi  = GetLumi(datasetsMgr)

    # Update to PU & load luminosities 
    datasetsMgr.updateNAllEventsToPUWeighted()
    datasetsMgr.loadLuminosities()
    #datasetsMgr.normalizeMCByLuminosity()

    # Print luminisoties and cross-sections
    datasetsMgr.PrintLuminosities()
    datasetsMgr.PrintCrossSections()

    # Default merging & ordering: "Data", "QCD", "SingleTop", "Diboson"
    plots.mergeRenameReorderForDataMC(datasetsMgr)
    
    # Get datasets
    datasetsMgr.mergeMC()
    dataset_Data = datasetsMgr.getDataDatasets()
    dataset_MC   = datasetsMgr.getMCDatasets()

    # Define lists of Triggers to be plotted and Variables 
    xVars   = ["pt6thJet", "eta6thJet", "phi6thJet", "Ht", "nBTagJets", "pu", "JetMulti", "BJetMulti"]
    trgList = ["1BTag", "2BTag", "OR", "OR_PFJet450"]
    if opts.fast:
        trgList = ["OR_PFJet450"]
        xVars   = ["pt6thJet", "Ht"]
    nPlots  = len(trgList)*len(xVars)
    counter =  0

    # For-loop: All signal triggers
    for i, trg in enumerate(trgList, 1):
        
        # For-loop: All x-variables
        for j, xVar in enumerate(xVars, 1):
            counter+=1
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (nPlots), "%s Vs %s" % (trg, xVar))
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)


            # Define names
            hNumerator   = "hNum_%s_RefTrg_OfflineSel_Signal%s" % (xVar, trg)
            hDenominator = "hDen_%s_RefTrg_OfflineSel" % (xVar)
            plotName     = "Eff_%s_%s" % (xVar, trg)
            
            # Get Efficiency Plots
            _kwargs  = GetHistoKwargs(xVar, opts)
            eff_Data = GetEfficiency(datasetsMgr, dataset_Data, hNumerator, hDenominator , **_kwargs)
            eff_MC   = GetEfficiency(datasetsMgr, dataset_MC, hNumerator, hDenominator, **_kwargs) 
                       
            # Apply Styles
            styles.dataStyle.apply(eff_Data)
            styles.mcStyle.apply(eff_MC)
        
            # Create the plot
            p = plots.ComparisonPlot(histograms.HistoGraph(eff_Data, "eff_Data", "p", "P"),
                                     histograms.HistoGraph(eff_MC,   "eff_MC"  , "p", "P"),
                                     saveFormats=[])                  

            # Define the legend entries
            p.histoMgr.setHistoLegendLabelMany(
                {
                    "eff_Data": "Data", 
                    "eff_MC"  : "Simulation"
                    }
                )
            
            # Draw and save the plot
            p.setLuminosity(intLumi)
            plots.drawPlot(p, plotName, **_kwargs)
                                                   
            # Draw
            histograms.addText(0.65, 0.06, "Runs "+ runRange, 17)
            histograms.addText(0.65, 0.10, "2016", 17)

            # Save the canvas to a file
            SavePlot(p, plotName, os.path.join(opts.saveDir, opts.optMode), saveFormats=[".pdf", ".png", ".C"] )

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(False)
    style.setGridY(False)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab1)
    
    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Get the datasets from the directory
        datasetsMgr1 = GetDatasetsFromDir(opts.mcrab1, opts)
        datasetsMgr2 = GetDatasetsFromDir(opts.mcrab2, opts)
        datasetsMgr3 = GetDatasetsFromDir(opts.mcrab3, opts)
        
        # Setup the dataset managers
        datasetsMgr1.updateNAllEventsToPUWeighted()
        datasetsMgr1.loadLuminosities() # from lumi.json
        datasetsMgr2.updateNAllEventsToPUWeighted()
        datasetsMgr2.loadLuminosities() # from lumi.json
        datasetsMgr3.updateNAllEventsToPUWeighted()
        datasetsMgr3.loadLuminosities() # from lumi.json

        # Print dataset info?
        if opts.verbose:

            datasetsMgr1.PrintCrossSections()
            datasetsMgr1.PrintLuminosities()

            datasetsMgr2.PrintCrossSections()
            datasetsMgr2.PrintLuminosities()

            datasetsMgr2.PrintCrossSections()
            datasetsMgr2.PrintLuminosities()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr1) 
        plots.mergeRenameReorderForDataMC(datasetsMgr2) 
        plots.mergeRenameReorderForDataMC(datasetsMgr3) 
        
        # Get Luminosity
        lumi1 = datasetsMgr1.getDataset("Data").getLuminosity()
        lumi2 = datasetsMgr2.getDataset("Data").getLuminosity()
        lumi3 = datasetsMgr3.getDataset("Data").getLuminosity()
        if lumi1 != lumi2 != lumi3:
            raise Exception("Lumi1 (=%.2f) != Lumi2 (=%.2f) != Lumi3 (=%.2f" % (lumi1, lumi2, lumi3))
        else:
            opts.intLumi = datasetsMgr1.getDataset("Data").getLuminosity()
   
        # Merge EWK samples
        datasetsMgr1.merge("EWK", aux.GetListOfEwkDatasets())
        datasetsMgr2.merge("EWK", aux.GetListOfEwkDatasets())
        datasetsMgr3.merge("EWK", aux.GetListOfEwkDatasets())
        plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr1.PrintInfo()
        if 0:
            datasetsMgr2.PrintInfo()
            datasetsMgr3.PrintInfo()

        # Get all the histograms and their paths (e.g. ForFakeBMeasurement/Baseline_DeltaRLdgTrijetBJetTetrajetBJet_AfterCRSelections)
        hList  = datasetsMgr1.getDataset(datasetsMgr1.getAllDatasetNames()[0]).getDirectoryContent(opts.folder)
        hPaths = [os.path.join(opts.folder, h) for h in hList]

        # Create a smaller list with only histos of interest
        hListS = []
        for h in hList:
            if "StandardSelections" in h:
                continue
            if "IsGenuineB" in h:
                continue
            if "_Bjet" in h:
                continue
            if "_Jet" in h:
                continue
            if "_SubLdg" in h:
                continue
            if "_Njets" in h:
                continue
            if "_NBjets" in h:
                continue
            if "_Delta" in h:
                continue
            if "Dijet" in h:
                continue
            if "Bdisc" in h:
                continue
            #if "MVA" in h:
            #    continue
            if "MET" in h:
                continue
            if "HT" in h:
                continue
            # Otherwise keep the histogram
            hListS.append(h)

        hPathsS = [os.path.join(opts.folder, h) for h in hListS]
        
        # Create two lists of paths: one for "Baseline" (SR)  and one for "Inverted" (CR)
        path_SR  = []  # baseline, _AfterAllSelections
        path_CR1 = []  # baseline, _AfterCRSelections
        path_VR  = []  # inverted, _AfterAllSelections
        path_CR2 = []  # inverted, _AfterCRSelections

        # For-loop: All histogram paths
        for p in hPathsS: #hPaths:
            if "Baseline" in p:
                if "AllSelections" in p:
                    path_SR.append(p)
                if "CRSelections" in p:
                    path_CR1.append(p)
            if "Inverted" in p:
                if "AllSelections" in p:
                    path_VR.append(p)
                if "CRSelections" in p:
                    path_CR2.append(p)

        counter = 1
        # For-loop: All histogram pairs
        for hCR1, hCR2 in zip(path_CR1, path_CR2):
            if "IsGenuineB" in hCR1:
                continue
            #hName = hCR1.replace("_AfterCRSelections", "_CR1vCR2").replace("ForFakeBMeasurement/Baseline_", "")
            hName = hCR1.replace("_AfterCRSelections", " (CR1 and R2)").replace("ForFakeBMeasurement/Baseline_", "")
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)), hName)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)

            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hCR1, hCR2, "CR1")
            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hCR1, hCR2, "CR2") #iro
            counter+=1

        
        # WARNING! This unblinds the Signal Region (SR)        
        for hSR, hVR in zip(path_SR, path_VR):
            if "IsGenuineB" in hSR:
                continue
            if 1:
                continue
            #hName = hCR1.replace("_AfterCRSelections", "_SRvVR").replace("ForFakeBMeasurement/Baseline_", "")
            hName = hCR1.replace("_AfterCRSelections", " (SR and VR)").replace("ForFakeBMeasurement/Baseline_", "")
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)), hName)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)

            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hSR, hVR, "SR")
            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hSR, hVR, "VR")
            counter+=1

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #14
0
def main(opts):

    #optModes = ["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"]
    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json

        datasetsMgr_matched = GetDatasetsFromDir(opts)
        datasetsMgr_matched.updateNAllEventsToPUWeighted()
        datasetsMgr_matched.loadLuminosities() # from lumi.json

        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        datasetsMgr.remove(filter(lambda name: "QCD_b" in name, datasetsMgr.getAllDatasetNames())) #soti
        datasetsMgr_matched.remove(filter(lambda name: "QCD" in name, datasetsMgr_matched.getAllDatasetNames())) #soti
        # Set/Overwrite cross-sections
        datasetsToRemove = ["QCD-b"]#, "QCD_HT50to100", "QCD_HT100to200"]#, "QCD_HT200to300"]#, "QCD_HT300to500"]
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits
                #if d.getName() != opts.signal:
                if "M_650" in d.getName():  #soti fixmi
                    datasetsToRemove.append(d.getName())
                if "M_800" in d.getName():
                    datasetsToRemove.append(d.getName())
                if "M_200" in d.getName():
                    datasetsToRemove.append(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Custom Filtering of datasets 
        for i, d in enumerate(datasetsToRemove, 0):
            msg = "Removing dataset %s" % d
            Print(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0)
            datasetsMgr.remove(filter(lambda name: d in name, datasetsMgr.getAllDatasetNames()))
            datasetsMgr_matched.remove(filter(lambda name: d in name, datasetsMgr_matched.getAllDatasetNames())) #soti
        if opts.verbose:
            datasetsMgr.PrintInfo()

        # ZJets and DYJets overlap
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))


        #datasetsMgr.merge("QCD", GetListOfQCDatasets())
        #plots._plotStyles["QCD"] = styles.getQCDLineStyle()
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        # Get Luminosity
        #intLumi = datasetsMgr.getDataset("Data").getLuminosity() Soti
        intLumi = 35920

        # Re-order datasets (different for inverted than default=baseline)

        newOrder = []
        # For-loop: All MC datasets
        for d in datasetsMgr.getMCDatasets():
            newOrder.append(d.getName())
        
        # Move signal to top
#        if opts.signal in newOrder:
#            s = newOrder.pop( newOrder.index(opts.signal) )
#            newOrder.insert(0, s)
        print len(newOrder), "newOrder"
        signalMass = ["M_300", "M_500", "M_1000"]
        for d in datasetsMgr.getMCDatasets():
            for m in signalMass:
                if m in d.getName():
                    s = newOrder.pop( newOrder.index(d.getName()) )
                    newOrder.insert(0, s)
                    #datasetsMgr.selectAndReorder(newOrder)
        print len(newOrder), "newOrder"
        # Add Data to list of samples!
        if not opts.onlyMC:
            newOrder.insert(0, "Data")
            
        # Apply new dataset order!
        datasetsMgr.selectAndReorder(newOrder)

        # Merge EWK samples
        if opts.mergeEWK:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()
        
        # Apply TDR style
        style = tdrstyle.TDRStyle()
        style.setOptStat(True)
        style.setGridX(opts.gridX)
        style.setGridY(opts.gridY)

        # Do Data-MC histograms with DataDriven QCD
        folder     = opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths1 = [os.path.join(folder, h) for h in histoList]
        histoPaths2 = [h for h in histoPaths1]# if "jet" not in h.lower()]
        nHistos     = len(histoPaths2)

        # For-loop: All histograms
        for i, h in enumerate(histoPaths2, 1):
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (nHistos), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)
            PlotHistograms(datasetsMgr, datasetsMgr_matched, h, intLumi)
        ROOT.gStyle.SetNdivisions(10, "X")
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #15
0
def main(opts):

    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setLogX(opts.logX)
    style.setLogY(opts.logY)
    style.setLogZ(opts.logZ)
    style.setWide(True, 0.15)
    # style.setPadRightMargin()#0.13)

    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities()  # from lumi.json
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        # Print merged datasets and MC samples
        if 0:
            datasetsMgr.PrintInfo()

        # Get Luminosity
        if opts.intLumi < 0:
            opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()

        # Merge EWK samples
        if opts.dataset == "EWK":
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Re-order datasets (different for inverted than default=baseline)
        newOrder = []
        for d in datasetsMgr.getAllDatasets():
            if d.getName() == opts.dataset:
                newOrder.append(d.getName())

        # Sanity check on selected dataset
        nDatasets = len(newOrder)
        if nDatasets < 1:
            msg = "Please select a valid dataset. Dataset \"%s\" does not exist!" % (
                opts.dataset)
            Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(),
                  True)
            datasetsMgr.PrintInfo()
            sys.exit()
        if nDatasets > 1:
            msg = "Please select only 1 valid dataset. Requested %i datasets for plotting!" % (
                nDatasets)
            Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(),
                  True)
            datasetsMgr.PrintInfo()
            sys.exit()

        # Select only given dataset
        datasetsMgr.selectAndReorder(newOrder)

        # Print dataset information
        msg = "Plotting for single dataset \"%s\". Integrated luminosity is %.2f 1/fb" % (
            opts.dataset, opts.intLumi)
        Print(ShellStyles.NoteStyle() + msg + ShellStyles.NormalStyle(), True)
        datasetsMgr.PrintInfo()

        # Get list of histogram paths
        folder = opts.folder
        histoList = datasetsMgr.getDataset(
            datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths = [os.path.join(folder, h) for h in histoList]

        # For-loop: All histograms
        for h in histoPaths:
            if "_vs_" not in h.lower():
                continue
            Plot2dHistograms(datasetsMgr, h)

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList = dsetMgrCreator.getDataEras()
    modesList = dsetMgrCreator.getSearchModes()
    optList = dsetMgrCreator.getOptimizationModes()
    sysVarList = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities()  # from lumi.json

        # Print PSets used for FakeBMeasurement
        if 0:
            datasetsMgr.printSelections()

        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ZJetsToQQ_HT600toInf" in d.getName():
                datasetsMgr.remove(d.getName())

            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)
                if d.getName() not in opts.signal:
                    if not opts.acceptance:
                        datasetsMgr.remove(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        # Get Luminosity
        # For acceptance plot use all available masses
        if opts.acceptance:
            opts.signal = []
            opts.signalMasses = []
            for d in datasetsMgr.getAllDatasets():
                if "ChargedHiggs" in d.getName():
                    #dName = d.getName().replace("_ext1", "").split("M_")
                    dName = d.getName().split("M_")
                    m = int(dName[-1])
                    opts.signal.append(d.getName())
                    opts.signalMasses.append(m)

        if opts.intLumi < 0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = 1.0

        # Merge EWK samples
        if 1:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print post EWK-merge dataset summary
        datasetsMgr.PrintInfo()

        # Get the efficiency graphs
        hGraphList = []
        histoName = os.path.join(opts.folder, "counter")
        hGraphList, _kwargs = GetHistoGraphs(datasetsMgr, opts.folder,
                                             histoName)

        # Plot the histo graphs
        PlotHistoGraphs(hGraphList, _kwargs)

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
예제 #17
0
def main(opts):
    
    # Suppress warnings about weight being re-applied
    ROOT.gErrorIgnoreLevel = ROOT.kError 

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()
    
    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    opts.optMode = ""
    mcrabName    = opts.mcrab
    RunEra       = mcrabName.split("_")[1]

    # Setup ROOT and style
    ROOT.gROOT.SetBatch(opts.batchMode)
    style = tdrstyle.TDRStyle()
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    if opts.paper:
        style.setGridX(False)
        style.setGridY(False)
    
    # Setup & configure the dataset manager
    datasetsMgr = GetDatasetsFromDir(opts)

    # Remove some QCD samples (the cross sections of these samples are not calculated)
    if 0:
        msg = "Removing following samples:"
        Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(), True)
        for d in getDatasetsToExclude():
            Print(d, False)
            datasetsMgr.remove(d)

    # Get run-range 
    minRunRange, maxRunRange, runRange = GetRunRange(datasetsMgr)

    # Get int lumi
    intLumi  = GetLumi(datasetsMgr)

    # Update to PU & load luminosities 
    datasetsMgr.updateNAllEventsToPUWeighted()
    datasetsMgr.loadLuminosities()
    #datasetsMgr.normalizeMCByLuminosity()

    # Print luminisoties and cross-sections
    datasetsMgr.PrintLuminosities()
    datasetsMgr.PrintCrossSections()

    # Default merging & ordering: "Data", "QCD", "SingleTop", "Diboson"
    plots.mergeRenameReorderForDataMC(datasetsMgr)
    
    # Get datasets
    datasetsMgr.mergeMC()
    dataset_Data = datasetsMgr.getDataDatasets()
    dataset_MC   = datasetsMgr.getMCDatasets()

    # Define lists of Triggers to be plotted and Variables 
    xVars   = ["pt6thJet", "eta6thJet", "phi6thJet", "Ht", "nBTagJets", "pu", "JetMulti", "BJetMulti"]
    trgList = ["1BTag", "2BTag", "OR", "OR_PFJet450"]
    if opts.fast:
        trgList = ["OR_PFJet450"]
        xVars   = ["pt6thJet", "Ht"]
    nPlots  = len(trgList)*len(xVars)
    counter =  0

    # For-loop: All signal triggers
    for i, trg in enumerate(trgList, 1):
        
        # For-loop: All x-variables
        for j, xVar in enumerate(xVars, 1):
            counter+=1
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (nPlots), "%s Vs %s" % (trg, xVar))
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)


            # Define names
            hNumerator   = "hNum_%s_RefTrg_OfflineSel_Signal%s" % (xVar, trg)
            hDenominator = "hDen_%s_RefTrg_OfflineSel" % (xVar)
            plotName     = "Eff_%s_%s" % (xVar, trg)
            
            # Get Efficiency Plots
            _kwargs  = GetHistoKwargs(xVar, opts)
            eff_Data = GetEfficiency(datasetsMgr, dataset_Data, hNumerator, hDenominator , **_kwargs)
            eff_MC   = GetEfficiency(datasetsMgr, dataset_MC, hNumerator, hDenominator, **_kwargs) 
                       
            # Apply Styles
            styles.dataStyle.apply(eff_Data)
            styles.mcStyle.apply(eff_MC)
        
            # Create the plot
            p = plots.ComparisonPlot(histograms.HistoGraph(eff_Data, "eff_Data", "p", "P"),
                                     histograms.HistoGraph(eff_MC,   "eff_MC"  , "p", "P"),
                                     saveFormats=[])                  

            # Define the legend entries
            p.histoMgr.setHistoLegendLabelMany(
                {
                    "eff_Data": "Data", 
                    "eff_MC"  : "Simulation"
                    }
                )
            
            # Draw and save the plot
            p.setLuminosity(intLumi)
            plots.drawPlot(p, plotName, **_kwargs)
                                                   
            # Draw
            histograms.addText(0.65, 0.06, "Runs "+ runRange, 17)
            histograms.addText(0.65, 0.10, "2016", 17)

            # Save the canvas to a file
            SavePlot(p, plotName, os.path.join(opts.saveDir, opts.optMode), saveFormats=[".pdf", ".png", ".C"] )

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(True) #opts.gridX)
    style.setGridY(True) #opts.gridY)
    style.setLogX(False) #opts.logX)
    style.setLogY(False) #opts.logY)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json

        if 0:
            datasetsMgr.printSelections()
        
        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            
        # Custom Filtering of datasets 
        if 0:
            datasetsMgr.remove(filter(lambda name: "Charged" in name and not "M_500" in name, datasetsMgr.getAllDatasetNames()))

        # ZJets and DYJets overlap!
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))
               
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        datasetsMgr.PrintInfo()
   
        # Get Luminosity
        if opts.intLumi < 0.0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = 1.0

        # Merge EWK samples
        if opts.dataset == "EWK":
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Get all histogram names in the given ROOT folder
        histoNames = datasetsMgr.getAllDatasets()[0].getDirectoryContent(opts.folder)
        histoList_ = [os.path.join(opts.folder, h) for h in histoNames if "_SR" in h]
        histoList  = [h for h in histoList_ if "Pt" in h] + [h for h in histoList_ if "Eta" in h]

        # For-loop: All histos in SR
        nHistos = len(histoList)
        for i, h in enumerate(histoList, 1):

            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i,"/", "%s:" % (nHistos), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)
            # print "*** h = ", h
            PlotHistograms(datasetsMgr, h)
            #break

    # Inform user where the plots where saved
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #19
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(False)
    style.setGridY(False)
    style.setOptStat(False)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList = dsetMgrCreator.getDataEras()
    modesList = dsetMgrCreator.getSearchModes()
    optList = dsetMgrCreator.getOptimizationModes()
    sysVarList = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities()  # from lumi.json

        if 0:
            datasetsMgr.printSelections()
            # PrintPSet("BJetSelection", datasetsMgr)
            # PrintPSet("TopSelectionBDT", datasetsMgr)
            # PrintPSet("FakeBMeasurement", datasetsMgr)
            sys.exit()

        # Print dataset info?
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Set signal cross-section
        if 0:
            datasetsMgr.getDataset(opts.signal).setCrossSection(1.0)

        # Remove unwanted datasets
        if 0:
            datasetsMgr.remove(
                filter(lambda name: "QCD-b" in name,
                       datasetsMgr.getAllDatasetNames()))

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        # Get Luminosity
        opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()

        # Merge EWK samples
        datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
        plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Get all the histograms and their paths (e.g. ForFakeBMeasurement/Baseline_DeltaRLdgTrijetBJetTetrajetBJet_AfterCRSelections)
        hList = datasetsMgr.getDataset(
            datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(
                opts.folder)
        hPaths = [os.path.join(opts.folder, h) for h in hList]

        # Create two lists of paths: one for "Baseline" (SR)  and one for "Inverted" (CR)
        path_SR = []  # baseline, _AfterAllSelections
        path_CR1 = []  # baseline, _AfterCRSelections
        path_VR = []  # inverted, _AfterAllSelections
        path_CR2 = []  # inverted, _AfterCRSelections

        # For-loop: All histogram paths
        for p in hPaths:
            if "AfterStandardSelections" in p:
                #print p
                continue

            if "Baseline" in p:
                if "AllSelections" in p:
                    path_SR.append(p)
                if "CRSelections" in p:
                    path_CR1.append(p)
            if "Inverted" in p:
                if "AllSelections" in p:
                    path_VR.append(p)
                if "CRSelections" in p:
                    path_CR2.append(p)

        # For-loop: All histogram pairs
        for hVR, hCR2, hCR1 in zip(path_VR, path_CR2, path_CR1):
            break  # not needed now
            if "IsGenuineB" in hVR:
                continue
            PlotComparison(datasetsMgr, hVR, hCR2, "VRvCR2")

        # For-loop: All histogram pairs
        counter = 1
        for hCR1, hCR2 in zip(path_CR1, path_CR2):
            if "IsGenuineB" in hCR1:
                continue

            hName = hCR1.replace("_AfterCRSelections", "_CR1vCR2").replace(
                "ForFakeBMeasurement/Baseline_", "")
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format(
                "Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)),
                hName)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(),
                  counter == 1)
            PlotComparison(datasetsMgr, hCR1, hCR2, "CR1vCR2")
            counter += 1

        # For-loop: All histogram pairs
        for hSR, hVR in zip(path_SR, path_VR):
            break
            Print("UNBLINDING SR! Are you nuts ? BREAK!", False)
            if "IsGenuineB" in hSR:
                continue
            PlotComparison(datasetsMgr, hSR, hVR, "SRvVR")


#        # For-loop: All histogram pairs
#        for hSR, hCR1 in zip(path_SR, path_CR1):
#            #break
#            Print("UNBLINDING SR! Are you nuts ? BREAK!", False)
#            raw_input("Press any key to continue")
#            if "IsGenuineB" in hSR:
#                continue
#            PlotComparison(datasetsMgr, hSR, hCR1, "SRvCR1")

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
예제 #20
0
def main(opts):

    #optModes = ["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"]
    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json

        if 0:
            datasetsMgr.printSelections()
            sys.exit()

        # Define datasets to remove by default
        QCD_list = ["QCD_HT700to1000", "QCD_HT50to100", "QCD_HT500to700", "QCD_HT300to500", 
                    "QCD_HT200to300", "QCD_HT2000toInf", "QCD_HT1500to2000", "QCD_HT100to200", "QCD_HT1000to1500"]
        QCDExt_list = [x+"_ext1" for x in QCD_list]
        datasetsToRemove = ["QCD-b"]
        # datasetsToRemove.extend(QCD_list)
        # datasetsToRemove.extend(QCDExt_list)

        # ZJets and DYJets overlap
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))
            #datasetsMgr.remove(filter(lambda name: "DYJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))
        
        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits
                if d.getName() != opts.signal:
                    datasetsToRemove.append(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 

        # Custom Filtering of datasets 
        for i, d in enumerate(datasetsToRemove, 0):
            msg = "Removing dataset %s" % d
            Verbose(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0)
            datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames()))

        if opts.verbose:
            datasetsMgr.PrintInfo()
  
        # Re-order datasets (different for inverted than default=baseline)
        newOrder = ["Data"]
        for i, d in enumerate(datasetsMgr.getAllDatasets(), 0):
            if d.isData():
                continue
            else:
                newOrder.append(d.getName())

        # Re-arrange dataset order?
        if 0:
            s = newOrder.pop( newOrder.index("noTop") )
            newOrder.insert(len(newOrder), s) #after "Data"

        # Move signal to top
        if opts.signal in newOrder:
            s = newOrder.pop( newOrder.index(opts.signal) )
            newOrder.insert(1, s)
        datasetsMgr.selectAndReorder(newOrder)
        
        # Merge EWK samples
        if opts.mergeEWK:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Apply TDR style
        style = tdrstyle.TDRStyle()
        style.setOptStat(True)
        style.setGridX(opts.gridX)
        style.setGridY(opts.gridY)

        # Do Data-MC histograms with DataDriven QCD
        folder     = opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)        
        histoPaths = [os.path.join(folder, h) for h in histoList]
        ignoreList = ["Aplanarity", "Planarity", "Sphericity", "FoxWolframMoment", "Circularity", "ThirdJetResolution", "Centrality", "_Vs_"]
        myHistos   = []
        for h in histoPaths:
            skip = False

            # Skip unwanted histos
            for i in ignoreList:
                if i in h:
                    skip = True

            if skip:
                continue
            else:
                myHistos.append(h)

        for i, h in enumerate(myHistos, 1):
            # Plot the histograms!
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(myHistos)), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)

            DataMCHistograms(datasetsMgr, h)
        
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)    
    return
예제 #21
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(False)
    style.setGridY(False)
    style.setOptStat(False)
    
    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json
        
        if 0:
            datasetsMgr.printSelections()
        
        # Print PSets used for FakeBMeasurement
        if 0:
            datasetsMgr.printSelections()
            PrintPSet("BJetSelection", datasetsMgr)
            PrintPSet("TopSelectionBDT", datasetsMgr)
            PrintPSet("FakeBMeasurement", datasetsMgr)
            sys.exit()

        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()

        # Filter the datasets 
        datasetsMgr.remove(filter(lambda name: "Charged" in name, datasetsMgr.getAllDatasetNames()))
        # datasetsMgr.remove(filter(lambda name: "Charged" in name and not "M_500" in name, datasetsMgr.getAllDatasetNames()))

        # ZJets and DYJets overlap!
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))
               
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 

        # Get Luminosity
        if opts.intLumi < 0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = 1.0

        # Re-order datasets (different for inverted than default=baseline)
        if 0:
            newOrder = ["Data"]
            newOrder.extend(aux.GetListOfEwkDatasets())
            datasetsMgr.selectAndReorder(newOrder)

        # Print post-merged data dataset summary
        if 0:
            datasetsMgr.PrintInfo()

        # Merge EWK samples
        datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
        plots._plotStyles["EWK"] = styles.getAltEWKStyle()
            
        # Print post EWK-merge dataset summary
        if 1:
            datasetsMgr.PrintInfo()

        # Get all histograms from the  in the selected folder inside the ROOT files 
        allHistos = datasetsMgr.getAllDatasets()[0].getDirectoryContent(opts.folder)
        hList     = [h for h in allHistos if "CRSelections" in h and "_Vs" not in h]
        hList.extend([h for h in allHistos if "AllSelections" in h and "_Vs" not in h])
        # hList.extend([h for h in allHistos if "StandardSelections" in h and "_Vs" not in h])

        # Create a list with strings included in the histogram names you want to plot
        myHistos = ["LdgTrijetPt", "LdgTrijetMass",  "TetrajetBJetPt", "TetrajetBJetEta", "LdgTetrajetPt", "LdgTetrajetMass", "MVAmax2", "MVAmax1", "HT", "MET"]
        
        # For-loop: All histos
        for i, h in enumerate(myHistos, 1):
            hGraphList = []
            for b in ["Baseline_", "Inverted_"]:
                for r in [ "_AfterCRSelections", "_AfterAllSelections"]:
                    histoName = b + h + r
                    hgQCD, kwargs = GetPurityHistoGraph(datasetsMgr, opts.folder, histoName)

                    # Do not draw SR in multigraph plot!
                    if GetControlRegionLabel(histoName) != "SR":
                        hGraphList.append(hgQCD)

                    # Plot individual purity graphs?
                    if 0:
                        PlotHistoGraph(hgQCD, kwargs)

            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(myHistos)), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)
            PlotHistoGraphs(hGraphList, kwargs)
    
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #22
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(False)
    style.setGridY(False)
    
    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager for pseudo-multicrab with default matching definition
        datasetsMgr_default = GetDatasetsFromDir(opts, opts.mcrab)
        datasetsMgr_default.updateNAllEventsToPUWeighted()
        datasetsMgr_default.loadLuminosities()
        
        datasetsMgr_second = GetDatasetsFromDir(opts, opts.mcrab2)
        datasetsMgr_second.updateNAllEventsToPUWeighted()
        datasetsMgr_second.loadLuminosities()
        
        if opts.verbose:
            datasetsMgr_default.PrintCrossSections()
            datasetsMgr_default.PrintLuminosities()

        # Print datasets info summary
        datasetsMgr_default.PrintInfo()
        datasetsMgr_second.PrintInfo()
        
        Numerator = ["AllTopQuarkPt_MatchedBDT",
                     "TrijetFakePt_BDT",
                     "AllTopQuarkPt_MatchedBDT",
                     "AllTopQuarkPt_Matched",
                     ]
        Denominator = ["AllTopQuarkPt_Matched",
                       "TrijetFakePt",
                       "TopQuarkPt",
                       "TopQuarkPt",
                       ]

        eff_def = ["genuineTop",
                   "fakeTop",
                   "inclusiveTop",
                   "matching",
                   ]
        
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr_default) 
        plots.mergeRenameReorderForDataMC(datasetsMgr_default)
        
        counter =  0
        opts.nDatasets = len(datasetsMgr_default.getAllDatasets())
        nPlots  = len(Numerator)
        # For-loop: All numerator-denominator pairs

        for i in range(len(Numerator)):
            
            numerator   = os.path.join(opts.folder, Numerator[i])
            denominator = os.path.join(opts.folder, Denominator[i])
            counter+=1
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50} {:<2} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (nPlots), "%s" % (numerator), "/", "%s" % (denominator))
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)
            PlotEfficiency(datasetsMgr_default, datasetsMgr_second, numerator, denominator, eff_def[i])
            
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #23
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setOptStat(False)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)
    
    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json

        if 0:
            datasetsMgr.printSelections()
            # PrintPSet("BJetSelection", datasetsMgr)
            # PrintPSet("TopSelectionBDT", datasetsMgr)
            # PrintPSet("FakeBMeasurement", datasetsMgr)
            sys.exit()

        # Print dataset info?
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Set signal cross-section
        if 0:
            datasetsMgr.getDataset(opts.signal).setCrossSection(1.0)

        # Remove unwanted datasets
        if 0:
            datasetsMgr.remove(filter(lambda name: "QCD-b" in name, datasetsMgr.getAllDatasetNames()))
               
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        
        # Get Luminosity
        opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
   
        # Merge EWK samples
        datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
        plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Get all the histograms and their paths (e.g. ForFakeBMeasurement/Baseline_DeltaRLdgTrijetBJetTetrajetBJet_AfterCRSelections)
        hList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(opts.folder)
        hPaths = [os.path.join(opts.folder, h) for h in hList]

        # Create two lists of paths: one for "Baseline" (SR)  and one for "Inverted" (CR)
        path_SR  = []  # baseline, _AfterAllSelections
        path_CR1 = []  # baseline, _AfterCRSelections
        path_VR  = []  # inverted, _AfterAllSelections
        path_CR2 = []  # inverted, _AfterCRSelections
        
        # For-loop: All histogram paths
        for p in hPaths:
            if "AfterStandardSelections" in p:
                continue
            
            if "Baseline" in p:
                if "AllSelections" in p:
                    path_SR.append(p)
                if "CRSelections" in p:
                    path_CR1.append(p)
            if "Inverted" in p:
                if "AllSelections" in p:
                    path_VR.append(p)
                if "CRSelections" in p:
                    path_CR2.append(p)

        # For-loop: All histogram pairs
        for hVR, hCR2, hCR1 in zip(path_VR, path_CR2, path_CR1):
            break
            if "IsGenuineB" in hVR:
                continue
            PlotComparison(datasetsMgr, hVR, hCR2, "VRvCR2")

        # For-loop: All histogram pairs
        counter = 1
        for hCR1, hCR2 in zip(path_CR1, path_CR2):
            if "IsGenuineB" in hCR1:
                continue
            
            hName = hCR1.replace("_AfterCRSelections", "_CR1vCR2").replace("ForFakeBMeasurement/Baseline_", "")
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)), hName)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)
            PlotComparison(datasetsMgr, hCR1, hCR2, "CR1vCR2")
            counter+=1

        # For-loop: All histogram pairs
        for hSR, hVR in zip(path_SR, path_VR):
            break
            # Print("UNBLINDING SR! Are you nuts ? BREAK!", False)
            if "IsGenuineB" in hSR:
                continue
            PlotComparison(datasetsMgr, hSR, hVR, "SRvVR")

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #24
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setLogX(opts.logX)
    style.setLogY(opts.logY)

    # Setup & configure the dataset manager
    datasetsMgr = GetDatasetsFromDir(opts)
    datasetsMgr.updateNAllEventsToPUWeighted()
    datasetsMgr.loadLuminosities()  # from lumi.json
    plots.mergeRenameReorderForDataMC(datasetsMgr)
    opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()

    # Do the plot
    moduleDict = {}
    moduleNames = list(
        filter(
            lambda x: "FakeBTransferFactors" in x and x.endswith(".py") and
            not x.startswith("#"), os.listdir(opts.mcrab)))
    sKeys = []
    Verbose(
        "Found %d import files:%s%s%s" %
        (len(moduleNames), hs, "\n\t" + "\n\t".join(moduleNames), ns), True)

    # For-loop: All module files to be imported
    for i, m in enumerate(moduleNames, 1):
        # This is the default file (inclusive). But another inclusive one (.._Run2016.py) is also inclded (=>duplicate)
        if "80to1000" in str(m):
            continue
        if not opts.verbose:
            Print(
                "Importing module %s" %
                (hs + os.path.join(opts.mcrab, m) + ns), i == 1)
        else:
            Print(
                "Importing module %s" %
                (hs + os.path.join(opts.mcrab, m) + ns), True)

        # Define the path to the .py file (module Path) and the name to be imported as (module name)
        mPath = os.path.join(os.getcwd(), opts.mcrab, m)
        mName = m.split("_")[-1].replace(".py", "")
        sKeys.append(mName)
        mObj = imp.load_source(mName, mPath)
        moduleDict[mName] = mObj

        # Debugging
        Verbose(moduleDict[mName].FakeBNormalisation_Value.keys(), False)
        Verbose(moduleDict[mName].FakeBNormalisation_Value.values(), False)

    gList = []
    gListR = []
    # For-loop: All modules imported
    for i, k in enumerate(sorted(sKeys, key=natural_keys), 0):
        g = PlotTFs(i, k, moduleDict[k])
        gList.extend(g)
        gListR.extend(g)

    # Make sure you use correct graph as reference
    refPos = 0
    for i, g in enumerate(gList, 0):
        if g.getName() == opts.refHisto:
            refPos = i
            break

    # Reference histograph
    gList.insert(0, gList.pop(refPos))
    gListR.insert(0, gListR.pop(refPos))

    # Create comparison plot
    PlotTFsCompare("transferFactors", sKeys, gList)

    # Create comparison ratio plot
    gListR = [
        divideGraph(g, gListR[0], errorY=True, invRatio=False) for g in gListR
    ]
    PlotTFsCompare("transferFactorsR", sKeys, gListR, isRatio=True)

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(False)
    style.setGridY(False)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab1)

    # Get list of eras, modes, and optimisation modes
    erasList = dsetMgrCreator.getDataEras()
    modesList = dsetMgrCreator.getSearchModes()
    optList = dsetMgrCreator.getOptimizationModes()
    sysVarList = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Get the datasets from the directory
        datasetsMgr1 = GetDatasetsFromDir(opts.mcrab1, opts)
        datasetsMgr2 = GetDatasetsFromDir(opts.mcrab2, opts)
        datasetsMgr3 = GetDatasetsFromDir(opts.mcrab3, opts)

        # Setup the dataset managers
        datasetsMgr1.updateNAllEventsToPUWeighted()
        datasetsMgr1.loadLuminosities()  # from lumi.json
        datasetsMgr2.updateNAllEventsToPUWeighted()
        datasetsMgr2.loadLuminosities()  # from lumi.json
        datasetsMgr3.updateNAllEventsToPUWeighted()
        datasetsMgr3.loadLuminosities()  # from lumi.json

        # Print dataset info?
        if opts.verbose:

            datasetsMgr1.PrintCrossSections()
            datasetsMgr1.PrintLuminosities()

            datasetsMgr2.PrintCrossSections()
            datasetsMgr2.PrintLuminosities()

            datasetsMgr2.PrintCrossSections()
            datasetsMgr2.PrintLuminosities()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr1)
        plots.mergeRenameReorderForDataMC(datasetsMgr2)
        plots.mergeRenameReorderForDataMC(datasetsMgr3)

        # Get Luminosity
        lumi1 = datasetsMgr1.getDataset("Data").getLuminosity()
        lumi2 = datasetsMgr2.getDataset("Data").getLuminosity()
        lumi3 = datasetsMgr3.getDataset("Data").getLuminosity()
        if lumi1 != lumi2 != lumi3:
            raise Exception("Lumi1 (=%.2f) != Lumi2 (=%.2f) != Lumi3 (=%.2f" %
                            (lumi1, lumi2, lumi3))
        else:
            opts.intLumi = datasetsMgr1.getDataset("Data").getLuminosity()

        # Merge EWK samples
        datasetsMgr1.merge("EWK", aux.GetListOfEwkDatasets())
        datasetsMgr2.merge("EWK", aux.GetListOfEwkDatasets())
        datasetsMgr3.merge("EWK", aux.GetListOfEwkDatasets())
        plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr1.PrintInfo()
        if 0:
            datasetsMgr2.PrintInfo()
            datasetsMgr3.PrintInfo()

        # Get all the histograms and their paths (e.g. ForFakeBMeasurement/Baseline_DeltaRLdgTrijetBJetTetrajetBJet_AfterCRSelections)
        hList = datasetsMgr1.getDataset(
            datasetsMgr1.getAllDatasetNames()[0]).getDirectoryContent(
                opts.folder)
        hPaths = [os.path.join(opts.folder, h) for h in hList]

        # Create a smaller list with only histos of interest
        hListS = []
        for h in hList:
            if "StandardSelections" in h:
                continue
            if "IsGenuineB" in h:
                continue
            if "_Bjet" in h:
                continue
            if "_Jet" in h:
                continue
            if "_SubLdg" in h:
                continue
            if "_Njets" in h:
                continue
            if "_NBjets" in h:
                continue
            if "_Delta" in h:
                continue
            if "Dijet" in h:
                continue
            if "Bdisc" in h:
                continue
            #if "MVA" in h:
            #    continue
            if "MET" in h:
                continue
            if "HT" in h:
                continue
            # Otherwise keep the histogram
            hListS.append(h)

        hPathsS = [os.path.join(opts.folder, h) for h in hListS]

        # Create two lists of paths: one for "Baseline" (SR)  and one for "Inverted" (CR)
        path_SR = []  # baseline, _AfterAllSelections
        path_CR1 = []  # baseline, _AfterCRSelections
        path_VR = []  # inverted, _AfterAllSelections
        path_CR2 = []  # inverted, _AfterCRSelections

        # For-loop: All histogram paths
        for p in hPathsS:  #hPaths:
            if "Baseline" in p:
                if "AllSelections" in p:
                    path_SR.append(p)
                if "CRSelections" in p:
                    path_CR1.append(p)
            if "Inverted" in p:
                if "AllSelections" in p:
                    path_VR.append(p)
                if "CRSelections" in p:
                    path_CR2.append(p)

        counter = 1
        # For-loop: All histogram pairs
        for hCR1, hCR2 in zip(path_CR1, path_CR2):
            if "IsGenuineB" in hCR1:
                continue
            #hName = hCR1.replace("_AfterCRSelections", "_CR1vCR2").replace("ForFakeBMeasurement/Baseline_", "")
            hName = hCR1.replace("_AfterCRSelections",
                                 " (CR1 and R2)").replace(
                                     "ForFakeBMeasurement/Baseline_", "")
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format(
                "Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)),
                hName)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(),
                  counter == 1)

            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hCR1,
                           hCR2, "CR1")
            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hCR1,
                           hCR2, "CR2")  #iro
            counter += 1

        # WARNING! This unblinds the Signal Region (SR)
        for hSR, hVR in zip(path_SR, path_VR):
            if "IsGenuineB" in hSR:
                continue
            if 1:
                continue
            #hName = hCR1.replace("_AfterCRSelections", "_SRvVR").replace("ForFakeBMeasurement/Baseline_", "")
            hName = hCR1.replace("_AfterCRSelections", " (SR and VR)").replace(
                "ForFakeBMeasurement/Baseline_", "")
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format(
                "Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)),
                hName)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(),
                  counter == 1)

            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hSR, hVR,
                           "SR")
            PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hSR, hVR,
                           "VR")
            counter += 1

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
예제 #26
0
def main(opts):

    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setLogX(opts.logX)
    style.setLogY(opts.logY)
    style.setLogZ(opts.logZ)


    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        
        # Print merged datasets and MC samples
        if 0:
            datasetsMgr.PrintInfo()

        # Get Luminosity
        if opts.intLumi < 0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = 1.0
         
        # Set/Overwrite cross-sections. Remove all but 1 signal mass
        removeList = []
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)
                if d.getName() != opts.signal:
                    removeList.append(d.getName())

        # Custom filtering of datasets
        for i, d in enumerate(removeList, 1):
            msg = "Removing datasets %s from dataset manager" % (ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle())
            Verbose(msg, i==1)
            datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames()))


        # Merge EWK samples
        if opts.mergeEWK == "EWK":
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        if 1:
            datasetsMgr.PrintInfo()
            
        # Get list of histogram paths
        folder     = opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths = [os.path.join(folder, h) for h in histoList]

        # For-loop: All histograms
        for i, h in enumerate(histoPaths, 1):
            if "_Vs_" in h:
                continue

            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(histoPaths)), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)
            PlotHistograms(datasetsMgr, h)
            break

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
def main(opts):

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)
    
    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setOptStat(False)

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        optModes = optList
    else:
        optModes = [opts.optMode]

    # Define genuineB and fakeB datasets
    mergeMap = {"TT": "GenuineB",
                "QCD_HT50to100"   : "FakeB", #v. poor stats!
                "QCD_HT200to300"  : "FakeB", #v. poor stats!
                "QCD_HT100to200"  : "FakeB", #v. poor stats!
                "QCD_HT200to300"  : "FakeB", #v. poor stats!
                "QCD_HT300to500"  : "FakeB",
                "QCD_HT500to700"  : "FakeB", 
                "QCD_HT700to1000" : "FakeB",
                "QCD_HT1000to1500": "FakeB",
                "QCD_HT1500to2000": "FakeB", 
                "QCD_HT2000toInf" : "FakeB",
                "WJetsToQQ_HT_600ToInf": "FakeB"
                }
    # Definitions
    results  = []

    # For-loop: All optimisation modes
    for index, opt in enumerate(optModes, 1):
        opts.optMode = opt
        
        # Definitions
        genuineB = None
        fakeB    = None

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json   
        
        # Print datasets info ?
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Remove unwanted datasets
        removeList = ["QCD_HT50to100", "QCD_HT100to200", "QCD_HT200to300", "QCD_HT200to300_ext1", "WJetsToQQ_HT_600ToInf"]
        for k, d in enumerate(datasetsMgr.getAllDatasets(), 1):
            if d.getName() in removeList:
                datasetsMgr.remove(d.getName())
                Verbose(ShellStyles.ErrorStyle() + "Removing dataset %s" % d.getName() + ShellStyles.NormalStyle(), k==1)
        if index == 1:
            datasetsMgr.PrintInfo()

        # Merge datasets into two groups: Genuine-B and Fake-B
        datasetsMgr.mergeMany(mergeMap, addition=False)
        for d in datasetsMgr.getAllDatasets():
            if d.getName() == "GenuineB":
                genuineB = d
            if d.getName() == "FakeB":
                fakeB = d

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        # Get integrated luminosity
        intLumi = datasetsMgr.getDataset("Data").getLuminosity()
        datasetsMgr.remove(filter(lambda name: "Data" in name, datasetsMgr.getAllDatasetNames()))
                    
        # Print dataset information
        if index == 1:
            datasetsMgr.PrintInfo()

        # Do the plot
        name = GetPlotName(opts)
        myResults = doPlot(name, genuineB, fakeB, opts.errorlevel, opts.optMode, intLumi) 
        
        # Save results and msgs
        results.extend(myResults)
        
        # For-loop: All points
        if opts.verbose:
            for item in results:
                print item
    
    # Print path of all saved plots
    msg = "All plots saved under directory %s" % (aux.convertToURL(opts.saveDir, opts.url))
    Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), True)

    # Write results to a json file
    with open(opts.json, 'w') as outfile:
        json.dump(results, outfile)
    msg = "Wrote results to \"%s\"" % (opts.json)
    Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), True)
    return
예제 #28
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(True) #opts.gridX)
    style.setGridY(True) #opts.gridY)
    style.setLogX(False) #opts.logX)
    style.setLogY(False) #opts.logY)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json

        if 0:
            datasetsMgr.printSelections()
        
        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            
        # Custom Filtering of datasets 
        if 0:
            datasetsMgr.remove(filter(lambda name: "Charged" in name and not "M_500" in name, datasetsMgr.getAllDatasetNames()))

        # ZJets and DYJets overlap!
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))
               
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        datasetsMgr.PrintInfo()
   
        # Get Luminosity
        if opts.intLumi < 0.0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = 1.0

        # Merge EWK samples
        if opts.dataset == "EWK":
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Get all histogram names in the given ROOT folder
        histoNames = datasetsMgr.getAllDatasets()[0].getDirectoryContent(opts.folder)
        # histoList  = [os.path.join(opts.folder, h) for h in histoNames if "_" + opts.region in h and opts.refBdisc in h]
        histoList  = [os.path.join(opts.folder, h) for h in histoNames if opts.refBdisc in h]

        # For-loop: All histos in CR of interest
        nHistos = len(histoList)
        for i, h in enumerate(histoList, 1):
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i,"/", "%s:" % (nHistos), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)
            PlotHistograms(datasetsMgr, h)

    # Inform user where the plots where saved
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #29
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setLogX(opts.logX)
    # If you want BOTH pads (main and ratio) in log scale 
    if 0:
        style.setLogY(opts.logY) 

    # Overwrite default legends
    plots._legendLabels["MCStatError"] = "Bkg. stat."
    plots._legendLabels["MCStatSystError"] = "Bkg. stat.#oplussyst."
    plots._legendLabels["BackgroundStatError"] = "Bkg. stat. unc"
    plots._legendLabels["BackgroundStatSystError"] = "Bkg. stat.#oplussyst. unc."
    
    # Define optimisatio modes to run on
    optModes = [""] #["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # Inform user of EWK datasets used
    Print("The EWK datasets used are the following:", True)
    for i,d in enumerate(aux.GetListOfEwkDatasets(), 1):
        Print(ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle(), i==0)

    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        dsetMgr1 = GetDatasetsFromDir(opts, False) 
        dsetMgr2 = GetDatasetsFromDir(opts, True)

        # Setup the dataset managers
        dsetMgr1.updateNAllEventsToPUWeighted()
        dsetMgr2.updateNAllEventsToPUWeighted()

        # Load luminosities
        dsetMgr1.loadLuminosities() # from lumi.json
        # dsetMgr2.loadLuminosities()

        # Print PSets. Perhaps i can use this to ensure parameters are matching!
        if 0:
            dsetMgr1.printSelections()
            dsetMgr2.printSelections()
            PrintPSet("FakeBMeasurement", dsetMgr1)
            PrintPSet("TopSelectionBDT" , dsetMgr2)

        # Remove datasets with overlap?
        removeList = ["QCD-b"]
        dsetDY     = "DYJetsToQQ_HT180"
        dsetZJ     = "ZJetsToQQ_HT600toInf"
        dsetRM     = dsetZJ # datasets with overlap
        removeList.append(dsetRM)

        # Set/Overwrite cross-sections. Remove all but 1 signal mass 
        for d in dsetMgr1.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                dsetMgr1.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits
                if d.getName() != opts.signal:
                    removeList.append(d.getName())

        # Print useful information?
        if opts.verbose:
            dsetMgr1.PrintCrossSections()
            dsetMgr1.PrintLuminosities()
            dsetMgr2.PrintCrossSections()
            dsetMgr2.PrintLuminosities()

        # Merge histograms
        plots.mergeRenameReorderForDataMC(dsetMgr1) 
   
        # Get the luminosity
        if opts.intLumi < 0:
            opts.intLumi = dsetMgr1.getDataset("Data").getLuminosity()

        # Custom Filtering of datasets 
        for i, d in enumerate(removeList, 1):
            msg = "Removing datasets %s from dataset manager" % (ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle())
            Verbose(msg, i==1)
            dsetMgr1.remove(filter(lambda name: d == name, dsetMgr1.getAllDatasetNames()))

        # Print dataset information
        dsetMgr1.PrintInfo()
        dsetMgr2.PrintInfo()

        # Replace MC datasets with data-driven
        if not opts.useMC:
            replaceQCD(dsetMgr1, dsetMgr2, "FakeBMeasurementTrijetMass", "FakeB") #dsetMgr1 now contains "FakeB" pseudo-dataset

        # Definitions
        allHistos   = dsetMgr2.getAllDatasets()[0].getDirectoryContent(opts.folder)
        histoPaths  = []
        ignoreKeys  = ["MCEWK", "Purity", "BJetPt", "BJetEta", "BtagDiscriminator", "METPhi", "MHT", "NBjets", "Njets", "_Vs_", "JetEta"]
        # For-loop: All histograms in directory
        for h in allHistos:
            bKeep = True
            for k in ignoreKeys:
                if k in h:
                    bKeep = False
                    continue
            if bKeep:
                histoPaths.append(os.path.join(opts.folder, h))

        # For-loop: All histograms in list
        for i, hName in enumerate(histoPaths, 1):
            
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(histoPaths)), hName)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)

            PlotHistogram(dsetMgr1, hName, opts)

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)    
    return
예제 #30
0
            Verbose("Reference histo is \"%s\"" % (rhName), True)
            p.histoMgr.setHistoDrawStyle(rhName, "CE4")
            p.histoMgr.setHistoLegendStyle(rhName, "LF")
        else:
            setStyle(i, h.getRootHisto(), False)
            p.histoMgr.setHistoDrawStyle(rhName, "P")
            p.histoMgr.setHistoLegendStyle(rhName, "LP")
            #p.histoMgr.setHistoDrawStyle(styles.styles[i]) #styles.generator(False), "P2")

    kwargs = opts._kwargs
    kwargs["rebinX"] = systematics.getBinningForPlot(
        "LdgTetrajetMass_AfterAllSelections")
    kwargs["divideByBinWidth"] = True
    kwargs["stackMCHistograms"] = False
    kwargs["addLuminosityText"] = False
    kwargs["createLegend"] = {"x1": 0.50, "y1": 0.60, "x2": 0.92, "y2": 0.92}
    kwargs["opts"] = {"ymin": 1e-6, "ymaxfactor": 5, "xmax": 3000.0}

    hName = opts.histoKey + "_AllEras"
    dName = aux.getSaveDirPath(opts.mcrab, prefix="", postfix="")
    plots.drawPlot(p, hName, **kwargs)
    SavePlot(p, hName, dName, saveFormats=[".png", ".pdf", ".C"])
    Print(
        "Saving \"%s\" under \"%s\"" %
        (hName, aux.convertToURL(dName, opts.url)), True)

    if not opts.batchMode:
        raw_input(
            "=== plot_ClosureInPartialDataset.py: Press any key to quit ROOT ..."
        )
예제 #31
0
def main(opts):

    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setLogX(opts.logX)
    style.setLogY(opts.logY)
    style.setLogZ(opts.logZ)

    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities()  # from lumi.json
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        # Print merged datasets and MC samples
        if 0:
            datasetsMgr.PrintInfo()

        # Get Luminosity
        if opts.intLumi < 0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = 1.0

        # Set/Overwrite cross-sections. Remove all but 1 signal mass
        removeList = []
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)
                if d.getName() != opts.signal:
                    removeList.append(d.getName())

        # Custom filtering of datasets
        for i, d in enumerate(removeList, 1):
            msg = "Removing datasets %s from dataset manager" % (
                ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle())
            Verbose(msg, i == 1)
            datasetsMgr.remove(
                filter(lambda name: d == name,
                       datasetsMgr.getAllDatasetNames()))

        # Merge EWK samples
        if opts.mergeEWK == "EWK":
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        if 1:
            datasetsMgr.PrintInfo()

        # Get list of histogram paths
        folder = opts.folder
        histoList = datasetsMgr.getDataset(
            datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths = [os.path.join(folder, h) for h in histoList]

        # For-loop: All histograms
        for i, h in enumerate(histoPaths, 1):
            if "_Vs_" in h:
                continue

            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format(
                "Histogram", "%i" % i, "/", "%s:" % (len(histoPaths)), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(),
                  i == 1)
            PlotHistograms(datasetsMgr, h)
            break

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
예제 #32
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(False)
    style.setGridY(False)
    style.setOptStat(False)

    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList = dsetMgrCreator.getDataEras()
    modesList = dsetMgrCreator.getSearchModes()
    optList = dsetMgrCreator.getOptimizationModes()
    sysVarList = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities()  # from lumi.json
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Get the PSets:
        if 0:
            datasetsMgr.printSelections()
            #PrintPSet("BJetSelection", datasetsMgr, depth=150)
            #PrintPSet("fakeBMeasurement", datasetsMgr, depth=150)
            sys.exit()

        # ZJets and DYJets overlap!
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames(
        ) and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print(
                "Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..",
                True)
            datasetsMgr.remove(
                filter(lambda name: "ZJetsToQQ" in name,
                       datasetsMgr.getAllDatasetNames()))

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        # Get luminosity if a value is not specified
        if opts.intLumi < 0:
            opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()

        # Remove datasets
        removeList = ["QCD-b", "Charged"]
        if not opts.useMC:
            removeList.append("QCD")
        for i, d in enumerate(removeList, 0):
            msg = "Removing dataset %s" % d
            Verbose(
                ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(),
                i == 0)
            datasetsMgr.remove(
                filter(lambda name: d in name,
                       datasetsMgr.getAllDatasetNames()))

        # Print summary of datasets to be used
        if 0:
            datasetsMgr.PrintInfo()

        # Merge EWK samples
        datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())

        # Print dataset information
        datasetsMgr.PrintInfo()

        # List of TDirectoryFile (_CRone, _CRtwo, _VR, _SR)
        tdirs = [
            "LdgTrijetPt_", "LdgTrijetMass_", "TetrajetBJetPt_",
            "TetrajetBJetEta_", "LdgTetrajetPt_", "LdgTetrajetMass_"
        ]
        region = ["CRone", "CRtwo"]
        hList = []
        for d in tdirs:
            for r in region:
                hList.append(d + r)

        # Get the folders with the binned histograms
        folderList_ = datasetsMgr.getDataset(
            datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(
                opts.folder)
        folderList = [h for h in folderList_ if h in hList]

        # For-loop: All folders
        histoPaths = []
        for f in folderList:
            folderPath = os.path.join(opts.folder, f)
            histoList = datasetsMgr.getDataset(
                datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(
                    folderPath)
            pathList = [os.path.join(folderPath, h) for h in histoList]
            histoPaths.extend(pathList)

        # Get all the bin labels
        binLabels = GetBinLabels("CRone", histoPaths)

        for i, t in enumerate(tdirs, 1):
            myList = []
            for p in histoPaths:
                if t in p:
                    myList.append(p)
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format(
                "Histogram", "%i" % i, "/", "%s:" % (len(tdirs)),
                t.replace("_", ""))
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(),
                  i == 1)

            PlotHistograms(datasetsMgr, myList, binLabels, opts)

    # Save the plots
    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
예제 #33
0
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(False)
    style.setGridY(False)

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities()  # from lumi.json

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        if 0:
            plots.mergeRenameReorderForDataMC(datasetsMgr)

        # Print dataset information before removing anything?
        if 0:
            datasetsMgr.PrintInfo()

        # Print datasets info summary
        datasetsMgr.PrintInfo()

        # Re-order datasets
        datasetOrder = []
        haveQCD = False
        for d in datasetsMgr.getAllDatasets():
            if "QCD" in d.getName():
                haveQCD = True
            datasetOrder.append(d.getName())

        # Append signal datasets
        datasetsMgr.selectAndReorder(datasetOrder)

        # Define the mapping histograms in numerator->denominator pairs
        VariableList = ["LeadingTrijet_Pt"]
        # VariableList = ["LeadingTrijet_Pt", "LeadingTrijet_Eta", "LeadingTrijet_Phi"]

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py)
        plots.mergeRenameReorderForDataMC(datasetsMgr)

        counter = 0
        opts.nDatasets = len(datasetsMgr.getAllDatasets())
        nPlots = len(VariableList)
        # For-loop: All numerator-denominator pairs
        for var in VariableList:
            hNumerator = "AfterAllSelections_" + var + "_SR"
            hDenominator = "AfterStandardSelections_" + var + "_SR"
            numerator = os.path.join(opts.folder, hNumerator)
            denFolder = opts.folder
            #denFolder    = denFolder.replace("Genuine", "")
            #print "denFolder", denFolder
            denominator = os.path.join(denFolder, hDenominator)

            counter += 1
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format(
                "Histogram", "%i" % counter, "/", "%s:" % (nPlots),
                "%s" % (var))
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(),
                  counter == 1)

            PlotEfficiency(datasetsMgr, numerator, denominator)

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(False)
    style.setGridY(False)
    style.setOptStat(False)
    
    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()
        
    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            
        # Get the PSets:
        if 0:
            datasetsMgr.printSelections()
            #PrintPSet("BJetSelection", datasetsMgr, depth=150)
            #PrintPSet("fakeBMeasurement", datasetsMgr, depth=150)
            sys.exit()

        # ZJets and DYJets overlap!
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 

        # Get luminosity if a value is not specified
        if opts.intLumi < 0:
            opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
        
        # Remove datasets
        removeList = ["QCD-b", "Charged"]
        if not opts.useMC:
            removeList.append("QCD")
        for i, d in enumerate(removeList, 0):
            msg = "Removing dataset %s" % d
            Verbose(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0)
            datasetsMgr.remove(filter(lambda name: d in name, datasetsMgr.getAllDatasetNames()))

        # Print summary of datasets to be used
        if 0:
            datasetsMgr.PrintInfo()
        
        # Merge EWK samples
        datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            
        # Print dataset information
        datasetsMgr.PrintInfo()
        
        # List of TDirectoryFile (_CRone, _CRtwo, _VR, _SR)
        tdirs  = ["LdgTetrajetMass_", "LdgTetrajetPt_", "LdgTrijetPt_", "LdgTrijetMass_", "TetrajetBJetPt_", "TetrajetBJetEta_"] 
        region = ["CRone", "CRtwo", "SR", "VR"]
        hList  = []
        for d in tdirs:
            for r in region:
                hList.append(d + r)

        # Get the folders with the binned histograms
        folderList_ = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(opts.folder)
        folderList  = [h for h in folderList_ if h in hList]
        
        # For-loop: All folders
        histoPaths = []
        for f in folderList:
            folderPath = os.path.join(opts.folder, f)
            histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folderPath)            
            pathList   = [os.path.join(folderPath, h) for h in histoList]
            histoPaths.extend( pathList )

        # Get all the bin labels 
        binLabels = GetBinLabels("CRone", histoPaths)
    
        for i, t in enumerate(tdirs, 1):
            myList = []
            for p in histoPaths:
                if t in p:
                    myList.append(p)
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(tdirs)), t.replace("_", ""))
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)

            PlotHistograms(datasetsMgr, myList, binLabels, opts)

    # Save the plots
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #35
0
def main(opts):

    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # Apply TDR style
    global style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setLogX(opts.logX)
    style.setLogY(opts.logY)

    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        
        # Print merged datasets and MC samples
        if 0:
            datasetsMgr.PrintInfo()

        # Get Luminosity
        if opts.intLumi == 0.0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = GetLumi(datasetsMgr)

        # Set/Overwrite cross-sections. Remove all but 1 signal mass
        signalsList = []
        for s in opts.signalList:
            signalsList.append("ChargedHiggs_HplusTB_HplusToTB_M_%s" % s)

        # Remove datasets with overlap?
        removeList = ["QCD-b"]
        dsetDY     = "DYJetsToQQ_HT180"
        dsetZJ     = "ZJetsToQQ_HT600toInf"
        dsetRM     = dsetZJ # datasets with overlap
        removeList.append(dsetRM)
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)
                if d.getName() not in signalsList:
                    removeList.append(d.getName())

        # Custom filtering of datasets
        for i, d in enumerate(removeList, 1):
            msg = "Removing datasets %s from dataset manager" % (ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle())
            Verbose(msg, i==1)
            datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames()))


        # Merge EWK samples
        if opts.mergeEWK == "EWK":
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        if 1:
            datasetsMgr.PrintInfo()
            
        # Get list of histogram paths
        folder      = opts.folder
        histoList   = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths  = [os.path.join(folder, h) for h in histoList if "AllSelections" in h]
        myHistos    = []
        skipStrings = ["StandardSelections", "JetPt", "JetEta", "JetEtaPhi", "BJetPt", "BJetEta", 
                       "BtagDiscriminator", "Eta", "LdgTrijetTopMassWMassRatio", "Subldg", "Dijet", 
                       "MET", "MHT", "MinDeltaPhiJetMHT", "MaxDeltaPhiJetMHT", "MinDeltaRJetMHT", "MinDeltaRJetMHTReversed"]

        for h in histoPaths:
            bSkip = False
            for s in skipStrings:
                if s in h:
                    bSkip = True
                    break
            if bSkip:
                continue
            else:
                myHistos.append(h)

        # For-loop: All histograms
        for i, h in enumerate(myHistos, 1):

            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(myHistos)), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)
            PlotHistograms(datasetsMgr, h, signalsList, opts.cutDir)

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
예제 #36
0
def main(opts):

    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    style.setLogX(opts.logX)
    style.setLogY(opts.logY)
    style.setLogZ(opts.logZ)
    style.setWide(True, 0.15)
    # style.setPadRightMargin()#0.13)


    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        
        # Print merged datasets and MC samples
        if 0:
            datasetsMgr.PrintInfo()

        # Get Luminosity
        if opts.intLumi < 0:
            opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            
        # Merge EWK samples
        if opts.dataset == "EWK":
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Re-order datasets (different for inverted than default=baseline)
        newOrder = []
        for d in datasetsMgr.getAllDatasets():
            if d.getName() == opts.dataset:
                newOrder.append(d.getName())
        
        # Sanity check on selected dataset
        nDatasets = len(newOrder)
        if nDatasets < 1:
            msg = "Please select a valid dataset. Dataset \"%s\" does not exist!" % (opts.dataset)
            Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(), True)
            datasetsMgr.PrintInfo()
            sys.exit()
        if nDatasets > 1:
            msg = "Please select only 1 valid dataset. Requested %i datasets for plotting!" % (nDatasets)
            Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(), True)
            datasetsMgr.PrintInfo()
            sys.exit()

        # Select only given dataset         
        datasetsMgr.selectAndReorder(newOrder)

        # Print dataset information
        msg = "Plotting for single dataset \"%s\". Integrated luminosity is %.2f 1/fb" % (opts.dataset, opts.intLumi)
        Print(ShellStyles.NoteStyle() + msg + ShellStyles.NormalStyle(), True)
        datasetsMgr.PrintInfo()
            
        # Get list of histogram paths
        folder     = opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths = [os.path.join(folder, h) for h in histoList]

        # For-loop: All histograms
        for h in histoPaths:
            if "_vs_" not in h.lower():
                continue
            Plot2dHistograms(datasetsMgr, h)

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)    
    return
def main(opts):

    #optModes = ["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"]
    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json

        if 0:
            datasetsMgr.printSelections()
            sys.exit()

        # Define datasets to remove by default
        QCD_list = ["QCD_HT700to1000", "QCD_HT50to100", "QCD_HT500to700", "QCD_HT300to500", 
                    "QCD_HT200to300", "QCD_HT2000toInf", "QCD_HT1500to2000", "QCD_HT100to200", "QCD_HT1000to1500"]
        QCDExt_list = [x+"_ext1" for x in QCD_list]
        datasetsToRemove = ["QCD-b"]
        # datasetsToRemove.extend(QCD_list)
        # datasetsToRemove.extend(QCDExt_list)

        # ZJets and DYJets overlap
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))
            #datasetsMgr.remove(filter(lambda name: "DYJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))
        
        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits
                if d.getName() != opts.signal:
                    datasetsToRemove.append(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 

        # Custom Filtering of datasets 
        for i, d in enumerate(datasetsToRemove, 0):
            msg = "Removing dataset %s" % d
            Verbose(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0)
            datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames()))

        if opts.verbose:
            datasetsMgr.PrintInfo()
  
        # Re-order datasets (different for inverted than default=baseline)
        newOrder = ["Data"]
        for i, d in enumerate(datasetsMgr.getAllDatasets(), 0):
            if d.isData():
                continue
            else:
                newOrder.append(d.getName())

        # Re-arrange dataset order?
        if 0:
            s = newOrder.pop( newOrder.index("noTop") )
            newOrder.insert(len(newOrder), s) #after "Data"

        # Move signal to top
        if opts.signal in newOrder:
            s = newOrder.pop( newOrder.index(opts.signal) )
            newOrder.insert(1, s)
        datasetsMgr.selectAndReorder(newOrder)
        
        # Merge EWK samples
        if opts.mergeEWK:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Apply TDR style
        style = tdrstyle.TDRStyle()
        style.setOptStat(True)
        style.setGridX(opts.gridX)
        style.setGridY(opts.gridY)

        # Do Data-MC histograms with DataDriven QCD
        folder     = opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)        
        histoPaths = [os.path.join(folder, h) for h in histoList]
        ignoreList = ["Aplanarity", "Planarity", "Sphericity", "FoxWolframMoment", "Circularity", "ThirdJetResolution", "Centrality", "_Vs_"]
        myHistos   = []
        for h in histoPaths:
            skip = False

            # Skip unwanted histos
            for i in ignoreList:
                if i in h:
                    skip = True

            if skip:
                continue
            else:
                myHistos.append(h)

        for i, h in enumerate(myHistos, 1):
            # Plot the histograms!
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(myHistos)), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)

            DataMCHistograms(datasetsMgr, h)
        
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)    
    return
예제 #38
0
def main(opts):

    #optModes = ["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"]
    optModes = [""]

    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json

        datasetsMgr_matched = GetDatasetsFromDir(opts)
        datasetsMgr_matched.updateNAllEventsToPUWeighted()
        datasetsMgr_matched.loadLuminosities() # from lumi.json

        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        datasetsMgr.remove(filter(lambda name: "QCD_b" in name, datasetsMgr.getAllDatasetNames())) #soti
        datasetsMgr_matched.remove(filter(lambda name: "QCD" in name, datasetsMgr_matched.getAllDatasetNames())) #soti
        # Set/Overwrite cross-sections
        datasetsToRemove = ["QCD-b"]#, "QCD_HT50to100", "QCD_HT100to200"]#, "QCD_HT200to300"]#, "QCD_HT300to500"]
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits
                #if d.getName() != opts.signal:
                #if "M_650" in d.getName():  #soti fixmi
                #    datasetsToRemove.append(d.getName())
                if "M_800" in d.getName():
                    datasetsToRemove.append(d.getName())
                #if "M_200" in d.getName():
                #    datasetsToRemove.append(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Custom Filtering of datasets 
        for i, d in enumerate(datasetsToRemove, 0):
            msg = "Removing dataset %s" % d
            Print(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0)
            datasetsMgr.remove(filter(lambda name: d in name, datasetsMgr.getAllDatasetNames()))
            datasetsMgr_matched.remove(filter(lambda name: d in name, datasetsMgr_matched.getAllDatasetNames())) #soti
        if opts.verbose:
            datasetsMgr.PrintInfo()

        # ZJets and DYJets overlap
        if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames():
            Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True)
            datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames()))


        #datasetsMgr.merge("QCD", GetListOfQCDatasets())
        #plots._plotStyles["QCD"] = styles.getQCDLineStyle()
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        # Get Luminosity
        #intLumi = datasetsMgr.getDataset("Data").getLuminosity() Soti
        intLumi = 35920

        # Re-order datasets (different for inverted than default=baseline)

        newOrder = []
        # For-loop: All MC datasets
        for d in datasetsMgr.getMCDatasets():
            newOrder.append(d.getName())
        
        # Move signal to top
#        if opts.signal in newOrder:
#            s = newOrder.pop( newOrder.index(opts.signal) )
#            newOrder.insert(0, s)
        print len(newOrder), "newOrder"
        signalMass = ["M_200", "M_500", "M_1000", "M_650"]
        for d in datasetsMgr.getMCDatasets():
            for m in signalMass:
                if m in d.getName():
                    s = newOrder.pop( newOrder.index(d.getName()) )
                    newOrder.insert(0, s)
                    #datasetsMgr.selectAndReorder(newOrder)
        print len(newOrder), "newOrder"
        # Add Data to list of samples!
        if not opts.onlyMC:
            newOrder.insert(0, "Data")
            
        # Apply new dataset order!
        datasetsMgr.selectAndReorder(newOrder)

        # Merge EWK samples
        if opts.mergeEWK:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()
        
        # Apply TDR style
        style = tdrstyle.TDRStyle()
        style.setOptStat(True)
        style.setGridX(opts.gridX)
        style.setGridY(opts.gridY)

        # Do Data-MC histograms with DataDriven QCD
        folder     = opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths1 = [os.path.join(folder, h) for h in histoList]
        histoPaths2 = [h for h in histoPaths1]# if "jet" not in h.lower()]
        nHistos     = len(histoPaths2)

        # For-loop: All histograms
        for i, h in enumerate(histoPaths2, 1):
            msg   = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (nHistos), h)
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1)
            PlotHistograms(datasetsMgr, datasetsMgr_matched, h, intLumi)
        ROOT.gStyle.SetNdivisions(10, "X")
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
def main(opts):

    optModes = [""]
    if opts.optMode != None:
        optModes = [opts.optMode]
        
    # For-loop: All opt Mode
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities(fname="lumi.json")

        # Get Luminosity
        if opts.intLumi < 0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi =  datasetsMgr.loadLumi()

        # Set/Overwrite cross-sections
        datasetsToRemove = []
        for d in datasetsMgr.getAllDatasets():
            if "M_%s" % (opts.signalMass) in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)
            else:
                datasetsToRemove.append(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 

        # Custom Filtering of datasets 
        for i, d in enumerate(datasetsToRemove, 0):
            msg = "Removing dataset %s" % d
            Verbose(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0)
            datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames()))

        if opts.verbose:
            datasetsMgr.PrintInfo()
  
        # Merge EWK samples
        if opts.mergeEWK:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()

        # Print dataset information
        datasetsMgr.PrintInfo()

        # Apply TDR style
        style = tdrstyle.TDRStyle()
        style.setOptStat(True)
        style.setGridX(opts.gridX)
        style.setGridY(opts.gridY)

        # Do Data-MC histograms with DataDriven QCD
        folder     = opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)        
        histoPaths = [os.path.join(folder, h) for h in histoList]
        keepList   = ["LdgTetrajetMass_AfterAllSelections"]
        #keepList   = ["LdgTetrajetMass_AfterStandardSelections"]
        myHistos   = []
        for h in histoPaths:
            if h.split("/")[-1] not in keepList:
                continue
            else:
                myHistos.append(h)

        for i, h in enumerate(myHistos, 1):
            PlotHistograms(datasetsMgr, h)
        
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)    
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(False)
    style.setGridY(False)
    
    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]

    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json
        
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()

        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        if 0:
            plots.mergeRenameReorderForDataMC(datasetsMgr) 

        # Print dataset information before removing anything?
        if 0:
            datasetsMgr.PrintInfo()

        # Print datasets info summary
        datasetsMgr.PrintInfo()

        # Re-order datasets
        datasetOrder = []
        haveQCD = False
        for d in datasetsMgr.getAllDatasets():
            if "QCD" in d.getName():
                haveQCD = True
            datasetOrder.append(d.getName())
            
        # Append signal datasets
        datasetsMgr.selectAndReorder(datasetOrder)

        # Define the mapping histograms in numerator->denominator pairs
        VariableList = ["LeadingTrijet_Pt"]
        # VariableList = ["LeadingTrijet_Pt", "LeadingTrijet_Eta", "LeadingTrijet_Phi"]

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        
        counter =  0
        opts.nDatasets = len(datasetsMgr.getAllDatasets())
        nPlots  = len(VariableList)
        # For-loop: All numerator-denominator pairs
        for var in VariableList:
            hNumerator   = "AfterAllSelections_" + var + "_SR"
            hDenominator = "AfterStandardSelections_" +var + "_SR"
            numerator    = os.path.join(opts.folder, hNumerator)
            denFolder    = opts.folder
            #denFolder    = denFolder.replace("Genuine", "")
            #print "denFolder", denFolder
            denominator  = os.path.join(denFolder, hDenominator)

            counter+=1
            msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % counter, "/", "%s:" % (nPlots), "%s" % (var))
            Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1)
            
            PlotEfficiency(datasetsMgr, numerator, denominator)            
            
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
def main(opts):

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)
    
    # Obtain dsetMgrCreator and register it to module selector
    dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab)

    # Get list of eras, modes, and optimisation modes
    erasList      = dsetMgrCreator.getDataEras()
    modesList     = dsetMgrCreator.getSearchModes()
    optList       = dsetMgrCreator.getOptimizationModes()
    sysVarList    = dsetMgrCreator.getSystematicVariations()
    sysVarSrcList = dsetMgrCreator.getSystematicVariationSources()

    # If user does not define optimisation mode do all of them
    if opts.optMode == None:
        if len(optList) < 1:
            optList.append("")
        else:
            pass
        optModes = optList
    else:
        optModes = [opts.optMode]


    # For-loop: All optimisation modes
    for opt in optModes:
        opts.optMode = opt

        # Setup & configure the dataset manager 
        datasetsMgr = GetDatasetsFromDir(opts)
        datasetsMgr.updateNAllEventsToPUWeighted()
        datasetsMgr.loadLuminosities() # from lumi.json
        
        # Print PSets used for FakeBMeasurement
        if 0:
            datasetsMgr.printSelections()

        # Set/Overwrite cross-sections
        for d in datasetsMgr.getAllDatasets():
            if "ZJetsToQQ_HT600toInf" in d.getName():
                datasetsMgr.remove(d.getName())

            if "ChargedHiggs" in d.getName():
                datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)
                if d.getName() not in opts.signal:
                    if not opts.acceptance:
                        datasetsMgr.remove(d.getName())

        if opts.verbose:
            datasetsMgr.PrintCrossSections()
            datasetsMgr.PrintLuminosities()
            datasetsMgr.PrintInfo()
               
        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 

        # Get Luminosity
        # For acceptance plot use all available masses
        if opts.acceptance:
            opts.signal = []
            opts.signalMasses = []
            for d in datasetsMgr.getAllDatasets():
                if "ChargedHiggs" in d.getName():
                    #dName = d.getName().replace("_ext1", "").split("M_")
                    dName = d.getName().split("M_")
                    m = int(dName[-1])
                    opts.signal.append(d.getName())
                    opts.signalMasses.append(m)

        if opts.intLumi < 0:
            if "Data" in datasetsMgr.getAllDatasetNames():
                opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity()
            else:
                opts.intLumi = 1.0

        # Merge EWK samples
        if 1:
            datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets())
            plots._plotStyles["EWK"] = styles.getAltEWKStyle()
            
        # Print post EWK-merge dataset summary
        datasetsMgr.PrintInfo()

        # Get the efficiency graphs
        hGraphList = []
        histoName  = os.path.join(opts.folder, "counter")
        hGraphList, _kwargs = GetHistoGraphs(datasetsMgr, opts.folder, histoName)

        # Plot the histo graphs
        PlotHistoGraphs(hGraphList, _kwargs)

    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return