Esempio n. 1
0
def goodMuID_POG(c, imu):
    # POG MU Tight
    #  return getVarValue(c, 'muonsPt', imu)>20. and getVarValue(c, 'muonsisPF', imu) and getVarValue(c, 'muonsisGlobal', imu) and abs(getVarValue(c, 'muonsEta', imu)) < 2.4  and getVarValue(c, 'muonsPFRelIso', imu)<0.20 and getVarValue(c, 'muonsNormChi2', imu)<10. and getVarValue(c, 'muonsNValMuonHits', imu)>0 and getVarValue(c, 'muonsNumMatchedStadions', imu) > 1 and getVarValue(c, 'muonsPixelHits', imu) > 0 and getVarValue(c, 'muonsNumtrackerLayerWithMeasurement', imu) > 5 and getVarValue(c, 'muonsDxy', imu) < 0.2 and getVarValue(c, 'muonsDz', imu) < 0.5
    # POG MU Loose
    return getVarValue(c, 'muonsisPF', imu) and (getVarValue(
        c, 'muonsisGlobal', imu) or getVarValue(
            c, 'muonsisTracker', imu)) and getVarValue(c, 'muonsPt', imu) > 5.
Esempio n. 2
0
def getAllTaus(c, ntaus ):
  res=[]
  for i in range(0, int(ntaus)):
    if goodTauID_POG(c, i):
      res.append({'pt':getVarValue(c, 'tausPt', i),'eta':getVarValue(c, 'tausEta', i), 'phi':getVarValue(c, 'tausPhi', i),\
      'pdg':getVarValue(c, 'tausPdg', i)})
  res = sorted(res, key=lambda k: -k['pt'])
  return res
def getAllTaus(c, ntaus ):
  res=[]
  for i in range(0, int(ntaus)):
    if goodTauID_POG(c, i):
      res.append({'pt':getVarValue(c, 'tausPt', i),'eta':getVarValue(c, 'tausEta', i), 'phi':getVarValue(c, 'tausPhi', i),\
      'pdg':getVarValue(c, 'tausPdg', i)})
  res = sorted(res, key=lambda k: -k['pt'])
  return res
Esempio n. 4
0
def getSoftGenMuon(c):
    for igp in range(int(getVarValue(c, "ngp"))):
        pdg = getVarValue(c, "gpPdg", igp)
        if abs(pdg) == 13:
            pt = getVarValue(c, "gpPt", igp)
            if pt > 5 and pt < 20:
                eta = getVarValue(c, "gpEta", igp)
                if abs(eta) < 2.1:
                    phi = getVarValue(c, "gpPhi", igp)
                    return {"pt": pt, "eta": eta, "phi": phi, "pdg": pdg}
Esempio n. 5
0
def getSoftGenElectron(c):
    for igp in range(int(getVarValue(c, 'ngp'))):
        pdg = getVarValue(c, 'gpPdg', igp)
        if abs(pdg) == 11:
            pt = getVarValue(c, 'gpPt', igp)
            if pt > 5 and pt < 20:
                eta = getVarValue(c, 'gpEta', igp)
                if abs(eta) < 2.1:
                    phi = getVarValue(c, 'gpPhi', igp)
                    return {'pt': pt, 'eta': eta, 'phi': phi, 'pdg': pdg}
Esempio n. 6
0
def goodMuID(c, imu ):  
  isPF = getVarValue(c, 'muonsisPF', imu)
  isGlobal = getVarValue(c, 'muonsisGlobal', imu)
  isTracker = getVarValue(c, 'muonsisTracker', imu)
  pt = getVarValue(c, 'muonsPt', imu)
  dz = getVarValue(c, 'muonsDz', imu)
  eta=getVarValue(c, 'muonsEta', imu)
  relIso=getVarValue(c, 'muonsPFRelIso', imu)
  if isPF and (isGlobal or isTracker) and pt>20. and abs(eta)<2.1 and abs(dz)<0.5 and relIso<0.2:
    return {'pt':pt, 'phi':getVarValue(c, 'muonsPhi', imu), 'eta':eta, 'IsGlobal':isGlobal, 'IsTracker':isTracker, 'IsPF':isPF, 'relIso':getVarValue(c, 'muonsPFRelIso', imu), 'Dz':dz} 
Esempio n. 7
0
def getSoftMuon(c):
    for imu in reversed(range(int(getVarValue(c, "nmuCount")))):
        relIso = getVarValue(c, "muRelIso", imu)
        pt = getVarValue(c, "muPt", imu)
        isGlobal = getVarValue(c, "muIsGlobal", imu)
        isTracker = getVarValue(c, "muIsTracker", imu)
        dz = getVarValue(c, "muDz", imu)
        eta = getVarValue(c, "muEta", imu)
        if (isGlobal or isTracker) and pt > 5.0 and abs(eta) < 2.1 and abs(dz) < 0.5:
            if pt < 20.0 and pt * relIso < 10:
                return {"pt": pt, "eta": eta, "phi": getVarValue(c, "muPhi", imu), "pdg": getVarValue(c, "muPdg", imu)}
Esempio n. 8
0
def getSoftMuon(c):
    for imu in reversed(range(int(getVarValue(c, 'nmuCount')))):
        relIso = getVarValue(c, 'muRelIso', imu)
        pt = getVarValue(c, 'muPt', imu)
        isGlobal = getVarValue(c, 'muIsGlobal', imu)
        isTracker = getVarValue(c, 'muIsTracker', imu)
        dz = getVarValue(c, 'muDz', imu)
        eta = getVarValue(c, 'muEta', imu)
        if (isGlobal
                or isTracker) and pt > 5. and abs(eta) < 2.1 and abs(dz) < 0.5:
            if (pt < 20. and pt * relIso < 10):
                return {
                    'pt': pt,
                    'eta': eta,
                    'phi': getVarValue(c, 'muPhi', imu),
                    'pdg': getVarValue(c, 'muPdg', imu)
                }
Esempio n. 9
0
def getAllElectrons(c, neles ):
  res=[]
  for i in range(0, int(neles)):
    eta = getVarValue(c, 'elesEta', i)
    if goodEleID(c, i, abs(eta)):
      res.append({'pt':getVarValue(c, 'elesPt', i),'eta':eta, 'phi':getVarValue(c, 'elesPhi', i),\
      'pdg':getVarValue(c, 'elesPdg', i), 'relIso':getVarValue(c, 'elesPfRelIso', i),\
      'dxy':getVarValue(c, 'elesDxy', i), 'dz':getVarValue(c, 'elesDz', i)} )
  res = sorted(res, key=lambda k: -k['pt'])
  return res
def getAllElectrons(c, neles ):
  res=[]
  for i in range(0, int(neles)):
    eta = getVarValue(c, 'elesEta', i)
    if goodEleID_POG(c, i, abs(eta)):
      res.append({'pt':getVarValue(c, 'elesPt', i),'eta':eta, 'phi':getVarValue(c, 'elesPhi', i),\
      'pdg':getVarValue(c, 'elesPdg', i), 'relIso':getVarValue(c, 'elesPfRelIso', i),\
      'dxy':getVarValue(c, 'elesDxy', i), 'dz':getVarValue(c, 'elesDz', i)} )
  res = sorted(res, key=lambda k: -k['pt'])
  return res
def goodTauID_POG(c, itau ): 
  return getVarValue(c, 'tausisPF', itau) and \
         getVarValue(c, 'tausDecayModeFinding', itau) and \
         getVarValue(c, 'tausAgainstMuonLoose', itau) and \
         getVarValue(c, 'tausAgainstElectronLoose', itau) and \
         getVarValue(c, 'tausByLooseCombinedIsolationDBSumPtCorr', itau) and \
         getVarValue(c, 'tausPt', itau)>5.
Esempio n. 12
0
def goodTauID_POG(c, itau ): 
  return getVarValue(c, 'tausisPF', itau) and \
         getVarValue(c, 'tausDecayModeFinding', itau) and \
         getVarValue(c, 'tausAgainstMuonLoose', itau) and \
         getVarValue(c, 'tausAgainstElectronLoose', itau) and \
         getVarValue(c, 'tausByLooseCombinedIsolationDBSumPtCorr', itau) and \
         getVarValue(c, 'tausPt', itau)>15.
Esempio n. 13
0
def goodEleID_POG(c, iele, eta='none'):  # POG Ele veto
    if eta == 'none':
        eta = getVarValue(c, 'elesEta', iele)
    sietaieta = getVarValue(c, 'elesSigmaIEtaIEta', iele)
    dphi = getVarValue(c, 'elesDPhi', iele)
    deta = getVarValue(c, 'elesDEta', iele)
    HoE = getVarValue(c, 'elesHoE', iele)
    isEB = abs(eta) < 1.4442
    isEE = abs(eta) > 1.566
    relIso = getVarValue(c, 'elesPfRelIso', iele)
    pt = getVarValue(c, 'elesPt', iele)
    relIsoCut = 0.15
    return ( isEE or isEB)\
      and ( relIso < relIsoCut ) and (abs(eta) < 2.5)\
      and ( (isEB and HoE < 0.15 ) or (isEE and HoE < 0.10))\
      and ( (isEB and sietaieta < 0.01 ) or (isEE and sietaieta < 0.03))\
      and ( (isEB and dphi < 0.8) or (isEE and dphi < 0.7)) and ( (isEB and deta < 0.007) or (isEE and deta < 0.01) )\
      and getVarValue(c, 'elesDxy', iele) < 0.04 and getVarValue(c, 'elesDz', iele) < 0.2 and getVarValue(c, 'elesPt', iele)>5.
def goodEleID_POG(c, iele, eta = 'none'): # POG Ele veto
  if eta=='none':
    eta = getVarValue(c, 'elesEta', iele)
  sietaieta = getVarValue(c, 'elesSigmaIEtaIEta', iele)
  dphi = getVarValue(c, 'elesDPhi', iele)
  deta = getVarValue(c, 'elesDEta', iele)
  HoE  = getVarValue(c, 'elesHoE', iele)
  isEB = abs(eta) < 1.4442
  isEE = abs(eta) > 1.566
  relIso = getVarValue(c, 'elesPfRelIso', iele)
  pt = getVarValue(c, 'elesPt', iele)
  relIsoCut = 0.15
  return ( isEE or isEB)\
    and ( relIso < relIsoCut ) and (abs(eta) < 2.5)\
    and ( (isEB and HoE < 0.15 ) or (isEE and HoE < 0.10))\
    and ( (isEB and sietaieta < 0.01 ) or (isEE and sietaieta < 0.03))\
    and ( (isEB and dphi < 0.8) or (isEE and dphi < 0.7)) and ( (isEB and deta < 0.007) or (isEE and deta < 0.01) )\
    and getVarValue(c, 'elesDxy', iele) < 0.04 and getVarValue(c, 'elesDz', iele) < 0.2 and getVarValue(c, 'elesPt', iele)>5.
Esempio n. 15
0
def getAllMuons(c, nmuons ):
  res=[]
  for i in range(0, int(nmuons)):
    cand = goodMuID(c, i)
    if cand:
      for v in ['Pdg', 'Dxy', 'NormChi2', 'NValMuonHits', 'NumMatchedStations', 'PixelHits', 'NumtrackerLayerWithMeasurement']:
        cand[v] = getVarValue(c, 'muons'+v, i)
      res.append(cand)
#      res.append({'pt':getVarValue(c, 'muonsPt', i),'eta':getVarValue(c, 'muonsEta', i), 'phi':getVarValue(c, 'muonsPhi', i),\
#      'pdg':getVarValue(c, 'muonsPdg', i), 'relIso':getVarValue(c, 'muonsPFRelIso', i),\
#      'dxy':getVarValue(c, 'muonsDxy', i), 'dz':getVarValue(c, 'muonsDz', i)})
  res = sorted(res, key=lambda k: -k['pt'])
  return res
def getAllMuons(c, nmuons ):
  res=[]
  for i in range(0, int(nmuons)):
    if goodMuID_POG(c, i):
      res.append({'pt':getVarValue(c, 'muonsPt', i),'eta':getVarValue(c, 'muonsEta', i), 'phi':getVarValue(c, 'muonsPhi', i),\
      'pdg':getVarValue(c, 'muonsPdg', i), 'relIso':getVarValue(c, 'muonsPFRelIso', i),\
      'dxy':getVarValue(c, 'muonsDxy', i), 'dz':getVarValue(c, 'muonsDz', i)})
  res = sorted(res, key=lambda k: -k['pt'])
  return res
Esempio n. 17
0
def getAllMuons(c, nmuons):
    res = []
    for i in range(0, int(nmuons)):
        if goodMuID_POG(c, i):
            res.append({'pt':getVarValue(c, 'muonsPt', i),'eta':getVarValue(c, 'muonsEta', i), 'phi':getVarValue(c, 'muonsPhi', i),\
            'pdg':getVarValue(c, 'muonsPdg', i), 'relIso':getVarValue(c, 'muonsPFRelIso', i),\
            'dxy':getVarValue(c, 'muonsDxy', i), 'dz':getVarValue(c, 'muonsDz', i)})
    res = sorted(res, key=lambda k: -k['pt'])
    return res
Esempio n. 18
0
def goodMuID(c, imu ):  
  # POG MU Tight
  #  return getVarValue(c, 'muonsPt', imu)>20. and getVarValue(c, 'muonsisPF', imu) and getVarValue(c, 'muonsisGlobal', imu) and abs(getVarValue(c, 'muonsEta', imu)) < 2.4  and getVarValue(c, 'muonsPFRelIso', imu)<0.20 and getVarValue(c, 'muonsNormChi2', imu)<10. and getVarValue(c, 'muonsNValMuonHits', imu)>0 and getVarValue(c, 'muonsNumMatchedStadions', imu) > 1 and getVarValue(c, 'muonsPixelHits', imu) > 0 and getVarValue(c, 'muonsNumtrackerLayerWithMeasurement', imu) > 5 and getVarValue(c, 'muonsDxy', imu) < 0.2 and getVarValue(c, 'muonsDz', imu) < 0.5 
  # POG MU Loose
  isPF = getVarValue(c, 'muonsisPF', imu)
  isGlobal = getVarValue(c, 'muonsisGlobal', imu)
  isTracker = getVarValue(c, 'muonsisTracker', imu)
  pt = getVarValue(c, 'muonsPt', imu)
  if isPF and (isGlobal or isTracker) and pt>5.:
    return {'pt':pt, 'phi':getVarValue(c, 'muonsPhi', imu), 'eta':getVarValue(c, 'muonsEta', imu), 'IsGlobal':isGlobal, 'IsTracker':isTracker, 'IsPF':isPF, 'relIso':getVarValue(c, 'muonsPFRelIso', imu)} 
Esempio n. 19
0
def goodMuID(c, imu):
    # POG MU Tight
    #  return getVarValue(c, 'muonsPt', imu)>20. and getVarValue(c, 'muonsisPF', imu) and getVarValue(c, 'muonsisGlobal', imu) and abs(getVarValue(c, 'muonsEta', imu)) < 2.4  and getVarValue(c, 'muonsPFRelIso', imu)<0.20 and getVarValue(c, 'muonsNormChi2', imu)<10. and getVarValue(c, 'muonsNValMuonHits', imu)>0 and getVarValue(c, 'muonsNumMatchedStadions', imu) > 1 and getVarValue(c, 'muonsPixelHits', imu) > 0 and getVarValue(c, 'muonsNumtrackerLayerWithMeasurement', imu) > 5 and getVarValue(c, 'muonsDxy', imu) < 0.2 and getVarValue(c, 'muonsDz', imu) < 0.5
    # POG MU Loose
    isPF = getVarValue(c, 'muonsisPF', imu)
    isGlobal = getVarValue(c, 'muonsisGlobal', imu)
    isTracker = getVarValue(c, 'muonsisTracker', imu)
    pt = getVarValue(c, 'muonsPt', imu)
    if isPF and (isGlobal or isTracker) and pt > 5.:
        return {
            'pt': pt,
            'phi': getVarValue(c, 'muonsPhi', imu),
            'eta': getVarValue(c, 'muonsEta', imu),
            'IsGlobal': isGlobal,
            'IsTracker': isTracker,
            'IsPF': isPF,
            'relIso': getVarValue(c, 'muonsPFRelIso', imu)
        }
Esempio n. 20
0
        eList = ROOT.gDirectory.Get('eList')
        if j == 0:
            y = {}
            ye = {}
        else:
            y = 0
            ye = 0
        for i in range(eList.GetN()):
            #      if not i%10000: print "At",i,"/",eList.GetN()
            c.GetEntry(eList.GetEntry(i))
            #      mu = getSoftMuon(c)
            #      mu = getSoftGenElectron(c)
            #      mu = getSoftGenMuon(c)
            #      print mu
            #      if mu and muRequirement(mu) and pdgSign==mu['pdg']/abs(mu['pdg']):
            pdg_ = getVarValue(c, 'softIsolatedMuPdg')

            if pdgSign * pdg_ > 0 and abs(getVarValue(
                    c, 'softIsolatedMuEta')) < 1.5:
                mT = getVarValue(c, 'softIsolatedMT')
                #        if mT-getVarValue(c, 'softIsolatedMT')>10:
                #          print getVarValue(c,'event'), getVarValue(c,'lumi'), mT-getVarValue(c, 'softIsolatedMT')
                #        if mT>0 and mT<60:
                #        if mT>88:# and mT<60:
                #        if mT>88:# and mT<60:
                if mT > 60 and mT < 88:
                    #          if j==1:
                    #            resc = rescalePartonWeight(c)
                    #            w*=resc
                    if j == 0:
                        w = getVarValue(c, 'puWeight')
    if small: filelist = filelist[:10]
  ####
    for tfile in filelist:
  #      if os.path.isfile(subdirname+tfile) and tfile[-5:] == '.root' and tfile.count('histo') == 1:
        sample['filenames'][bin].append(subdirname+tfile)

    for tfile in sample['filenames'][bin]:
      print sample['name'], prefix+tfile
      c.Add(prefix+tfile)
      d.Add(prefix+tfile)
    nevents = 0
    nruns = d.GetEntries()
    for i in range(0, nruns):
      d.GetEntry(i)
      nevents += getVarValue(d,'uint_EventCounter_runCounts_PAT.obj')
    if not bin.lower().count('run'):
      weight = xsec.xsec[bin]*target_lumi/nevents
    else:
      weight = 1.
    print 'Sample', sample['name'], 'bin', bin, 'n-events',nevents,'weight',weight
    sample["weight"][bin]=weight

if not os.path.isdir(outputDir):
  os.system('mkdir -p '+outputDir)
if not os.path.isdir(outputDir+"/"+chmode):
  os.system("mkdir "+outputDir+"/"+chmode)

nc = 0
for isample, sample in enumerate(allSamples):
  if not os.path.isdir(outputDir+"/"+chmode+"/"+sample["name"]):
Esempio n. 22
0
        eList = ROOT.gDirectory.Get("eList")
        if j == 0:
            y = {}
            ye = {}
        else:
            y = 0
            ye = 0
        for i in range(eList.GetN()):
            #      if not i%10000: print "At",i,"/",eList.GetN()
            c.GetEntry(eList.GetEntry(i))
            #      mu = getSoftMuon(c)
            #      mu = getSoftGenElectron(c)
            #      mu = getSoftGenMuon(c)
            #      print mu
            #      if mu and muRequirement(mu) and pdgSign==mu['pdg']/abs(mu['pdg']):
            pdg_ = getVarValue(c, "softIsolatedMuPdg")

            if pdgSign * pdg_ > 0 and abs(getVarValue(c, "softIsolatedMuEta")) < 1.5:
                mT = getVarValue(c, "softIsolatedMT")
                #        if mT-getVarValue(c, 'softIsolatedMT')>10:
                #          print getVarValue(c,'event'), getVarValue(c,'lumi'), mT-getVarValue(c, 'softIsolatedMT')
                #        if mT>0 and mT<60:
                #        if mT>88:# and mT<60:
                #        if mT>88:# and mT<60:
                if mT > 60 and mT < 88:
                    #          if j==1:
                    #            resc = rescalePartonWeight(c)
                    #            w*=resc
                    if j == 0:
                        w = getVarValue(c, "puWeight")
Esempio n. 23
0
def getJets(c, jetVars=jetVars, jetColl="Jet"):
    return [
        getObjDict(c, jetColl + '_', jetVars, i)
        for i in range(int(getVarValue(c, 'n' + jetColl)))
    ]
Esempio n. 24
0
def getGoodJets(c, crosscleanobjects):
  njets = getVarValue(c, 'nsoftjets')   # jet.pt() > 10.
  res = []
  bres = []
  ht = 0.
  nbtags = 0
  for i in range(int(njets)):
    eta = getVarValue(c, 'jetsEta', i)
    pt  = getVarValue(c, 'jetsPt', i)
    id =  getVarValue(c, 'jetsID', i)
    if abs(eta) <= 4.5 and pt >= 30. and id:
      phi = getVarValue(c, 'jetsPhi', i)
      parton = int(abs(getVarValue(c, 'jetsParton', i)))
      jet = {'pt':pt, 'eta':eta,'phi':phi, 'pdg':parton,\
      'id':id,
      'chef':getVarValue(c, 'jetsChargedHadronEnergyFraction', i), 'nhef':getVarValue(c, 'jetsNeutralHadronEnergyFraction', i),\
      'ceef':getVarValue(c, 'jetsChargedEmEnergyFraction', i), 'neef':getVarValue(c, 'jetsNeutralEmEnergyFraction', i), 'id':id,\
      'hfhef':getVarValue(c, 'jetsHFHadronEnergyFraction', i), 'hfeef':getVarValue(c, 'jetsHFEMEnergyFraction', i),\
      'muef':getVarValue(c, 'jetsMuonEnergyFraction', i), 'elef':getVarValue(c, 'jetsElectronEnergyFraction', i), 'phef':getVarValue(c, 'jetsPhotonEnergyFraction', i),\
      'jetCutBasedPUJetIDFlag':getVarValue(c, 'jetsCutBasedPUJetIDFlag', i),'jetMET53XPUJetIDFlag':getVarValue(c, 'jetsMET53XPUJetIDFlag', i),'jetFull53XPUJetIDFlag':getVarValue(c, 'jetsFull53XPUJetIDFlag', i), 
      'btag': getVarValue(c, 'jetsBtag', i)
      }
      isolated = True
  #      if max([jet['muef'],jet['elef']]) > 0.6 : print jet
      for obj in crosscleanobjects:   #Jet cross-cleaning
        if deltaR(jet, obj) < 0.3:# and  obj['relIso']< relIsoCleaningRequ: #(obj['pt']/jet['pt']) > 0.4:  
          isolated = False
#          print "Cleaned", 'deltaR', deltaR(jet, obj), 'maxfrac', max([jet['muef'],jet['elef']]), 'pt:jet/obj', jet['pt'], obj['pt'], "relIso",  obj['relIso'], 'btag',getVarValue(c, 'jetsBtag', i), "parton", parton
  #          print 'Not this one!', jet, obj, deltaR(jet, obj)
          break
      if  isolated:
        res.append(jet)
  res  = sorted(res,  key=lambda k: -k['pt'])
  return res 
def getGoodJets(c, crosscleanobjects, relIsoCleaningRequ = 0.2):
  njets = getVarValue(c, 'nsoftjets')   # jet.pt() > 10.
  res = []
  bres = []
  ht = 0.
  nbtags = 0
  for i in range(int(njets)):
    eta = getVarValue(c, 'jetsEta', i)
    pt  = getVarValue(c, 'jetsPt', i)
    id  = getVarValue(c, 'jetsID', i)
    if abs(eta) <= 4.5 and pt >= 30. and id:
      phi = getVarValue(c, 'jetsPhi', i)
      parton = int(abs(getVarValue(c, 'jetsParton', i)))
      jet = {'pt':pt, 'eta':eta,'phi':phi, 'pdg':parton,\
  #      'ptUncorr':getVarValue(c, 'jetsPtUncorr', i),\
      'chef':getVarValue(c, 'jetsChargedHadronEnergyFraction', i), 'nhef':getVarValue(c, 'jetsNeutralHadronEnergyFraction', i),\
      'ceef':getVarValue(c, 'jetsChargedEmEnergyFraction', i), 'neef':getVarValue(c, 'jetsNeutralEmEnergyFraction', i), 'id':id,\
      'hfhef':getVarValue(c, 'jetsHFHadronEnergyFraction', i), 'hfeef':getVarValue(c, 'jetsHFEMEnergyFraction', i),\
      'muef':getVarValue(c, 'jetsMuonEnergyFraction', i), 'elef':getVarValue(c, 'jetsElectronEnergyFraction', i), 'phef':getVarValue(c, 'jetsPhotonEnergyFraction', i),\
      'jetCutBasedPUJetIDFlag':getVarValue(c, 'jetsCutBasedPUJetIDFlag', i),'jetMET53XPUJetIDFlag':getVarValue(c, 'jetsMET53XPUJetIDFlag', i),'jetFull53XPUJetIDFlag':getVarValue(c, 'jetsFull53XPUJetIDFlag', i) 
      }
      isolated = True
  #      if max([jet['muef'],jet['elef']]) > 0.6 : print jet
      for obj in crosscleanobjects:   #Jet cross-cleaning
        if deltaR(jet, obj) < 0.3 and  obj['relIso']< relIsoCleaningRequ: #(obj['pt']/jet['pt']) > 0.4:  
          isolated = False
#          print "Cleaned", 'deltaR', deltaR(jet, obj), 'maxfrac', max([jet['muef'],jet['elef']]), 'pt:jet/obj', jet['pt'], obj['pt'], "relIso",  obj['relIso'], 'btag',getVarValue(c, 'jetsBtag', i), "parton", parton
  #          print 'Not this one!', jet, obj, deltaR(jet, obj)
          break
  #      for obj in crosscleanobjects:   #Jet cross-cleaning
      if isolated:
        ht += jet['pt']
        btag = getVarValue(c, 'jetsBtag', i)
        jet['btag'] = btag
        res.append(jet)
        if btag >= 0.679:   # bjets
          bres.append(jet)
          nbtags = nbtags+1
  res  = sorted(res,  key=lambda k: -k['pt'])
  bres = sorted(bres, key=lambda k: -k['pt'])
  return {"jets":res, "bjets":bres,"ht": ht, "nbtags":nbtags}
def getRelevantObjects(c):
  return {'jets':getJets(c), \
          'mu':{'pt':getVarValue(c, 'softIsolatedMuPt'), 'phi':getVarValue(c, 'softIsolatedMuPhi')},
          'met':{'pt':getVarValue(c, 'type1phiMet'), 'phi':getVarValue(c, 'type1phiMetphi')} }
def goodMuID_POG(c, imu ):  
  # POG MU Tight
  #  return getVarValue(c, 'muonsPt', imu)>20. and getVarValue(c, 'muonsisPF', imu) and getVarValue(c, 'muonsisGlobal', imu) and abs(getVarValue(c, 'muonsEta', imu)) < 2.4  and getVarValue(c, 'muonsPFRelIso', imu)<0.20 and getVarValue(c, 'muonsNormChi2', imu)<10. and getVarValue(c, 'muonsNValMuonHits', imu)>0 and getVarValue(c, 'muonsNumMatchedStadions', imu) > 1 and getVarValue(c, 'muonsPixelHits', imu) > 0 and getVarValue(c, 'muonsNumtrackerLayerWithMeasurement', imu) > 5 and getVarValue(c, 'muonsDxy', imu) < 0.2 and getVarValue(c, 'muonsDz', imu) < 0.5 
  # POG MU Loose
  return getVarValue(c, 'muonsisPF', imu) and ( getVarValue(c, 'muonsisGlobal', imu) or getVarValue(c, 'muonsisTracker', imu)) and getVarValue(c, 'muonsPt', imu)>5.
Esempio n. 28
0
def goodEleID(c, iele, eta = 'none'): # POG Ele veto https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification
  if eta=='none':
    eta = getVarValue(c, 'elesEta', iele)
  sietaieta = getVarValue(c, 'elesSigmaIEtaIEta', iele)
  dphi = getVarValue(c, 'elesDPhi', iele)
  deta = getVarValue(c, 'elesDEta', iele)
  HoE  = getVarValue(c, 'elesHoE', iele)
  isEB = abs(eta) < 1.479
  isEE = abs(eta) > 1.479 and abs(eta) < 2.5
  relIso = getVarValue(c, 'elesPfRelIso', iele)
  pt = getVarValue(c, 'elesPt', iele)
  relIsoCut = 0.15
  return( isEE or isEB)\
    and ((isEB and dphi < 0.15) or (isEE and dphi < 0.1)) and ( (isEB and deta < 0.007) or (isEE and deta < 0.009) )\
    and ((isEB and sietaieta < 0.01 ) or (isEE and sietaieta < 0.03))\
    and (( isEB and HoE < 0.12 ) or ( isEE and HoE < 0.10 ))\
    and getVarValue(c, 'elesDxy', iele) < 0.02 and getVarValue(c, 'elesDz', iele) < 0.2 \
    and ( relIso < relIsoCut ) \
    and getVarValue(c, 'elesPassConversionRejection', iele)\
    and getVarValue(c, 'elesMissingHits', iele)<=1\
    and getVarValue(c, 'elesPt', iele)>20.
Esempio n. 29
0
def getJets(c, jetVars=jetVars, jetColl="Jet"):
    return [getObjDict(c, jetColl+'_', jetVars, i) for i in range(int(getVarValue(c, 'n'+jetColl)))]
Esempio n. 30
0
        if small: filelist = filelist[:10]
        ####
        for tfile in filelist:
            #      if os.path.isfile(subdirname+tfile) and tfile[-5:] == '.root' and tfile.count('histo') == 1:
            sample['filenames'][bin].append(subdirname + tfile)

        for tfile in sample['filenames'][bin]:
            print sample['name'], prefix + tfile
            c.Add(prefix + tfile)
            d.Add(prefix + tfile)
        nevents = 0
        nruns = d.GetEntries()
        for i in range(0, nruns):
            d.GetEntry(i)
            nevents += getVarValue(d, 'uint_EventCounter_runCounts_PAT.obj')
        if not bin.lower().count('run'):
            weight = xsec.xsec[bin] * target_lumi / nevents
        else:
            weight = 1.
        print 'Sample', sample[
            'name'], 'bin', bin, 'n-events', nevents, 'weight', weight
        sample["weight"][bin] = weight

if not os.path.isdir(outputDir):
    os.system('mkdir -p ' + outputDir)
if not os.path.isdir(outputDir + "/" + chmode):
    os.system("mkdir " + outputDir + "/" + chmode)

nc = 0
for isample, sample in enumerate(allSamples):
Esempio n. 31
0
      elist = ROOT.gDirectory.Get("eList")
      number_events = elist.GetN()
      print "Reading: ", sample["name"], bin, "with",number_events,"Events using cut", commoncf
      if small:
        if number_events>1000:
          number_events=1000
      for i in range(0, number_events):
        if (i%10000 == 0) and i>0 :
          print i
  #      # Update all the Tuples
        if elist.GetN()>0 and ntot>0:
          c.GetEntry(elist.GetEntry(i))
          s.weight = sample["weight"][bin]
          for var in variables[1:]:
            getVar = var
            exec("s."+var+"="+str(getVarValue(c, getVar)).replace("nan","float('nan')"))
          s.event = long(c.GetLeaf(c.GetAlias('event')).GetValue())

          if not sample['name'].lower().count('data'):
            nvtxWeightSysPlus, nvtxWeightSysMinus, nvtxWeight = 1.,1.,1.
            if sample.has_key('reweightingHistoFile'): 
              s.puWeight = s.weight*sample['reweightingHistoFile'].GetBinContent(sample['reweightingHistoFile'].FindBin(s.nTrueGenVertices))
            if sample.has_key('reweightingHistoFileSysPlus'): 
              s.puWeightSysPlus = s.weight*sample['reweightingHistoFileSysPlus'].GetBinContent(sample['reweightingHistoFileSysPlus'].FindBin(s.nTrueGenVertices))
            if sample.has_key('reweightingHistoFileSysMinus'): 
              s.puWeightSysMinus = s.weight*sample['reweightingHistoFileSysMinus'].GetBinContent(sample['reweightingHistoFileSysMinus'].FindBin(s.nTrueGenVertices))


          for var in extraVariables:
            exec("s."+var+"=float('nan')")
          nmuons = getVarValue(c, 'nmuons')   #Number of muons in Muon Vec
Esempio n. 32
0
def getRelevantObjects(c):
    return {'jets':getJets(c), \
            'mu':{'pt':getVarValue(c, 'softIsolatedMuPt'), 'phi':getVarValue(c, 'softIsolatedMuPhi')},
            'met':{'pt':getVarValue(c, 'type1phiMet'), 'phi':getVarValue(c, 'type1phiMetphi')} }