genMet = getVarValue(chain, "met_genPt") genMetPhi = getVarValue(chain, "met_genPhi") deltaMet = sqrt((met * cos(metPhi) - genMet * cos(genMetPhi))**2 + (met * sin(metPhi) - genMet * sin(genMetPhi))**2) jets = filter( lambda j: j['pt'] > 30 and abs(j['eta']) < 2.4 and j['id'], getJets(chain)) allLeptons = getLeptons( chain, collVars=leptonVars + [ 'mcMatchId', 'mcMatchAny', 'mcMatchTau', 'mcPt', 'ip3d', 'relIso03', 'relIso04', 'jetPtRatiov1', 'jetPtRelv1', 'jetPtRelv2', 'jetPtRatiov2', 'jetBTagCSV', 'jetDR' ]) leptons = filter(lambda l: looseMuID(l) or looseEleID(l), allLeptons) #LepGood_mcMatchId Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake for Leptons after the preselection #LepGood_mcMatchAny Match to any final state leptons: 0 if unmatched, 1 if light flavour (including prompt), 4 if charm, 5 if bottom for Leptons after the preselection #LepGood_mcMatchTau True if the leptons comes from a tau for Leptons after the preselection # for l in leptons: # if (l['mcMatchAny']==0 and (not (l['mcMatchId']==0))) or ( (not l['mcMatchAny']==0) and (l['mcMatchId']==0)): # print "Match?",l #RECO looseMu = filter( lambda l: abs(l['pdgId']) == 13 and l['miniRelIso'] < 0.4 and l[ 'pt'] > 15, allLeptons) looseEle = filter( lambda l: abs(l['pdgId']) == 11 and l['miniRelIso'] < 0.4 and l[
isElecElec[0] = 1 if not s["name"].find("DoubleMuon") and triggerMuMu : trigger = 1 isMuonMuon[0] = 1 if not s["name"].find("DoubleMuon") and triggerMuMu==0 : trigger = 0 isMuonMuon[0] = 1 if not s["name"].find("MuonEG") and triggerMuEle : trigger = 1 isMuonElec[0] = 1 if not s["name"].find("MuonEG") and triggerMuEle==0 : trigger = 0 isMuonElec[0] = 1 leptons = filter(lambda l: looseMuID(l) or looseEleID(l), getLeptons(chain)) jets = filter(lambda j:j['pt']>30 and abs(j['eta'])<2.4 and j['id'], getJets(chain)) bjets = filter(lambda j:j['btagCSV']>0.890, jets) nbjets[0] = len(bjets) njets[0] = len(jets) nleptons[0] = len(leptons) Process[:200] = s["name"] HT[0] = sum([j['pt'] for j in jets]) PhiMetJet1 = deltaPhi(metPhi,getVarValue(chain, "Jet_phi",0)) PhiMetJet2 = deltaPhi(metPhi,getVarValue(chain, "Jet_phi",1)) if PhiMetJet1 <= PhiMetJet2: PhiMetJet_small = PhiMetJet1 else: PhiMetJet_small = PhiMetJet2
reader.data.evt) nonId_jets = filter(lambda j: j['pt'] > 30 and not j['id'], getJets(cmg_reader.data)) for j in nonId_jets: logger.info("Non-ID Jet found pt %3.2f eta %3.2f phi %3.2f", j['pt'], j['eta'], j['phi']) # reco leptons all_reco_leps = getGoodAndOtherLeptons(cmg_reader.data, ptCut=10, miniRelIso=999., dz=0.1, dxy=1.) loose_mu = filter(lambda l: abs(l['pdgId']) == 13 and looseMuID(l), all_reco_leps) loose_e = filter(lambda l: abs(l['pdgId']) == 11 and looseEleID(l), all_reco_leps) extra_mu = filter(lambda l: abs(l['pdgId']) == 13 and not looseMuID(l), all_reco_leps) extra_e = filter(lambda l: abs(l['pdgId']) == 11 and not looseEleID(l), all_reco_leps) reco_mode = "unknown" if reader.data.isMuMu: reco_mode = "MuMu" if reader.data.isEE: reco_mode = "EE" if reader.data.isEMu:
cmg_reader.goToPosition( cmg_positions[event] ) # Make sure alignement of trees is OK assert reader.data.met_pt == cmg_reader.data.met_pt, "Events inconsistent!" logger.info( "###################### Event %2i #############################" % i_event ) logger.info( "Run %i lumi %i event %i", reader.data.run, reader.data.lumi, reader.data.evt ) nonId_jets = filter(lambda j:j['pt']>30 and not j['id'], getJets(cmg_reader.data)) for j in nonId_jets: logger.info( "Non-ID Jet found pt %3.2f eta %3.2f phi %3.2f", j['pt'], j['eta'], j['phi'] ) # reco leptons all_reco_leps = getGoodAndOtherLeptons(cmg_reader.data, ptCut=10, miniRelIso = 999. , dz = 0.1, dxy = 1.) loose_mu = filter(lambda l:abs(l['pdgId'])==13 and looseMuID(l), all_reco_leps ) loose_e = filter(lambda l:abs(l['pdgId'])==11 and looseEleID(l), all_reco_leps ) extra_mu = filter(lambda l:abs(l['pdgId'])==13 and not looseMuID(l), all_reco_leps ) extra_e = filter(lambda l:abs(l['pdgId'])==11 and not looseEleID(l), all_reco_leps ) reco_mode = "unknown" if reader.data.isMuMu: reco_mode = "MuMu" if reader.data.isEE: reco_mode = "EE" if reader.data.isEMu: reco_mode = "EMu" logger.info( "reco'd as %s isOS %i, loose_mu %i, loose_e %i", bold(reco_mode), reader.data.isOS, len(loose_mu), len(loose_e) ) logger.info( "extra mu %i, extra e %i", len(extra_mu), len(extra_e) )
counterRecoGen_allMatched[mode]={} counterRecoGen_oneMuMatchedToB[mode]={} counterRecoGen_oneEleMatchedToB[mode]={} counterRecoGen_oneMuMatchedToTau[mode]={} counterRecoGen_oneEleMatchedToTau[mode]={} for ev in range(nEvents): ntot+=1 if ev%10000==0:print "At %i/%i"%(ev,nEvents) chain.GetEntry(eList.GetEntry(ev)) mt2Calc.reset() weight = reduceStat*getVarValue(chain, "weight")*lumiScale if not s['isData'] else 1 met = getVarValue(chain, "met_pt") metPhi = getVarValue(chain, "met_phi") jets = filter(lambda j:j['pt']>30 and abs(j['eta'])<2.4 and j['id'], getJets(chain)) leptons = filter(lambda l: looseMuID(l) or looseEleID(l), getLeptons(chain, collVars=leptonVars+['mcMatchId','mcMatchAny','mcMatchTau','mcPt'])) #LepGood_mcMatchId Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake for Leptons after the preselection #LepGood_mcMatchAny Match to any final state leptons: 0 if unmatched, 1 if light flavour (including prompt), 4 if charm, 5 if bottom for Leptons after the preselection #LepGood_mcMatchTau True if the leptons comes from a tau for Leptons after the preselection # for l in leptons: # if (l['mcMatchAny']==0 and (not (l['mcMatchId']==0))) or ( (not l['mcMatchAny']==0) and (l['mcMatchId']==0)): # print "Match?",l #RECO mu = filter(lambda l: abs(l['pdgId'])==13, leptons) ele = filter(lambda l: abs(l['pdgId'])==11, leptons) #RECO mathes muMatched = filter(lambda l: abs(l['mcMatchAny'])==1, mu) eleMatched = filter(lambda l: abs(l['mcMatchAny'])==1, ele)
counterRecoGen_oneEleMatchedToTau[mode] = {} for ev in range(nEvents): ntot += 1 if ev % 10000 == 0: print "At %i/%i" % (ev, nEvents) chain.GetEntry(eList.GetEntry(ev)) mt2Calc.reset() weight = reduceStat * getVarValue( chain, "weight") * lumiScale if not s['isData'] else 1 met = getVarValue(chain, "met_pt") metPhi = getVarValue(chain, "met_phi") jets = filter( lambda j: j['pt'] > 30 and abs(j['eta']) < 2.4 and j['id'], getJets(chain)) leptons = filter( lambda l: looseMuID(l) or looseEleID(l), getLeptons(chain, collVars=leptonVars + ['mcMatchId', 'mcMatchAny', 'mcMatchTau', 'mcPt'])) #LepGood_mcMatchId Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake for Leptons after the preselection #LepGood_mcMatchAny Match to any final state leptons: 0 if unmatched, 1 if light flavour (including prompt), 4 if charm, 5 if bottom for Leptons after the preselection #LepGood_mcMatchTau True if the leptons comes from a tau for Leptons after the preselection # for l in leptons: # if (l['mcMatchAny']==0 and (not (l['mcMatchId']==0))) or ( (not l['mcMatchAny']==0) and (l['mcMatchId']==0)): # print "Match?",l #RECO mu = filter(lambda l: abs(l['pdgId']) == 13, leptons) ele = filter(lambda l: abs(l['pdgId']) == 11, leptons)
for ev in range(nEvents): ntot+=1 if ev%10000==0:print "At %i/%i"%(ev,nEvents) chain.GetEntry(eList.GetEntry(ev)) mt2Calc.reset() weight = reduceStat*getVarValue(chain, "weight")*lumiScale if not s['isData'] else 1 mt2ll = getVarValue(chain, "dl_mt2ll") met = getVarValue(chain, "met_pt") metPhi = getVarValue(chain, "met_phi") genMet = getVarValue(chain, "met_genPt") genMetPhi = getVarValue(chain, "met_genPhi") deltaMet = sqrt((met*cos(metPhi)-genMet*cos(genMetPhi))**2+(met*sin(metPhi)-genMet*sin(genMetPhi))**2) jets = filter(lambda j:j['pt']>30 and abs(j['eta'])<2.4 and j['id'], getJets(chain)) allLeptons = getLeptons(chain, collVars=leptonVars+['mcMatchId','mcMatchAny','mcMatchTau','mcPt','ip3d', 'relIso03', 'relIso04', 'jetPtRatiov1', 'jetPtRelv1', 'jetPtRelv2', 'jetPtRatiov2', 'jetBTagCSV', 'jetDR']) leptons = filter(lambda l: looseMuID(l) or looseEleID(l), allLeptons) #LepGood_mcMatchId Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake for Leptons after the preselection #LepGood_mcMatchAny Match to any final state leptons: 0 if unmatched, 1 if light flavour (including prompt), 4 if charm, 5 if bottom for Leptons after the preselection #LepGood_mcMatchTau True if the leptons comes from a tau for Leptons after the preselection # for l in leptons: # if (l['mcMatchAny']==0 and (not (l['mcMatchId']==0))) or ( (not l['mcMatchAny']==0) and (l['mcMatchId']==0)): # print "Match?",l #RECO looseMu = filter(lambda l: abs(l['pdgId'])==13 and l['miniRelIso']<0.4 and l['pt']>15, allLeptons) looseEle= filter(lambda l: abs(l['pdgId'])==11 and l['miniRelIso']<0.4 and l['pt']>15, allLeptons) mu = filter(lambda l: abs(l['pdgId'])==13, leptons) ele = filter(lambda l: abs(l['pdgId'])==11, leptons) tau = getGoodTaus(chain)
# Start with reco leptons and match to generated logger.info( "gen lep: %i, all_reco_leps %i", len(gen_leps), len(all_reco_leps) ) logger.info( "prompt mu %i, non-prompt mu %i, prompt mu from tau %i, other %i", \ len(filter( lambda l:abs(l['pdgId'])==13 and l['prompt_from_W'], gen_leps )), len(filter( lambda l:abs(l['pdgId'])==13 and l['nonprompt'], gen_leps )), len(filter( lambda l:abs(l['pdgId'])==13 and l['prompt_from_tau'], gen_leps )), len(filter( lambda l:abs(l['pdgId'])==13 and l['other'], gen_leps )) ) logger.info( "prompt ele %i, non-prompt ele %i, prompt ele from tau %i, other %i", \ len(filter( lambda l:abs(l['pdgId'])==11 and l['prompt_from_W'], gen_leps )), len(filter( lambda l:abs(l['pdgId'])==11 and l['nonprompt'], gen_leps )), len(filter( lambda l:abs(l['pdgId'])==11 and l['prompt_from_tau'], gen_leps )), len(filter( lambda l:abs(l['pdgId'])==11 and l['other'], gen_leps )) ) loose_mu = filter(lambda l:abs(l['pdgId'])==13 and looseMuID(l), all_reco_leps ) loose_e = filter(lambda l:abs(l['pdgId'])==11 and looseEleID(l), all_reco_leps ) extra_mu = filter(lambda l:abs(l['pdgId'])==13 and not looseMuID(l), all_reco_leps ) extra_e = filter(lambda l:abs(l['pdgId'])==11 and not looseEleID(l), all_reco_leps ) reco_mode = "unknown" if reader.data.isMuMu: reco_mode = "MuMu" if reader.data.isEE: reco_mode = "EE" if reader.data.isEMu: reco_mode = "EMu" logger.info( "reco'd as %s isOS %i, loose_mu %i, loose_e %i", bold(reco_mode), reader.data.isOS, len(loose_mu), len(loose_e) ) logger.info( "extra mu %i, extra e %i", len(extra_mu), len(extra_e) ) l1 = {'pt':reader.data.l1_pt, 'eta':reader.data.l1_eta, 'phi':reader.data.l1_phi, 'pdgId':reader.data.l1_pdgId}
isElecElec[0] = 1 if not s["name"].find("DoubleMuon") and triggerMuMu : trigger = 1 isMuonMuon[0] = 1 if not s["name"].find("DoubleMuon") and triggerMuMu==0 : trigger = 0 isMuonMuon[0] = 1 if not s["name"].find("MuonEG") and triggerMuEle : trigger = 1 isMuonElec[0] = 1 if not s["name"].find("MuonEG") and triggerMuEle==0 : trigger = 0 isMuonElec[0] = 1 leptons = filter(lambda l: looseMuID(l) or looseEleID(l), getLeptons(chain)) jets = filter(lambda j:j['pt']>30 and abs(j['eta'])<2.4 and j['id'], getJets(chain)) bjets = filter(lambda j:j['btagCSV']>0.890, jets) nbjets[0] = len(bjets) njets[0] = len(jets) nleptons[0] = len(leptons) Process[:200] = s["name"] HT[0] = sum([j['pt'] for j in jets]) METSqrtHT[0] = met/HT[0] ptLeadingBJet[0] = bjets[0]['pt'] etaLeadingBJet[0] = bjets[0]['eta'] PhiMetJet1 = deltaPhi(metPhi,getVarValue(chain, "Jet_phi",0)) PhiMetJet2 = deltaPhi(metPhi,getVarValue(chain, "Jet_phi",1))