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