CMS 3D CMS Logo

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