def buildDiLeptonsSingle(self, leptons, event):
        '''
        '''
        di_objects = []

        if hasattr(event, 'calibratedTaus'):
            taus = event.calibratedTaus
        else:
            taus = self.handles['taus'].product()

        met = event.pfmet

        taus = [Tau(tau) for tau in taus]

        if getattr(self.cfg_ana, 'scaleTaus', False):
            for tau in taus:
                HTTGenAnalyzer.genMatch(event, tau, event.ptSelGentauleps,
                                        event.ptSelGenleps,
                                        event.ptSelGenSummary)
                HTTGenAnalyzer.attachGenStatusFlag(tau)
                self.scaleP4(tau, self.cfg_ana.tes_scale)

        for leg1 in taus:
            for leg2 in taus:
                if leg1 != leg2:
                    di_tau = DirectTauTau(leg1, leg2, met)
                    di_tau.leg2().associatedVertex = event.goodVertices[0]
                    di_tau.leg1().associatedVertex = event.goodVertices[0]
                    di_tau.leg1().event = event.input.object()
                    di_tau.leg2().event = event.input.object()
                    di_tau.mvaMetSig = None
                    di_objects.append(di_tau)
        return di_objects
Esempio n. 2
0
    def process(self, event):
        # needed when doing handle.product(), goes back to
        # PhysicsTools.Heppy.analyzers.core.Analyzer
        self.readCollections(event.input)

        if not eval(self.skimFunction):
            return False

        event.genJets = self.mchandles['genJets'].product()

        ptcut = 8.
        ptSelGentauleps = [lep for lep in event.gentauleps if lep.pt() > ptcut]
        ptSelGenleps = [lep for lep in event.genleps if lep.pt() > ptcut]
        ptSelGenSummary = [
            p for p in event.generatorSummary if p.pt() > ptcut
            and abs(p.pdgId()) not in [6, 23, 24, 25, 35, 36, 37]
        ]

        for tau in event.selectedTaus:
            HTTGenAnalyzer.genMatch(event, tau, ptSelGentauleps, ptSelGenleps,
                                    ptSelGenSummary)

        for i_tau, tau in enumerate(event.selectedTaus):

            if i_tau < self.maxNTaus:
                self.tree.reset()
                self.fillJetMETVars(event)
                self.fillTau(self.tree, 'tau', tau)
                self.fill(self.tree, 'tau_puppi_iso_pt', tau.puppi_iso_pt)
                self.fill(self.tree, 'tau_puppi_iso04_pt', tau.puppi_iso04_pt)
                self.fill(self.tree, 'tau_puppi_iso03_pt', tau.puppi_iso03_pt)
                self.fill(self.tree, 'tau_trigger_iso', tau.trigger_iso)
                if tau.genp:
                    self.fillGenParticle(self.tree, 'tau_gen', tau.genp)
                    if tau.genJet():
                        self.fillGenParticle(self.tree, 'tau_gen_vis',
                                             tau.genJet())
                        self.fill(self.tree, 'tau_gen_decayMode',
                                  tauDecayModes.genDecayModeInt(tau.genJet()))
                if not tau.leadNeutralCand().isNull():
                    self.fillParticle(self.tree, 'tau_lead_neutral',
                                      tau.leadNeutralCand())
                if not tau.leadChargedHadrCand().isNull():
                    self.fillParticle(self.tree, 'tau_lead_charged',
                                      tau.leadChargedHadrCand())
                self.fill(self.tree, 'tau_charged_iso', tau.chargedPtSumIso)
                self.fill(self.tree, 'tau_gamma_iso', tau.gammaPtSumIso)
                self.fill(self.tree, 'tau_neutral_iso', tau.neutralPtSumIso)
                self.fill(self.tree, 'tau_charged_sig',
                          tau.chargedCandsPtSumSignal)
                self.fill(self.tree, 'tau_gamma_sig',
                          tau.gammaCandsPtSumSignal)
                self.fill(self.tree, 'tau_neutral_sign',
                          tau.neutralCandsPtSumSignal)

                self.fillTree(event)
 def Scale(self, tau, ptSelGentauleps, ptSelGenleps, event):
     # this function should take values of scales from a file
     tau.unscaledP4 = copy.deepcopy(tau.p4())
     HTTGenAnalyzer.genMatch(event, tau, ptSelGentauleps, ptSelGenleps, [])
     HTTGenAnalyzer.attachGenStatusFlag(tau)
     if tau.gen_match == 5:
         if tau.decayMode() == 0:
             tau.scaleEnergy(0.995)
         elif tau.decayMode() == 1:
             tau.scaleEnergy(1.011)
         elif tau.decayMode() == 10:
             tau.scaleEnergy(1.006)
     elif tau.gen_match == 1:
         if tau.decayMode() == 0:
             tau.scaleEnergy(1.024)
         elif tau.decayMode() == 1:
             tau.scaleEnergy(1.076)
Esempio n. 4
0
    def buildDiLeptons(self, cmgDiLeptons, event):
        '''Build di-leptons, associate best vertex to both legs.'''
        diLeptons = []
        for index, dil in enumerate(cmgDiLeptons):
            pydil = TauTau(dil, iso=self.cfg_ana.isolation)
            pydil.leg1().associatedVertex = event.goodVertices[0]
            pydil.leg2().associatedVertex = event.goodVertices[0]
            pydil.leg1().event = event.input.object()
            pydil.leg2().event = event.input.object()
            diLeptons.append(pydil)
            pydil.mvaMetSig = pydil.met().getSignificanceMatrix()
            if getattr(self.cfg_ana, 'scaleTaus', False):
                for leg in [pydil.leg1(), pydil.leg2()]:
                    HTTGenAnalyzer.genMatch(event, leg, event.ptSelGentauleps,
                                            event.ptSelGenleps,
                                            event.ptSelGenSummary)
                    HTTGenAnalyzer.attachGenStatusFlag(leg)
                    self.scaleP4(leg, self.cfg_ana.tes_scale)

        return diLeptons
Esempio n. 5
0
    def process(self, event):

        self.l1 = event.diLepton.leg1()
        self.l2 = event.diLepton.leg2()

        HTTGenAnalyzer.genMatch(event, self.l1, event.ptSelGentauleps, event.ptSelGenleps, event.ptSelGenSummary)
        HTTGenAnalyzer.genMatch(event, self.l2, event.ptSelGentauleps, event.ptSelGenleps, event.ptSelGenSummary)

        HTTGenAnalyzer.attachGenStatusFlag(self.l1)
        HTTGenAnalyzer.attachGenStatusFlag(self.l2)

        if hasattr(event, 'selectedTaus'):
            for tau in event.selectedTaus:
                HTTGenAnalyzer.genMatch(event, tau, event.ptSelGentauleps, event.ptSelGenleps, event.ptSelGenSummary)
Esempio n. 6
0
 def addInfo(tau, event, cands=None, maxDeltaR=None):
     HTTGenAnalyzer.genMatch(event, tau, event.gentauleps, event.genleps, [], dR=0.2, matchAll=True)
     HTTGenAnalyzer.attachGenStatusFlag(tau)
     TauIsoAnalyzer.tauIsoBreakdown(tau, cands, maxDeltaR=maxDeltaR)
     tau.nphotons = sum(1 for cand in TauIsoAnalyzer.tauFilteredPhotons(tau))
Esempio n. 7
0
    def process(self, event):
        # needed when doing handle.product(), goes back to
        # PhysicsTools.Heppy.analyzers.core.Analyzer
        self.readCollections(event.input)

        if not eval(self.skimFunction):
            return False

        ptSelGentauleps = []
        ptSelGenleps = []
        ptSelGenSummary = []

        if self.cfg_comp.isMC:
            event.genJets = self.mchandles['genJets'].product()

            ptcut = 8.
            ptSelGentauleps = [
                lep for lep in event.gentauleps if lep.pt() > ptcut
            ]
            ptSelGenleps = [lep for lep in event.genleps if lep.pt() > ptcut]
            ptSelGenSummary = [
                p for p in event.generatorSummary if p.pt() > ptcut
                and abs(p.pdgId()) not in [6, 23, 24, 25, 35, 36, 37]
            ]

        for i_dil, dil in enumerate(event.selDiLeptons):

            muon = dil.leg1()
            jet = dil.leg2()
            found = False
            for corr_jet in event.jets:
                if deltaR2(jet.eta(), jet.phi(), corr_jet.eta(),
                           corr_jet.phi()) < 0.01:
                    pt = max(
                        corr_jet.pt(),
                        corr_jet.pt() * corr_jet.corrJECUp / corr_jet.corr,
                        corr_jet.pt() * corr_jet.corrJECDown / corr_jet.corr)
                    if pt < 20.:
                        continue
                    found = True

            if not found:
                continue

            tau = jet.tau if hasattr(jet, 'tau') else None
            if self.cfg_comp.isMC:
                if tau:
                    HTTGenAnalyzer.genMatch(event, tau, ptSelGentauleps,
                                            ptSelGenleps, ptSelGenSummary)
                    HTTGenAnalyzer.attachGenStatusFlag(tau)
                HTTGenAnalyzer.genMatch(event, muon, ptSelGentauleps,
                                        ptSelGenleps, ptSelGenSummary)
                HTTGenAnalyzer.attachGenStatusFlag(muon)

            self.tree.reset()
            self.fillEvent(self.tree, event)
            self.fillDiLepton(self.tree, event.diLepton, fill_svfit=False)
            self.fillExtraMetInfo(self.tree, event)
            self.fillGenInfo(self.tree, event)

            self.fillJetMETVars(event)
            self.fillMuon(self.tree, 'muon', muon)
            jet = Jet(jet)
            jet.btagMVA = jet.btag(
                'pfCombinedInclusiveSecondaryVertexV2BJetTags')
            jet.btagFlag = jet.btagMVA > 0.8
            self.fillJet(self.tree, 'oriJet', jet)
            self.fill(self.tree, 'jet_nth', i_dil)

            for corr_jet in event.jets:
                if deltaR2(jet.eta(), jet.phi(), corr_jet.eta(),
                           corr_jet.phi()) < 0.01:
                    self.fillJet(self.tree, 'jet', corr_jet)
                    self.fill(self.tree, 'jet_nooverlap',
                              True if corr_jet in event.cleanJets else False)
                    self.fill(self.tree, 'jet_corrJECUp',
                              corr_jet.corrJECUp / corr_jet.corr)
                    self.fill(self.tree, 'jet_corrJECDown',
                              corr_jet.corrJECDown / corr_jet.corr)
                    self.fill(self.tree, 'jet_corr', corr_jet.corr)

            if tau:
                self.fillTau(self.tree, 'tau', tau)

                if hasattr(tau, 'genp') and tau.genp:
                    self.fillGenParticle(self.tree, 'tau_gen', tau.genp)
                    if tau.genJet():
                        self.fillGenParticle(self.tree, 'tau_gen_vis',
                                             tau.genJet())
                        self.fill(self.tree, 'tau_gen_decayMode',
                                  tauDecayModes.genDecayModeInt(tau.genJet()))

            self.fillTree(event)