def process(self, event): '''event should contain: * gen_particles: list of all stable gen particles ''' genptcs = event.gen_particles bquarks = [] charged_hadrons = [] event.hadrons_from_b = [] for ptc in genptcs: if abs(ptc.pdgid()) == 5: bquarks.append(ptc) elif ptc.q() and ptc.status() == 1: charged_hadrons.append(ptc) if len(bquarks) == 0 or len(charged_hadrons) == 0: return event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices) event.hadrons_from_b = [] event.hadrons_not_from_b = [] for hadron in charged_hadrons: ancestors = event.genbrowser.ancestors(hadron) is_from_b = False for ancestor in ancestors: if hasBottom(ancestor.pdgid()): is_from_b = True if is_from_b: event.hadrons_from_b.append(hadron) else: event.hadrons_not_from_b.append(hadron)
def process(self, event): '''event should contain: * gen_particles: list of all stable gen particles ''' ptc_stable = getattr(event, self.cfg_ana.input_particle) output_W_minus = None output_W_plus = None charged_hadrons = [] for ptc in ptc_stable: if ptc.q(): charged_hadrons.append(ptc) event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices) event.hadrons_from_W_minus = [] event.hadrons_from_W_plus = [] for hadron in charged_hadrons: is_from_W_minus = is_ptc_from_W_minus(event, hadron, event.genbrowser) if is_from_W_minus: event.hadrons_from_W_minus.append(hadron) else: event.hadrons_from_W_plus.append(hadron) setattr(event, self.cfg_ana.output_W_minus, event.hadrons_from_W_minus) setattr(event, self.cfg_ana.output_W_plus, event.hadrons_from_W_plus)
def process(self, event): genptcs = event.gen_particles charged_hadrons = [ ptc for ptc in genptcs if ptc.q() and ptc.status() == 1 ] event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices) event.hadrons_from_b = [] for hadron in charged_hadrons: ancestors = event.genbrowser.ancestors(hadron) for ancestor in ancestors: if hasBottom(ancestor.pdgid()): event.hadrons_from_b.append(hadron) break
def process(self, event): '''event should contain: * gen_particles: list of all stable gen particles ''' genptcs = event.gen_particles genphotons=[] for ptc in genptcs: if abs(ptc.pdgid())==22: genphotons.append(ptc) if len(genphotons) == 0: return event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices)
def process(self, event): gens = getattr(event, self.cfg_ana.gen_particles) gen_taus = [ gen for gen in gens if abs(gen.pdgid()) == 15 and gen.status() == 2 ] ## pprint.pprint(gen_taus) if not hasattr(event, 'genbrowser'): event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices) thetamax = 75. * math.pi / 180. acceptance = { 211: lambda ptc: ptc.pt() > 0.3 and abs(ptc.theta()) < thetamax, 11: lambda ptc: ptc.e() > 5 and abs(ptc.theta()) < thetamax, 13: lambda ptc: ptc.e() > 7.5 and abs(ptc.theta()) < thetamax, } acc_taus = [] gen_taus_decayed = [] for tau in gen_taus: ## print tau ncharged = 0 acc_charged = [] descendants = event.genbrowser.descendants(tau) stable_daugthers = [ desc for desc in descendants if desc.status() == 1 ] consts = JetConstituents() p4sum = TLorentzVector() for dau in stable_daugthers: assert (dau.status() == 1) ## print '\t', dau if abs(dau.pdgid()) in [12, 14, 16]: continue p4sum += dau.p4() consts.append(dau) pdgid = group_pdgid(dau) if dau.q() and acceptance[pdgid](dau): acc_charged.append(dau) gen_tau_decayed = GenTau(p4sum) gen_tau_decayed.constituents = consts gen_taus_decayed.append(gen_tau_decayed) if len(acc_charged) in [1, 3]: acc_taus.append(gen_tau_decayed) event.gen_taus = gen_taus_decayed event.gen_taus_acc = acc_taus
def process(self, event): bosons = [ ptc for ptc in event.gen_particles if abs(ptc.pdgid()) in self.cfg_ana.pdgids and ptc.status() in self.cfg_ana.statuses ] if not hasattr(event, 'genbrowser'): event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices) output = [] for boson in bosons: daughters = event.genbrowser.decay_daughters(boson) assert (len(daughters) == 2) if hasattr(self.cfg_ana, 'decay_pdgids') and \ not ( abs(daughters[0].pdgid()) in self.cfg_ana.decay_pdgids and \ abs(daughters[1].pdgid()) in self.cfg_ana.decay_pdgids ): continue d0, d1 = daughters[0], daughters[1] # putting particle before anti particle if d1.pdgid() > d0.pdgid(): d0, d1 = d1, d0 # but if the 1st particle is neutral, put it at the end (W->lnu) if d0.q() == 0: d0, d1 = d1, d0 resonance = Resonance2(d0, d1, boson.pdgid(), boson.status()) output.append(resonance) output.sort(key=lambda x: x.pdgid()) idstring = '_'.join(map(str, self.cfg_ana.pdgids)) output_name = '_'.join(['gen_bosons', idstring]) # e.g. gen_bosons_23_25 if hasattr(self.cfg_ana, 'output'): output_name = self.cfg_ana.output setattr(event, output_name, output) if self.verbose: print self if not len(output): print 'no boson found' else: for gb in output: print gb pprint.pprint(gb.legs) print
def is_from_b(jet, event, fraction=0.05): '''returns true if more than a fraction of the jet energy is from a b.''' history = HistoryHelper(event.papasevent) if not hasattr(event, 'genbrowser'): event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices) sum_e_from_b = 0 # charged_ptcs = jet.constituents[211] from_b = False for ptc in jet.constituents.particles: simids = history.get_linked_collection(ptc.uniqueid, 'ps') for simid in simids: simptc = event.papasevent.get_object(simid) if is_ptc_from_b(event, simptc.gen_ptc, event.genbrowser): from_b = True break if from_b: sum_e_from_b += ptc.e() bfrac = sum_e_from_b / jet.e() jet.tags['bfrac'] = bfrac return bfrac > fraction
def process(self, event): event.genbrowser = GenBrowser(event.gen_particles, event.gen_vertices)