Example #1
0
allProcesses = [
    item for item in allProcesses
    if not "fakes-DD" in item and not "_had" in item
]
allEstimators = estimators.constructEstimatorList(allProcesses)
mc = list(set([e.name.split("_")[0] for e in allEstimators]))

if not args.noData:
    allEstimators += [
        DataObservation(name="Data",
                        process=setup.processes["Data"],
                        cacheDir=setup.defaultCacheDir())
    ]

if args.controlRegion:
    setup = setup.sysClone(parameters=CR_para)


def wrapper(arg):
    r, channel, setup, estimate, cat, est = arg
    estimate.initCache(setup.defaultCacheDir())
    if estimate.name == "Data" and blind:
        res = u_float(0, 0)
    else:
        res = estimate.cachedEstimate(r,
                                      channel,
                                      setup,
                                      overwrite=False,
                                      checkOnly=True)
    if args.removeNegative and res < 0: res = u_float(0, 0)
    return est, str(r), cat, channel, res.tuple()
Example #2
0
     cutInterpreter.cutString("mu")])
mc_mu.setWeightString(weightStringAR)

mc_e.setSelectionString(
    [filterCutMC, "reweightHEM>0",
     cutInterpreter.cutString("e")])
mc_e.setWeightString(weightStringAR)

print "e", mc_e.selectionString
print
print "mu", mc_mu.selectionString

setup = Setup(
    year=args.year, photonSelection=False, checkOnly=False,
    runOnLxPlus=False)  #photonselection always false for qcd estimate
setup = setup.sysClone(parameters=allRegions[args.selection]["parameters"])

selection = setup.selection("MC", channel="all",
                            **setup.defaultParameters())["prefix"]
selection = cutInterpreter.cutString(selection)
selection += "&&pTStitching==1&&triggered==1"
print selection
if args.addCut:
    selection += "&&" + cutInterpreter.cutString(args.addCut)
print("Using selection string: %s" % selection)

key = (mc_e.name, "AR", args.variable, "_".join(map(str, args.binning)),
       mc_e.weightString, mc_e.selectionString, selection)
if dirDB.contains(key) and not args.overwrite:
    mcHist_e = dirDB.get(key.Clone("e"))
else:
Example #3
0
            #            return setup.lumi/1000.*u_float(**getattr(self,"".join(["process",signalAddon if signalAddon else ""])).getYieldFromDraw(selectionString = cut, weightString = weight) )
            #            print cut, weight
            return u_float(**getattr(
                self, "".join(["process", signalAddon if signalAddon else ""])
            ).getYieldFromDraw(selectionString=cut, weightString=weight))

if __name__ == "__main__":
    from TTGammaEFT.Analysis.regions import regionsTTG, noPhotonRegionTTG, inclRegionsTTG
    from TTGammaEFT.Analysis.SetupHelpers import allRegions
    from TTGammaEFT.Analysis.Setup import Setup

    print "lowPT"
    r = regionsTTG[0]

    setup = Setup(year=2016, photonSelection=True)
    setup = setup.sysClone(parameters=allRegions["VG3"]["parameters"])

    estimate = MCBasedEstimate(name="TTG_gen",
                               process=setup.processes["TTG_gen"])
    estimate.initCache(setup.defaultCacheDir())
    res = estimate.TuneSystematic(r, "e", setup)

    #    res = estimate._estimate( r, "e", setup, overwrite=False )
    print "TTG", res

    estimate = MCBasedEstimate(name="TTG_gen",
                               process=setup.processes["TTG_gen"])
    estimate.initCache(setup.defaultCacheDir())
    #    res = estimate._estimate( r, "e", setup, overwrite=False )
    print "TTG_gen", res
Example #4
0
def get_weight_string(parameters):
    return w.get_weight_string(**parameters)


baseDir = os.path.join(cache_directory, "analysis", "eft")
cacheFileName = os.path.join(baseDir, eftSample.name)
cache = MergingDirDB(cacheFileName)

parameters = allRegions[args.controlRegion]["parameters"]
channels = allRegions[args.controlRegion]["channels"]
photonSelection = not allRegions[args.controlRegion]["noPhotonCR"]
allPhotonRegions = allRegions[args.controlRegion]["inclRegion"] + allRegions[
    args.controlRegion]["regions"] if photonSelection else allRegions[
        args.controlRegion]["regions"]
setup = Setup(year=2016, checkOnly=args.checkOnly)
setup = setup.sysClone(parameters=parameters)


def wrapper(arg):
    r, channel, setup, (ctZ, ctZI, ctW, ctWI) = arg
    EFTparams = ["ctZ", str(ctZ), "ctZI",
                 str(ctZI)]  #, "ctW", str(ctW), "ctWI", str(ctWI) ]
    params = {"ctZ": ctZ, "ctZI": ctZI}  #,  "ctW":ctW, "ctWI":ctWI }
    key = (args.controlRegion, str(r), channel, "_".join(EFTparams))
    keymu = (args.controlRegion.replace("All",
                                        ""), str(r), "e", "_".join(EFTparams))
    keye = (args.controlRegion.replace("All",
                                       ""), str(r), "mu", "_".join(EFTparams))
    print key
    print keymu
    print keye
Example #5
0
# Select estimate
if args.selectEstimator == "Data":
    estimate = DataObservation(name="Data", process=setup.processes["Data"])
    estimate.isData = True
else:
    estimators = EstimatorList(setup, processes=[args.selectEstimator])
    estimate = getattr(estimators, args.selectEstimator)
    estimate.isData = False

if not estimate:
    logger.warning(args.selectEstimator + " not known")
    sys.exit(0)

estimate.initCache(setup.defaultCacheDir())
setup3p = setup.sysClone(parameters=parameters3p)
setup3 = setup.sysClone(parameters=parameters3)
setup4p = setup.sysClone(parameters=parameters4p)


def wrapper(arg):
    r, channel, setup3p, addon, setup3, setup4p = arg
    logger.info(
        "Running estimate for region %s, channel %s in setup %s for estimator %s"
        % (r, channel, args.controlRegion if args.controlRegion else "None",
           args.selectEstimator if args.selectEstimator else "None"))
    res3 = estimate.cachedEstimate(r,
                                   channel,
                                   setup3,
                                   signalAddon=addon,
                                   save=True,
Example #6
0
    "cos(JetGood0_phi-JetGood1_phi)":
    "cos(JetGoodInvLepIso0_phi-JetGoodInvLepIso1_phi)",
}

invVariable = replaceVariable[
    args.variable] if args.variable in replaceVariable.keys(
    ) else args.variable

# get cached transferfactors
setup = Setup(
    year=args.year, photonSelection=False, checkOnly=False,
    runOnLxPlus=False)  #photonselection always false for qcd estimate
reg = "TT" if "1p" in args.selection else "WJets"
reg += "4p" if "4p" in args.selection else "3"

setup = setup.sysClone(parameters=allRegions[reg]["parameters"])
estimators = EstimatorList(setup, processes=["QCD-DD"])
estimate = getattr(estimators, "QCD-DD")
estimate.initCache(setup.defaultCacheDir())

# Accounting for
leptonPtCutVar = "LeptonTightInvIsoNoSieie0_pt"
leptonEtaCutVar = "abs(LeptonTightInvIsoNoSieie0_eta+LeptonTightInvIsoNoSieie0_deltaEtaSC)"
QCDTF_updates_2J = copy.deepcopy(QCDTF_updates)

key = (data_sample.name, "AR", args.variable, "_".join(map(str, args.binning)),
       data_sample.weightString, data_sample.selectionString, selection)
if dirDB.contains(key) and not args.overwrite:
    dataHist = dirDB.get(key).Clone("data")
else:
    dataHist = data_sample.get1DHistoFromDraw(args.variable,
    default_photon_setup.addon = ""
    default_photon_setup.regions = inclRegionsTTG if args.inclRegion else regionsTTG

# Define SR, CR, channels and regions
setups = []
for key, val in allRegions.items():
    if not key in args.useRegions: continue
    if key not in limitOrdering:
        limitOrdering += [key]

    if args.checkOnly:
        locals()["setup" + key] = None
        continue

    locals()["setup" + key] = default_setup.sysClone(
        parameters=val["parameters"]
    ) if val["noPhotonCR"] else default_photon_setup.sysClone(
        parameters=val["parameters"])
    estimators = EstimatorList(locals()["setup" + key])
    locals()["setup" + key].name = key
    locals()["setup" + key].channels = val["channels"]  #default_setup.channels
    locals()["setup" + key].noPhotonCR = val["noPhotonCR"]
    locals()["setup" + key].signalregion = "SR" in key
    locals()["setup" +
             key].regions = val["inclRegion" if args.inclRegion else "regions"]
    locals()["setup" + key].data = default_setup.data if val[
        "noPhotonCR"] else default_photon_setup.data
    locals()["setup" + key].processes = estimators.constructProcessDict(
        processDict=val["processes"]
    ) if "processes" in val else default_setup.processes if val[
        "noPhotonCR"] else default_photon_setup.processes
Example #8
0
extensions_ = ["pdf", "png", "root"]
plot_directory_ = os.path.join(plot_directory, 'QCDMCTFComp', str(args.year),
                               args.plot_directory, args.mode)
copyIndexPHP(plot_directory_)

if args.year == 2016: lumi_scale = 35.92
elif args.year == 2017: lumi_scale = 41.53
elif args.year == 2018: lumi_scale = 59.74
elif args.year == "RunII": lumi_scale = 35.92 + 41.53 + 59.74

parameters0b0p = allRegions["WJets2"]["parameters"]
setup0b0p = Setup(year=args.year, photonSelection=False, checkOnly=True)
estimators0b0p = EstimatorList(setup0b0p, processes=["QCD-DD"])
estimate0b0p = getattr(estimators0b0p, "QCD-DD")
setup0b0p = setup0b0p.sysClone(parameters=parameters0b0p)
estimate0b0p.initCache(setup0b0p.defaultCacheDir())

parameters1b0p = allRegions["TT2"]["parameters"]
setup1b0p = Setup(year=args.year, photonSelection=False, checkOnly=True)
estimators1b0p = EstimatorList(setup1b0p, processes=["QCD-DD"])
estimate1b0p = getattr(estimators1b0p, "QCD-DD")
setup1b0p = setup1b0p.sysClone(parameters=parameters1b0p)
estimate1b0p.initCache(setup1b0p.defaultCacheDir())

cachedTF = {}
cachedTF["0b0p"] = {}
cachedTF["1b0p"] = {}
cachedTF["0b1p"] = {}
cachedTF["1b1p"] = {}
for nJet in [(2, 2), (3, 3), (4, -1)]:
Example #9
0
    counter_tot = 0
    counter_reco = 0
    counter_fid = 0
    counter_fid_reco = 0
    yield_tot = 0
    yield_reco = 0
    yield_fid = 0
    yield_fid_reco = 0

    for i_year, year in enumerate(settings.years):
        setup = Setup(year=int(year),
                      photonSelection=False,
                      checkOnly=True,
                      runOnLxPlus=False)
        setup = setup.sysClone(
            parameters=allRegions[settings.reco_selection]["parameters"])
        # reco selection
        reco_selection = setup.selection("MC",
                                         channel="all",
                                         **setup.defaultParameters())

        MET_filter_cut = "(year==%s&&" % year + getFilterCut(
            isData=False, year=int(year), skipBadChargedCandidate=True) + ")"
        reco_selection_str = MET_filter_cut + "&&triggered&&pTStitching==1&&overlapRemoval==1&&" + cutInterpreter.cutString(
            reco_selection['prefix'])

        # fiducial seletion
        fiducial_selection_str = cutInterpreter.cutString(
            settings.fiducial_selection
        ) + "&&pTStitching==1&&overlapRemoval==1"
Example #10
0
# use this for job splitting
from RootTools.core.helpers import partition
#

inclEstimate = "TTG_NLO"

# setup and sample
parameters = allRegions["SR3"]["parameters"]
channels = allRegions["SR3"]["channels"]
photonSelection = not allRegions["SR3"]["noPhotonCR"]
allPhotonRegions = allRegions["SR3"]["inclRegion"] + allRegions["SR3"][
    "regions"] if photonSelection else allRegions["SR3"]["regions"]

setup = Setup(year="RunII", photonSelection=photonSelection,
              private=True)  #photonselection always false for qcd es$
setup = setup.sysClone(parameters=parameters)
estimates = EstimatorList(setup, processes=["TTG_NLO_gen", inclEstimate])
estimate = getattr(estimates, "TTG_NLO_gen")
estimate.initCache(setup.defaultCacheDir() + "/PDF")

scale_indices = [0, 1, 3, 5, 7, 8]  #4 central?
pdf_indices = range(100)
aS_variations = ["abs(LHEPdfWeight[101])", "abs(LHEPdfWeight[102])"]
scale_variations = ["abs(LHEScaleWeight[%i])" % i for i in scale_indices]
PDF_variations = ["abs(LHEPdfWeight[%i])" % i for i in pdf_indices]

PDF_unc = []
Scale_unc = []
PS_unc = []
ISR_unc = []
FSR_unc = []
Example #11
0
if args.year == 2016: lumi_scale = 35.92
elif args.year == 2017: lumi_scale = 41.53
elif args.year == 2018: lumi_scale = 59.74
elif args.year == "RunII": lumi_scale = 35.92 + 41.53 + 59.74

parameters0b = allRegions["VG2"]["parameters"]
parameters1b = allRegions["SR2"]["parameters"]
setup = Setup(year=args.year,
              photonSelection=False,
              checkOnly=True,
              runOnLxPlus=False)
estimators = EstimatorList(setup, processes=["QCD-DD"])
estimate = getattr(estimators, "QCD-DD")

setup0b = setup.sysClone(parameters=parameters0b)
setup1b = setup.sysClone(parameters=parameters1b)
estimate.initCache(setup.defaultCacheDir())

cachedTF = {}
cachedTF["0b"] = {}
cachedTF["1b"] = {}
# get brute force all of them
for key, qcdUpdate in customQCDTF_updates.iteritems():
    cachedTF["0b"][key] = estimate.cachedTransferFactor(args.mode,
                                                        setup0b,
                                                        qcdUpdates=qcdUpdate,
                                                        checkOnly=True)
    cachedTF["1b"][key] = estimate.cachedTransferFactor(args.mode,
                                                        setup1b,
                                                        qcdUpdates=qcdUpdate,
Example #12
0
        str(regionsTTG[1]): "medPT",
        str(regionsTTG[2]): "highPT"
    }

if photonSelection:
    setup = Setup(year=args.year,
                  photonSelection=photonSelection,
                  checkOnly=True)
    estimators = EstimatorList(setup, processes=["QCD-DD"])
    estimate = getattr(estimators, "QCD-DD")
    estimate.isData = False

    setups = {}
    setups[args.year] = {}
    for r in args.regions:
        setups[args.year][r] = setup.sysClone(
            parameters=allRegions[r]["parameters"])
        setups[args.year][r].verbose = True

else:
    setups = {}
    for y in [2016, 2017, 2018]:
        setup = Setup(year=y, photonSelection=False, checkOnly=True)
        estimators = EstimatorList(setup, processes=["QCD-DD"])
        estimate = getattr(estimators, "QCD-DD")
        estimate.isData = False

        setups[y] = {}
        for r in args.regions:
            setups[y][r] = setup.sysClone(
                parameters=allRegions[r]["parameters"])
            setups[y][r].verbose = True
Example #13
0
channels = allRegions[args.controlRegion]["channels"]
photonSelection = not allRegions[args.controlRegion]["noPhotonCR"]
allPhotonRegions = allRegions[args.controlRegion]["inclRegion"] + allRegions[
    args.controlRegion]["regions"] if photonSelection else allRegions[
        args.controlRegion]["regions"]
regions = allPhotonRegions if not args.selectRegion else [
    allPhotonRegions[args.selectRegion]
]

setup = Setup(
    year=args.year,
    photonSelection=photonSelection,
    checkOnly=args.checkOnly,
    runOnLxPlus=args.runOnLxPlus,
    private=args.runOnTopNanoAOD)  #photonselection always false for qcd es$
setup = setup.sysClone(parameters=parameters)
estimates = EstimatorList(setup,
                          processes=[args.selectEstimator, inclEstimate])
estimate = getattr(estimates, args.selectEstimator)
estimate.initCache(setup.defaultCacheDir() + "/PDF")

setupIncl = Setup(
    year=args.year,
    photonSelection=False,
    checkOnly=args.checkOnly,
    runOnLxPlus=args.runOnLxPlus,
    private=args.runOnTopNanoAOD)  #photonselection always false for qcd es$
setupIncl = setupIncl.sysClone(parameters={
    "zWindow": "all",
    "nJet": (0, -1),
    "nBTag": (0, -1),