def update(self, _): jets = self.source['TopJets'] p4 = self.source['AdjustedP4'.join(jets)] scale = self.source['ScalingBQN'.join(jets)] self.value = {} for iPQB in self.source['HTopCandidateIndices']: proxy = sum([ p4[i] * (scale['B' if j == 2 else 'Q'][i]) for j, i in enumerate(iPQB) if i != None ], utils.LorentzV()) self.value[iPQB] = proxy.M()
def update(self, _): reco = self.source["TopReconstruction"][0] t = reco['top'] tbar = reco['tbar'] q_z = 0.5 * (t + tbar).z() self.value = { 't': t, 'tbar': tbar, 'quark': utils.LorentzV().SetPxPyPzE(0, 0, q_z, abs(q_z)), 'lepton': reco['lep'], 'neutrino': reco['nu'], 'p': reco['hadP'], 'q': reco['hadQ'], 'rawW': reco['hadWraw'], 'metP4': reco['metP4'], 'key': reco['key'], 'chi2': reco['chi2'], 'hadChi2': reco['hadChi2'], 'ttx': reco['ttx'], 'fifth': reco['iX'] != None, 'iPQHL': reco['iPQHL'], 'iOtherJets': [ i for i in self.source['Indices'.join(self.source['TopJets'])] if i not in reco['iPQHL'] ] }
def uponAcceptance(self, ev): ids = list(ev['genPdgId']) if not (6 in ids and -6 in ids): return iTop = ids.index(6) iTbar = ids.index(-6) iQs = range(2, min( iTop, iTbar)) # interested in stuff listed between protons and tops mom = ev['genMotherIndex'] p4s = ev['genP4'] status = ev['genStatus'] labels = { 1: ' d', -1: r'/d', 2: ' u', -2: r'/u', 3: ' s', -3: r'/s', 4: ' c', -4: r'/c', 5: ' b', -5: r'/b', 21: ' g', 6: ' t', -6: '/t' } iGs = filter(lambda i: ids[i] == 21, range(max(iTop, iTbar) + 1, len(ids))) iDaughters = filter(lambda i: mom[i] < min(iTop, iTbar), range(max(iTop, iTbar) + 1, len(ids))) print '-' * 50 print '\t'.join(['item', 'mom', 'pt', 'm', 'eta', 'phi']) print for i in iQs + [iTop, iTbar] + iDaughters: print '\t'.join( str(d)[:5] for d in [ "%d(%s)" % (i, labels[ids[i]] if ids[i] in labels else str(ids[i])), mom[i], p4s[i].pt(), '-', p4s[i].eta(), p4s[i].phi(), status[i] ]) print pD = sum([p4s[i] for i in iDaughters], utils.LorentzV()) print '\t'.join( str(d)[:5] for d in ["Daught", '-', pD.pt(), pD.M(), pD.eta(), pD.phi()]) p4 = p4s[2] + p4s[3] print '\t'.join( str(d)[:5] for d in ["[%s,%s]" % (2, 3), '-', p4.pt(), p4.M(), p4.eta(), p4.phi()]) p4 = p4s[4] + p4s[5] print '\t'.join( str(d)[:5] for d in ["[%s,%s]" % (4, 5), '-', p4.pt(), p4.M(), p4.eta(), p4.phi()]) tt = p4s[iTop] + p4s[iTbar] print '\t'.join( str(d)[:5] for d in ["ttbar", '-', tt.pt(), tt.M(), tt.eta(), tt.phi()]) print print if abs(tt.E() - (p4s[4] + p4s[5]).E()) > 0.5: print(50 * ' '), "2 -> 3+"
def update(self, _): self.value = sum( utils.hackMap( self.delta, *[self.source[getattr(self, item)] for item in self.stashed]), utils.LorentzV())
def __init__(self, nSamples=16, qDirFunc=None): self.nSamples = nSamples self.qDirFunc = qDirFunc self.moreName = "%d samples; %s" % (nSamples, qDirFunc) self.nu = utils.LorentzV()
def update(self, _): jets = dict( (item, self.source[item.join(self.source["TopJets"])]) for item in ["AdjustedP4", "Indices", "Resolution", "ScalingBQN"]) lepton = dict((item, self.source[item.join(self.source['TopLeptons'])][ self.source["SemileptonicTopIndex"]]) for item in ["Charge", "P4"]) topP = self.source["TopComboQQBBProbability"] TCL = self.source['TopCandidateLikelihood'] recos = [] metP4 = self.source["metAdjustedP4"] nuXY = np.array([metP4.x(), metP4.y()]) nuErr2 = self.source["metCovariance"] for iPQHL in TCL.keys()[:self.maxFits]: iProxyL = [i for i in iPQHL if i != None] p4s = [jets['AdjustedP4'][i] for i in iProxyL] scales = [ jets['ScalingBQN']['B' if j > 1 else 'Q'][i] for j, i in enumerate(iPQHL) if i != None ] sp4s = [j * s for j, s in zip(p4s, scales)] hadProxy = sum(sp4s[:3], utils.LorentzV()) iL = iPQHL[-1] iQQBB = iPQHL[:2] + tuple(sorted(iPQHL[2:])) nuXY_mod = sum([(1 - s) * np.array([j.x(), j.y()]) for j, s in zip(p4s, scales)], nuXY) lepFit = utils.fitKinematic.leastsqLeptonicTop2( sp4s[-1], jets["Resolution"][iL], lepton["P4"], nuXY_mod, nuErr2) tt = hadProxy + lepFit.fitT iX, ttx = (None, tt) recos.append({ "nu": lepFit.fitNu, "hadP": sp4s[0], "lep": lepFit.mu, "hadQ": sp4s[1], "lepB": lepFit.fitB, "hadB": sp4s[2], "lepW": lepFit.fitW, "hadW": utils.LorentzV(), "lepTopP4": lepFit.fitT, "hadTopP4": hadProxy, "lepChi2": lepFit.chi2, "hadChi2": 0, "chi2": 0 + lepFit.chi2, "probability": max(self.epsilon, topP[iQQBB]), "top": lepFit.fitT if lepton["Charge"] > 0 else hadProxy, "tbar": hadProxy if lepton["Charge"] > 0 else lepFit.fitT, "ttx": ttx, "iX": iX, "iPQHL": iPQHL, "lepCharge": lepton["Charge"], "hadTraw": hadProxy, "lepTraw": lepFit.rawT, "lepBound": lepFit.bound, "hadWraw": utils.LorentzV(), "lepWraw": lepFit.rawW, "metP4": metP4 + sp4s[-1] - lepFit.fitB, "nuErr2": nuErr2, "residuals": dict( zip(["lep" + i for i in "BSLWT"], lepFit.residualsBSLWT) + zip(["had" + i for i in "PQBWT"], [0] * 5)), "nuEllipse": lepFit.Ellipse, "nuSolutions": lepFit.solutions, "nuChi2Matrix": lepFit.X }) recos[-1]["key"] = recos[-1]['chi2'] - 2 * math.log( recos[-1]['probability']) self.value = sorted(recos, key=lambda x: x["key"])