Exemplo n.º 1
0
    def process(self, event):
        self.tree.reset()
        haas = getattr(event, self.cfg_ana.haas)
        hbbs = getattr(event, self.cfg_ana.hbbs)

        haas.sort(key=lambda x: abs(x.m() - 125.))
        hbbs.sort(key=lambda x: abs(x.m() - 125.))

        if len(haas) > 0 and len(hbbs) > 0:

            self.tree.fill('weight', event.weight)
            # jet multiplicities
            self.tree.fill('nbjets', len(event.selected_bs))
            self.tree.fill('nljets', len(event.selected_lights))
            self.tree.fill('njets',
                           len(event.selected_lights) + len(event.selected_bs))
            self.tree.fill('nlep', len(event.selected_leptons))

            # missing Et
            fillMet(self.tree, 'met', event.met)

            # Reco higgses
            photons = []
            photons.append(haas[0].leg1())
            photons.append(haas[0].leg2())
            photons.sort(key=lambda x: x.pt(), reverse=True)

            bs = []
            bs.append(hbbs[0].leg1())
            bs.append(hbbs[0].leg2())
            bs.sort(key=lambda x: x.pt(), reverse=True)

            hh = Resonance(haas[0], hbbs[0], 25)

            fillParticle(self.tree, 'hh', hh)
            fillParticle(self.tree, 'haa', haas[0])
            fillParticle(self.tree, 'hbb', hbbs[0])
            fillParticle(self.tree, 'a1', photons[0])
            fillParticle(self.tree, 'a2', photons[1])
            fillParticle(self.tree, 'b1', bs[0])
            fillParticle(self.tree, 'b2', bs[1])

            drbb = deltaR(bs[0], bs[1])
            draa = deltaR(photons[0], photons[1])

            self.tree.fill('draa', draa)
            self.tree.fill('drbb', drbb)

            self.tree.tree.Fill()
        '''phos = getattr(event, self.cfg_ana.photons)
        bs   = getattr(event, self.cfg_ana.bs)
	
        phos.sort(key=lambda x: x.pt(), reverse=True)
        bs.sort(key=lambda x: x.pt(), reverse=True)'''

        #print len(phos), len(bs)
        '''if len(phos) > 1 and len(bs) > 1 :
Exemplo n.º 2
0
 def process(self, event):
     '''process event
     
     The event must contain:
      - self.cfg_ana.particles: the particles to be matched
      - self.cfg_ana.match_particles: the particles in which the match has to be found
      
     Modifies the particles in event.<self.cfg_ana.particles>
     '''
     particles = getattr(event, self.cfg_ana.particles)
     # match_particles = getattr(event, self.cfg_ana.match_particles)
     for collname, pdgid in self.match_collections:
         match_ptcs = getattr(event, collname)
         match_ptcs_filtered = match_ptcs
         if pdgid is not None:
             match_ptcs_filtered = [ptc for ptc in match_ptcs
                                    if ptc.pdgid()==pdgid]
         pairs = matchObjectCollection(particles, match_ptcs_filtered,
                                       self.cfg_ana.delta_r)
         for ptc in particles:
             matchname = 'match'
             if pdgid: 
                 matchname = 'match_{pdgid}'.format(pdgid=pdgid)
             match = pairs[ptc]
             setattr(ptc, matchname, match)
             if match:
                 drname = 'dr'
                 if pdgid:
                     drname = 'dr_{pdgid}'.format(pdgid=pdgid)
                 dr = deltaR(ptc, match)
                 setattr(ptc, drname, dr)
Exemplo n.º 3
0
 def process(self, event):
     particles = getattr(event, self.cfg_ana.particles)
     # match_particles = getattr(event, self.cfg_ana.match_particles)
     for collname, pdgid in self.match_collections:
         match_ptcs = getattr(event, collname)
         match_ptcs_filtered = match_ptcs
         if pdgid is not None:
             match_ptcs_filtered = [
                 ptc for ptc in match_ptcs if ptc.pdgid() == pdgid
             ]
         pairs = matchObjectCollection(particles, match_ptcs_filtered,
                                       0.3**2)
         for ptc in particles:
             matchname = 'match'
             if pdgid:
                 matchname = 'match_{pdgid}'.format(pdgid=pdgid)
             match = pairs[ptc]
             setattr(ptc, matchname, match)
             if match:
                 drname = 'dr'
                 if pdgid:
                     drname = 'dr_{pdgid}'.format(pdgid=pdgid)
                 dr = deltaR(ptc.theta(), ptc.phi(), match.theta(),
                             match.phi())
                 setattr(ptc, drname, dr)
Exemplo n.º 4
0
 def process(self, event):
     '''process event
     
     The event must contain:
      - self.cfg_ana.particles: the particles to be matched
      - self.cfg_ana.match_particles: the particles in which the match has to be found
      
     Modifies the particles in event.<self.cfg_ana.particles>
     '''
     particles = getattr(event, self.cfg_ana.particles)
     # match_particles = getattr(event, self.cfg_ana.match_particles)
     for collname, pdgid in self.match_collections:
         match_ptcs = getattr(event, collname)
         match_ptcs_filtered = match_ptcs
         if pdgid is not None:
             match_ptcs_filtered = [ptc for ptc in match_ptcs
                                    if ptc.pdgid()==pdgid]
         pairs = matchObjectCollection(particles, match_ptcs_filtered,
                                       self.cfg_ana.delta_r)
         for ptc in particles:
             matchname = 'match'
             if pdgid: 
                 matchname = 'match_{pdgid}'.format(pdgid=pdgid)
             match = pairs[ptc]
             setattr(ptc, matchname, match)
             if match:
                 drname = 'dr'
                 if pdgid:
                     drname = 'dr_{pdgid}'.format(pdgid=pdgid)
                 dr = deltaR(ptc.theta(), ptc.phi(),
                             match.theta(), match.phi())
                 setattr(ptc, drname, dr)
Exemplo n.º 5
0
 def hcal_hcal(self, ele1, ele2):
     dR = deltaR(ele1.position.Theta(),
                 ele1.position.Phi(),
                 ele2.position.Theta(),
                 ele2.position.Phi())
     link_ok = dR < ele1.angular_size() + ele2.angular_size()
     return ('hcal_in', 'hcal_in'), link_ok, dR 
Exemplo n.º 6
0
 def is_inside_cluster(self, other):
     '''TODO change name to "overlaps" ? '''
     #now we have original unmerged clusters so we can compare directly to see if they overlap
     dR = deltaR(self.position.Theta(), self.position.Phi(),
                 other.position.Theta(), other.position.Phi())
     link_ok = dR < self.angular_size() + other.angular_size()
     return link_ok, dR
Exemplo n.º 7
0
 def process(self, event):
     pivot = getattr(event, self.cfg_ana.pivot)
     ptcs = getattr(event, self.cfg_ana.particles)
     dR_list = []
     if ptcs and pivot:
         pivot = pivot[0]
         for ptc in ptcs:
             dR_list.append(deltaR(pivot, ptc))
         setattr(event, 'dR_list', dR_list)
Exemplo n.º 8
0
 def is_inside_cluster(self, other):
     '''TODO change name to "overlaps" ? '''
     #now we have original unmerged clusters so we can compare directly to see if they overlap
     dR = deltaR(self.position.Theta(),
                 self.position.Phi(),
                 other.position.Theta(),
                 other.position.Phi())
     link_ok = dR < self.angular_size() + other.angular_size()
     return link_ok, dR
Exemplo n.º 9
0
 def process(self, event):
     jets = getattr(event, self.cfg_ana.jets)
     genjets = getattr(event, self.cfg_ana.genjets)
     pairs = matchObjectCollection(jets, genjets, 0.3**2)
     for jet in jets:
         jet.gen = pairs[jet]
         if jet.gen:
             jet.dR = deltaR(jet.theta(), jet.phi(),
                             jet.gen.theta(), jet.gen.phi())
Exemplo n.º 10
0
 def process(self, event):
     jets = getattr(event, self.cfg_ana.jets)
     genjets = getattr(event, self.cfg_ana.genjets)
     pairs = matchObjectCollection(jets, genjets, 0.3**2)
     for jet in jets:
         jet.gen = pairs[jet]
         if jet.gen:
             jet.dR = deltaR(jet.theta(), jet.phi(),
                             jet.gen.theta(), jet.gen.phi())
Exemplo n.º 11
0
 def process(self, event):
     jets = event.rec_jets
     genjets = event.gen_jets
     pairs = matchObjectCollection(jets, genjets, 0.3**2)
     for jet in jets:
         jet.gen = pairs[jet]
         if jet.gen:
             jet.dR = deltaR(jet.theta(), jet.phi(),
                             jet.gen.theta(), jet.gen.phi())
Exemplo n.º 12
0
 def process(self, event):
     pivot = getattr(event, self.cfg_ana.pivot)
     ptcs = getattr(event, self.cfg_ana.particles)
     dR_list = []
     if ptcs and pivot:
         pivot = pivot[0]
         for ptc in ptcs:
             dR_list.append(deltaR(pivot, ptc))
         setattr(event, 'dR_list', dR_list)
Exemplo n.º 13
0
 def process(self, event):
     particles = getattr(event, self.cfg_ana.particles)
     match_particles = getattr(event, self.cfg_ana.match_particles)
     pairs = matchObjectCollection(particles, match_particles,
                                   self.dr2)
     for ptc in particles:
         match = pairs[ptc]
         if match:
             dr = deltaR(ptc.theta(), ptc.phi(),
                         match.theta(), match.phi())
             setattr(ptc, self.instance_label, MatchInfo(match, dr))
Exemplo n.º 14
0
def drmin(event):
    drmin = 999999.
    for i, j in itertools.combinations(range(4), 2):
        theta1 = getattr(event, 'jets4_{}_theta'.format(i))
        phi1 = getattr(event, 'jets4_{}_phi'.format(i))
        theta2 = getattr(event, 'jets4_{}_theta'.format(j))
        phi2 = getattr(event, 'jets4_{}_phi'.format(j))
        dr = deltaR(theta1, phi1, theta2, phi2)
        if dr < drmin:
            drmin = dr
    return drmin
Exemplo n.º 15
0
 def process(self, event):
     pivot = getattr(event, self.cfg_ana.pivot)[0]
     ptcs = getattr(event, self.cfg_ana.particles)
     dR = self.cfg_ana.dR
     cone_ptcs = inConeCollection(pivot, ptcs, dR, 0.)
     for ptc in cone_ptcs:
         setattr(ptc, 'dR', deltaR(pivot, ptc))
     tlv = TLorentzVector(pivot.p4())
     tlv.SetPhi(pivot.p4().Phi() + math.pi)
     tlv_theta = math.pi - pivot.p4().Theta()
     if tlv_theta >= math.pi:
         tlv_theta -= math.pi
     tlv.SetTheta(tlv_theta)
     control_pivot = Particle(pivot.pdgid(), pivot.charge(), tlv)
     control_cone_ptcs = inConeCollection(control_pivot, ptcs, dR, 0.)
     setattr(event, self.cfg_ana.output, cone_ptcs)
     setattr(event, self.cfg_ana.control_output, control_cone_ptcs)
Exemplo n.º 16
0
    def is_inside_clusters(self, other):
        '''TODO: no need for two versions of this method, see below.
        one should have a single overlap method that always works, whether or not there are any
        subclusters.
        '''
        #see if two clusters overlap (allowing for merged clusters which contain subclusters)
        #we have a link if any of the subclusters overlap
        #the distance is the distance betewen the weighted centres of each (merged) cluster

        dist = deltaR(self.position.Theta(), self.position.Phi(),
                      other.position.Theta(), other.position.Phi())

        for c in self.subclusters:
            for o in other.subclusters:
                is_link, innerdist = c.is_inside_cluster(o)
                if is_link:
                    return True, dist
        return False, dist
Exemplo n.º 17
0
 def process(self, event):
     pivot = getattr(event, self.cfg_ana.pivot)[0]
     ptcs = getattr(event, self.cfg_ana.particles)
     dR = self.cfg_ana.dR
     cone_ptcs = inConeCollection(pivot, ptcs, dR, 0.)
     for ptc in cone_ptcs:
         setattr(ptc, 'dR', deltaR(pivot, ptc))
     tlv = TLorentzVector(pivot.p4())
     tlv.SetPhi(pivot.p4().Phi()+math.pi)
     tlv_theta = math.pi-pivot.p4().Theta()
     if tlv_theta >= math.pi: 
         tlv_theta -= math.pi
     tlv.SetTheta(tlv_theta)
     control_pivot = Particle(pivot.pdgid(),
                              pivot.charge(),
                              tlv)
     control_cone_ptcs = inConeCollection(control_pivot, ptcs, dR, 0.)
     setattr(event, self.cfg_ana.output, cone_ptcs)
     setattr(event, self.cfg_ana.control_output, control_cone_ptcs)
Exemplo n.º 18
0
    def is_inside_clusters(self, other):
        '''TODO: no need for two versions of this method, see below.
        one should have a single overlap method that always works, whether or not there are any
        subclusters.
        '''
        #see if two clusters overlap (allowing for merged clusters which contain subclusters)
        #we have a link if any of the subclusters overlap
        #the distance is the distance betewen the weighted centres of each (merged) cluster

        dist = deltaR(self.position.Theta(),
                      self.position.Phi(),
                      other.position.Theta(),
                      other.position.Phi())

        for c in self.subclusters:
            for o in  other.subclusters:
                is_link, innerdist = c.is_inside_cluster(o)
                if is_link:
                    return True, dist
        return False, dist
Exemplo n.º 19
0
    def process(self, event):
        self.tree.reset()
        gen_higgses = getattr(event, self.cfg_ana.gen_higgses)

        self.tree.fill('weight', event.weight)
        self.tree.fill('nh', len(gen_higgses))

        gen_higgses.sort(key=lambda x: x.pt(), reverse=True)

        if len(gen_higgses) > 1:

            hh = Resonance(gen_higgses[0], gen_higgses[1], 25)
            if hh.pt() > 500.:

                fillParticle(self.tree, 'h1', gen_higgses[0])
                fillParticle(self.tree, 'h2', gen_higgses[1])

                fillParticle(self.tree, 'hh', hh)

                drhh = deltaR(gen_higgses[0], gen_higgses[1])
                self.tree.fill('drhh', drhh)

                self.tree.tree.Fill()
Exemplo n.º 20
0
 def process(self, event):
     particles = getattr(event, self.cfg_ana.particles)
     # match_particles = getattr(event, self.cfg_ana.match_particles)
     for collname, pdgid in self.match_collections:
         match_ptcs = getattr(event, collname)
         match_ptcs_filtered = match_ptcs
         if pdgid is not None:
             match_ptcs_filtered = [ptc for ptc in match_ptcs
                                    if ptc.pdgid()==pdgid]
         pairs = matchObjectCollection(particles, match_ptcs_filtered,
                                       self.dr2)
         for ptc in particles:
             matchname = 'match'
             if pdgid: 
                 matchname = 'match_{pdgid}'.format(pdgid=pdgid)
             match = pairs[ptc]
             setattr(ptc, matchname, match)
             if match:
                 drname = 'dr'
                 if pdgid:
                     drname = 'dr_{pdgid}'.format(pdgid=pdgid)
                 dr = deltaR(ptc.theta(), ptc.phi(),
                             match.theta(), match.phi())
                 setattr(ptc, drname, dr)
Exemplo n.º 21
0
    def process(self, event):
        assumed_vertex = TVector3(0, 0, 0)
        jets = getattr(event, self.cfg_ana.jets)
        detector = self.cfg_ana.detector
        pt_min = self.cfg_ana.pt_min
        dxy_max = self.cfg_ana.dxy_max
        dz_max = self.cfg_ana.dz_max
        for jet in jets:
            IP_b_LL = 0  # value of the log likelihood ratio based on IP initiated at 0
            IPs_b_LL = 0  # value of the log likelihood ratio based on IP significance initiated at 0
            ipsig_ptcs = []  # list of IP signif and associated ptcs
            for id, ptcs in jet.constituents.iteritems():
                if abs(id) in [22, 130, 11]:
                    continue
                for ptc in ptcs:
                    if ptc.q() == 0:
                        continue
                    ptc.path.compute_IP(assumed_vertex, jet)

                    ptc_IP_signif = 0
                    if hasattr(ptc.path, 'points'
                               ) == True and 'beampipe_in' in ptc.path.points:
                        phi_in = ptc.path.phi(ptc.path.points['beampipe_in'].X(),\
                                                    ptc.path.points['beampipe_in'].Y())
                        phi_out= ptc.path.phi(ptc.path.points['beampipe_out'].X(),\
                                                    ptc.path.points['beampipe_out'].Y())
                        deltat = ptc.path.time_at_phi(
                            phi_out) - ptc.path.time_at_phi(phi_in)
                        x = ptc.path.path_length(deltat)
                        X_0 = detector.elements['beampipe'].material.x0
                        ptc.path.compute_theta_0(x, X_0)
                        ptc.path.compute_IP_signif(
                            ptc.path.IP, ptc.path.theta_0,
                            ptc.path.points['beampipe_in'])
                    else:
                        ptc.path.compute_IP_signif(ptc.path.IP, None, None)

                    dx = ptc.path.IP_coord.x() - assumed_vertex.x()
                    dy = ptc.path.IP_coord.y() - assumed_vertex.y()
                    dz = ptc.path.IP_coord.z() - assumed_vertex.z()
                    if ptc.path.p4.Perp() > pt_min and (
                            dx**2 +
                            dy**2)**0.5 < dxy_max and dz**2 < dz_max**2:
                        ipsig_ptcs.append([ptc.path.IP_signif, ptc])

                        if self.tag_IP_b_LL:
                            ptc.path.IP_b_LL = self.ll_tag(
                                self.ratio_IP, ptc.path.IP, IP_b_LL)
                        if self.tag_IPs_b_LL:
                            ptc.path.IPs_b_LL = self.ll_tag(
                                self.ratio_IPs, ptc.path.IP_signif, IPs_b_LL)

            ipsig_ptcs.sort(reverse=True)

            if len(ipsig_ptcs) < 2:
                TCHE = -99
                TCHP = -99
                TCHE_IP = -99
                TCHP_IP = -99
                TCHE_x = -99
                TCHE_y = -99
                TCHE_z = -99
                TCHE_pt = -99
                TCHE_dr = -99

            if len(ipsig_ptcs) > 1:
                TCHE = ipsig_ptcs[1][0]
                ptc = ipsig_ptcs[1][1]
                TCHE_IP = ptc.path.IP
                TCHE_x, TCHE_y, TCHE_z = ptc.path.coord_at_time(0)
                TCHE_pt = ptc.path.p4.Perp()
                TCHE_dr = deltaR(jet.eta(), jet.phi(), ptc.eta(), ptc.phi())
                TCHP = -99
                TCHP_IP = -99

            if len(ipsig_ptcs) > 2:
                TCHP = ipsig_ptcs[2][0]
                ptc = ipsig_ptcs[2][1]
                TCHP_IP = ptc.path.IP

            jet.tags['IP_b_LL'] = IP_b_LL if self.tag_IP_b_LL else None
            jet.tags['IPs_b_LL'] = IPs_b_LL if self.tag_IPs_b_LL else None
            #TODO COLIN : create a BTagInfo class.
            jet.tags['TCHE'] = TCHE
            jet.tags['TCHP'] = TCHP
            jet.tags['TCHE_IP'] = TCHE_IP
            jet.tags['TCHP_IP'] = TCHP_IP
            jet.tags['TCHE_x'] = TCHE_x
            jet.tags['TCHE_y'] = TCHE_y
            jet.tags['TCHE_z'] = TCHE_z
            jet.tags['TCHE_xy'] = (TCHE_x**2 + TCHE_y**2)**0.5
            jet.tags['TCHE_pt'] = TCHE_pt
            jet.tags['TCHE_dr'] = TCHE_dr

            if hasattr(event, 'K0s') == True:
                jet.tags['K0s'] = event.K0s
            else:
                jet.tags['K0s'] = -99
            if hasattr(event, 'Kp') == True:
                jet.tags['Kp'] = event.Kp
            else:
                jet.tags['Kp'] = -99
            if hasattr(event, 'L0') == True:
                jet.tags['L0'] = event.L0
            else:
                jet.tags['L0'] = -99
            if hasattr(event, 'S0') == True:
                jet.tags['S0'] = event.S0
            else:
                jet.tags['S0'] = -99
            if hasattr(event, 'Sp') == True:
                jet.tags['Sp'] = event.Sp
            else:
                jet.tags['Sp'] = -99
            if hasattr(event, 'Sm') == True:
                jet.tags['Sm'] = event.Sm
            else:
                jet.tags['Sm'] = -99
            if hasattr(event, 'Muons') == True:
                jet.tags['Muons'] = event.Muons
            else:
                jet.tags['Muons'] = -99
Exemplo n.º 22
0
    def process(self, event):

        self.counters['cut_flow'].inc('All events')

        mus = getattr(event, self.cfg_ana.muons)
        photons = getattr(event, self.cfg_ana.photons)
        particles = getattr(event, self.cfg_ana.particles)

        lenmu = len(mus)
        setattr(event, self.cfg_ana.lenmu, lenmu)

        posmus1 = [mu for mu in mus if mu.pdgid() == -13]
        negmus1 = [mu for mu in mus if mu.pdgid() == 13]
        if len(posmus1) < 1 or len(negmus1) < 1:
            return False
        self.counters['cut_flow'].inc('Mumu pair')

        isomus = [mu for mu in mus if mu.iso.sume / mu.e() < 0.2]
        posmus = [mu for mu in isomus if mu.pdgid() == -13]
        negmus = [mu for mu in isomus if mu.pdgid() == 13]
        if len(posmus) < 1 or len(negmus) < 1:
            return False
        self.counters['cut_flow'].inc('Relative isolation < 0.2')

        bremphotons = []
        for i in photons:
            for j in isomus:
                if deltaR(i, j) < 0.5:
                    bremphotons.append(i)

    # pos_mus and neg_mus may contain repeats of the muons or antimuons but, ordered, they contain a list of pairs that survive the cuts
    #photon_combos = sum([map(list, combinations(bremphotons, k)) for k in range(len(bremphotons) + 0)], [])
        min_mass_diff = 9999.9
        recoilmass = 0
        pos_mus = []
        neg_mus = []

        #below is a method for iterating over all photons, alongside the muons, to choose bremsstrahlung photons such that the system of muons and photons has a recoil mass equal to the Z mass
        #chosenphotons = []

        #for i in range(len(posmus)):
        #    mu1 = posmus[i]
        #    for j in range(len(negmus)):
        #        mu2 = negmus[j]
        #        part1 = 240 - mu1.e() - mu2.e()
        #        part2 = mu1.p3() + mu2.p3()
        #        for l in range(len(photon_combos)):
        #            for m in range(len(photon_combos[l])):
        #                part1 -= photon_combos[l][m].e()
        #                part2 += photon_combos[l][m].p3()
        #            recoil_mass_square = part1**2 - numpy.dot(part2, part2)
        #            if recoil_mass_square<0:
        #                recoil_mass = 0
        #            else:
        #                recoil_mass = math.sqrt(recoil_mass_square)
        #            mass_diff = abs(recoil_mass - 91.2)
        #            if mass_diff < min_mass_diff:
        #                min_mass_diff = mass_diff
        #                recoilmass = recoil_mass
        #                for n in range(len(photon_combos[l])):
        #                    chosenphotons.append(photon_combos[l][n])

        for i in range(len(posmus)):
            mu1 = posmus[i]
            for j in range(len(negmus)):
                mu2 = negmus[j]
                part1 = 240 - mu1.e() - mu2.e()
                part2 = mu1.p3() + mu2.p3()
                for l in range(len(bremphotons)):
                    part1 -= bremphotons[l].e()
                    part2 += bremphotons[l].p3()
                recoil_mass_square = part1**2 - numpy.dot(part2, part2)
                if recoil_mass_square < 0:
                    recoil_mass = 0
                    print 'negative recoil mass squared'
                else:
                    recoil_mass = math.sqrt(recoil_mass_square)
                mass_diff = abs(recoil_mass - 91.2)
                if mass_diff < min_mass_diff:
                    min_mass_diff = mass_diff
                    recoilmass = recoil_mass
                if 80 < recoilmass < 110:
                    pos_mus.append(mu1)
                    neg_mus.append(mu2)

        if len(pos_mus) < 1:
            return False
        self.counters['cut_flow'].inc('80 < recoil mass < 110')

        if len(pos_mus) > 1:
            min_mass_diff = 9999.9
            id1 = -1
            id2 = -1
            for i in range(len(pos_mus)):
                for j in range(len(neg_mus)):
                    mass_square = 2 * (pos_mus[i].e() *
                                       neg_mus[j].e()) - 2 * numpy.dot(
                                           pos_mus[i].p3(), neg_mus[j].p3())
                    if mass_square < 0:
                        print 'Negative mass squared'
                        break
                    else:
                        mass = math.sqrt(mass_square)
                    mass_diff = abs(mass - 125.1)
                    if mass_diff < min_mass_diff:
                        id1 = i
                        id2 = j
                        min_mass_diff = mass_diff
            higgscandidates = (pos_mus[id1], neg_mus[id2])
        else:
            higgscandidates = (pos_mus[0], neg_mus[0])

        visible_particle2 = [
            ptc for ptc in particles
            if ptc.pdgid() not in [12, -12, 14, -14, 16, -16]
        ]
        visible_particle1 = [
            ptc for ptc in visible_particle2 if ptc not in bremphotons
        ]
        visible_particle = [
            ptc for ptc in visible_particle1 if ptc not in higgscandidates
        ]
        if len(visible_particle) < 2:
            return False
        self.counters['cut_flow'].inc('Two visible jets')

        newparticles = [
            ptc for ptc in particles
            if ptc not in higgscandidates and ptc not in bremphotons
        ]

        setattr(event, self.cfg_ana.newparticles, newparticles)
        setattr(event, self.cfg_ana.higgscandidates, higgscandidates)
Exemplo n.º 23
0
    def process(self, event):
        self.tree.reset()
        gen_bs = getattr(event, self.cfg_ana.gen_bs)
        gen_higgses = getattr(event, self.cfg_ana.gen_higgses)
        gen_higgses.sort(key=lambda x: x.pt(), reverse=True)
        gen_tops = getattr(event, self.cfg_ana.gen_tops)
        gen_tops.sort(key=lambda x: x.pt(), reverse=True)
        fatjets = getattr(event, self.cfg_ana.fatjets)
        leptons = getattr(event, self.cfg_ana.selected_leptons)
        bjets = event.selected_bs
        for_jets = event.jets_nolepton
        jets = event.jets_30

        #_________________________________________________________________
        # compute eflow, tau_ij and bdt variables

        R = 1.5

        use_DELPHES = False
        jet_forTRF = []
        jetin_forTRF = []

        # fill jet collection to compute TRF -> use all jets
        for j in for_jets:
            ipdg = 0
            if use_DELPHES == True:
                ipdg = j.tags['flav']
                if ipdg != 4 and ipdg != 5: ipdg = 0
            else:
                ipdg = j.flavour
            jet_forTRF.append([j, ipdg])

        for jet in fatjets:

            setattr(jet, 'njs', 0)
            setattr(jet, 'nbs', 0)
            setattr(jet, 'ncs', 0)
            setattr(jet, 'nls', 0)
            setattr(jet, 'flow', [0] * 5)
            setattr(jet, 'p4_js', TLorentzVector())
            setattr(jet, 'p4_bs', TLorentzVector())

            setattr(jet, 'tau32', -9.)
            setattr(jet, 'tau31', -9.)
            setattr(jet, 'tau21', -9.)

            #setattr(jet, 'bdt_th', -99.)

            if (jet.tau1 != 0.0):
                jet.tau31 = jet.tau3 / jet.tau1
                jet.tau21 = jet.tau2 / jet.tau1
            if (jet.tau2 != 0.0):
                jet.tau32 = jet.tau3 / jet.tau2

            # counting the number of jets inside (R = 1.5 - 0.4 = 1.1) fatjet
            for j in for_jets:

                # fill different jets matched with fatjet
                drjjet = deltaR(j, jet)
                if drjjet < 1.1:
                    jet.njs += 1
                    jet.p4_js += j.p4()

                    # get pdgID to compute TRF
                    ipdg = 0
                    if use_DELPHES == True:
                        ipdg = j.tags['flav']
                        if ipdg != 4 and ipdg != 5: ipdg = 0
                    else:
                        ipdg = j.flavour

                    if ipdg == 5:
                        jet.nbs += 1
                        jet.p4_bs += j.p4()
                    elif ipdg == 4:
                        jet.ncs += 1
                    else:
                        jet.nls += 1

            # do eflow with constituents here
            constituent_vector = TLorentzVector()

            #print jet.pt, jet.flow
            for n in range(1, 5 + 1):
                #print n
                for constituent in jet.jetConstituents[1:]:
                    #print constituent.pt()
                    dR = jet.p4().DeltaR(constituent.p4())
                    if ((dR >= (n - 1) / 5. * R) and (dR < n / 5. * R)):
                        #print 'in ring', dR
                        jet.flow[n -
                                 1] += abs(constituent.pt()) / abs(jet.pt())

            #print jet.flow

            ## do what is needed to evaluate bdt here
            #self.bdt_tau1              [0] = jet.tau1
            #self.bdt_tau2              [0] = jet.tau2
            #self.bdt_tau3              [0] = jet.tau3
            #self.bdt_tau31             [0] = jet.tau31
            #self.bdt_tau21             [0] = jet.tau21
            #self.bdt_tau32             [0] = jet.tau32
            #self.bdt_flow15            [0] = jet.flow[0]
            #self.bdt_flow25            [0] = jet.flow[1]
            #self.bdt_flow35            [0] = jet.flow[2]
            #self.bdt_flow45            [0] = jet.flow[3]
            #self.bdt_flow55            [0] = jet.flow[4]
            #self.bdt_jet_m             [0] = jet.p4().M()
            #self.bdt_softDropped_jet_m [0] = jet.subjetsSoftDrop[0].p4().M()
            #self.bdt_jet_nbs           [0] = float(jet.nbs)
            #
            #jet.bdt_th = self.reader.EvaluateMVA("BDT")

        # highest bdt score is more higgs like
        #fatjets.sort(key=lambda x: x.bdt_th, reverse = True)

        # 1/ highest number of jets in fatjet is more top like
        fatjets.sort(key=lambda x: x.njs, reverse=True)
        # 2/ lowest mass is more higgs like
        if len(fatjets) > 1 and fatjets[0].njs == fatjets[1].njs:
            fatjets.sort(key=lambda x: x.subjetsSoftDrop[0].p4().M(),
                         reverse=True)

        if len(leptons) > 0 and len(fatjets) > 1:

            self.tree.fill('weight', event.weight)
            fillLepton(self.tree, 'l', leptons[0])
            fillMet(self.tree, 'met', event.met)
            self.tree.fill('nbjets', len(bjets))

            # compute and fill TRF
            self.tree.fill('weight_0tagex', getNbTagEx(0, jet_forTRF, -1))
            self.tree.fill('weight_1tagex', getNbTagEx(1, jet_forTRF, -1))
            self.tree.fill('weight_2tagex', getNbTagEx(2, jet_forTRF, -1))
            self.tree.fill('weight_3tagex', getNbTagEx(3, jet_forTRF, -1))
            self.tree.fill('weight_4tagex', getNbTagEx(4, jet_forTRF, -1))
            '''higgsjet = fatjets[1]
            if higgsjet.nbs > 1:
                print higgsjet.p4_bs.M(), higgsjet.subjetsSoftDrop[0].p4().M()'''

            for flavour in ['higgs', 'top']:

                if flavour == 'higgs':
                    jet = fatjets[1]
                else:
                    jet = fatjets[0]

                fillParticle(self.tree, '{}jet'.format(flavour), jet)
                fillParticle(self.tree, 'softDropped_{}jet'.format(flavour),
                             jet.subjetsSoftDrop[0])

                self.tree.fill('{}jet_tau1'.format(flavour), jet.tau1)
                self.tree.fill('{}jet_tau2'.format(flavour), jet.tau2)
                self.tree.fill('{}jet_tau3'.format(flavour), jet.tau3)
                self.tree.fill('{}jet_tau31'.format(flavour), jet.tau31)
                self.tree.fill('{}jet_tau32'.format(flavour), jet.tau32)
                self.tree.fill('{}jet_tau21'.format(flavour), jet.tau21)

                #print 'filling: ',jet.flow[0], jet.flow[1], jet.flow[2], jet.flow[3], jet.flow[4]

                self.tree.fill('{}jet_flow15'.format(flavour), jet.flow[0])
                self.tree.fill('{}jet_flow25'.format(flavour), jet.flow[1])
                self.tree.fill('{}jet_flow35'.format(flavour), jet.flow[2])
                self.tree.fill('{}jet_flow45'.format(flavour), jet.flow[3])
                self.tree.fill('{}jet_flow55'.format(flavour), jet.flow[4])

                self.tree.fill('{}jet_njs'.format(flavour), jet.njs)
                self.tree.fill('{}jet_nbs'.format(flavour), jet.nbs)
                self.tree.fill('{}jet_ncs'.format(flavour), jet.ncs)
                self.tree.fill('{}jet_nls'.format(flavour), jet.nls)
                self.tree.fill('{}jet_mjs'.format(flavour), jet.p4_js.M())
                self.tree.fill('{}jet_mbs'.format(flavour), jet.p4_bs.M())
                ##self.tree.fill('{}jet_bdt_th'.format(flavour), jet.bdt_th)

            #Hjet = fatjets[1]
            #tjet = fatjets[0]
            #isHiggsOK = False
            # 1/ 18/31 wrong
            #if Hjet.nbs > tjet.nbs : isHiggsOK=True
            #elif Hjet.nbs == tjet.nbs and Hjet.subjetsSoftDrop[0].p4().M() < tjet.subjetsSoftDrop[0].p4().M() : isHiggsOK=True
            # 2/ 18/31 wrong
            #if Hjet.nbs > 1 : # 3/ 14/15 wrong
            #  if Hjet.bdt_th > tjet.bdt_th : isHiggsOK=True
            #  if isHiggsOK==True : print "good match Higgs"
            #  else :               print "wrong match Higgs"
            self.tree.tree.Fill()
Exemplo n.º 24
0
 def process(self, event):
     assumed_vertex = TVector3(0, 0, 0)
     jets = getattr(event, self.cfg_ana.jets)
     detector = self.cfg_ana.detector
     pt_min = self.cfg_ana.pt_min
     dxy_max = self.cfg_ana.dxy_max
     dz_max = self.cfg_ana.dz_max
     for jet in jets:
         IP_b_LL = 0     # value of the log likelihood ratio based on IP initiated at 0
         IPs_b_LL = 0    # value of the log likelihood ratio based on IP significance initiated at 0
         ipsig_ptcs = [] # list of IP signif and associated ptcs
         for id, ptcs in jet.constituents.iteritems():
             if abs(id) in [22,130,11]:
                 continue
             for ptc in ptcs :
                 if ptc.q() == 0 :
                     continue
                 ptc.path.compute_IP(assumed_vertex,jet)
                 
                 ptc_IP_signif = 0
                 if hasattr(ptc.path, 'points') == True and 'beampipe_in' in ptc.path.points:
                     phi_in = ptc.path.phi(ptc.path.points['beampipe_in'].X(),\
                                                 ptc.path.points['beampipe_in'].Y())
                     phi_out= ptc.path.phi(ptc.path.points['beampipe_out'].X(),\
                                                 ptc.path.points['beampipe_out'].Y())
                     deltat = ptc.path.time_at_phi(phi_out)-ptc.path.time_at_phi(phi_in)
                     x = ptc.path.path_length(deltat)
                     X_0 = detector.elements['beampipe'].material.x0
                     ptc.path.compute_theta_0(x, X_0)
                     ptc.path.compute_IP_signif(ptc.path.IP,
                                                ptc.path.theta_0,
                                                ptc.path.points['beampipe_in'])
                 else :
                     ptc.path.compute_IP_signif(ptc.path.IP, None, None)
                 
                 dx = ptc.path.IPcoord.x() - assumed_vertex.x()
                 dy = ptc.path.IPcoord.y() - assumed_vertex.y()
                 dz = ptc.path.IPcoord.z() - assumed_vertex.z()
                 if ptc.path.p4.Perp() > pt_min and (dx**2 + dy**2)**0.5 < dxy_max and dz**2 < dz_max**2 :
                     ipsig_ptcs.append([ptc.path.IP_signif, ptc])
                     
                     if self.tag_IP_b_LL:
                         ptc.path.IP_b_LL = self.ll_tag(self.ratio_IP, ptc.path.IP,IP_b_LL )
                     if self.tag_IPs_b_LL:
                         ptc.path.IPs_b_LL = self.ll_tag(self.ratio_IPs, ptc.path.IP_signif, IPs_b_LL )
                         
         ipsig_ptcs.sort(reverse=True)
         
         if len(ipsig_ptcs) < 2 :
             TCHE = -99
             TCHP = -99
             TCHE_IP = -99
             TCHP_IP = -99
             TCHE_x = -99
             TCHE_y = -99
             TCHE_z = -99
             TCHE_pt = -99
             TCHE_dr = -99
             
         if len(ipsig_ptcs) > 1 :
             TCHE = ipsig_ptcs[1][0]
             ptc = ipsig_ptcs[1][1]
             TCHE_IP = ptc.path.IP
             TCHE_x, TCHE_y, TCHE_z = ptc.path.coord_at_time(0)
             TCHE_pt = ptc.path.p4.Perp()
             TCHE_dr = deltaR(jet.eta(), jet.phi(), ptc.eta(), ptc.phi())
             TCHP = -99
             TCHP_IP = -99
             
         if len(ipsig_ptcs) > 2 :
             TCHP = ipsig_ptcs[2][0]
             ptc = ipsig_ptcs[2][1]
             TCHP_IP = ptc.path.IP
             
         jet.tags['IP_b_LL'] = IP_b_LL  if self.tag_IP_b_LL  else None
         jet.tags['IPs_b_LL']= IPs_b_LL if self.tag_IPs_b_LL else None
         #TODO COLIN : create a BTagInfo class. 
         jet.tags['TCHE'] = TCHE
         jet.tags['TCHP'] = TCHP
         jet.tags['TCHE_IP'] = TCHE_IP
         jet.tags['TCHP_IP'] = TCHP_IP
         jet.tags['TCHE_x'] = TCHE_x
         jet.tags['TCHE_y'] = TCHE_y
         jet.tags['TCHE_z'] = TCHE_z
         jet.tags['TCHE_xy'] = (TCHE_x**2+TCHE_y**2)**0.5
         jet.tags['TCHE_pt'] = TCHE_pt
         jet.tags['TCHE_dr'] = TCHE_dr
         
         if hasattr(event, 'K0s') == True :
             jet.tags['K0s'] = event.K0s
         else :
             jet.tags['K0s'] = -99
         if hasattr(event, 'Kp') == True :
             jet.tags['Kp'] = event.Kp
         else :
             jet.tags['Kp'] = -99
         if hasattr(event, 'L0') == True :
             jet.tags['L0'] = event.L0
         else :
             jet.tags['L0'] = -99
         if hasattr(event, 'S0') == True :
             jet.tags['S0'] = event.S0
         else :
             jet.tags['S0'] = -99
         if hasattr(event, 'Sp') == True :
             jet.tags['Sp'] = event.Sp
         else :
             jet.tags['Sp'] = -99
         if hasattr(event, 'Sm') == True :
             jet.tags['Sm'] = event.Sm
         else :
             jet.tags['Sm'] = -99
         if hasattr(event, 'Muons') == True :
             jet.tags['Muons'] = event.Muons
         else :
             jet.tags['Muons'] = -99
Exemplo n.º 25
0
    def process(self, event):
        self.tree.reset()
        gen_bs = getattr(event, self.cfg_ana.gen_bs)
        gen_higgses = getattr(event, self.cfg_ana.gen_higgses)
        gen_higgses.sort(key=lambda x: x.pt(), reverse=True)
        gen_tops = getattr(event, self.cfg_ana.gen_tops)
        gen_tops.sort(key=lambda x: x.pt(), reverse=True)
        fatjets = getattr(event, self.cfg_ana.fatjets)
        leptons = getattr(event, self.cfg_ana.selected_leptons)
        bjets = event.selected_bs
        jets = event.jets_30

        #_________________________________________________________________
        # compute eflow, tau_ij and bdt variables

        R = 1.5

        for jet in fatjets:

            setattr(jet, 'nbs', 0)
            setattr(jet, 'flow', [0] * 5)
            setattr(jet, 'p4_bs', TLorentzVector())

            setattr(jet, 'tau32', -9.)
            setattr(jet, 'tau31', -9.)
            setattr(jet, 'tau21', -9.)

            setattr(jet, 'bdt_th', -99.)

            if (jet.tau1 != 0.0):
                jet.tau31 = jet.tau3 / jet.tau1
                jet.tau21 = jet.tau2 / jet.tau1
            if (jet.tau2 != 0.0):
                jet.tau32 = jet.tau3 / jet.tau2

            # counting the number of bjets inside (R = 1.5 - 0.4 = 1.1) fatjet
            for b in bjets:

                #print b.flavour

                drjb = deltaR(b, jet)
                if drjb < 1.1:
                    jet.nbs += 1
                    jet.p4_bs += b.p4()

            # do eflow with constituents here
            constituent_vector = TLorentzVector()

            #print jet.pt, jet.flow
            for n in range(1, 5 + 1):
                #print n
                for constituent in jet.jetConstituents[1:]:
                    #print constituent.pt()
                    dR = jet.p4().DeltaR(constituent.p4())
                    if ((dR >= (n - 1) / 5. * R) and (dR < n / 5. * R)):
                        #print 'in ring', dR
                        jet.flow[n -
                                 1] += abs(constituent.pt()) / abs(jet.pt())

            #print jet.flow

            # do what is needed to evaluate bdt here
            self.bdt_tau1[0] = jet.tau1
            self.bdt_tau2[0] = jet.tau2
            self.bdt_tau3[0] = jet.tau3
            self.bdt_tau31[0] = jet.tau31
            self.bdt_tau21[0] = jet.tau21
            self.bdt_tau32[0] = jet.tau32
            self.bdt_flow15[0] = jet.flow[0]
            self.bdt_flow25[0] = jet.flow[1]
            self.bdt_flow35[0] = jet.flow[2]
            self.bdt_flow45[0] = jet.flow[3]
            self.bdt_flow55[0] = jet.flow[4]
            self.bdt_jet_m[0] = jet.p4().M()
            self.bdt_softDropped_jet_m[0] = jet.subjetsSoftDrop[0].p4().M()
            self.bdt_jet_nbs[0] = float(jet.nbs)

            jet.bdt_th = self.reader.EvaluateMVA("BDT")

        # highest bdt score is more higgs like
        fatjets.sort(key=lambda x: x.bdt_th, reverse=True)

        #print '--------------- new event --------------------------------'

        if len(leptons) > 0 and len(fatjets) > 1:

            self.tree.fill('weight', event.weight)
            fillLepton(self.tree, 'l', leptons[0])
            fillMet(self.tree, 'met', event.met)
            self.tree.fill('nbjets', len(bjets))
            '''higgsjet = fatjets[1]
            if higgsjet.nbs > 1:
                print higgsjet.p4_bs.M(), higgsjet.subjetsSoftDrop[0].p4().M()'''

            for flavour in ['higgs', 'top']:

                if flavour == 'higgs':
                    jet = fatjets[1]
                else:
                    jet = fatjets[0]

                fillParticle(self.tree, '{}jet'.format(flavour), jet)
                fillParticle(self.tree, 'softDropped_{}jet'.format(flavour),
                             jet.subjetsSoftDrop[0])

                self.tree.fill('{}jet_tau1'.format(flavour), jet.tau1)
                self.tree.fill('{}jet_tau2'.format(flavour), jet.tau2)
                self.tree.fill('{}jet_tau3'.format(flavour), jet.tau3)
                self.tree.fill('{}jet_tau31'.format(flavour), jet.tau31)
                self.tree.fill('{}jet_tau32'.format(flavour), jet.tau32)
                self.tree.fill('{}jet_tau21'.format(flavour), jet.tau21)

                #print 'filling: ',jet.flow[0], jet.flow[1], jet.flow[2], jet.flow[3], jet.flow[4]

                self.tree.fill('{}jet_flow15'.format(flavour), jet.flow[0])
                self.tree.fill('{}jet_flow25'.format(flavour), jet.flow[1])
                self.tree.fill('{}jet_flow35'.format(flavour), jet.flow[2])
                self.tree.fill('{}jet_flow45'.format(flavour), jet.flow[3])
                self.tree.fill('{}jet_flow55'.format(flavour), jet.flow[4])

                self.tree.fill('{}jet_nbs'.format(flavour), jet.nbs)
                self.tree.fill('{}jet_mbs'.format(flavour), jet.p4_bs.M())
                self.tree.fill('{}jet_bdt_th'.format(flavour), jet.bdt_th)

            self.tree.tree.Fill()
Exemplo n.º 26
0
 def ecal_hcal(self, ele1, ele2):
     #TODO eta or theta?
     dR = deltaR(ele1.position.Theta(), ele1.position.Phi(),
                 ele2.position.Theta(), ele2.position.Phi())
     link_ok = dR < ele1.angular_size() + ele2.angular_size()
     return ('ecal_in', 'hcal_in'), link_ok, dR
Exemplo n.º 27
0
    def process(self, event):
        self.treeS.reset()
        self.treeB.reset()
        gen_bs = getattr(event, self.cfg_ana.gen_bs)
        gen_higgses = getattr(event, self.cfg_ana.gen_higgses)
        gen_higgses.sort(key=lambda x: x.pt(), reverse = True)
        gen_tops = getattr(event, self.cfg_ana.gen_tops)
        gen_tops.sort(key=lambda x: x.pt(), reverse = True)
        jets = getattr(event, self.cfg_ana.fatjets)
        leptons = getattr(event, self.cfg_ana.selected_leptons)
        bjets = event.selected_bs

        if len(gen_higgses) > 1:
            hh_gen = Resonance(gen_higgses[0], gen_higgses[1], 25)

        ljets = []

        #_________________________________________________________________
        # count number of bjets inside jet
        for jet in jets:
            is_light = True
            setattr(jet, 'nbs', 0)
            for b in bjets:
                drjb = deltaR(b, jet)
                if drjb < 1.5: 
                    jet.nbs += 1
        
        #_________________________________________________________________
        # compute eflow variables
        
        R = 1.5
        
        for jet in jets:
            
            setattr(jet, 'flow', [0]*5)
            constituent_vector = TLorentzVector()
            #print jet.pt, jet.flow
            for n in range(1,5+1):
                 #print n 
                 for constituent in jet.jetConstituents[1:]:
                     #print constituent.pt()
                     dR = jet.p4().DeltaR(constituent.p4())
                     if ((dR >= (n-1)/5.*R) and (dR < n/5.*R)):
                         #print 'in ring', dR
                         jet.flow[n-1] += abs(constituent.pt())/abs(jet.pt())
        
        #print '--------------- new event --------------------------------'
        
        if len(leptons) > 0 and len(jets) > 1:

            #print len(jets), len(leptons)
            
            #print deltaR(jets[0], leptons[0]), deltaR(jets[1], leptons[0])
            
            selected_higgs_jets = []
            selected_top_jets = []

            # to decide wheather top or higgs jet will be done with MVA
            # for now just cheat by checking MC truth
            
            for jet in jets:
                drmin_h = 999.
                drmin_t = 999.

                for higgs in gen_higgses:
                    drjh = deltaR(higgs, jet)
                    if drjh < drmin_h: 
                        drmin_h = drjh

                for top in gen_tops:
                    drjt = deltaR(top, jet)
                    if drjt < drmin_t: 
                        drmin_t = drjt

                if  drmin_h < drmin_t and drmin_h < 1.0:   
                    selected_higgs_jets.append(jet)

                elif  drmin_t < drmin_h and drmin_t < 1.0:   
                    selected_top_jets.append(jet)


            if len(selected_higgs_jets) > 0 and len(selected_top_jets) > 0 :
                for tree in [self.treeS, self.treeB]:

                    if tree == self.treeS:
		        jet =  selected_higgs_jets[0]
		    else:
                        jet   =  selected_top_jets[0]

                    fillParticle(tree, 'jet', jet)
                    fillParticle(tree, 'softDropped_jet', jet.subjetsSoftDrop[0])

                    tree.fill('jet_tau1' , jet.tau1 )
                    tree.fill('jet_tau2' , jet.tau2 )
                    tree.fill('jet_tau3' , jet.tau3 )

                    jet_tau31 = -9.0
                    jet_tau21 = -9.0
                    jet_tau32 = -9.0

                    if (jet.tau1 != 0.0):
                	jet_tau31 = jet.tau3/jet.tau1
                	jet_tau21 = jet.tau2/jet.tau1 
                    if (jet.tau2 != 0.0):
                	jet_tau32 = jet.tau3/jet.tau2

                    tree.fill('jet_tau31' , jet_tau31 )
                    tree.fill('jet_tau32' , jet_tau32 )
                    tree.fill('jet_tau21' , jet_tau21 )

                    #print 'filling: ',jet.flow[0], jet.flow[1], jet.flow[2], jet.flow[3], jet.flow[4]

                    tree.fill('jet_flow15', jet.flow[0])
                    tree.fill('jet_flow25', jet.flow[1])
                    tree.fill('jet_flow35', jet.flow[2])
                    tree.fill('jet_flow45', jet.flow[3])
                    tree.fill('jet_flow55', jet.flow[4])

                    tree.fill('jet_nbs', jet.nbs)

                    tree.tree.Fill()
Exemplo n.º 28
0
    def process(self, event):
        self.tree.reset()
        htatas = getattr(event, self.cfg_ana.htatas)
        hbbs = getattr(event, self.cfg_ana.hbbs)
        met = event.met

        htatas.sort(key=lambda x: abs(x.m() - 125.))
        hbbs.sort(key=lambda x: abs(x.m() - 125.))

        bs = event.selected_bs
        taus = event.selected_taus
        lights = event.selected_lights
        leptons = event.selected_leptons

        #print '-------------------'

        #print len(htatas), len(hbbs)
        #print len(taus), len(bs)

        #for tau in taus:
        #    print tau.charge

        #print ROOT.return2()
        #f = Foo()
        #f.bar() #and you will see "Hello" on the screen
        '''
        mVisA = 10.; # mass of visible object on side A.  Must be >=0.
        pxA = 20.; # x momentum of visible object on side A.
        pyA = 30.; # y momentum of visible object on side A.

        mVisB = 10.; # mass of visible object on side B.  Must be >=0.
        pxB = -20.; # x momentum of visible object on side B.
        pyB = -30.; # y momentum of visible object on side B.

        pxMiss = -5.; # x component of missing transverse momentum.
        pyMiss = -5.; # y component of missing transverse momentum.

        chiA = 4.; # hypothesised mass of invisible on side A.  Must be >=0.
        chiB = 7.; # hypothesised mass of invisible on side B.  Must be >=0.

        desiredPrecisionOnMt2 = 0.; # Must be >=0.  If 0 alg aims for machine precision.  if >0, MT2 computed to supplied absolute precision.
        useDeciSectionsInitially=True

        asymm_mt2 = asymm_mt2_lester_bisect()
        print '-----------------------------------------'
        MT2 =  asymm_mt2.get_mT2(
           mVisA, pxA, pyA,
           mVisB, pxB, pyB,
           pxMiss, pyMiss,
           chiA, chiB,
           desiredPrecisionOnMt2,
           useDeciSectionsInitially)
        
        print 'MT2', MT2
        '''

        # fully hadronic selection
        if len(taus) > 1 and len(bs) > 1 and len(leptons) == 0:

            self.tree.fill('weight', event.weight)
            #print  event.weight
            fillParticle(self.tree, 'ta1', taus[0])
            fillParticle(self.tree, 'ta2', taus[1])
            fillParticle(self.tree, 'b1', bs[0])
            fillParticle(self.tree, 'b2', bs[1])
            '''
            def mTsq(bT, cT, mB, mC):
                eB = math.sqrt(mB*mB+ bT*bT)
                eC = math.sqrt(mC*mC+ cT*cT)
                return mB*mB+mC*mC+2*(eB*eC - bT*cT)

            def smT2(bt1, bt2):
                return max(math.sqrt(bt1),math.sqrt(bt2))

            mTsq1 = mTsq(taus[0].p4().Vect().XYvector(), bs[0].p4().Vect().XYvector(), taus[0].p4().M(), bs[0].p4().M())
            mTsq2 = mTsq(taus[1].p4().Vect().XYvector(), bs[1].p4().Vect().XYvector(), taus[1].p4().M(), bs[1].p4().M())

            smTsq = smT2(mTsq1, mTsq2)
            #print mTsq1, mTsq2, smTsq
            '''

            mVisA = bs[0].p4().M()
            # mass of visible object on side A.  Must be >=0.
            pxA = bs[0].p4().Px()
            # x momentum of visible object on side A.
            pyA = bs[0].p4().Py()
            # y momentum of visible object on side A.

            mVisB = bs[1].p4().M()
            # mass of visible object on side A.  Must be >=0.
            pxB = bs[1].p4().Px()
            # x momentum of visible object on side A.
            pyB = bs[1].p4().Py()
            # y momentum of visible object on side A.

            pxMiss = taus[0].p4().Px() + taus[1].p4().Px() + met.p4().Px(
            )  # x component of missing transverse momentum.
            pyMiss = taus[0].p4().Py() + taus[1].p4().Py() + met.p4().Py(
            )  # x component of missing transverse momentum.

            chiA = taus[0].p4().M()
            # hypothesised mass of invisible on side A.  Must be >=0.
            chiB = taus[1].p4().M()
            # hypothesised mass of invisible on side B.  Must be >=0.

            desiredPrecisionOnMt2 = 0.
            # Must be >=0.  If 0 alg aims for machine precision.  if >0, MT2 computed to supplied absolute precision.
            useDeciSectionsInitially = True

            asymm_mt2 = asymm_mt2_lester_bisect()

            MT2 = asymm_mt2.get_mT2(mVisA, pxA, pyA, mVisB, pxB, pyB, pxMiss,
                                    pyMiss, chiA, chiB, desiredPrecisionOnMt2,
                                    useDeciSectionsInitially)

            #print 'MT2', MT2

            self.tree.fill('mT2', MT2)

            if len(lights) > 0:
                fillParticle(self.tree, 'j1', lights[0])
                if len(lights) > 1:
                    fillParticle(self.tree, 'j2', lights[1])

            def computeMT(taup4, metp4):
                scalar_prod = taup4.Px() * metp4.Px() + taup4.Py() * metp4.Py()
                return math.sqrt(2 * (taup4.Pt() * metp4.Pt() - scalar_prod))

            mt1 = computeMT(taus[0].p4(), met.p4())
            mt2 = computeMT(taus[1].p4(), met.p4())

            self.tree.fill('ta1_mt', mt1)
            self.tree.fill('ta2_mt', mt2)

            st = taus[0].p4().Pt() + taus[1].p4().Pt() + bs[0].p4().Pt(
            ) + bs[0].p4().Pt() + met.p4().Pt()
            self.tree.fill('sT', st)

            fillMet(self.tree, 'met', met)
            fillParticle(self.tree, 'htata', htatas[0])
            fillParticle(self.tree, 'hbb', hbbs[0])

            htata_metcorr_p4 = taus[0].p4() + taus[1].p4() + met.p4()
            htata_metcorr = Particle(25, 0, htata_metcorr_p4, 1)

            fillParticle(self.tree, 'htata_metcorr', htata_metcorr)

            hh = Resonance(htatas[0], hbbs[0], 25)
            hh_metcorr = Resonance(htata_metcorr, hbbs[0], 25)

            fillParticle(self.tree, 'hh', hh)
            fillParticle(self.tree, 'hh_metcorr', hh_metcorr)

            self.tree.fill('nbjets', len(event.selected_bs))
            self.tree.fill('nljets', len(event.selected_lights))
            self.tree.fill(
                'njets',
                len(event.selected_lights) + len(event.selected_bs) +
                len(event.selected_taus))
            self.tree.fill('nlep', len(event.selected_leptons))
            self.tree.fill('ntajets', len(event.selected_taus))

            drbb = deltaR(bs[0], bs[1])
            drtata = deltaR(taus[0], taus[1])

            self.tree.fill('drtata', drtata)
            self.tree.fill('drbb', drbb)

            # here fill all variables for BDT
            self.bdt_ta1_pt[0] = taus[0].p4().Pt()
            self.bdt_ta1_eta[0] = taus[0].p4().Eta()
            self.bdt_ta1_phi[0] = taus[0].p4().Phi()
            self.bdt_ta2_pt[0] = taus[1].p4().Pt()
            self.bdt_ta2_eta[0] = taus[1].p4().Eta()
            self.bdt_ta2_phi[0] = taus[1].p4().Phi()
            self.bdt_b1_pt[0] = bs[0].p4().Pt()
            self.bdt_b1_eta[0] = bs[0].p4().Eta()
            self.bdt_b1_phi[0] = bs[0].p4().Phi()
            self.bdt_b2_pt[0] = bs[1].p4().Pt()
            self.bdt_b2_eta[0] = bs[1].p4().Eta()
            self.bdt_b2_phi[0] = bs[1].p4().Phi()
            self.bdt_met_pt[0] = met.p4().Pt()
            self.bdt_met_phi[0] = met.p4().Phi()
            self.bdt_met_px[0] = met.p4().Px()
            self.bdt_met_py[0] = met.p4().Py()
            self.bdt_htata_pt[0] = htatas[0].p4().Pt()
            self.bdt_htata_eta[0] = htatas[0].p4().Eta()
            self.bdt_htata_phi[0] = htatas[0].p4().Phi()
            self.bdt_htata_m[0] = htatas[0].p4().M()
            self.bdt_hbb_pt[0] = hbbs[0].p4().Pt()
            self.bdt_hbb_eta[0] = hbbs[0].p4().Eta()
            self.bdt_hbb_phi[0] = hbbs[0].p4().Phi()
            self.bdt_hbb_m[0] = hbbs[0].p4().M()
            self.bdt_hh_pt[0] = hh.p4().Pt()
            self.bdt_hh_eta[0] = hh.p4().Eta()
            self.bdt_hh_phi[0] = hh.p4().Phi()
            self.bdt_hh_m[0] = hh.p4().M()
            self.bdt_ta1_mt[0] = mt1
            self.bdt_ta2_mt[0] = mt2
            self.bdt_mT2[0] = MT2
            self.bdt_sT[0] = st
            self.bdt_njets[0] = len(event.selected_lights) + len(
                event.selected_bs) + len(event.selected_taus)
            self.bdt_nbjets[0] = len(event.selected_bs)
            self.bdt_ntajets[0] = len(event.selected_taus)
            #self.bdt_nlep     [0] =  len(event.selected_leptons)

            #print MT2, ",", s ,",", len(event.selected_lights) + len(event.selected_bs) + len(event.selected_taus), ",", len(event.selected_bs) ,",", len(event.selected_taus) ,",", len(event.selected_leptons)t

            mva_value = self.reader.EvaluateMVA("BDT")
            #print mva_value
            self.tree.fill('tmva_bdt', mva_value)
            self.tree.tree.Fill()
Exemplo n.º 29
0
    def process(self, event):
        self.tree.reset()
        gen_bs = getattr(event, self.cfg_ana.gen_bs)
        gen_higgses = getattr(event, self.cfg_ana.gen_higgses)
        gen_higgses.sort(key=lambda x: x.pt(), reverse=True)
        jets = getattr(event, self.cfg_ana.fatjets)

        if len(gen_higgses) > 1:
            hh_gen = Resonance(gen_higgses[0], gen_higgses[1], 25)

        bjets = []
        ljets = []
        # do b-tagging on the fly ...
        for jet in jets:
            is_light = True
            for b in gen_bs:
                drjb = deltaR(b, jet)
                if drjb < 0.8:
                    is_light = False
            if is_light:
                ljets.append(jet)
            else:
                bjets.append(jet)

        bjets.sort(key=lambda x: x.pt(), reverse=True)
        ljets.sort(key=lambda x: x.pt(), reverse=True)

        #if (len(ljets)>0 and len(bjets)>1):
        if len(bjets) > 1:

            hh = Resonance(bjets[0], bjets[1], 25)
            if hh.pt() > 250.:

                #self.tree.fill('weight' , event.weight  )
                weight = (0.70**4) * event.weight
                self.tree.fill('weight', weight)

                self.tree.fill('nljets', len(ljets))
                self.tree.fill('njets', len(jets))
                self.tree.fill('nbjets', len(bjets))

                fillParticle(self.tree, 'bJet1', bjets[0])
                fillParticle(self.tree, 'bJet2', bjets[1])

                fillParticle(self.tree, 'softDropped_bJet1',
                             bjets[0].subjetsSoftDrop[0])
                fillParticle(self.tree, 'softDropped_bJet2',
                             bjets[1].subjetsSoftDrop[0])

                fillParticle(self.tree, 'hh', hh)
                self.tree.fill('drhh', deltaR(bjets[0], bjets[1]))

                self.tree.fill('dPtRel',
                               abs(bjets[0].pt() - bjets[1].pt()) / hh.pt())

                if (bjets[0].tau1 != 0.0):
                    self.tree.fill('bJet1_tau21',
                                   bjets[0].tau2 / bjets[0].tau1)
                else:
                    self.tree.fill('bJet1_tau21', -99)
                if (bjets[1].tau1 != 0.0):
                    self.tree.fill('bJet2_tau21',
                                   bjets[1].tau2 / bjets[1].tau1)
                else:
                    self.tree.fill('bJet2_tau21', -99)

                if len(ljets) > 0:

                    fillParticle(self.tree, 'lJet1', ljets[0])
                    fillParticle(self.tree, 'softDropped_lJet1',
                                 ljets[0].subjetsSoftDrop[0])

                    if (ljets[0].tau1 != 0.0):
                        self.tree.fill('lJet1_tau21',
                                       ljets[0].tau2 / ljets[0].tau1)
                    else:
                        self.tree.fill('lJet1_tau21', -99)

                if len(bjets) > 2:

                    fillParticle(self.tree, 'bJet3', bjets[2])
                    fillParticle(self.tree, 'softDropped_bJet3',
                                 bjets[2].subjetsSoftDrop[0])

                    if (bjets[2].tau1 != 0.0):
                        self.tree.fill('bJet3_tau21',
                                       bjets[2].tau2 / bjets[2].tau1)
                    else:
                        self.tree.fill('bJet3_tau21', -99)

                if len(ljets) > 1:

                    fillParticle(self.tree, 'lJet2', ljets[1])
                    fillParticle(self.tree, 'softDropped_lJet1',
                                 ljets[1].subjetsSoftDrop[0])

                    if (ljets[1].tau1 != 0.0):
                        self.tree.fill('lJet2_tau21',
                                       ljets[1].tau2 / ljets[1].tau1)
                    else:
                        self.tree.fill('lJet2_tau21', -99)

                if len(gen_higgses) > 1:
                    hh_gen = Resonance(gen_higgses[0], gen_higgses[1], 25)
                    fillParticle(self.tree, 'hh_gen', hh_gen)

                self.tree.tree.Fill()