Esempio n. 1
0
def main():

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        sys.exit(0)
    else:
        pass

    ###################
    ## SETUP THE PROCESS
    ###################

    maxEvents = {}

    process = Process(prefix, maxEvents=maxEvents)

    ###################
    ## ADD DATASETS
    ###################

    process.addDatasetsFromMulticrab(sys.argv[1],
                                     blacklist=blacklist,
                                     whitelist=whitelist)

    # Enable genuine tau histograms for common plots (needed for calculating N_QCD)
    allSelections.CommonPlots.enableGenuineTauHistograms = True

    # Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
    allSelections.CommonPlots.histogramSplitting = [
        PSet(label="tauPt_1", binLowEdges=[40, 60], useAbsoluteValues=False),
        PSet(label="decayMode_1", binLowEdges=[2, 3], useAbsoluteValues=False),
        PSet(label="tauPt_2",
             binLowEdges=[20, 40, 60],
             useAbsoluteValues=False),
        PSet(label="decayMode_2",
             binLowEdges=[1, 2, 3],
             useAbsoluteValues=False),
    ]

    ##################
    ## BUILD ANALYSIS MODULES
    ###################

    builder = AnalysisBuilder(
        prefix,
        dataEras,
        searchModes,
        ### OPRIONS ###
        usePUreweighting=True,
        useTopPtReweighting=False,
        doSystematicVariations=True,
        analysisType="HToHW_background")

    builder.build(process, allSelections)

    process.run()
Esempio n. 2
0
def main():


    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        sys.exit(0)
    else:
        pass


    ###################
    ## SETUP THE PROCESS
    ###################

    maxEvents = {}

    process = Process(prefix, maxEvents = maxEvents)

    ###################
    ## ADD DATASETS
    ###################

    process.addDatasetsFromMulticrab(sys.argv[1],blacklist=blacklist,whitelist=whitelist)


    ##################
    ## BUILD ANALYSIS MODULES
    ###################

    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
			      ### OPRIONS ###
                              usePUreweighting       = True,
                              useTopPtReweighting    = False,
                              doSystematicVariations = False
			      )



    builder.build(process, allSelections)


    process.run()
Esempio n. 3
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    completeList = GetDatasetCompleteList()
    whiteList = GetDatasetWhitelist(opts)
    blackList = GetDatasetBlackList(completeList, whiteList)
    maxEvents = {}
    for d in whiteList:
        #maxEvents[d] = 100
        maxEvents[d] = -1
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" %
              (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" %
              (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        myBlackList = []
        myBlackList.extend(blackList)
        Verbose("Adding all datasets from multiCRAB directory %s" %
                (opts.mcrab))
        Verbose(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        regex = "|".join(myBlackList)
        if len(whiteList) > 0:
            process.addDatasetsFromMulticrab(
                opts.mcrab, includeOnlyTasks="|".join(whiteList))
        elif len(myBlackList) > 0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.jetTriggers import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    #==========================
    #  Systematics selections
    #==========================

    # MET
    allSelections.METSelection.METCutValue = 50.0

    # Muon
    allSelections.MuonSelection.muonPtCut = 30

    # Jets
    allSelections.JetSelection.numberOfJetsCutValue = 4
    allSelections.JetSelection.jetPtCuts = [40.0, 40.0, 40.0, 30.0]

    # Triggers
    allSelections.Trigger.triggerOR = ["HLT_Mu50"]
    # Bjets
    allSelections.BJetSelection.jetPtCuts = [40.0, 30.0]
    allSelections.BJetSelection.numberOfBJetsCutValue = 2

    # allSelections.BjetSelection.triggerMatchingApply = True
    # allSelections.TopSelection.ChiSqrCutValue = 100.0
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics,
                              analysisType="HToTB")

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt = int(tFinish) - int(tStart)
    days = divmod(dt, 86400)  # days
    hours = divmod(days[1], 3600)  # hours
    mins = divmod(hours[1], 60)  # minutes
    secs = mins[1]  # seconds
    Print(
        "Total elapsed time is %s days, %s hours, %s mins, %s secs" %
        (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 4
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    completeList = GetDatasetCompleteList()
    whiteList = GetDatasetWhitelist(opts)
    blackList = GetDatasetBlackList(completeList, whiteList)
    maxEvents = {}
    for d in whiteList:
        maxEvents[d] = -1
        #maxEvents[d] = 100 #for testing
        #if  d == "ChargedHiggs_HplusTB_HplusToTB_M_650":
        #    maxEvents[d] = 4000000
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" %
                (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" %
                (opts.excludeTasks, opts.mcrab))
        Verbose(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        myBlackList = [
            "QCD_b"
            "ChargedHiggs_HplusTB_HplusToTB_M_180",
            "ChargedHiggs_HplusTB_HplusToTB_M_200",
            "ChargedHiggs_HplusTB_HplusToTB_M_220",
            "ChargedHiggs_HplusTB_HplusToTB_M_250",
            "ChargedHiggs_HplusTB_HplusToTB_M_300",
            "ChargedHiggs_HplusTB_HplusToTB_M_350",
            "ChargedHiggs_HplusTB_HplusToTB_M_400",
            "ChargedHiggs_HplusTB_HplusToTB_M_500",
            "ChargedHiggs_HplusTB_HplusToTB_M_650",
            "ChargedHiggs_HplusTB_HplusToTB_M_800",
            "ChargedHiggs_HplusTB_HplusToTB_M_1000",
            "ChargedHiggs_HplusTB_HplusToTB_M_1500",
            "ChargedHiggs_HplusTB_HplusToTB_M_2000",
            "ChargedHiggs_HplusTB_HplusToTB_M_2500",
            "ChargedHiggs_HplusTB_HplusToTB_M_3000",
            "ChargedHiggs_HplusTB_HplusToTB_M_5000",
            "ChargedHiggs_HplusTB_HplusToTB_M_7000",
            "ChargedHiggs_HplusTB_HplusToTB_M_10000",
            # "ChargedHiggs_HplusTB_HplusToTB_M_180_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_200_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_220_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_250_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_300_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_350_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_400_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_500_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_800_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_1000_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_1500_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_2000_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_2500_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_3000_ext1",
        ]
        if opts.doSystematics:
            whiteList = GetDatasetWhitelist(opts)

        # Extend the blacklist with datasets not in the group
        myBlackList.extend(blackList)

        Verbose(
            "Adding the following datasets from multiCRAB directory %s:\n\t%s"
            % (opts.mcrab, "\n\t".join(whiteList)))
        Verbose(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        if len(whiteList) > 0:
            process.addDatasetsFromMulticrab(
                opts.mcrab, includeOnlyTasks="|".join(whiteList))
        elif len(myBlackList) > 0:
            #if len(myBlackList)>0:
            process.addDatasetsFromMulticrab(
                opts.mcrab, excludeTasks="|".join(myBlackList))
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

        # ***************************************
        # Keep ONLY datasets in whitelist
        # ***************************************
        Verbose("Removing datasets NOT included in whitelist:")
        removeList = []
        for i, d in enumerate(process.getDatasets()):
            if d.getName() not in whiteList:
                Verbose("Dataset to be removed: %s" % (d.getName()))
                removeList.append(d)

        for d in removeList:
            process._datasets.remove(d)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel
    # allSelections.BjetSelection.triggerMatchingApply = True
    # allSelections.TopSelection.ChiSqrCutValue = 100.0
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose,
                              systVarsList=opts.systVarsList)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Verbose("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt = int(tFinish) - int(tStart)
    days = divmod(dt, 86400)  # days
    hours = divmod(days[1], 3600)  # hours
    mins = divmod(hours[1], 60)  # minutes
    secs = mins[1]  # seconds
    Print(
        "Total elapsed time is %s days, %s hours, %s mins, %s secs" %
        (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 5
0
#!/usr/bin/env python

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer

process = Process()

# Example of adding a dataset which has its files defined in data/<dataset_name>.txt file
#process.addDatasets(["TTbar_HBWB_HToTauNu_M_160_13TeV_pythia6"])

# Example of adding datasets from a multicrab directory
import sys
if len(sys.argv) != 2:
    print "Usage: ./exampleAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)
process.addDatasetsFromMulticrab(sys.argv[1])

# Example of adding an analyzer
process.addAnalyzer("test", Analyzer("ExampleAnalysis",
                                     tauPtCut = 10
))

# Example of adding an analyzer whose configuration depends on dataVersion
def createAnalyzer(dataVersion):
    a = Analyzer("ExampleAnalysis")
    if dataVersion.isMC():
        a.tauPtCut = 10
    else:
        a.tauPtCut = 20
    return a
process.addAnalyzer("test2", createAnalyzer)
Esempio n. 6
0
#!/usr/bin/env python

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer

import os
import re

process = Process(outputPrefix="tauLegEfficiency")

# Example of adding a dataset which has its files defined in data/<dataset_name>.txt file
#process.addDatasets(["TTbar_HBWB_HToTauNu_M_160_13TeV_pythia6"])

# Example of adding datasets from a multicrab directory
import sys
if len(sys.argv) != 2:
    print "Usage: ./exampleAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)

process.addDatasetsFromMulticrab(sys.argv[1])
#process.addDatasetsFromMulticrab(sys.argv[1],includeOnlyTasks="SingleMuon_Run2015D_PromptReco_v3_246908_260426_25ns$")
#process.addDatasetsFromMulticrab(sys.argv[1],includeOnlyTasks="SingleMuon_Run2015")
#process.addDatasetsFromMulticrab(sys.argv[1],includeOnlyTasks="DYJetsToLL_M50")
#process.addDatasetsFromMulticrab(sys.argv[1],includeOnlyTasks="GluGluHToTauTau_M125")

leg = "taulegSelection"
#binning = [20, 30, 40, 50, 60, 70, 80, 100, 120, 140, 160, 180, 200]
binning = [20, 30, 40, 50, 60, 80, 100, 200]
xLabel = "#tau-jet p_{T} (GeV/c)"
yLabel = "HLT tau efficiency"

import HiggsAnalysis.NtupleAnalysis.tools.aux as aux
Esempio n. 7
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    process = Process(prefix, postfix, maxEvents)
                
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = ["QCD_b"
                       "ChargedHiggs_HplusTB_HplusToTB_M_180_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_200_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_220_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_250_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_300_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_350_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_400_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_500_ext1", 
                       #"ChargedHiggs_HplusTB_HplusToTB_M_650",  #10M events!
                       "ChargedHiggs_HplusTB_HplusToTB_M_800_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_1000_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_2000_ext1"
                       "ChargedHiggs_HplusTB_HplusToTB_M_2500_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_3000_ext1", 
                       # "ChargedHiggs_HplusTB_HplusToTB_M_1000",
                       "ChargedHiggs_HplusTB_HplusToTB_M_1500",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_2000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_2500",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_3000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_5000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_7000",   # Speeed things up  
                       "ChargedHiggs_HplusTB_HplusToTB_M_10000",  # Speeed things up
                       ]
        if opts.doSystematics:
            myBlackList.append("QCD")

        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        regex =  "|".join(myBlackList)
        if len(myBlackList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)



    # ================================================================================================
    # Overwrite Default Settings  
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.jetTriggers import allSelections
    from HiggsAnalysis.NtupleAnalysis.main import PSet
    import HiggsAnalysis.NtupleAnalysis.parameters.scaleFactors as scaleFactors

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    #==========================
    #  Systematics selections
    #==========================

    # BDT MisID SF
    MisIDSF = PSet(
        MisIDSFJsonName = "Efficiency_SystBDT_CR2_MET50_MuIso0p1_InvMET20_InvMuIso0p1.json", # For Fake TT:  CR1, qcd+ewk+st CR2
        ApplyMisIDSF    = False, 
        )
    scaleFactors.assignMisIDSF(MisIDSF, "nominal", MisIDSF.MisIDSFJsonName)
    allSelections.MisIDSF = MisIDSF
    
    allSelections.SystTopBDTSelection.MiniIsoCutValue    = 0.1
    allSelections.SystTopBDTSelection.MiniIsoInvCutValue = 0.1
    allSelections.SystTopBDTSelection.METCutValue        = 50.0
    allSelections.SystTopBDTSelection.METInvCutValue     = 20.0
    
    # Muon
    allSelections.MuonSelection.muonPtCut = 30
    
    # Jets
    allSelections.JetSelection.numberOfJetsCutValue = 4
    allSelections.JetSelection.jetPtCuts = [40.0, 40.0, 40.0, 30.0]
        
    # Trigger 
    allSelections.Trigger.triggerOR = ["HLT_Mu50"]

    # Bjets
    allSelections.BJetSelection.jetPtCuts = [40.0, 30.0]
    allSelections.BJetSelection.numberOfBJetsCutValue = 2
    
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections


    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    
    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics,
                              analysisType="HToTB")

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt      = int(tFinish) - int(tStart)
    days    = divmod(dt,86400)      # days
    hours   = divmod(days[1],3600)  # hours
    mins    = divmod(hours[1],60)   # minutes
    secs    = mins[1]               # seconds
    Print("Total elapsed time is %s days, %s hours, %s mins, %s secs" % (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 8
0
def addAnalyzer(era):
    process = Process(outputPrefix="L1Study")
    process.addDatasetsFromMulticrab(sys.argv[1],includeOnlyTasks="2016H")
    ds = getDatasetsForEras(process.getDatasets(),eras[era])
    process.setDatasets(ds)
    global runmin,runmax
    runmin,runmax = process.getRuns()
    process.addAnalyzer("L1Study_"+eras[era], lambda dv: createAnalyzer(dv, era))
    process.run()
Esempio n. 9
0
def main():

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    process = Process(prefix, postfix, opts.nEvts)

            
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab)


    # ================================================================================================
    # Selection customisations
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    #from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections

    # Overwrite verbosity
    allSelections.verbose = opts.verbose

    # Overwrite histo ambient level (Options: Systematics, Vital, Informative, Debug)
    allSelections.histogramAmbientLevel = opts.histoLevel

    
    # Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
    # allSelections.CommonPlots.histogramSplitting = [
    #     PSet(label="tauPt", binLowEdges=[60.0, 70.0, 80.0, 100.0], useAbsoluteValues=False),
    #     ]

    # allSelections.TauSelection.rtau = 0.0      
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections
    

    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    
    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics)

    # Perform variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))


    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? By default it uses all cores, but you can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()
Esempio n. 10
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    completeList = GetDatasetCompleteList()
    whiteList = GetDatasetWhitelist(opts)
    blackList = GetDatasetBlackList(completeList, whiteList)
    maxEvents = {}
    for d in whiteList:
        maxEvents[d] = -1
        #if  d == "ChargedHiggs_HplusTB_HplusToTB_M_650":
        #    maxEvents[d] = 4000000
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" %
                (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" %
                (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        myBlackList = blackList
        #myBlackList = ["M_180", "M_200" , "M_220" , "M_250" , "M_300" , "M_350" , "M_400" , "M_500" , "M_650",
        #               "M_800", "M_1000", "M_1500", "M_2000", "M_2500", "M_3000", "M_5000", "M_7000", "M_10000"]

        # Extend the blacklist with datasets not in the group
        #myBlackList.extend(blackList)

        Verbose("Adding all datasets from multiCRAB directory %s except %s" %
                (opts.mcrab, (",".join(myBlackList))))
        Verbose(
            "Vertex reweighting is done according to the chosen data era (%s)"
            % (",".join(dataEras)))
        regex = "|".join(myBlackList)
        if len(myBlackList) > 0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    # Set splitting of phase-space (first bin is below first edge value and last bin is above last edge value)
    allSelections.CommonPlots.histogramSplitting = [
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 160,  300], useAbsoluteValues=False), # last (not bad)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 120,  300], useAbsoluteValues=False), # last (not bad)
        #PSet(label="TetrajetBjetPt" , binLowEdges=[50, 150,  300], useAbsoluteValues=False), # last (quite good)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 60,  150], useAbsoluteValues=False),
        # PSet(label="TetrajetBjetPt" , binLowEdges=[60, 90, 160, 300], useAbsoluteValues=False), # BEST (v1)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 60, 90, 160, 330], useAbsoluteValues=False),
        PSet(label="TetrajetBjetPt",
             binLowEdges=[60, 90, 160, 300],
             useAbsoluteValues=False),  # BEST (v2)
        #PSet(label="TetrajetBjetPt" , binLowEdges=[60, 90, 160, 300], useAbsoluteValues=False), # BEST (v3)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 65, 130, 330], useAbsoluteValues=False), # BEST (v4)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 65, 95, 130, 330], useAbsoluteValues=False), # BEST (v5)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[45, 50, 60, 90, 160, 330], useAbsoluteValues=False), # BEST (v5)
        #
        PSet(label="TetrajetBjetEta",
             binLowEdges=[0.8, 1.4, 2.0],
             useAbsoluteValues=True),  # optimised
    ]

    # Overwrite values
    # allSelections.TopSelectionBDT.CSV_bDiscCutDirection  = ">="
    allSelections.TopSelectionBDT.CSV_bDiscCutValue = 0.54  # allow CSVv2-L for inverted top

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    # ================================================================================================
    # Build analysis modules
    # ================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose,
                              systVarsList=opts.systVarsList)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("BJetSelection.triggerMatchingApply", [True, False]) # At least 1 trg b-jet dR-matched to offline b-jets
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutValue", [100, 20])
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["=="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutDirection", [">="])
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscr", "")
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscrWorkingPoint", "Loose")
    # builder.addVariation("FakeBMeasurement.invertedBJetsSortType", ["Random", "DescendingBDiscriminator"])
    # builder.addVariation("FakeBMeasurement.invertedBJetsDiscrMaxCutValue", [0.82, 0.80, 0.75, 0.70])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [100])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT450_SixJet40"], ["HLT_PFHT400_SixJet30"]])
    # builder.addVariation("TopologySelection.FoxWolframMomentCutValue", [0.5, 0.7])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"], ["HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056", "HLT_PFHT450_SixJet40_BTagCSV_p056"]])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    # def createAnalyzer(dataVersion):
    # a = Analyzer("ExampleAnalysis")
    # if dataVersion.isMC():
    # a.tauPtCut = 10
    # else:
    # a.tauPtCut = 20
    # return a
    # process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    # process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt = int(tFinish) - int(tStart)
    days = divmod(dt, 86400)  # days
    hours = divmod(days[1], 3600)  # hours
    mins = divmod(hours[1], 60)  # minutes
    secs = mins[1]  # seconds
    Print(
        "Total elapsed time is %s days, %s hours, %s mins, %s secs" %
        (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 11
0
def main():

    # Require at least two arguments (script-name, path to multicrab)     
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass


    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    # maxEvents["2016"] = 1
    # maxEvents["ZZTo4Q"] = -1
    # maxEvents["ZJetsToQQ_HT600toInf"] = 1
    # maxEvents["WZ_ext1"] = 1
    # maxEvents["WZ"] = 1
    # maxEvents["WWTo4Q"] = 1
    # maxEvents["WJetsToQQ_HT_600ToInf"] = 1
    # maxEvents["TTZToQQ"] = 1
    # maxEvents["TTWJetsToQQ"] = 1
    # maxEvents["TTTT"] = 1
    # maxEvents["TT"] = 1
    # maxEvents["ST_t_channel_top_4f_inclusiveDecays"] = 1
    # maxEvents["ST_t_channel_antitop_4f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays"] = 1
    # maxEvents["ST_s_channel_4f_InclusiveDecays"] = 1
    # maxEvents["QCD_HT700to1000_ext1"] = 1
    # maxEvents["QCD_HT700to1000"] = 1
    # maxEvents["QCD_HT50to100"] = 1
    # maxEvents["QCD_HT500to700_ext1"] = 1
    # maxEvents["QCD_HT500to700"] = 1
    # maxEvents["QCD_HT300to500_ext1"] = 1
    # maxEvents["QCD_HT300to500"] = 1
    # maxEvents["QCD_HT200to300_ext1"] = 1
    # maxEvents["QCD_HT200to300"] = 1
    # maxEvents["QCD_HT2000toInf_ext1"] = 1
    # maxEvents["QCD_HT2000toInf"] = 1
    # maxEvents["QCD_HT1500to2000_ext1"] = 1
    # maxEvents["QCD_HT1500to2000"] = 1
    # maxEvents["QCD_HT100to200"] = 1
    # maxEvents["QCD_HT1000to1500_ext1"] = 1
    # maxEvents["QCD_HT1000to1500"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver3_v1_284036_284044"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver2_v1_281613_284035"] = 1
    # maxEvents["JetHT_Run2016G_03Feb2017_v1_278820_280385"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_278801_278808"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_277932_278800"] = 1
    # maxEvents["JetHT_Run2016E_03Feb2017_v1_276831_277420"] = 1
    # maxEvents["JetHT_Run2016D_03Feb2017_v1_276315_276811"] = 1
    # maxEvents["JetHT_Run2016C_03Feb2017_v1_275656_276283"] = 1
    # maxEvents["JetHT_Run2016B_03Feb2017_ver2_v2_273150_275376"] = 1
    # maxEvents["DYJetsToQQ_HT180"] = 1
    # maxEvents["ChargedHiggs_HplusTB_HplusToTB_M_500"] = 1
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = ["M_1500", "M_2000", "M_2500", "M_3000", "M_5000", "M_7000", "M_10000", "QCD"]
        Print("Adding all datasets from multiCRAB directory %s except %s" % (opts.mcrab, (",".join(myBlackList))) )
        Print("Vertex reweighting is done according to the chosen data era (%s)" % (",".join(dataEras)) )
        # process.addDatasetsFromMulticrab(opts.mcrab, blacklist=myBlackList)
        if len(myBlackList) > 0:
            regex = "|".join(myBlackList)
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    # Set splitting of phase-space (first bin is below first edge value and last bin is above last edge value)
    allSelections.CommonPlots.histogramSplitting = [
        #PSet(label="TetrajetBjetPt" , binLowEdges=[40, 60, 100, 200, 300], useAbsoluteValues=False), # pT < 40, pT=40-60, pT=60-100, pT=100-200, pT > 200
        PSet(label="TetrajetBjetEta", binLowEdges=[-1.8, -1.2, -0.4, 0.0, 0.4, 1.2, 1.8], useAbsoluteValues=False), 
        #PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 1.2, 1.8], useAbsoluteValues=True), #|eta| < 0.4,  0.4 < |eta| < 1.2, 1.2 < |eta| < 1.8, |eta| > 1.8, 
        #PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 1.2], useAbsoluteValues=True),
        #PSet(label="TetrajetBjetEta", binLowEdges=[1.2], useAbsoluteValues=True),
        #PSet(label="TetrajetBjetEta", binLowEdges=[1.3], useAbsoluteValues=True), # good but perhaps limit to 1.2
        #PSet(label="TetrajetBjetEta", binLowEdges=[0.6, 1.4], useAbsoluteValues=True), #middle bin is bad
        ]
    
    # allSelections.BJetSelection.triggerMatchingApply = True # at least 1 trg b-jet matched to offline b-jets
    # allSelections.Trigger.triggerOR = ["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"]
    # allSelections.Trigger.triggerOR = ["HLT_PFHT450_SixJet40_BTagCSV_p056"]

    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)
    

    # ================================================================================================
    # Build analysis modules
    # ================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("BJetSelection.triggerMatchingApply", [True, False]) # At least 1 trg b-jet dR-matched to offline b-jets
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutValue", [100, 20])
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["=="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutDirection", [">="])
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscr", "")
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscrWorkingPoint", "Loose")
    # builder.addVariation("FakeBMeasurement.invertedBJetsSortType", ["Random", "DescendingBDiscriminator"])
    # builder.addVariation("FakeBMeasurement.invertedBJetsDiscrMaxCutValue", [0.82, 0.80, 0.75, 0.70])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [100])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT450_SixJet40"], ["HLT_PFHT400_SixJet30"]])
    # builder.addVariation("TopologySelection.FoxWolframMomentCutValue", [0.5, 0.7])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"], ["HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056", "HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    
    # Build the builder
    builder.build(process, allSelections)
    
    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    # def createAnalyzer(dataVersion):
    # a = Analyzer("ExampleAnalysis")
    # if dataVersion.isMC():
    # a.tauPtCut = 10
    # else:
    # a.tauPtCut = 20
    # return a
    # process.addAnalyzer("test2", createAnalyzer)
    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    # process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()

    return
Esempio n. 12
0
#!/usr/bin/env python

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer

import os

process = Process(outputPrefix="generatorComparison")

# Example of adding a dataset which has its files defined in data/<dataset_name>.txt file
#process.addDatasets(["TTbar_HBWB_HToTauNu_M_160_13TeV_pythia6"])

# Example of adding datasets from a multicrab directory
import sys
if len(sys.argv) != 2:
    print "Usage: ./exampleAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)

#print sys.argv[1]

process.addDatasetsFromMulticrab(sys.argv[1])

import HiggsAnalysis.NtupleAnalysis.tools.aux as aux
PileupHistogramPath = os.path.join(aux.higgsAnalysisPath(), "NtupleAnalysis", "data", "PUWeights")

process.addAnalyzer("generatorComparison", 
    Analyzer("GeneratorComparison",
        histogramAmbientLevel = "Informative",
        tauPtCut = 41.0,
        tauEtaCut = 2.1,
        bjetEtCut = 30.0,
        bjetEtaCut = 2.4,
Esempio n. 13
0
#!/usr/bin/env python
import sys

dataEras = ["2015"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

if len(sys.argv) < 2:
    print "Usage: ./exampleAnalysis.py <path-to-multicrab-directory> <1pr> <2pr> <3pr>"
    sys.exit(0)

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import obtainAnalysisSuffix 
process = Process("SignalAnalysis"+obtainAnalysisSuffix(sys.argv))
process.addDatasetsFromMulticrab(sys.argv[1])

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections,applyAnalysisCommandLineOptions,setAngularCutsWorkingPoint
# Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
allSelections.CommonPlots.histogramSplitting = [
    #PSet(label="tauPt", binLowEdges=[60.0, 70.0, 80.0, 100.0], useAbsoluteValues=False),
  ]
#===== Selection customisations
#allSelections.TauSelection.rtau = 0.0
#allSelections.BJetSelection.numberOfBJetsCutValue = 0
#allSelections.BJetSelection.numberOfBJetsCutDirection = "=="
#setAngularCutsWorkingPoint(allSelections.AngularCutsCollinear, "Loose")
#===== End of selection customisations

applyAnalysisCommandLineOptions(sys.argv, allSelections)
Esempio n. 14
0
def addAnalyzer(era,onlineSelection):
    process = Process(outputPrefix="metLegEfficiency_"+era)
    process.addDatasetsFromMulticrab(sys.argv[1])
    ds = getDatasetsForEras(process.getDatasets(),eras[era])
    process.setDatasets(ds)
    global runmin,runmax
    runmin,runmax = process.getRuns()
    process.addAnalyzer("METLeg_"+era+"_"+onlineSelection, lambda dv: createAnalyzer(dv, era, onlineSelection))
    process.run()
Esempio n. 15
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    # maxEvents["2016"] = 1
    # maxEvents["ZZTo4Q"] = -1
    # maxEvents["ZJetsToQQ_HT600toInf"] = 1
    # maxEvents["WZ_ext1"] = 1
    # maxEvents["WZ"] = 1
    # maxEvents["WWTo4Q"] = 1
    # maxEvents["WJetsToQQ_HT_600ToInf"] = 1
    # maxEvents["TTZToQQ"] = 1
    # maxEvents["TTWJetsToQQ"] = 1
    # maxEvents["TTTT"] = 1
    # maxEvents["TT"] = 1
    # maxEvents["ST_t_channel_top_4f_inclusiveDecays"] = 1
    # maxEvents["ST_t_channel_antitop_4f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays"] = 1
    # maxEvents["ST_s_channel_4f_InclusiveDecays"] = 1
    # maxEvents["QCD_HT700to1000_ext1"] = 1
    # maxEvents["QCD_HT700to1000"] = 1
    # maxEvents["QCD_HT50to100"] = 1
    # maxEvents["QCD_HT500to700_ext1"] = 1
    # maxEvents["QCD_HT500to700"] = 1
    # maxEvents["QCD_HT300to500_ext1"] = 1
    # maxEvents["QCD_HT300to500"] = 1
    # maxEvents["QCD_HT200to300_ext1"] = 1
    # maxEvents["QCD_HT200to300"] = 1
    # maxEvents["QCD_HT2000toInf_ext1"] = 1
    # maxEvents["QCD_HT2000toInf"] = 1
    # maxEvents["QCD_HT1500to2000_ext1"] = 1
    # maxEvents["QCD_HT1500to2000"] = 1
    # maxEvents["QCD_HT100to200"] = 1
    # maxEvents["QCD_HT1000to1500_ext1"] = 1
    # maxEvents["QCD_HT1000to1500"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver3_v1_284036_284044"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver2_v1_281613_284035"] = 1
    # maxEvents["JetHT_Run2016G_03Feb2017_v1_278820_280385"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_278801_278808"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_277932_278800"] = 1
    # maxEvents["JetHT_Run2016E_03Feb2017_v1_276831_277420"] = 1
    # maxEvents["JetHT_Run2016D_03Feb2017_v1_276315_276811"] = 1
    # maxEvents["JetHT_Run2016C_03Feb2017_v1_275656_276283"] = 1
    # maxEvents["JetHT_Run2016B_03Feb2017_ver2_v2_273150_275376"] = 1
    # maxEvents["DYJetsToQQ_HT180"] = 1
    # maxEvents["ChargedHiggs_HplusTB_HplusToTB_M_500"] = 1
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" %
                (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" %
                (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        myBlackList = [
            "M_180", "M_200", "M_220", "M_250", "M_300", "M_350", "M_400",
            "M_500", "M_650", "M_800", "M_1000", "M_1500", "M_2000", "M_2500",
            "M_3000", "M_5000", "M_7000", "M_10000", "QCD"
        ]
        Verbose("Adding all datasets from multiCRAB directory %s except %s" %
                (opts.mcrab, (",".join(myBlackList))))
        Verbose(
            "Vertex reweighting is done according to the chosen data era (%s)"
            % (",".join(dataEras)))
        # process.addDatasetsFromMulticrab(opts.mcrab, blacklist=myBlackList)
        if len(myBlackList) > 0:
            regex = "|".join(myBlackList)
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    # Set splitting of phase-space (first bin is below first edge value and last bin is above last edge value)
    allSelections.CommonPlots.histogramSplitting = [
        # PSet(label="TetrajetBjetPt" , binLowEdges=[60, 100], useAbsoluteValues=False),
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.8, 1.6, 2.1], useAbsoluteValues=True), # B) not bad for -1.0 < BDT < 0.4
        ## PSet(label="TetrajetBjetPt" , binLowEdges=[120], useAbsoluteValues=False),
        ## PSet(label="TetrajetBjetEta", binLowEdges=[0.6, 1.2, 1.8, 2.1], useAbsoluteValues=True),
        ## PSet(label="TetrajetBjetPt" , binLowEdges=[100], useAbsoluteValues=False),
        ## PSet(label="TetrajetBjetEta", binLowEdges=[0.6, 0.9, 1.2, 1.5, 1.8, 2.1], useAbsoluteValues=True),
        ## PSet(label="TetrajetBjetPt" , binLowEdges=[80], useAbsoluteValues=False),
        ## PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 0.8, 1.6, 2.0], useAbsoluteValues=True),
        ### Default binning
        #PSet(label="TetrajetBjetPt" , binLowEdges=[60, 80, 160], useAbsoluteValues=False), # Alexandros (40-60, and 60-80 bins off. others v. good)
        #PSet(label="TetrajetBjetEta", binLowEdges=[1.0, 1.8], useAbsoluteValues=True), # Alexandros good!
        #PSet(label="TetrajetBjetPt" , binLowEdges=[80, 160], useAbsoluteValues=False), # Alexandros (40-60, and 60-80 bins off. others good)
        #PSet(label="TetrajetBjetEta", binLowEdges=[1.0, 1.8], useAbsoluteValues=True), # Alexandros good!
        #
        # PSet(label="TetrajetBjetPt" , binLowEdges=[80, 200], useAbsoluteValues=False), # Fotis
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.8, 1.6], useAbsoluteValues=True), # Fotis
        #
        # PSet(label="TetrajetBjetPt" , binLowEdges=[60, 80, 140, 200], useAbsoluteValues=False), #Fotis
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.8, 1.5, 2.1], useAbsoluteValues=True),  #Fotis
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 60, 80, 100, 160], useAbsoluteValues=False),
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.2, 0.4, 0.6, 0.8, 1.6, 2.0, 2.2], useAbsoluteValues=True),
        PSet(label="TetrajetBjetEta",
             binLowEdges=[0.4, 0.8, 1.6, 2.0, 2.2],
             useAbsoluteValues=True),  #AN v4
        ### Other attempts
        # PSet(label="TetrajetBjetEta", binLowEdges=[-2.2, -2.0, -1.6, -0.8, -0.4, +0.4, +0.8, +1.6, +2.0, +2.2], useAbsoluteValues=False),
        # PSet(label="TetrajetBjetPt" , binLowEdges=[100], useAbsoluteValues=False), # C)
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 1.2, 1.8, 2.1], useAbsoluteValues=True), # C)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[60, 100], useAbsoluteValues=False), # B) not bad for -1.0 < BDT < 0.4
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 1.2, 1.8, 2.0], useAbsoluteValues=True), # B) not bad for -1.0 < BDT < 0.4
        # PSet(label="TetrajetBjetPt" , binLowEdges=[120, 200], useAbsoluteValues=False),          # A) not great for -1.0 < BDT < 0.4
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 1.2, 1.8, 2.1], useAbsoluteValues=True), # A) not great for -1.0 < BDT < 0.4
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 0.8, 1.6, 1.8, 2.0, 2.2], useAbsoluteValues=True), #so-so
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 1.2, 1.8], useAbsoluteValues=True), #|eta| < 0.4,  0.4 < |eta| < 1.2, 1.2 < |eta| < 1.8, |eta| > 1.8,
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.2, 0.4, 0.8, 1.2, 1.6, 2.0, 2.2], useAbsoluteValues=True),
        # PSet(label="TetrajetBjetEta", binLowEdges=[-1.8, -1.2, -0.4, 0.0, 0.4, 1.2, 1.8], useAbsoluteValues=False),
        # PSet(label="TetrajetBjetPt" , binLowEdges=[40, 60, 100, 200, 300], useAbsoluteValues=False), # pT < 40, pT=40-60, pT=60-100, pT=100-200, pT > 200
    ]

    # allSelections.BJetSelection.triggerMatchingApply = True # at least 1 trg b-jet matched to offline b-jets
    # allSelections.Trigger.triggerOR = ["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"]
    # allSelections.Trigger.triggerOR = ["HLT_PFHT450_SixJet40_BTagCSV_p056"]

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    # ================================================================================================
    # Build analysis modules
    # ================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("BJetSelection.triggerMatchingApply", [True, False]) # At least 1 trg b-jet dR-matched to offline b-jets
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutValue", [100, 20])
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["=="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutDirection", [">="])
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscr", "")
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscrWorkingPoint", "Loose")
    # builder.addVariation("FakeBMeasurement.invertedBJetsSortType", ["Random", "DescendingBDiscriminator"])
    # builder.addVariation("FakeBMeasurement.invertedBJetsDiscrMaxCutValue", [0.82, 0.80, 0.75, 0.70])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [100])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT450_SixJet40"], ["HLT_PFHT400_SixJet30"]])
    # builder.addVariation("TopologySelection.FoxWolframMomentCutValue", [0.5, 0.7])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"], ["HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056", "HLT_PFHT450_SixJet40_BTagCSV_p056"]])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    # def createAnalyzer(dataVersion):
    # a = Analyzer("ExampleAnalysis")
    # if dataVersion.isMC():
    # a.tauPtCut = 10
    # else:
    # a.tauPtCut = 20
    # return a
    # process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    # process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt = int(tFinish) - int(tStart)
    days = divmod(dt, 86400)  # days
    hours = divmod(days[1], 3600)  # hours
    mins = divmod(hours[1], 60)  # minutes
    secs = mins[1]  # seconds
    Print(
        "Total elapsed time is %s days, %s hours, %s mins, %s secs" %
        (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 16
0
def main():

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    process = Process(prefix, postfix, maxEvents)

            
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset \"%s\" from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except \"%s\" from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = []
        if opts.analysisType == "HToTB":
            myBlackList = ["QCD_b", "ChargedHiggs", "DY", "WZ", "WW", "ZZ", "TTTT", "ST", "TTWJets", "TTZ"]

        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        regex =  "|".join(myBlackList)
        if len(myBlackList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Selection customisations
    # ================================================================================================
    if opts.analysisType == "HToTauNu":
        from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections
        # Disable rtau
        allSelections.TauSelection.prongs = 1
        allSelections.TauSelection.rtau = 0.0
    elif opts.analysisType == "HToTB":
        from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    else:
        raise Exception("Invalid analysis selection \"%s\"! Valid options are: %s" % (opts.analysisType, ", ".join(allowedAnalysis)))
    
    # Jet cut values
    allSelections.__setattr__("jetPtCutMin", 0.0)
    allSelections.__setattr__("jetPtCutMax", 99990.0)
    allSelections.__setattr__("jetEtaCutMin", -2.5)
    allSelections.__setattr__("jetEtaCutMax", 2.5)
    if 0:
        for algo in ["combinedInclusiveSecondaryVertexV2BJetTags"]:
            for wp in ["Loose", "Medium", "Tight"]:
                selections = allSelections.clone()
                selections.BJetSelection.bjetDiscr = algo
                selections.BJetSelection.bjetDiscrWorkingPoint = wp
                suffix = "_%s_%s"%(algo,wp)
                print "Added analyzer for algo/wp: %s"%suffix
                process.addAnalyzer("BTagEfficiency"+suffix, Analyzer("BTagEfficiencyAnalysis", config=selections, silent=False))

    # Set the analysis type
    allSelections.__setattr__("AnalysisType", opts.analysisType)

    # Overwrite verbosity
    allSelections.verbose = opts.verbose

    # Overwrite histo ambient level (Options: Systematics, Vital, Informative, Debug)
    allSelections.histogramAmbientLevel = opts.histoLevel
    
    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              #### Options ####
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics)

    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    builder.addVariation("BJetSelection.bjetDiscr", ["pfCombinedInclusiveSecondaryVertexV2BJetTags"])
    builder.addVariation("BJetSelection.bjetDiscrWorkingPoint", ["Loose", "Medium", "Tight"])

    # ================================================================================================
    # Build the builder
    # ================================================================================================
    builder.build(process, allSelections)

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    Print("Running process", True)
    process.run()
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    completeList = GetDatasetCompleteList()
    whiteList    = GetDatasetWhitelist(opts)
    blackList    = GetDatasetBlackList(completeList, whiteList)
    maxEvents = {}
    for d in whiteList:
        #maxEvents[d] = 100
        maxEvents[d] = -1
    process = Process(prefix, postfix, maxEvents)
                
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = []
        myBlackList.extend(blackList)
        Verbose("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Verbose("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        regex =  "|".join(myBlackList)
        if len(whiteList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks="|".join(whiteList))
        elif len(myBlackList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)



    # ================================================================================================
    # Overwrite Default Settings  
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.jetTriggers import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    #==========================
    #  Systematics selections
    #==========================

    # MET
    allSelections.METSelection.METCutValue = 50.0
    
    # Muon
    allSelections.MuonSelection.muonPtCut = 30
    
    # Jets
    allSelections.JetSelection.numberOfJetsCutValue = 4
    allSelections.JetSelection.jetPtCuts = [40.0, 40.0, 40.0, 30.0]
    
    # Triggers 
    allSelections.Trigger.triggerOR = ["HLT_Mu50"]
    # Bjets
    allSelections.BJetSelection.jetPtCuts = [40.0, 30.0]
    allSelections.BJetSelection.numberOfBJetsCutValue = 2

    
    # allSelections.BjetSelection.triggerMatchingApply = True
    # allSelections.TopSelection.ChiSqrCutValue = 100.0
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections


    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    
    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics,
                              analysisType="HToTB")

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt      = int(tFinish) - int(tStart)
    days    = divmod(dt,86400)      # days
    hours   = divmod(days[1],3600)  # hours
    mins    = divmod(hours[1],60)   # minutes
    secs    = mins[1]               # seconds
    Print("Total elapsed time is %s days, %s hours, %s mins, %s secs" % (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 18
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)     
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass


    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    # maxEvents["2016"] = 1
    # maxEvents["ZZTo4Q"] = -1
    # maxEvents["ZJetsToQQ_HT600toInf"] = 1
    # maxEvents["WZ_ext1"] = 1
    # maxEvents["WZ"] = 1
    # maxEvents["WWTo4Q"] = 1
    # maxEvents["WJetsToQQ_HT_600ToInf"] = 1
    # maxEvents["TTZToQQ"] = 1
    # maxEvents["TTWJetsToQQ"] = 1
    # maxEvents["TTTT"] = 1
    # maxEvents["TT"] = 1
    # maxEvents["ST_t_channel_top_4f_inclusiveDecays"] = 1
    # maxEvents["ST_t_channel_antitop_4f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays"] = 1
    # maxEvents["ST_s_channel_4f_InclusiveDecays"] = 1
    # maxEvents["QCD_HT700to1000_ext1"] = 1
    # maxEvents["QCD_HT700to1000"] = 1
    # maxEvents["QCD_HT50to100"] = 1
    # maxEvents["QCD_HT500to700_ext1"] = 1
    # maxEvents["QCD_HT500to700"] = 1
    # maxEvents["QCD_HT300to500_ext1"] = 1
    # maxEvents["QCD_HT300to500"] = 1
    # maxEvents["QCD_HT200to300_ext1"] = 1
    # maxEvents["QCD_HT200to300"] = 1
    # maxEvents["QCD_HT2000toInf_ext1"] = 1
    # maxEvents["QCD_HT2000toInf"] = 1
    # maxEvents["QCD_HT1500to2000_ext1"] = 1
    # maxEvents["QCD_HT1500to2000"] = 1
    # maxEvents["QCD_HT100to200"] = 1
    # maxEvents["QCD_HT1000to1500_ext1"] = 1
    # maxEvents["QCD_HT1000to1500"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver3_v1_284036_284044"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver2_v1_281613_284035"] = 1
    # maxEvents["JetHT_Run2016G_03Feb2017_v1_278820_280385"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_278801_278808"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_277932_278800"] = 1
    # maxEvents["JetHT_Run2016E_03Feb2017_v1_276831_277420"] = 1
    # maxEvents["JetHT_Run2016D_03Feb2017_v1_276315_276811"] = 1
    # maxEvents["JetHT_Run2016C_03Feb2017_v1_275656_276283"] = 1
    # maxEvents["JetHT_Run2016B_03Feb2017_ver2_v2_273150_275376"] = 1
    # maxEvents["DYJetsToQQ_HT180"] = 1
    # maxEvents["ChargedHiggs_HplusTB_HplusToTB_M_500"] = 1
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = ["M_180", "M_200" , "M_220" , "M_250" , "M_300" , "M_350" , "M_400" , "M_500" , "M_650",
                       "M_800", "M_1000", "M_1500", "M_2000", "M_2500", "M_3000", "M_5000", "M_7000", "M_10000", "QCD_b"]
        Verbose("Adding all datasets from multiCRAB directory %s except %s" % (opts.mcrab, (",".join(myBlackList))) )
        Verbose("Vertex reweighting is done according to the chosen data era (%s)" % (",".join(dataEras)) )
        # process.addDatasetsFromMulticrab(opts.mcrab, blacklist=myBlackList)
        if len(myBlackList) > 0:
            regex = "|".join(myBlackList)
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    # Set splitting of phase-space (first bin is below first edge value and last bin is above last edge value)
    allSelections.CommonPlots.histogramSplitting = [                
        PSet(label="TetrajetBjetPt" , binLowEdges=[60, 90, 160, 300], useAbsoluteValues=False), # Final
        PSet(label="TetrajetBjetEta", binLowEdges=[0.8, 1.4, 2.0], useAbsoluteValues=True), # Final
        # 
        # PSet(label="TetrajsetBjetPt", binLowEdges=[60, 100, 150], useAbsoluteValues=False),
        # PSet(label="TetrajsetBjetPt", binLowEdges=[60, 150], useAbsoluteValues=False),
        # PSet(label="TetrajsetBjetPt", binLowEdges=[55, 110], useAbsoluteValues=False),
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.8, 1.6], useAbsoluteValues=True),
        # PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 0.8, 1.6, 2.0, 2.2], useAbsoluteValues=True),  #AN v4
        ]

    # Overwrite values
    # allSelections.TopSelectionBDT.CSV_bDiscCutDirection  = ">="
    allSelections.TopSelectionBDT.CSV_bDiscCutValue = 0.54 # allow CSVv2-L for inverted top
    
    # Testing
    if 0:
        msg = "WARNING! This is a simple testing of the FakeB measurement with only 1 CSVv2-M. Disable once done!"
        Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(), True)
        allSelections.FakeBMeasurement.baselineBJetsCutValue     = 0 #1
        allSelections.FakeBMeasurement.baselineBJetsCutDirection = "=="


    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)
    

    # ================================================================================================
    # Build analysis modules
    # ================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("BJetSelection.triggerMatchingApply", [True, False]) # At least 1 trg b-jet dR-matched to offline b-jets
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutValue", [100, 20])
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["=="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutDirection", [">="])
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscr", "")
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscrWorkingPoint", "Loose")
    # builder.addVariation("FakeBMeasurement.invertedBJetsSortType", ["Random", "DescendingBDiscriminator"])
    # builder.addVariation("FakeBMeasurement.invertedBJetsDiscrMaxCutValue", [0.82, 0.80, 0.75, 0.70])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [100])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT450_SixJet40"], ["HLT_PFHT400_SixJet30"]])
    # builder.addVariation("TopologySelection.FoxWolframMomentCutValue", [0.5, 0.7])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"], ["HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056", "HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    
    # Build the builder
    builder.build(process, allSelections)
    
    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    # def createAnalyzer(dataVersion):
    # a = Analyzer("ExampleAnalysis")
    # if dataVersion.isMC():
    # a.tauPtCut = 10
    # else:
    # a.tauPtCut = 20
    # return a
    # process.addAnalyzer("test2", createAnalyzer)
    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    # process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt      = int(tFinish) - int(tStart)
    days    = divmod(dt,86400)      # days
    hours   = divmod(days[1],3600)  # hours
    mins    = divmod(hours[1],60)   # minutes
    secs    = mins[1]               # seconds
    Print("Total elapsed time is %s days, %s hours, %s mins, %s secs" % (days[0], hours[0], mins[0], secs), True)
    return
#!/usr/bin/env python
import sys

dataEras = ["2016"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer

process = Process("BTagEfficiencyAnalysis")


# Example of adding a dataset which has its files defined in data/<dataset_name>.txt file
#process.addDatasets(["TTbar_HBWB_HToTauNu_M_160_13TeV_pythia6"])

# Example of adding datasets from a multicrab directory
if len(sys.argv) < 2:
    print "Usage: ./btagEfficiencyAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)
process.addDatasetsFromMulticrab(sys.argv[1], blacklist=["ChargedHiggs"])

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections
# Disable rtau
allSelections.TauSelection.prongs = 1
allSelections.TauSelection.rtau = 0.0
allSelections.__setattr__("jetPtCutMin", 0.0)
allSelections.__setattr__("jetPtCutMax", 99990.0)
allSelections.__setattr__("jetEtaCutMin", -2.5)
allSelections.__setattr__("jetEtaCutMax", 2.5)
#!/usr/bin/env python

dataEras = ["2015"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer

process = Process("BTagEfficiencyAnalysis")

# Example of adding a dataset which has its files defined in data/<dataset_name>.txt file
#process.addDatasets(["TTbar_HBWB_HToTauNu_M_160_13TeV_pythia6"])

# Example of adding datasets from a multicrab directory
import sys
if len(sys.argv) < 2:
    print "Usage: ./btagEfficiencyAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)
process.addDatasetsFromMulticrab(sys.argv[1])

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections
# Disable rtau
allSelections.TauSelection.rtau = 0.0
allSelections.__setattr__("jetPtCutMin", 0.0)
allSelections.__setattr__("jetPtCutMax", 99990.0)
allSelections.__setattr__("jetEtaCutMin", -2.5)
allSelections.__setattr__("jetEtaCutMax", 2.5)

#for algo in ["combinedInclusiveSecondaryVertexV2BJetTags"]:
#    for wp in ["Loose", "Medium", "Tight"]:
Esempio n. 21
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    process = Process(prefix, postfix, maxEvents)
                
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Verbose("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = ["QCD_b"
                       "ChargedHiggs_HplusTB_HplusToTB_M_180_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_200_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_220_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_250_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_300_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_350_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_400_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_500_ext1", 
                       #"ChargedHiggs_HplusTB_HplusToTB_M_650",  #10M events!
                       "ChargedHiggs_HplusTB_HplusToTB_M_800_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_1000_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_2000_ext1"
                       "ChargedHiggs_HplusTB_HplusToTB_M_2500_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_3000_ext1", 
                       # "ChargedHiggs_HplusTB_HplusToTB_M_1000",
                       # "ChargedHiggs_HplusTB_HplusToTB_M_1500",   # Speeed things up
                       # "ChargedHiggs_HplusTB_HplusToTB_M_2000",   # Speeed things up
                       # "ChargedHiggs_HplusTB_HplusToTB_M_2500",   # Speeed things up
                       # "ChargedHiggs_HplusTB_HplusToTB_M_3000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_5000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_7000",   # Speeed things up  
                       "ChargedHiggs_HplusTB_HplusToTB_M_10000",  # Speeed things up
                       ]
        #if opts.doSystematics:
        #    myBlackList.append("QCD")

        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        regex =  "|".join(myBlackList)
        if len(myBlackList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)



    # ================================================================================================
    # Overwrite Default Settings  
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel
    # allSelections.BjetSelection.triggerMatchingApply = True

    #===============
    # Trigger
    #===============
    allSelections.Trigger.triggerOR = ["HLT_PFHT900"]

    #===============
    # Jet Selection
    #===============
    allSelections.JetSelection.jetPtCuts                = [40, 40, 40, 40]
    allSelections.JetSelection.numberOfJetsCutValue     = 4
    allSelections.JetSelection.numberOfJetsCutDirection = ">="
    allSelections.JetSelection.HTCutValue               = 1000.0
    allSelections.JetSelection.HTCutDirection           = ">="


    #===============
    # Bjet Selection 
    #===============
    allSelections.BJetSelection.jetPtCuts                 = [40.0]
    allSelections.BJetSelection.numberOfBJetsCutValue     = 1
    allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    #===============
    # MET Selection 
    #===============    
    allSelections.METSelection.METCutValue                = -1000.0
    allSelections.METSelection.METCutDirection            = ">"

    # Study MisID vs BDT Cut
    #allSelections.TopSelectionBDT.MVACutValue = 0.40
    
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections


    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    
    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose)

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Verbose("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt      = int(tFinish) - int(tStart)
    days    = divmod(dt,86400)      # days
    hours   = divmod(days[1],3600)  # hours
    mins    = divmod(hours[1],60)   # minutes
    secs    = mins[1]               # seconds
    Print("Total elapsed time is %s days, %s hours, %s mins, %s secs" % (days[0], hours[0], mins[0], secs), True)
    return
#!/usr/bin/env python
import sys

dataEras = ["2016"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

if len(sys.argv) < 2:
    print "Usage: ./QCDMeasurementAnalysis.py <path-to-multicrab-directory> <1pr> <2pr> <3pr>"
    sys.exit(0)

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import obtainAnalysisSuffix
process = Process("QCDMeasurement" + obtainAnalysisSuffix(sys.argv))
process.addDatasetsFromMulticrab(sys.argv[1], blacklist=["ChargedHiggs"])

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections, applyAnalysisCommandLineOptions, setAngularCutsWorkingPoint
# Enable genuine tau histograms for common plots (needed for calculating N_QCD)
allSelections.CommonPlots.enableGenuineTauHistograms = True
# Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
allSelections.CommonPlots.histogramSplitting = [
    PSet(label="tauPt",
         binLowEdges=[60.0, 80.0, 100.0],
         useAbsoluteValues=False),
]
#===== Selection customisations
allSelections.TauSelection.prongs = 1
allSelections.TauSelection.tauPtCut = 50.0
allSelections.METSelection.METCutValue = 90.0
allSelections.AngularCutsBackToBack.cutValueJet1 = 40.0
Esempio n. 23
0
def addAnalyzer(era):
    process = Process(outputPrefix="tauLegEfficiency_"+era)
#    process.setDatasets([])
    process.addDatasetsFromMulticrab(sys.argv[1])
    ds = getDatasetsForEras(process.getDatasets(),eras[era])
    process.setDatasets(ds)
    global runmin,runmax
    runmin,runmax = process.getRuns()
    process.addAnalyzer("TauLeg_"+era, lambda dv: createAnalyzer(dv, era))
#    process.addAnalyzer("TauLeg_"+era, createAnalyzer(dv, era))
    process.run()
#!/usr/bin/env python
import sys

dataEras = ["2016"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer

process = Process("BTagEfficiencyAnalysis")

# Example of adding a dataset which has its files defined in data/<dataset_name>.txt file
#process.addDatasets(["TTbar_HBWB_HToTauNu_M_160_13TeV_pythia6"])

# Example of adding datasets from a multicrab directory
if len(sys.argv) < 2:
    print "Usage: ./btagEfficiencyAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)
process.addDatasetsFromMulticrab(sys.argv[1], blacklist=["ChargedHiggs"])

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections
# Disable rtau
allSelections.AnalysisType = "HToTauNu"
allSelections.TauSelection.prongs = 1
allSelections.TauSelection.rtau = 0.0
allSelections.__setattr__("jetPtCutMin", 0.0)
allSelections.__setattr__("jetPtCutMax", 99990.0)
allSelections.__setattr__("jetEtaCutMin", -2.5)
allSelections.__setattr__("jetEtaCutMax", 2.5)
def addAnalyzer(era,onlineSelection):
    process = Process(outputPrefix="metLegEfficiency_"+era)
    process.addDatasetsFromMulticrab(sys.argv[1])
    ds = getDatasetsForEras(process.getDatasets(),eras[era])
    process.setDatasets(ds)
    global runmin,runmax
    runmin,runmax = process.getRuns()
    process.addAnalyzer("METLeg_"+era+"_"+onlineSelection, lambda dv: createAnalyzer(dv, era, onlineSelection))
    process.run()
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    completeList = GetDatasetCompleteList()
    whiteList    = GetDatasetWhitelist(opts)
    blackList    = GetDatasetBlackList(completeList, whiteList)
    maxEvents = {}
    for d in whiteList:
        maxEvents[d] = -1
        #maxEvents[d] = 100 #for testing
        #if  d == "ChargedHiggs_HplusTB_HplusToTB_M_650":
        #    maxEvents[d] = 4000000
    process = Process(prefix, postfix, maxEvents)
                
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Verbose("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = [
            "QCD_b"
            "ChargedHiggs_HplusTB_HplusToTB_M_180",
            "ChargedHiggs_HplusTB_HplusToTB_M_200",
            "ChargedHiggs_HplusTB_HplusToTB_M_220",
            "ChargedHiggs_HplusTB_HplusToTB_M_250",
            "ChargedHiggs_HplusTB_HplusToTB_M_300",
            "ChargedHiggs_HplusTB_HplusToTB_M_350",
            "ChargedHiggs_HplusTB_HplusToTB_M_400",
            "ChargedHiggs_HplusTB_HplusToTB_M_500",
            "ChargedHiggs_HplusTB_HplusToTB_M_650",
            "ChargedHiggs_HplusTB_HplusToTB_M_800",
            "ChargedHiggs_HplusTB_HplusToTB_M_1000",
            "ChargedHiggs_HplusTB_HplusToTB_M_1500",
            "ChargedHiggs_HplusTB_HplusToTB_M_2000",
            "ChargedHiggs_HplusTB_HplusToTB_M_2500",
            "ChargedHiggs_HplusTB_HplusToTB_M_3000",
            "ChargedHiggs_HplusTB_HplusToTB_M_5000",
            "ChargedHiggs_HplusTB_HplusToTB_M_7000",
            "ChargedHiggs_HplusTB_HplusToTB_M_10000",
            # "ChargedHiggs_HplusTB_HplusToTB_M_180_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_200_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_220_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_250_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_300_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_350_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_400_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_500_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_800_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_1000_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_1500_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_2000_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_2500_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_3000_ext1",
            ]
        if opts.doSystematics:
            whiteList = GetDatasetWhitelist(opts)

        # Extend the blacklist with datasets not in the group
        myBlackList.extend(blackList)

        Verbose("Adding the following datasets from multiCRAB directory %s:\n\t%s" % (opts.mcrab, "\n\t".join(whiteList) ))
        Verbose("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        if len(whiteList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks="|".join(whiteList))
        elif len(myBlackList)>0:
        #if len(myBlackList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks="|".join(myBlackList))
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)


        # ***************************************
        # Keep ONLY datasets in whitelist
        # ***************************************
        Verbose("Removing datasets NOT included in whitelist:")    
        removeList = []
        for i, d in enumerate(process.getDatasets()):
            if d.getName() not in whiteList:
                Verbose("Dataset to be removed: %s" % (d.getName()))
                removeList.append(d) 

        for d in removeList:
            process._datasets.remove(d)
        

    # ================================================================================================
    # Overwrite Default Settings  
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel
    # allSelections.BjetSelection.triggerMatchingApply = True
    # allSelections.TopSelection.ChiSqrCutValue = 100.0
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections


    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    
    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose,
                              systVarsList=opts.systVarsList)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Verbose("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt      = int(tFinish) - int(tStart)
    days    = divmod(dt,86400)      # days
    hours   = divmod(days[1],3600)  # hours
    mins    = divmod(hours[1],60)   # minutes
    secs    = mins[1]               # seconds
    Print("Total elapsed time is %s days, %s hours, %s mins, %s secs" % (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 27
0
def main():

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" %
              (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" %
              (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        myBlackList = ["QCD_b"]
        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        regex = "|".join(myBlackList)
        if len(myBlackList) > 0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel
    # allSelections.BjetSelection.triggerMatchingApply = True
    # allSelections.TopSelection.ChiSqrCutValue = 100.0
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process")
        process.run()
Esempio n. 28
0
#!/usr/bin/env python
import sys

dataEras = ["2016"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

if len(sys.argv) < 2:
    print "Usage: ./exampleAnalysis.py <path-to-multicrab-directory> <1pr> <2pr> <3pr>"
    sys.exit(0)

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import obtainAnalysisSuffix
process = Process("SignalAnalysis" + obtainAnalysisSuffix(sys.argv))
blacklist = []
#blacklist = ["ChargedHiggs_TTToHplusBWB"]
#blacklist = ["ChargedHiggs_HplusTB"]
whitelist = []
#whitelist = ["Tau_Run2016G_","TT"]
process.addDatasetsFromMulticrab(sys.argv[1],
                                 blacklist=blacklist,
                                 whitelist=whitelist)

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections, applyAnalysisCommandLineOptions, setAngularCutsWorkingPoint
# Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
allSelections.CommonPlots.histogramSplitting = [
    #PSet(label="tauPt", binLowEdges=[60.0, 70.0, 80.0, 100.0], useAbsoluteValues=False),
]
#===== Selection customisations
allSelections.TauSelection.prongs = 1
Esempio n. 29
0
def main():

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    process = Process(prefix, postfix, maxEvents)
                
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        #myBlackList = ["QCD_b"]
        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        regex =  "|".join(myBlackList)
        if len(myBlackList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)



    # ================================================================================================
    # Overwrite Default Settings  
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel
    # allSelections.BjetSelection.triggerMatchingApply = True
    # allSelections.TopSelection.ChiSqrCutValue = 100.0
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="
    #allSelections.TopSelectionBDT.WeightFile             = "TopRecoTree_180523_DeltaR0p3_DeltaPtOverPt0p32_TopPtReweighting_BDTG.weights.xml"
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections


    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    
    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process")
        process.run()
Esempio n. 30
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" %
                (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
        myBlackList = [
            "ChargedHiggs_HplusTB_HplusToTB_M_2000_ext1"
            "ChargedHiggs_HplusTB_HplusToTB_M_2500_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_3000_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_1500",  # Speeed things up
            "ChargedHiggs_HplusTB_HplusToTB_M_2000",  # Speeed things up
            "ChargedHiggs_HplusTB_HplusToTB_M_2500",  # Speeed things up
            "ChargedHiggs_HplusTB_HplusToTB_M_3000",  # Speeed things up
            "ChargedHiggs_HplusTB_HplusToTB_M_5000",  # Speeed things up
            "ChargedHiggs_HplusTB_HplusToTB_M_7000",  # Speeed things up  
            "ChargedHiggs_HplusTB_HplusToTB_M_10000",  # Speeed things up
        ]

    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" %
                (opts.excludeTasks, opts.mcrab))
        Verbose(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        myBlackList = [
            "QCD_b"
            "ChargedHiggs_HplusTB_HplusToTB_M_180_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_200_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_220_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_250_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_300_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_350_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_400_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_500_ext1",
            #"ChargedHiggs_HplusTB_HplusToTB_M_650",  #10M events!
            "ChargedHiggs_HplusTB_HplusToTB_M_800_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_1000_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_2000_ext1"
            "ChargedHiggs_HplusTB_HplusToTB_M_2500_ext1",
            "ChargedHiggs_HplusTB_HplusToTB_M_3000_ext1",
            # "ChargedHiggs_HplusTB_HplusToTB_M_1000",
            # "ChargedHiggs_HplusTB_HplusToTB_M_1500",   # Speeed things up
            # "ChargedHiggs_HplusTB_HplusToTB_M_2000",   # Speeed things up
            # "ChargedHiggs_HplusTB_HplusToTB_M_2500",   # Speeed things up
            # "ChargedHiggs_HplusTB_HplusToTB_M_3000",   # Speeed things up
            "ChargedHiggs_HplusTB_HplusToTB_M_5000",  # Speeed things up
            "ChargedHiggs_HplusTB_HplusToTB_M_7000",  # Speeed things up  
            "ChargedHiggs_HplusTB_HplusToTB_M_10000",  # Speeed things up
        ]

        #if opts.doSystematics:
        #    myBlackList.append("QCD")

        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        regex = "|".join(myBlackList)
        if len(myBlackList) > 0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    allSelections.TopSelectionBDT.TopMVACutValue = 0.40
    allSelections.TopSelectionBDT.TopMVACutDirection = ">="
    allSelections.TopSelectionBDT.WeightFile = "BDTG_DeltaR0p3_DeltaPtOverPt0p32_BJetPt40_14July2018.weight.xml"
    #BDTG_DeltaR0p4_BJetPt40_25Sept2018.weights.xml
    #BDTG_DeltaR0p3_DeltaPtOverPt0p50_BJetPt40_18Sept2018.weights.xml
    #BDTG_DeltaR0p3_BJetPt40_17July2018.weights.xml
    #BDTG_DeltaR0p3_DeltaPtOverPt0p32_BJetPt40_14July2018.weight.xml
    allSelections.DeltaR = 0.3
    allSelections.DeltaPtOverPt = 0.32
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Verbose("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt = int(tFinish) - int(tStart)
    days = divmod(dt, 86400)  # days
    hours = divmod(days[1], 3600)  # hours
    mins = divmod(hours[1], 60)  # minutes
    secs = mins[1]  # seconds
    Print(
        "Total elapsed time is %s days, %s hours, %s mins, %s secs" %
        (days[0], hours[0], mins[0], secs), True)
    return
Esempio n. 31
0
def main():

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    process = Process(prefix, postfix, opts.nEvts)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" %
              (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" %
              (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Selection customisations
    # ================================================================================================
    if opts.analysisType == "HToTauNu":
        from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections
        # Disable rtau
        allSelections.TauSelection.prongs = 1
        allSelections.TauSelection.rtau = 0.0
    elif opts.analysisType == "HToTB":
        from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    else:
        raise Exception(
            "Invalid analysis selection \"%s\"! Valid options are: %s" %
            (opts.analysisType, ", ".join(allowedAnalysis)))

    # Jet cut values
    allSelections.__setattr__("jetPtCutMin", 0.0)
    allSelections.__setattr__("jetPtCutMax", 99990.0)
    allSelections.__setattr__("jetEtaCutMin", -2.5)
    allSelections.__setattr__("jetEtaCutMax", 2.5)
    # for algo in ["combinedInclusiveSecondaryVertexV2BJetTags"]:
    # for wp in ["Loose", "Medium", "Tight"]:
    #    selections = allSelections.clone()
    #    selections.BJetSelection.bjetDiscr = algo
    #    selections.BJetSelection.bjetDiscrWorkingPoint = wp
    #    suffix = "_%s_%s"%(algo,wp)
    #    print "Added analyzer for algo/wp: %s"%suffix
    #    process.addAnalyzer("BTagEfficiency"+suffix, Analyzer("BTagEfficiencyAnalysis", config=selections, silent=False))

    # Set the analysis type
    allSelections.__setattr__("AnalysisType", opts.analysisType)

    # Overwrite verbosity
    allSelections.verbose = opts.verbose

    # Overwrite histo ambient level (Options: Systematics, Vital, Informative, Debug)
    allSelections.histogramAmbientLevel = opts.histoLevel

    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(
        prefix,
        dataEras,
        searchModes,
        #### Options ####
        usePUreweighting=opts.usePUreweighting,
        useTopPtReweighting=opts.useTopPtReweighting,
        doSystematicVariations=opts.doSystematics)

    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    builder.addVariation("BJetSelection.bjetDiscr",
                         ["pfCombinedInclusiveSecondaryVertexV2BJetTags"])
    builder.addVariation("BJetSelection.bjetDiscrWorkingPoint",
                         ["Loose", "Medium", "Tight"])

    # ================================================================================================
    # Build the builder
    # ================================================================================================
    builder.build(process, allSelections)

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    Print("Running process", True)
    process.run()
#!/usr/bin/env python

dataEras = ["2015"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer
process = Process()

import sys
if len(sys.argv) < 2:
    print "Usage: ./QCDMeasurementAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)
process.addDatasetsFromMulticrab(sys.argv[1])

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections
# Enable genuine tau histograms for common plots (needed for calculating N_QCD)
allSelections.CommonPlots.enableGenuineTauHistograms = True
# Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
allSelections.CommonPlots.histogramSplitting = [
    PSet(label="tauPt",
         binLowEdges=[60.0, 70.0, 80.0, 100.0, 120.0],
         useAbsoluteValues=False),
]

# Build analysis modules
from HiggsAnalysis.NtupleAnalysis.AnalysisBuilder import AnalysisBuilder
builder = AnalysisBuilder(
    "QCDMeasurement",
    dataEras,
Esempio n. 33
0
#!/usr/bin/env python

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer

process = Process()

# Example of adding a dataset which has its files defined in data/<dataset_name>.txt file
#process.addDatasets(["TTbar_HBWB_HToTauNu_M_160_13TeV_pythia6"])

# Example of adding datasets from a multicrab directory
import sys
if len(sys.argv) != 2:
    print "Usage: ./metAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)
process.addDatasetsFromMulticrab(sys.argv[1])

# Example of adding an analyzer
process.addAnalyzer("test", Analyzer("MetAnalysis", tauPtCut=10))


# Example of adding an analyzer whose configuration depends on dataVersion
def createAnalyzer(dataVersion):
    a = Analyzer("MetAnalysis")
    if dataVersion.isMC():
        a.tauPtCut = 10
    else:
        a.tauPtCut = 20
    return a


process.addAnalyzer("test2", createAnalyzer)
Esempio n. 34
0
def main():

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    # maxEvents["2016"] = 1
    # maxEvents["ZZTo4Q"] = -1
    # maxEvents["ZJetsToQQ_HT600toInf"] = 1
    # maxEvents["WZ_ext1"] = 1
    # maxEvents["WZ"] = 1
    # maxEvents["WWTo4Q"] = 1
    # maxEvents["WJetsToQQ_HT_600ToInf"] = 1
    # maxEvents["TTZToQQ"] = 1
    # maxEvents["TTWJetsToQQ"] = 1
    # maxEvents["TTTT"] = 1
    # maxEvents["TT"] = 1
    # maxEvents["ST_t_channel_top_4f_inclusiveDecays"] = 1
    # maxEvents["ST_t_channel_antitop_4f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_top_5f_inclusiveDecays"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays_ext1"] = 1
    # maxEvents["ST_tW_antitop_5f_inclusiveDecays"] = 1
    # maxEvents["ST_s_channel_4f_InclusiveDecays"] = 1
    # maxEvents["QCD_HT700to1000_ext1"] = 1
    # maxEvents["QCD_HT700to1000"] = 1
    # maxEvents["QCD_HT50to100"] = 1
    # maxEvents["QCD_HT500to700_ext1"] = 1
    # maxEvents["QCD_HT500to700"] = 1
    # maxEvents["QCD_HT300to500_ext1"] = 1
    # maxEvents["QCD_HT300to500"] = 1
    # maxEvents["QCD_HT200to300_ext1"] = 1
    # maxEvents["QCD_HT200to300"] = 1
    # maxEvents["QCD_HT2000toInf_ext1"] = 1
    # maxEvents["QCD_HT2000toInf"] = 1
    # maxEvents["QCD_HT1500to2000_ext1"] = 1
    # maxEvents["QCD_HT1500to2000"] = 1
    # maxEvents["QCD_HT100to200"] = 1
    # maxEvents["QCD_HT1000to1500_ext1"] = 1
    # maxEvents["QCD_HT1000to1500"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver3_v1_284036_284044"] = 1
    # maxEvents["JetHT_Run2016H_03Feb2017_ver2_v1_281613_284035"] = 1
    # maxEvents["JetHT_Run2016G_03Feb2017_v1_278820_280385"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_278801_278808"] = 1
    # maxEvents["JetHT_Run2016F_03Feb2017_v1_277932_278800"] = 1
    # maxEvents["JetHT_Run2016E_03Feb2017_v1_276831_277420"] = 1
    # maxEvents["JetHT_Run2016D_03Feb2017_v1_276315_276811"] = 1
    # maxEvents["JetHT_Run2016C_03Feb2017_v1_275656_276283"] = 1
    # maxEvents["JetHT_Run2016B_03Feb2017_ver2_v2_273150_275376"] = 1
    # maxEvents["DYJetsToQQ_HT180"] = 1
    # maxEvents["ChargedHiggs_HplusTB_HplusToTB_M_500"] = 1
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" %
              (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" %
              (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        myBlackList = [
            "M_180", "M_2500", "M_3000", "M_5000", "M_7000", "M_10000", "QCD"
        ]
        Print("Adding all datasets from multiCRAB directory %s except %s" %
              (opts.mcrab, (",".join(myBlackList))))
        Print(
            "Vertex reweighting is done according to the chosen data era (%s)"
            % (",".join(dataEras)))
        # process.addDatasetsFromMulticrab(opts.mcrab, blacklist=myBlackList)
        if len(myBlackList) > 0:
            regex = "|".join(myBlackList)
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    # Set splitting of phase-space (first bin is below first edge value and last bin is above last edge value)
    allSelections.CommonPlots.histogramSplitting = [
        PSet(label="TetrajetBjetEta",
             binLowEdges=[0.4, 1.2, 1.8],
             useAbsoluteValues=True),
        #PSet(label="TetrajetBjetEta", binLowEdges=[0.4, 1.2], useAbsoluteValues=True),
        #PSet(label="TetrajetBjetEta", binLowEdges=[1.2], useAbsoluteValues=True),
        #PSet(label="TetrajetBjetEta", binLowEdges=[1.3], useAbsoluteValues=True), # good but perhaps limit to 1.2
        #PSet(label="TetrajetBjetEta", binLowEdges=[0.6, 1.4], useAbsoluteValues=True), #middle bin is bad
    ]

    # allSelections.BJetSelection.triggerMatchingApply = True # at least 1 trg b-jet matched to offline b-jets
    # allSelections.Trigger.triggerOR = ["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"]
    # allSelections.Trigger.triggerOR = ["HLT_PFHT450_SixJet40_BTagCSV_p056"]

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    # ================================================================================================
    # Build analysis modules
    # ================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("BJetSelection.triggerMatchingApply", [True, False]) # At least 1 trg b-jet dR-matched to offline b-jets
    # builder.addVariation("TestQGLR.prelimTopFitChiSqrCutValue", [100, 20])
    # builder.addVariation("TestQGLR.prelimTopFitChiSqrCutDirection", ["<=", "==", ">="])
    # builder.addVariation("TestQGLR.numberOfBJetsCutValue", [0, 1])
    # builder.addVariation("TestQGLR.numberOfBJetsCutDirection", ["=="])
    # builder.addVariation("TestQGLR.numberOfBJetsCutDirection", ["<=", "==", ">="])
    # builder.addVariation("TestQGLR.numberOfInvertedBJetsCutValue", [0, 1])
    # builder.addVariation("TestQGLR.numberOfInvertedBJetsCutDirection", [">="])
    # builder.addVariation("TestQGLR.invertedBJetDiscr", "")
    # builder.addVariation("TestQGLR.invertedBJetDiscrWorkingPoint", "Loose")
    # builder.addVariation("TestQGLR.invertedBJetsSortType", ["Random", "DescendingBDiscriminator"])
    # builder.addVariation("TestQGLR.invertedBJetsDiscrMaxCutValue", [0.82, 0.80, 0.75, 0.70])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [100])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT450_SixJet40"], ["HLT_PFHT400_SixJet30"]])
    # builder.addVariation("TopologySelection.FoxWolframMomentCutValue", [0.5, 0.7])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"], ["HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056", "HLT_PFHT450_SixJet40_BTagCSV_p056"]])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    # def createAnalyzer(dataVersion):
    # a = Analyzer("ExampleAnalysis")
    # if dataVersion.isMC():
    # a.tauPtCut = 10
    # else:
    # a.tauPtCut = 20
    # return a
    # process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    # process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()

    return
Esempio n. 35
0
def main():

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    #from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import obtainAnalysisSuffix
    #process = Process("QCDMeasurement"+obtainAnalysisSuffix(sys.argv))
    process = Process(prefix, postfix, opts.nEvts)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" %
              (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" %
              (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        #myBlackList = [] #QCD_bEnriched"] #["ChargedHiggs", "QCD-b"]
        myBlackList = [
            "M_800", "M_400", "M_350", "M_3000", "M_300", "M_250", "M_220",
            "M_2000", "M_200", "M_180", "M_1000", "QCD_b"
        ]
        Print("Adding all datasets from multiCRAB directory %s except %s" %
              (opts.mcrab, (",".join(myBlackList))))
        Print(
            "Vertex reweighting is done according to the chosen data era (%s)"
            % (",".join(dataEras)))
        # process.addDatasetsFromMulticrab(opts.mcrab, blacklist=myBlackList)
        if len(myBlackList) > 0:
            regex = "|".join(myBlackList)
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel
    allSelections.BJetSelection.jetPtCuts = [40.0, 30.0]
    # allSelections.BJetSelection.triggerMatchingApply = True # at least 1 trg b-jet matched to offline b-jets
    # allSelections.Trigger.triggerOR = ["HLT_PFHT400_SixJet30", #Prescale 110 at inst. lumi 1.35E+34
    #                                    "HLT_PFHT450_SixJet40", #Prescale  26 at inst. lumi 1.35E+34]
    # allSelections.Trigger.triggerOR = ["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"]
    # allSelections.Trigger.triggerOR = ["HLT_PFHT450_SixJet40_BTagCSV_p056"]

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    # ================================================================================================
    # Build analysis modules
    # ================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.usePUreweighting,
                              useTopPtReweighting=opts.useTopPtReweighting,
                              doSystematicVariations=opts.doSystematics)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("BJetSelection.triggerMatchingApply", [True, False]) # At least 1 trg b-jet dR-matched to offline b-jets
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutValue", [100, 20])
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["=="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutDirection", [">="])
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscr", "")
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscrWorkingPoint", "Loose")
    # builder.addVariation("FakeBMeasurement.invertedBJetsSortType", ["Random", "DescendingBDiscriminator"])
    # builder.addVariation("FakeBMeasurement.invertedBJetsDiscrMaxCutValue", [0.82, 0.80, 0.75, 0.70])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [100])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT450_SixJet40"], ["HLT_PFHT400_SixJet30"]])
    # builder.addVariation("TopologySelection.FoxWolframMomentCutValue", [0.5, 0.7])
    builder.addVariation("Trigger.triggerOR",
                         [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"],
                          ["HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056", "HLT_PFHT450_SixJet40_BTagCSV_p056"]])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    # def createAnalyzer(dataVersion):
    # a = Analyzer("ExampleAnalysis")
    # if dataVersion.isMC():
    # a.tauPtCut = 10
    # else:
    # a.tauPtCut = 20
    # return a
    # process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    # process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()

    return
#!/usr/bin/env python

dataEras = ["2015"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer
process = Process()

import sys
if len(sys.argv) < 2:
    print "Usage: ./QCDMeasurementAnalysis.py <path-to-multicrab-directory>"
    sys.exit(0)
process.addDatasetsFromMulticrab(sys.argv[1])

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections
# Enable genuine tau histograms for common plots (needed for calculating N_QCD)
allSelections.CommonPlots.enableGenuineTauHistograms = True
# Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
allSelections.CommonPlots.histogramSplitting = [
    PSet(label="tauPt", binLowEdges=[60.0, 70.0, 80.0, 100.0, 120.0], useAbsoluteValues=False),
  ]

# Build analysis modules
from HiggsAnalysis.NtupleAnalysis.AnalysisBuilder import AnalysisBuilder
builder = AnalysisBuilder("QCDMeasurement", 
                          dataEras,
                          searchModes,
                          #### Options ####
                          #doSystematicVariations=True,
Esempio n. 37
0
def main():

    # Require at least two arguments (script-name, path to multicrab)
    if len(sys.argv) < 2:
        Print(
            "Not enough arguments passed to script execution. Printing docstring & EXIT."
        )
        print __doc__
        sys.exit(0)
    else:
        pass

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    process = Process(prefix, postfix, opts.nEvts)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" %
              (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(
            opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" %
              (opts.excludeTasks, opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab,
                                         excludeTasks=opts.excludeTasks)
    else:
        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print(
            "If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc..."
        )
        process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Selection customisations
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections
    #from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections

    # Overwrite verbosity
    allSelections.verbose = opts.verbose

    # Overwrite histo ambient level (Options: Systematics, Vital, Informative, Debug)
    allSelections.histogramAmbientLevel = opts.histoLevel

    # Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
    # allSelections.CommonPlots.histogramSplitting = [
    #     PSet(label="tauPt", binLowEdges=[60.0, 70.0, 80.0, 100.0], useAbsoluteValues=False),
    #     ]

    # allSelections.TauSelection.rtau = 0.0
    # allSelections.BJetSelection.numberOfBJetsCutValue = 0
    # allSelections.BJetSelection.numberOfBJetsCutDirection = "=="

    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections

    # ================================================================================================
    # Command Line Options
    # ================================================================================================
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    #================================================================================================
    # Build analysis modules
    #================================================================================================
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting=opts.puReweight,
                              doSystematicVariations=opts.systematics)

    # Perform variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? By default it uses all cores, but you can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" %
              (str(opts.jCores)))
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()
dataEras = ["2016"]
#dataEras = ["2015B","2015C"]
searchModes = ["80to1000"]

if len(sys.argv) < 2:
    print "Usage: ./exampleAnalysis.py <path-to-multicrab-directory> <1pr> <2pr> <3pr>"
    sys.exit(0)

from HiggsAnalysis.NtupleAnalysis.main import Process, PSet, Analyzer
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import obtainAnalysisSuffix 
maxEvents = {}
#maxEvents["TT"] = 100
#maxEvents["All"] = 100
#maxEvents["^T\S+"] = 200
#maxEvents["Charged"] = 100
process = Process("SignalAnalysis"+obtainAnalysisSuffix(sys.argv),maxEvents=maxEvents)
blacklist = []
#blacklist = ["ChargedHiggs_HplusTB_HplusToTauNu_M_","ChargedHiggs_HplusToTauNu_M_200_","ChargedHiggs_HplusTB_HplusToTauNu_HeavyMass_M_"]
whitelist = []
#whitelist = ["Tau_Run2016C_","DY","ChargedHiggs_HplusTB_HplusToTauNu_IntermediateMassNoNeutral_M_175"]
process.addDatasetsFromMulticrab(sys.argv[1],blacklist=blacklist,whitelist=whitelist)

# Add config
from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import allSelections,applyAnalysisCommandLineOptions,setAngularCutsWorkingPoint
# Set splitting of phase space (first bin is below first edge value and last bin is above last edge value)
allSelections.CommonPlots.histogramSplitting = [
    #PSet(label="tauPt", binLowEdges=[60.0, 70.0, 80.0, 100.0], useAbsoluteValues=False),
  ]
#===== Selection customisations

allSelections.TauSelection.prongs = 1
def addAnalyzer(era):
    process = Process(outputPrefix="singleTauEfficiency_"+era)
    process.addDatasetsFromMulticrab(sys.argv[1])
    ds = getDatasetsForEras(process.getDatasets(),eras[era])
    process.setDatasets(ds)
    global runmin,runmax
    runmin,runmax = process.getRuns()
    process.addAnalyzer("SingleTau"+tauThreshold+"_"+era, lambda dv: createAnalyzer(dv, era))
    process.run()
Esempio n. 40
0
def addAnalyzer(era):
    process = Process(outputPrefix="tauLegEfficiency_" + era)
    #    process.setDatasets([])
    process.addDatasetsFromMulticrab(sys.argv[1])
    ds = getDatasetsForEras(process.getDatasets(), eras[era])
    process.setDatasets(ds)
    global runmin, runmax
    runmin, runmax = process.getRuns()
    process.addAnalyzer("TauLeg_" + era, lambda dv: createAnalyzer(dv, era))
    #    process.addAnalyzer("TauLeg_"+era, createAnalyzer(dv, era))
    process.run()
Esempio n. 41
0
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)      
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass
        

    # ================================================================================================
    # Setup the process
    # ================================================================================================
    maxEvents = {}
    maxEvents["All"] = opts.nEvts
    process = Process(prefix, postfix, maxEvents)
                
    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Print("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Print("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = ["QCD_b"
                       "ChargedHiggs_HplusTB_HplusToTB_M_180_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_200_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_220_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_250_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_300_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_350_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_400_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_500_ext1", 
                       #"ChargedHiggs_HplusTB_HplusToTB_M_650",  #10M events!
                       "ChargedHiggs_HplusTB_HplusToTB_M_800_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_1000_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_2000_ext1"
                       "ChargedHiggs_HplusTB_HplusToTB_M_2500_ext1", 
                       "ChargedHiggs_HplusTB_HplusToTB_M_3000_ext1", 
                       # "ChargedHiggs_HplusTB_HplusToTB_M_1000",
                       "ChargedHiggs_HplusTB_HplusToTB_M_1500",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_2000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_2500",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_3000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_5000",   # Speeed things up
                       "ChargedHiggs_HplusTB_HplusToTB_M_7000",   # Speeed things up  
                       "ChargedHiggs_HplusTB_HplusToTB_M_10000",  # Speeed things up
                       ]
        if opts.doSystematics:
            myBlackList.append("QCD")

        Print("Adding all datasets from multiCRAB directory %s" % (opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        regex =  "|".join(myBlackList)
        if len(myBlackList)>0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)



    # ================================================================================================
    # Overwrite Default Settings  
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.jetTriggers import allSelections
    from HiggsAnalysis.NtupleAnalysis.main import PSet
    import HiggsAnalysis.NtupleAnalysis.parameters.scaleFactors as scaleFactors

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    #==========================
    #  Systematics selections
    #==========================
    
    # marina
    allSelections.SystTopBDTSelection.MVACutValue = 0.40
    allSelections.TopSelectionBDT.TopMVACutValue  = 0.40
    
    # BDT MisID SF
    MisIDSF = PSet(
        MisIDSFJsonName = "topMisID_BDT0p40_TopMassCut400.json",
        ApplyMisIDSF    = False, 
        )
    
    scaleFactors.assignMisIDSF(MisIDSF, "nominal", MisIDSF.MisIDSFJsonName)
    allSelections.MisIDSF = MisIDSF
    
    allSelections.SystTopBDTSelection.MiniIsoCutValue    = 0.1
    allSelections.SystTopBDTSelection.MiniIsoInvCutValue = 0.1
    allSelections.SystTopBDTSelection.METCutValue        = 50.0
    allSelections.SystTopBDTSelection.METInvCutValue     = 20.0
    
    # Muon
    allSelections.MuonSelection.muonPtCut = 30
    
    # Jets
    allSelections.JetSelection.numberOfJetsCutValue = 4
    allSelections.JetSelection.jetPtCuts = [40.0, 40.0, 40.0, 40.0]
        
    # Trigger 
    allSelections.Trigger.triggerOR = ["HLT_Mu50"]

    # Bjets
    allSelections.BJetSelection.jetPtCuts = [40.0, 40.0]
    allSelections.BJetSelection.numberOfBJetsCutValue = 2
    
    # ================================================================================================
    # Add Analysis Variations
    # ================================================================================================
    # selections = allSelections.clone()
    # process.addAnalyzer(prefix, Analyzer(prefix, config=selections, silent=False) ) #trigger passed from selections


    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)

    #================================================================================================
    # Build analysis modules
    #================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics,
                              analysisType="HToTB")

    # Add variations (e.g. for optimisation)
    # builder.addVariation("METSelection.METCutValue", [100,120,140])
    # builder.addVariation("AngularCutsBackToBack.workingPoint", ["Loose","Medium","Tight"])
    # builder.addVariation("BJetSelection.triggerMatchingApply", [False])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [5, 10, 15, 20])

    # Build the builder
    builder.build(process, allSelections)

    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    #def createAnalyzer(dataVersion):
    #a = Analyzer("ExampleAnalysis")
    #if dataVersion.isMC():
    #a.tauPtCut = 10
    #else:
    #a.tauPtCut = 20
    #return a
    #process.addAnalyzer("test2", createAnalyzer)

    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    #process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))
    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt      = int(tFinish) - int(tStart)
    days    = divmod(dt,86400)      # days
    hours   = divmod(days[1],3600)  # hours
    mins    = divmod(hours[1],60)   # minutes
    secs    = mins[1]               # seconds
    Print("Total elapsed time is %s days, %s hours, %s mins, %s secs" % (days[0], hours[0], mins[0], secs), True)
    return
def main():

    # Save start time (epoch seconds)
    tStart = time.time()
    Verbose("Started @ " + str(tStart), True)

    # Require at least two arguments (script-name, path to multicrab)     
    if len(sys.argv) < 2:
        Print("Not enough arguments passed to script execution. Printing docstring & EXIT.")
        print __doc__
        sys.exit(0)
    else:
        pass


    # ================================================================================================
    # Setup the process
    # ================================================================================================
    completeList = GetDatasetCompleteList()
    whiteList    = GetDatasetWhitelist(opts)
    blackList    = GetDatasetBlackList(completeList, whiteList)
    maxEvents = {}
    for d in whiteList:
        maxEvents[d] = -1
        #if  d == "ChargedHiggs_HplusTB_HplusToTB_M_650":
        #    maxEvents[d] = 4000000
    process = Process(prefix, postfix, maxEvents)

    # ================================================================================================
    # Add the datasets (according to user options)
    # ================================================================================================
    if (opts.includeOnlyTasks):
        Verbose("Adding only dataset %s from multiCRAB directory %s" % (opts.includeOnlyTasks, opts.mcrab))
        process.addDatasetsFromMulticrab(opts.mcrab, includeOnlyTasks=opts.includeOnlyTasks)
    elif (opts.excludeTasks):
        Verbose("Adding all datasets except %s from multiCRAB directory %s" % (opts.excludeTasks, opts.mcrab))
        Print("If collision data are present, then vertex reweighting is done according to the chosen data era (era=2015C, 2015D, 2015) etc...")
        process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=opts.excludeTasks)
    else:
        myBlackList = blackList
        #myBlackList = ["M_180", "M_200" , "M_220" , "M_250" , "M_300" , "M_350" , "M_400" , "M_500" , "M_650",
        #               "M_800", "M_1000", "M_1500", "M_2000", "M_2500", "M_3000", "M_5000", "M_7000", "M_10000"]

        # Extend the blacklist with datasets not in the group
        #myBlackList.extend(blackList)

        Verbose("Adding all datasets from multiCRAB directory %s except %s" % (opts.mcrab, (",".join(myBlackList))) )
        Verbose("Vertex reweighting is done according to the chosen data era (%s)" % (",".join(dataEras)) )
        regex = "|".join(myBlackList)
        if len(myBlackList) > 0:
            process.addDatasetsFromMulticrab(opts.mcrab, excludeTasks=regex)
        else:
            process.addDatasetsFromMulticrab(opts.mcrab)

    # ================================================================================================
    # Overwrite Default Settings
    # ================================================================================================
    from HiggsAnalysis.NtupleAnalysis.parameters.hplus2tbAnalysis import allSelections

    allSelections.verbose = opts.verbose
    allSelections.histogramAmbientLevel = opts.histoLevel

    # Set splitting of phase-space (first bin is below first edge value and last bin is above last edge value)
    allSelections.CommonPlots.histogramSplitting = [               
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 160,  300], useAbsoluteValues=False), # last (not bad)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 120,  300], useAbsoluteValues=False), # last (not bad)
        #PSet(label="TetrajetBjetPt" , binLowEdges=[50, 150,  300], useAbsoluteValues=False), # last (quite good)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 60,  150], useAbsoluteValues=False),
        # PSet(label="TetrajetBjetPt" , binLowEdges=[60, 90, 160, 300], useAbsoluteValues=False), # BEST (v1)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 60, 90, 160, 330], useAbsoluteValues=False),
        PSet(label="TetrajetBjetPt" , binLowEdges=[60, 90, 160, 300], useAbsoluteValues=False), # BEST (v2)
        #PSet(label="TetrajetBjetPt" , binLowEdges=[60, 90, 160, 300], useAbsoluteValues=False), # BEST (v3)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 65, 130, 330], useAbsoluteValues=False), # BEST (v4)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[50, 65, 95, 130, 330], useAbsoluteValues=False), # BEST (v5)
        # PSet(label="TetrajetBjetPt" , binLowEdges=[45, 50, 60, 90, 160, 330], useAbsoluteValues=False), # BEST (v5)
        #
        PSet(label="TetrajetBjetEta", binLowEdges=[0.8, 1.4, 2.0], useAbsoluteValues=True), # optimised
        ]

    # Overwrite values
    # allSelections.TopSelectionBDT.CSV_bDiscCutDirection  = ">="
    allSelections.TopSelectionBDT.CSV_bDiscCutValue = 0.54 # allow CSVv2-L for inverted top

    # ================================================================================================
    # Command Line Options
    # ================================================================================================ 
    # from HiggsAnalysis.NtupleAnalysis.parameters.signalAnalysisParameters import applyAnalysisCommandLineOptions
    # applyAnalysisCommandLineOptions(sys.argv, allSelections)
    

    # ================================================================================================
    # Build analysis modules
    # ================================================================================================
    PrintOptions(opts)
    builder = AnalysisBuilder(prefix,
                              dataEras,
                              searchModes,
                              usePUreweighting       = opts.usePUreweighting,
                              useTopPtReweighting    = opts.useTopPtReweighting,
                              doSystematicVariations = opts.doSystematics,
                              analysisType="HToTB",
                              verbose=opts.verbose,
                              systVarsList=opts.systVarsList)

    # Add variations (e.g. for optimisation)
    # builder.addVariation("BJetSelection.triggerMatchingApply", [True, False]) # At least 1 trg b-jet dR-matched to offline b-jets
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutValue", [100, 20])
    # builder.addVariation("FakeBMeasurement.prelimTopFitChiSqrCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["=="])
    # builder.addVariation("FakeBMeasurement.numberOfBJetsCutDirection", ["<=", "==", ">="])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutValue", [0, 1])
    # builder.addVariation("FakeBMeasurement.numberOfInvertedBJetsCutDirection", [">="])
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscr", "")
    # builder.addVariation("FakeBMeasurement.invertedBJetDiscrWorkingPoint", "Loose")
    # builder.addVariation("FakeBMeasurement.invertedBJetsSortType", ["Random", "DescendingBDiscriminator"])
    # builder.addVariation("FakeBMeasurement.invertedBJetsDiscrMaxCutValue", [0.82, 0.80, 0.75, 0.70])
    # builder.addVariation("TopSelection.ChiSqrCutValue", [100])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT450_SixJet40"], ["HLT_PFHT400_SixJet30"]])
    # builder.addVariation("TopologySelection.FoxWolframMomentCutValue", [0.5, 0.7])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056"], ["HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    # builder.addVariation("Trigger.triggerOR", [["HLT_PFHT400_SixJet30_DoubleBTagCSV_p056", "HLT_PFHT450_SixJet40_BTagCSV_p056"]])
    
    # Build the builder
    builder.build(process, allSelections)
    
    # ================================================================================================
    # Example of adding an analyzer whose configuration depends on dataVersion
    # ================================================================================================
    # def createAnalyzer(dataVersion):
    # a = Analyzer("ExampleAnalysis")
    # if dataVersion.isMC():
    # a.tauPtCut = 10
    # else:
    # a.tauPtCut = 20
    # return a
    # process.addAnalyzer("test2", createAnalyzer)
    
    # ================================================================================================
    # Pick events
    # ================================================================================================
    # process.addOptions(EventSaver = PSet(enabled = True,pickEvents = True))

    # ================================================================================================
    # Run the analysis
    # ================================================================================================
    # Run the analysis with PROOF? You can give proofWorkers=<N> as a parameter
    if opts.jCores:
        Print("Running process with PROOF (proofWorkes=%s)" % ( str(opts.jCores) ) )
        process.run(proof=True, proofWorkers=opts.jCores)
    else:
        Print("Running process (no PROOF)")
        process.run()

    # Print total time elapsed
    tFinish = time.time()
    dt      = int(tFinish) - int(tStart)
    days    = divmod(dt,86400)      # days
    hours   = divmod(days[1],3600)  # hours
    mins    = divmod(hours[1],60)   # minutes
    secs    = mins[1]               # seconds
    Print("Total elapsed time is %s days, %s hours, %s mins, %s secs" % (days[0], hours[0], mins[0], secs), True)
    return