def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" if not self.isFastsim: return True if self.applyUncert == "JESUp": met = ObjectRemapped(event, self.metBranchName, replaceMap={"pt":"pt_jesTotalUp", "phi":"phi_jesTotalUp"}) elif self.applyUncert == "JESDown": met = ObjectRemapped(event, self.metBranchName, replaceMap={"pt":"pt_jesTotalDown", "phi":"phi_jesTotalDown"}) elif self.applyUncert == "METUnClustUp": met = ObjectRemapped(event, self.metBranchName, replaceMap={"pt":"pt_unclustEnUp", "phi":"phi_unclustEnUp"}) elif self.applyUncert == "METUnClustDown": met = ObjectRemapped(event, self.metBranchName, replaceMap={"pt":"pt_unclustEnDown", "phi":"phi_unclustEnDown"}) else: met = Object(event, self.metBranchName) genmet = Object(event, "GenMET") fastmet = (met.pt + genmet.pt)/2.0 fastmet_err = math.fabs(fastmet - met.pt) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Store output ~~~~~ if self.applyUncert == "JESUp": self.out.fillBranch("MET_pt_jesTotalUp", fastmet) elif self.applyUncert == "JESDown": self.out.fillBranch("MET_pt_jesTotalDown", fastmet) elif self.applyUncert == "METUnClustUp": self.out.fillBranch("MET_pt_unclustEnUp", fastmet) elif self.applyUncert == "METUnClustDown": self.out.fillBranch("MET_pt_unclustEnDown", fastmet) else: self.out.fillBranch("MET_pt", fastmet) self.out.fillBranch("MET_pt_fasterr", fastmet_err) return True
def analyze(self, event): #called by the eventloop per-event """process event, return True (go to next module) or False (fail, go to next event)""" #Increment counter and skip events past the maxEventsToProcess, if larger than -1 self.counter +=1 if -1 < self.maxEventsToProcess < self.counter: return False if (self.counter % 100) == 0: print("Processed {0:2d} Events".format(self.counter)) HT = 0 electrons = Collection(event, "Electron") muons = Collection(event, "Muon") jets = Collection(event, "Jet") met = Object(event, "MET") HLT = Object(event, "HLT") if met.pt < 25: return False for jet in jets: if jet.jetId < 2: continue if abs(jet.eta) > 2.5: continue HT += jet.pt if HT < 350: return False return True
def analyze(self, event): jets = Collection(event, "Jet") muons = Collection(event, "Muon") pfmet = Object(event, self.pfmetBranchName) rawmet = Object(event, self.rawmetBranchName) puppimet = Object(event, self.puppimetBranchName) flag = Object(event, self.flagBranchName) #print flag.goodVertices, flag.HBHENoiseFilter, flag.HBHENoiseIsoFilter, flag.EcalDeadCellTriggerPrimitiveFilter, flag.BadPFMuonFilter, flag.ecalBadCalibFilter if (flag.goodVertices == False or flag.HBHENoiseFilter == False or flag.HBHENoiseIsoFilter == False or flag.EcalDeadCellTriggerPrimitiveFilter == False or flag.BadPFMuonFilter == False or flag.ecalBadCalibFilter == False): return False mu0 = ROOT.TLorentzVector() mu0.SetPtEtaPhiM(muons[0].pt, muons[0].eta, muons[0].phi, muons[0].mass) mu1 = ROOT.TLorentzVector() mu1.SetPtEtaPhiM(muons[1].pt, muons[1].eta, muons[1].phi, muons[1].mass) mass_dimuon = (mu0 + mu1).M() zpt = (mu0 + mu1).Pt() self.h_dimuonmass.Fill(mass_dimuon) #select events with at least 2 muons if abs(mass_dimuon - 91.0) < 10.0: self.h_zpt.Fill(zpt) self.h_rawmet.Fill(rawmet.pt) #fill histogram self.h_pfmet.Fill(pfmet.pt) #fill histogram self.h_puppimet.Fill(puppimet.pt) #fill histogram return True
def analyze(self, event): jets = Collection(event, "Jet") genjets = Collection(event, "GenJet") met = Object(event, self.metBranchName) weight = Object(event, "genWeight") # matching gen jet can be called by the index Jet_genJetIdx, jet.genJetIdx == matched GenJet #bootstrapping should be done here #the histogram can be accessed by doing self.targeth.{some root function to get the value} #xBinWidth = float(2/self.targeth.GetNbinsX()) xBinWidth = 0.01 #begin smearing smearWeight = 1 nj = 0 for gJ in genjets : if nj == self.nSmearJets: break else: nj+=1 gj = j.genJetIdx #you know have a matching index to the reco jet testMet = self.addFourVector(met, j).Pt() print "nj: ", nj print "index: ", gj print "testMet: ", testMet jetFlavour = j.partonFlavour self.out.fillBranch("jetFlav", jetFlavour) #This calculates the response with matched gen and reco jets origRes_ = self.jetResFunction(j, genjets[gj]) print "CDF: ", self.targeth.GetBinContent(int(origRes_/self.xBinWidth)) self.out.fillBranch("origRes", origRes_) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" if not self.isFastsim: return True met = Object(event, "MET") genmet = Object(event, "GenMET") genpar = Object(event, "GenPart") fastmet = (met.pt + genmet.pt) / 2.0 fastmet_err = math.fabs(fastmet - met.pt) # print(type(genpar.status)) # status = genpar.status == 62 # print(type(status)) mothermass = np.unique( genpar.mass[(genpar.status == 62) & (np.absolute(genpar.pdgId) > 1000000)]) LSPmass = np.unique(genpar.mass[(genpar.status == 1) & (genpar.pdgId == 1000022)]) if mothermass.shape != (1, ) or LSPmass.shape != (1, ): print("Not pair SUSY? Danger!") #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Store output ~~~~~ self.out.fillBranch("MET_pt", fastmet) self.out.fillBranch("MET_pt_fasterr", fastmet_err) self.out.fillBranch("Stop0l_MotherMass", mothermass[0]) self.out.fillBranch("Stop0l_LSPMass", LSPmass[0])
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" ## Getting objects electrons = Collection(event, "Electron") muons = Collection(event, "Muon") isotracks = Collection(event, "IsoTrack") jets = Collection(event, "Jet") isvs = Collection(event, "SB") photons = Collection(event, "Photon") met = Object(event, self.metBranchName) flags = Object(event, "Flag") ## Selecting objects self.Electron_Stop0l = map(self.SelEle, electrons) self.Muon_Stop0l = map(self.SelMuon, muons) self.IsoTrack_Stop0l = map(lambda x: self.SelIsotrack(x, met), isotracks) self.Jet_Stop0l = map(self.SelJets, jets) local_BJet_Stop0l = map(self.SelBtagJets, jets) self.BJet_Stop0l = [ a and b for a, b in zip(self.Jet_Stop0l, local_BJet_Stop0l) ] self.SB_Stop0l = map(self.SelSoftb, isvs) self.Photon_Stop0l = map(self.SelPhotons, photons) ## Jet variables jet_phi = np.asarray([jet.phi for jet in jets]) Jet_dPhi = jet_phi - met.phi np.subtract(Jet_dPhi, 2 * math.pi, out=Jet_dPhi, where=(Jet_dPhi >= math.pi)) np.add(Jet_dPhi, 2 * math.pi, out=Jet_dPhi, where=(Jet_dPhi < -1 * math.pi)) np.fabs(Jet_dPhi, out=Jet_dPhi) ## TODO: Need to improve speed HT = self.CalHT(jets) Mtb, Ptb = self.CalMTbPTb(jets, met) ### Store output self.out.fillBranch("Electron_Stop0l", self.Electron_Stop0l) self.out.fillBranch("Muon_Stop0l", self.Muon_Stop0l) self.out.fillBranch("IsoTrack_Stop0l", self.IsoTrack_Stop0l) self.out.fillBranch("Jet_btagStop0l", self.BJet_Stop0l) self.out.fillBranch("Jet_Stop0l", self.Jet_Stop0l) self.out.fillBranch("SB_Stop0l", self.SB_Stop0l) self.out.fillBranch("Photon_Stop0l", self.Photon_Stop0l) self.out.fillBranch("Jet_dPhiMET", Jet_dPhi) self.out.fillBranch("Stop0l_HT", HT) self.out.fillBranch("Stop0l_Mtb", Mtb) self.out.fillBranch("Stop0l_Ptb", Ptb) self.out.fillBranch("Stop0l_nJets", sum(self.Jet_Stop0l)) self.out.fillBranch("Stop0l_nbtags", sum(self.BJet_Stop0l)) self.out.fillBranch("Stop0l_nSoftb", sum(self.SB_Stop0l)) self.out.fillBranch("Stop0l_METSig", met.pt / math.sqrt(HT) if HT > 0 else 0) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" HLT = Object(event, "HLT") run = Object(event, "run") if self.year == '2016' and self.runP != 'H': if run.__getattr__('') > 274954: good_HLT = HLT.PFHT800 or HLT.PFHT900 or HLT.Mu50 or HLT.TkMu50 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon175 or HLT.Ele27_WPTight_Gsf return good_HLT
def Object___init__(self, event, prefix, index=None): if type(event) is MappedEvent: try: prefix = event._collectionmap[prefix] except KeyError: pass Object._original_init(self, event, prefix, index=index)
def analyze(self, event): #================ read needed collections/objects here ==================== Muons = Collection(event, "Muon") Flags = Object(event, "Flag") MET = Object(event, "MET") CaloMET = Object(event, "CaloMET") #================ analyze each event ====================================== self.BaseLineTest_h.Fill(0) self.MET_h.Fill(MET.pt) self.CaloMET_h.Fill(CaloMET.pt) #print event.event, CaloMET.pt if self.pass_event_filter(Flags): self.BaseLineTest_h.Fill(1) SelMuons = self.sel_muons(Muons) if len(SelMuons) == 2: ZmumuCand = self.sel_zmumu_cand(SelMuons) if ZmumuCand is not None: ZmumuCandMass = ZmumuCand.M() self.ZmumuCand_mass_h.Fill(ZmumuCandMass) if ZmumuCandMass > 81 and ZmumuCandMass < 101: ZmumuCandPt = ZmumuCand.Pt() self.MET_with_Z_h.Fill(MET.pt) self.METphi_with_Z_h.Fill(MET.phi) dPhiZMET = MET.phi - ZmumuCand.Phi() METPara = MET.pt * math.cos(dPhiZMET) METVert = MET.pt * math.sin(dPhiZMET) UPara = -METPara - ZmumuCandPt UVert = -METVert self.METPara_h.Fill(METPara) self.METVert_h.Fill(METVert) self.UPara_ratio_vs_Zpt_h.Fill(ZmumuCandPt, -UPara / ZmumuCandPt) self.UPara_vs_Zpt_h.Fill(ZmumuCandPt, UPara) self.UVert_vs_Zpt_h.Fill(ZmumuCandPt, UVert) self.CaloMET_with_Z_h.Fill(CaloMET.pt) self.CaloMETphi_with_Z_h.Fill(CaloMET.phi) dPhiZCaloMET = CaloMET.phi - ZmumuCand.Phi() CaloMETPara = CaloMET.pt * math.cos(dPhiZCaloMET) CaloMETVert = CaloMET.pt * math.sin(dPhiZCaloMET) UCaloPara = -CaloMETPara - ZmumuCandPt UCaloVert = -CaloMETVert self.CaloMETPara_h.Fill(CaloMETPara) self.CaloMETVert_h.Fill(CaloMETVert) self.UCaloPara_ratio_vs_Zpt_h.Fill( ZmumuCandPt, -UCaloPara / ZmumuCandPt) self.UCaloPara_vs_Zpt_h.Fill(ZmumuCandPt, UCaloPara) self.UCaloVert_vs_Zpt_h.Fill(ZmumuCandPt, UCaloVert) #return true to move on to the next module. return false to go to the next event return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" HLT = Object(event, "HLT") flag = Object(event, 'Flag') good_MET = flag.goodVertices and flag.globalSuperTightHalo2016Filter and flag.HBHENoiseFilter and flag.HBHENoiseIsoFilter and flag.EcalDeadCellTriggerPrimitiveFilter and flag.BadPFMuonFilter if (self.year == 2016): good_HLT = HLT.PFHT800 or HLT.PFHT900 or HLT.Mu50 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon175 or HLT.Ele27_WPTight_Gsf elif (self.year == 2017): good_HLT = HLT.PFHT780 or HLT.PFHT890 or HLT.Mu50 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon200 or HLT.Ele35_WPTight_Gsf elif (self.year == 2018): good_HLT = HLT.PFHT780 or HLT.PFHT890 or HLT.Mu50 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Ele35_WPTight_Gsf else: print "Please specify the year: possible choices are 2016, 2017 or 2018" return good_MET and good_HLT
def analyze(self, event): met = Object(event, "MET") hlt = Object(event, "HLT") refAccept = hlt.Ele27_eta2p1_WPTight_Gsf sigAccept = hlt.PFMET170_HBHECleaned self.h_passreftrig.Fill(refAccept) if not refAccept: return False self.h_met_all.Fill(met.pt) if sigAccept: self.h_met_passtrig.Fill(met.pt) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" ## Getting objects jets = Collection(event, "Jet") fatjets = Collection(event, "FatJet") subjets = Collection(event, "SubJet") resolves = Collection(event, "ResolvedTop") met = Object(event, self.metBranchName) self.Clear() ## Selecting objects self.FatJet_Stop0l = map(self.SelDeepAK8, fatjets) self.ResolvedTop_Stop0l = map(lambda x: self.SelDeepResolved(x, jets), resolves) temp = self.ResolvedTop_Stop0l self.ResovleOverlapDeepAK8(resolves, fatjets, jets, subjets) # if (temp != self.ResolvedTop_Stop0l) : # print (temp, self.ResolvedTop_Stop0l) self.nTop = sum([i for i in self.FatJet_Stop0l if i == 1]) self.nW = sum([1 for i in self.FatJet_Stop0l if i == 2]) self.nResolved = sum(self.ResolvedTop_Stop0l) self.ISRJetidx = self.GetISRJets(fatjets, subjets, met.phi) ISRJetPt = fatjets[self.ISRJetidx].pt if self.ISRJetidx != -1 else 0 ### Store output self.out.fillBranch("FatJet_Stop0l", self.FatJet_Stop0l) self.out.fillBranch("ResolvedTop_Stop0l", self.ResolvedTop_Stop0l) self.out.fillBranch("Stop0l_nTop", self.nTop) self.out.fillBranch("Stop0l_nW", self.nW) self.out.fillBranch("Stop0l_nResolved", self.nResolved) self.out.fillBranch("Stop0l_ISRJetIdx", self.ISRJetidx) self.out.fillBranch("Stop0l_ISRJetPt", ISRJetPt) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" Generator = Object(event, "Generator") LHEPdfWeight = Collection(event, 'LHEPdfWeight') LHEScaleWeight = Collection(event, 'LHEScaleWeight') PSWeight = Collection(event, 'PSWeight') if not len(LHEPdfWeight) == 0: self.h_PDFweight.SetNameTitle('h_PDFweight', 'h_PDFweight') self.h_PDFweight.SetBins(len(LHEPdfWeight), 0, len(LHEPdfWeight)) for pdfw, i in zip(LHEPdfWeight, xrange(1, len(LHEPdfWeight)+1)): self.h_PDFweight.GetXaxis().SetBinLabel(i, 'pdf['+str(i)+']') self.h_PDFweight.AddBinContent(i, pdfw.__getattr__("")) if not len(LHEScaleWeight) == 0: #LHE scale variation weights (w_var / w_nominal); [0] is muR=0.5 muF=0.5 hdamp=mt=272.7225 ; [1] is muR=0.5 muF=1 hdamp=mt=272.7225 ; [2] is muR=0.5 muF=2 hdamp=mt=272.7225 ; [3] is muR=1 muF=0.5 hdamp=mt=272.7225 ; [4] is muR=1 muF=1 hdamp=mt=272.7225 ; [5] is muR=1 muF=2 hdamp=mt=272.7225 ; [6] is muR=2 muF=0.5 hdamp=mt=272.7225 ; [7] is muR=2 muF=1 hdamp=mt=272.7225 ; [8] is muR=2 muF=2 hdamp=mt=272.7225 self.h_q2weight.Fill('muR=0.5 muF=0.5', LHEScaleWeight[0].__getattr__("")) self.h_q2weight.Fill('muR=0.5 muF=1', LHEScaleWeight[1].__getattr__("")) self.h_q2weight.Fill('muR=0.5 muF=2', LHEScaleWeight[2].__getattr__("")) self.h_q2weight.Fill('muR=1 muF=0.5', LHEScaleWeight[3].__getattr__("")) self.h_q2weight.Fill('muR=1 muF=2', LHEScaleWeight[5].__getattr__("")) self.h_q2weight.Fill('muR=2 muF=0.5', LHEScaleWeight[6].__getattr__("")) self.h_q2weight.Fill('muR=2 muF=1', LHEScaleWeight[7].__getattr__("")) self.h_q2weight.Fill('muR=2 muF=2', LHEScaleWeight[8].__getattr__("")) if len(PSWeight) > 1: #PS weights (w_var / w_nominal); [0] is ISR=0.5 FSR=1; [1] is ISR=1 FSR=0.5; [2] is ISR=2 FSR=1; [3] is ISR=1 FSR=2 self.h_psweight.Fill('ISRdown', PSWeight[0].__getattr__("")) self.h_psweight.Fill('FSRdown', PSWeight[1].__getattr__("")) self.h_psweight.Fill('ISRup', PSWeight[2].__getattr__("")) self.h_psweight.Fill('FSRup', PSWeight[3].__getattr__("")) else: self.h_psweight.Fill('ISRdown', PSWeight[0].__getattr__("")) self.h_psweight.Fill('FSRdown', PSWeight[0].__getattr__("")) self.h_psweight.Fill('ISRup', PSWeight[0].__getattr__("")) self.h_psweight.Fill('FSRup', PSWeight[0].__getattr__("")) self.h_genweight.Fill("SumEvents", 1) self.h_genweight.Fill("GenWeights", Generator.weight) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" newmetmodule = -1 newmetphi = -1 met = Object(event, "MET") met_px = met.pt * math.cos(met.phi) met_py = met.pt * math.sin(met.phi) if self.kind == 'Up': met_px_UnclEnUp = met_px + getattr(event, "MET_MetUnclustEnUpDeltaX") met_py_UnclEnUp = met_py + getattr(event, "MET_MetUnclustEnUpDeltaY") met_pt_UnclEnUp = math.sqrt(met_px_UnclEnUp**2 + met_py_UnclEnUp**2) met_phi_UnclEnUp = math.atan2(met_py_UnclEnUp, met_px_UnclEnUp) newmet_phi_UnclEnUp = self.FixAngle(met.phi + self.FixAngle( met_phi_UnclEnUp - getattr(event, "RawMET_phi") )) newmetmodule = met_pt_UnclEnUp newmetphi = newmet_phi_UnclEnUp elif self.kind == 'Dn' or self.kind == 'Down': met_px_UnclEnDn = met_px - getattr(event, "MET_MetUnclustEnUpDeltaX") met_py_UnclEnDn = met_py - getattr(event, "MET_MetUnclustEnUpDeltaY") met_pt_UnclEnDn = math.sqrt(met_px_UnclEnDn**2 + met_py_UnclEnDn**2) met_phi_UnclEnDn = math.atan2(met_py_UnclEnDn, met_px_UnclEnDn) newmet_phi_UnclEnDn = self.FixAngle(met.phi + self.FixAngle( met_phi_UnclEnDn - getattr(event, "RawMET_phi") )) newmetmodule = met_pt_UnclEnDn newmetphi = newmet_phi_UnclEnDn self.out.fillBranch("MET_pt", newmetmodule) self.out.fillBranch("MET_phi", newmetphi) return True
def analyze(self, event): isMC = event.run == 1 electrons = Collection(event, "Electron") muons = Collection(event, "Muon") met = Object(event, "MET") #lepton selection wElectrons = [ x for x in electrons if (x.cutBased == 4 and x.miniPFRelIso_all < 0.1 and x.convVeto) ] #loose pt cut for veto wMuons = [ x for x in muons if (x.mediumId and x.miniPFRelIso_all < 0.2 and x.sip3d < 4) ] #loose pt cut for veto wMuons.sort(key=lambda x: x.pt, reverse=True) wElectrons.sort(key=lambda x: x.pt, reverse=True) Vtype = -1 vLeptons = [] # decay products of V if len(wElectrons) + len(wMuons) == 1: if len(wMuons) == 1: Vtype = 0 vLeptons = [wMuons[0]] if len(wElectrons) == 1: Vtype = 1 vLeptons = [wElectrons[0]] else: return False self.out.fillBranch("L_T", vLeptons[0].pt + met.pt) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" electrons = Collection(event, "Electron") muons = Collection(event, "Muon") jets = Collection(event, "Jet") fatjets = Collection(event, "FatJet") PV = Object(event, "PV") isGoodPV = (PV.ndof>4 and abs(PV.z)<20 and math.hypot(PV.x, PV.y)<2) goodMu = list(filter(lambda x : x.tightId and x.pt > 55 and abs(x.eta) < 2.4 and x.miniPFRelIso_all < 0.1, muons)) highMu = list(filter(lambda x : x.highPtId == 2 and x.pt > 55 and abs(x.eta) < 2.4 and x.miniPFRelIso_all < 0.1, muons)) looseMu = list(filter(lambda x : x.looseId and not x.tightId and x.pt > 35 and x.miniPFRelIso_all < 0.4 and abs(x.eta) < 2.4, muons)) goodEle = list(filter(lambda x : x.mvaFall17V2noIso_WP90 and x.miniPFRelIso_all < 0.1 and ((abs(x.eta) < 1.4442) or (abs(x.eta) > 1.566 and abs(x.eta) < 2.5)), electrons)) looseEle = list(filter(lambda x : x.mvaFall17V2noIso_WPL and not x.mvaFall17V2noIso_WP90 and x.miniPFRelIso_all < 0.4 and x.pt > 35 and ((abs(x.eta) < 1.4442) or (abs(x.eta) > 1.566 and abs(x.eta)< 2.5)), electrons)) goodJet = list(filter(lambda x : x.jetId >= 2 and abs(x.eta) < 2.4 and x.pt > 100, jets)) isGoodEvent = (((len(goodMu) == 1) and (len(goodEle) == 0)) and len(goodJet)>=1 and len(fatjets) > 1) isHighEvent = (((len(highMu) == 1) and (len(goodEle) == 0)) and len(goodJet)>=1 and len(fatjets) > 1) self.out.fillBranch("isTight", int(isGoodEvent and isGoodPV)) self.out.fillBranch("isMCTight", int(isGoodEvent and isGoodPV and (goodMu[0].genPartFlav == 1 or goodMu[0].genPartFlav == 15))) self.out.fillBranch("isHighPt", int(isHighEvent and isGoodPV)) self.out.fillBranch("isMCHighPt", int(isHighEvent and isGoodPV and (highMu[0].genPartFlav == 1 or highMu[0].genPartFlav == 15))) return isGoodPV and (isGoodEvent or isHighEvent)
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" jets = Collection(event, self.jetBranchName) met = Object(event, "MET") jets_pt_nom = [] (met_px, met_py) = (met.pt * math.cos(met.phi), met.pt * math.sin(met.phi)) (met_px_nom, met_py_nom) = (met_px, met_py) met_px_nom = met_px met_py_nom = met_py rho = getattr(event, self.rhoBranchName) for jet in jets: jet_pt = jet.pt jet_pt = self.jetReCalibrator.correct(jet, rho) jet_pt_nom = jet_pt # don't smear resolution in data if jet_pt_nom < 0.0: jet_pt_nom *= -1.0 jets_pt_nom.append(jet_pt_nom) if jet_pt_nom > 15.: jet_cosPhi = math.cos(jet.phi) jet_sinPhi = math.sin(jet.phi) met_px_nom = met_px_nom - (jet_pt_nom - jet.pt) * jet_cosPhi met_py_nom = met_py_nom - (jet_pt_nom - jet.pt) * jet_sinPhi self.out.fillBranch("%s_pt_nom" % self.jetBranchName, jets_pt_nom) self.out.fillBranch("MET_pt_nom", math.sqrt(met_px_nom**2 + met_py_nom**2)) self.out.fillBranch("MET_phi_nom", math.atan2(met_py_nom, met_px_nom)) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" metUnclustX = getattr(event, "MET_MetUnclustEnUpDeltaX") metUnclustY = getattr(event, "MET_MetUnclustEnUpDeltaY") for metType in self.metCollections: try: met = Object(event, metType) except AttributeError: continue met_px = met.pt * math.cos(met.phi) met_py = met.pt * math.sin(met.phi) sumEt = met.sumEt if self.kind == 'Up': met_px_UnclEn = met_px + metUnclustX met_py_UnclEn = met_py + metUnclustY elif self.kind == 'Dn' or self.kind == 'Down': met_px_UnclEn = met_px - metUnclustX met_py_UnclEn = met_py - metUnclustY met_pt_UnclEn = math.sqrt(met_px_UnclEn**2 + met_py_UnclEn**2) met_phi_UnclEn = self.FixAngle( math.atan2(met_py_UnclEn, met_px_UnclEn)) self.out.fillBranch(metType + "_pt", met_pt_UnclEn) self.out.fillBranch(metType + "_phi", met_phi_UnclEn) return True
def analyze(self, event): goodEvent = False isVetoMu = False isVetoEle = False """process event, return True (go to next module) or False (fail, go to next event)""" electrons = Collection(event, "Electron") muons = Collection(event, "Muon") jets = Collection(event, "Jet") fatjets = Collection(event, "FatJet") PV = Object(event, "PV") goodEle = [] goodJet = [] eventSum = ROOT.TLorentzVector() isGoodPV = (PV.ndof>4 and abs(PV.z)<20 and math.hypot(PV.x, PV.y)<2) goodMu = list(filter(lambda x : x.tightId and abs(x.eta) < 2.4 and x.miniPFRelIso_all < 0.1, muons)) looseMu = list(filter(lambda x : x.looseId and not x.tightId and x.pt > 35 and x.miniPFRelIso_all < 0.4 and abs(x.eta) < 2.4, muons)) goodEle = list(filter(lambda x : x.mvaFall17V2noIso_WP90 and x.miniPFRelIso_all < 0.1 and ((abs(x.eta) < 1.4442) or (abs(x.eta) > 1.566 and abs(x.eta) < 2.5)), electrons)) looseEle = list(filter(lambda x : x.mvaFall17V2noIso_WPL and not x.mvaFall17V2noIso_WP90 and x.miniPFRelIso_all < 0.4 and x.pt > 35 and ((abs(x.eta) < 1.4442) or (abs(x.eta) > 1.566 and abs(x.eta)< 2.5)), electrons)) goodJet = list(filter(lambda x : x.jetId >= 2 and abs(x.eta) < 2.4 and x.pt > 25, jets)) for j in goodJet: eventSum += j.p4() self.out.fillBranch("HT_eventHT", eventSum.Pt()) isGoodEvent = ((((len(goodMu) >= 1) and (len(goodEle) == 0)) or ((len(goodMu) == 0) and (len(goodEle) >= 1))) and len(goodJet)>=1) goodEvent = isGoodPV and isGoodEvent #if(goodEvent): #print "No. Mu = ", len(goodMu), " No. Ele = ", len(goodEle), " veto Mu is ", not isVetoMu, " veto Ele is ", not isVetoEle, " No. barrel jets = ", len(goodJet) return goodEvent
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" ## Getting objects jets = Collection(event, "Jet") #if self.isData == False: genjets = Collection(event, "GenJet") met = Object(event, self.metBranchName) jetNearMETInd, MMJetDPhi = -1, -1 for iJ in range(1, len(jets)): if iJ > 2: continue dPhi = abs(deltaPhi(jets[iJ].phi, met.phi)) if (MMJetDPhi < 0 or dPhi < MMJetDPhi): MMJetDPhi = dPhi jetNearMETInd = iJ if jetNearMETInd < 0: return True pJ = jets[jetNearMETInd] passFilter = len(jets) > jetNearMETInd pseudoGenPT = self.addFourVec(met, pJ).Pt() MMPseudoResp = pJ.pt / pseudoGenPT if pseudoGenPT > 0 else 999 # True response info #print "isQCD: ", self.isQCD mmOut = [] #if self.isQCD == True or self.isQCDOrig == True: #if isData ==False: mmOut = self.getQCDRespTailCorrector(jets, genjets, met) #else: # mmOut = [-1, -1.0, -1] trueRespInd, trueResp = mmOut[0], mmOut[1] #print "trueResp: ", trueRespInd, trueResp trueRespFlv = 99 trueRespGenPT = -1.0 if trueRespInd >= 0: for iG in xrange(len(genjets)): gjet = genjets[iG] if iG != trueRespInd: continue trueRespGenPT = gjet.pt trueRespFlv = gjet.partonFlavour break #if self.isQCDOrig: b = [] for iB in xrange(self.nBootstraps): b.append(1) self.out.fillBranch("nBootstrapWeight", self.nBootstraps) self.out.fillBranch("bootstrapWeight", b) ### Store output self.out.fillBranch("pseudoResp", MMPseudoResp) self.out.fillBranch("pseudoRespCSV", pJ.btagDeepB) self.out.fillBranch("pseudoRespPseudoGenPT", pseudoGenPT) self.out.fillBranch("pseudoRespPassFilter", passFilter) self.out.fillBranch("trueResp", trueResp if trueRespInd >= 0 else -1) self.out.fillBranch("trueRespFlv", trueRespFlv) self.out.fillBranch("trueRespGenPT", trueRespGenPT) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" jets = Collection(event, self.jetBranchName ) met = Object(event, "MET") jets_pt_raw = [] jets_pt_nom = [] jets_mass_raw = [] jets_mass_nom = [] jets_corr_JEC = [] ( met_px, met_py ) = ( met.pt*math.cos(met.phi), met.pt*math.sin(met.phi) ) ( met_px_nom, met_py_nom ) = ( met_px, met_py ) met_px_nom = met_px met_py_nom = met_py rho = getattr(event, self.rhoBranchName) for jet in jets: #jet pt and mass corrections jet_pt=jet.pt jet_mass=jet.mass #redo JECs if desired if hasattr(jet, "rawFactor"): jet_rawpt = jet_pt * (1 - jet.rawFactor) jet_rawmass = jet_mass * (1 - jet.rawFactor) else: jet_rawpt = -1.0 * jet_pt #If factor not present factor will be saved as -1 jet_rawmass = -1.0 * jet_mass #If factor not present factor will be saved as -1 if self.redoJEC : (jet_pt, jet_mass) = self.jetReCalibrator.correct(jet,rho) jets_pt_raw.append(jet_rawpt) jets_mass_raw.append(jet_rawmass) jets_corr_JEC.append(jet_pt/jet_rawpt) jet_pt_nom = jet_pt # don't smear resolution in data if jet_pt_nom < 0.0: jet_pt_nom *= -1.0 jets_pt_nom .append(jet_pt_nom) jet_mass_nom = jet_mass if jet_mass_nom < 0.0: jet_mass_nom *= -1.0 jets_mass_nom .append(jet_mass_nom) if jet_pt_nom > 15.: jet_cosPhi = math.cos(jet.phi) jet_sinPhi = math.sin(jet.phi) met_px_nom = met_px_nom - (jet_pt_nom - jet.pt)*jet_cosPhi met_py_nom = met_py_nom - (jet_pt_nom - jet.pt)*jet_sinPhi self.out.fillBranch("%s_pt_raw" % self.jetBranchName, jets_pt_raw) self.out.fillBranch("%s_pt_nom" % self.jetBranchName, jets_pt_nom) self.out.fillBranch("%s_mass_raw" % self.jetBranchName, jets_mass_raw) self.out.fillBranch("%s_mass_nom" % self.jetBranchName, jets_mass_nom) self.out.fillBranch("MET_pt_nom", math.sqrt(met_px_nom**2 + met_py_nom**2)) self.out.fillBranch("MET_phi_nom", math.atan2(met_py_nom, met_px_nom)) self.out.fillBranch("%s_corr_JEC" % self.jetBranchName, jets_corr_JEC) return True
def analyze(self, event): HLT = Object(event, "HLT") if (HLT.IsoMu24 or HLT.IsoMu27 or HLT.Mu50): return False return True
def analyze(self, event): PV = Object(event, "PV") self.quantities.HT = event.SoftActivityJetHT self.quantities.PV = ROOT.TVector3(PV.x, PV.y, PV.z) self.quantitiesBranch.Fill() return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" jets = Collection(event, self.jetBranchName) mets = [] met_px = [] met_py = [] for mid, met in enumerate(self.metCollections): mets.append(Object(event, met)) met_px.append(mets[mid].pt * math.cos(mets[mid].phi)) met_py.append(mets[mid].pt * math.sin(mets[mid].phi)) jets_pt_newlist = [] rawFactor_newlist = [] otherjets = [] otherjets_pt_newlist = [] for jname in self.otherJetBranches: otherjets.append(Collection(event, jname)) otherjets_pt_newlist.append([]) rho = getattr(event, self.rhoBranchName) for jid, jet in enumerate(jets): # Apply new correction (this includes undoing previous correction first) newjet_pt = self.jetReCalibrator.correct(jet, rho)[0] # Rewrite new correction factor rawFactor_newlist.append(1. - ((jet.pt * (1. - jet.rawFactor)) / newjet_pt)) if newjet_pt < 0.0: newjet_pt *= -1.0 jets_pt_newlist.append(newjet_pt) if newjet_pt > 15.: jet_cosPhi = math.cos(jet.phi) jet_sinPhi = math.sin(jet.phi) for mid, met in enumerate(self.metCollections): met_px[mid] = met_px[mid] - (newjet_pt - jet.pt) * jet_cosPhi met_py[mid] = met_py[mid] - (newjet_pt - jet.pt) * jet_sinPhi for oj, jname in enumerate(self.otherJetBranches): for ojet in otherjets[oj]: if jid == ojet.jetIdx: otherjets_pt_newlist[oj].append(newjet_pt) self.out.fillBranch("%s_pt" % self.jetBranchName, jets_pt_newlist) self.out.fillBranch("%s_rawFactor" % self.jetBranchName, rawFactor_newlist) for oj, jname in enumerate(self.otherJetBranches): self.out.fillBranch("%s_pt" % jname, otherjets_pt_newlist[oj]) for mid, met in enumerate(self.metCollections): self.out.fillBranch("%s_pt" % met, math.sqrt(met_px[mid]**2 + met_py[mid]**2)) self.out.fillBranch("%s_phi" % met, math.atan2(met_py[mid], met_px[mid])) return True
def CheckisData(self, event): if self.isData is not None: return False run = Object(event, "run") if run > 1: self.isData = True else: self.isData = False return True
def correctJetMET_Data(self, event): """Process data event.""" ###print ">>> %8s "%event.event + '-'*80 # NOMINAL VALUES jets_pt_nom = [] if self.corrMET: met = Object(event, self.metBranchName) met_px_nom, met_py_nom = met.pt * cos(met.phi), met.pt * sin( met.phi) # APPLY JEC per jet jets = Collection(event, self.jetBranchName) rho = getattr(event, self.rhoBranchName) for jet in jets: # RAW VALUES jet_pt0 = jet.pt if hasattr(jet, 'rawFactor'): jet_pt_raw = jet_pt0 * (1 - jet.rawFactor) else: jet_pt_raw = -1.0 * jet_pt0 # if factor not present factor will be saved as -1 # CALIBRATE - apply JES corrections if self.redoJEC: jet_pt_nom, jet_mass_nom = self.jetReCalibrator.correct( jet, rho) jet.pt = jet_pt_nom jet.mass = jet_mass_nom else: jet_pt_nom = jet.pt jet_mass_nom = jet.mass jets_pt_nom.append(jet_pt_nom) ###print "%10.4f %10.4f %10.5f %10.5f"%(jet_pt_raw,jet_pt_nom,jet.eta,jet.rawFactor) ###print "%10.4f %8.4f %8.4f %10.6f %10.6f"%(jet_pt_raw, jet_pt0, jet_pt_nom, jet.rawFactor, jet_pt_nom/jet_pt_raw-1.) #### UPDATE JET in event ###if self.updateEvent: ### getattr(event,self.jetBranchName+'_pt')[jet._index] = jet_pt_nom # PROPAGATE JES corrections to MET if self.corrMET and jet_pt_nom > self.unclEnThreshold: jet_cosPhi = cos(jet.phi) jet_sinPhi = sin(jet.phi) met_px_nom = met_px_nom - (jet_pt_nom - jet_pt0) * jet_cosPhi met_py_nom = met_py_nom - (jet_pt_nom - jet_pt0) * jet_sinPhi # PREPARE MET for return if self.corrMET: met_nom = TLorentzVector(met_px_nom, met_py_nom, 0, sqrt(met_px_nom**2 + met_py_nom**2)) ###if self.updateEvent: ### setattr(event,self.metBranchName+'_pt', met_vars['nom'].Pt()) ### setattr(event,self.metBranchName+'_phi', met_vars['nom'].Phi()) return jets_pt_nom, met_nom return jets_pt_nom
def analyze(self, event): if not self.isData: pileUp = Object(event, "Pileup") puWeight = self.pileUpWeight.GetBinContent( self.pileUpWeight.FindBin(pileUp.nPU)) self.out.fillBranch("puWeight", puWeight) return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" self.eventCounter += 1 if self.eventCounter > self.eventLimit > -1: return False ################################## # Event Collections and Objects # ################################## muons = Collection(event, "Muon") electrons = Collection(event, "Electron") jets = Collection(event, "Jet") hltObj = Object(event, "HLT") # object with only the trigger branches in that event met = Object(event, "MET") # genMet = Object(event, "GenMET") metPt = getattr(met, "pt") metPhi = getattr(met, "phi") # genMetPt = getattr(genMet, "pt") # genMetPhi = getattr(genMet, "phi") nJetPass, JetPassIdx, nBtagPass = self.jetCriteria(jets) nMuonPass, MuonPassIdx = self.muonCriteria(muons) nElPass, ElPassIdx = self.electronCriteria(electrons) if nJetPass > 5 and nBtagPass > 1: if nMuonPass == 1 and nElPass == 0: jetHt = 0 for nj, jet in enumerate(jets): jetHt += jet.pt self.out.fillBranch("Jet2_HT", jetHt) return True elif nMuonPass == 0 and nElPass == 1: jetHt = 0 for nj, jet in enumerate(jets): jetHt += jet.pt self.out.fillBranch("Jet2_HT", jetHt) return True else: return False else: return False return True
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" HLT = Object(event, "HLT") run = Object(event, "run") if self.year == '2016' and self.runP != 'H': if run.__getattr__('') > 274954: good_HLT = HLT.PFHT800 or HLT.PFHT900 or HLT.Mu50 or HLT.TkMu50 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon175 or HLT.Ele27_WPTight_Gsf else: good_HLT = HLT.PFHT800 or HLT.PFHT900 or HLT.Mu50 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon175 or HLT.Ele27_WPTight_Gsf elif self.year == '2016' and self.runP == 'H': good_HLT = HLT.PFHT900 or HLT.Mu50 or HLT.TkMu50 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon175 or HLT.Ele27_WPTight_Gsf elif self.year == '2017' and self.runP != 'B': good_HLT = HLT.PFHT780 or HLT.PFHT890 or HLT.Mu50 or HLT.OldMu100 or HLT.TkMu100 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon200 or HLT.Ele35_WPTight_Gsf elif self.year == '2017' and self.runP == 'B': good_HLT = HLT.PFHT780 or HLT.PFHT890 or HLT.Mu50 or HLT.Ele35_WPTight_Gsf elif self.year == '2018': good_HLT = HLT.PFHT780 or HLT.PFHT890 or HLT.Mu50 or HLT.OldMu100 or HLT.TkMu100 or HLT.Ele115_CaloIdVT_GsfTrkIdT or HLT.Photon200 or HLT.Ele35_WPTight_Gsf else: print "Please specify the year: possible choices are 2016, 2017 or 2018" return good_HLT
def __init__(self, jetCollection=lambda event: Collection(event, "Jet"), leptonCollection=lambda event: Collection(event, "Muon"), metInput=lambda event: Object(event, "MET"), outputName="EventObservables", globalOptions={"isData": False}): self.globalOptions = globalOptions self.jetCollection = jetCollection self.leptonCollection = leptonCollection self.metInput = metInput self.outputName = outputName