#  Set ROOT ingore level for verbosity
    ROOT.gErrorIgnoreLevel = ROOT.kFatal #kPrint = 0,  kInfo = 1000, kWarning = 2000, kError = 3000, kBreak = 4000, kSysError = 5000, kFatal = 6000   
    
    # Create the pseudo-multicrab dir (if the ROOT file exists)
    nFiles = len(opts.rootFiles)    
    if opts.rootFile != None:
        Verbose("Single ROOT file mode", True)

        # Check & assign ROOT file 
        CheckRootFile(opts.rootFile)
        # opts.rootFile = f
        
        # Create directory and subdirectories
        CreatePseudoDir(opts, args)
        aux.Print("%sFile %d/%d: %s%s" % (hs, i, nFiles, f, ns), i==1)
        
        Print("Created pseudo-multicrab directory %s!" % (ss + opts.dirName + ns), True)        
        sys.exit()
    elif nFiles > 0: 
        Verbose("Multiple ROOT files mode", True)

        # For-loop: All ROOT files
        for i, f in enumerate(opts.rootFiles, 1):
            
            # Check & assign ROOT file 
            CheckRootFile(f)
            opts.rootFile = f
            
            # Create directory and subdirectories
            CreatePseudoDir(opts, args)
def PlotHistos(datasetsMgr, histoList, signal, PU, saveName=None):
    
    # Get Histogram name and its kwargs
    kwargs    = GetHistoKwargs(saveName, opts)
    hList     = []
    legDict   = {}
    algos     = getAlgos()
    if "_all"  in saveName:
        algos = ["Inclusive", "1-prong", "3-prong", "#geq 1 #pi^{0}'s", "0 #pi^{0}'s"]
    if "_cif"  in saveName:
        #algos = ["Inclusive", "Central", "Intermediate", "Forward"]
        algos = ["Inclusive", "|#eta| < 0.8 (C)", "0.8 < |#eta| < 1.6 (I)", "|#eta| > 1.6 (F)"]

    # For-loop: All tau algorithms
    for l, hName in enumerate(histoList, 0):
        
        algo = hName.split("_")[0]
        msg  = "Resolution for \"%s\" algorithm (%s)" % (algo, signal)
        aux.PrintFlushed(msg, False)
        h = datasetsMgr.getDataset(signal).getDatasetRootHisto(hName).getHistogram()
        h.SetName(hName)
        legDict[hName] = algos[l]
        hList.append(h)

        # Create the rate histograms
        if opts.normalizeToOne:
            p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[])
            norm = True
            for hist in p.histoMgr.getHistos():
                if hist.getRootHisto().Integral() == 0:
                    norm = False
                    break
            if (norm):
                p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Scale(1.0/h.getRootHisto().Integral()) )
            else:
                aux.Print("Cannot normalise empty histo \"%s\" for dataset \"%s\"" % (hName, signal), True)
        else:
            p = plots.ComparisonManyPlot(hList[0], hList[1:], saveFormats=[])

    # Set legend labels
    for i, h in enumerate(p.histoMgr.getHistos(), 0):
        hName = h.getName()
        p.histoMgr.forHisto(hName, styles.getCaloStyle(i))
        #p.histoMgr.setHistoDrawStyle(hName, "HIST")
        #p.histoMgr.setHistoLegendStyle(hName, "L")
        p.histoMgr.setHistoDrawStyle(hName, "AP")
        p.histoMgr.setHistoLegendStyle(hName, "P")
    
    # Set legend labels
    p.histoMgr.setHistoLegendLabelMany(legDict)

    # Draw and save the plot
    plots.drawPlot(p, saveName, **kwargs)

    # Add additional canvas text
    histograms.addPileupText("PU=%s" % (PU) )
    histograms.addText(0.22, 0.86, plots._legendLabels[signal], 17)

    # Save the plots in custom list of saveFormats
    aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, True)
    return
Example #3
0
def main(opts):

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

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

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

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

    # Print datasets info summary
    datasetsMgr.PrintInfo()

    # Define the mapping histograms in numerator->denominator pairs
    VariableList = [
        "L1Taus_SingleTau_Eff", "L1Taus_SingleTau_Rate", "L1Taus_TurnOn25",
        "L1Taus_TurnOn50"
    ]

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

    # For-loop: All datasets
    for dataset in datasetsMgr.getAllDatasets():

        opts.saveDir = aux.getSaveDirPath(opts.saveDirBase,
                                          prefix="hltaus/",
                                          postfix="ROC")
        PlotRateVsEff(datasetsMgr, dataset, "SingleTau", "PU140")
        PlotRateVsEff(datasetsMgr, dataset, "SingleTau", "PU200")
        PlotRateVsEff(datasetsMgr, dataset, "DiTau", "PU140")
        PlotRateVsEff(datasetsMgr, dataset, "DiTau", "PU200")

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

            if "neutrino" in dataset.getName().lower():
                if "rate" in hName.lower():
                    opts.saveDir = aux.getSaveDirPath(opts.saveDirBase,
                                                      prefix="hltaus/",
                                                      postfix="Rates")
                    PlotHistos(dataset.getName(), hPath,
                               hName.split("_")[0] + "_")
                else:
                    pass
            else:
                if "rate" in hName.lower():
                    continue
                else:
                    if "eff" in hName.lower():
                        opts.saveDir = aux.getSaveDirPath(
                            opts.saveDirBase,
                            prefix="hltaus/",
                            postfix="Efficiencies")
                        PlotHistos(dataset.getName(), hPath,
                                   hName.split("_")[0] + "_")

                    if "turnon" in hName.lower():
                        opts.saveDir = aux.getSaveDirPath(opts.saveDirBase,
                                                          prefix="hltaus/",
                                                          postfix="TurnOns")
                        PlotHistos(dataset.getName(), hPath,
                                   hName.split("_")[1] + "_")

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

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

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

    # Setup & configure the dataset manager
    datasetsMgr = GetDatasetsFromDir(opts)
    datasetsMgr.updateNAllEventsToPUWeighted()

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

    # Setup & configure the dataset manager (no collision data => not needed)
    if 0:
        datasetsMgr.loadLuminosities()
        datasetsMgr.updateNAllEventsToPUWeighted()

    # Print information
    if opts.verbose:
        datasetsMgr.PrintCrossSections()
        # datasetsMgr.PrintLuminosities()

    # Print dataset information (before merge)
    datasetsMgr.PrintInfo()

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

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

    # Apply new dataset order?
    newOrder = ReorderDatasets(datasetsMgr.getAllDatasetNames())
    if 0:
        datasetsMgr.selectAndReorder(newOrder)

    # Sanity check (exactly 1 dataset)
    nDsets = len(datasetsMgr.getAllDatasetNames())
    if nDsets > 1:
        msg = "Must have exactly 1 dataset (got %d). Please use the -i and -e options to choose exactly 1 dataset!" % (
            nDsets)
        Print(msg, True)
        sys.exit()

    # Print dataset information (after merge)
    if 0:
        datasetsMgr.PrintInfo()  #Requires python 2.7.6 or 2.6.6

    # Plot Histograms
    histoList = datasetsMgr.getDataset(
        datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(opts.folder)
    histoPaths = [os.path.join(opts.folder, h) for h in histoList]
    skipList = ["eff_", "counter", "match_trk", "match_tp", "tp_pt",
                "tp_eta"]  #, "resVsEta_ptRel", "resVsPt_ptRel"]
    histoList = []
    allowedReg = ["C", "I", "F", "L", "M", "H"]

    # For-loop: All histograms (in region)
    for h in histoPaths:
        skip = False
        for s in skipList:
            if s in h.lower():
                skip = True
        if skip:
            continue

        region = h.split("_")[-1]
        if region in allowedReg:
            hName = h.replace(region, "")
            histoList.append(hName)

    # Plot the resolution histograms
    uniqueList = set(histoList)

    # For-loop: All histo (generic) names
    for i, h in enumerate(uniqueList, 1):
        if h.endswith("_"):
            h = h[:-1]

        aux.Print("%d/%d: %s" % (i, len(uniqueList), h), i == 1)
        PlotHistograms(datasetsMgr, h)

    #print
    Print(
        "All plots saved under directory %s" %
        (ts + aux.convertToURL(opts.saveDir, opts.url) + ns), True)

    return
Example #5
0
        type="float",
        default=BANDVALUE,
        help=
        "Add a symmetric band around 1.0. Value passed should be the percentage (e.g 10 or 5)  [default: %s]"
        % (BANDVALUE))

    (opts, parseArgs) = parser.parse_args()

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        parser.print_help()
        sys.exit(1)

    if len(opts.mcrabs) == 0:
        aux.Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        parser.print_help()
        #print __doc__
        sys.exit(1)

    # Store all (comma-separated) pseudomulticrabs in a list
    if opts.mcrabs == None:
        aux.Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        parser.print_help()
        sys.exit(1)
    else:
        if "," in opts.mcrabs:
            opts.mcrabs = opts.mcrabs.split(",")