etaBins = [0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4] extensions_ = ["pdf", "png", "root"] plot_directory_ = os.path.join(plot_directory, 'transferFactor', str(args.year), args.plot_directory, "ptEta", args.mode) 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 print "hist2D" parameters = allRegions["WJets2"]["parameters"] setup = Setup(year=args.year, photonSelection=False, checkOnly=False, runOnLxPlus=False) estimators = EstimatorList(setup, processes=["QCD-DD"]) estimate = getattr(estimators, "QCD-DD") setup = setup.sysClone(parameters=parameters) estimate.initCache(setup.defaultCacheDir()) QCDTF_updates = {} QCDTF_updates["CR"] = { "invertLepIso": True, "nJet": (2, 2), "nBTag": (0, 0), "nPhoton": (0, 0), "MET": (0, -1), "m3Window": "all",
"nBTagGood": "nBTagGoodInvLepIso", "mT": "mTinv", "m3": "m3inv", "LeptonTight0": "LeptonTightInvIso0", "JetGood0": "JetGoodInvLepIso0", "JetGood1": "JetGoodInvLepIso1", "PhotonNoChgIsoNoSieie0": "PhotonNoChgIsoNoSieieInvLepIso0", "ltight0GammaNoSieieNoChgIsodR": "ltight0GammaNoSieieNoChgIsoInvLepIsodR", } if len(args.selection.split("-")) == 1 and args.selection in allRegions.keys(): print("Plotting region from SetupHelpers: %s" % args.selection) 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=args.mode, **setup.defaultParameters())["prefix"] selection = cutInterpreter.cutString(selection) selection += "&&triggered==1" print selection if args.addCut: selection += "&&" + cutInterpreter.cutString(args.addCut) print("Using selection string: %s" % selection) preSelection = setup.selection(
"cos(LeptonTightInvIsoNoSieie0_phi-JetGoodInvLepIso0_phi)", "cos(LeptonTightNoSieie0_phi-JetGood1_phi)": "cos(LeptonTightInvIsoNoSieie0_phi-JetGoodInvLepIso1_phi)", "cos(JetGood0_phi-MET_phi)": "cos(JetGoodInvLepIso0_phi-MET_phi)", "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)),
"3p", "3"), args.controlRegion.replace("3p", "4p"), args.controlRegion) parameters3p = allRegions[args.controlRegion]["parameters"] parameters3 = allRegions[args.controlRegion.replace("3p", "3")]["parameters"] parameters4p = allRegions[args.controlRegion.replace("3p", "4p")]["parameters"] channels = allRegions[args.controlRegion]["channels"] photonSelection = not allRegions[args.controlRegion]["noPhotonCR"] if args.noInclusive: allPhotonRegions = allRegions[args.controlRegion]["regions"] else: allPhotonRegions = allRegions[ args.controlRegion]["inclRegion"] + allRegions[ args.controlRegion]["regions"] if photonSelection else allRegions[ args.controlRegion]["regions"] setup = Setup(year=args.year, photonSelection=photonSelection and not "QCD" in args.selectEstimator, checkOnly=True) #photonselection always false for qcd estimate # 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)
noCat_sel = "all" allCat = ["all","gen","misID","had"] blind = False if photonSelection: if "SR" in args.controlRegion: inclRegionsTTG = inclRegionsTTGloose regionsTTG = regionsTTGloose blind = args.year != 2016 ptDict = {str(inclRegionsTTG[0]):"all", str(regionsTTG[0]):"lowPT", str(regionsTTG[1]):"medPT", str(regionsTTG[2]):"highPT"} catSel = ["all","gen","misID","had"] else: ptDict = {str(noPhotonRegionTTG[0]):"all"} catSel = ["all"] setup = Setup(year=args.year, photonSelection=False, checkOnly=True) estimators = EstimatorList(setup) 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)
if "SR" in args.controlRegion: inclRegionsTTG = inclRegionsTTGloose regionsTTG = regionsTTGloose blind = args.year != 2016 ptDict = { str(inclRegionsTTG[0]): "all", str(regionsTTG[0]): "lowPT", str(regionsTTG[1]): "medPT", str(regionsTTG[2]): "highPT" } catSel = ["all", "gen", "misID", "np"] else: ptDict = {str(noPhotonRegionTTG[0]): "all"} catSel = ["all"] setup = Setup(year=args.year, photonSelection=False, checkOnly=True) estimators = EstimatorList(setup) 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()) ]
logger_rt = logger_rt.get_logger(args.logLevel, logFile=None) # setup and sample 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"] 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={
matrix.GetXaxis().SetTitle(settings.tex_reco) matrix.GetYaxis().SetTitle(settings.tex_gen) 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(
for i_param, ( coeff, str_val, ) in enumerate(zip(coeffs, str_vals)): EFTparams.append(coeff) EFTparams.append(str_val) eft = "_".join(EFTparams) if args.keepCard: args.overwrite = False regionNames = [] if not args.checkOnly: # Define estimators for CR default_setup = Setup(year=2016, checkOnly=True) default_setup.estimators = EstimatorList(default_setup) default_setup.data = default_setup.processes["Data"] # default_setup.processes = default_setup.estimators.constructProcessDict( processDict=default_processes ) default_setup.processes["Data"] = default_setup.data default_setup.addon = "" default_setup.regions = inclRegionsTTG if args.inclRegion else regionsTTG default_photon_setup = Setup(year=2016, photonSelection=True, checkOnly=True) default_photon_setup.estimators = EstimatorList(default_photon_setup) default_photon_setup.data = default_photon_setup.processes["Data"] # default_photon_setup.processes = default_setup.estimators.constructProcessDict( processDict=default_processes ) default_photon_setup.processes["Data"] = default_photon_setup.data default_photon_setup.addon = ""
WGPT_thresholds) parameters = allRegions[args.controlRegion]["parameters"] channels = allRegions[args.controlRegion]["channels"] photonSelection = not allRegions[args.controlRegion]["noPhotonCR"] if args.noInclusive: allPhotonRegions = allRegions[args.controlRegion]["regions"] else: allPhotonRegions = allRegions[ args.controlRegion]["inclRegion"] + allRegions[ args.controlRegion]["regions"] if photonSelection else allRegions[ args.controlRegion]["regions"] allPhotonRegions = allRegions[args.controlRegion]["inclRegion"] setup = Setup(year=args.year, photonSelection=photonSelection and not "QCD" in args.selectEstimator, checkOnly=args.checkOnly, runOnLxPlus=args.runOnLxPlus ) #photonselection always false for qcd estimate # Select estimate if args.selectEstimator == "Data": estimate = DataObservation(name="Data", process=setup.processes["Data"], cacheDir=setup.defaultCacheDir()) estimate.isData = True else: estimators = EstimatorList(setup, processes=[args.selectEstimator]) estimate = getattr(estimators, args.selectEstimator) estimate.isData = False if not estimate:
from Analysis.Tools.u_float import u_float # 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 = []
mc = ["TTG", "Top", "WG", "ZG", "WJets", "DY_LO", "GQCD", "other", "all_mc"] allEst = [] allEst += [s for s in mc] allEst += [s + "_gen" for s in mc] allEst += [s + "_misID" for s in mc] allEst += [s + "_had" for s in mc] allEst += [s + "_hp" for s in mc] allEst += [s + "_fake" for s in mc] allEst += [s + "_PU" for s in mc] years = [2016, 2017, 2018] if args.year == "RunII" else [args.year] setup = {} estimators = {} allEstimators = {} for y in years: setup[y] = Setup(year=y, photonSelection=True, checkOnly=True) estimators[y] = EstimatorList(setup[y]) allEstimators[y] = estimators[y].constructEstimatorList(allEst) for estimate in allEstimators[y]: estimate.initCache(setup[y].defaultCacheDir()) setup[y] = setup[y].sysClone(parameters=CR_para) def getVals(proc, ptRegion): print proc, ptRegion ests = [ proc + s for s in ["", "_gen", "_misID", "_had", "_hp", "_fake", "_PU"] ] filteredEsts = []
sieieSel = ["lowSieie", "highSieie"] chgSel = ["lowChgIso", "highChgIso"] elif not photonSelection: ptDict = {str(noPhotonRegionTTG[0]): "all"} else: ptDict = { str(inclRegionsTTG[0]): "all", str(regionsTTG[0]): "lowPT", 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]:
from TTGammaEFT.Analysis.Setup import Setup from TTGammaEFT.Analysis.MCBasedEstimate import MCBasedEstimate from TTGammaEFT.Analysis.DataDrivenQCDEstimate import DataDrivenQCDEstimate from TTGammaEFT.Analysis.SetupHelpers import default_sampleList setup = Setup() bkgEstimators = [] for process in default_sampleList: if process.count("DD"): bkgEstimators.append( DataDrivenDYEstimate(name=process, cacheDir="analysis")) else: bkgEstimators.append( MCBasedEstimate(name=process, process=setup.processes[process], cacheDir="analysis")) nList = [e.name for e in bkgEstimators] assert len(list(set(nList))) == len( nList), "Names of bkgEstimators are not unique: %s" % ",".join(nList)
# 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
logger = logger.get_logger(args.logLevel, logFile=None) import RootTools.core.logger as logger_rt logger_rt = logger_rt.get_logger(args.logLevel, logFile=None) 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"] = {}
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
if not args.controlRegion: logger.warning("ControlRegion not known") sys.exit(0) parameters = allRegions[args.controlRegion]["parameters"] channels = allRegions[args.controlRegion]["channels"] photonSelection = not allRegions[args.controlRegion]["noPhotonCR"] if args.noInclusive: allPhotonRegions = allRegions[args.controlRegion]["regions"] else: allPhotonRegions = allRegions[ args.controlRegion]["inclRegion"] + allRegions[ args.controlRegion]["regions"] if photonSelection else allRegions[ args.controlRegion]["regions"] setup = Setup(year=args.year, photonSelection=photonSelection and not "QCD" in args.selectEstimator, checkOnly=True) #photonselection always false for qcd estimate # Select estimate if args.selectEstimator == "Data": estimateFrom = DataObservation(name="Data", process=setup.processes["Data"]) estimateFrom.isData = True else: estimators = EstimatorList(setup, processes=[args.selectEstimator]) estimateFrom = getattr(estimators, args.selectEstimator) estimateFrom.isData = False if not estimateFrom: logger.warning(args.selectEstimator + " not known") sys.exit(0)
mc_mu.setSelectionString( [filterCutMC, "reweightHEM>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:
if args.customQCDUpdates: args.customQCDUpdates = customQCDTF_updates[args.customQCDUpdates] if not args.controlRegion: logger.warning("ControlRegion not known") sys.exit(0) parameters = allRegions[args.controlRegion]["parameters"] channels = [args.mode] if args.mode != "all" else [ "e", "mu" ] #allRegions[args.controlRegion]["channels"] #regions = allRegions[args.controlRegion]["inclRegion"] #if allRegions[args.controlRegion]["noPhotonCR"] else allRegions[args.controlRegion]["inclRegion"] + allRegions[args.controlRegion]["regions"] + regionsTTG20To120 + regionsTTG120To220 + regionsTTG220 setup = Setup(year=args.year, photonSelection=False, checkOnly=args.checkOnly, runOnLxPlus=args.runOnLxPlus ) #photonselection always false for qcd estimate estimators = EstimatorList(setup, processes=["QCD-DD"]) estimate = getattr(estimators, "QCD-DD") estimate.isData = False setup = setup.sysClone(parameters=parameters) estimate.initCache(setup.defaultCacheDir()) def wrapper(arg): # r,channel,set = arg channel, set = arg logger.debug("Running transfer factor, channel %s in setup %s for QCD-DD" %