Esempio n. 1
0
    def process(self, event):
        gen_particles_stable_and_neutrinos = getattr(
            event, self.cfg_ana.gen_particles_stable_and_neutrinos)
        gen_particles_stable = getattr(event,
                                       self.cfg_ana.gen_particles_stable)
        rec_particles = getattr(event, self.cfg_ana.rec_particles)

        event.total_gen = Resonance(gen_particles_stable_and_neutrinos, 0)
        event.total_gen_visible = Resonance(gen_particles_stable, 0)
        event.total_rec = Resonance(rec_particles, 0)
Esempio n. 2
0
    def process(self, event):
        '''Process the event.
        
        The event must contain:
         - self.cfg_ana.jets : the input collection of jets
         
        This method creates:
         - event.<self.instance_label> : output M3 particle
        '''
        jets = getattr(event, self.cfg_ana.jets)

        m3 = None
        pt3max = 0
        seljets = None
        #print jets

        if len(jets) >= 3:
            for l in list(itertools.permutations(jets, 3)):
                #ntag=sum([l[0].tags['b'],l[1].tags['b'],l[2].tags['b']])
                pt3 = (l[0].p4() + l[1].p4() + l[2].p4()).Pt()
                if pt3 > pt3max:
                    ptmax = pt3
                    seljets = l

            top_pdgid = 6
            m3 = Resonance(seljets, top_pdgid)
        setattr(event, self.instance_label, m3)
Esempio n. 3
0
    def process(self, event):
        self.tree.reset()
        zeds = getattr(event, self.cfg_ana.zeds)
        zeds.sort(key=lambda x: abs(x.m() - 91.))
        photons = getattr(event, self.cfg_ana.photons)
        photons.sort(key=lambda x: x.pt(), reverse=True)

        leptons = []
        if len(zeds) > 0 and len(photons) > 0:
            higgs = Resonance(zeds[0], photons[0], 25)

            self.tree.fill('weight', event.weight)

            # Reco Higgs
            fillParticle(self.tree, 'higgs', higgs)
            fillParticle(self.tree, 'zed', zeds[0])
            fillMet(self.tree, 'met', event.met)

            leptons.append(zeds[0].legs[0])
            leptons.append(zeds[0].legs[1])

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

            fillLepton(self.tree, 'l1', leptons[0])
            fillLepton(self.tree, 'l2', leptons[1])
            fillLepton(self.tree, 'a', photons[0])

            self.tree.tree.Fill()
Esempio n. 4
0
 def process(self, event):
     '''Process the event
     
     The event must contain:
      - self.cfg_ana.leg_collection: the input collection of particles
      
     This method creates:
      - event.<self.cfg_ana.output>: collection of resonances
      - event.<self.cfg_ana.output>_legs: the two legs of the best resonance.
     '''
     legs = getattr(event, self.cfg_ana.leg_collection)
     resonances = []
     for leg1, leg2 in itertools.combinations(legs, 2):
         resonances.append(Resonance(leg1, leg2, self.cfg_ana.pdgid))
     # sorting according to distance to nominal mass
     nominal_mass = mass[self.cfg_ana.pdgid]
     if self.cfg_ana.pdgid == 32:
         resonances.sort(key=lambda x: x.m(), reverse=True)
     else:
         resonances.sort(key=lambda x: abs(x.m() - nominal_mass))
     if len(resonances) > 1: print resonances
     setattr(event, self.cfg_ana.output, resonances)
     # getting legs of best resonance
     legs = []
     if len(resonances):
         legs = resonances[0].legs
     setattr(event, '_'.join([self.cfg_ana.output, 'legs']), legs)
Esempio n. 5
0
 def test_acoplanarity(self):
     '''test acoplanarity w/r to Patricks implementation
     '''
     ptc1 = Particle(11, -1, TLorentzVector(1, 2, 3, 7))
     ptc2 = Particle(-11, 1, TLorentzVector(2, 3, 4, 10))
     reso = Resonance(ptc1, ptc2, 23)
     self.assertEqual(reso.cross(), acop_patrick(reso.leg1(), reso.leg2()))
Esempio n. 6
0
    def process(self, event):
        leptons = getattr(event, "sel_iso_leptons")
        missing_rec = getattr(event, "missing_rec")

        w_lep = Resonance([leptons[0], missing_rec], 24)

        setattr(event, "w_lep", w_lep)
 def __init__(self, taus, jets):
     qqjetsp = [jet for jet in jets if jet not in taus]
     # assert(len(qqjetsp) == 2)
     self.zed = Resonance(qqjetsp, 23, 1)
     self.higgs = Resonance2(taus[0], taus[1], 25, 1)
     self.taus = taus
     self.jets2 = qqjetsp
     self.zed2 = self.zed
Esempio n. 8
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 :
Esempio n. 9
0
    def findHiggsPair(self, jets):
        hlist = []
        for jet in jets:
            jet.tags['higgs_from_pair'] = False
        for j1, j2, j3, j4 in itertools.permutations(jets):
            if j1.tags['ancestor'] == 25 and j2.tags['ancestor'] == 25:
                hlist.append(
                    [Resonance(j1, j2, 25), j1, j2,
                     Resonance(j3, j4, 23)])

            elif j3.tags['ancestor'] == 23 and j4.tags['ancestor'] == 23:
                hlist.append(
                    [Resonance(j1, j2, 25), j1, j2,
                     Resonance(j3, j4, 23)])
        hlist.sort(key=lambda x: abs(x[0].m() - mass[25]))
        hlist[0][1].tags['higgs_from_pair'] = True
        hlist[0][2].tags['higgs_from_pair'] = True
        return hlist[0][0], hlist[0][3]
Esempio n. 10
0
    def process(self, event):
        self.tree.reset()
        zeds = getattr(event, self.cfg_ana.zeds)
        zeds.sort(key=lambda x: abs(x.m()-91.))
        higgses = getattr(event, self.cfg_ana.higgses)

        self.tree.fill('weight' , event.weight )
        
        if len(zeds) > 1:
            
            # Reco zeds
            fillParticle(self.tree, 'zed1', zeds[0])
            fillParticle(self.tree, 'zed2', zeds[1])

            fillLepton(self.tree, 'zed1_lep1', zeds[0].legs[0])
            fillLepton(self.tree, 'zed1_lep2', zeds[0].legs[1])
            fillLepton(self.tree, 'zed2_lep1', zeds[1].legs[0])
            fillLepton(self.tree, 'zed2_lep2', zeds[1].legs[1])

            # MC truth zeds
            gen_zeds = []
            gen_zeds.append(Resonance(zeds[0].legs[0].gen, zeds[0].legs[1].gen, 23))
            gen_zeds.append(Resonance(zeds[1].legs[0].gen, zeds[1].legs[1].gen, 23))

            fillParticle(self.tree, 'gen_zed1', gen_zeds[0])
            fillParticle(self.tree, 'gen_zed2', gen_zeds[1])

            fillLepton(self.tree, 'gen_zed1_lep1', gen_zeds[0].legs[0])
            fillLepton(self.tree, 'gen_zed1_lep2', gen_zeds[0].legs[1])
            fillLepton(self.tree, 'gen_zed2_lep1', gen_zeds[1].legs[0])
            fillLepton(self.tree, 'gen_zed2_lep2', gen_zeds[1].legs[1])

        if len(higgses) > 0:  
            
            # Reco Higgs
            higgs = higgses[0]
            fillParticle(self.tree, 'higgs', higgs)

            # MC truth Higgs
            gen_higgs = Resonance(gen_zeds[0], gen_zeds[1], 25)
            fillParticle(self.tree, 'gen_higgs', gen_higgs)

        self.tree.tree.Fill()
Esempio n. 11
0
 def test_resonance(self):
     ptc1 = Particle(11, -1, TLorentzVector(1, 0, 0, 1))
     ptc2 = Particle(-11, 1, TLorentzVector(2, 0, 0, 2))
     reso = Resonance(ptc1, ptc2, 23)
     self.assertEqual(reso._pid, 23)
     self.assertEqual(reso.e(), 3)
     self.assertEqual(reso.leg1(), ptc1)
     self.assertEqual(reso.leg2(), ptc2)
     self.assertEqual(reso.q(), 0)
     self.assertEqual(reso.p4(), TLorentzVector(3, 0, 0, 3))
Esempio n. 12
0
 def process(self, event):
     jets = getattr(event, self.cfg_ana.input_jets)
     bjets = [jet for jet in jets if jet.tags['b']]
     higgses = []
     for leg1, leg2 in itertools.combinations(bjets, 2):
         higgses.append(Resonance(leg1, leg2, 25))
     higgs = None
     zed = None
     if len(higgses):
         # sorting according to distance to nominal mass
         nominal_mass = mass[25]
         higgses.sort(key=lambda x: abs(x.m() - nominal_mass))
         higgs = higgses[0]
         remaining_jets = copy.copy(jets)
         remaining_jets.remove(higgs.leg1())
         remaining_jets.remove(higgs.leg2())
         assert (len(remaining_jets) == 2)
         zed = Resonance(remaining_jets[0], remaining_jets[1], 21)
     setattr(event, self.cfg_ana.output_higgs, higgs)
     setattr(event, self.cfg_ana.output_zed, zed)
Esempio n. 13
0
 def process(self, event):
     legs = getattr(event, self.cfg_ana.leg_collection)
     resonances = []
     for leg1, leg2 in itertools.combinations(legs, 2):
         resonances.append(Resonance(leg1, leg2, self.cfg_ana.pdgid))
     # sorting according to distance to nominal mass
     nominal_mass = mass[self.cfg_ana.pdgid]
     resonances.sort(key=lambda x: abs(x.m() - nominal_mass))
     setattr(event, self.cfg_ana.output, resonances)
     # getting legs of best resonance
     legs = []
     if len(resonances):
         legs = resonances[0].legs
     setattr(event, '_'.join([self.cfg_ana.output, 'legs']), legs)
Esempio n. 14
0
    def process(self, event):

        self.counters['cut_flow'].inc('All events')
        newparticles = getattr(event, self.cfg_ana.newparticles)
        higgscandidates = getattr(event, self.cfg_ana.higgscandidates)
        jets = getattr(event, self.cfg_ana.input_jets)
        emfrac = [0, 0]
        for i in range(len(jets)):
            emfrac[i] = (jets[i].constituents[22].e() +
                         jets[i].constituents[11].e()) / jets[i].e()
        if emfrac[0] > 0.8 and emfrac[1] > 0.8:
            return False
        self.counters['cut_flow'].inc('EM fraction < 0.8')

        higgs = Resonance(higgscandidates[0], higgscandidates[1], 25)
        setattr(event, self.cfg_ana.higgs, higgs)
Esempio n. 15
0
 def process(self, event):
     '''Process the event
     
     The event must contain:
      - self.cfg_ana.leg_collection: the input collection of particles
      
     This method creates:
      - event.<self.cfg_ana.output>: collection of resonances
      - event.<self.cfg_ana.output>_legs: the two legs of the best resonance.
     '''
     legs = getattr(event, self.cfg_ana.leg_collection)
     resonances = []
     for leg1, leg2 in itertools.combinations(legs, 2):
         resonances.append(Resonance(leg1, leg2, self.cfg_ana.pdgid))
     # sorting according to distance to nominal mass
     nominal_mass = mass[self.cfg_ana.pdgid]
     resonances.sort(key=lambda x: abs(x.m() - nominal_mass))
     setattr(event, self.cfg_ana.output, resonances)
Esempio n. 16
0
    def process(self, event):
        jets = getattr(event, self.cfg_ana.jets)

        m3 = None
        pt3max = 0
        seljets = None
        #print jets

        if len(jets) >= 3:
            for l in list(itertools.permutations(jets, 3)):
                #ntag=sum([l[0].tags['b'],l[1].tags['b'],l[2].tags['b']])
                pt3 = (l[0].p4() + l[1].p4() + l[2].p4()).Pt()
                if pt3 > pt3max:
                    ptmax = pt3
                    seljets = l

            top_pdgid = 6
            m3 = Resonance(seljets, top_pdgid)
        setattr(event, self.instance_label, m3)
Esempio n. 17
0
 def test_many(self):
     nzeds = 100
     masses = np.linspace(80, 100, nzeds)
     boosts = np.linspace(1, 50, nzeds)
     thetas = np.linspace(1, math.pi, nzeds)
     for mass, boost, theta in zip(masses, boosts, thetas):
         energy = mass / 2.
         ptc1 = Particle(11, -1, TLorentzVector(0, energy, 0, energy))
         ptc2 = Particle(11, 1, TLorentzVector(0, -energy, 0, energy))
         resonance = Resonance(ptc1, ptc2, 23)
         p3_lab = TVector3()
         p3_lab.SetMagThetaPhi(boost, theta, 0.1)
         p4_lab = TLorentzVector()
         p4_lab.SetVectM(p3_lab, mass)
         bp4 = copy.deepcopy(resonance.p4())
         boost_vector = p4_lab.BoostVector()
         bp4.Boost(boost_vector)
         places = 8
         self.assertAlmostEqual(bp4.Vect().Mag(), boost, places)
         self.assertAlmostEqual(bp4.M(), mass, places)
         resonance.boost(boost_vector)
         self.assertAlmostEqual(bp4.E(), resonance.e(), places)
    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()
Esempio n. 19
0
    def process(self, event):
        legs = getattr(event, self.cfg_ana.leptons)

        uncleaned_zeds = []

        # first form all possible combinations, regardless of flavor or charge
        for leg1, leg2 in itertools.combinations(legs, 2):
            uncleaned_zeds.append(Resonance(leg1, leg2, 25))

        # check that leptons occur only in one pair and that they are same flavor, opp charge.
        zeds = []
        for z in uncleaned_zeds:
            if not self.matches(z, zeds): zeds.append(z)

        # sorting according to distance to nominal mass
        nominal_mass = 125
        zeds.sort(key=lambda x: abs(x.m() - nominal_mass))
        setattr(event, self.cfg_ana.output, zeds)

        # getting legs of best resonance
        legs = []
        if len(zeds):
            legs = zeds[0].legs
        setattr(event, '_'.join([self.cfg_ana.output, 'legs']), legs)
Esempio n. 20
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()
    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()
Esempio n. 22
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])

            for kl in kl_list:
                # here fill all variables for BDT

                self.bdt_a1_pt['bdt_a1_pt_{}'.format(
                    kl)][0] = photons[0].p4().Pt()
                self.bdt_a1_eta['bdt_a1_eta_{}'.format(
                    kl)][0] = photons[0].p4().Eta()
                self.bdt_a1_phi['bdt_a1_phi_{}'.format(
                    kl)][0] = photons[0].p4().Phi()
                self.bdt_a2_pt['bdt_a2_pt_{}'.format(
                    kl)][0] = photons[1].p4().Pt()
                self.bdt_a2_eta['bdt_a2_eta_{}'.format(
                    kl)][0] = photons[1].p4().Eta()
                self.bdt_a2_phi['bdt_a2_phi_{}'.format(
                    kl)][0] = photons[1].p4().Phi()
                self.bdt_b1_pt['bdt_b1_pt_{}'.format(kl)][0] = bs[0].p4().Pt()
                self.bdt_b1_eta['bdt_b1_eta_{}'.format(
                    kl)][0] = bs[0].p4().Eta()
                self.bdt_b1_phi['bdt_b1_phi_{}'.format(
                    kl)][0] = bs[0].p4().Phi()
                self.bdt_b2_pt['bdt_b2_pt_{}'.format(kl)][0] = bs[1].p4().Pt()
                self.bdt_b2_eta['bdt_b2_eta_{}'.format(
                    kl)][0] = bs[1].p4().Eta()
                self.bdt_b2_phi['bdt_b2_phi_{}'.format(
                    kl)][0] = bs[1].p4().Phi()
                self.bdt_met_pt['bdt_met_pt_{}'.format(
                    kl)][0] = event.met.p4().Pt()
                self.bdt_met_phi['bdt_met_phi_{}'.format(
                    kl)][0] = event.met.p4().Phi()
                self.bdt_met_px['bdt_met_px_{}'.format(
                    kl)][0] = event.met.p4().Px()
                self.bdt_met_py['bdt_met_py_{}'.format(
                    kl)][0] = event.met.p4().Py()
                self.bdt_haa_pt['bdt_haa_pt_{}'.format(
                    kl)][0] = haas[0].p4().Pt()
                self.bdt_haa_eta['bdt_haa_eta_{}'.format(
                    kl)][0] = haas[0].p4().Eta()
                self.bdt_haa_phi['bdt_haa_phi_{}'.format(
                    kl)][0] = haas[0].p4().Phi()
                self.bdt_haa_m['bdt_haa_m_{}'.format(kl)][0] = haas[0].p4().M()
                self.bdt_hbb_pt['bdt_hbb_pt_{}'.format(
                    kl)][0] = hbbs[0].p4().Pt()
                self.bdt_hbb_eta['bdt_hbb_eta_{}'.format(
                    kl)][0] = hbbs[0].p4().Eta()
                self.bdt_hbb_phi['bdt_hbb_phi_{}'.format(
                    kl)][0] = hbbs[0].p4().Phi()
                self.bdt_hbb_m['bdt_hbb_m_{}'.format(kl)][0] = hbbs[0].p4().M()
                self.bdt_hh_pt['bdt_hh_pt_{}'.format(kl)][0] = hh.p4().Pt()
                self.bdt_hh_eta['bdt_hh_eta_{}'.format(kl)][0] = hh.p4().Eta()
                self.bdt_hh_phi['bdt_hh_phi_{}'.format(kl)][0] = hh.p4().Phi()
                self.bdt_hh_m['bdt_hh_m_{}'.format(kl)][0] = hh.p4().M()
                self.bdt_njets['bdt_njets_{}'.format(kl)][0] = len(
                    event.selected_lights) + len(event.selected_bs)
                self.bdt_nbjets['bdt_nbjets_{}'.format(kl)][0] = len(
                    event.selected_bs)
                self.bdt_nljets['bdt_nljets_{}'.format(kl)][0] = len(
                    event.selected_lights)

                self.bdt2_a1_pt['bdt2_a1_pt_{}'.format(
                    kl)][0] = photons[0].p4().Pt()
                self.bdt2_a1_eta['bdt2_a1_eta_{}'.format(
                    kl)][0] = photons[0].p4().Eta()
                self.bdt2_a1_phi['bdt2_a1_phi_{}'.format(
                    kl)][0] = photons[0].p4().Phi()
                self.bdt2_a2_pt['bdt2_a2_pt_{}'.format(
                    kl)][0] = photons[1].p4().Pt()
                self.bdt2_a2_eta['bdt2_a2_eta_{}'.format(
                    kl)][0] = photons[1].p4().Eta()
                self.bdt2_a2_phi['bdt2_a2_phi_{}'.format(
                    kl)][0] = photons[1].p4().Phi()
                self.bdt2_b1_pt['bdt2_b1_pt_{}'.format(
                    kl)][0] = bs[0].p4().Pt()
                self.bdt2_b1_eta['bdt2_b1_eta_{}'.format(
                    kl)][0] = bs[0].p4().Eta()
                self.bdt2_b1_phi['bdt2_b1_phi_{}'.format(
                    kl)][0] = bs[0].p4().Phi()
                self.bdt2_b2_pt['bdt2_b2_pt_{}'.format(
                    kl)][0] = bs[1].p4().Pt()
                self.bdt2_b2_eta['bdt2_b2_eta_{}'.format(
                    kl)][0] = bs[1].p4().Eta()
                self.bdt2_b2_phi['bdt2_b2_phi_{}'.format(
                    kl)][0] = bs[1].p4().Phi()
                self.bdt2_met_pt['bdt2_met_pt_{}'.format(
                    kl)][0] = event.met.p4().Pt()
                self.bdt2_met_phi['bdt2_met_phi_{}'.format(
                    kl)][0] = event.met.p4().Phi()
                self.bdt2_met_px['bdt2_met_px_{}'.format(
                    kl)][0] = event.met.p4().Px()
                self.bdt2_met_py['bdt2_met_py_{}'.format(
                    kl)][0] = event.met.p4().Py()
                self.bdt2_haa_pt['bdt2_haa_pt_{}'.format(
                    kl)][0] = haas[0].p4().Pt()
                self.bdt2_haa_eta['bdt2_haa_eta_{}'.format(
                    kl)][0] = haas[0].p4().Eta()
                self.bdt2_haa_phi['bdt2_haa_phi_{}'.format(
                    kl)][0] = haas[0].p4().Phi()
                self.bdt2_haa_m['bdt2_haa_m_{}'.format(
                    kl)][0] = haas[0].p4().M()
                self.bdt2_hbb_pt['bdt2_hbb_pt_{}'.format(
                    kl)][0] = hbbs[0].p4().Pt()
                self.bdt2_hbb_eta['bdt2_hbb_eta_{}'.format(
                    kl)][0] = hbbs[0].p4().Eta()
                self.bdt2_hbb_phi['bdt2_hbb_phi_{}'.format(
                    kl)][0] = hbbs[0].p4().Phi()
                self.bdt2_hbb_m['bdt2_hbb_m_{}'.format(
                    kl)][0] = hbbs[0].p4().M()
                self.bdt2_hh_pt['bdt2_hh_pt_{}'.format(kl)][0] = hh.p4().Pt()
                self.bdt2_hh_eta['bdt2_hh_eta_{}'.format(
                    kl)][0] = hh.p4().Eta()
                self.bdt2_hh_phi['bdt2_hh_phi_{}'.format(
                    kl)][0] = hh.p4().Phi()
                self.bdt2_hh_m['bdt2_hh_m_{}'.format(kl)][0] = hh.p4().M()
                self.bdt2_njets['bdt2_njets_{}'.format(kl)][0] = len(
                    event.selected_lights) + len(event.selected_bs)
                self.bdt2_nbjets['bdt2_nbjets_{}'.format(kl)][0] = len(
                    event.selected_bs)
                self.bdt2_nljets['bdt2_nljets_{}'.format(kl)][0] = len(
                    event.selected_lights)

                mva_value2 = self.reader2['reader2_{}'.format(kl)].EvaluateMVA(
                    "BDT")
                #print mva_value2
                self.tree.fill('tmva_bdt_singleh_{}'.format(kl), mva_value2)

                #print '--------------------------------------------'
                mva_value = self.reader['reader_{}'.format(kl)].EvaluateMVA(
                    "BDT")
                #print mva_value
                self.tree.fill('tmva_bdt_qcd_{}'.format(kl), mva_value)

                #print kl, mva_value, mva_value2

            self.tree.tree.Fill()
            '''
Esempio n. 23
0
    def process(self, event):

        def debug():
            for top in tops:
                print "TOP"
                print top
                print
                for top_daughter in top.daughters:
                    print "TOP daughter"
                    print top_daughter
                    print
                    for top_grand_daughter in top_daughter.daughters:
                        print "W-daughter"
                        print top_grand_daughter
                        print
                        for top_grand_grand_daughter in top_grand_daughter.daughters:
                            print "real w daughter"
                            print top_grand_grand_daughter
                            print
                            for top_grand_grand_grand_daughter in top_grand_grand_daughter.daughters:
                                print "top_grand_grand_grand_daughter"
                                print top_grand_grand_grand_daughter
                                print
                            print
                        print
                    print
                print

        def match_lepton(lepton):

            if abs(lepton.pdgid()) in [11, 13]:
                if lepton.status() == 1:
                    #setattr(event, self.cfg_ana.output1, lepton)
                    mc_leptons.append(lepton)
                    return 1
                else:
                    for stable_lepton in event.genbrowser.descendants(w):
                        if stable_lepton.pdgid() == lepton.pdgid() and stable_lepton.status() == 1:
                            #setattr(event, self.cfg_ana.output1, stable_lepton)
                            mc_leptons.append(stable_lepton)
                            return 1
                    print "error, didn't find any stable lepton among lepton.descendants"
                    import pdb; pdb.set_trace()
                    return False

            elif abs(lepton.pdgid()) == 15:
                if lepton.status() == 2:
                    #setattr(event, self.cfg_ana.output1, lepton)
                    mc_leptons.append(lepton)
                    return 1
                else:
                    for stable_lepton in event.genbrowser.descendants(w):
                        if stable_lepton.pdgid() == lepton.pdgid() and stable_lepton.status() == 2:
                            #setattr(event, self.cfg_ana.output1, stable_lepton)
                            mc_leptons.append(stable_lepton)
                            found = True
                            return 1
                    print "error, didn't find any stable tau among lepton.descendants"
                    import pdb; pdb.set_trace()
                    return False

            elif abs(lepton.pdgid()) in [12, 14, 16]:
                if lepton.status() == 1:
                    #setattr(event, self.cfg_ana.output2, lepton)
                    mc_neutrinos.append(lepton)
                    return 1
                else:
                    for stable_lepton in event.genbrowser.descendants(w):
                        if stable_lepton.pdgid() == lepton.pdgid() and stable_lepton.status() == 1:
                            #setattr(event, self.cfg_ana.output2, stable_lepton)
                            mc_neutrinos.append(stable_lepton)
                            found = True
                            return 1
                    print "error, didn't find any stable neutrino among lepton.descendants"
                    import pdb; pdb.set_trace()
                    return False

            elif abs(lepton.pdgid()) == 24:
                sum_lep = 0
                for ptc_daughter in lepton.daughters:
                    sum_lep += match_lepton(ptc_daughter)
                return sum_lep
            else:
                return 0


        gen_particles = event.gen_particles

        tops = []
        for gen_ptc in gen_particles:
            if abs(gen_ptc.pdgid()) == 6:
                tops.append(gen_ptc)

        found_leptons = 0
        mc_leptons = []
        mc_neutrinos = [] 
        for top in tops:
            for w in top.daughters:
                # if it's a W boson
                if abs(w.pdgid()) == 24:
                    # check if the daughter is another w or a lepton
                    for ptc in w.daughters:
                        if abs(ptc.pdgid()) == 24:
                            for lepton in ptc.daughters:
                                found_leptons += match_lepton(lepton)

                        else:
                            found_leptons += match_lepton(ptc)
                            
                            
        setattr(event, self.cfg_ana.output1, mc_leptons)
        setattr(event, self.cfg_ana.output2, mc_neutrinos)
        
        if found_leptons != 2:
            print event
            print "found not right number of leptons ", found_leptons
            print "Disabled the return False statement in MCLeptonFinder.py analyzer for now"
            #return False

        mc_lepton = getattr(event, self.cfg_ana.output1)
        mc_neutrino = getattr(event, self.cfg_ana.output2)

        mc_w_lep = []
        if len(mc_lepton) == len(mc_neutrino):
            for i in range(len(mc_lepton)):
                mc_w_lep.append(Resonance([mc_lepton[i], mc_neutrino[i]], 24))
        setattr(event, "mc_w_lep", mc_w_lep)

        leptons = getattr(event, self.cfg_ana.sel_leptons)
        for lepton in leptons:
            for imc,mc_lep in enumerate(mc_lepton):
                if lepton.match == mc_lep:
                    lepton.match_with_mc = imc+1
                else:
                    lepton.match_with_mc = 0
Esempio n. 24
0
    def process(self, event):
        self.tree.reset()

        ## these pairs contain overlap
        hbbs = getattr(event, self.cfg_ana.hbbs)
        bs = getattr(event, self.cfg_ana.bs)
        hbbs.sort(key=lambda x: abs(x.m() - 125.))

        if len(bs) > 3:

            def bestHiggsPair(hbbs):

                higgs_pairs = []

                for p in hbbs:
                    p1 = p.leg1()
                    p2 = p.leg2()

                    for m in hbbs:
                        m1 = m.leg1()
                        m2 = m.leg2()

                        if m1 == p1 or m1 == p2 or m2 == p1 or m2 == p2:
                            continue

                        fillpair = True
                        for hp in higgs_pairs:

                            if m in hp and p in hp:
                                fillpair = False

                        if fillpair:
                            higgs_pairs.append((p, m))

                higgs_pairs.sort(key=lambda x: abs(x[0].m() - x[1].m()))
                return higgs_pairs[0]

            higgs_pair = bestHiggsPair(hbbs)

            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)

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

            hh = Resonance(higgs_pair[0], higgs_pair[1], 25)

            higgses = [higgs_pair[0], higgs_pair[1]]
            higgses.sort(key=lambda x: x.pt(), reverse=True)

            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_b3_pt[0] = bs[2].p4().Pt()
            self.bdt_b3_eta[0] = bs[2].p4().Eta()
            self.bdt_b3_phi[0] = bs[2].p4().Phi()

            self.bdt_b4_pt[0] = bs[3].p4().Pt()
            self.bdt_b4_eta[0] = bs[3].p4().Eta()
            self.bdt_b4_phi[0] = bs[3].p4().Phi()

            self.bdt_h1_pt[0] = higgses[0].p4().Pt()
            self.bdt_h1_eta[0] = higgses[0].p4().Eta()
            self.bdt_h1_phi[0] = higgses[0].p4().Phi()
            self.bdt_h1_m[0] = higgses[0].p4().M()

            self.bdt_h2_pt[0] = higgses[1].p4().Pt()
            self.bdt_h2_eta[0] = higgses[1].p4().Eta()
            self.bdt_h2_phi[0] = higgses[1].p4().Phi()
            self.bdt_h2_m[0] = higgses[1].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()

            mva_value = self.reader.EvaluateMVA("BDT")
            print mva_value

            fillParticle(self.tree, 'hh', hh)
            fillParticle(self.tree, 'h1', higgses[0])
            fillParticle(self.tree, 'h2', higgses[1])
            fillParticle(self.tree, 'b1', bs[0])
            fillParticle(self.tree, 'b2', bs[1])
            fillParticle(self.tree, 'b3', bs[2])
            fillParticle(self.tree, 'b4', bs[3])

            self.tree.fill('tmva_bdt', mva_value)
            self.tree.tree.Fill()
Esempio 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)
        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()
Esempio n. 26
0
    def process(self, event):

        self.counters['cut_flow'].inc('All events')
        
        gammas2 = getattr(event, self.cfg_ana.photons)
        if len(gammas2)<2:
            return False
        self.counters['cut_flow'].inc('>= 2 photons')

        gammas1 = [gamma1 for gamma1 in gammas2 if (gamma1.e()>=40)]
        if len(gammas1)<2:
            return False
        self.counters['cut_flow'].inc('e>=40GeV')

        gammas = [gamma for gamma in gammas1 if abs(gamma.eta())<2.5]
        if len(gammas)<2:
            return False
        self.counters['cut_flow'].inc('eta < 2.5')
       
        if len(gammas)==2:
            higgscandidates = (gammas[0], gammas[1]) 
        
        if len(gammas)>2:
            min_mass_diff = 9999.9
            photon_id_1 = -1
            photon_id_2 = -1
            for i in range(len(gammas)):
                for j in range(len(gammas)):
                    if i<j:
                        recoil_mass_square = ((240 - gammas[i].e() - gammas[j].e())**2 - numpy.dot((gammas[i].p3()+gammas[j].p3()),(gammas[i].p3()+gammas[j].p3())))
                        if recoil_mass_square < 0:
                            print 'Negative recoil mass squared'
                            break
                        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
                            photon_id_1 = i
                            photon_id_2 = j
            higgscandidates = (gammas[photon_id_1],gammas[photon_id_2])

        isosum = 0	
        isolations = []
        for candidate in higgscandidates:
            isolation = candidate.iso.sume/candidate.e()
            isosum += isolation
            isolations.append(isolation)
#        if isosum >= 0.4:
#            return False
#        self.counters['cut_flow'].inc('sum of photon isolations < 0.4')

        etagap = abs(higgscandidates[0].eta() - higgscandidates[1].eta())
#        if etagap >= 1.8:
#            return False
#        self.counters['cut_flow'].inc('pseudorapidity gap < 1.8')

        higgs = Resonance(higgscandidates[0], higgscandidates[1], 25)
#        if numpy.degrees(abs(higgs.theta())) >= 65:
#            return False
#        self.counters['cut_flow'].inc('Higgs candidate beam angle > 25 degrees')

        genphotons = getattr(event, self.cfg_ana.genphotons)
        status = []
        matchedphotons = []
        mothers = []
        for particle in higgscandidates:
            if particle.match is not None:
                status.append(particle.match.status())
                matchedphotons.append(particle.match)
                for i in range(len(particle.match.mothers)):
                    mothers.append(particle.match.mothers[i])
            if particle.match is None:
                print 'No match found'
        
        mass_square = (2*(higgscandidates[0].e()*higgscandidates[1].e()) - 2*numpy.dot(higgscandidates[0].p3(),higgscandidates[1].p3()))
        if mass_square < 0:
            mass = 0
            print 'Negative mass squared'
        else:
            mass = math.sqrt(mass_square) 

        setattr(event, self.cfg_ana.higgs, higgs)
        setattr(event, self.cfg_ana.photons, higgscandidates)
        setattr(event, self.cfg_ana.isolations, isolations)
        setattr(event, self.cfg_ana.status, status)
        setattr(event, self.cfg_ana.matchedphotons, matchedphotons)
        setattr(event, self.cfg_ana.mothers, mothers)
        setattr(event, self.cfg_ana.etagap, etagap)
        setattr(event, self.cfg_ana.isosum, isosum)