def force_2_jets(self, particles):
     self.__class__.clusterizer.clear()
     other_particles = []
     for ptc in particles:
         keep = True
         for tau in self.taus:
             if ptc in tau.constituents.particles:
                 keep = False
         if keep:
             self.__class__.clusterizer.add_p4(ptc.p4())
             other_particles.append(ptc)
     assert (len(other_particles) +
             len(self.taus[0].constituents.particles) +
             len(self.taus[1].constituents.particles) == len(particles))
     njets = 2
     if len(other_particles) < njets:
         return False
     self.__class__.clusterizer.make_exclusive_jets(njets)
     assert (self.__class__.clusterizer.n_jets() == njets)
     jets = []
     for jeti in range(self.__class__.clusterizer.n_jets()):
         jet = Jet(self.__class__.clusterizer.jet(jeti))
         jet.constituents = JetConstituents()
         for consti in range(
                 self.__class__.clusterizer.n_constituents(jeti)):
             constituent_index = self.__class__.clusterizer.constituent_index(
                 jeti, consti)
             constituent = particles[constituent_index]
             jet.constituents.append(constituent)
         jet.constituents.sort()
         jets.append(jet)
     self.jets2 = jets
     self.zed2 = Resonance2(jets[0], jets[1], 23, 1)
     return True
Example #2
0
 def process(self, event):
     p4 = TLorentzVector()
     charge = 0
     pdgid = 0
     ptcs = getattr(event, self.cfg_ana.particles)
     jet = Jet(p4)
     constituents = JetConstituents()
     for ptc in ptcs:
         p4 += ptc.p4()
         charge += ptc.q()
         constituents.append(ptc)
     sumptc = Particle(pdgid, charge, p4)
     jet = Jet(p4)
     jet.constituents = constituents
     jet.constituents.sort()
     setattr(event, self.cfg_ana.output, jet)
Example #3
0
 def process(self, event):
     '''Process event.
     
     The event must contain:
      - self.cfg_ana.particles: the list of particles to be clustered
      
     This method creates:
      - event.<self.cfg_ana.output>: the list of L{jets<heppy.particles.jet.Jet>}. 
     '''
     particles = getattr(event, self.cfg_ana.particles)
     # removing neutrinos
     particles = [
         ptc for ptc in particles if abs(ptc.pdgid()) not in [12, 14, 16]
     ]
     self.clusterizer.clear()
     for ptc in particles:
         self.clusterizer.add_p4(ptc.p4())
     self.clusterize()
     jets = []
     for jeti in range(self.clusterizer.n_jets()):
         jet = Jet(self.clusterizer.jet(jeti))
         jet.constituents = JetConstituents()
         jets.append(jet)
         for consti in range(self.clusterizer.n_constituents(jeti)):
             constituent_index = self.clusterizer.constituent_index(
                 jeti, consti)
             constituent = particles[constituent_index]
             jet.constituents.append(constituent)
         jet.constituents.sort()
         self.validate(jet)
     setattr(event, self.cfg_ana.output, jets)
Example #4
0
 def process(self, event):
     p4 = TLorentzVector()
     charge = 0
     pdgid = 0
     ptcs = getattr(event, self.cfg_ana.particles)
     jet = Jet(p4)
     constituents = JetConstituents()
     for ptc in ptcs:
         p4 += ptc.p4()
         charge += ptc.q()
         constituents.append(ptc)
     sumptc = Particle(pdgid, charge, p4)
     jet = Jet(p4)
     jet.constituents = constituents
     jet.constituents.sort()
     setattr(event, self.cfg_ana.output, jet)
    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
Example #6
0
class Jet(BaseJet):
    def __init__(self, candidate):
        super(Jet, self).__init__()
        self.candidate = candidate
        self._tlv = TLorentzVector()
        p4 = candidate.p4()
        self._tlv.SetPtEtaPhiM(p4.pt(), p4.eta(), p4.phi(), p4.mass())
        self.convert_constituents()

    def convert_constituents(self):
        constits = []
        constits = map(Particle, self.getJetConstituents())
        self.constituents = JetConstituents()
        for ptc in constits:
            self.constituents.append(ptc)

    def __getattr__(self, attr):
        return getattr(self.candidate, attr)
Example #7
0
 def process(self, event):
     '''Process event.
     
     The event must contain:
      - self.cfg_ana.particles: the input collection of particles.
     '''
     p4 = TLorentzVector()
     charge = 0
     pdgid = 0
     ptcs = getattr(event, self.cfg_ana.particles)
     jet = Jet(p4)
     constituents = JetConstituents()
     for ptc in ptcs:
         p4 += ptc.p4()
         charge += ptc.q()
         constituents.append(ptc)
     sumptc = Particle(pdgid, charge, p4)
     jet = Jet(p4)
     jet.constituents = constituents
     jet.constituents.sort()
     setattr(event, self.cfg_ana.output, jet)
Example #8
0
 def process(self, event):
     '''Process event.
     
     The event must contain:
      - self.cfg_ana.particles: the input collection of particles.
     '''
     p4 = TLorentzVector()
     charge = 0
     pdgid = 0
     ptcs = getattr(event, self.cfg_ana.particles)
     jet = Jet(p4)
     constituents = JetConstituents()
     for ptc in ptcs:
         p4 += ptc.p4()
         charge += ptc.q()
         constituents.append(ptc)
     sumptc = Particle(pdgid, charge, p4)
     jet = Jet(p4)
     jet.constituents = constituents
     jet.constituents.sort()
     setattr(event, self.cfg_ana.output, jet)
 def process(self, event):
     ptcs = getattr(event, self.cfg_ana.particles)
     if ptcs:
         tlv = TLorentzVector()
         for ptc in ptcs:
             tlv += ptc.p4()
         jet = Jet(tlv)
         jet.constituents = JetConstituents()
         for ptc in ptcs:
             jet.constituents.append(ptc)
         jet.constituents.sort()
         setattr(event, self.cfg_ana.output, jet)
Example #10
0
    def process(self, event):
        '''Process event.
        
        The event must contain:
         - self.cfg_ana.particles: the list of particles to be clustered
         
        This method creates:
         - event.<self.cfg_ana.output>: the list of L{jets<heppy.particles.jet.Jet>}. 
        '''
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [
            ptc for ptc in particles if abs(ptc.pdgid()) not in [12, 14, 16]
        ]
        if len(particles) < self.njets:
            if hasattr(
                    self.cfg_ana,
                    'njets_required') and self.cfg_ana.njets_required == False:
                # not enough particles for the required number of jets,
                # making no jet
                setattr(event, self.cfg_ana.output, [])
                return True

            else:
                # njets_required not provided, or njets_required set to True
                err = 'Cannot make {} jets with {} particles -> Event discarded'.format(
                    self.njets, len(particles))
                self.mainLogger.error(err)
                # killing the sequence, as the user requests exactly njets
                return False
        # enough particles to make the required number of jets
        self.clusterizer.clear()
        for ptc in particles:
            self.clusterizer.add_p4(ptc.p4())
        self.clusterize()
        jets = []
        if self.cfg_ana.verbose:
            print self.clusterizer.n_jets(), 'jets:'
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet(self.clusterizer.jet(jeti))
            jet.constituents = JetConstituents()
            jets.append(jet)
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(
                    jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
            if self.cfg_ana.verbose:
                print '\t', jet
        setattr(event, self.cfg_ana.output, jets)
Example #11
0
    def merge_constituents(self, constituent_list):
        """
        returns the combination of the constituents lists
        @param constituent_list list of JetConstituent objects, e.g. [jet1.constituents, jet2.constituents]
        """
        ret = JetConstituents()
        for elem in constituent_list:
            for group in elem.values():
                for ptc in group:
                    ret.append(ptc)

        ret.sort()
        return ret
Example #12
0
 def process(self, event):
     particles = getattr(event, self.cfg_ana.particles)
     # removing neutrinos
     particles = [
         ptc for ptc in particles if abs(ptc.pdgid()) not in [12, 14, 16]
     ]
     self.clusterizer.clear()
     for ptc in particles:
         self.clusterizer.add_p4(ptc.p4())
     self.clusterize()
     jets = []
     for jeti in range(self.clusterizer.n_jets()):
         jet = Jet(self.clusterizer.jet(jeti))
         jet.constituents = JetConstituents()
         jets.append(jet)
         for consti in range(self.clusterizer.n_constituents(jeti)):
             constituent_index = self.clusterizer.constituent_index(
                 jeti, consti)
             constituent = particles[constituent_index]
             jet.constituents.append(constituent)
         jet.constituents.sort()
         self.validate(jet)
     setattr(event, self.cfg_ana.output, jets)
Example #13
0
 def convert_constituents(self):
     constits = []
     constits = map(Particle, self.getJetConstituents())
     self.constituents = JetConstituents()
     for ptc in constits:
         self.constituents.append(ptc)