Ejemplo n.º 1
0
 def closestMatch(self,phiRef,etaRef,phis,etas):
     minDr = 999999.
     minIdx = None
     for i in range(len(phis)):
         dr = deltaR(phiRef,etaRef,phis[i],etas[i])
         if dr<minDr:
             minDr = dr
             minIdx = i
     return (minDr, minIdx)
Ejemplo n.º 2
0
 def closestMatch(self, phiRef, etaRef, phis, etas):
     minDr = 999999.
     minIdx = None
     for i in range(len(phis)):
         dr = deltaR(phiRef, etaRef, phis[i], etas[i])
         if dr < minDr:
             minDr = dr
             minIdx = i
     return (minDr, minIdx)
Ejemplo n.º 3
0
    def fill(self,eh,sample,itree):


        self.timers[0].start()
        if not sample.isData():
#            w = eh.get("weight")*sample.downscale*sample.extweight
#            if self.reweightDY:
#                w *= self.reweightClass.isrWeightDY(zpt)
            w = eh.get("xsec")*sample.baseweights[itree]*sample.downscale*sample.extweight
            if sample.mcReweight:
                w *= sample.mcReweight.weight(eh)
        else:
            w = 1
        self.timers[0].stop()        

        if len(self.flavours)<2:
            pdgLep = None
        else:
            pdgLep = 0
        self.fill1DByFlavour("before",pdgLep,1,w)
        self.passedCutByFlavour("all",pdgLep,w)

        ht = eh.get("htJet30j")
        self.fill1DByFlavour("ht",pdgLep,ht,w)
        if ht<500:
            return
        self.passedCutByFlavour("ht500",pdgLep,w)

        tightLeps = tightLeptons(eh)
        nTightLep = len(tightLeps)
        self.fill1DByFlavour("nTightLep",pdgLep,nTightLep,w)
        if nTightLep!=1:
            return
        self.passedCutByFlavour("oneTightLep",pdgLep,w)

        # now lepton flavour is defined
        if len(self.flavours)>=2 or self.options.channel!=None:
            pdgLep = eh.get("LepGood_pdgId")[tightLeps[0]]
            if ( self.options.channel=="Ele" and abs(pdgLep)!=11 ) or \
               ( self.options.channel=="Mu" and abs(pdgLep)!=13 ):
                return
        if len(self.flavours)==1:
            pdgLep = None
        lepPt = eh.get("LepGood_pt")[tightLeps[0]]

        vetoLeps = vetoLeptons(eh)
        nVetoLep = len(vetoLeps)
        self.fill1DByFlavour("nVetoLep",pdgLep,nVetoLep,w)
        if nVetoLep>0:
            return
        self.passedCutByFlavour("noVetoLep",pdgLep,w)

        goodJs = goodJets(eh)
        nGoodJs = len(goodJs)
        self.fill1DByFlavour("nJet30",pdgLep,nGoodJs,w)
        if nGoodJs<4:
            return
        self.passedCutByFlavour("njet4",pdgLep,w)

        jet1Pt = eh.get("Jet_pt")[goodJs[0]]
        jet2Pt = eh.get("Jet_pt")[goodJs[1]]

        self.fill1DByFlavour("nVert",pdgLep,eh.get("nVert"),w)
        self.fill1DByFlavour("ptJet1",pdgLep,jet1Pt,w)
        self.fill1DByFlavour("ptJet2",pdgLep,jet2Pt,w)
        if jet2Pt<80.:
            return
        self.passedCutByFlavour("jet2Pt80",pdgLep,w)

        met = eh.get("met_pt")
        metPhi = eh.get("met_phi")

        lt = met + lepPt
        self.fill1DByFlavour("lt",pdgLep,lt,w)
        if lt<250:
            return
        self.passedCutByFlavour("lt250",pdgLep,w)

        nBJets = eh.get("nBJetMedium30")
        if nBJets==0:
            self.passedCutByFlavour("nb0",pdgLep,w)
        else:
            self.passedCutByFlavour("nbge1",pdgLep,w)

        self.selection.set(eh)
        lt2 = self.selection.wkin.lt()
        assert abs(lt2-lt)/lt<0.00001
        dphi = abs(self.selection.wkin.dPhi())
        self.fill1DByFlavour("dPhi",pdgLep,abs(dphi),w)
        self.fill1DByFlavour("lp",pdgLep,self.selection.wkin.lp(),w)

        incRegSign = -1 if dphi<0.75 else +1
        incRegs = [ 1 ]
#        self.fill1DByFlavour("InclusiveRegs",pdgLep,incRegSign*1,w)
#        self.fill1DByFlavour("dPhiIncReg1",pdgLep,dphi,w)
        if nGoodJs>=3 and nGoodJs<=4 and nBJets==0:
            incRegs.append(2)
#            self.fill1DByFlavour("InclusiveRegs",pdgLep,incRegSign*2,w)
#            self.fill1DByFlavour("dPhiIncReg2",pdgLep,dphi,w)
        if nGoodJs>=4 and nGoodJs<=5 and nBJets<3:
            incRegs.append(3+min(nBJets,2))
#            self.fill1DByFlavour("InclusiveRegs",pdgLep,incRegSign*(3+min(nBJets,2)),w)
#            self.fill1DByFlavour("dPhiIncReg"+str(min(nBJets,2)+3),pdgLep,dphi,w)
        for ir in incRegs:
            self.fill1DByFlavour("InclusiveRegs",pdgLep,incRegSign*ir,w)
            self.fill1DByFlavour("dPhiIncReg"+str(ir),pdgLep,dphi,w)
            self.fill1DByFlavour("metIncReg"+str(ir),pdgLep,met,w)
            jetPhi = eh.get("Jet_phi")[goodJs[0]]
            self.fill1DByFlavour("dPhiJet1MetIncReg"+str(ir),pdgLep,abs(deltaPhi(metPhi,jetPhi)),w)
            self.fill1DByFlavour("ptLepIncReg"+str(ir),pdgLep,lepPt,w)
            self.fill1DByFlavour("isoLepIncReg"+str(ir),pdgLep,eh.get("LepGood_miniRelIso")[tightLeps[0]],w)
            self.fill1DByFlavour("lpIncReg"+str(ir),pdgLep,self.selection.wkin.lp(),w)

#        if nGoodJs<5:
#            return

        self.fill1DByFlavour("nBJet",pdgLep,nBJets,w)
        self.fill1DByFlavour("ptLep",pdgLep,lepPt,w)
        self.fill1DByFlavour("isoLep",pdgLep,eh.get("LepGood_miniRelIso")[tightLeps[0]],w)
        self.fill1DByFlavour("dxyLep",pdgLep,eh.get("LepGood_dxy")[tightLeps[0]],w)
        self.fill1DByFlavour("dzLep",pdgLep,eh.get("LepGood_dz")[tightLeps[0]],w)
        self.fill1DByFlavour("sip3dLep",pdgLep,eh.get("LepGood_sip3d")[tightLeps[0]],w)
        jetDRLep = deltaR(eh.get("Jet_phi")[goodJs[0]],eh.get("Jet_eta")[goodJs[0]],
                          eh.get("LepGood_phi")[tightLeps[0]],eh.get("LepGood_eta")[tightLeps[0]])
        self.fill1DByFlavour("jet1DRLep",pdgLep,jetDRLep,w)
        jetDRLep = deltaR(eh.get("Jet_phi")[goodJs[1]],eh.get("Jet_eta")[goodJs[1]],
                          eh.get("LepGood_phi")[tightLeps[0]],eh.get("LepGood_eta")[tightLeps[0]])
        self.fill1DByFlavour("jet2DRLep",pdgLep,jetDRLep,w)
        self.fill1DByFlavour("met",pdgLep,eh.get("met_pt"),w)
        self.fill1DByFlavour("metPhi",pdgLep,metPhi,w)
        jetPhi = eh.get("Jet_phi")[goodJs[0]]
        self.fill1DByFlavour("dPhiMetJet1",pdgLep,abs(deltaPhi(metPhi,jetPhi)),w)
        jetPhi = eh.get("Jet_phi")[goodJs[1]]
        self.fill1DByFlavour("dPhiMetJet2",pdgLep,abs(deltaPhi(metPhi,jetPhi)),w)
#        assert eh.get("nBJetMedium30")==self.selection.nBJets
#        if eh.get("nBJetMedium30")>0:
#            return
#        assert self.selection.preselection()
        #
        # W+jets region:
        #
        wRs = self.selection.wRegions()
        for r in wRs:
            assert r[0]=="C" or r[0]=="S"
            if r[0]=="C":
                self.fill1DByFlavour("wCSRs",pdgLep,-int(r[2:]),w)
            else:
                self.fill1DByFlavour("wCSRs",pdgLep,int(r[2:]),w)
        #
        # ttbar region:
        #
        for ib in [ 0, 1, 2 ]:
            ttRs = self.selection.ttRegions(ib)
            for r in ttRs:
                assert r[0]=="C" or r[0]=="S"
                hn = "tt" + str(ib) + "bCSRs"
                if r[0]=="C":
                    self.fill1DByFlavour(hn,pdgLep,-int(r[2:]),w)
                else:
                    self.fill1DByFlavour(hn,pdgLep,int(r[2:]),w)
            
            
        region = self.selection.region()
#        if region==None:
#            self.fill1DByFlavour("CSRs",pdgLep,0.,w)
#            print "*Rejected: ",eh.get("nBJetMedium30"),self.selection.preselection(),self.selection.__dict__
        if region!=None:
            assert region[0]=="C" or region[0]=="S"
            ir = int(region[2:])
            if region[0]=="C":
                self.fill1DByFlavour("CSRs",pdgLep,-ir,w)
            else:
                self.fill1DByFlavour("CSRs",pdgLep,ir,w)
            self.fill1DByFlavour("dPhiR"+"{0:02d}".format(ir),pdgLep,abs(dphi),w)
            self.passedCutByFlavour(region,pdgLep,w,nameFlow="CSRflow")
            
        self.fill1DByFlavour("after",pdgLep,1,w)
Ejemplo n.º 4
0
    def fill(self, eh, sample, itree):

        self.timers[0].start()
        if not sample.isData():
            #            w = eh.get("weight")*sample.downscale*sample.extweight
            #            if self.reweightDY:
            #                w *= self.reweightClass.isrWeightDY(zpt)
            w = eh.get("xsec") * sample.baseweights[itree] * sample.downscale * sample.extweight
            if sample.mcReweight:
                w *= sample.mcReweight.weight(eh)
        else:
            w = 1
        self.timers[0].stop()

        if len(self.flavours) < 2:
            pdgLep = None
        else:
            pdgLep = 0
        self.fill1DByFlavour("before", pdgLep, 1, w)
        self.passedCutByFlavour("all", pdgLep, w)

        ht = eh.get("htJet30j")
        self.fill1DByFlavour("ht", pdgLep, ht, w)
        if ht < 500:
            return
        self.passedCutByFlavour("ht500", pdgLep, w)

        tightLeps = tightLeptons(eh)
        nTightLep = len(tightLeps)
        self.fill1DByFlavour("nTightLep", pdgLep, nTightLep, w)
        if nTightLep != 1:
            return
        self.passedCutByFlavour("oneTightLep", pdgLep, w)

        # now lepton flavour is defined
        if len(self.flavours) >= 2 or self.options.channel != None:
            pdgLep = eh.get("LepGood_pdgId")[tightLeps[0]]
            if (self.options.channel == "Ele" and abs(pdgLep) != 11) or (
                self.options.channel == "Mu" and abs(pdgLep) != 13
            ):
                return
        if len(self.flavours) == 1:
            pdgLep = None
        lepPt = eh.get("LepGood_pt")[tightLeps[0]]

        vetoLeps = vetoLeptons(eh)
        nVetoLep = len(vetoLeps)
        self.fill1DByFlavour("nVetoLep", pdgLep, nVetoLep, w)
        if nVetoLep > 0:
            return
        self.passedCutByFlavour("noVetoLep", pdgLep, w)

        goodJs = goodJets(eh)
        nGoodJs = len(goodJs)
        self.fill1DByFlavour("nJet30", pdgLep, nGoodJs, w)
        if nGoodJs < 4:
            return
        self.passedCutByFlavour("njet4", pdgLep, w)

        jet1Pt = eh.get("Jet_pt")[goodJs[0]]
        jet2Pt = eh.get("Jet_pt")[goodJs[1]]

        self.fill1DByFlavour("nVert", pdgLep, eh.get("nVert"), w)
        self.fill1DByFlavour("ptJet1", pdgLep, jet1Pt, w)
        self.fill1DByFlavour("ptJet2", pdgLep, jet2Pt, w)
        if jet2Pt < 80.0:
            return
        self.passedCutByFlavour("jet2Pt80", pdgLep, w)

        met = eh.get("met_pt")
        metPhi = eh.get("met_phi")

        lt = met + lepPt
        self.fill1DByFlavour("lt", pdgLep, lt, w)
        if lt < 250:
            return
        self.passedCutByFlavour("lt250", pdgLep, w)

        nBJets = eh.get("nBJetMedium30")
        if nBJets == 0:
            self.passedCutByFlavour("nb0", pdgLep, w)
        else:
            self.passedCutByFlavour("nbge1", pdgLep, w)

        self.selection.set(eh)
        lt2 = self.selection.wkin.lt()
        assert abs(lt2 - lt) / lt < 0.00001
        dphi = abs(self.selection.wkin.dPhi())
        self.fill1DByFlavour("dPhi", pdgLep, abs(dphi), w)
        self.fill1DByFlavour("lp", pdgLep, self.selection.wkin.lp(), w)

        incRegSign = -1 if dphi < 0.75 else +1
        incRegs = [1]
        #        self.fill1DByFlavour("InclusiveRegs",pdgLep,incRegSign*1,w)
        #        self.fill1DByFlavour("dPhiIncReg1",pdgLep,dphi,w)
        if nGoodJs >= 3 and nGoodJs <= 4 and nBJets == 0:
            incRegs.append(2)
        #            self.fill1DByFlavour("InclusiveRegs",pdgLep,incRegSign*2,w)
        #            self.fill1DByFlavour("dPhiIncReg2",pdgLep,dphi,w)
        if nGoodJs >= 4 and nGoodJs <= 5 and nBJets < 3:
            incRegs.append(3 + min(nBJets, 2))
        #            self.fill1DByFlavour("InclusiveRegs",pdgLep,incRegSign*(3+min(nBJets,2)),w)
        #            self.fill1DByFlavour("dPhiIncReg"+str(min(nBJets,2)+3),pdgLep,dphi,w)
        for ir in incRegs:
            self.fill1DByFlavour("InclusiveRegs", pdgLep, incRegSign * ir, w)
            self.fill1DByFlavour("dPhiIncReg" + str(ir), pdgLep, dphi, w)
            self.fill1DByFlavour("metIncReg" + str(ir), pdgLep, met, w)
            jetPhi = eh.get("Jet_phi")[goodJs[0]]
            self.fill1DByFlavour("dPhiJet1MetIncReg" + str(ir), pdgLep, abs(deltaPhi(metPhi, jetPhi)), w)
            self.fill1DByFlavour("ptLepIncReg" + str(ir), pdgLep, lepPt, w)
            self.fill1DByFlavour("isoLepIncReg" + str(ir), pdgLep, eh.get("LepGood_miniRelIso")[tightLeps[0]], w)
            self.fill1DByFlavour("lpIncReg" + str(ir), pdgLep, self.selection.wkin.lp(), w)

        #        if nGoodJs<5:
        #            return

        self.fill1DByFlavour("nBJet", pdgLep, nBJets, w)
        self.fill1DByFlavour("ptLep", pdgLep, lepPt, w)
        self.fill1DByFlavour("isoLep", pdgLep, eh.get("LepGood_miniRelIso")[tightLeps[0]], w)
        self.fill1DByFlavour("dxyLep", pdgLep, eh.get("LepGood_dxy")[tightLeps[0]], w)
        self.fill1DByFlavour("dzLep", pdgLep, eh.get("LepGood_dz")[tightLeps[0]], w)
        self.fill1DByFlavour("sip3dLep", pdgLep, eh.get("LepGood_sip3d")[tightLeps[0]], w)
        jetDRLep = deltaR(
            eh.get("Jet_phi")[goodJs[0]],
            eh.get("Jet_eta")[goodJs[0]],
            eh.get("LepGood_phi")[tightLeps[0]],
            eh.get("LepGood_eta")[tightLeps[0]],
        )
        self.fill1DByFlavour("jet1DRLep", pdgLep, jetDRLep, w)
        jetDRLep = deltaR(
            eh.get("Jet_phi")[goodJs[1]],
            eh.get("Jet_eta")[goodJs[1]],
            eh.get("LepGood_phi")[tightLeps[0]],
            eh.get("LepGood_eta")[tightLeps[0]],
        )
        self.fill1DByFlavour("jet2DRLep", pdgLep, jetDRLep, w)
        self.fill1DByFlavour("met", pdgLep, eh.get("met_pt"), w)
        self.fill1DByFlavour("metPhi", pdgLep, metPhi, w)
        jetPhi = eh.get("Jet_phi")[goodJs[0]]
        self.fill1DByFlavour("dPhiMetJet1", pdgLep, abs(deltaPhi(metPhi, jetPhi)), w)
        jetPhi = eh.get("Jet_phi")[goodJs[1]]
        self.fill1DByFlavour("dPhiMetJet2", pdgLep, abs(deltaPhi(metPhi, jetPhi)), w)
        #        assert eh.get("nBJetMedium30")==self.selection.nBJets
        #        if eh.get("nBJetMedium30")>0:
        #            return
        #        assert self.selection.preselection()
        #
        # W+jets region:
        #
        wRs = self.selection.wRegions()
        for r in wRs:
            assert r[0] == "C" or r[0] == "S"
            if r[0] == "C":
                self.fill1DByFlavour("wCSRs", pdgLep, -int(r[2:]), w)
            else:
                self.fill1DByFlavour("wCSRs", pdgLep, int(r[2:]), w)
        #
        # ttbar region:
        #
        for ib in [0, 1, 2]:
            ttRs = self.selection.ttRegions(ib)
            for r in ttRs:
                assert r[0] == "C" or r[0] == "S"
                hn = "tt" + str(ib) + "bCSRs"
                if r[0] == "C":
                    self.fill1DByFlavour(hn, pdgLep, -int(r[2:]), w)
                else:
                    self.fill1DByFlavour(hn, pdgLep, int(r[2:]), w)

        region = self.selection.region()
        #        if region==None:
        #            self.fill1DByFlavour("CSRs",pdgLep,0.,w)
        #            print "*Rejected: ",eh.get("nBJetMedium30"),self.selection.preselection(),self.selection.__dict__
        if region != None:
            assert region[0] == "C" or region[0] == "S"
            ir = int(region[2:])
            if region[0] == "C":
                self.fill1DByFlavour("CSRs", pdgLep, -ir, w)
            else:
                self.fill1DByFlavour("CSRs", pdgLep, ir, w)
            self.fill1DByFlavour("dPhiR" + "{0:02d}".format(ir), pdgLep, abs(dphi), w)
            self.passedCutByFlavour(region, pdgLep, w, nameFlow="CSRflow")

        self.fill1DByFlavour("after", pdgLep, 1, w)