Ejemplo n.º 1
0
    def makeMETs(self, event):
        import ROOT
        if self.cfg_ana.copyMETsByValue:
          self.met = ROOT.pat.MET(self.handles['met'].product()[0])
          if self.cfg_ana.doMetNoPU: self.metNoPU = ROOT.pat.MET(self.handles['nopumet'].product()[0])
        else:
          self.met = self.handles['met'].product()[0]
          if self.cfg_ana.doMetNoPU: self.metNoPU = self.handles['nopumet'].product()[0]

        if self.recalibrateMET == "type1":
          type1METCorr = getattr(event, 'type1METCorr'+self.jetAnalyzerPostFix)
          self.type1METCorrector.correct(self.met, type1METCorr)
        elif self.recalibrateMET == True:
          deltaMetJEC = getattr(event, 'deltaMetFromJEC'+self.jetAnalyzerPostFix)
          self.applyDeltaMet(self.met, deltaMetJEC)
        if self.applyJetSmearing:
          deltaMetSmear = getattr(event, 'deltaMetFromJetSmearing'+self.jetAnalyzerPostFix)
          self.applyDeltaMet(self.met, deltaMetSmear)


        if (not self.cfg_ana.copyMETsByValue) and getattr(self.cfg_ana, 'makeShiftedMETs', True):
          shifts = [] 
          for obj in 'JetEn', 'JetRes', 'MuonEn', 'ElectronEn', 'PhotonEn', 'TauEn', 'UnclusteredEn':
            for sh in 'Up', 'Down':
                shifts.append( (obj+sh, getattr(self.met,obj+sh)) )
          shifts.append( ('NoShift', self.met.NoShift) )
          for name,i in shifts:
               key = i
               m = ROOT.pat.MET(self.met)
               if self.old74XMiniAODs:
                    if key > 12:   key = 12
                    elif key <= 3: key = { 'JetEnUp':0, 'JetEnDown':1, 'JetResUp':2, 'JetResDown':3 }[name]
               m.setP4(self.met.shiftedP4(key))
               setattr(event, "met{0}_shifted_{1}".format(self.cfg_ana.collectionPostFix, i),m)
               setattr(event, "met{0}_shifted_{1}".format(self.cfg_ana.collectionPostFix, name),m)

        self.met_sig = self.met.significance()
        self.met_sumet = self.met.sumEt()

        if self.old74XMiniAODs and self.recalibrateMET != "type1":
           oldraw = self.met.shiftedP2_74x(12,0);
           setFakeRawMETOnOldMiniAODs( self.met, oldraw.px, oldraw.py, self.met.shiftedSumEt_74x(12,0) )
           px, py = oldraw.px, oldraw.py
        else:
           px, py = self.met.uncorPx(), self.met.uncorPy()
        self.met_raw = ROOT.reco.Particle.LorentzVector(px,py,0,hypot(px,py))

        if hasattr(event,'zll_p4'):
            self.adduParaPerp(self.met,event.zll_p4,"_zll")
            self.adduParaPerp(self.met_raw, event.zll_p4,"_zll")
            setattr(event,"met_raw"+self.cfg_ana.collectionPostFix, self.met_raw)
            setattr(event,"met_raw.upara_zll"+self.cfg_ana.collectionPostFix, self.met_raw.upara_zll)
            setattr(event,"met_raw.uperp_zll"+self.cfg_ana.collectionPostFix, self.met_raw.uperp_zll)

        if hasattr(event,"met"+self.cfg_ana.collectionPostFix): raise RuntimeError, "Event already contains met with the following postfix: "+self.cfg_ana.collectionPostFix
        setattr(event, "met"+self.cfg_ana.collectionPostFix, self.met)
        if self.cfg_ana.doMetNoPU: setattr(event, "metNoPU"+self.cfg_ana.collectionPostFix, self.metNoPU)
        setattr(event, "met_sig"+self.cfg_ana.collectionPostFix, self.met_sig)
        setattr(event, "met_sumet"+self.cfg_ana.collectionPostFix, self.met_sumet)

        genMET = self.met.genMET()
        if genMET:
          setattr(event, "met_genPt"+self.cfg_ana.collectionPostFix, genMET.pt())
          setattr(event, "met_genPhi"+self.cfg_ana.collectionPostFix, genMET.phi())
        else:
          setattr(event, "met_genPt"+self.cfg_ana.collectionPostFix, float('nan'))
          setattr(event, "met_genPhi"+self.cfg_ana.collectionPostFix, float('nan'))

        if self.cfg_ana.doMetNoMu and hasattr(event, 'selectedMuons'):
            self.makeMETNoMu(event)

        if self.cfg_ana.doMetNoEle and hasattr(event, 'selectedElectrons'):
            self.makeMETNoEle(event)

        if self.cfg_ana.doMetNoPhoton and hasattr(event, 'selectedPhotons'):
            self.makeMETNoPhoton(event)
Ejemplo n.º 2
0
    def makeMETs(self, event):
        import ROOT
        if self.cfg_ana.copyMETsByValue:
            self.met = ROOT.pat.MET(self.handles['met'].product()[0])
            self.metUncor = copy.deepcopy(self.met)
            if self.cfg_ana.doMetNoPU:
                self.metNoPU = ROOT.pat.MET(
                    self.handles['nopumet'].product()[0])
        else:
            self.met = self.handles['met'].product()[0]
            self.metUncor = copy.deepcopy(self.met)
            if self.cfg_ana.doMetNoPU:
                self.metNoPU = self.handles['nopumet'].product()[0]

        if self.recalibrateMET == "type1":
            type1METCorr = getattr(event,
                                   'type1METCorr' + self.jetAnalyzerPostFix)
            self.type1METCorrector.correct(self.met, type1METCorr)
        elif self.recalibrateMET == True:
            deltaMetJEC = getattr(event,
                                  'deltaMetFromJEC' + self.jetAnalyzerPostFix)
            self.applyDeltaMet(self.met, deltaMetJEC)
        if self.applyJetSmearing:
            deltaMetSmear = getattr(
                event, 'deltaMetFromJetSmearing' + self.jetAnalyzerPostFix)
            self.applyDeltaMet(self.met, deltaMetSmear)

        if (not self.cfg_ana.copyMETsByValue) and getattr(
                self.cfg_ana, 'makeShiftedMETs', True):
            shifts = []
            for obj in 'JetEn', 'JetRes', 'MuonEn', 'ElectronEn', 'PhotonEn', 'TauEn', 'UnclusteredEn':
                for sh in 'Up', 'Down':
                    shifts.append((obj + sh, getattr(self.met, obj + sh)))
            shifts.append(('NoShift', self.met.NoShift))
            for name, i in shifts:
                key = i
                m = ROOT.pat.MET(self.met)
                if self.old74XMiniAODs:
                    if key > 12: key = 12
                    elif key <= 3:
                        key = {
                            'JetEnUp': 0,
                            'JetEnDown': 1,
                            'JetResUp': 2,
                            'JetResDown': 3
                        }[name]
                m.setP4(self.met.shiftedP4(key))
                setattr(
                    event,
                    "met{0}_shifted_{1}".format(self.cfg_ana.collectionPostFix,
                                                i), m)
                setattr(
                    event,
                    "met{0}_shifted_{1}".format(self.cfg_ana.collectionPostFix,
                                                name), m)

        self.met_sig = self.met.metSignificance()
        self.met_sumet = self.met.sumEt()

        if self.cfg_ana.storePuppiExtra:
            self.met.EGCorX = self.handles['corX'].product()[0]
            self.met.EGCorY = self.handles['corY'].product()[0]
            setattr(event, "met_EGCorX" + self.cfg_ana.collectionPostFix,
                    self.met.EGCorX)
            setattr(event, "met_EGCorY" + self.cfg_ana.collectionPostFix,
                    self.met.EGCorY)

        if self.old74XMiniAODs and self.recalibrateMET != "type1":
            oldraw = self.met.shiftedP2_74x(12, 0)
            setFakeRawMETOnOldMiniAODs(self.met, oldraw.px, oldraw.py,
                                       self.met.shiftedSumEt_74x(12, 0))
            px, py = oldraw.px, oldraw.py
        else:
            px, py = self.met.uncorPx(), self.met.uncorPy()
        self.met_raw = ROOT.reco.Particle.LorentzVector(
            px, py, 0, hypot(px, py))

        if hasattr(event, 'zll_p4'):
            self.adduParaPerp(self.met, event.zll_p4, "_zll")
            self.adduParaPerp(self.met_raw, event.zll_p4, "_zll")
            setattr(event, "met_raw" + self.cfg_ana.collectionPostFix,
                    self.met_raw)
            setattr(event,
                    "met_raw.upara_zll" + self.cfg_ana.collectionPostFix,
                    self.met_raw.upara_zll)
            setattr(event,
                    "met_raw.uperp_zll" + self.cfg_ana.collectionPostFix,
                    self.met_raw.uperp_zll)

        if hasattr(event, 'gamma_p4'):
            self.adduParaPerp(self.met, event.gamma_p4, "_gamma")
            self.adduParaPerp(self.met_raw, event.gamma_p4, "_gamma")
            setattr(event, "met_raw" + self.cfg_ana.collectionPostFix,
                    self.met_raw)
            setattr(event,
                    "met_raw.upara_gamma" + self.cfg_ana.collectionPostFix,
                    self.met_raw.upara_gamma)
            setattr(event,
                    "met_raw.uperp_gamma" + self.cfg_ana.collectionPostFix,
                    self.met_raw.uperp_gamma)

        if hasattr(event, "met" + self.cfg_ana.collectionPostFix):
            raise RuntimeError, "Event already contains met with the following postfix: " + self.cfg_ana.collectionPostFix
        setattr(event, "met" + self.cfg_ana.collectionPostFix, self.met)
        setattr(event, "metUncor" + self.cfg_ana.collectionPostFix,
                self.metUncor)
        if self.cfg_ana.doMetNoPU:
            setattr(event, "metNoPU" + self.cfg_ana.collectionPostFix,
                    self.metNoPU)
        setattr(event, "met_sig" + self.cfg_ana.collectionPostFix,
                self.met_sig)
        setattr(event, "met_sumet" + self.cfg_ana.collectionPostFix,
                self.met_sumet)

        genMET = self.met.genMET()
        if genMET:
            setattr(event, "met_genPt" + self.cfg_ana.collectionPostFix,
                    genMET.pt())
            setattr(event, "met_genPhi" + self.cfg_ana.collectionPostFix,
                    genMET.phi())
        else:
            setattr(event, "met_genPt" + self.cfg_ana.collectionPostFix,
                    float('nan'))
            setattr(event, "met_genPhi" + self.cfg_ana.collectionPostFix,
                    float('nan'))

        if self.cfg_ana.doMetNoMu and hasattr(event, 'selectedMuons'):
            self.makeMETNoMu(event)

        if self.cfg_ana.doMetNoEle and hasattr(event, 'selectedElectrons'):
            self.makeMETNoEle(event)

        if self.cfg_ana.doMetNoPhoton and hasattr(event, 'selectedPhotons'):
            self.makeMETNoPhoton(event)
Ejemplo n.º 3
0
    def makeMETs(self, event):
        import ROOT
        if self.cfg_ana.copyMETsByValue:
            self.met = ROOT.pat.MET(self.handles['met'].product()[0])
            if self.cfg_ana.doMetNoPU:
                self.metNoPU = ROOT.pat.MET(
                    self.handles['nopumet'].product()[0])
        else:
            self.met = self.handles['met'].product()[0]
            if self.cfg_ana.doMetNoPU:
                self.metNoPU = self.handles['nopumet'].product()[0]

        if self.recalibrateMET == "type1":
            type1METCorr = getattr(event,
                                   'type1METCorr' + self.jetAnalyzerPostFix)
            self.type1METCorrector.correct(self.met, type1METCorr)
        elif self.recalibrateMET == True:
            deltaMetJEC = getattr(event,
                                  'deltaMetFromJEC' + self.jetAnalyzerPostFix)
            self.applyDeltaMet(self.met, deltaMetJEC)
        if self.applyJetSmearing:
            deltaMetSmear = getattr(
                event, 'deltaMetFromJetSmearing' + self.jetAnalyzerPostFix)
            self.applyDeltaMet(self.met, deltaMetSmear)

        #Shifted METs: to be re-enabled after updates to MiniAOD pass 2
        #Uncertainties defined in https://github.com/cms-sw/cmssw/blob/CMSSW_7_2_X/DataFormats/PatCandidates/interface/MET.h#L168
        #event.met_shifted = []
        #if not self.cfg_ana.copyMETsByValue:
        #  for i in range(self.met.METUncertaintySize):
        #      m = ROOT.pat.MET(self.met)
        #      px  = m.shiftedPx(i);
        #      py  = m.shiftedPy(i);
        #      m.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
        #      #event.met_shifted += [m]
        #      setattr(event, "met{0}_shifted_{1}".format(self.cfg_ana.collectionPostFix, i), m)

        self.met_sig = self.met.significance()
        self.met_sumet = self.met.sumEt()

        if self.old74XMiniAODs and self.recalibrateMET != "type1":
            oldraw = self.met.shiftedP2_74x(12, 0)
            setFakeRawMETOnOldMiniAODs(self.met, oldraw.px, oldraw.py,
                                       self.met.shiftedSumEt_74x(12, 0))
            px, py = oldraw.px, oldraw.py
        else:
            px, py = self.met.uncorPx(), self.met.uncorPy()
        self.met_raw = ROOT.reco.Particle.LorentzVector(
            px, py, 0, hypot(px, py))

        if hasattr(event, 'zll_p4'):
            self.adduParaPerp(self.met, event.zll_p4, "_zll")
            self.adduParaPerp(self.met_raw, event.zll_p4, "_zll")
            setattr(event, "met_raw" + self.cfg_ana.collectionPostFix,
                    self.met_raw)
            setattr(event,
                    "met_raw.upara_zll" + self.cfg_ana.collectionPostFix,
                    self.met_raw.upara_zll)
            setattr(event,
                    "met_raw.uperp_zll" + self.cfg_ana.collectionPostFix,
                    self.met_raw.uperp_zll)

        if hasattr(event, "met" + self.cfg_ana.collectionPostFix):
            raise RuntimeError, "Event already contains met with the following postfix: " + self.cfg_ana.collectionPostFix
        setattr(event, "met" + self.cfg_ana.collectionPostFix, self.met)
        if self.cfg_ana.doMetNoPU:
            setattr(event, "metNoPU" + self.cfg_ana.collectionPostFix,
                    self.metNoPU)
        setattr(event, "met_sig" + self.cfg_ana.collectionPostFix,
                self.met_sig)
        setattr(event, "met_sumet" + self.cfg_ana.collectionPostFix,
                self.met_sumet)

        genMET = self.met.genMET()
        if genMET:
            setattr(event, "met_genPt" + self.cfg_ana.collectionPostFix,
                    genMET.pt())
            setattr(event, "met_genPhi" + self.cfg_ana.collectionPostFix,
                    genMET.phi())
        else:
            setattr(event, "met_genPt" + self.cfg_ana.collectionPostFix,
                    float('nan'))
            setattr(event, "met_genPhi" + self.cfg_ana.collectionPostFix,
                    float('nan'))

        if self.cfg_ana.doMetNoMu and hasattr(event, 'selectedMuons'):
            self.makeMETNoMu(event)

        if self.cfg_ana.doMetNoEle and hasattr(event, 'selectedElectrons'):
            self.makeMETNoEle(event)

        if self.cfg_ana.doMetNoPhoton and hasattr(event, 'selectedPhotons'):
            self.makeMETNoPhoton(event)