def __init__(self, year): self.year = year if self.year == 2016: ## Electrons e_file = '$CMSSW_BASE/src/TopEFT/Tools/data/leptonSFData/EGamma_Run2016BtoH_passingRECO_Legacy2016.root' e_file_lowEt = '$CMSSW_BASE/src/TopEFT/Tools/data/leptonSFData/EGamma_Run2016BtoH_passingRECO_lowEt_Legacy2016.root' e_key = "EGamma_SF2D" m_file = '$CMSSW_BASE/src/TopEFT/Tools/data/leptonSFData/Muon_Run2016_passingRECO.root' m_key = "ratio_eff_eta3_dr030e030_corr" self.e_sf = getObjFromFile(os.path.expandvars(e_file), e_key) self.e_sf_lowEt = getObjFromFile(os.path.expandvars(e_file_lowEt), e_key) assert self.e_sf, "Could not load ele SF histo %s from file %s." % ( e_key, e_file) assert self.e_sf_lowEt, "Could not load ele SF histo %s from file %s." % ( e_key, e_file_lowEt) self.e_ptMax = self.e_sf.GetYaxis().GetXmax() self.e_ptMin = self.e_sf.GetYaxis().GetXmin() self.e_ptMin_lowEt = self.e_sf_lowEt.GetYaxis().GetXmin() self.e_etaMax = self.e_sf.GetXaxis().GetXmax() self.e_etaMin = self.e_sf.GetXaxis().GetXmin() ## Muons # SFs are 1. https://hypernews.cern.ch/HyperNews/CMS/get/muon/1425/1.html elif self.year == 2017: ## Electrons e_file = '$CMSSW_BASE/src/TopEFT/Tools/data/leptonSFData/EGamma_Run2017BCDEF_passingRECO.root' e_file_lowEt = '$CMSSW_BASE/src/TopEFT/Tools/data/leptonSFData/EGamma_Run2017BCDEF_passingRECO_lowEt.root' e_key = "EGamma_SF2D" self.e_sf = getObjFromFile(os.path.expandvars(e_file), e_key) self.e_sf_lowEt = getObjFromFile(os.path.expandvars(e_file_lowEt), e_key) assert self.e_sf, "Could not load ele SF histo %s from file %s." % ( e_key, e_file) assert self.e_sf_lowEt, "Could not load ele SF histo %s from file %s." % ( e_key, e_file_lowEt) self.e_ptMax = self.e_sf.GetYaxis().GetXmax() self.e_ptMin = self.e_sf.GetYaxis().GetXmin() self.e_ptMin_lowEt = self.e_sf_lowEt.GetYaxis().GetXmin() self.e_etaMax = self.e_sf.GetXaxis().GetXmax() self.e_etaMin = self.e_sf.GetXaxis().GetXmin()
def __init__(self): self.e_sf = getObjFromFile(os.path.expandvars(e_file), e_key) assert self.e_sf, "Could not load ele SF histo %s from file %s." % ( e_key, e_file) self.e_ptMax = self.e_sf.GetYaxis().GetXmax() self.e_ptMin = self.e_sf.GetYaxis().GetXmin() self.e_etaMax = self.e_sf.GetXaxis().GetXmax() self.e_etaMin = self.e_sf.GetXaxis().GetXmin() self.m_sf = getObjFromFile(os.path.expandvars(m_file), m_key) assert self.m_sf, "Could not load muon SF histo %s from file %s." % ( m_key, m_file) self.m_etaMax = self.m_sf.GetXaxis().GetXmax() self.m_etaMin = self.m_sf.GetXaxis().GetXmin()
def __init__(self, name, sample, setup, cacheDir=None): super(FakeEstimate, self).__init__(name, cacheDir=cacheDir) self.sample = sample self.dataMC = "Data" if sample.isData else "MC" self.magicNumber = 0.85 if sample.isData: if setup.year == 2017: muFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/fakerate_mu_data_2017.root" ) elFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/fakerate_el_data_2017.root" ) elif setup.year == 2016: muFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/fakerate_mu_data_2016.root" ) elFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/fakerate_el_data_2016.root" ) else: raise NotImplementedError else: if setup.year == 2017: # FR maps from ttbar MC muFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/muFR_all.root") elFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/elFR_all.root") elif setup.year == 2016: # this should be another root file muFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/muFR_all.root") elFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/elFR_all.root") else: raise NotImplementedError self.muMap = getObjFromFile(muFile, "passed") self.elMap = getObjFromFile(elFile, "passed")
def getReweightingFunction(data="PU_2100_XSecCentral", mc="Spring15"): # Data fileNameData = "$CMSSW_BASE/src/TopEFT/Tools/data/puReweightingData/%s.root" % data histoData = getObjFromFile(fileNameData, 'pileup') histoData.Scale(1. / histoData.Integral()) logger.info("Loaded 'pileup' from data file %s", fileNameData) # MC #if mc=='Spring15': # from TopEFT.Tools.puProfiles import spring15 as mcProfile # logger.info("Loaded Spring15 MC Profile" ) #elif mc=="Fall15": # mcProfile = extendHistoTo(getObjFromFile("$CMSSW_BASE/src/TopEFT/Tools/data/puReweightingData/MCProfile_Fall15.root", 'MC'), histoData) #elif mc=='Spring16': # mcProfile = extendHistoTo(getObjFromFile("$CMSSW_BASE/src/TopEFT/Tools/data/puReweightingData/MCProfile_Spring16.root", 'MC'), histoData) if mc == 'Summer16': mcProfile = extendHistoTo( getObjFromFile( "$CMSSW_BASE/src/TopEFT/Tools/data/puReweightingData/MCProfile_Summer16.root", 'pileup'), histoData) else: raise ValueError("Don't know about MC PU profile %s" % mc) mcProfile.Scale(1. / mcProfile.Integral()) # Create reweighting histo reweightingHisto = histoData.Clone('_'.join(['reweightingHisto', data, mc])) reweightingHisto.Divide(mcProfile) # Define reweightingFunc def reweightingFunc(nvtx): return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nvtx)) return reweightingFunc
def __init__(self, year, ID = None): self.dataDir = "$CMSSW_BASE/src/TopEFT/Tools/data/leptonSFData" self.year = year if not ID in maps_ele[year].keys(): raise Exception("Don't know ID %s"%ID) self.mu = [getObjFromFile(os.path.expandvars(os.path.join(self.dataDir, file)), key) for (file, key) in maps_mu[year][ID]] self.mu_stat = [getObjFromFile(os.path.expandvars(os.path.join(self.dataDir, file)), key+'_stat') for (file, key) in maps_mu[year][ID]] self.mu_sys = [getObjFromFile(os.path.expandvars(os.path.join(self.dataDir, file)), key+'_sys') for (file, key) in maps_mu[year][ID]] self.ele = [getObjFromFile(os.path.expandvars(os.path.join(self.dataDir, file)), key) for (file, key) in maps_ele[year][ID]] self.ele_stat = [getObjFromFile(os.path.expandvars(os.path.join(self.dataDir, file)), key+'_stat') for (file, key) in maps_ele[year][ID]] self.ele_sys = [getObjFromFile(os.path.expandvars(os.path.join(self.dataDir, file)), key+'_sys') for (file, key) in maps_ele[year][ID]] for effMap in self.mu + self.ele: assert effMap
else: presel = 'nLeptons_FO_3l==3&&lep_pt[0]>40&&lep_pt[1]>20&&lep_pt[2]>10&&abs(Z_mass-91.2)<10' # loop over 3 leptons. Too tired to think of something nicer if options.channel == "dilep": ran = range(2) else: ran = range(3) ran = range(3) for i in ran: if options.Run2017: if options.channel == "dilep": MC = TTW_17 DataCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/MET_Run2017/turnOn_3l_MET_HTMHT_JetHT_altBinning_ttWSel/%s/lep_pt[%s]_MET_Run2017_comp.root" % (options.flavor, i), "can") MCCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/TTLep_pow_17/turnOn_3l_MET_HTMHT_JetHT_altBinning_ttWSel/%s/lep_pt[%s]_TTLep_pow_17_comp.root" % (options.flavor, i), "can") else: MC = TTZtoLLNuNu_17 DataCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/MET_Run2017/turnOn_3l_MET_HTMHT_JetHT_altBinning/3pl/lep_pt[%s]_MET_Run2017_comp.root" % i, "can") MCCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/TTZtoLLNuNu_17/turnOn_3l_MET_HTMHT_JetHT_altBinning/3pl/lep_pt[%s]_TTZtoLLNuNu_17_comp.root" % i, "can") #DataCanvas = getObjFromFile("/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/MET_Run2017/turnOn_3l_MET_HTMHT_JetHT_altBinning/3pl/nGoodElectrons_MET_Run2017_comp.root", "can") #MCCanvas = getObjFromFile("/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/TTZtoLLNuNu_17/turnOn_3l_MET_HTMHT_JetHT_altBinning_SF/3pl/nGoodElectrons_TTZtoLLNuNu_17_comp.root", "can")
def __init__(self, with_backup_triggers=False): if not with_backup_triggers: self.mumu_highEta = getObjFromFile( os.path.expandvars(mumu_trigger_SF), "eff_pt1_pt2_highEta1_veryCoarse") self.mumu_lowEta = getObjFromFile( os.path.expandvars(mumu_trigger_SF), "eff_pt1_pt2_lowEta1_veryCoarse") self.ee_highEta = getObjFromFile( os.path.expandvars(ee_trigger_SF), "eff_pt1_pt2_highEta1_veryCoarse") self.ee_lowEta = getObjFromFile(os.path.expandvars(ee_trigger_SF), "eff_pt1_pt2_lowEta1_veryCoarse") self.mue_highEta = getObjFromFile( os.path.expandvars(mue_trigger_SF), "eff_pt1_pt2_highEta1_veryCoarse") self.mue_lowEta = getObjFromFile( os.path.expandvars(mue_trigger_SF), "eff_pt1_pt2_lowEta1_veryCoarse") else: self.mumu_highEta = getObjFromFile( os.path.expandvars(mumu_trigger_SF_with_backup), "eff_pt1_pt2_highEta1_veryCoarse") self.mumu_lowEta = getObjFromFile( os.path.expandvars(mumu_trigger_SF_with_backup), "eff_pt1_pt2_lowEta1_veryCoarse") self.ee_highEta = getObjFromFile( os.path.expandvars(ee_trigger_SF_with_backup), "eff_pt1_pt2_highEta1_veryCoarse") self.ee_lowEta = getObjFromFile( os.path.expandvars(ee_trigger_SF_with_backup), "eff_pt1_pt2_lowEta1_veryCoarse") self.mue_highEta = getObjFromFile( os.path.expandvars(mue_trigger_SF_with_backup), "eff_pt1_pt2_highEta1_veryCoarse") self.mue_lowEta = getObjFromFile( os.path.expandvars(mue_trigger_SF_with_backup), "eff_pt1_pt2_lowEta1_veryCoarse") h_ = [ self.mumu_highEta, self.mumu_lowEta, self.ee_highEta, self.ee_lowEta, self.mue_highEta, self.mue_lowEta ] assert False not in [bool(x) for x in h_], "Could not load trigger SF: %r" % h_ self.ptMax = self.mumu_highEta.GetXaxis().GetXmax()
#for m in ["MET_Run2017", "MET_Run2016", "WJets", "WJets_LO"]: for m in ["SL_Run2017", "tt_Summer17"]: efficiencies[c][m] = {} for t in triggers: #efficiencies[c][m][t] = getObjFromFile("/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/MET_1l/efficiencies2D/1%s/%s_%s.root"%(c,m,t), "eff") if m == "SL_Run2017" and c == "e": effDir, effFile = "SingleMuon_Run2017", "singleElectron_lep_pt_vs_lep_eta" if m == "SL_Run2017" and c == "mu": effDir, effFile = "SingleElectron_Run2017", "singleMuon_lep_pt_vs_lep_eta" if m == "tt_Summer17" and c == "e": effDir, effFile = "TT_pow_17", "singleElectron_lep_pt_vs_lep_eta" if m == "tt_Summer17" and c == "mu": effDir, effFile = "TT_pow_17", "singleMuon_lep_pt_vs_lep_eta" efficiencies[c][m][t] = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger_TnP_2017/%s/%s.root" % (effDir, effFile), "eff") def getEfficiency(pt, eta, pdgId, trigger, measurement): if abs(pdgId) == 11: eff_map = efficiencies['e'][measurement][trigger] elif abs(pdgId) == 13: eff_map = efficiencies['mu'][measurement][trigger] else: raise (NotImplementedError, "Don't know what to do with pdgId %s" % pdgId) return eff_map.GetBinContent(eff_map.GetXaxis().FindBin(pt), eff_map.GetYaxis().FindBin(abs(eta)))
else: presel = 'nLeptons_FO_3l==3&&lep_pt[0]>40&&lep_pt[1]>20&&lep_pt[2]>10&&abs(Z_mass-91.2)<10' # loop over 3 leptons. Too tired to think of something nicer if options.channel == "dilep": ran = range(2) else: ran = range(3) ran = range(1) for i in ran: if options.Run2017: if options.channel == "dilep": MC = TTW_17 DataCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/MET_Run2017/turnOn_3l_MET_HTMHT_JetHT_altBinning_ttWSel/%s/lep_pt[%s]_MET_Run2017_comp.root" % (options.flavor, i), "can") MCCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/TTLep_pow_17/turnOn_3l_MET_HTMHT_JetHT_altBinning_ttWSel/%s/lep_pt[%s]_TTLep_pow_17_comp.root" % (options.flavor, i), "can") else: MC = TTZtoLLNuNu_17 #DataCanvas = getObjFromFile("/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/MET_Run2017/turnOn_3l_MET_HTMHT_JetHT_altBinning_updateFO/3pl/lep_pt[%s]_MET_Run2017_comp.root"%i, "can") #MCCanvas = getObjFromFile("/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/TTLep_pow_17/turnOn_3l_MET_HTMHT_JetHT_altBinning_updateFO/3pl/lep_pt[%s]_TTLep_pow_17_comp.root"%i, "can") DataCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/MET_Run2017/turnOn_3l_MET_HTMHT_JetHT_altBinning_updateFO/3pl/nElectrons_FO_3l_MET_Run2017_comp.root", "can") MCCanvas = getObjFromFile( "/afs/hephy.at/user/d/dspitzbart/www/TopEFT/trigger/TTLep_pow_17/turnOn_3l_MET_HTMHT_JetHT_altBinning_updateFO/3pl/nElectrons_FO_3l_TTLep_pow_17_comp.root", "can")
else: weights = [getattr(reader.event, w) for w in allweights] weight = reduce(mul, weights, 1) hists["lep_pt_trail"].Fill(lep[2]['pt'], (weight * 41.2)) for var in plotvars: hists_pred[var] = hists[var].Clone() hists_pred[var].Reset() # Get the nonprompt prediction muFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/muFR_all.root") elFile = os.path.expandvars( "$CMSSW_BASE/src/TopEFT/Tools/data/FRData/elFR_all.root") muMap = getObjFromFile(muFile, "passed") elMap = getObjFromFile(elFile, "passed") sample.setSelectionString(np_sel_string) reader = sample.treeReader(variables=variables) reader.start() while reader.run(): nLep = len([l for l in reader.event.lep_pt if l > 0]) lep = [ getObjDict(reader.event, "lep" + '_', [ "pt", "ptCorr", "eta", "phi", "FO_3l", "FO_SS", "tight_3l", "tight_SS", "pdgId", "jetPtRatiov2" ], i) for i in range(nLep) ] # get the relevant leptons