From c79f692126b277a42833ea16d3d50e1995daa1c8 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 27 Feb 2015 18:01:11 +0100 Subject: [PATCH 1/7] added Pt, eta, phi of jet from which the tau was build (needed for cross-cleaning of jet collection) --- PhysicsTools/Heppy/python/analyzers/objects/autophobj.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py b/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py index 1381941fa7ace..50fe3886e671b 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py @@ -108,6 +108,10 @@ NTupleVariable("idDecayModeNewDMs", lambda x : x.idDecayModeNewDMs, int), NTupleVariable("dxy", lambda x : x.dxy(), help="d_{xy} of lead track with respect to PV, in cm (with sign)"), NTupleVariable("dz", lambda x : x.dz() , help="d_{z} of lead track with respect to PV, in cm (with sign)"), + NTupleVariable("rawJetPt", lambda x : x.pfEssential().p4Jet_.pt(), help="transverse momentum of jet from which this tau was built, jet energy corrections not applied"), + NTupleVariable("corrJetPt", lambda x : x.pfEssential().p4CorrJet_.pt(), help="transverse momentum of jet from which this tau was built, jet energy corrections applied"), + NTupleVariable("rawJetEta", lambda x : x.pfEssential().p4Jet_.eta(), help="pseudo-rapidity of jet from which this tau was built"), + NTupleVariable("rawJetPhi", lambda x : x.pfEssential().p4Jet_.phi(), help="azimuthal angle of jet from which this tau was built"), NTupleVariable("idMVA", lambda x : x.idMVA, int, help="1,2,3,4,5,6 if the tau passes the very loose to very very tight WP of the MVA3oldDMwLT discriminator"), NTupleVariable("idMVANewDM", lambda x : x.idMVANewDM, int, help="1,2,3,4,5,6 if the tau passes the very loose to very very tight WP of the MVA3newDMwLT discriminator"), NTupleVariable("idCI3hit", lambda x : x.idCI3hit, int, help="1,2,3 if the tau passes the loose, medium, tight WP of the ByCombinedIsolationDBSumPtCorr3Hits discriminator"), From 41715018a4f1e76a3cdb6aa09fb0d6e0c50046e6 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 28 Feb 2015 17:57:36 +0100 Subject: [PATCH 2/7] stored jet index instead of rawJet Pt, eta, phi (in order to allow for cross-cleaning of jet collection wrt. taus on analysis level) --- .../python/analyzers/objects/TauAnalyzer.py | 25 +++++++++++++------ .../python/analyzers/objects/autophobj.py | 5 +--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/PhysicsTools/Heppy/python/analyzers/objects/TauAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/objects/TauAnalyzer.py index 11200ae13d1ec..c5e48940dbc8d 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/TauAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/TauAnalyzer.py @@ -6,9 +6,7 @@ import PhysicsTools.HeppyCore.framework.config as cfg - class TauAnalyzer( Analyzer ): - def __init__(self, cfg_ana, cfg_comp, looperName ): super(TauAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName) @@ -18,8 +16,8 @@ def __init__(self, cfg_ana, cfg_comp, looperName ): #---------------------------------------- def declareHandles(self): super(TauAnalyzer, self).declareHandles() - self.handles['taus'] = AutoHandle( ('slimmedTaus',''),'std::vector') - + self.handles['taus'] = AutoHandle( ('slimmedTaus',''), 'std::vector' ) + self.handles['jets'] = AutoHandle( ('slimmedJets',''), 'std::vector' ) def beginLoop(self, setup): super(TauAnalyzer,self).beginLoop(setup) @@ -58,9 +56,9 @@ def makeTaus(self, event): if tau.lepVeto: continue if self.cfg_ana.vetoLeptonsPOG: if not tau.tauID(self.cfg_ana.tauAntiMuonID): - tau.lepVeto = True + tau.lepVeto = True if not tau.tauID(self.cfg_ana.tauAntiElectronID): - tau.lepVeto = True + tau.lepVeto = True if tau.lepVeto: continue if tau.pt() < self.cfg_ana.ptMin: continue @@ -84,8 +82,19 @@ def id6(tau,X): tau.idMVANewDM = id6(tau, "by%sIsolationMVA3newDMwLT") tau.idCI3hit = id3(tau, "by%sCombinedIsolationDeltaBetaCorr3Hits") tau.idAntiMu = tau.tauID("againstMuonLoose") + tau.tauID("againstMuonTight") - tau.idAntiE = id5(tau, "againstElectron%sMVA5") + tau.idAntiE = id5(tau, "againstElectron%sMVA5") #print "Tau pt %5.1f: idMVA2 %d, idCI3hit %d, %s, %s" % (tau.pt(), tau.idMVA2, tau.idCI3hit, tau.tauID(self.cfg_ana.tauID), tau.tauID(self.cfg_ana.tauLooseID)) + + idxJet_matched = -1 + dRmin = 1.e+3 + for idxJet in range(len(event.jets)): + jet = event.jets[idxJet] + dR = deltaR(tau.eta(), tau.phi(), jet.eta(), jet.phi()) + if dR < 0.5 and dR < dRmin: + idxJet_matched = idxJet + dRmin = dR + tau.idxJetMatch = idxJet_matched + if tau.tauID(self.cfg_ana.tauID): event.selectedTaus.append(tau) event.inclusiveTaus.append(tau) @@ -125,7 +134,7 @@ def process(self, event): # http://cmslxr.fnal.gov/lxr/source/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py setattr(TauAnalyzer,"defaultConfig",cfg.Analyzer( - class_object=TauAnalyzer, + class_object = TauAnalyzer, ptMin = 20, etaMax = 9999, dxyMax = 1000., diff --git a/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py b/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py index 50fe3886e671b..02d1b7b807e83 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py @@ -108,10 +108,7 @@ NTupleVariable("idDecayModeNewDMs", lambda x : x.idDecayModeNewDMs, int), NTupleVariable("dxy", lambda x : x.dxy(), help="d_{xy} of lead track with respect to PV, in cm (with sign)"), NTupleVariable("dz", lambda x : x.dz() , help="d_{z} of lead track with respect to PV, in cm (with sign)"), - NTupleVariable("rawJetPt", lambda x : x.pfEssential().p4Jet_.pt(), help="transverse momentum of jet from which this tau was built, jet energy corrections not applied"), - NTupleVariable("corrJetPt", lambda x : x.pfEssential().p4CorrJet_.pt(), help="transverse momentum of jet from which this tau was built, jet energy corrections applied"), - NTupleVariable("rawJetEta", lambda x : x.pfEssential().p4Jet_.eta(), help="pseudo-rapidity of jet from which this tau was built"), - NTupleVariable("rawJetPhi", lambda x : x.pfEssential().p4Jet_.phi(), help="azimuthal angle of jet from which this tau was built"), + NTupleVariable("idxJetMatch", lambda x : x.idxJetMatch, help="index of jet matched to tau candidate (for cross-cleaning purposes"), NTupleVariable("idMVA", lambda x : x.idMVA, int, help="1,2,3,4,5,6 if the tau passes the very loose to very very tight WP of the MVA3oldDMwLT discriminator"), NTupleVariable("idMVANewDM", lambda x : x.idMVANewDM, int, help="1,2,3,4,5,6 if the tau passes the very loose to very very tight WP of the MVA3newDMwLT discriminator"), NTupleVariable("idCI3hit", lambda x : x.idCI3hit, int, help="1,2,3 if the tau passes the loose, medium, tight WP of the ByCombinedIsolationDBSumPtCorr3Hits discriminator"), From 4034a0c17b54ddcf45664293e3aba5937a118c56 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 28 Feb 2015 18:04:03 +0100 Subject: [PATCH 3/7] added information for ttH, H -> tautau analysis: - event category on generator level - flag indicating if reconstructed tau candidate matches a hadronic tau decay on generator level or is due to misidentified jet, electron or muon --- .../Heppy/python/TTHtoTauTauAnalyzer.py | 66 ++++++++ .../python/TTHtoTauTauGeneratorAnalyzer.py | 148 ++++++++++++++++++ .../Heppy/python/VHGeneratorAnalyzer.py | 2 +- VHbbAnalysis/Heppy/python/tthobj.py | 14 ++ VHbbAnalysis/Heppy/test/vhbb.py | 47 +++--- 5 files changed, 257 insertions(+), 20 deletions(-) create mode 100644 VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py create mode 100644 VHbbAnalysis/Heppy/python/TTHtoTauTauGeneratorAnalyzer.py create mode 100644 VHbbAnalysis/Heppy/python/tthobj.py diff --git a/VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py b/VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py new file mode 100644 index 0000000000000..3cce07a22404e --- /dev/null +++ b/VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py @@ -0,0 +1,66 @@ +from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer +from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle +from PhysicsTools.Heppy.physicsobjects.Tau import Tau + +from PhysicsTools.HeppyCore.utils.deltar import deltaR, matchObjectCollection3 + +import PhysicsTools.HeppyCore.framework.config as cfg + +class TTHtoTauTauAnalyzer( Analyzer ): + '''Analyze ttH, H -> tautau events''' + + def declareHandles(self): + super(TTHtoTauTauAnalyzer, self).declareHandles() + + ##self.handles['taus'] = AutoHandle( ('slimmedTaus',''), 'std::vector' ) + + #mc information + self.mchandles['genParticles'] = AutoHandle( 'prunedGenParticles', + 'std::vector' ) + + def addTau_genMatchType(self, event, tau): + '''Determine if given tau matched gen level hadronic tau decay or is due to a misidentified jet, electron or muon + tau.genMatchType = 0 for matched to gen level hadronic tau decay + = 1 for matched to gen level jet + = 2 for matched to gen level electron + = 3 for matched to gen level muon + ''' + + genParticles = list(self.mchandles['genParticles'].product() ) + + genMatchType = 1 # assume hadronic tau to be due to misidentified jet per default + if tau.genJet(): + genMatchType = 0 + if genMatchType == 1: + match = matchObjectCollection3([ tau ], genParticles, deltaRMax = 0.4, filter = lambda x,y : True if (y.pt() > 0.5*x.pt() and abs(y.pdgId()) == 11) else False) + if match[tau]: + genMatchType = 2 + if genMatchType == 1: + match = matchObjectCollection3([ tau ], genParticles, deltaRMax = 0.4, filter = lambda x,y : True if (y.pt() > 0.5*x.pt() and abs(y.pdgId()) == 13) else False) + if match[tau]: + genMatchType = 3 + + return genMatchType + + def process(self, event): + print ":" + + self.readCollections( event.input ) + + ##taus = list( self.handles['taus'].product() ) + taus = event.selectedTaus + taus_modified = [] + for idxTau in range(len(taus)): + tau = Tau(taus[idxTau]) + print "processing tau #%i: Pt = %1.2f, eta = %1.2f, phi = %1.2f" % (idxTau, tau.pt(), tau.eta(), tau.phi()) + # if not MC, nothing to do + if self.cfg_comp.isMC: + tau.genMatchType = self.addTau_genMatchType(event, tau) + else: + tau.genMatchType = -1 + print " genMatchType = %i" % tau.genMatchType + taus_modified.append(tau) + + event.selectedTaus = taus_modified + + return True diff --git a/VHbbAnalysis/Heppy/python/TTHtoTauTauGeneratorAnalyzer.py b/VHbbAnalysis/Heppy/python/TTHtoTauTauGeneratorAnalyzer.py new file mode 100644 index 0000000000000..e77c23a0c46e0 --- /dev/null +++ b/VHbbAnalysis/Heppy/python/TTHtoTauTauGeneratorAnalyzer.py @@ -0,0 +1,148 @@ + +from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer +from PhysicsTools.HeppyCore.framework.event import Event +from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle +from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import GenParticle + +from PhysicsTools.Heppy.physicsutils.genutils import * +import PhysicsTools.HeppyCore.framework.config as cfg + +class TTHtoTauTauGeneratorAnalyzer( Analyzer ): + """Do generator-level analysis of ttH, H -> tautau decay: + + Creates in the event: + event.genTTHtoTauTauDecayMode = 0 for 2b_2taul_2wl + 1 for 2b_2taulh_2wl + 2 for 2b_2tauh_2wl + 3 for 2b_2taul_2wlj + 4 for 2b_2taulh_2wlj + 5 for 2b_2tauh_2wlj + 6 for 2b_2taul_2wj + 7 for 2b_2taulh_2wj + 8 for 2b_2tauh_2wj + -1 other + """ + def __init__(self, cfg_ana, cfg_comp, looperName ): + super(TTHtoTauTauGeneratorAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName) + + #--------------------------------------------- + # DECLARATION OF HANDLES OF GEN LEVEL OBJECTS + #--------------------------------------------- + + def declareHandles(self): + super(TTHtoTauTauGeneratorAnalyzer, self).declareHandles() + + #mc information + self.mchandles['genParticles'] = AutoHandle( 'prunedGenParticles', + 'std::vector' ) + + def beginLoop(self,setup): + super(TTHtoTauTauGeneratorAnalyzer,self).beginLoop(setup) + + def findFirstDaughterGivenPdgId(self, givenMother, givenPdgIds): + """Get the first gen level daughter particle with given pdgId""" + + mothers = [] + if givenMother: + mothers.append(givenMother) + while len(mothers) > 0: + daughters = [] + for mother in mothers: + for idxDaughter in range(mother.numberOfDaughters()): + daughter = GenParticle(mother.daughter(idxDaughter)) + daughters.append(daughter) + for daughter in daughters: + if daughter.pdgId() in givenPdgIds: + return daughter + mothers = daughters + + # no daughter particle with given pdgId found + return None + + def fillGenTTHtoTauTauDecayMode(self, event, genParticles): + """Determine gen level ttH, H -> tautau decay mode""" + + t = None + tbar = None + H = None + + for genParticle in genParticles: + pdgId = genParticle.pdgId() + if pdgId == +6 and not t: + t = genParticle + if pdgId == -6 and not tbar: + tbar = genParticle + if pdgId in [ 25, 35, 36 ] and not H: + H = genParticle + + numElectrons_or_Muons_fromH = 0 + numHadTaus_fromH = 0 + if self.findFirstDaughterGivenPdgId(H, [ -11, -13 ]): + numElectrons_or_Muons_fromH = numElectrons_or_Muons_fromH + 1 + elif self.findFirstDaughterGivenPdgId(H, [ -15 ]): + numHadTaus_fromH = numHadTaus_fromH + 1 + if self.findFirstDaughterGivenPdgId(H, [ +11, +13 ]): + numElectrons_or_Muons_fromH = numElectrons_or_Muons_fromH + 1 + elif self.findFirstDaughterGivenPdgId(H, [ +15 ]): + numHadTaus_fromH = numHadTaus_fromH + 1 + + numBs = 0 + if self.findFirstDaughterGivenPdgId(t, [ +5 ]): + numBs = numBs + 1 + if self.findFirstDaughterGivenPdgId(tbar, [ -5 ]): + numBs = numBs + 1 + + Wplus = self.findFirstDaughterGivenPdgId(t, [ +24 ]) + Wminus = self.findFirstDaughterGivenPdgId(tbar, [ -24 ]) + + numElectrons_or_Muons_fromW = 0 + numHadTaus_fromW = 0 + if self.findFirstDaughterGivenPdgId(Wplus, [ -11, -13 ]): + numElectrons_or_Muons_fromW = numElectrons_or_Muons_fromW + 1 + elif self.findFirstDaughterGivenPdgId(Wplus, [ -15 ]): + numHadTaus_fromW = numHadTaus_fromW + 1 + if self.findFirstDaughterGivenPdgId(Wminus, [ +11, +13 ]): + numElectrons_or_Muons_fromW = numElectrons_or_Muons_fromW + 1 + elif self.findFirstDaughterGivenPdgId(Wminus, [ +15 ]): + numHadTaus_fromW = numHadTaus_fromW + 1 + + event.genTTHtoTauTauDecayMode = -1 + if numElectrons_or_Muons_fromH == 2 and (numElectrons_or_Muons_fromW + numHadTaus_fromW) == 2: + event.genTTHtoTauTauDecayMode = 0 + elif numElectrons_or_Muons_fromH == 1 and numHadTaus_fromH == 1 and (numElectrons_or_Muons_fromW + numHadTaus_fromW) == 2: + event.genTTHtoTauTauDecayMode = 1 + elif numHadTaus_fromH == 2 and numElectrons_or_Muons_fromW == 2: + event.genTTHtoTauTauDecayMode = 2 + elif numElectrons_or_Muons_fromH == 2 and (numElectrons_or_Muons_fromW + numHadTaus_fromW) == 1: + event.genTTHtoTauTauDecayMode = 3 + elif numElectrons_or_Muons_fromH == 1 and numHadTaus_fromH == 1 and (numElectrons_or_Muons_fromW + numHadTaus_fromW) == 1: + event.genTTHtoTauTauDecayMode = 4 + elif numHadTaus_fromH == 2 and (numElectrons_or_Muons_fromW + numHadTaus_fromW) == 1: + event.genTTHtoTauTauDecayMode = 5 + elif numElectrons_or_Muons_fromH == 2 and (numElectrons_or_Muons_fromW + numHadTaus_fromW) == 0: + event.genTTHtoTauTauDecayMode = 6 + elif numElectrons_or_Muons_fromH == 1 and numHadTaus_fromH == 1 and numElectrons_or_Muons_fromW == 0: + event.genTTHtoTauTauDecayMode = 7 + elif numHadTaus_fromH == 2 and numElectrons_or_Muons_fromW == 0: + event.genTTHtoTauTauDecayMode = 8 + + def makeMCInfo(self, event): + genParticles = list(self.mchandles['genParticles'].product() ) + self.fillGenTTHtoTauTauDecayMode(event, genParticles) + + def process(self, event): + self.readCollections(event.input) + + # if not MC, nothing to do + if not self.cfg_comp.isMC: + return True + + # do MC level analysis + self.makeMCInfo(event) + + return True + +setattr(TTHtoTauTauGeneratorAnalyzer, "defaultConfig", cfg.Analyzer( + class_object = TTHtoTauTauGeneratorAnalyzer, + verbose = False, +)) diff --git a/VHbbAnalysis/Heppy/python/VHGeneratorAnalyzer.py b/VHbbAnalysis/Heppy/python/VHGeneratorAnalyzer.py index a7fa643398c54..5c15a354a3efe 100644 --- a/VHbbAnalysis/Heppy/python/VHGeneratorAnalyzer.py +++ b/VHbbAnalysis/Heppy/python/VHGeneratorAnalyzer.py @@ -294,7 +294,7 @@ def process(self, event): return True setattr(GeneratorAnalyzer,"defaultConfig",cfg.Analyzer( - class_object=GeneratorAnalyzer, + class_object = GeneratorAnalyzer, filterHiggsDecays = False, verbose = False, PDFWeights = [] diff --git a/VHbbAnalysis/Heppy/python/tthobj.py b/VHbbAnalysis/Heppy/python/tthobj.py new file mode 100644 index 0000000000000..c0d651fd7cee8 --- /dev/null +++ b/VHbbAnalysis/Heppy/python/tthobj.py @@ -0,0 +1,14 @@ + +#!/bin/env python +from math import * +import ROOT +from PhysicsTools.Heppy.analyzers.objects.autophobj import * + +##------------------------------------------ +## TAU +##------------------------------------------ + +tauTypeVHbb = NTupleObjectType("tauTypeVHbb", baseObjectTypes = [ tauType ], variables = [ + NTupleVariable("genMatchType", lambda x : x.genMatchType, int) +]) + diff --git a/VHbbAnalysis/Heppy/test/vhbb.py b/VHbbAnalysis/Heppy/test/vhbb.py index 99833192a52e4..1749d44ae426c 100755 --- a/VHbbAnalysis/Heppy/test/vhbb.py +++ b/VHbbAnalysis/Heppy/test/vhbb.py @@ -8,6 +8,7 @@ from DataFormats.FWLite import * import PhysicsTools.HeppyCore.framework.config as cfg from VHbbAnalysis.Heppy.vhbbobj import * +from VHbbAnalysis.Heppy.tthobj import * from PhysicsTools.HeppyCore.utils.deltar import deltaPhi from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer import * @@ -30,22 +31,23 @@ NTupleVariable("rho", lambda ev: ev.rho, float, help="kt6PFJets rho"), NTupleVariable("deltaR_jj", lambda ev: deltaR(ev.hJets[0].eta(),ev.hJets[0].phi(),ev.hJets[1].eta(),ev.hJets[1].phi()) if len(ev.hJets) > 1 else -1, float, help="deltaR higgsJets"), NTupleVariable("minDr3", lambda ev: ev.minDr3, help="dR of closest jets for 3 jest case"), - NTupleVariable("lheNj", lambda ev: ev.lheNj, float,mcOnly=True, help="number of jets at LHE level"), - NTupleVariable("lheNb", lambda ev: ev.lheNb, float,mcOnly=True, help="number of b-jets at LHE level"), - NTupleVariable("lheNc", lambda ev: ev.lheNc, float,mcOnly=True, help="number of c-jets at LHE level"), - NTupleVariable("lheNg", lambda ev: ev.lheNg, float,mcOnly=True, help="number of gluon jets at LHE level"), - NTupleVariable("lheNl", lambda ev: ev.lheNl, float,mcOnly=True, help="number of light(uds) jets at LHE level"), + NTupleVariable("lheNj", lambda ev: ev.lheNj, float,mcOnly=True, help="number of jets at LHE level"), + NTupleVariable("lheNb", lambda ev: ev.lheNb, float,mcOnly=True, help="number of b-jets at LHE level"), + NTupleVariable("lheNc", lambda ev: ev.lheNc, float,mcOnly=True, help="number of c-jets at LHE level"), + NTupleVariable("lheNg", lambda ev: ev.lheNg, float,mcOnly=True, help="number of gluon jets at LHE level"), + NTupleVariable("lheNl", lambda ev: ev.lheNl, float,mcOnly=True, help="number of light(uds) jets at LHE level"), NTupleVariable("lheV_pt", lambda ev: ev.lheV_pt, float,mcOnly=True, help="Vector pT at LHE level"), - NTupleVariable("lheHT", lambda ev: ev.lheHT, float,mcOnly=True, help="HT at LHE level"), + NTupleVariable("lheHT", lambda ev: ev.lheHT, float,mcOnly=True, help="HT at LHE level"), + NTupleVariable("genTTHtoTauTauDecayMode", lambda ev: ev.genTTHtoTauTauDecayMode, int, help="gen level ttH, H -> tautau decay mode") ], globalObjects = { "met" : NTupleObject("met", metType, help="PF E_{T}^{miss}, after default type 1 corrections"), "fakeMET" : NTupleObject("fakeMET", fourVectorType, help="fake MET in Zmumu event obtained removing the muons"), "H" : NTupleObject("H", fourVectorType, help="higgs"), "HCSV" : NTupleObject("HCSV", fourVectorType, help="higgs CSV selection"), - "H3cj" : NTupleObject("H3cj", fourVectorType, help="higgs 3 cen jets selection"), + "H3cj" : NTupleObject("H3cj", fourVectorType, help="higgs 3 cen jets selection"), "V" : NTupleObject("V", fourVectorType, help="z or w"), -}, + }, collections = { #standard dumping of objects "selectedLeptons" : NTupleCollection("selLeptons", leptonTypeVHbb, 8, help="Leptons after the preselection"), @@ -64,7 +66,7 @@ "hjidx3cj" : NTupleCollection("hJ3Cidx", objectInt, 2,help="Higgs jet indices 3 cen jets"), "ajidx3cj" : NTupleCollection("aJ3Cidx", objectInt, 2,help="additional jet indices 3 cen jets"), "cleanJetsAll" : NTupleCollection("Jet", jetTypeVHbb, 15, help="Cental+fwd jets after full selection and cleaning, sorted by b-tag"), - "selectedTaus" : NTupleCollection("TauGood", tauType, 3, help="Taus after the preselection"), + "selectedTaus" : NTupleCollection("TauGood", tauTypeVHbb, 3, help="Taus after the preselection"), #dump of gen objects "genJets" : NTupleCollection("GenJet", genParticleType, 15, help="Generated top quarks from hard scattering",filter=lambda x: x.pt() > 20,mcOnly=True), @@ -114,15 +116,13 @@ from PhysicsTools.Heppy.analyzers.objects.METAnalyzer import METAnalyzer METAna = METAnalyzer.defaultConfig - from PhysicsTools.Heppy.analyzers.core.PileUpAnalyzer import PileUpAnalyzer PUAna = PileUpAnalyzer.defaultConfig - from VHbbAnalysis.Heppy.VHbbAnalyzer import VHbbAnalyzer JetAna.jetPt = 15 -VHbb= cfg.Analyzer( +VHbb = cfg.Analyzer( verbose=False, class_object=VHbbAnalyzer, wEleSelection = lambda x : x.pt() > 25 and x.electronID("cutBasedElectronID-CSA14-PU20bx25-V0-standalone-tight"), @@ -133,8 +133,18 @@ zLeadingMuPt = 20, higgsJetsPreSelection = lambda x: x.puJetId() > 0 and x.jetID('POG_PFID_Loose') and x.pt() > 15 , passall=False, +) - ) +from VHbbAnalysis.Heppy.TTHtoTauTauAnalyzer import TTHtoTauTauAnalyzer +TTHtoTauTau = cfg.Analyzer( + verbose = False, + class_object = TTHtoTauTauAnalyzer, +) +from VHbbAnalysis.Heppy.TTHtoTauTauGeneratorAnalyzer import TTHtoTauTauGeneratorAnalyzer +TTHtoTauTauGen = cfg.Analyzer( + verbose = False, + class_object = TTHtoTauTauGeneratorAnalyzer, +) #from VHbbAnalysis.Heppy.HeppyShell import HeppyShell #sh = cfg.Analyzer( class_object=HeppyShell) @@ -165,8 +175,6 @@ option='recreate' ) - - from PhysicsTools.Heppy.analyzers.core.TriggerBitAnalyzer import TriggerBitAnalyzer FlagsAna = TriggerBitAnalyzer.defaultEventFlagsConfig @@ -187,7 +195,7 @@ #TrigAna.unrollbits=True -sequence = [LHEAna,FlagsAna, GenAna,VHGenAna,PUAna,TrigAna,VertexAna,LepAna,TauAna,PhoAna,JetAna,METAna,PdfAna,VHbb,treeProducer]#,sh] +sequence = [LHEAna,FlagsAna, GenAna,VHGenAna,PUAna,TrigAna,VertexAna,LepAna,PhoAna,JetAna,TauAna,METAna,PdfAna,VHbb,TTHtoTauTau,TTHtoTauTauGen,treeProducer]#,sh] from PhysicsTools.Heppy.utils.miniAodFiles import miniAodFiles @@ -198,12 +206,13 @@ # 'root://eoscms//eos/cms//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_POSTLS170_V5-v1/00000/62ED6255-AE09-E411-97CB-00266CFFBF88.root', # 'root://eoscms//eos/cms//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_POSTLS170_V5-v1/00000/72C26B45-AD09-E411-A77C-00266CFFBF80.root', # 'root://eoscms//eos/cms//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_POSTLS170_V5-v1/00000/BAEE7255-AE09-E411-8F9F-00266CFFBF88.root', -# 'root://eoscms//eos/cms//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_POSTLS170_V5-v1/00000/D600138D-AD09-E411-917F-00266CFFBF88.root'], +# 'root://eoscms//eos/cms//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_POSTLS170_V5-v1/00000/D600138D-AD09-E411-917F-00266CFFBF88.root' #'root://xrootd.ba.infn.it//store/mc/Phys14DR/WH_HToBB_WToLNu_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_tsg_PHYS14_25_V1-v1/00000/12328AE8-796B-E411-9D32-002590A831B4.root' #"32ABFE4A-916B-E411-B2FA-00266CFFBC60.root" #Hbb #"04860BAA-B673-E411-8B20-002481E0D50C.root" #DY 600 #"TTPU20-007B37D4-8B70-E411-BC2D-0025905A6066.root" # -#"root://xrootd.ba.infn.it//store/mc/Phys14DR/ZH_HToBB_ZToNuNu_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_tsg_PHYS14_25_V1-v1/00000/32ABFE4A-916B-E411-B2FA-00266CFFBC60.root" +##"root://xrootd.ba.infn.it//store/mc/Phys14DR/ZH_HToBB_ZToNuNu_M-125_13TeV_powheg-herwigpp/MINIAODSIM/PU20bx25_tsg_PHYS14_25_V1-v1/00000/32ABFE4A-916B-E411-B2FA-00266CFFBC60.root" +"root://eoscms//eos/cms//store/user/veelken/veelken/Phys14/miniAODs/tth_HiggsToTauTau/tth_HiggsToTauTau_miniAOD_10_1_XrX.root" #"root://xrootd.ba.infn.it//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/#141029_PU40bx50_PLS170_V6AN2-v1/10000/80161D59-6665-E411-9B4F-C4346BB25698.root", #"root://xrootd.ba.infn.it:1194//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/141029_PU40bx50_PLS170_V6AN2-v1/10000/8A345C56-6665-E411-9C25-1CC1DE04DF20.root", #"root://stormgf1.pi.infn.it//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/141029_PU40bx50_PLS170_V6AN2-v1/10000/8A345C56-6665-E411-9C25-1CC1DE04DF20.root", @@ -211,7 +220,7 @@ #"root://xrootd.ba.infn.it//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/141029_PU40bx50_PLS170_V6AN2-v1/10000/9C477248-6665-E411-A9A6-1CC1DE1D0600.root", #"root://xrootd.ba.infn.it//store/mc/Spring14miniaod/ZH_HToBB_ZToLL_M-125_13TeV_powheg-herwigpp/MINIAODSIM/141029_PU40bx50_PLS170_V6AN2-v1/10000/C6D4D875-6665-E411-9E35-00266CF91A18.root" #"/home/joosep/mac-docs/tth/data/phys14/tth_hbb_phys14_08B36E8F-5E7F-E411-9D5A-002590200AE4.root" -"/home/joosep/mac-docs/tth/data/phys14/ttjets_phys14_00C90EFC-3074-E411-A845-002590DB9262.root" +#"/home/joosep/mac-docs/tth/data/phys14/ttjets_phys14_00C90EFC-3074-E411-A845-002590DB9262.root" ], #files = ["226BB247-A565-E411-91CF-00266CFF0AF4.root"], From 0808fb4d92e3efc5985d8dafec45ac56cd2e3344 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 28 Feb 2015 18:45:51 +0100 Subject: [PATCH 4/7] move definition of tau branches specific to VHbb Ntuples to vhbbobj.py file --- VHbbAnalysis/Heppy/python/tthobj.py | 14 -------------- VHbbAnalysis/Heppy/python/vhbbobj.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 VHbbAnalysis/Heppy/python/tthobj.py diff --git a/VHbbAnalysis/Heppy/python/tthobj.py b/VHbbAnalysis/Heppy/python/tthobj.py deleted file mode 100644 index c0d651fd7cee8..0000000000000 --- a/VHbbAnalysis/Heppy/python/tthobj.py +++ /dev/null @@ -1,14 +0,0 @@ - -#!/bin/env python -from math import * -import ROOT -from PhysicsTools.Heppy.analyzers.objects.autophobj import * - -##------------------------------------------ -## TAU -##------------------------------------------ - -tauTypeVHbb = NTupleObjectType("tauTypeVHbb", baseObjectTypes = [ tauType ], variables = [ - NTupleVariable("genMatchType", lambda x : x.genMatchType, int) -]) - diff --git a/VHbbAnalysis/Heppy/python/vhbbobj.py b/VHbbAnalysis/Heppy/python/vhbbobj.py index 1686792fa4d18..7013088aa6fec 100644 --- a/VHbbAnalysis/Heppy/python/vhbbobj.py +++ b/VHbbAnalysis/Heppy/python/vhbbobj.py @@ -5,8 +5,6 @@ #from CMGTools.TTHAnalysis.signedSip import * from PhysicsTools.Heppy.analyzers.objects.autophobj import * - - leptonTypeVHbb = NTupleObjectType("leptonTypeVHbb", baseObjectTypes = [ leptonType ], variables = [ # Loose id NTupleVariable("looseIdSusy", lambda x : x.looseIdSusy if hasattr(x, 'looseIdSusy') else -1, int, help="Loose ID for Susy ntuples (always true on selected leptons)"), @@ -41,6 +39,14 @@ # NTupleVariable("mcMatchTau", lambda x : x.mcMatchTau, int, mcOnly=True, help="True if the leptons comes from a tau"), ]) +##------------------------------------------ +## TAU +##------------------------------------------ + +tauTypeVHbb = NTupleObjectType("tauTypeVHbb", baseObjectTypes = [ tauType ], variables = [ + NTupleVariable("genMatchType", lambda x : x.genMatchType, int) +]) + ##------------------------------------------ ## JET ##------------------------------------------ From 7403ba8f736ee1580b38cb7795619b5ba45d43d0 Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 1 Mar 2015 09:50:13 +0100 Subject: [PATCH 5/7] Heppy: Add tau matching --- .../Heppy/python/analyzers/objects/JetAnalyzer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py index d879c29cae095..f6aa15f12291d 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py @@ -165,7 +165,16 @@ def process(self, event): lep.jet = lep else: lep.jet = jet + ## Associate jets to taus + taus = getattr(event,'selectedTaus',[]) + jtaupairs = matchObjectCollection( taus, allJets, self.jetLepDR**2) + for jet in allJets: + jet.taus = [l for l in jtaupairs if jtaupairs[l] == jet ] + for tau in taus: + tau.jet = jtaupairs[tau] + + #MC stuff if self.cfg_comp.isMC: event.deltaMetFromJetSmearing = [0, 0] for j in event.cleanJetsAll: From 8ba8dbb855a05fff3624ab6eb92c8d3a6cc0a1bb Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 1 Mar 2015 09:50:52 +0100 Subject: [PATCH 6/7] Tau stuff in VHbb --- VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py | 6 +++--- VHbbAnalysis/Heppy/python/VHbbAnalyzer.py | 9 ++++++++- VHbbAnalysis/Heppy/python/vhbbobj.py | 4 +++- VHbbAnalysis/Heppy/test/vhbb-btag.py | 2 +- VHbbAnalysis/Heppy/test/vhbb.py | 5 ++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py b/VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py index 3cce07a22404e..1b20403282048 100644 --- a/VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py +++ b/VHbbAnalysis/Heppy/python/TTHtoTauTauAnalyzer.py @@ -43,7 +43,7 @@ def addTau_genMatchType(self, event, tau): return genMatchType def process(self, event): - print ":" + #print ":" self.readCollections( event.input ) @@ -52,13 +52,13 @@ def process(self, event): taus_modified = [] for idxTau in range(len(taus)): tau = Tau(taus[idxTau]) - print "processing tau #%i: Pt = %1.2f, eta = %1.2f, phi = %1.2f" % (idxTau, tau.pt(), tau.eta(), tau.phi()) + #print "processing tau #%i: Pt = %1.2f, eta = %1.2f, phi = %1.2f" % (idxTau, tau.pt(), tau.eta(), tau.phi()) # if not MC, nothing to do if self.cfg_comp.isMC: tau.genMatchType = self.addTau_genMatchType(event, tau) else: tau.genMatchType = -1 - print " genMatchType = %i" % tau.genMatchType + #print " genMatchType = %i" % tau.genMatchType taus_modified.append(tau) event.selectedTaus = taus_modified diff --git a/VHbbAnalysis/Heppy/python/VHbbAnalyzer.py b/VHbbAnalysis/Heppy/python/VHbbAnalyzer.py index a49b0e907dab0..fff39ec53e75b 100644 --- a/VHbbAnalysis/Heppy/python/VHbbAnalyzer.py +++ b/VHbbAnalysis/Heppy/python/VHbbAnalyzer.py @@ -228,6 +228,13 @@ def classifyEvent(self,event): event.aLeptons = [x for x in event.inclusiveLeptons if x not in event.vLeptons] return True + + def fillTauIndices(self,event) : + for j in event.cleanJetsAll : + j.tauIdxs = [event.selectedTaus.index(x) for x in j.taus if j.taus in event.selectedTaus] + for t in event.selectedTaus : + t.jetIdx = event.cleanJetsAll.index(t.jet) if t.jet in event.cleanJetsAll else -1 + def initOutputs (self,event) : event.hJets = [] event.aJets = [] @@ -274,7 +281,7 @@ def process(self, event): self.doHiggsHighCSV(event) self.doHiggsHighPt(event) self.doHiggs3cj(event) - + self.fillTauIndices(event) # event.jee = list(self.handles['jee'].product()) diff --git a/VHbbAnalysis/Heppy/python/vhbbobj.py b/VHbbAnalysis/Heppy/python/vhbbobj.py index d612382257712..10056d8e9ef78 100644 --- a/VHbbAnalysis/Heppy/python/vhbbobj.py +++ b/VHbbAnalysis/Heppy/python/vhbbobj.py @@ -51,7 +51,8 @@ ##------------------------------------------ tauTypeVHbb = NTupleObjectType("tauTypeVHbb", baseObjectTypes = [ tauType ], variables = [ - NTupleVariable("genMatchType", lambda x : x.genMatchType, int) + NTupleVariable("idxJetMatch", lambda x : x.jetIdx, int, help="index of the matching jet"), + NTupleVariable("genMatchType", lambda x : x.genMatchType, int,mcOnly=True, help="..FILLME PLEASE..") ]) ##------------------------------------------ @@ -59,6 +60,7 @@ ##------------------------------------------ jetTypeVHbb = NTupleObjectType("jet", baseObjectTypes = [ jetType ], variables = [ + NTupleVariable("idxFirstTauMatch", lambda x : x.tauIdxs[0] if len(x.tauIdxs) > 0 else -1, int,help='index of the first matching tau'), NTupleVariable("hadronFlavour", lambda x : x.mcFlavour, int, mcOnly=True, help="match to heavy hadrons"), NTupleVariable("btagBDT", lambda x : getattr(x,"btagBDT",-99), help="btag"), NTupleVariable("btagProb", lambda x : x.btag('jetProbabilityBJetTags') , help="btag"), diff --git a/VHbbAnalysis/Heppy/test/vhbb-btag.py b/VHbbAnalysis/Heppy/test/vhbb-btag.py index 8aee72b6b8879..a811eb1ad75c9 100755 --- a/VHbbAnalysis/Heppy/test/vhbb-btag.py +++ b/VHbbAnalysis/Heppy/test/vhbb-btag.py @@ -10,7 +10,7 @@ config.preprocessor=preprocessor if __name__ == '__main__': from PhysicsTools.HeppyCore.framework.looper import Looper - looper = Looper( 'Loop', config, nPrint = 20, nEvents = 300) + looper = Looper( 'Loop', config, nPrint = 20, nEvents = 3000) import time import cProfile p = cProfile.Profile(time.clock) diff --git a/VHbbAnalysis/Heppy/test/vhbb.py b/VHbbAnalysis/Heppy/test/vhbb.py index d7184ba69ef25..1f85b823d9619 100755 --- a/VHbbAnalysis/Heppy/test/vhbb.py +++ b/VHbbAnalysis/Heppy/test/vhbb.py @@ -8,7 +8,6 @@ from DataFormats.FWLite import * import PhysicsTools.HeppyCore.framework.config as cfg from VHbbAnalysis.Heppy.vhbbobj import * -from VHbbAnalysis.Heppy.tthobj import * from PhysicsTools.HeppyCore.utils.deltar import deltaPhi from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer import * @@ -199,7 +198,7 @@ #TrigAna.unrollbits=True -sequence = [LHEAna,FlagsAna, GenAna,VHGenAna,PUAna,TrigAna,VertexAna,LepAna,PhoAna,JetAna,TauAna,METAna,PdfAna,VHbb,TTHtoTauTau,TTHtoTauTauGen,treeProducer]#,sh] +sequence = [LHEAna,FlagsAna, GenAna,VHGenAna,PUAna,TrigAna,VertexAna,LepAna,PhoAna,TauAna,JetAna,METAna,PdfAna,VHbb,TTHtoTauTau,TTHtoTauTauGen,treeProducer]#,sh] from PhysicsTools.Heppy.utils.miniAodFiles import miniAodFiles @@ -252,7 +251,7 @@ def filter(self, record): # and the following runs the process directly if __name__ == '__main__': from PhysicsTools.HeppyCore.framework.looper import Looper - looper = Looper( 'Loop', config, nPrint = 1, nEvents = 100) + looper = Looper( 'Loop', config, nPrint = 1, nEvents = 400) import time import cProfile From 9d8091bf7dce1b91d7080a59a27f417382cbddd8 Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 1 Mar 2015 09:50:13 +0100 Subject: [PATCH 7/7] Heppy: Add tau matching --- .../Heppy/python/analyzers/objects/JetAnalyzer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py index d879c29cae095..f6aa15f12291d 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py @@ -165,7 +165,16 @@ def process(self, event): lep.jet = lep else: lep.jet = jet + ## Associate jets to taus + taus = getattr(event,'selectedTaus',[]) + jtaupairs = matchObjectCollection( taus, allJets, self.jetLepDR**2) + for jet in allJets: + jet.taus = [l for l in jtaupairs if jtaupairs[l] == jet ] + for tau in taus: + tau.jet = jtaupairs[tau] + + #MC stuff if self.cfg_comp.isMC: event.deltaMetFromJetSmearing = [0, 0] for j in event.cleanJetsAll: