def buildLeptons(self, cmgLeptons, event): '''Build muons for veto, associate best vertex, select loose ID muons. The loose ID selection is done to ensure that the muon has an inner track.''' leptons = [] for index, lep in enumerate(cmgLeptons): # pyl = self.__class__.LeptonClass(lep) pyl = Muon(lep) pyl.associatedVertex = event.goodVertices[0] leptons.append(pyl) return leptons
def buildLeptons(self, cmgLeptons, event): '''Build muons for veto, associate best vertex, select loose ID muons. The loose ID selection is done to ensure that the muon has an inner track.''' leptons = [] for index, lep in enumerate(cmgLeptons): pyl = Muon(lep) pyl.associatedVertex = event.goodVertices[0] if not pyl.muonID('POG_ID_Medium'): continue if not pyl.relIso(dBetaFactor=0.5, allCharged=0) < 0.3: continue if not self.testLegKine(pyl, ptcut=10, etacut=2.4): continue leptons.append(pyl) return leptons
def buildLeptons(self, cmgLeptons, event): '''Build muons for veto, associate best vertex, select loose ID muons. The loose ID selection is done to ensure that the muon has an inner track.''' leptons = [] for index, lep in enumerate(cmgLeptons): pyl = Muon(lep) pyl.associatedVertex = event.goodVertices[0] if not pyl.muonID('POG_ID_Medium') : continue if not pyl.relIso(dBetaFactor=0.5, allCharged=0) < 0.3 : continue if not self.testLegKine(pyl, ptcut=10, etacut=2.4) : continue leptons.append( pyl ) return leptons
def buildOtherLeptons(self, cmgLeptons, event): '''Build muons for veto, associate best vertex, select loose ID muons. The loose ID selection is done to ensure that the muon has an inner track.''' leptons = [] for index, lep in enumerate(cmgLeptons): pyl = Muon(lep) pyl.associatedVertex = event.goodVertices[0] pyl.event = event.input.object() if not pyl.muonID("POG_ID_Medium_Moriond"): continue if not pyl.relIso(0.4, dbeta_factor=0.5, all_charged=0) < 0.3: continue if not self.testLegKine(pyl, ptcut=10, etacut=2.4): continue if not abs(pyl.dxy()) < 0.045: continue if not abs(pyl.dz()) < 0.2: continue leptons.append(pyl) return leptons
def process(self, event): self.readCollections(event.input) self.counters.counter('KinematicVertexFitter').inc('all events') event.bs = self.handles['offlinebeamspot'].product() point = ROOT.reco.Vertex.Point( event.bs.position().x(), event.bs.position().y(), event.bs.position().z(), ) error = event.bs.covariance3D() chi2 = 0. ndof = 0. bsvtx = ROOT.reco.Vertex(point, error, chi2, ndof, 3) # size? say 3? does it matter? # select the best triplet candidate, according to: # - the candidate must have a good refitted vertex candidates = [ cand for cand in event.seltau3mu if self.checkTripletVertex(cand) ] if not len(candidates): return False self.counters.counter('KinematicVertexFitter').inc( '>0 triplets with good vertex') # - none of the candidate's muons can make a good resonance with another muon in the event candidates = [ cand for cand in candidates if self.checkResonanceOtherMuon(cand, event) ] if not len(candidates): return False self.counters.counter('KinematicVertexFitter').inc( '>0 triplets without resonances with other muons') # - if there's still more than one candidate, pick the one with the best vertex probability. # Give precedence to candidates with the correct charge candidate = sorted(candidates, key=lambda cand: ((cand.charge() != 1), cand.svtree.prob), reverse=True)[0] self.counters.counter('KinematicVertexFitter').inc('candidate chosen') # save the number of candidates as event attribute event.ncands = len(candidates) # now investigate the one good candidate event.tau3mu = candidate svtree = candidate.svtree # accessing the tree components svtree.movePointerToTheTop() # We are now at the top of the decay tree getting # the Tau reconstructed KinematicPartlcle tauref = svtree.currentParticle() event.tau3mu.refitTau = self.buildP4(tauref)[0] # getting the tau->mu mu mu decay vertex sv = svtree.currentDecayVertex().get() if not sv.vertexIsValid(): return False self.counters.counter('KinematicVertexFitter').inc( 'valid refitted vertex') # this shit does not work, but it should http://cmslxr.fnal.gov/source/RecoVertex/KinematicFitPrimitives/src/KinematicVertex.cc#0112 # event.tau3mu.refittedVertex = getattr(sv, 'operator Vertex')() # this is now a reco::Vertex # let's work it around tauvtx = self.RecoVertex(sv, kinVtxTrkSize=3) # Now navigating down the tree, mu1 if not svtree.movePointerToTheFirstChild(): return False self.counters.counter('KinematicVertexFitter').inc( 'valid refitted muon 1') mu1ref = svtree.currentParticle() refitMu1 = self.buildP4(mu1ref)[0] # mu2 if not svtree.movePointerToTheNextChild(): return False self.counters.counter('KinematicVertexFitter').inc( 'valid refitted muon 2') mu2ref = svtree.currentParticle() refitMu2 = self.buildP4(mu2ref)[0] # mu3 if not svtree.movePointerToTheNextChild(): return False self.counters.counter('KinematicVertexFitter').inc( 'valid refitted muon 3') mu3ref = svtree.currentParticle() refitMu3 = self.buildP4(mu3ref)[0] # create a new tau3mu object using the original pat muons # after their p4 is updated to the refitted p4 mu1refit = dc(event.tau3mu.mu1().physObj) # clone PAT Muons mu2refit = dc(event.tau3mu.mu2().physObj) # clone PAT Muons mu3refit = dc(event.tau3mu.mu3().physObj) # clone PAT Muons mu1refit.setP4(refitMu1) # update p4 mu2refit.setP4(refitMu2) # update p4 mu3refit.setP4(refitMu3) # update p4 # instantiate heppy muons from PAT muons refitMuons = [ Muon(mu1refit), Muon(mu2refit), Muon(mu3refit), ] # associate the primary vertex to the muons for mu in refitMuons: mu.associatedVertex = event.vertices[0] # create a new tau3mu object event.tau3muRefit = Tau3MuMET(refitMuons, event.tau3mu.met()) # append the refitted vertex to it event.tau3muRefit.refittedVertex = tauvtx # calculate 2D displacement significance distanceTauBS = self.vertTool.distance(tauvtx, bsvtx) event.tau3muRefit.refittedVertex.ls = distanceTauBS.significance() # calculate decay length significance w.r.t. the beamspot tauperp = ROOT.math.XYZVector(event.tau3mu.refitTau.px(), event.tau3mu.refitTau.py(), 0.) displacementFromBeamspotTau = ROOT.GlobalPoint( -1 * ((event.bs.x0() - tauvtx.x()) + (tauvtx.z() - event.bs.z0()) * event.bs.dxdz()), -1 * ((event.bs.y0() - tauvtx.y()) + (tauvtx.z() - event.bs.z0()) * event.bs.dydz()), 0) vperptau = ROOT.math.XYZVector(displacementFromBeamspotTau.x(), displacementFromBeamspotTau.y(), 0.) event.tau3muRefit.refittedVertex.cos = vperptau.Dot(tauperp) / ( vperptau.R() * tauperp.R()) return True
def __init__(self, diobject): super(MuonElectron, self).__init__(diobject) self.mu = Muon(super(MuonElectron, self).leg1()) self.ele = Electron(super(MuonElectron, self).leg2()) self.diobject.setP4(self.p4())
def __init__(self, diobject): super(TauMuon, self).__init__(diobject) self.tau = Tau(super(TauMuon, self).leg1()) self.mu = Muon(super(TauMuon, self).leg2()) self.diobject.setP4(self.p4())
def __init__(self, diobject): super(DiMuon, self).__init__(diobject) self.mu1 = Muon(super(DiMuon, self).leg1()) self.mu2 = Muon(super(DiMuon, self).leg2()) self.diobject.setP4(self.p4())
def process(self, event): self.readCollections(event.input) # all jets miniaodjets = [Jet(jet) for jet in self.handles['jets'].product()] # ugt decision event.ugt = self.handles['ugt'].product().at(0, 0) # now find the L1 muons from BX = 0 L1muons_allbx = self.handles['L1muons'].product() if getattr(self.cfg_ana, 'onlyBX0', True): L1_muons = [] for jj in range(L1muons_allbx.size(0)): L1_muons.append(L1muons_allbx.at(0, jj)) event.L1_muons = L1_muons else: event.L1_muons = [mu for mu in L1muons_allbx] if len(event.L1_muons): import pdb pdb.set_trace() # append a reco jet (if it exists) to each L1 muon for mu in event.L1_muons: jets = sorted([ jj for jj in miniaodjets if deltaR2( jj.eta(), jj.phi(), mu.etaAtVtx(), mu.phiAtVtx()) < 0.16 ], key=lambda x: deltaR2(x, mu)) if len(jets): mu.jet = jets[0] event.L1_muons_eta_0p5_q8 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 0.5 and mu.hwQual() >= 8 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_0p5_q12 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 0.5 and mu.hwQual() >= 12 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_0p8_q8 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 0.8 and mu.hwQual() >= 8 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_0p8_q12 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 0.8 and mu.hwQual() >= 12 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_1p0_q8 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 1.0 and mu.hwQual() >= 8 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_1p0_q12 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 1.0 and mu.hwQual() >= 12 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_1p5_q8 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 1.5 and mu.hwQual() >= 8 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_1p5_q12 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 1.5 and mu.hwQual() >= 12 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_2p1_q8 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 2.1043125 and mu.hwQual() >= 8 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_2p1_q12 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 2.1043125 and mu.hwQual() >= 12 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_2p5_q8 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 2.5 and mu.hwQual() >= 8 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_2p5_q12 = sorted([ mu for mu in event.L1_muons if abs(mu.eta()) < 2.5 and mu.hwQual() >= 12 ], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_inf_q8 = sorted( [mu for mu in event.L1_muons if mu.hwQual() >= 8], key=lambda mu: mu.pt(), reverse=True) event.L1_muons_eta_inf_q12 = sorted( [mu for mu in event.L1_muons if mu.hwQual() >= 12], key=lambda mu: mu.pt(), reverse=True) # # 29 L1_SingleMu22er2p1 # if ugt.getAlgoDecisionFinal(29) and len([mu for mu in event.L1_muons_eta_2p1_q12 if mu.pt()>=22.])==0: # import pdb ; pdb.set_trace() # if any([mm.eta() == 2.1 for mm in event.L1_muons]): # print 'cazz...' # import pdb ; pdb.set_trace() # if len(event.L1_muons_eta_2p5_q12)>1: # for mm in event.L1_muons_eta_2p5_q12: print mm.pt(), mm.eta(), mm.phi(), mm.hwQual() # import pdb ; pdb.set_trace() # if event.run==305081: event.fakeL1mu = True event.deltapt = -9999. event.isiso = -99. event.lowptjet = False if len(event.L1_muons_eta_2p1_q12 ) > 0 and event.L1_muons_eta_2p1_q12[0].pt() >= 22.: print 'Jets, unfiltered' for jet in miniaodjets: print jet, '\tpfJetId', jet.jetID( "POG_PFID_Loose"), '\tpuJetId', jet.puJetId( ), '\tbtag', jet.btag( 'pfCombinedInclusiveSecondaryVertexV2BJetTags') if deltaR2(jet.eta(), jet.phi(), event.L1_muons_eta_2p1_q12[0].etaAtVtx(), event.L1_muons_eta_2p1_q12[0].phiAtVtx()) < 0.25: if jet.pt() < 20.: event.lowptjet = True print 'L1 muons' for mu in event.L1_muons_eta_2p1_q12: print 'pt %.2f\teta %.2f\tphi %.2f\tetaAtVtx %.2f\tphiAtVtx %.2f' % ( mu.pt(), mu.eta(), mu.phi(), mu.etaAtVtx(), mu.phiAtVtx()) print 'offline muons' for mm in [Muon(ii) for ii in self.handles['muons'].product()]: print mm if deltaR2(mm.eta(), mm.phi(), event.L1_muons_eta_2p1_q12[0].etaAtVtx(), event.L1_muons_eta_2p1_q12[0].phiAtVtx()) < 0.25: event.fakeL1mu = False event.isiso = int(mm.relIso() < 1.) event.deltapt = event.L1_muons_eta_2p1_q12[0].pt() - mm.pt( ) # jj = miniaodjets[1] # deltaR(jj.eta(), jj.phi(), mu.etaAtVtx(), mu.phiAtVtx()) # import pdb ; pdb.set_trace() return True
def __init__(self, diobject): super(DiMuon, self).__init__(diobject) self.mu1 = Muon(diobject.leg1()) self.mu2 = Muon(diobject.leg2())
def __init__(self, diobject): super(MuonElectron, self).__init__(diobject) self.mu = Muon(diobject.leg1()) self.ele = HTauTauElectron(diobject.leg2())