def selectFirstTwoJets(chain, new_chain): if chain is new_chain: new_chain.j_pt = [0.0] * 2 new_chain.j_eta = [0.0] * 2 new_chain.j_phi = [0.0] * 2 new_chain.j_e = [0.0] * 2 new_chain.j_indices = [0.0] * 2 new_chain.j_btag = [0.0] * 2 chain.jets = [(chain._jetPt[j], j) for j in xrange(chain._nJets) if isGoodJet(chain, j)] ptAndIndex = sorted(chain.jets, reverse=True, key=getSortKey) for i in xrange(2): if i < len(chain.jets): new_chain.j_pt[i] = ptAndIndex[i][0] new_chain.j_eta[i] = chain._jetEta[ptAndIndex[i][1]] new_chain.j_phi[i] = chain._jetPhi[ptAndIndex[i][1]] new_chain.j_e[i] = chain._jetE[ptAndIndex[i][1]] new_chain.j_indices[i] = ptAndIndex[i][1] new_chain.j_btag[i] = returnBTagValueBySelection( chain, ptAndIndex[i][1]) else: new_chain.j_pt[i] = 0. new_chain.j_eta[i] = 0. new_chain.j_phi[i] = 0. new_chain.j_e[i] = 0. new_chain.j_indices[i] = -1 new_chain.j_btag[i] = -99. return True
def calculateGeneralVariables(chain, new_chain, is_reco_level=True): if is_reco_level: #ptCone new_chain.pt_cone = [] for l in xrange(chain._nLight): new_chain.pt_cone.append(chain._lPt[l] * (1 + max(0., chain._miniIso[l] - 0.4)) ) #TODO: is this the correct definition? #calculate #jets and #bjets njets = 0 nbjets = 0 # print 'start' for jet in xrange(chain._nJets): if isGoodJet(chain, jet): # print 'new good jet with index : ', jet # print 'Is good b jet? ', isBJet(chain, jet, 'Deep', 'loose') njets += 1 if isBJet(chain, jet, 'Deep', 'loose'): nbjets += 1 new_chain.njets = njets new_chain.nbjets = nbjets new_chain.hasOSSF = containsOSSF(new_chain)
def calcHT(chain, new_chain): HT = 0. for jet in xrange(chain._nJets): if not isGoodJet(chain, jet): continue HT += chain._jetPt[jet] return HT
def selectJets(chain, cleaned='loose'): jet_indices = [] for jet in xrange(chain._nJets): if isGoodJet(chain, jet, cleaned=cleaned): jet_indices.append(jet) return jet_indices
def calculateKinematicVariables(chain, new_chain, is_reco_level=True): l1Vec = getFourVec(new_chain.l_pt[l1], new_chain.l_eta[l1], new_chain.l_phi[l1], new_chain.l_e[l1]) l2Vec = getFourVec(new_chain.l_pt[l2], new_chain.l_eta[l2], new_chain.l_phi[l2], new_chain.l_e[l2]) l3Vec = getFourVec(new_chain.l_pt[l3], new_chain.l_eta[l3], new_chain.l_phi[l3], new_chain.l_e[l3]) lVec = [l1Vec, l2Vec, l3Vec] #M3l new_chain.M3l = (l1Vec + l2Vec + l3Vec).M() #All combinations of dilepton masses new_chain.Ml12 = (l1Vec + l2Vec).M() new_chain.Ml23 = (l2Vec + l3Vec).M() new_chain.Ml13 = (l1Vec + l3Vec).M() # # Get OS, OSSF, SS, SSSF variables # min_os = [None, None] max_os = [None, None] min_ss = [None, None] max_ss = [None, None] min_ossf = [None, None] max_ossf = [None, None] min_sssf = [None, None] max_sssf = [None, None] tmp_minos = 99999999. tmp_minss = 99999999. tmp_minossf = 99999999. tmp_minsssf = 99999999. tmp_maxos = 0 tmp_maxss = 0 tmp_maxossf = 0 tmp_maxsssf = 0 for i1, l in enumerate([new_chain.l1, new_chain.l2, new_chain.l3]): for i2, sl in enumerate([new_chain.l1, new_chain.l2, new_chain.l3]): if i2 <= i1: continue tmp_mass = (lVec[i1] + lVec[i2]).M() if new_chain.l_charge[i1] == new_chain.l_charge[i2]: if tmp_mass < tmp_minss: min_ss = [i1, i2] tmp_minss = tmp_mass if tmp_mass > tmp_maxss: max_ss = [i1, i2] tmp_maxss = tmp_mass if new_chain.l_flavor[i1] == new_chain.l_flavor[i2]: if tmp_mass < tmp_minsssf: min_sssf = [i1, i2] tmp_minsssf = tmp_mass if tmp_mass > tmp_maxsssf: max_sssf = [i1, i2] tmp_maxsssf = tmp_mass else: if tmp_mass < tmp_minos: min_os = [i1, i2] tmp_minos = tmp_mass if tmp_mass > tmp_maxos: max_os = [i1, i2] tmp_maxos = tmp_mass if new_chain.l_flavor[i1] == new_chain.l_flavor[i2]: if tmp_mass < tmp_minossf: min_ossf = [i1, i2] tmp_minossf = tmp_mass if tmp_mass > tmp_maxossf: max_ossf = [i1, i2] tmp_maxossf = tmp_mass #Mass variables chain.minMos = (lVec[min_os[0]] + lVec[min_os[1]]).M() if all(min_os) else 0 chain.maxMos = (lVec[max_os[0]] + lVec[max_os[1]]).M() if all(max_os) else 0 chain.minMss = (lVec[min_ss[0]] + lVec[min_ss[1]]).M() if all(min_ss) else 0 chain.maxMss = (lVec[max_ss[0]] + lVec[max_ss[1]]).M() if all(max_ss) else 0 chain.minMossf = (lVec[min_ossf[0]] + lVec[min_ossf[1]]).M() if all(min_ossf) else 0 chain.maxMossf = (lVec[max_ossf[0]] + lVec[max_ossf[1]]).M() if all(max_ossf) else 0 chain.minMsssf = (lVec[min_sssf[0]] + lVec[min_sssf[1]]).M() if all(min_sssf) else 0 chain.maxMsssf = (lVec[max_sssf[0]] + lVec[max_sssf[1]]).M() if all(max_sssf) else 0 # min_mos = 9999999. # min_os = [10, 10] # for i1, l in enumerate([new_chain.l1, new_chain.l2, new_chain.l3]): # for i2, sl in enumerate([new_chain.l1, new_chain.l2, new_chain.l3]): # if i2 <= i1: continue # if new_chain.l_charge[i1] == new_chain.l_charge[i2]: continue # tmp_mos = (lVec[i1]+lVec[i2]).M() # if tmp_mos < min_mos: # min_mos = tmp_mos # min_os = [l, sl] # new_chain.minMos = min_mos #MTother new_chain.index_other = [ item for item in [new_chain.l1, new_chain.l2, new_chain.l3] if item not in min_os ][0] #TODO: Seems like there must be a better way to do this if is_reco_level: new_chain.mtOther = np.sqrt( 2 * chain._met * chain._lPt[new_chain.index_other] * (1 - np.cos( deltaPhi(chain._lPhi[new_chain.index_other], chain._metPhi)))) #ptCone new_chain.pt_cone = [] for l in xrange(chain._nLight): new_chain.pt_cone.append(chain._lPt[l] * (1 + max(0., chain._miniIso[l] - 0.4)) ) #TODO: is this the correct definition? else: new_chain.mtOther = np.sqrt( 2 * chain._gen_met * chain._gen_lPt[new_chain.index_other] * (1 - np.cos( deltaPhi(chain._gen_lPhi[new_chain.index_other], chain._gen_metPhi)))) # #ptCone # new_chain.pt_cone = [] # for l in xrange(chain._nLight): # new_chain.pt_cone.append(chain._lPt[l]) #TODO: is this the correct definition? #calculate #jets and #bjets njets = 0 nbjets = 0 # print 'start' for jet in xrange(chain._nJets): if isGoodJet(chain, jet): # print 'new good jet with index : ', jet # print 'Is good b jet? ', isBJet(chain, jet, 'Deep', 'loose') njets += 1 if isBJet(chain, jet, 'Deep', 'loose'): nbjets += 1 new_chain.njets = njets new_chain.nbjets = nbjets new_chain.hasOSSF = containsOSSF(new_chain) # # dR variables # new_chain.dr_l1l2 = l1Vec.DeltaR(l2Vec) new_chain.dr_l1l3 = l1Vec.DeltaR(l2Vec) new_chain.dr_l2l3 = l1Vec.DeltaR(l2Vec) new_chain.dr_minOS = lVec[min_os[0]].DeltaR( lVec[min_os[1]]) if all(min_os) else -999. new_chain.dr_maxOS = lVec[max_os[0]].DeltaR( lVec[max_os[1]]) if all(max_os) else -999. new_chain.dr_minSS = lVec[min_ss[0]].DeltaR( lVec[min_ss[1]]) if all(min_ss) else -999. new_chain.dr_maxSS = lVec[max_ss[0]].DeltaR( lVec[max_ss[1]]) if all(max_ss) else -999. new_chain.dr_minOSSF = lVec[min_ossf[0]].DeltaR( lVec[min_ossf[1]]) if all(min_ossf) else -999. new_chain.dr_maxOSSF = lVec[max_ossf[0]].DeltaR( lVec[max_ossf[1]]) if all(max_ossf) else -999. new_chain.dr_minSSSF = lVec[min_sssf[0]].DeltaR( lVec[min_sssf[1]]) if all(min_sssf) else -999. new_chain.dr_maxSSSF = lVec[max_sssf[0]].DeltaR( lVec[max_sssf[1]]) if all(max_sssf) else -999. new_chain.mindr_l1 = min(new_chain.dr_l1l2, new_chain.dr_l1l3) new_chain.maxdr_l1 = max(new_chain.dr_l1l2, new_chain.dr_l1l3) new_chain.mindr_l2 = min(new_chain.dr_l1l2, new_chain.dr_l2l3) new_chain.maxdr_l2 = max(new_chain.dr_l1l2, new_chain.dr_l2l3) new_chain.mindr_l3 = min(new_chain.dr_l1l3, new_chain.dr_l2l3) new_chain.maxdr_l3 = max(new_chain.dr_l1l3, new_chain.dr_l2l3) return