from TTGammaEFT.Tools.user import plot_directory tt0l = Sample.fromDirectory("tt0l", directory = ["/scratch/robert.schoefbeck/TTGammaEFT/nanoTuples/postprocessed/TTGammaEFT_PP_2016_TTG_private_v45/inclusive/TTHad_pow_CP5/"]) tt1l = Sample.fromDirectory("tt1l", directory = ["/scratch/robert.schoefbeck/TTGammaEFT/nanoTuples/postprocessed/TTGammaEFT_PP_2016_TTG_private_v45/inclusive/TTSingleLep_pow_CP5/"]) tt2l = Sample.fromDirectory("tt2l", directory = ["/scratch/robert.schoefbeck/TTGammaEFT/nanoTuples/postprocessed/TTGammaEFT_PP_2016_TTG_private_v45/inclusive/TTLep_pow_CP5/"]) ttg0l = Sample.fromDirectory("ttg0l", directory = ["/scratch/robert.schoefbeck/TTGammaEFT/nanoTuples/postprocessed/TTGammaEFT_PP_2016_TTG_private_v45/inclusive/TTGHad_LO/"]) ttg1l = Sample.fromDirectory("ttg1l", directory = ["/scratch/robert.schoefbeck/TTGammaEFT/nanoTuples/postprocessed/TTGammaEFT_PP_2016_TTG_private_v45/inclusive/TTGSingleLep_LO/"]) ttg2l = Sample.fromDirectory("ttg2l", directory = ["/scratch/robert.schoefbeck/TTGammaEFT/nanoTuples/postprocessed/TTGammaEFT_PP_2016_TTG_private_v45/inclusive/TTGLep_LO/"]) ttg = Sample.combine( "ttg", [ttg0l, ttg1l, ttg2l] ) ## Missing: Add TT contribution + 'overlapremoval' ## Missing: Add years triggerSelector = TriggerSelector(2016) lumi_weight_str = "(%f*(year==2016)+%f*(year==2017)+%f*(year==2018))"%(Run2016.lumi/1000,Run2017.lumi/1000,Run2018.lumi/1000) weight = "%s*weight*reweightHEM*reweightTrigger*reweightL1Prefire*reweightPU*reweightLeptonTightSF*reweightLeptonTrackingTightSF*reweightPhotonSF*reweightPhotonElectronVetoSF*reweightBTag_SF" % lumi_weight_str reco_cut = "nLeptonTight==1&&nLeptonVetoIsoCorr==1&&nJetGood>=3&&nBTagGood>=1&&nPhotonGood==1&&nPhotonNoChgIsoNoSieie==1&&triggered==1&&reweightHEM>0&&overlapRemoval==1&&(PhotonGood0_photonCatMagic==0||PhotonGood0_photonCatMagic==2)&&((year==2016&&Flag_goodVertices&&Flag_globalSuperTightHalo2016Filter&&Flag_HBHENoiseFilter&&Flag_HBHENoiseIsoFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter&&Flag_BadPFMuonFilter&&PV_ndof>4&&sqrt(PV_x*PV_x+PV_y*PV_y)<=2&&abs(PV_z)<=24)||(year==2017&&Flag_goodVertices&&Flag_globalSuperTightHalo2016Filter&&Flag_HBHENoiseFilter&&Flag_HBHENoiseIsoFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter&&Flag_BadPFMuonFilter&&PV_ndof>4&&sqrt(PV_x*PV_x+PV_y*PV_y)<=2&&abs(PV_z)<=24)||(year==2018&&Flag_goodVertices&&Flag_globalSuperTightHalo2016Filter&&Flag_HBHENoiseFilter&&Flag_HBHENoiseIsoFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter&&Flag_BadPFMuonFilter&&PV_ndof>4&&sqrt(PV_x*PV_x+PV_y*PV_y)<=2&&abs(PV_z)<=24))" fiducial_cut = "overlapRemoval==1&&nGenLeptonCMSUnfold==1&&nGenJetsCMSUnfold>=3&&nGenBJetCMSUnfold>=1&&nGenPhotonCMSUnfold==1" MET_filter_cut = "(year==2016&&Flag_goodVertices&&Flag_globalSuperTightHalo2016Filter&&Flag_HBHENoiseFilter&&Flag_HBHENoiseIsoFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter&&Flag_BadPFMuonFilter&&PV_ndof>4&&sqrt(PV_x*PV_x+PV_y*PV_y)<=2&&abs(PV_z)<=24)" gen_match_photon_cut = "sqrt(acos(cos(GenPhotonCMSUnfold0_phi-PhotonGood0_phi))**2+(GenPhotonCMSUnfold0_eta-PhotonGood0_eta)**2)<0.1" weightString = "weight*reweightPhotonSF*reweightPhotonElectronVetoSF*reweightLeptonTightSF*reweightLeptonTrackingTightSF*reweightPU*reweightTrigger*reweightHEM*reweightL1Prefire*reweightBTag_SF" pt_thresholds = [20, 35, 50, 65, 80, 120, 160, 200, 260, 320, 520] ROOT.TH1.SetDefaultSumw2(0) f_out_ref = ttg.get1DHistoFromDraw("PhotonGood0_pt", selectionString = reco_cut, weightString = weightString, binning = pt_thresholds, binningIsExplicit = True)
stack.extend([[s] for s in signals]) for sample in mc + signals: sample.read_variables = read_variables_MC sample.scale = lumi_scale sample.style = styles.fillStyle(sample.color) sample.weight = lambda event, sample: event.reweightDilepTriggerBackup * event.reweightPU * event.reweightLeptonSF * event.reweightLeptonTrackingSF * event.reweightPhotonSF * event.reweightPhotonElectronVetoSF * event.reweightBTag_SF if args.small: for sample in stack.samples: sample.normalization = 1. sample.reduceFiles(factor=15) sample.scale /= sample.normalization weight_ = lambda event, sample: event.weight tr = TriggerSelector(args.year, None) # Use some defaults (set defaults before you create/import list of Plots!!) Plot.setDefaults(stack=stack, weight=staticmethod(weight_), selectionString=cutInterpreter.cutString(args.selection), addOverFlowBin='upper') # Import plots list (AFTER setDefaults!!) plotListFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plotLists', args.plotFile + '.py') if not os.path.isfile(plotListFile): logger.info("Plot file not found: %s", plotListFile) sys.exit(1) plotModule = imp.load_source("plotLists", os.path.expandvars(plotListFile))
# MC samples need to be corrected by certain scale factors to correct e.g. detector effects. Define the "weight" here: mcWeight = lambda event, sample: event.reweightL1Prefire * event.reweightPU * event.reweightLeptonTightSF * event.reweightLeptonTrackingTightSF * event.reweightPhotonSF * event.reweightPhotonElectronVetoSF * event.reweightBTag_SF # a weight for all samples incluuding data is defined here weight = lambda event, sample: event.weight # get some additional cuts specific for MC and/or data # MET Filter cut for data and MC filterCutData = getFilterCut(args.year, isData=True, skipBadChargedCandidate=True) filterCutMc = getFilterCut(args.year, isData=False, skipBadChargedCandidate=True) # Trigger cuts for MC (already applied for Data) tr = TriggerSelector(args.year, singleLepton=True) #single lepton trigger also for DY CR triggerCutMc = tr.getSelection("MC") # Sample definition mc = [ mc_samples.TTG, mc_samples.TT_pow, mc_samples.DY_LO, mc_samples.WJets, mc_samples.WG, mc_samples.ZG, mc_samples.rest ] ttg = mc_samples.TTG if args.noData: # Scale the histograms by the luminosity taken by CMS in each year if args.year == 2016: lumi_scale = 35.92 elif args.year == 2017: lumi_scale = 41.53 elif args.year == 2018: lumi_scale = 59.74 # add all samples to the Stack
# sample.weight = lambda event, sample: event.reweightDilepTriggerBackup # sample.weight = lambda event, sample: event.reweightPU36fb # sample.weight = lambda event, sample: event.reweightLeptonSF # sample.weight = lambda event, sample: event.reweightLeptonTrackingSF # sample.weight = lambda event, sample: event.reweightPhotonSF # sample.weight = lambda event, sample: event.reweightPhotonElectronVetoSF # sample.weight = lambda event, sample: event.reweightBTag_SF if args.small: for sample in stack.samples: sample.normalization = 1. sample.reduceFiles(factor=5) sample.scale /= sample.normalization weight_ = lambda event, sample: event.weight tr = TriggerSelector(2017) # Use some defaults (set defaults before you create/import list of Plots!!) Plot.setDefaults(stack=stack, weight=staticmethod(weight_), selectionString=cutInterpreter.cutString(args.selection), addOverFlowBin='upper') # Import plots list (AFTER setDefaults!!) plotListFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plotLists', args.plotFile + '.py') if not os.path.isfile(plotListFile): logger.info("Plot file not found: %s", plotListFile) sys.exit(1) plotModule = imp.load_source("plotLists", os.path.expandvars(plotListFile))
# sample.weight = lambda event, sample: event.reweightDilepTriggerBackup # sample.weight = lambda event, sample: event.reweightPU36fb # sample.weight = lambda event, sample: event.reweightLeptonSF # sample.weight = lambda event, sample: event.reweightLeptonTrackingSF # sample.weight = lambda event, sample: event.reweightPhotonSF # sample.weight = lambda event, sample: event.reweightPhotonElectronVetoSF # sample.weight = lambda event, sample: event.reweightBTag_SF if args.small: for sample in stack.samples: sample.normalization = 1. sample.reduceFiles(factor=15) sample.scale /= sample.normalization weight_ = lambda event, sample: event.weight tr = TriggerSelector(2016) # Use some defaults (set defaults before you create/import list of Plots!!) Plot.setDefaults(stack=stack, weight=staticmethod(weight_), selectionString=cutInterpreter.cutString(args.selection), addOverFlowBin='upper') # Import plots list (AFTER setDefaults!!) plotListFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plotLists', args.plotFile + '.py') if not os.path.isfile(plotListFile): logger.info("Plot file not found: %s", plotListFile) sys.exit(1) plotModule = imp.load_source("plotLists", os.path.expandvars(plotListFile))
stack = Stack([Run2017], Run2017_noPreFiring) Run2017.texName = "data" Run2017.name = "data" Run2017.style = styles.errorStyle( ROOT.kBlue) #styles.fillStyle( ROOT.kOrange-3 ) Run2017.scale = 1 if args.small: for sample in stack.samples: sample.normalization = 1. sample.reduceFiles(factor=50) sample.scale /= sample.normalization weight_ = lambda event, sample: event.weight tr = TriggerSelector(2017, singleLepton=True) triggerCond = tr.getSelection("SingleMuon") # Use some defaults (set defaults before you create/import list of Plots!!) Plot.setDefaults(stack=stack, weight=staticmethod(weight_), selectionString=cutInterpreter.cutString(args.selection), addOverFlowBin='upper') # Import plots list (AFTER setDefaults!!) plotListFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plotLists', args.plotFile + '.py') if not os.path.isfile(plotListFile): logger.info("Plot file not found: %s", plotListFile) sys.exit(1)
# Loop over channels if args.mode != "None": allModes = [args.mode] elif args.nJobs != 1: allModes = ['mumu', 'mue', 'ee', 'SF', 'all' ] if "dilep" in args.selection else ["mu", "e", "all"] allModes = splitList(allModes, args.nJobs)[args.job] else: allModes = ['mumu', 'mue', 'ee' ] if "dilep" in args.selection else ["mu", "e"] filterCutMc = getFilterCut(args.year, isData=False, skipBadChargedCandidate=True) tr = TriggerSelector(args.year, singleLepton=True) triggerCutMc = tr.getSelection("MC") for index, mode in enumerate(allModes): logger.info("Computing plots for mode %s", mode) # always initialize with [], elso you get in trouble with pythons references! plots = [] # plots += plotList # plots += [ getYieldPlot( index ) ] plots += addPlots # Define lepton selections leptonSelection = cutInterpreter.cutString(mode) mcSelection = [ filterCutMc, leptonSelection, triggerCutMc, "pTStitching==1",
allPlots = {} if args.mode != "None": allModes = [args.mode] elif args.nJobs != 1: allModes = ['mumu', 'mue', 'ee', 'SF', 'all'] allModes = splitList(allModes, args.nJobs)[args.job] else: allModes = ['mumu', 'mue', 'ee'] filterCutData = getFilterCut(args.year, isData=True, skipBadChargedCandidate=True) filterCutMc = getFilterCut(args.year, isData=False, skipBadChargedCandidate=True) tr = TriggerSelector(args.year, singleLepton="nLepTight1" in args.selection) triggerCutMc = tr.getSelection("MC") cat_sel0 = ["%s_photonCat==0" % args.categoryPhoton] cat_sel1 = ["%s_photonCat==1" % args.categoryPhoton] cat_sel2 = ["%s_photonCat==2" % args.categoryPhoton] cat_sel3 = ["%s_photonCat==3" % args.categoryPhoton] for index, mode in enumerate(allModes): logger.info("Computing plots for mode %s", mode) yields[mode] = {} # always initialize with [], elso you get in trouble with pythons references! plots = [] plots += plotList