def fillTau(self, tau, tau_name):
        self.fillParticle(self.tree, tau_name, tau)
        if tau.genp:
            self.fillGenParticle(self.tree, tau_name + '_gen', tau.genp)
            if abs(tau.genp.pdgId()) == 15:
                self.fill(self.tree, 'tau_gen_decayMode',
                          tauDecayModes.genDecayModeInt(tau.genp.daughters))

                print 'From final daughters', tauDecayModes.genDecayModeInt(
                    tau.genp.daughters)

        for var in [
                'ptSumIso', 'chargedPtSumIso', 'chargedPUPtSumIso',
                'gammaPtSumIso', 'neutralPtSumIso', 'ptSumSignal',
                'chargedCandsPtSumSignal', 'gammaCandsPtSumSignal',
                'neutralCandsPtSumSignal', 'dm', 'loose_db_iso', 'nphotons'
        ]:
            try:
                self.fill(self.tree, '_'.join([tau_name, var]),
                          getattr(tau, var))
            except TypeError:
                import pdb
                pdb.set_trace()
        for var in ['decayMode']:
            try:
                self.fill(self.tree, '_'.join([tau_name, var]),
                          getattr(tau, var)())
            except TypeError:
                import pdb
                pdb.set_trace()
    def getGenTauJets(event):
        event.genTauJets = []
        event.genTauJetConstituents = []
        for gentau in event.gentaus:
            gentau = GenAnalyzer.getFinalTau(gentau)

            c_genjet = TauGenTreeProducer.finalDaughters(gentau)
            c_genjet = [
                d for d in c_genjet if abs(d.pdgId()) not in [12, 14, 16]
            ]
            p4_genjet = sum(
                (d.p4()
                 for d in c_genjet if abs(d.pdgId()) not in [12, 14, 16]),
                ROOT.math.XYZTLorentzVectorD())

            genjet = GenParticle(gentau)
            genjet.setP4(p4_genjet)
            genjet.daughters = c_genjet
            genjet.decayMode = tauDecayModes.genDecayModeInt(c_genjet)

            if p4_genjet.pt() > 15.:
                if any(
                        deltaR(p4_genjet, stored_genjet) < 0.002
                        for stored_genjet in event.genTauJets):
                    continue  # Remove duplicates
                event.genTauJets.append(genjet)
                event.genTauJetConstituents.append(c_genjet)
Exemple #3
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

        self.tree.reset()
        self.fill(self.tree, 'n_gen_taus', len(event.gentaus))

        for i_tau, gen_tau in enumerate(event.gentaus):
            if i_tau >= 2:
                print 'More than two generated hadronic taus!'
                continue

            self.fillGenParticle(self.tree, 'tau{i}_gen'.format(i=i_tau + 1),
                                 gen_tau)
            self.fillParticle(self.tree, 'tau{i}_gen_vis'.format(i=i_tau + 1),
                              self.visibleP4(gen_tau))
            self.fill(
                self.tree, 'tau{i}_gen_decayMode'.format(i=i_tau + 1),
                tauDecayModes.genDecayModeInt([
                    d for d in TauGenTreeProducer.finalDaughters(gen_tau)
                    if abs(d.pdgId()) not in [12, 14, 16]
                ]))

            for tau in event.selectedTaus:
                if tau.mcTau == gen_tau:
                    # import pdb; pdb.set_trace()
                    self.fillTau(self.tree, 'tau{i}'.format(i=i_tau + 1), tau)
                    # if tau.genJet():
                    # self.fillGenParticle(self.tree, 'tau{i}_gen_vis'.format(i=i_tau), tau.genJet())

        self.fillTree(event)
Exemple #4
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

        self.tree.reset()

        n_gen_tau = 0
        for gen_tau in event.gentaus:
            # FIXME - temporary, let's see for a longer-term solution...
            if abs(gen_tau.mother().pdgId()) in [23, 24]:
                continue

            if n_gen_tau >= 2:
                print 'More than two generated hadronic taus!'
                continue

            self.fillGenParticle(self.tree,
                                 'tau{i}_gen'.format(i=n_gen_tau + 1), gen_tau)
            self.fillParticle(self.tree,
                              'tau{i}_gen_vis'.format(i=n_gen_tau + 1),
                              self.visibleP4(gen_tau))
            self.fill(
                self.tree, 'tau{i}_gen_decayMode'.format(i=n_gen_tau + 1),
                tauDecayModes.genDecayModeInt([
                    d for d in TauGenTreeProducer.finalDaughters(gen_tau)
                    if abs(d.pdgId()) not in [12, 14, 16]
                ]))

            for tau in event.selectedTaus:
                if tau.genp == gen_tau:
                    # import pdb; pdb.set_trace()
                    self.fillTau(self.tree, 'tau{i}'.format(i=n_gen_tau + 1),
                                 tau)
                    # if tau.genJet():
                    # self.fillGenParticle(self.tree, 'tau{i}_gen_vis'.format(i=n_gen_tau), tau.genJet())

            n_gen_tau += 1

        self.fill(self.tree, 'n_gen_taus', n_gen_tau)

        n_gen_taulep = 0
        for gen_tau_lep in event.gentauleps:
            tau = gen_tau_lep.mother()
            if abs(tau.pdgId()) != 15:
                continue
            if abs(tau.mother().pdgId()) == 15:
                tau = tau.mother()
            if abs(tau.mother().pdgId()) in [23, 24]:
                continue

            n_gen_taulep += 1

        self.fill(self.tree, 'n_gen_tauleps', n_gen_taulep)

        self.fillTree(event)
    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 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

        self.tree.reset()
        

        n_gen_tau = 0
        for gen_tau in event.gentaus:
            # FIXME - temporary, let's see for a longer-term solution...
            if abs(gen_tau.mother().pdgId()) in [23, 24]:
                continue

            if n_gen_tau >= 2:
                print 'More than two generated hadronic taus!'
                continue

            self.fillGenParticle(self.tree, 'tau{i}_gen'.format(i=n_gen_tau+1), gen_tau)
            self.fillParticle(self.tree, 'tau{i}_gen_vis'.format(i=n_gen_tau+1), self.visibleP4(gen_tau))
            self.fill(self.tree, 'tau{i}_gen_decayMode'.format(i=n_gen_tau+1), tauDecayModes.genDecayModeInt([d for d in TauGenTreeProducer.finalDaughters(gen_tau) if abs(d.pdgId()) not in [12, 14, 16]]))

            for tau in event.selectedTaus:
                if tau.genp == gen_tau:
                    # import pdb; pdb.set_trace()
                    self.fillTau(self.tree, 'tau{i}'.format(i=n_gen_tau+1), tau)
                    # if tau.genJet():
                        # self.fillGenParticle(self.tree, 'tau{i}_gen_vis'.format(i=n_gen_tau), tau.genJet())

            n_gen_tau += 1

        self.fill(self.tree, 'n_gen_taus', n_gen_tau)
                            
        n_gen_taulep = 0
        for gen_tau_lep in event.gentauleps:
            tau = gen_tau_lep.mother()
            if abs(tau.pdgId()) != 15:
                continue
            if abs(tau.mother().pdgId()) == 15:
                tau = tau.mother()
            if abs(tau.mother().pdgId()) in [23, 24]:
                continue
            
            n_gen_taulep += 1

        
        self.fill(self.tree, 'n_gen_tauleps', n_gen_taulep)

        self.fillTree(event)
Exemple #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

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

            if i_tau < self.maxNTaus:
                self.tree.reset()
                self.fillTau(self.tree, 'tau', tau)
                if tau.mcTau:
                    self.fillGenParticle(self.tree, 'tau_gen', tau.mcTau)
                    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)
    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.0
        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:
            DYJetsFakeAnalyzer.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)
                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()))

                self.fillTree(event)
Exemple #9
0
    genParticles = genParticlesH.product()
    jets = [jet for jet in jetH.product() if jet.pt() > 20 and abs(jet.eta()) < 2.3]

    genTaus = [p for p in genParticles if abs(p.pdgId()) == 15 and p.status()==2]
    genElectrons = [p for p in genParticles if abs(p.pdgId()) == 11 and p.status()==1 and p.pt() > 20 and abs(p.eta())<2.3]
    genMuons = [p for p in genParticles if abs(p.pdgId()) == 13 and p.status()==1 and p.pt() > 20 and abs(p.eta())<2.3]

    for tau in taus:

        _genparticle_ = []

        for igen in genTaus:
                        
            visP4 = visibleP4(igen)

            gen_dm = tauDecayModes.genDecayModeInt([d for d in finalDaughters(igen) if abs(d.pdgId()) not in [12, 14, 16]])

            igen.decaymode = gen_dm
            igen.vis = visP4
            
            if abs(visP4.eta()) > 2.3: continue
            if visP4.pt() < 20: continue

            dr = deltaR(tau.eta(), tau.phi(), visP4.eta(), visP4.phi())

            if dr < 0.5:
                _genparticle_.append(igen)



        if runtype=='ZTT':
    ]
    genMuons = [
        p for p in genParticles if abs(p.pdgId()) == 13 and p.status() == 1
        and p.pt() > 20 and abs(p.eta()) < 2.3
    ]

    for tau in taus:

        _genparticle_ = []

        for igen in genTaus:

            visP4 = visibleP4(igen)

            gen_dm = tauDecayModes.genDecayModeInt([
                d for d in finalDaughters(igen)
                if abs(d.pdgId()) not in [12, 14, 16]
            ])

            igen.decaymode = gen_dm
            igen.vis = visP4

            if abs(visP4.eta()) > 2.3: continue
            if visP4.pt() < 20: continue

            dr = deltaR(tau.eta(), tau.phi(), visP4.eta(), visP4.phi())

            if dr < 0.5:
                _genparticle_.append(igen)

        if runtype == 'ZTT':
            h_ngen.Fill(len(genTaus))
Exemple #11
0
    # select only hadronically decaying taus
    gen_taus = [pp for pp in gen_particles if abs(pp.pdgId())==15 and \
                pp.status()==8 and isGenHadTau(pp) and\
                pp.pt()>10 and abs(pp.eta()) < 2.1]

    if len(gen_taus) == 0:  continue

    # determine gen decaymode and find mother
    for gg in gen_taus:

        ## reset other attributes
        for ifeat in feat_list:
            setattr(gg, ifeat, -9999.)

        gg.decayMode = tauDecayModes.genDecayModeInt([d for d in finalDaughters(gg) \
                                                      if abs(d.pdgId()) not in [12, 14, 16]])
        if 'gmsb' in sample:
            dm_string = genDecayModeGEANT( [d for d in finalDaughters(gg) if abs(d.pdgId()) not in [12, 14, 16]])
            gg.decayMode = tauDecayModes.nameToInt(dm_string)

        gg.bestmom = None
        if gg.numberOfMothers() > 1:
            ## print 'more than 1 one, taking first one'
            tau_moms = [imom for imom in ev.gen_particles if isAncestor(imom, gg) and abs(imom.pdgId()) in mom_pdgId]
            gg.bestmom = tau_moms[0]
        elif gg.numberOfMothers() == 1 and abs(gg.mother(0).pdgId()) in mom_pdgId:
            gg.bestmom = gg.mother(0)

        ### find first dau to be used for vertices
        gg.dau = None
        if gg.numberOfDaughters() > 0:  gg.dau = gg.daughter(0)
Exemple #12
0
                        p.isPromptDecayed()
                    )
                )
            )
        ]
        #if len(visibleTaus) > 0:
        #    print([g.pdgId() for g in genLeptons], len(visibleTaus))
        genLeptons += visibleTaus

        refObjs = []
        if runtype in tau_run_types:
            for gen_tau in genTaus:
                gen_tau.visP4 = visibleP4(gen_tau)

                gen_dm = tauDecayModes.genDecayModeInt(
                    [d for d in gen_tau.final_ds
                        if abs(d.pdgId()) not in [12, 14, 16]]
                )
                if abs(gen_tau.visP4.eta()) >= 3.0:
                    continue
                if gen_tau.visP4.pt() <= 20:
                    continue
                if gen_dm == -11 or gen_dm == -13:
                    continue
                # For the 10-tau sample, remove gen taus that have overlap
                if any(deltaR(other_tau, gen_tau) < 0.5
                       for other_tau in genTaus if other_tau is not gen_tau):
                    continue

                refObjs.append(gen_tau)

        elif runtype in jet_run_types:
    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:
                    DYJetsFakeAnalyzer.genMatch(event, tau, ptSelGentauleps,
                                                ptSelGenleps, ptSelGenSummary)
                    DYJetsFakeAnalyzer.attachGenStatusFlag(tau)
                DYJetsFakeAnalyzer.genMatch(event, muon, ptSelGentauleps,
                                            ptSelGenleps, ptSelGenSummary)
                DYJetsFakeAnalyzer.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)