# 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 stack = Stack(mc) else: # Data Sample definition # define the name on the plot postFix = " (%s)" % args.mode.replace("mu", "#mu").replace("all", "e+#mu") data_sample.texName = "data" + postFix data_sample.name = "data" # add here variables that should be read only for Data samples data_sample.read_variables = read_variables_Data # set additional cuts specific for data data_sample.setSelectionString([filterCutData, "triggered==1"]) # change the style of the data sample (dots with error bars) data_sample.style = styles.errorStyle(ROOT.kBlack) # you can scale the histograms of each sample by defining sample.scale (don't scale data) data_sample.scale = 1 # Scale the MC histograms by the luminosity taken by CMS in each year lumi_scale = data_sample.lumi * 0.001 # add all samples to the Stack stack = Stack(mc, data_sample) # settings for MC Samples for sample in mc: # add here variables that should be read only for MC samples sample.read_variables = read_variables_MC # set additional cuts specific for MC # overlapremoval for separating samples with and without a photon (e.g. ttbar from ttgamma)
# Sample definition os.environ["gammaSkim"] = "False" #always false for QCD estimate if args.year == 2016: from TTGammaEFT.Samples.nanoTuples_Run2016_14Dec2018_semilep_postProcessed import Run2016 as data_sample elif args.year == 2017: from TTGammaEFT.Samples.nanoTuples_Run2017_14Dec2018_semilep_postProcessed import Run2017 as data_sample elif args.year == 2018: from TTGammaEFT.Samples.nanoTuples_Run2018_14Dec2018_semilep_postProcessed import Run2018 as data_sample elif args.year == "RunII": from TTGammaEFT.Samples.nanoTuples_RunII_postProcessed import RunII as data_sample filterCutData = getFilterCut(args.year, isData=True, skipBadChargedCandidate=True) data_sample.setSelectionString([filterCutData, "reweightHEM>0"]) data_sample.setWeightString("weight") lumi_scale = data_sample.lumi * 0.001 replaceSelection = { # "nLeptonVetoIsoCorr": "nLeptonVetoNoIso", "nLeptonTight": "nLeptonTightInvIso", "nMuonTight": "nMuonTightInvIso", "nElectronTight": "nElectronTightInvIso", "mLtight0Gamma": "mLinvtight0Gamma", "nPhotonGood": "nPhotonGoodInvLepIso", "nJetGood": "nJetGoodInvLepIso", "nBTagGood": "nBTagGoodInvLepIso", "mT": "mTinv", "m3": "m3inv", "LeptonTight0": "LeptonTightInvIso0",
# add all samples to the Stack stack = Stack(mc) else: # Data Sample definition # mc samples are defined in TTGammaEFT/Samples/python/nanoTuples_Run201X_14Dec2018_semilep_postProcessed.py if args.year == 2016: data_sample = Run2016 elif args.year == 2017: data_sample = Run2017 elif args.year == 2018: data_sample = Run2018 # define the name on the plot postFix = " (%s)" % args.mode.replace("mu", "#mu").replace("all", "e+#mu") data_sample.texName = "data" + postFix data_sample.name = "data" # add here variables that should be read only for Data samples data_sample.read_variables = read_variables_Data # set additional cuts specific for data data_sample.setSelectionString([filterCutData]) # change the style of the data sample (dots with error bars) data_sample.style = styles.errorStyle(ROOT.kBlack) # you can scale the histograms of each sample by defining sample.scale (don't scale data) data_sample.scale = 1 # Scale the MC histograms by the luminosity taken by CMS in each year lumi_scale = data_sample.lumi * 0.001 # add all samples to the Stack stack = Stack(mc, data_sample) # settings for MC Samples for sample in mc: # add here variables that should be read only for MC samples sample.read_variables = read_variables_MC # set additional cuts specific for MC # overlapremoval for separating samples with and without a photon (e.g. ttbar from ttgamma)
"nPhotonGood": "nPhotonGoodInvLepIso", "LeptonTightNoSieie0": "LeptonTightInvIsoNoSieie0", } filterCutData = getFilterCut(args.year, isData=True, skipBadChargedCandidate=True) filterCutMc = getFilterCut(args.year, isData=False, skipBadChargedCandidate=True) blinding = [] if args.year != 2016 and args.blind: blinding += [cutInterpreter.cutString("highSieieLep")] data_sample.setSelectionString([filterCutData, "reweightHEM>0"] + blinding) data_sample.setWeightString("weight") if args.small: data_sample.normalization = 1. data_sample.reduceFiles(factor=5) data_sample.setWeightString("weight*%f" % (1. / data_sample.normalization)) for s in mc: s.setSelectionString([filterCutMc, "pTStitching==1", "overlapRemoval==1"]) s.read_variables = read_variables_MC sampleWeight = "1" if args.small: s.normalization = 1. s.reduceFiles(factor=100) sampleWeight = "%f" % (1. / s.normalization)
ws17 = "+(%s*(PhotonNoChgIsoNoSieie0_photonCatMagic==2)*(%f-1)*(year==2017))" %(ws, misIDSF_val[2017].val) ws18 = "+(%s*(PhotonNoChgIsoNoSieie0_photonCatMagic==2)*(%f-1)*(year==2018))" %(ws, misIDSF_val[2018].val) #weightStringAR = ws + ws16 + ws17 + ws18 weightStringAR = ws wsInv = "(%s*weight*reweightHEM*reweightInvIsoTrigger*reweightL1Prefire*reweightPU*reweightLeptonTightSFInvIso*reweightLeptonTrackingTightSFInvIso*reweightPhotonSF*reweightPhotonElectronVetoSF*reweightBTag_SF)"%lumiString wsInv16 = "+(%s*(PhotonNoChgIsoNoSieieInvLepIso0_photonCatMagic==2)*(%f-1)*(year==2016))" %(wsInv, misIDSF_val[2016].val) wsInv17 = "+(%s*(PhotonNoChgIsoNoSieieInvLepIso0_photonCatMagic==2)*(%f-1)*(year==2017))" %(wsInv, misIDSF_val[2017].val) wsInv18 = "+(%s*(PhotonNoChgIsoNoSieieInvLepIso0_photonCatMagic==2)*(%f-1)*(year==2018))" %(wsInv, misIDSF_val[2018].val) #weightStringInv = wsInv + wsInv16 + wsInv17 + wsInv18 weightStringInv = wsInv filterCutData = getFilterCut( args.year, isData=True, skipBadChargedCandidate=True ) filterCutMc = getFilterCut( args.year, isData=False, skipBadChargedCandidate=True ) data_sample.setSelectionString( [filterCutData, "reweightHEM>0"] ) data_sample.setWeightString( "weight" ) for s in mc: s.setSelectionString( [ filterCutMc, "pTStitching==1", "overlapRemoval==1" ] ) s.read_variables = read_variables_MC sampleWeight = "1" photonRegion = False bjetRegion = False # get selection cuts regionPlot = False if len(args.selection.split("-")) == 1 and args.selection in allRegions.keys(): print( "Plotting region from SetupHelpers: %s"%args.selection ) regionPlot = True
wsInv17 = "+(%s*(PhotonNoChgIsoNoSieie0_photonCatMagic==2)*(%f-1)*(year==2017))" % ( wsInv, misIDSF_val[2017].val) wsInv18 = "+(%s*(PhotonNoChgIsoNoSieie0_photonCatMagic==2)*(%f-1)*(year==2018))" % ( wsInv, misIDSF_val[2018].val) weightStringInv = wsInv + wsInv16 + wsInv17 + wsInv18 filterCutData = getFilterCut(args.year, isData=True, skipBadChargedCandidate=True) filterCutMc = getFilterCut(args.year, isData=False, skipBadChargedCandidate=True) #tr = TriggerSelector( args.year, singleLepton=True ) #triggerCutMc = tr.getSelection( "MC" ) data_sample.setSelectionString([filterCutData, "reweightHEM>0"]) data_sample.setWeightString("weight") if args.small: data_sample.normalization = 1. data_sample.reduceFiles(factor=5) data_sample.setWeightString("weight*%f" % (1. / data_sample.normalization)) for s in mc: s.setSelectionString([filterCutMc, "pTStitching==1", "overlapRemoval==1"]) s.read_variables = read_variables_MC sampleWeight = "1" if args.small: s.normalization = 1. s.reduceFiles(factor=100) sampleWeight = "%f" % (1. / s.normalization)
if True: filterCut = getFilterCut(args.year, isData=True, skipBadChargedCandidate=True, skipVertexFilter=False) selection = "&&".join( [cutInterpreter.cutString(args.selection), filterCut, "triggered==1"]) print selection # Define a reader r = sample.treeReader( \ variables = [ TreeVariable.fromString("event/l"), TreeVariable.fromString('run/i'), TreeVariable.fromString('luminosityBlock/i') ], selectionString = selection, ) r.start() selection = args.selection allEvents = [] while r.run(): run, lumi, evt = r.event.run, r.event.luminosityBlock, r.event.event allEvents += [(run, lumi, evt)] filepath = "logs/overlapCheck_%i_EventList_%s.dat" % (args.year, selection) with open(filepath, "w") as f: for run, lumi, evt in allEvents:
logger.info("Computing plots for mode %s", mode) yields[mode] = {} # always initialize with [], elso you get in trouble with pythons references! plots = [] plots += addPlots # Define 2l selections leptonSelection = cutInterpreter.cutString(mode) if args.sideband == "chgIso": data_sample.texName = "data (%s) chg Iso fit region" % mode.replace( "mu", "#mu").replace("all", "e+#mu") data_sample.setSelectionString([ cutInterpreter.cutString("lowChgIsoNoSieie"), filterCutData, leptonSelection, "triggered==1" ]) mc_fit.setSelectionString( [cutInterpreter.cutString("lowChgIsoNoSieie"), leptonSelection] + mcSelection) mc_sb.setSelectionString( [cutInterpreter.cutString("highChgIsoNoSieie"), leptonSelection] + mcSelection) elif args.sideband == "sieie": data_sample.texName = "data (%s) #sigma_{i#eta i#eta} fit region" % mode.replace( "mu", "#mu").replace("all", "e+#mu") data_sample.setSelectionString([ cutInterpreter.cutString("lowSieieNoChgIso"), filterCutData, leptonSelection, "triggered==1" ]) mc_fit.setSelectionString(