Beispiel #1
0
def main(opts):

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

    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()
        if 0:
            datasetsMgr.loadLuminosities()  # from lumi.json

        # Custom filtering of datasets
        datasetsToRemove = []
        # For-loop: All dsets to be removed
        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()))

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

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

        # Define signal and background datasets names
        dsets_signal = []
        dsets_minBias = []
        for d in datasetsMgr.getAllDatasetNames():
            if "SingleNeutrino" in d:
                dsets_minBias.append(d)
            else:
                dsets_signal.append(d)

        # ROC curve ingredients (histograms)
        effLists = [[
            "Calo_Eff", "Tk_Eff", "VtxIso_Eff", "RelIso_Eff", "Iso_Eff"
        ],
                    [
                        "DiTau_Eff_Calo", "DiTau_Eff_Tk", "DiTau_Eff_VtxIso",
                        "DiTau_Eff_RelIso", "DiTau_Eff_Iso"
                    ]]

        rateLists = [
            ["Calo_Rate", "Tk_Rate", "VtxIso_Rate", "RelIso_Rate", "Iso_Rate"],
            [
                "DiTau_Rate_Calo", "DiTau_Rate_Tk", "DiTau_Rate_VtxIso",
                "DiTau_Rate_RelIso", "DiTau_Rate_Iso"
            ]
        ]

        turnOnLists = [[
            "Calo_TurnOn25", "Tk_TurnOn25", "RelIso_TurnOn25",
            "VtxIso_TurnOn25", "Iso_TurnOn25"
        ],
                       [
                           "Calo_TurnOn50", "Tk_TurnOn50", "RelIso_TurnOn50",
                           "VtxIso_TurnOn50", "Iso_TurnOn50"
                       ]]

        # For-loop: All background histos (min bias)
        for i, b in enumerate(dsets_minBias, 1):
            bPU = b.split("PU")[1]

            # Create rate plots (SingleTau, DiTau)
            PlotRate(datasetsMgr, rateLists[0], b, bPU)
            PlotRate(datasetsMgr, rateLists[1], b, bPU)

            # For-loop: All signal histos
            for j, s in enumerate(dsets_signal, 1):
                sPU = s.split("PU")[1]

                # Create rate plots (SingleTau, DiTau)
                PlotEfficiency(datasetsMgr, effLists[0], s, sPU)
                PlotEfficiency(datasetsMgr, effLists[1], s, sPU)

                if bPU != sPU:
                    continue
                else:
                    PU = sPU

                # For-loop: All triggers (Calo, Calo+Tk, Calo+VtxIso)
                for k in range(0, len(effLists)):
                    eff = effLists[k]
                    rate = rateLists[k]
                    Verbose("Bkg = %s, Signal = %s" % (b, s), False)
                    PlotRateVsEff(datasetsMgr, eff, rate, s, b, PU)

        # For-loop: All signal histos
        for i, s in enumerate(dsets_signal, 1):
            PU = s.split("PU")[1]

            # Create rate plots (SingleTau, DiTau)
            PlotTurnOns(datasetsMgr, turnOnLists[0], s, PU)
            PlotTurnOns(datasetsMgr, turnOnLists[1], s, PU)
        print

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

    # Set the ROOTeError verbosity
    ROOT.gErrorIgnoreLevel = 3000  # kUnset=-1, kPrint=0, kInfo=1000, kWarning=2000, kError=3000, kBreak=4000

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

    # 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(),
                               bReverse=False)
    datasetsMgr.selectAndReorder(newOrder)

    # 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]
    histoType = type(
        datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()
                               [0]).getDatasetRootHisto(h).getHistogram())
    plotCount = 0
    inList = ["ETResolution"]

    # For-loop: All# histos in opts.folder
    for i, h in enumerate(histoPaths, 1):

        # Only do Et (don't expect dependence on PU for eta, phi
        if "etresolution" not in h.lower():
            continue

        # Forwards region not yet available for Calos
        if "_F" in h:
            continue

        bSkip = True
        for s in inList:
            bSkip = False
        if bSkip:
            continue

        histoType = str(
            type(
                datasetsMgr.getDataset(
                    datasetsMgr.getAllDatasetNames()[0]).getDatasetRootHisto(
                        h).getHistogram()))
        if "TH1" not in histoType:
            continue

        aux.PrintFlushed(h, plotCount == 0)
        plotCount += 1

        PlotHisto(datasetsMgr, h)

    print
    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
Beispiel #3
0
import HLTausAnalysis.NtupleAnalysis.tools.dataset as dataset
import HLTausAnalysis.NtupleAnalysis.tools.histograms as histograms
import HLTausAnalysis.NtupleAnalysis.tools.counter as counter
import HLTausAnalysis.NtupleAnalysis.tools.tdrstyle as tdrstyle
import HLTausAnalysis.NtupleAnalysis.tools.styles as styles
import HLTausAnalysis.NtupleAnalysis.tools.plots as plots
import HLTausAnalysis.NtupleAnalysis.tools.crosssection as xsect
import HLTausAnalysis.NtupleAnalysis.tools.aux as aux
import HLTausAnalysis.NtupleAnalysis.tools.multicrabConsistencyCheck as consistencyCheck
import HLTausAnalysis.NtupleAnalysis.tools.ShellStyles as ShellStyles

#================================================================================================
# Variable definition
#================================================================================================
ss = ShellStyles.SuccessStyle()
ns = ShellStyles.NormalStyle()
ts = ShellStyles.NoteStyle()
hs = ShellStyles.HighlightAltStyle()
ls = ShellStyles.HighlightStyle()
es = ShellStyles.ErrorStyle()
cs = ShellStyles.CaptionStyle()


#================================================================================================
# Function Definition
#================================================================================================
def Print(msg, printHeader=False):
    fName = __file__.split("/")[-1]
    if printHeader == True:
        print "=== ", fName
def main(opts):
    
    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(False)
    style.setGridX(opts.gridX)
    style.setGridY(opts.gridY)

    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()
        if 0:
            datasetsMgr.loadLuminosities() # from lumi.json

        # Custom filtering of datasets 
        datasetsToRemove = []
        # For-loop: All dsets to be removed
        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()))        

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

        # Print dataset information
        datasetsMgr.PrintInfo()
        if opts.verbose:
            datasetsMgr.PrintCrossSections()
 
        # Define signal and background datasets names
        dsets_signal  = []
        dsets_minBias = []
        for d in datasetsMgr.getAllDatasetNames():
            if "SingleNeutrino" in d:
                dsets_minBias.append(d)
            else:
                dsets_signal.append(d)

        # ROC curve ingredients (histograms)
        resList = [
            ["Calo_ResolutionEt" , "Calo_ResolutionEt_1pr" , "Calo_ResolutionEt_3pr" , "Calo_ResolutionEt_withNeutrals" , "Calo_ResolutionEt_noNeutrals" ], 
            ["Calo_ResolutionEta", "Calo_ResolutionEta_1pr", "Calo_ResolutionEta_3pr", "Calo_ResolutionEta_withNeutrals", "Calo_ResolutionEta_noNeutrals"], 
            ["Calo_ResolutionPhi", "Calo_ResolutionPhi_1pr", "Calo_ResolutionPhi_3pr", "Calo_ResolutionPhi_withNeutrals", "Calo_ResolutionPhi_noNeutrals"],
            ["Calo_ResolutionEt" , "Calo_ResolutionEt_C"   , "Calo_ResolutionEt_I"], #  , "Calo_ResolutionEt_F" ],
            ["Calo_ResolutionEta", "Calo_ResolutionEta_C"  , "Calo_ResolutionEta_I"],#  , "Calo_ResolutionEta_F"],
            ["Calo_ResolutionPhi", "Calo_ResolutionPhi_C"  , "Calo_ResolutionPhi_I"],#  , "CaloIso_ResolutionPhi_F"],
            ]
                       
    
        # For-loop: All signal histos
        for i, s in enumerate(dsets_signal, 1):
            PU = s.split("PU")[1]
            
            # By decay mode
            PlotHistos(datasetsMgr, resList[0], s, PU, "ResolutionEt_%s_all" % (s) )
            PlotHistos(datasetsMgr, resList[1], s, PU, "ResolutionEta_%s_all" % (s) )
            PlotHistos(datasetsMgr, resList[2], s, PU, "ResolutionPhi_%s_all" % (s) )
            
            # By eta region (central, intermediate, forward)
            PlotHistos(datasetsMgr, resList[3], s, PU, "ResolutionEt_%s_cif"  % (s) )
            PlotHistos(datasetsMgr, resList[4], s, PU, "ResolutionEta_%s_cif" % (s) )
            PlotHistos(datasetsMgr, resList[5], s, PU, "ResolutionPhi_%s_cif" % (s) )
        print

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

    # Set the ROOTeError verbosity
    ROOT.gErrorIgnoreLevel = 3000  # kUnset=-1, kPrint=0, kInfo=1000, kWarning=2000, kError=3000, kBreak=4000

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

    # 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())
    datasetsMgr.selectAndReorder(newOrder)

    # 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]
    histoType = type(
        datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()
                               [0]).getDatasetRootHisto(h).getHistogram())
    plotCount = 0
    skipList = [
        "L1TkTau_MatchTk_d0", "L1TkTau_MatchTk_d0Abs", "L1TkTau_SigTks_d0",
        "L1TkTau_SigTks_d0Abs", "L1TkTau_SigTks_d0Sig",
        "L1TkTau_SigTks_d0SigAbs", "L1TkTau_IsoTks_d0", "L1TkTau_IsoTks_d0Abs",
        "L1TkTau_IsoTks_d0Sig", "L1TkTau_IsoTks_d0SigAbs",
        "L1TkTau_ResolutionCaloEt_F", "L1TkTau_ResolutionCaloEta_F",
        "L1TkTau_ResolutionCaloPhi_F", "L1TkIsoTau_ResolutionCaloEt_F",
        "L1TkIsoTau_ResolutionCaloEta_F", "L1TkIsoTau_ResolutionCaloPhi_F",
        "DiTau_Rate_Calo_F", "DiTau_Rate_Tk_F", "DiTau_Rate_VtxIso_F",
        "DiTau_Rate_RelIso_F", "Calo_Rate_F", "Tk_Rate_F", "VtxIso_Rate_F",
        "RelIso_Rate_F"
    ]

    # For-loop: All histos in opts.folder
    for i, h in enumerate(histoPaths, 1):

        # Obsolete quantity
        if h in skipList:
            continue

        histoType = str(
            type(
                datasetsMgr.getDataset(
                    datasetsMgr.getAllDatasetNames()[0]).getDatasetRootHisto(
                        h).getHistogram()))
        if "TH1" not in histoType:
            continue

        aux.PrintFlushed(h, plotCount == 0)
        plotCount += 1
        PlotHisto(datasetsMgr, h)

    print
    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
Beispiel #6
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
Beispiel #7
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() #marina
        if 0:
            datasetsMgr.loadLuminosities() # from lumi.json

        # Set/Overwrite cross-sections
        datasetsToRemove = []
        for d in datasetsMgr.getAllDatasets():
            datasetsMgr.getDataset(d.getName()).setCrossSection(1.0)

        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()))
        #if opts.verbose:
            #datasetsMgr.PrintInfo()

        # Merge histograms (see NtupleAnalysis/python/tools/plots.py) 
        plots.mergeRenameReorderForDataMC(datasetsMgr) 
        
        # Get Luminosity
        if 0:
            intLumi = datasetsMgr.getDataset("Data").getLuminosity()

        # Re-order datasets (different for inverted than default=baseline)
        newOrder = []
        # For-loop: All MC datasets
        for d in datasetsMgr.getMCDatasets():
            newOrder.append(d.getName())
            
        # Apply new dataset order!
        datasetsMgr.selectAndReorder(newOrder)
        
        # Print dataset information
        #datasetsMgr.PrintInfo()
        
        # Apply TDR style
        style = tdrstyle.TDRStyle()
        #style.setOptStat(True)
        style.setGridX(opts.gridX)
        style.setGridY(opts.gridY)

        # Plot Histograms
        folder     = "" #opts.folder
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder)
        histoPaths = [os.path.join(folder, h) for h in histoList]
        histoType  = type(datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDatasetRootHisto(h).getHistogram())
        for i, h in enumerate(histoPaths, 1):
            histoType  = str(type(datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDatasetRootHisto(h).getHistogram()))
            if "TH2" not in histoType:
                continue
            PlotHistograms(datasetsMgr, h)

    return
import HLTausAnalysis.NtupleAnalysis.tools.dataset as dataset
import HLTausAnalysis.NtupleAnalysis.tools.tdrstyle as tdrstyle
import HLTausAnalysis.NtupleAnalysis.tools.styles as styles
import HLTausAnalysis.NtupleAnalysis.tools.plots as plots
import HLTausAnalysis.NtupleAnalysis.tools.histograms as histograms
import HLTausAnalysis.NtupleAnalysis.tools.aux as aux
import HLTausAnalysis.NtupleAnalysis.tools.ShellStyles as ShellStyles

import ROOT
ROOT.gROOT.SetBatch(True)

#================================================================================================
# Shell Styles
#================================================================================================
ws = ShellStyles.WarningStyle()
es = ShellStyles.ErrorStyle()
ls = ShellStyles.HighlightStyle()
hs = ShellStyles.HighlightAltStyle()
cs = ShellStyles.CaptionStyle()
ns = ShellStyles.NormalStyle()
rs = ShellStyles.ResultStyle()
ss = ShellStyles.SuccessStyle()

# s = ShellStyles.NoteStyle()
# s = ShellStyles.AltStyle()
# s = ShellStyles.NoteLabel()
# s = ShellStyles.WarningLabel()
# s = ShellStyles.ErrorLabel()
# s = ShellStyles.SuccessLabel()
Beispiel #9
0
import HLTausAnalysis.NtupleAnalysis.tools.histograms as histograms
import HLTausAnalysis.NtupleAnalysis.tools.counter as counter
import HLTausAnalysis.NtupleAnalysis.tools.tdrstyle as tdrstyle
import HLTausAnalysis.NtupleAnalysis.tools.styles as styles
import HLTausAnalysis.NtupleAnalysis.tools.plots as plots
import HLTausAnalysis.NtupleAnalysis.tools.crosssection as xsect
import HLTausAnalysis.NtupleAnalysis.tools.aux as aux
import HLTausAnalysis.NtupleAnalysis.tools.multicrabConsistencyCheck as consistencyCheck
import HLTausAnalysis.NtupleAnalysis.tools.ShellStyles as ShellStyles

ROOT.gErrorIgnoreLevel = ROOT.kError

#================================================================================================
# Variable definition
#================================================================================================
ss = ShellStyles.SuccessStyle()
ns = ShellStyles.NormalStyle()
ts = ShellStyles.NoteStyle()
hs = ShellStyles.HighlightAltStyle()
ls = ShellStyles.HighlightStyle()
es = ShellStyles.ErrorStyle()
cs = ShellStyles.CaptionStyle()


#================================================================================================
# Function Definition
#================================================================================================
def Print(msg, printHeader=False):
    fName = __file__.split("/")[-1]
    if printHeader == True:
        print "=== ", fName
Beispiel #10
0
def main(opts):

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

    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()
        if 0:
            datasetsMgr.loadLuminosities()  # from lumi.json

        # Custom filtering of datasets
        datasetsToRemove = []
        # For-loop: All dsets to be removed
        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()))

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

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

        # Define signal and background datasets names
        dsets_signal = []
        dsets_minBias = []
        for d in datasetsMgr.getAllDatasetNames():
            if "SingleNeutrino" in d:
                dsets_minBias.append(d)
            else:
                dsets_signal.append(d)

        # ROC curve ingredients (histograms)
        effLists = [[
            "Tk_Eff", "RelIso_Eff", "VtxIso_Eff", "VtxIsoLoose_Eff",
            "VtxIsoTight_Eff", "RelIsoLoose_Eff", "RelIsoTight_Eff"
        ],
                    [
                        "DiTau_Eff_Tk",
                        "DiTau_Eff_RelIso",
                        "DiTau_Eff_VtxIso",
                        "DiTau_Eff_VtxIsoLoose",
                        "DiTau_Eff_VtxIsoTight",
                        "DiTau_Eff_RelIsoLoose",
                        "DiTau_Eff_RelIsoTight",
                    ]]

        rateLists = [[
            "Tk_Rate", "RelIso_Rate", "VtxIso_Rate", "VtxIsoLoose_Rate",
            "VtxIsoTight_Rate", "RelIsoLoose_Rate", "RelIsoTight_Rate"
        ],
                     [
                         "DiTau_Rate_Tk", "DiTau_Rate_RelIso",
                         "DiTau_Rate_VtxIso", "DiTau_Rate_VtxIsoLoose",
                         "DiTau_Rate_VtxIsoTight", "DiTau_Rate_RelIsoLoose",
                         "DiTau_Rate_RelIsoTight"
                     ]]

        turnOnLists = [
            [
                "Tk_TurnOn25", "RelIso_TurnOn25", "VtxIso_TurnOn25"
            ],  # "VtxIsoLoose_TurnOn25", "VtxIsoTight_TurnOn25", "RelIsoLoose_TurnOn25", "RelIsoTight_TurnOn25"], 
            ["Tk_TurnOn50", "RelIso_TurnOn50", "VtxIso_TurnOn50"]
        ]  #, "VtxIsoLoose_TurnOn50", "VtxIsoTight_TurnOn50", "RelIsoLoose_TurnOn50", "RelIsoTight_TurnOn50"]]

        turnOnLists_noNeutrals = [[
            "Tk_TurnOn25_noNeutrals", "RelIso_TurnOn25_noNeutrals",
            "VtxIso_TurnOn25_noNeutrals"
        ],
                                  [
                                      "Tk_TurnOn50_noNeutrals",
                                      "RelIso_TurnOn50_noNeutrals",
                                      "VtxIso_TurnOn50_noNeutrals"
                                  ]]

        turnOnLists_withNeutrals = [[
            "Tk_TurnOn25_withNeutrals", "RelIso_TurnOn25_withNeutrals",
            "VtxIso_TurnOn25_withNeutrals"
        ],
                                    [
                                        "Tk_TurnOn50_withNeutrals",
                                        "RelIso_TurnOn50_withNeutrals",
                                        "VtxIso_TurnOn50_withNeutrals"
                                    ]]

        turnOnLists_1pr = [[
            "Tk_TurnOn25_1pr", "RelIso_TurnOn25_1pr", "VtxIso_TurnOn25_1pr"
        ], ["Tk_TurnOn50_1pr", "RelIso_TurnOn50_1pr", "VtxIso_TurnOn50_1pr"]]

        turnOnLists_3pr = [[
            "Tk_TurnOn25_3pr", "RelIso_TurnOn25_3pr", "VtxIso_TurnOn25_3pr"
        ], ["Tk_TurnOn50_3pr", "RelIso_TurnOn50_3pr", "VtxIso_TurnOn50_3pr"]]

        turnOnLists_all = [[
            "VtxIso_TurnOn25", "VtxIso_TurnOn25_1pr", "VtxIso_TurnOn25_3pr",
            "VtxIso_TurnOn25_withNeutrals", "VtxIso_TurnOn25_noNeutrals"
        ],
                           [
                               "VtxIso_TurnOn50", "VtxIso_TurnOn50_1pr",
                               "VtxIso_TurnOn50_3pr",
                               "VtxIso_TurnOn50_withNeutrals",
                               "VtxIso_TurnOn50_noNeutrals"
                           ]]

        # For-loop: All background histos (min bias)
        for i, b in enumerate(dsets_minBias, 1):
            bPU = b.split("PU")[1]

            # Create rate plots (SingleTau, DiTau)
            if 1:
                opts.saveDir = aux.getSaveDirPath(opts.mcrab,
                                                  prefix="hltaus/",
                                                  postfix="Rates")
                PlotRate(datasetsMgr, rateLists[0], b, bPU, "SingleTau")
                PlotRate(datasetsMgr, rateLists[1], b, bPU, "DiTau")

            # For-loop: All signal histos
            for j, s in enumerate(dsets_signal, 1):
                sPU = s.split("PU")[1]

                # Create rate plots (SingleTau, DiTau)
                if i == 1:  # (since inside minBias loop)
                    opts.saveDir = aux.getSaveDirPath(opts.mcrab,
                                                      prefix="hltaus/",
                                                      postfix="Efficiencies")
                    PlotEfficiency(datasetsMgr, effLists[0], s, sPU,
                                   "SingleTau")
                    PlotEfficiency(datasetsMgr, effLists[1], s, sPU, "DiTau")

                # Skip non-matching signal and bkg PU pairs?
                if sPU != bPU and sPU != "":
                    continue
                else:
                    if sPU == "":
                        sPU = "0"  #rename before saving

                # For-loop: All triggers
                for k in range(0, len(effLists)):
                    eff = effLists[k]
                    rate = rateLists[k]
                    Verbose("Bkg = %s, Signal = %s" % (b, s), False)
                    if 1:
                        opts.saveDir = aux.getSaveDirPath(opts.mcrab,
                                                          prefix="hltaus/",
                                                          postfix="ROC")
                        PlotRateVsEff(datasetsMgr, eff, rate, s, b, sPU, bPU)

        # For-loop: All signal histos
        for i, s in enumerate(dsets_signal, 1):
            PU = s.split("PU")[1]

            # Create rate plots (SingleTau, DiTau)
            if 1:
                opts.saveDir = aux.getSaveDirPath(opts.mcrab,
                                                  prefix="hltaus/",
                                                  postfix="TurnOns")

                PlotTurnOns(datasetsMgr, turnOnLists[0], s, PU,
                            "TurnOns_25GeV_%s_Inclusive" % (s))
                PlotTurnOns(datasetsMgr, turnOnLists[1], s, PU,
                            "TurnOns_50GeV_%s_Inclusive" % (s))

                PlotTurnOns(datasetsMgr, turnOnLists_noNeutrals[0], s, PU,
                            "TurnOns_25GeV_%s_noNeutrals" % (s))
                PlotTurnOns(datasetsMgr, turnOnLists_noNeutrals[1], s, PU,
                            "TurnOns_50GeV_%s_noNeutrals" % (s))

                PlotTurnOns(datasetsMgr, turnOnLists_withNeutrals[0], s, PU,
                            "TurnOns_25GeV_%s_withNeutrals" % (s))
                PlotTurnOns(datasetsMgr, turnOnLists_withNeutrals[1], s, PU,
                            "TurnOns_50GeV_%s_withNeutrals" % (s))

                PlotTurnOns(datasetsMgr, turnOnLists_1pr[0], s, PU,
                            "TurnOns_25GeV_%s_1pr" % (s))
                PlotTurnOns(datasetsMgr, turnOnLists_1pr[1], s, PU,
                            "TurnOns_50GeV_%s_1pr" % (s))

                PlotTurnOns(datasetsMgr, turnOnLists_3pr[0], s, PU,
                            "TurnOns_25GeV_%s_3pr" % (s))
                PlotTurnOns(datasetsMgr, turnOnLists_3pr[1], s, PU,
                            "TurnOns_50GeV_%s_3pr" % (s))

                PlotTurnOns(datasetsMgr, turnOnLists_all[0], s, PU,
                            "TurnOns_25GeV_%s_VtxIso_allModes" % (s))
                PlotTurnOns(datasetsMgr, turnOnLists_all[1], s, PU,
                            "TurnOns_50GeV_%s_VtxIso_allModes" % (s))
        print

    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(opts.gridX)
    style.setGridY(opts.gridY)

    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()
        if 0:
            datasetsMgr.loadLuminosities()  # from lumi.json

        # Custom filtering of datasets
        datasetsToRemove = []
        # For-loop: All dsets to be removed
        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()))

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

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

        # Define signal and background datasets names
        dsets_signal = []
        dsets_minBias = []
        for d in datasetsMgr.getAllDatasetNames():
            if "SingleNeutrino" in d:
                dsets_minBias.append(d)
            else:
                dsets_signal.append(d)

        # ROC curve ingredients (histograms)
        resList = [
            [
                "TkEG_EtResolution", "TkEG_EtResolution_1pr",
                "TkEG_EtResolution_3pr", "TkEG_EtResolution_withNeutrals",
                "TkEG_EtResolution_noNeutrals"
            ],
            [
                "TkEG_EtaResolution", "TkEG_EtaResolution_1pr",
                "TkEG_EtaResolution_3pr", "TkEG_EtaResolution_withNeutrals",
                "TkEG_EtaResolution_noNeutrals"
            ],
            [
                "TkEG_PhiResolution", "TkEG_PhiResolution_1pr",
                "TkEG_PhiResolution_3pr", "TkEG_PhiResolution_withNeutrals",
                "TkEG_PhiResolution_noNeutrals"
            ],
            [
                "TkEG_EtResolution", "TkEG_EtResolution_C",
                "TkEG_EtResolution_I", "TkEG_EtResolution_F"
            ],
            [
                "TkEG_EtaResolution", "TkEG_EtaResolution_C",
                "TkEG_EtaResolution_I", "TkEG_EtaResolution_F"
            ],
            [
                "TkEG_PhiResolution", "TkEG_PhiResolution_C",
                "TkEG_PhiResolution_I", "TkEG_PhiResolution_F"
            ],
            [
                "TkEG_EtResolution_F", "TkEG_EtResolution_1pr_F",
                "TkEG_EtResolution_3pr_F", "TkEG_EtResolution_withNeutrals_F",
                "TkEG_EtResolution_noNeutrals_F"
            ],
            [
                "TkEG_EtaResolution_F", "TkEG_EtaResolution_1pr_F",
                "TkEG_EtaResolution_3pr_F",
                "TkEG_EtaResolution_withNeutrals_F",
                "TkEG_EtaResolution_noNeutrals_F"
            ],
            [
                "TkEG_PhiResolution_F", "TkEG_PhiResolution_1pr_F",
                "TkEG_PhiResolution_3pr_F",
                "TkEG_PhiResolution_withNeutrals_F",
                "TkEG_PhiResolution_noNeutrals_F"
            ],
            [
                "TkEG_EtResolution_F_withEGs",
                "TkEG_EtResolution_1pr_F_withEGs",
                "TkEG_EtResolution_3pr_F_withEGs",
                "TkEG_EtResolution_withNeutrals_F_withEGs",
                "TkEG_EtResolution_noNeutrals_F_withEGs"
            ],
            [
                "TkEG_EtaResolution_F_withEGs",
                "TkEG_EtaResolution_1pr_F_withEGs",
                "TkEG_EtaResolution_3pr_F_withEGs",
                "TkEG_EtaResolution_withNeutrals_F_withEGs",
                "TkEG_EtaResolution_noNeutrals_F_withEGs"
            ],
            [
                "TkEG_PhiResolution_F_withEGs",
                "TkEG_PhiResolution_1pr_F_withEGs",
                "TkEG_PhiResolution_3pr_F_withEGs",
                "TkEG_PhiResolution_withNeutrals_F_withEGs",
                "TkEG_PhiResolution_noNeutrals_F_withEGs"
            ],
            [
                "TkEG_EtResolution_F_noEGs", "TkEG_EtResolution_1pr_F_noEGs",
                "TkEG_EtResolution_3pr_F_noEGs",
                "TkEG_EtResolution_withNeutrals_F_noEGs",
                "TkEG_EtResolution_noNeutrals_F_noEGs"
            ],
            [
                "TkEG_EtaResolution_F_noEGs", "TkEG_EtaResolution_1pr_F_noEGs",
                "TkEG_EtaResolution_3pr_F_noEGs",
                "TkEG_EtaResolution_withNeutrals_F_noEGs",
                "TkEG_EtaResolution_noNeutrals_F_noEGs"
            ],
            [
                "TkEG_PhiResolution_F_noEGs", "TkEG_PhiResolution_1pr_F_noEGs",
                "TkEG_PhiResolution_3pr_F_noEGs",
                "TkEG_PhiResolution_withNeutrals_F_noEGs",
                "TkEG_PhiResolution_noNeutrals_F_noEGs"
            ],
            [
                "TkEG_EtResolution_F_withEGs_posEta",
                "TkEG_EtResolution_1pr_F_withEGs_posEta",
                "TkEG_EtResolution_3pr_F_withEGs_posEta",
                "TkEG_EtResolution_withNeutrals_F_withEGs_posEta",
                "TkEG_EtResolution_noNeutrals_F_withEGs_posEta"
            ],
            [
                "TkEG_EtaResolution_F_withEGs_posEta",
                "TkEG_EtaResolution_1pr_F_withEGs_posEta",
                "TkEG_EtaResolution_3pr_F_withEGs_posEta",
                "TkEG_EtaResolution_withNeutrals_F_withEGs_posEta",
                "TkEG_EtaResolution_noNeutrals_F_withEGs_posEta"
            ],
            [
                "TkEG_PhiResolution_F_withEGs_posEta",
                "TkEG_PhiResolution_1pr_F_withEGs_posEta",
                "TkEG_PhiResolution_3pr_F_withEGs_posEta",
                "TkEG_PhiResolution_withNeutrals_F_withEGs_posEta",
                "TkEG_PhiResolution_noNeutrals_F_withEGs_posEta"
            ],
            [
                "TkEG_EtResolution_F_noEGs_posEta",
                "TkEG_EtResolution_1pr_F_noEGs_posEta",
                "TkEG_EtResolution_3pr_F_noEGs_posEta",
                "TkEG_EtResolution_withNeutrals_F_noEGs_posEta",
                "TkEG_EtResolution_noNeutrals_F_noEGs_posEta"
            ],
            [
                "TkEG_EtaResolution_F_noEGs_posEta",
                "TkEG_EtaResolution_1pr_F_noEGs_posEta",
                "TkEG_EtaResolution_3pr_F_noEGs_posEta",
                "TkEG_EtaResolution_withNeutrals_F_noEGs_posEta",
                "TkEG_EtaResolution_noNeutrals_F_noEGs_posEta"
            ],
            [
                "TkEG_PhiResolution_F_noEGs_posEta",
                "TkEG_PhiResolution_1pr_F_noEGs_posEta",
                "TkEG_PhiResolution_3pr_F_noEGs_posEta",
                "TkEG_PhiResolution_withNeutrals_F_noEGs_posEta",
                "TkEG_PhiResolution_noNeutrals_F_noEGs_posEta"
            ],
            [
                "TkEG_EtResolution_F_withEGs_negEta",
                "TkEG_EtResolution_1pr_F_withEGs_negEta",
                "TkEG_EtResolution_3pr_F_withEGs_negEta",
                "TkEG_EtResolution_withNeutrals_F_withEGs_negEta",
                "TkEG_EtResolution_noNeutrals_F_withEGs_negEta"
            ],
            [
                "TkEG_EtaResolution_F_withEGs_negEta",
                "TkEG_EtaResolution_1pr_F_withEGs_negEta",
                "TkEG_EtaResolution_3pr_F_withEGs_negEta",
                "TkEG_EtaResolution_withNeutrals_F_withEGs_negEta",
                "TkEG_EtaResolution_noNeutrals_F_withEGs_negEta"
            ],
            [
                "TkEG_PhiResolution_F_withEGs_negEta",
                "TkEG_PhiResolution_1pr_F_withEGs_negEta",
                "TkEG_PhiResolution_3pr_F_withEGs_negEta",
                "TkEG_PhiResolution_withNeutrals_F_withEGs_negEta",
                "TkEG_PhiResolution_noNeutrals_F_withEGs_negEta"
            ],
            [
                "TkEG_EtResolution_F_noEGs_negEta",
                "TkEG_EtResolution_1pr_F_noEGs_negEta",
                "TkEG_EtResolution_3pr_F_noEGs_negEta",
                "TkEG_EtResolution_withNeutrals_F_noEGs_negEta",
                "TkEG_EtResolution_noNeutrals_F_noEGs_negEta"
            ],
            [
                "TkEG_EtaResolution_F_noEGs_negEta",
                "TkEG_EtaResolution_1pr_F_noEGs_negEta",
                "TkEG_EtaResolution_3pr_F_noEGs_negEta",
                "TkEG_EtaResolution_withNeutrals_F_noEGs_negEta",
                "TkEG_EtaResolution_noNeutrals_F_noEGs_negEta"
            ],
            [
                "TkEG_PhiResolution_F_noEGs_negEta",
                "TkEG_PhiResolution_1pr_F_noEGs_negEta",
                "TkEG_PhiResolution_3pr_F_noEGs_negEta",
                "TkEG_PhiResolution_withNeutrals_F_noEGs_negEta",
                "TkEG_PhiResolution_noNeutrals_F_noEGs_negEta"
            ],
            [
                "TkEG_ChargedResolution", "TkEG_ChargedResolution_1pr",
                "TkEG_ChargedResolution_3pr",
                "TkEG_ChargedResolution_withNeutrals",
                "TkEG_ChargedResolution_noNeutrals"
            ],
            [
                "TkEG_NeutralsResolution", "TkEG_NeutralsResolution_1pr",
                "TkEG_NeutralsResolution_3pr",
                "TkEG_NeutralsResolution_withNeutrals",
                "TkEG_NeutralsResolution_noNeutrals"
            ],
            [
                "TkEG_EtResolution_withEGs", "TkEG_EtResolution_1pr_withEGs",
                "TkEG_EtResolution_3pr_withEGs",
                "TkEG_EtResolution_withNeutrals_withEGs",
                "TkEG_EtResolution_noNeutrals_withEGs"
            ],
            [
                "TkEG_EtResolution_noEGs", "TkEG_EtResolution_1pr_noEGs",
                "TkEG_EtResolution_3pr_noEGs",
                "TkEG_EtResolution_withNeutrals_noEGs",
                "TkEG_EtResolution_noNeutrals_noEGs"
            ],
            [
                "TkEG_EtResolution_withNeutrals",
                "TkEG_EtResolution_withNeutrals_1pr",
                "TkEG_EtResolution_withNeutrals_3pr"
            ],
            [
                "TkEG_EtResolution_withNeutrals",
                "TkEG_EtResolution_withNeutrals_1pion0",
                "TkEG_EtResolution_withNeutrals_2pion0",
                "TkEG_EtResolution_withNeutrals_3pion0"
            ],  #,"TkEG_EtResolution_withNeutrals_4pion0"],
            [
                "TkEG_EtResolution_withNeutrals_withEGs",
                "TkEG_EtResolution_withNeutrals_withEGs_0to5GeV",
                "TkEG_EtResolution_withNeutrals_withEGs_5to10GeV",
                "TkEG_EtResolution_withNeutrals_withEGs_10to15GeV",
                "TkEG_EtResolution_withNeutrals_withEGs_15to20GeV",
                "TkEG_EtResolution_withNeutrals_withEGs_20to30GeV",
                "TkEG_EtResolution_withNeutrals_withEGs_30to40GeV",
                "TkEG_EtResolution_withNeutrals_withEGs_40to50GeV"
            ]
        ]

        # For-loop: All signal histos
        for i, s in enumerate(dsets_signal, 1):
            PU = s.split("PU")[1]

            # By decay mode
            PlotHistos(datasetsMgr, resList[0], s, PU,
                       "ResolutionEt_%s_all" % (s))
            PlotHistos(datasetsMgr, resList[1], s, PU,
                       "ResolutionEta_%s_all" % (s))
            PlotHistos(datasetsMgr, resList[2], s, PU,
                       "ResolutionPhi_%s_all" % (s))

            # By eta region (central, intermediate, forward)
            PlotHistos(datasetsMgr, resList[3], s, PU,
                       "ResolutionEt_%s_cif" % (s))
            PlotHistos(datasetsMgr, resList[4], s, PU,
                       "ResolutionEta_%s_cif" % (s))
            PlotHistos(datasetsMgr, resList[5], s, PU,
                       "ResolutionPhi_%s_cif" % (s))

            PlotHistos(datasetsMgr, resList[6], s, PU,
                       "ResolutionEt_%s_all_F" % (s))
            PlotHistos(datasetsMgr, resList[7], s, PU,
                       "ResolutionEta_%s_all_F" % (s))
            PlotHistos(datasetsMgr, resList[8], s, PU,
                       "ResolutionPhi_%s_all_F" % (s))

            PlotHistos(datasetsMgr, resList[9], s, PU,
                       "ResolutionEt_%s_all_F_withEGs" % (s))
            PlotHistos(datasetsMgr, resList[10], s, PU,
                       "ResolutionEta_%s_all_F_withEGs" % (s))
            PlotHistos(datasetsMgr, resList[11], s, PU,
                       "ResolutionPhi_%s_all_F_withEGs" % (s))

            PlotHistos(datasetsMgr, resList[12], s, PU,
                       "ResolutionEt_%s_all_F_noEGs" % (s))
            PlotHistos(datasetsMgr, resList[13], s, PU,
                       "ResolutionEta_%s_all_F_noEGs" % (s))
            PlotHistos(datasetsMgr, resList[14], s, PU,
                       "ResolutionPhi_%s_all_F_noEGs" % (s))

            PlotHistos(datasetsMgr, resList[15], s, PU,
                       "ResolutionEt_%s_all_F_withEGs_posEta" % (s))
            PlotHistos(datasetsMgr, resList[16], s, PU,
                       "ResolutionEta_%s_all_F_withEGs_posEta" % (s))
            PlotHistos(datasetsMgr, resList[17], s, PU,
                       "ResolutionPhi_%s_all_F_withEGs_posEta" % (s))

            PlotHistos(datasetsMgr, resList[18], s, PU,
                       "ResolutionEt_%s_all_F_noEGs_posEta" % (s))
            PlotHistos(datasetsMgr, resList[19], s, PU,
                       "ResolutionEta_%s_all_F_noEGs_posEta" % (s))
            PlotHistos(datasetsMgr, resList[20], s, PU,
                       "ResolutionPhi_%s_all_F_noEGs_posEta" % (s))

            PlotHistos(datasetsMgr, resList[21], s, PU,
                       "ResolutionEt_%s_all_F_withEGs_negEta" % (s))
            PlotHistos(datasetsMgr, resList[22], s, PU,
                       "ResolutionEta_%s_all_F_withEGs_negEta" % (s))
            PlotHistos(datasetsMgr, resList[23], s, PU,
                       "ResolutionPhi_%s_all_F_withEGs_negEta" % (s))

            PlotHistos(datasetsMgr, resList[24], s, PU,
                       "ResolutionEt_%s_all_F_noEGs_negEta" % (s))
            PlotHistos(datasetsMgr, resList[25], s, PU,
                       "ResolutionEta_%s_all_F_noEGs_negEta" % (s))
            PlotHistos(datasetsMgr, resList[26], s, PU,
                       "ResolutionPhi_%s_all_F_noEGs_negEta" % (s))

            PlotHistos(datasetsMgr, resList[27], s, PU,
                       "ResolutionCharged_%s_all" % (s))
            PlotHistos(datasetsMgr, resList[28], s, PU,
                       "ResolutionNeutrals_%s_all" % (s))

            PlotHistos(datasetsMgr, resList[29], s, PU,
                       "ResolutionEt_%s_all_withEGs" % (s))
            PlotHistos(datasetsMgr, resList[30], s, PU,
                       "ResolutionEt_%s_all_noEGs" % (s))
            PlotHistos(datasetsMgr, resList[31], s, PU,
                       "ResolutionEt_%s_withNeutrals" % (s))
            PlotHistos(datasetsMgr, resList[32], s, PU,
                       "ResolutionEt_%s_withNeutrals_Npion0" % (s))

            PlotHistos(datasetsMgr, resList[33], s, PU,
                       "ResolutionEt_%s_withNeutrals_withEGs_etSteps" % (s))

        print

    Print(
        "All plots saved under directory %s" %
        (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) +
         ShellStyles.NormalStyle()), True)
    return
Beispiel #12
0
def Plot2dHistograms(datasetsMgr, dsetName, histoName, index):

    msg = "%s%s (%s)%s" % (ShellStyles.SuccessStyle(), histoName, dsetName, ShellStyles.NormalStyle() )
    aux.PrintFlushed(msg, index==1)

    # Custom Filtering of datasets 
    dsetsMgr = datasetsMgr.deepCopy()
    if opts.verbose:
        dsetsMgr.PrintInfo()

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

    for i, d in enumerate(dsetsMgr.getAllDatasetNames(), 0):
        if d == dsetName:
            continue
        else:
            # Remove dataset from manager but do NOT close the file!
            dsetsMgr.remove(d, close=False)

    # Sanity check
    nDatasets = len(dsetsMgr.getAllDatasets())
    if nDatasets > 1:
        raise Exception("More than 1 datasets detected in the dataset manager! Can only support 1 dataset. Please use the -i option to choose exactly 1 dataset'")

    # Get the reference histo and the list of histos to compare
    datasets0 = dsetsMgr.getAllDatasets()[0].getName()
    histoList = [getHisto(dsetsMgr, datasets0, histoName)]

    # Create the 2d plot  
    Verbose("Creating the 2d plot", True)
    if opts.normalizeToLumi:
        p = plots.MCPlot(dsetsMgr, histoName, normalizeToLumi=opts.intLumi, saveFormats=[])
    elif opts.normalizeByCrossSection:
        p = plots.MCPlot(dsetsMgr, histoName, normalizeByCrossSection=True, saveFormats=[], **{})
    elif opts.normalizeToOne:
        p = plots.MCPlot(dsetsMgr, histoName, normalizeToOne=True, saveFormats=[], **{})
    else:
        raise Exception("One of the options --normalizeToOne, --normalizeByCrossSection, --normalizeToLumi must be enabled (set to \"True\").")

    Verbose("Setting universal histo styles", True)
    p.histoMgr.setHistoDrawStyleAll("COLZ")
    #p.histoMgr.setHistoLegendStyleAll("L")

    Verbose("Customising histograms", True)
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().GetZaxis().SetTitleOffset(1.3)) #fixme

    Verbose("Setting plot styles to histograms", True)
    for index, h in enumerate(p.histoMgr.getHistos()):
        plots._plotStyles[p.histoMgr.getHistos()[index].getDataset().getName()].apply(p.histoMgr.getHistos()[index].getRootHisto())

    Verbose("Drawing the plot", True)
    plots.drawPlot(p, saveName, **kwargs_) #the "**" unpacks the kwargs_ dictionary
    
    # Add fit line for shrinking cone?
    const= 0.0
    coeff= 0.0
    step = 1    
    xmin = 0
    xmax = 0
    if "GenP_VisEt_Vs" in histoName:
        const=   3.5
        coeff=   1.0        
        step =   100    
        xmin =   0
        xmax =  30
    if "GenP_PtLdg_Vs" in histoName:
        const=   2.5 #2.0
        coeff=   1.0
        step = 100
        xmin =   0
        xmax =  30
    if "VtxIso_Vs_RelIso" in histoName:
        const= -0.5
        coeff=  0.3 #0.4
        step =  100
        xmin =   0
        xmax =   0#3

    if "GenP_VisEt_Vs" in histoName or "GenP_PtLdg_Vs" in histoName:
        gr = getCustomTGraph(histoName, const, coeff, xmin, xmax, step)
        gr.SetLineWidth(3)
        gr.Draw("L same")

    Verbose("Removing the legend", True)
    p.removeLegend()

    Verbose("Adding text on canvas", True)
    histograms.addText(0.22, 0.89, plots._legendLabels[datasets0], 18)
    #histograms.addText(0.5, 0.89, plots._legendLabels[datasets0], 18)

    Verbose("Saving the canvas", True)
    aux.SavePlot(p, opts.saveDir, saveName, opts.saveFormats, opts.url)

    return
Beispiel #13
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(False, 0.15)

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

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

        # Custom Filtering of datasets 
        datasetsToRemove = []
        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()))

        if opts.verbose:
            datasetsMgr.PrintInfo()

        # Re-order datasets (different for inverted than default=baseline)
        newOrder = []
        for d in datasetsMgr.getMCDatasets():
            newOrder.append(d.getName())
            
        # Apply new dataset order!
        datasetsMgr.selectAndReorder(newOrder)
        
        # Print dataset information
        datasetsMgr.PrintInfo()        

        # Plot Histograms
        histoList  = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(opts.folder)
        histoPaths = [os.path.join(opts.folder, h) for h in histoList]
        
        # For-loop: All histograms in chosen folder
        counter = 0
        for i, h in enumerate(histoPaths, 1):
            histoType  = str(type(datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDatasetRootHisto(h).getHistogram()))
            if "TH2" not in histoType:
                continue
            if "DiTau" in h:
                continue
            if "L1TkIsoTau" in h:
                continue

            # For-loop: All datasets
            for d in datasetsMgr.getAllDatasetNames():
                counter += 1
                #if d != "SingleNeutrino_L1TPU140":
                #    continue
                #if "reliso" not in h.lower():
                #    continue
                Plot2dHistograms(datasetsMgr, d, h, counter)
    print
    Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True)
    return
Beispiel #14
0
def main(opts):

    # Set the ROOTeError verbosity
    ROOT.gErrorIgnoreLevel = 3000  # kUnset=-1, kPrint=0, kInfo=1000, kWarning=2000, kError=3000, kBreak=4000

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

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

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

    # Sanity check
    nDatasets = len(datasetsMgr.getAllDatasetNames())
    if (nDatasets) > 1:
        raise Exception(
            "More than 1 datasets found! Please choose only 1 dataset (-i \"regex\") and retry"
        )

    # Plot Histograms
    histoList = datasetsMgr.getDataset(
        datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(opts.folder)
    histoPaths = [os.path.join(opts.folder, h) for h in histoList]
    histoType = type(
        datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()
                               [0]).getDatasetRootHisto(h).getHistogram())
    plotCount = 0

    # For-loop: All# histos in opts.folder
    for i, h in enumerate(histoPaths, 1):

        histoType = str(
            type(
                datasetsMgr.getDataset(
                    datasetsMgr.getAllDatasetNames()[0]).getDatasetRootHisto(
                        h).getHistogram()))
        if "TH1" in histoType or "TDirectoryFile" in histoType:
            continue
        else:
            # print "histoType = ", histoType
            pass

        if "GenP" in h:
            continue

        aux.PrintFlushed(h, plotCount == 0)
        plotCount += 1

        PlotHisto(datasetsMgr, h, histoType)

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