CMS 3D CMS Logo

taus_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
3 from PhysicsTools.JetMCAlgos.TauGenJets_cfi import tauGenJets
4 from PhysicsTools.JetMCAlgos.TauGenJetsDecayModeSelectorAllHadrons_cfi import tauGenJetsSelectorAllHadrons
5 
6 ##################### Updated tau collection with MVA-based tau-Ids rerun #######
7 # Used only in some eras
9 
10 ##################### User floats producers, selectors ##########################
11 
12 
13 finalTaus = cms.EDFilter("PATTauRefSelector",
14  src = cms.InputTag("slimmedTausUpdated"),
15  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT2015') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBnewDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBdR03oldDMwLT2017v2'))")
16 )
17 
18 for era in [eras.run2_nanoAOD_94XMiniAODv1,eras.run2_nanoAOD_92X]:
19  era.toModify(finalTaus,
20  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v1') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBnewDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBdR03oldDMwLT2017v2'))")
21  )
22 eras.run2_miniAOD_80XLegacy.toModify(finalTaus,
23  src = cms.InputTag("slimmedTaus"),
24  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT'))")
25  )
26 
27 ##################### Tables for final output and docs ##########################
28 def _tauIdWPMask(pattern, choices, doc=""):
29  return Var(" + ".join(["%d * tauID('%s')" % (pow(2,i), pattern % c) for (i,c) in enumerate(choices)]), "uint8",
30  doc=doc+": bitmask "+", ".join(["%d = %s" % (pow(2,i),c) for (i,c) in enumerate(choices)]))
31 def _tauId2WPMask(pattern,doc):
32  return _tauIdWPMask(pattern,choices=("Loose","Tight"),doc=doc)
33 def _tauId3WPMask(pattern,doc):
34  return _tauIdWPMask(pattern,choices=("Loose","Medium","Tight"),doc=doc)
35 def _tauId5WPMask(pattern,doc):
36  return _tauIdWPMask(pattern,choices=("VLoose","Loose","Medium","Tight","VTight"),doc=doc)
37 def _tauId6WPMask(pattern,doc):
38  return _tauIdWPMask(pattern,choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"),doc=doc)
39 def _tauId7WPMask(pattern,doc):
40  return _tauIdWPMask(pattern,choices=("VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),doc=doc)
41 
42 tauTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
43  src = cms.InputTag("linkedObjects","taus"),
44  cut = cms.string(""), #we should not filter on cross linked collections
45  name= cms.string("Tau"),
46  doc = cms.string("slimmedTaus after basic selection (" + finalTaus.cut.value()+")"),
47  singleton = cms.bool(False), # the number of entries is variable
48  extension = cms.bool(False), # this is the main table for the taus
49  variables = cms.PSet() # PSet defined below in era dependent way
50 )
51 _tauVarsBase = cms.PSet(P4Vars,
52  charge = Var("charge", int, doc="electric charge"),
53  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
54  decayMode = Var("decayMode()",int),
55  idDecayMode = Var("tauID('decayModeFinding')", bool),
56  idDecayModeNewDMs = Var("tauID('decayModeFindingNewDMs')", bool),
57 
58  leadTkPtOverTauPt = Var("leadChargedHadrCand.pt/pt ",float, doc="pt of the leading track divided by tau pt",precision=10),
59  leadTkDeltaEta = Var("leadChargedHadrCand.eta - eta ",float, doc="eta of the leading track, minus tau eta",precision=8),
60  leadTkDeltaPhi = Var("deltaPhi(leadChargedHadrCand.phi, phi) ",float, doc="phi of the leading track, minus tau phi",precision=8),
61 
62  dxy = Var("leadChargedHadrCand().dxy()",float, doc="d_{xy} of lead track with respect to PV, in cm (with sign)",precision=10),
63  dz = Var("leadChargedHadrCand().dz()",float, doc="d_{z} of lead track with respect to PV, in cm (with sign)",precision=14),
64 
65  # these are too many, we may have to suppress some
66  rawIso = Var( "tauID('byCombinedIsolationDeltaBetaCorrRaw3Hits')", float, doc = "combined isolation (deltaBeta corrections)", precision=10),
67  rawIsodR03 = Var( "(tauID('chargedIsoPtSumdR03')+max(0.,tauID('neutralIsoPtSumdR03')-0.072*tauID('puCorrPtSum')))", float, doc = "combined isolation (deltaBeta corrections, dR=0.3)", precision=10),
68  chargedIso = Var( "tauID('chargedIsoPtSum')", float, doc = "charged isolation", precision=10),
69  neutralIso = Var( "tauID('neutralIsoPtSum')", float, doc = "neutral (photon) isolation", precision=10),
70  puCorr = Var( "tauID('puCorrPtSum')", float, doc = "pileup correction", precision=10),
71  photonsOutsideSignalCone = Var( "tauID('photonPtSumOutsideSignalCone')", float, doc = "sum of photons outside signal cone", precision=10),
72 
73  rawAntiEle = Var("tauID('againstElectronMVA6Raw')", float, doc= "Anti-electron MVA discriminator V6 raw output discriminator", precision=10),
74  rawAntiEleCat = Var("tauID('againstElectronMVA6category')", int, doc="Anti-electron MVA discriminator V6 category"),
75 
76  idAntiMu = _tauId2WPMask("againstMuon%s3", doc= "Anti-muon discriminator V3: "),
77  idAntiEle = _tauId5WPMask("againstElectron%sMVA6", doc= "Anti-electron MVA discriminator V6"),
78 
79 # isoCI3hit = Var( "tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits")" doc="byCombinedIsolationDeltaBetaCorrRaw3Hits raw output discriminator"),
80 # photonOutsideSigCone = Var( "tauID("photonPtSumOutsideSignalCone")" doc="photonPtSumOutsideSignalCone raw output discriminator"),
81 
82 )
83 
84 _mvaIsoVars2015 = cms.PSet(
85  rawMVAnewDM = Var( "tauID('byIsolationMVArun2v1DBnewDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
86  rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
87  rawMVAoldDMdR03 = Var( "tauID('byIsolationMVArun2v1DBdR03oldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
88  idMVAnewDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBnewDMwLT", doc="IsolationMVArun2v1DBnewDMwLT ID working point (2015)"),
89  idMVAoldDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBoldDMwLT", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)"),
90  idMVAoldDMdR03 = _tauId6WPMask( "by%sIsolationMVArun2v1DBdR03oldDMwLT", doc="IsolationMVArun2v1DBoldDMdR0p3wLT ID working point (2015)")
91 )
92 _mvaIsoVars2015Reduced = cms.PSet(
93  rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2015')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
94  idMVAoldDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBoldDMwLT2015", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)"),
95 )
96 _mvaIsoVars2017v1 = cms.PSet(
97  rawMVAoldDM2017v1 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v1)",precision=10),
98  idMVAoldDM2017v1 = _tauId7WPMask( "by%sIsolationMVArun2v1DBoldDMwLT", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v1)")
99 )
100 _mvaIsoVars2017v2 = cms.PSet(
101  rawMVAnewDM2017v2 = Var( "tauID('byIsolationMVArun2v1DBnewDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBnewDMwLT raw output discriminator (2017v2)",precision=10),
102  rawMVAoldDM2017v2 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v2)",precision=10),
103  rawMVAoldDMdR032017v2 = Var( "tauID('byIsolationMVArun2v1DBdR03oldDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBdR03oldDMwLT raw output discriminator (2017v2)",precision=10),
104  idMVAnewDM2017v2 = _tauId7WPMask( "by%sIsolationMVArun2v1DBnewDMwLT2017v2", doc="IsolationMVArun2v1DBnewDMwLT ID working point (2017v2)"),
105  idMVAoldDM2017v2 = _tauId7WPMask( "by%sIsolationMVArun2v1DBoldDMwLT2017v2", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v2)"),
106  idMVAoldDMdR032017v2 = _tauId7WPMask( "by%sIsolationMVArun2v1DBdR03oldDMwLT2017v2", doc="IsolationMVArun2v1DBoldDMdR0p3wLT ID working point (2017v2)")
107 )
108 
109 _variablesMiniV2 = cms.PSet(
110  _tauVarsBase,
111  _mvaIsoVars2015Reduced,
112  _mvaIsoVars2017v1,
113  _mvaIsoVars2017v2
114 )
115 _variablesMiniV1 = _variablesMiniV2.clone()
116 _variablesMiniV1.rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10)
117 _variablesMiniV1.rawMVAoldDM2017v1 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2017v1')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v1)",precision=10)
118 _variablesMiniV1.idMVAoldDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBoldDMwLT", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)")
119 _variablesMiniV1.idMVAoldDM2017v1 = _tauId7WPMask( "by%sIsolationMVArun2v1DBoldDMwLT2017v1", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v1)")
120 _variables80X = cms.PSet(
121  _tauVarsBase,
122  _mvaIsoVars2015
123 )
124 
125 tauTable.variables=_variablesMiniV2
126 
127 for era in [eras.run2_nanoAOD_94XMiniAODv1,eras.run2_nanoAOD_92X]:
128  era.toModify(tauTable,
129  variables = _variablesMiniV1
130  )
131 eras.run2_miniAOD_80XLegacy.toModify(tauTable,
132  variables = _variables80X
133 )
134 tauGenJets.GenParticles = cms.InputTag("prunedGenParticles")
135 tauGenJets.includeNeutrinos = cms.bool(False)
136 
137 genVisTaus = cms.EDProducer("GenVisTauProducer",
138  src = cms.InputTag("tauGenJetsSelectorAllHadrons"),
139  srcGenParticles = cms.InputTag("prunedGenParticles")
140 )
141 
142 genVisTauTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
143  src = cms.InputTag("genVisTaus"),
144  cut = cms.string("pt > 10."),
145  name = cms.string("GenVisTau"),
146  doc = cms.string("gen hadronic taus "),
147  singleton = cms.bool(False), # the number of entries is variable
148  extension = cms.bool(False), # this is the main table for generator level hadronic tau decays
149  variables = cms.PSet(
150  pt = Var("pt", float,precision=8),
151  phi = Var("phi", float,precision=8),
152  eta = Var("eta", float,precision=8),
153  mass = Var("mass", float,precision=8),
154  charge = Var("charge", int),
155  status = Var("status", int, doc="Hadronic tau decay mode. 0=OneProng0PiZero, 1=OneProng1PiZero, 2=OneProng2PiZero, 10=ThreeProng0PiZero, 11=ThreeProng1PiZero, 15=Other"),
156  genPartIdxMother = Var("?numberOfMothers>0?motherRef(0).key():-1", int, doc="index of the mother particle"),
157  )
158 )
159 
160 tausMCMatchLepTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
161  src = tauTable.src, # final reco collection
162  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
163  mcPdgId = cms.vint32(11,13), # one or more PDG ID (11 = electron, 13 = muon); absolute values (see below)
164  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
165  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
166  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
167  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
168  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
169  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
170 )
171 
172 tausMCMatchHadTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
173  src = tauTable.src, # final reco collection
174  matched = cms.InputTag("genVisTaus"), # generator level hadronic tau decays
175  mcPdgId = cms.vint32(15), # one or more PDG ID (15 = tau); absolute values (see below)
176  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
177  mcStatus = cms.vint32(), # CV: no *not* require certain status code for matching (status code corresponds to decay mode for hadronic tau decays)
178  maxDeltaR = cms.double(0.3), # Maximum deltaR for the match
179  maxDPtRel = cms.double(1.), # Maximum deltaPt/Pt for the match
180  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
181  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
182 )
183 
184 tauMCTable = cms.EDProducer("CandMCMatchTableProducer",
185  src = tauTable.src,
186  mcMap = cms.InputTag("tausMCMatchLepTauForTable"),
187  mcMapVisTau = cms.InputTag("tausMCMatchHadTauForTable"),
188  objName = tauTable.name,
189  objType = tauTable.name, #cms.string("Tau"),
190  branchName = cms.string("genPart"),
191  docString = cms.string("MC matching to status==2 taus"),
192 )
193 
194 
195 tauSequence = cms.Sequence(patTauMVAIDsSeq + finalTaus)
196 _tauSequence80X = cms.Sequence(finalTaus)
197 eras.run2_miniAOD_80XLegacy.toReplaceWith(tauSequence,_tauSequence80X)
198 tauTables = cms.Sequence(tauTable)
199 tauMC = cms.Sequence(tauGenJets + tauGenJetsSelectorAllHadrons + genVisTaus + genVisTauTable + tausMCMatchLepTauForTable + tausMCMatchHadTauForTable + tauMCTable)
200 
def _tauId7WPMask(pattern, doc)
Definition: taus_cff.py:39
def _tauId5WPMask(pattern, doc)
Definition: taus_cff.py:35
Updated tau collection with MVA-based tau-Ids rerun ####### Used only in some eras.
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20
def _tauId3WPMask(pattern, doc)
Definition: taus_cff.py:33
def _tauId6WPMask(pattern, doc)
Definition: taus_cff.py:37
def _tauIdWPMask(pattern, choices, doc="")
Tables for final output and docs ##########################.
Definition: taus_cff.py:28
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def _tauId2WPMask(pattern, doc)
Definition: taus_cff.py:31
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40