def __call__(self, event): f1 = particle(px=event.px3 * 1000., py=event.py3 * 1000., pz=event.pz3 * 1000., E=event.E_3 * 1000.) f1.set_px_py_pz_e(f1.px, f1.py, f1.pz, f1.E) f2 = particle( px=event.px4 * 1000., py=event.py4 * 1000., pz=event.pz4 * 1000., E=event.E_4 * 1000., ) f2.set_px_py_pz_e(f2.px, f2.py, f2.pz, f2.E) b = particle( px=event.px5 * 1000., py=event.py5 * 1000., pz=event.pz5 * 1000., E=event.E_5 * 1000., ) b.set_px_py_pz_e(b.px, b.py, b.pz, b.E) event.f1 = f1 event.f2 = f2 event.b = b
def __call__(self, event): if random.getrandbits(1): event.f1, event.f2 = event.f2, event.f1 #flip e<->mu decay tauola_call = [] mother = event.f1() + event.f2() boost = mother.BoostVector() for fermion in [event.f1(), event.f2()]: fermion.Boost(-boost) try: scale = sqrt(fermion.E()**2. - self.tau_mass**2.) / fermion.P() except ValueError: print 'Failed rescaling fermion of energy {0} mass {1} momentum {2}'.format( fermion.E(), fermion.M(), fermion.P()) event.__break__ = True return fermion.SetPxPyPzE(fermion.Px() * scale, fermion.Py() * scale, fermion.Pz() * scale, fermion.E()) fermion.Boost(boost) tauola_call += [ fermion.Px() / 1000., fermion.Py() / 1000., fermion.Pz() / 1000. ] #GEV for tauola tauola_call += [25] result = self.tauola.leptonic_decay(*tauola_call) event.l1 = particle() event.l2 = particle() event.l1.set_px_py_pz_e(*[energy * 1000. for energy in result[:4]]) event.l2.set_px_py_pz_e(*[energy * 1000. for energy in result[4:]]) event.missing_energy_vector = mother - event.l1() - event.l2() event.l1_pt = event.l1().Pt() event.l1_eta = event.l1().Eta() event.l1_phi = event.l1().Phi() event.l1_E = event.l1().E() event.l2_pt = event.l2().Pt() event.l2_eta = event.l2().Eta() event.l2_phi = event.l2().Phi() event.l2_E = event.l2().E()
def build_truth_tree(\ mc_n, mc_pt, mc_eta, mc_phi, mc_m, mc_charge, mc_pdgId, mc_parent_index, mc_status, pdgIds = None, ): truth = {} if pdgIds is not None: indices = [n for n in range(mc_n) if mc_pdgId[n] in pdgIds] else: indices = range(mc_n) for n in indices: truth[n] = node(\ [], [], particle(\ pt = mc_pt[n], eta = mc_eta[n], phi = mc_phi[n], m = mc_m[n], charge = mc_charge[n], pdgId = mc_pdgId[n], status = mc_status[n], )) for index,p in truth.items(): p.add_parents(*[truth[parent] for parent in mc_parent_index[index] if parent in truth]) return truth
def __call__(self,event): super(collect_tracks,self).__call__(event) event.trks = {} for trk in range(event.__dict__[self.collection_name+'n']): event.trks[trk] = particle(\ **dict((name,event.__dict__[self.collection_name+name][trk]) for name in self.names) ) for trk in event.trks.values(): trk.jet_owner = None trk.jet_owner_dR = 10000. trk.set_pt_eta_phi_m( trk.pt, trk.eta, trk.phi, 0., ) trk.passed_b_selection = all([ trk.pt>1000., abs(trk.d0)<1., abs(trk.z0_wrtPV)*sin(trk().Theta())<1.5, trk.nPixHits+trk.nBLHits>=2, trk.nBLHits>=1, ])
def __call__(self, event): super(collect_taus, self).__call__(event) #Collect electrons event.taus = {} for tau in range(event.__dict__[self.collection_name + 'n']): event.taus[tau] = particle(\ **dict((name,event.__dict__[self.collection_name+name][tau]) for name in self.names) ) for tau in event.taus.values(): tau.set_pt_eta_phi_m(tau.Et, tau.eta, tau.phi, 1777.) #Define selections for tau in event.taus.values(): tau.passed_preselection = all([ tau.Et > 15000., tau.author == 1 or tau.author == 3, tau.JetBDTSigMedium == 1, abs(tau.eta) < 2.47 and tau.track_n > 0, # and abs(tau.track_eta[0])<2.47, tau.numTrack == 1 or tau.numTrack == 3, abs(tau.charge - 1.) < 0.1, not (tau.numTrack == 1 and tau.EleBDTMedium == 1), tau.muonVeto == 0 ]) tau.passed_selection = tau.passed_preselection return
def __call__(self, event): super(collect_electrons, self).__call__(event) #code.interact(local=locals()) #Collect electrons event.electrons = {} for el in range(event.__dict__[self.collection_name + 'n']): event.electrons[el] = particle(\ **dict((name,event.__dict__[self.collection_name+name][el]) for name in self.names) ) #set electron direction for electron in event.electrons.values(): if (electron.nPixHits + electron.nSCTHits) < 4: eta = electron.cl_eta phi = electron.cl_phi pt = electron.cl_pt E = electron.cl_E else: eta = electron.tracketa phi = electron.trackphi try: pt = electron.cl_E / cosh(electron.tracketa) except ArithmeticError: pt = -999. E = electron.cl_E electron.pt = pt electron.eta = eta electron.phi = phi electron.E = E #Apply electron collections self.apply_corrections(event) #Define selections for electron in event.electrons.values(): electron.passed_preselection_taus = all([ electron.is_loosePP, electron.pt_corrected > self.min_pT, abs(electron.cl_eta) < 1.37 or (1.52 < abs(electron.cl_eta) < 2.47) if self.cut_crack else abs(electron.cl_eta) < 2.47, electron.author == 1 or electron.author == 3, (electron.OQ & 1446) == 0 ]) electron.passed_preselection_embedding = electron.passed_preselection_taus electron.passed_preselection = all([ electron.passed_preselection_taus, electron.is_mediumPP, ]) electron.passed_selection = all([ electron.passed_preselection, electron.etcone20_corrected / electron.pt_corrected < 0.09, electron.ptcone40 / electron.pt_corrected < 0.17, True ]) event.__dict__.update( list_attributes(event.electrons, self.new_collection_names.keys(), self.collection_name))
def __call__(self, event): super(identify_pythia_truth, self).__call__(event) event.A = [ p for p in event.truth.values() if abs(p().pdgId) == 25 and p().status == 3 ][0] try: event.f1, event.f2 = [ p() for p in event.truth.values() if abs(p().pdgId) in [5, 15] and p in event.A.children and p().status == 3 ] except ValueError: print[ p().pdgId for p in event.truth.values() if abs(p().pdgId) in [5, 15] and p in event.A.children and p().status == 3 ] raise event.A = event.A() bs = [ p for p in event.truth.values() if abs(p().pdgId) == 5 and p().status == 2 and not p.parents ] if len(bs) > 4: event.b1, event.b2, event.b3, event.b4 = tuple([ b() for b in sorted(bs, key=lambda b: b()().Pt(), reverse=True)[:4] ]) else: event.b1,event.b2,event.b3,event.b4 = tuple([b() for b in sorted(bs,key=lambda b: b()().Pt(),reverse=True)]+[ particle(\ pt = -10., eta = -10., phi = -10., m = -10., charge = -10. ) for i in range(4-len(bs))]) for item,name in [\ (event.b1,'b1_'), (event.b2,'b2_'), (event.b3,'b3_'), (event.b4,'b4_'), (event.A,'A_'), (event.f1,'f1_'), (event.f2,'f2_'), ]: event.__dict__[name + 'pt'] = item().Pt() event.__dict__[name + 'eta'] = item().Eta() event.__dict__[name + 'phi'] = item().Phi() event.__dict__[name + 'm'] = item().M()
def __call__(self, event): super(collect_truth_jets, self).__call__(event) event.truth_jets = {} for jet_n in range(event.__dict__[self.collection_name + 'n']): jet = particle(\ **dict((name,event.__dict__[self.collection_name+name][jet_n]) for name in self.names) ) jet.set_pt_eta_phi_e(jet.pt, jet.eta, jet.phi, jet.E) event.truth_jets[jet_n] = jet
def __call__(self, event): super(collect_muons, self).__call__(event) #Collect muons event.muons = {} for mu in range(event.__dict__[self.collection_name + 'n']): event.muons[mu] = particle(\ **dict((name,event.__dict__[self.collection_name+name][mu]) for name in self.names) ) #Apply corrections self.apply_corrections(event) #Define selections for muon in event.muons.values(): muon.passed_preselection_taus = all([ muon.id_z0_exPV < 10., muon.pt_corrected > 4000., abs(muon.eta) < 2.5, muon.loose, muon.expectBLayerHit == 0 or muon.nBLHits > 0, (muon.nPixHits + muon.nPixelDeadSensors) > 1, (muon.nSCTHits + muon.nSCTDeadSensors) > 5, (muon.nPixHoles + muon.nSCTHoles) < 3, not ((0.1 < abs(muon.eta) < 1.9) and not ((muon.nTRTHits + muon.nTRTOutliers) > 5 and muon.nTRTOutliers < 0.9 * (muon.nTRTHits + muon.nTRTOutliers))), not (((0.1 > abs(muon.eta) or abs(muon.eta) > 1.9) and ((muon.nTRTHits + muon.nTRTOutliers) > 5)) and not (muon.nTRTOutliers < 0.9 * (muon.nTRTHits + muon.nTRTOutliers))), ]) muon.passed_preselection_embedding = all([ muon.passed_preselection_taus, muon.pt_corrected > self.min_pT, ]) muon.passed_preselection = all([ muon.passed_preselection_taus, muon.tight, muon.pt_corrected > self.min_pT, ]) muon.passed_selection = all([ muon.passed_preselection, muon.isCombinedMuon, muon.etcone20_corrected / muon.pt_corrected < 0.09, muon.ptcone40 / muon.pt_corrected < 0.18, ])
def __call__(self, event): super(identify_sherpa_truth, self).__call__(event) bs = [ p for p in event.truth.values() if abs(p().pdgId) == 5 and p().status == 11 ] taus = [ p for p in event.truth.values() if abs(p().pdgId) == 15 and p().status == 2 and 15 in [parent().pdgId for parent in p.parents] ] if len(taus) != 2: raise identify_sherpa_truth.invalid_configuration() if len(bs) > 4: b1, b2, b3, b4 = tuple([ b() for b in sorted(bs, key=lambda b: b()().Pt(), reverse=True)[:4] ]) else: b1,b2,b3,b4 = tuple([b() for b in sorted(bs,key=lambda b: b()().Pt(),reverse=True)]+[ particle(\ pt = -10., eta = -10., phi = -10., m = -10., charge = -10. ) for i in range(4-len(bs))]) tau1, tau2 = taus try: e = [ item for item in tau1.children + tau2.children if abs(item().pdgId) == 11 ][0] nu_e = [ item for item in tau1.children + tau2.children if abs(item().pdgId) == 12 ][0] mu = [ item for item in tau1.children + tau2.children if abs(item().pdgId) == 13 ][0] nu_mu = [ item for item in tau1.children + tau2.children if abs(item().pdgId) == 14 ][0] nu_tau1, nu_tau2 = [ item for item in tau1.children + tau2.children if abs(item().pdgId) == 16 ][0:2] except IndexError: raise identify_sherpa_truth.select_emu() event.b1 = b1 event.b2 = b2 event.b3 = b3 event.b4 = b4 if mu in tau1.children: tau1, tau2 = tau2, tau1 event.tau1 = tau1() event.tau2 = tau2() event.l2 = mu() event.l1 = e() A = tau1()() + tau2()() event.A = particle() event.A.set_particle(A) for item,name in [\ (event.b1,'b1_'), (event.b2,'b2_'), (event.b3,'b3_'), (event.b4,'b4_'), (event.A,'A_'), (event.tau1,'tau1_'), (event.tau2,'tau2_'), (event.l1,'l1_'), (event.l2,'l2_'), ]: event.__dict__[name + 'pt'] = item().Pt() event.__dict__[name + 'eta'] = item().Eta() event.__dict__[name + 'phi'] = item().Phi() event.__dict__[name + 'm'] = item().M() return
def __call__(self,event): bs = [p for p in event.truth.values() if abs(p().pdgId)==5 and p().status==11] taus = [p for p in event.truth.values() if abs(p().pdgId)==15 and p().status==2 and 15 in [parent().pdgId for parent in p.parents]] if len(taus)!=2: event.__break__ = True return if len(bs)>4: b1,b2,b3,b4 = tuple([b() for b in sorted(bs,key=lambda b: b()().Pt(),reverse=True)[:4]]) else: b1,b2,b3,b4 = tuple([b() for b in sorted(bs,key=lambda b: b()().Pt(),reverse=True)]+[ particle(\ pt = -10., eta = -10., phi = -10., m = -10., charge = -10. ) for i in range(4-len(bs))]) tau1,tau2 = taus try: e = [item for item in tau1.children+tau2.children if abs(item().pdgId) == 11][0] nu_e = [item for item in tau1.children+tau2.children if abs(item().pdgId) == 12][0] mu = [item for item in tau1.children+tau2.children if abs(item().pdgId) == 13][0] nu_mu = [item for item in tau1.children+tau2.children if abs(item().pdgId) == 14][0] nu_tau1,nu_tau2 = [item for item in tau1.children+tau2.children if abs(item().pdgId) == 16][0:2] except IndexError: event.__break__ = True return event.b1 = b1 event.b2 = b2 event.b3 = b3 event.b4 = b4 event.mu = mu() event.e = e() A = tau1()()+tau2()() event.A = particle(); event.A.set_particle(A) event.A_m_visible = (event.mu()+event.e()).M() METLV = ( nu_tau1()()+ nu_tau2()()+ nu_mu()()+ nu_e()() ) event.MET = METLV.Pt() event.METx = METLV.Px() event.METy = METLV.Py() for item,name in [\ (event.b1,'b1_'), (event.b2,'b2_'), (event.b3,'b3_'), (event.b4,'b4_'), (event.A,'A_'), (event.mu,'mu_'), (event.e,'e_'), ]: event.__dict__[name+'pt'] = item().Pt() event.__dict__[name+'eta'] = item().Eta() event.__dict__[name+'phi'] = item().Phi() event.__dict__[name+'m'] = item().M() return
def __call__(self,event): super(collect_jets,self).__call__(event) #code.interact(local=locals()) #Collect jets event.jets = {} for jet in range(event.__dict__[self.collection_name+'n']): event.jets[jet] = particle(\ **dict((name,event.__dict__[self.collection_name+name][jet]) for name in self.names) ) #Apply jet corrections self.apply_corrections(event) self.apply_btag_corrections(event) #Categorize jet as b-jet preselection self.preselect_bjets(event) #Define selections for jet in event.jets.values(): jet.passed_preselection = all([ jet.pt>20000., abs(jet.eta)<4.5, ]) jet.passed_selection = all([ jet.passed_preselection, not ((abs(jet.eta)<2.4 and jet.pt<50000.) and not ((jet.jvtxf)>0.5)) ]) jet.passed_bselection = all([ jet.passed_selection, abs(jet.eta)<2.4, jet.flavor_weight_MV1> 0.7892, ]) #event.original_jet_pt = copy(event.jet_pt) #saves event.jet_n = 0 event.jet_pt = [] event.jet_eta = [] event.jet_phi = [] event.jet_E = [] event.jet_passed_b_preselection = [] """ event.jet_b_preselection_pt = [] event.jet_b_preselection_eta = [] event.jet_b_preselection_phi = [] event.jet_b_preselection_E = [] """ event.jet_jvf = [] event.jet_jvf_up_cut = [] event.jet_jvf_down_cut = [] event.jet_jes_Error_Baseline = [] event.jet_jes_Error_Pileup = [] event.jet_jes_Error_Closeby = [] event.jet_jes_Error_FlvCmp = [] event.jet_jes_Error_FlvRsp = [] event.jet_jes_Error_Bjet = [] event.jet_bJet_scale_factor = [] event.jet_bJet_scale_factor_error = [] event.jet_flavor_weight_MV1 = [] for jet in event.jets.values(): if not jet.passed_preselection: continue event.jet_n+=1 event.jet_pt.append(jet.pt) event.jet_eta.append(jet.eta) event.jet_phi.append(jet.phi) event.jet_E.append(jet.E) event.jet_passed_b_preselection.append(jet.passed_b_preselection) """ event.jet_b_preselection_pt.append(jet.b_preselection_pt) event.jet_b_preselection_eta.append(jet.b_preselection_eta) event.jet_b_preselection_phi.append(jet.b_preselection_phi) event.jet_b_preselection_E.append(jet.b_preselection_E) """ event.jet_jvf.append(jet.jvtxf) event.jet_jvf_up_cut.append(jet.jvf_up_cut) event.jet_jvf_down_cut.append(jet.jvf_down_cut) event.jet_jes_Error_Baseline.append(jet.jesErrorBaseline) event.jet_jes_Error_Pileup.append(jet.jesErrorPileup) event.jet_jes_Error_Closeby.append(jet.jesErrorCloseby) event.jet_jes_Error_FlvCmp.append(jet.jesErrorFlvCmp) event.jet_jes_Error_FlvRsp.append(jet.jesErrorFlvRsp) event.jet_jes_Error_Bjet.append(jet.jesErrorBjet) event.jet_bJet_scale_factor.append(jet.bJetScaleFactor) event.jet_bJet_scale_factor_error.append(jet.bJetScaleFactorError) event.jet_flavor_weight_MV1.append(jet.flavor_weight_MV1) return