CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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('chargedIsoPtSumdR03')+max(0.,tauID('neutralIsoPtSumdR03')-0.072*tauID('puCorrPtSum'))<2.5) || tauID('byVVVLooseDeepTau2017v2p1VSjet'))")
16 )
17 
18 for era in [run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_94X2016, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1]:
19  era.toModify(finalTaus,
20  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT2015') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBnewDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBdR03oldDMwLT2017v2') || tauID('byVVVLooseDeepTau2017v2p1VSjet'))")
21  )
22 for era in [run2_nanoAOD_94XMiniAODv1,]:
23  era.toModify(finalTaus,
24  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v1') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBnewDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBdR03oldDMwLT2017v2') || tauID('byVVVLooseDeepTau2017v2p1VSjet'))")
25  )
26 run2_miniAOD_80XLegacy.toModify(finalTaus,
27  src = cms.InputTag("slimmedTaus"),
28  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT'))")
29  )
30 
31 ##################### Tables for final output and docs ##########################
32 def _tauIdWPMask(pattern, choices, doc=""):
33  return Var(" + ".join(["%d * tauID('%s')" % (pow(2,i), pattern % c) for (i,c) in enumerate(choices)]), "uint8",
34  doc=doc+": bitmask "+", ".join(["%d = %s" % (pow(2,i),c) for (i,c) in enumerate(choices)]))
35 def _tauId2WPMask(pattern,doc):
36  return _tauIdWPMask(pattern,choices=("Loose","Tight"),doc=doc)
37 def _tauId3WPMask(pattern,doc):
38  return _tauIdWPMask(pattern,choices=("Loose","Medium","Tight"),doc=doc)
39 def _tauId4WPMask(pattern,doc):
40  return _tauIdWPMask(pattern, choices=("VLoose", "Loose", "Medium", "Tight"), doc=doc)
41 def _tauId5WPMask(pattern,doc):
42  return _tauIdWPMask(pattern,choices=("VLoose","Loose","Medium","Tight","VTight"),doc=doc)
43 def _tauId6WPMask(pattern,doc):
44  return _tauIdWPMask(pattern,choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"),doc=doc)
45 def _tauId7WPMask(pattern,doc):
46  return _tauIdWPMask(pattern,choices=("VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),doc=doc)
47 def _tauId8WPMask(pattern,doc):
48  return _tauIdWPMask(pattern,choices=("VVVLoose","VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),doc=doc)
49 
50 tauTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
51  src = cms.InputTag("linkedObjects","taus"),
52  cut = cms.string(""), #we should not filter on cross linked collections
53  name= cms.string("Tau"),
54  doc = cms.string("slimmedTaus after basic selection (" + finalTaus.cut.value()+")"),
55  singleton = cms.bool(False), # the number of entries is variable
56  extension = cms.bool(False), # this is the main table for the taus
57  variables = cms.PSet() # PSet defined below in era dependent way
58 )
59 _tauVarsBase = cms.PSet(P4Vars,
60  charge = Var("charge", int, doc="electric charge"),
61  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
62  decayMode = Var("decayMode()",int),
63  idDecayModeOldDMs = Var("tauID('decayModeFinding')", bool),
64 
65  leadTkPtOverTauPt = Var("leadChargedHadrCand.pt/pt ",float, doc="pt of the leading track divided by tau pt",precision=10),
66  leadTkDeltaEta = Var("leadChargedHadrCand.eta - eta ",float, doc="eta of the leading track, minus tau eta",precision=8),
67  leadTkDeltaPhi = Var("deltaPhi(leadChargedHadrCand.phi, phi) ",float, doc="phi of the leading track, minus tau phi",precision=8),
68 
69  dxy = Var("leadChargedHadrCand().dxy()",float, doc="d_{xy} of lead track with respect to PV, in cm (with sign)",precision=10),
70  dz = Var("leadChargedHadrCand().dz()",float, doc="d_{z} of lead track with respect to PV, in cm (with sign)",precision=14),
71 
72  # these are too many, we may have to suppress some
73  rawIso = Var( "tauID('byCombinedIsolationDeltaBetaCorrRaw3Hits')", float, doc = "combined isolation (deltaBeta corrections)", precision=10),
74  rawIsodR03 = Var( "(tauID('chargedIsoPtSumdR03')+max(0.,tauID('neutralIsoPtSumdR03')-0.072*tauID('puCorrPtSum')))", float, doc = "combined isolation (deltaBeta corrections, dR=0.3)", precision=10),
75  chargedIso = Var( "tauID('chargedIsoPtSum')", float, doc = "charged isolation", precision=10),
76  neutralIso = Var( "tauID('neutralIsoPtSum')", float, doc = "neutral (photon) isolation", precision=10),
77  puCorr = Var( "tauID('puCorrPtSum')", float, doc = "pileup correction", precision=10),
78  photonsOutsideSignalCone = Var( "tauID('photonPtSumOutsideSignalCone')", float, doc = "sum of photons outside signal cone", precision=10),
79 
80  idAntiMu = _tauId2WPMask("againstMuon%s3", doc= "Anti-muon discriminator V3: "),
81  idAntiEleDeadECal = Var("tauID('againstElectronDeadECAL')", bool, doc = "Anti-electron dead-ECal discriminator"),
82 
83 # isoCI3hit = Var( "tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits")" doc="byCombinedIsolationDeltaBetaCorrRaw3Hits raw output discriminator"),
84 # photonOutsideSigCone = Var( "tauID("photonPtSumOutsideSignalCone")" doc="photonPtSumOutsideSignalCone raw output discriminator"),
85 
86 )
87 
88 _mvaIsoVars2015 = cms.PSet(
89  rawMVAnewDM = Var( "tauID('byIsolationMVArun2v1DBnewDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
90  rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
91  rawMVAoldDMdR03 = Var( "tauID('byIsolationMVArun2v1DBdR03oldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
92  idMVAnewDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBnewDMwLT", doc="IsolationMVArun2v1DBnewDMwLT ID working point (2015)"),
93  idMVAoldDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBoldDMwLT", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)"),
94  idMVAoldDMdR03 = _tauId6WPMask( "by%sIsolationMVArun2v1DBdR03oldDMwLT", doc="IsolationMVArun2v1DBoldDMdR0p3wLT ID working point (2015)")
95 )
96 _mvaIsoVars2015Reduced = cms.PSet(
97  rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2015')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
98  idMVAoldDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBoldDMwLT2015", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)"),
99 )
100 _mvaIsoVars2017v1 = cms.PSet(
101  rawMVAoldDM2017v1 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v1)",precision=10),
102  idMVAoldDM2017v1 = _tauId7WPMask( "by%sIsolationMVArun2v1DBoldDMwLT", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v1)")
103 )
104 _mvaIsoVars2017v2 = cms.PSet(
105  rawMVAnewDM2017v2 = Var( "tauID('byIsolationMVArun2v1DBnewDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBnewDMwLT raw output discriminator (2017v2)",precision=10),
106  rawMVAoldDM2017v2 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v2)",precision=10),
107  rawMVAoldDMdR032017v2 = Var( "tauID('byIsolationMVArun2v1DBdR03oldDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBdR03oldDMwLT raw output discriminator (2017v2)",precision=10),
108  idMVAnewDM2017v2 = _tauId7WPMask( "by%sIsolationMVArun2v1DBnewDMwLT2017v2", doc="IsolationMVArun2v1DBnewDMwLT ID working point (2017v2)"),
109  idMVAoldDM2017v2 = _tauId7WPMask( "by%sIsolationMVArun2v1DBoldDMwLT2017v2", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v2)"),
110  idMVAoldDMdR032017v2 = _tauId7WPMask( "by%sIsolationMVArun2v1DBdR03oldDMwLT2017v2", doc="IsolationMVArun2v1DBoldDMdR0p3wLT ID working point (2017v2)")
111 )
112 _mvaAntiEVars2015 = cms.PSet(
113  rawAntiEle = Var("tauID('againstElectronMVA6Raw')", float, doc= "Anti-electron MVA discriminator V6 raw output discriminator (2015)", precision=10),
114  rawAntiEleCat = Var("tauID('againstElectronMVA6category')", int, doc="Anti-electron MVA discriminator V6 category (2015"),
115  idAntiEle = _tauId5WPMask("againstElectron%sMVA6", doc= "Anti-electron MVA discriminator V6 (2015)"),
116 )
117 _deepTauVars2017v2p1 = cms.PSet(
118  rawDeepTau2017v2p1VSe = Var("tauID('byDeepTau2017v2p1VSeraw')", float, doc="byDeepTau2017v2p1VSe raw output discriminator (deepTau2017v2p1)", precision=10),
119  rawDeepTau2017v2p1VSmu = Var("tauID('byDeepTau2017v2p1VSmuraw')", float, doc="byDeepTau2017v2p1VSmu raw output discriminator (deepTau2017v2p1)", precision=10),
120  rawDeepTau2017v2p1VSjet = Var("tauID('byDeepTau2017v2p1VSjetraw')", float, doc="byDeepTau2017v2p1VSjet raw output discriminator (deepTau2017v2p1)", precision=10),
121  idDeepTau2017v2p1VSe = _tauId8WPMask("by%sDeepTau2017v2p1VSe", doc="byDeepTau2017v2p1VSe ID working points (deepTau2017v2p1)"),
122  idDeepTau2017v2p1VSmu = _tauId4WPMask("by%sDeepTau2017v2p1VSmu", doc="byDeepTau2017v2p1VSmu ID working points (deepTau2017v2p1)"),
123  idDeepTau2017v2p1VSjet = _tauId8WPMask("by%sDeepTau2017v2p1VSjet", doc="byDeepTau2017v2p1VSjet ID working points (deepTau2017v2p1)"),
124 )
125 
126 _variablesMiniV2 = cms.PSet(
127  _tauVarsBase,
128  _deepTauVars2017v2p1
129 )
130 _variablesMiniV1 = cms.PSet(
131  _variablesMiniV2,
132  _mvaIsoVars2017v2
133 )
134 _variablesMiniV1.rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10)
135 _variablesMiniV1.rawMVAoldDM2017v1 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2017v1')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v1)",precision=10)
136 _variablesMiniV1.idMVAoldDM = _tauId6WPMask( "by%sIsolationMVArun2v1DBoldDMwLT", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)")
137 _variablesMiniV1.idMVAoldDM2017v1 = _tauId7WPMask( "by%sIsolationMVArun2v1DBoldDMwLT2017v1", doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v1)")
138 _variables80X = cms.PSet(
139  _tauVarsBase,
140  _mvaAntiEVars2015,
141  _mvaIsoVars2015
142 )
143 
144 tauTable.variables = _variablesMiniV2
145 
146 (run2_nanoAOD_92X | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_94X2016 | run2_nanoAOD_102Xv1 | run2_nanoAOD_106Xv1).toModify(tauTable,
147  variables = cms.PSet(tauTable.variables, _mvaIsoVars2015Reduced, _mvaIsoVars2017v1, _mvaIsoVars2017v2)
148  )
149 for era in [run2_nanoAOD_94XMiniAODv1,]:
150  era.toModify(tauTable,
151  variables = _variablesMiniV1
152  )
153 run2_miniAOD_80XLegacy.toModify(tauTable,
154  variables = _variables80X
155 )
156 for era in [run2_nanoAOD_92X, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, \
157  run2_nanoAOD_94X2016, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1]:
158  era.toModify(tauTable.variables,
159  rawAntiEle2018 = Var("tauID('againstElectronMVA6Raw2018')", float, doc= "Anti-electron MVA discriminator V6 raw output discriminator (2018)", precision=10),
160  rawAntiEleCat2018 = Var("tauID('againstElectronMVA6category2018')", int, doc="Anti-electron MVA discriminator V6 category (2018)"),
161  idAntiEle2018 = _tauId5WPMask("againstElectron%sMVA62018", doc= "Anti-electron MVA discriminator V6 (2018)"),
162  rawAntiEle = Var("tauID('againstElectronMVA6Raw')", float, doc= "Anti-electron MVA discriminator V6 raw output discriminator (2015)", precision=10),
163  rawAntiEleCat = Var("tauID('againstElectronMVA6category')", int, doc="Anti-electron MVA discriminator V6 category (2015"),
164  idAntiEle = _tauId5WPMask("againstElectron%sMVA6", doc= "Anti-electron MVA discriminator V6 (2015)")
165  )
166 
167 for era in [run2_miniAOD_80XLegacy, run2_nanoAOD_92X, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, \
168  run2_nanoAOD_94X2016, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1]:
169  era.toModify(tauTable.variables,
170  idDecayMode = Var("tauID('decayModeFinding')", bool),
171  idDecayModeNewDMs = Var("tauID('decayModeFindingNewDMs')", bool),
172  idDecayModeOldDMs = None
173  )
174 run2_miniAOD_80XLegacy.toModify(tauTable.variables,
175  idAntiEleDeadECal = None)
176 for era in [run2_nanoAOD_92X, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, \
177  run2_nanoAOD_94X2016, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1]:
178  era.toModify(tauTable.variables,
179  idAntiEleDeadECal = Var("tauID('againstElectronDeadECALForNano')", bool, doc = "Anti-electron dead-ECal discriminator"),
180  )
181 
182 tauGenJetsForNano = tauGenJets.clone(
183  GenParticles = "finalGenParticles",
184  includeNeutrinos = False
185 )
186 
187 tauGenJetsSelectorAllHadronsForNano = tauGenJetsSelectorAllHadrons.clone(
188  src = "tauGenJetsForNano"
189 )
190 
191 genVisTaus = cms.EDProducer("GenVisTauProducer",
192  src = cms.InputTag("tauGenJetsSelectorAllHadronsForNano"),
193  srcGenParticles = cms.InputTag("finalGenParticles")
194 )
195 
196 genVisTauTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
197  src = cms.InputTag("genVisTaus"),
198  cut = cms.string("pt > 10."),
199  name = cms.string("GenVisTau"),
200  doc = cms.string("gen hadronic taus "),
201  singleton = cms.bool(False), # the number of entries is variable
202  extension = cms.bool(False), # this is the main table for generator level hadronic tau decays
203  variables = cms.PSet(
204  pt = Var("pt", float,precision=8),
205  phi = Var("phi", float,precision=8),
206  eta = Var("eta", float,precision=8),
207  mass = Var("mass", float,precision=8),
208  charge = Var("charge", int),
209  status = Var("status", int, doc="Hadronic tau decay mode. 0=OneProng0PiZero, 1=OneProng1PiZero, 2=OneProng2PiZero, 10=ThreeProng0PiZero, 11=ThreeProng1PiZero, 15=Other"),
210  genPartIdxMother = Var("?numberOfMothers>0?motherRef(0).key():-1", int, doc="index of the mother particle"),
211  )
212 )
213 
214 tausMCMatchLepTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
215  src = tauTable.src, # final reco collection
216  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
217  mcPdgId = cms.vint32(11,13), # one or more PDG ID (11 = electron, 13 = muon); absolute values (see below)
218  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
219  mcStatus = cms.vint32(), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
220  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
221  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
222  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
223  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
224 )
225 
226 tausMCMatchHadTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
227  src = tauTable.src, # final reco collection
228  matched = cms.InputTag("genVisTaus"), # generator level hadronic tau decays
229  mcPdgId = cms.vint32(15), # one or more PDG ID (15 = tau); absolute values (see below)
230  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
231  mcStatus = cms.vint32(), # CV: no *not* require certain status code for matching (status code corresponds to decay mode for hadronic tau decays)
232  maxDeltaR = cms.double(0.3), # Maximum deltaR for the match
233  maxDPtRel = cms.double(1.), # Maximum deltaPt/Pt for the match
234  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
235  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
236 )
237 
238 tauMCTable = cms.EDProducer("CandMCMatchTableProducer",
239  src = tauTable.src,
240  mcMap = cms.InputTag("tausMCMatchLepTauForTable"),
241  mcMapVisTau = cms.InputTag("tausMCMatchHadTauForTable"),
242  objName = tauTable.name,
243  objType = tauTable.name, #cms.string("Tau"),
244  branchName = cms.string("genPart"),
245  docString = cms.string("MC matching to status==2 taus"),
246 )
247 
248 
249 tauTask = cms.Task( patTauMVAIDsTask,finalTaus)
250 
251 run2_miniAOD_80XLegacy.toReplaceWith(tauTask, cms.Task(finalTaus))
252 
253 tauTablesTask = cms.Task(tauTable)
254 
255 genTauTask = cms.Task(tauGenJetsForNano,tauGenJetsSelectorAllHadronsForNano,genVisTaus,genVisTauTable)
256 tauMCTask = cms.Task(genTauTask,tausMCMatchLepTauForTable,tausMCMatchHadTauForTable,tauMCTable)
257 
def _tauId6WPMask
Definition: taus_cff.py:43
def _tauId8WPMask
Definition: taus_cff.py:47
def _tauId4WPMask
Definition: taus_cff.py:39
def _tauId3WPMask
Definition: taus_cff.py:37
def _tauId2WPMask
Definition: taus_cff.py:35
Updated tau collection with MVA-based tau-Ids rerun ####### Used only in some eras.
def _tauId7WPMask
Definition: taus_cff.py:45
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def _tauIdWPMask
Tables for final output and docs ##########################.
Definition: taus_cff.py:32
def _tauId5WPMask
Definition: taus_cff.py:41
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29