CMS 3D CMS Logo

taus_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
3 from PhysicsTools.NanoAOD.common_cff import Var,P4Vars
4 from PhysicsTools.JetMCAlgos.TauGenJets_cfi import tauGenJets
5 from PhysicsTools.JetMCAlgos.TauGenJetsDecayModeSelectorAllHadrons_cfi import tauGenJetsSelectorAllHadrons
6 
7 
10 
11 
12 
13 # Original DeepTau v2p5 in 12_4_X doesn't include WPs in MINIAOD
14 # Import thresholds here to define WPs manually from raw scores
15 from RecoTauTag.RecoTau.tauIdWPsDefs import WORKING_POINTS_v2p5
16 
17 finalTaus = cms.EDFilter("PATTauRefSelector",
18  src = cms.InputTag("slimmedTaus"),
19  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || (tauID('chargedIsoPtSumdR03')+max(0.,tauID('neutralIsoPtSumdR03')-0.072*tauID('puCorrPtSum'))<2.5) || tauID('byVVVLooseDeepTau2017v2p1VSjet') || tauID('byVVVLooseDeepTau2018v2p5VSjet'))")
20 )
21 
22 run3_nanoAOD_124.toModify(finalTaus,
23  cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || (tauID('chargedIsoPtSumdR03')+max(0.,tauID('neutralIsoPtSumdR03')-0.072*tauID('puCorrPtSum'))<2.5) || tauID('byVVVLooseDeepTau2017v2p1VSjet') || (tauID('byDeepTau2018v2p5VSjetraw') > {}))".format(WORKING_POINTS_v2p5["jet"]["VVVLoose"]))
24  )
25 
26 
27 def _tauIdWPMask(pattern, choices, doc="", from_raw=False, wp_thrs=None):
28  if from_raw:
29  assert wp_thrs is not None, "wp_thrs argument in _tauIdWPMask() is None, expect it to be dict-like"
30 
31  var_definition = []
32  for wp_name in choices:
33  if not isinstance(wp_thrs[wp_name], float):
34  raise TypeError("Threshold for WP=%s is not a float number." % wp_name)
35  wp_definition = "test_bit(tauID('{}')-{}+1,0)".format(pattern, wp_thrs[wp_name])
36  var_definition.append(wp_definition)
37  var_definition = " + ".join(var_definition)
38  else:
39  var_definition = " + ".join(["tauID('%s')" % (pattern % c) for c in choices])
40 
41  doc = doc + ": "+", ".join(["%d = %s" % (i,c) for (i,c) in enumerate(choices, start=1)])
42  return Var(var_definition, "uint8", doc=doc)
43 
44 tauTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
45  src = cms.InputTag("linkedObjects","taus"),
46  cut = cms.string(""), #we should not filter on cross linked collections
47  name= cms.string("Tau"),
48  doc = cms.string("slimmedTaus after basic selection (" + finalTaus.cut.value()+")"),
49  singleton = cms.bool(False), # the number of entries is variable
50  extension = cms.bool(False), # this is the main table for the taus
51  variables = cms.PSet() # PSet defined below in era dependent way
52 )
53 _tauVarsBase = cms.PSet(P4Vars,
54  charge = Var("charge", int, doc="electric charge"),
55  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
56  decayMode = Var("decayMode()",int),
57  idDecayModeOldDMs = Var("tauID('decayModeFinding')", bool),
58 
59  leadTkPtOverTauPt = Var("leadChargedHadrCand.pt/pt ",float, doc="pt of the leading track divided by tau pt",precision=10),
60  leadTkDeltaEta = Var("leadChargedHadrCand.eta - eta ",float, doc="eta of the leading track, minus tau eta",precision=8),
61  leadTkDeltaPhi = Var("deltaPhi(leadChargedHadrCand.phi, phi) ",float, doc="phi of the leading track, minus tau phi",precision=8),
62 
63  dxy = Var("leadChargedHadrCand().dxy()",float, doc="d_{xy} of lead track with respect to PV, in cm (with sign)",precision=10),
64  dz = Var("leadChargedHadrCand().dz()",float, doc="d_{z} of lead track with respect to PV, in cm (with sign)",precision=14),
65 
66  # these are too many, we may have to suppress some
67  rawIso = Var( "tauID('byCombinedIsolationDeltaBetaCorrRaw3Hits')", float, doc = "combined isolation (deltaBeta corrections)", precision=10),
68  rawIsodR03 = Var( "(tauID('chargedIsoPtSumdR03')+max(0.,tauID('neutralIsoPtSumdR03')-0.072*tauID('puCorrPtSum')))", float, doc = "combined isolation (deltaBeta corrections, dR=0.3)", precision=10),
69  chargedIso = Var( "tauID('chargedIsoPtSum')", float, doc = "charged isolation", precision=10),
70  neutralIso = Var( "tauID('neutralIsoPtSum')", float, doc = "neutral (photon) isolation", precision=10),
71  puCorr = Var( "tauID('puCorrPtSum')", float, doc = "pileup correction", precision=10),
72  photonsOutsideSignalCone = Var( "tauID('photonPtSumOutsideSignalCone')", float, doc = "sum of photons outside signal cone", precision=10),
73 
74  idAntiMu = _tauIdWPMask("againstMuon%s3", choices=("Loose","Tight"), doc= "Anti-muon discriminator V3: "),
75  idAntiEleDeadECal = Var("tauID('againstElectronDeadECAL')", bool, doc = "Anti-electron dead-ECal discriminator"),
76 
77 # isoCI3hit = Var( "tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits")" doc="byCombinedIsolationDeltaBetaCorrRaw3Hits raw output discriminator"),
78 # photonOutsideSigCone = Var( "tauID("photonPtSumOutsideSignalCone")" doc="photonPtSumOutsideSignalCone raw output discriminator"),
79 
80 )
81 
82 _mvaIsoVars2015 = cms.PSet(
83  rawMVAnewDM = Var( "tauID('byIsolationMVArun2v1DBnewDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
84  rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
85  rawMVAoldDMdR03 = Var( "tauID('byIsolationMVArun2v1DBdR03oldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
86  idMVAnewDM = _tauIdWPMask( "by%sIsolationMVArun2v1DBnewDMwLT", choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"), doc="IsolationMVArun2v1DBnewDMwLT ID working point (2015)"),
87  idMVAoldDM = _tauIdWPMask( "by%sIsolationMVArun2v1DBoldDMwLT", choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"), doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)"),
88  idMVAoldDMdR03 = _tauIdWPMask( "by%sIsolationMVArun2v1DBdR03oldDMwLT", choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"), doc="IsolationMVArun2v1DBoldDMdR0p3wLT ID working point (2015)")
89 )
90 _mvaIsoVars2015Reduced = cms.PSet(
91  rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2015')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10),
92  idMVAoldDM = _tauIdWPMask( "by%sIsolationMVArun2v1DBoldDMwLT2015", choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"), doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)"),
93 )
94 _mvaIsoVars2017v1 = cms.PSet(
95  rawMVAoldDM2017v1 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v1)",precision=10),
96  idMVAoldDM2017v1 = _tauIdWPMask( "by%sIsolationMVArun2v1DBoldDMwLT", choices=("VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"), doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v1)")
97 )
98 _mvaIsoVars2017v2 = cms.PSet(
99  rawMVAnewDM2017v2 = Var( "tauID('byIsolationMVArun2v1DBnewDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBnewDMwLT raw output discriminator (2017v2)",precision=10),
100  rawMVAoldDM2017v2 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v2)",precision=10),
101  rawMVAoldDMdR032017v2 = Var( "tauID('byIsolationMVArun2v1DBdR03oldDMwLTraw2017v2')",float, doc="byIsolationMVArun2v1DBdR03oldDMwLT raw output discriminator (2017v2)",precision=10),
102  idMVAnewDM2017v2 = _tauIdWPMask( "by%sIsolationMVArun2v1DBnewDMwLT2017v2",
103  choices=("VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
104  doc="IsolationMVArun2v1DBnewDMwLT ID working point (2017v2)"),
105  idMVAoldDM2017v2 = _tauIdWPMask( "by%sIsolationMVArun2v1DBoldDMwLT2017v2",
106  choices=("VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
107  doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v2)"),
108  idMVAoldDMdR032017v2 = _tauIdWPMask( "by%sIsolationMVArun2v1DBdR03oldDMwLT2017v2",
109  choices=("VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
110  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 = _tauIdWPMask("againstElectron%sMVA6", choices=("VLoose","Loose","Medium","Tight","VTight"), 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 = _tauIdWPMask("by%sDeepTau2017v2p1VSe",
122  choices=("VVVLoose","VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
123  doc="byDeepTau2017v2p1VSe ID working points (deepTau2017v2p1)"),
124  idDeepTau2017v2p1VSmu = _tauIdWPMask("by%sDeepTau2017v2p1VSmu",
125  choices=("VLoose", "Loose", "Medium", "Tight"),
126  doc="byDeepTau2017v2p1VSmu ID working points (deepTau2017v2p1)"),
127  idDeepTau2017v2p1VSjet = _tauIdWPMask("by%sDeepTau2017v2p1VSjet",
128  choices=("VVVLoose","VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
129  doc="byDeepTau2017v2p1VSjet ID working points (deepTau2017v2p1)"),
130 )
131 _deepTauVars2018v2p5 = cms.PSet(
132  rawDeepTau2018v2p5VSe = Var("tauID('byDeepTau2018v2p5VSeraw')", float, doc="byDeepTau2018v2p5VSe raw output discriminator (deepTau2018v2p5)", precision=10),
133  rawDeepTau2018v2p5VSmu = Var("tauID('byDeepTau2018v2p5VSmuraw')", float, doc="byDeepTau2018v2p5VSmu raw output discriminator (deepTau2018v2p5)", precision=10),
134  rawDeepTau2018v2p5VSjet = Var("tauID('byDeepTau2018v2p5VSjetraw')", float, doc="byDeepTau2018v2p5VSjet raw output discriminator (deepTau2018v2p5)", precision=10),
135  idDeepTau2018v2p5VSe = _tauIdWPMask("by%sDeepTau2018v2p5VSe",
136  choices=("VVVLoose","VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
137  doc="byDeepTau2018v2p5VSe ID working points (deepTau2018v2p5)"),
138  idDeepTau2018v2p5VSmu = _tauIdWPMask("by%sDeepTau2018v2p5VSmu",
139  choices=("VLoose", "Loose", "Medium", "Tight"),
140  doc="byDeepTau2018v2p5VSmu ID working points (deepTau2018v2p5)"),
141  idDeepTau2018v2p5VSjet = _tauIdWPMask("by%sDeepTau2018v2p5VSjet",
142  choices=("VVVLoose","VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
143  doc="byDeepTau2018v2p5VSjet ID working points (deepTau2018v2p5)"),
144 )
145 
146 _variablesMiniV2 = cms.PSet(
147  _tauVarsBase,
148  _deepTauVars2017v2p1,
149  _deepTauVars2018v2p5
150 )
151 _variablesMiniV1 = cms.PSet(
152  _variablesMiniV2,
153  _mvaIsoVars2017v2
154 )
155 _variablesMiniV1.rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10)
156 _variablesMiniV1.rawMVAoldDM2017v1 = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw2017v1')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2017v1)",precision=10)
157 _variablesMiniV1.idMVAoldDM = _tauIdWPMask( "by%sIsolationMVArun2v1DBoldDMwLT",
158  choices=("VLoose","Loose","Medium","Tight","VTight","VVTight"),
159  doc="IsolationMVArun2v1DBoldDMwLT ID working point (2015)")
160 _variablesMiniV1.idMVAoldDM2017v1 = _tauIdWPMask( "by%sIsolationMVArun2v1DBoldDMwLT2017v1",
161  choices=("VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
162  doc="IsolationMVArun2v1DBoldDMwLT ID working point (2017v1)")
163 _variables80X = cms.PSet(
164  _tauVarsBase,
165  _mvaAntiEVars2015,
166  _mvaIsoVars2015
167 )
168 
169 tauTable.variables = _variablesMiniV2
170 
171 
172 run3_nanoAOD_124.toModify(
173  tauTable.variables,
174  idDeepTau2018v2p5VSe = _tauIdWPMask("byDeepTau2018v2p5VSeraw",
175  choices=("VVVLoose","VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
176  doc="byDeepTau2018v2p5VSe ID working points (deepTau2018v2p5)",
177  from_raw=True, wp_thrs=WORKING_POINTS_v2p5["e"]),
178  idDeepTau2018v2p5VSmu = _tauIdWPMask("byDeepTau2018v2p5VSmuraw",
179  choices=("VLoose", "Loose", "Medium", "Tight"),
180  doc="byDeepTau2018v2p5VSmu ID working points (deepTau2018v2p5)",
181  from_raw=True, wp_thrs=WORKING_POINTS_v2p5["mu"]),
182  idDeepTau2018v2p5VSjet = _tauIdWPMask("byDeepTau2018v2p5VSjetraw",
183  choices=("VVVLoose","VVLoose","VLoose","Loose","Medium","Tight","VTight","VVTight"),
184  doc="byDeepTau2018v2p5VSjet ID working points (deepTau2018v2p5)",
185  from_raw=True, wp_thrs=WORKING_POINTS_v2p5["jet"])
186 )
187 
188 
189 tauGenJetsForNano = tauGenJets.clone(
190  GenParticles = "finalGenParticles",
191  includeNeutrinos = False
192 )
193 
194 tauGenJetsSelectorAllHadronsForNano = tauGenJetsSelectorAllHadrons.clone(
195  src = "tauGenJetsForNano"
196 )
197 
198 genVisTaus = cms.EDProducer("GenVisTauProducer",
199  src = cms.InputTag("tauGenJetsSelectorAllHadronsForNano"),
200  srcGenParticles = cms.InputTag("finalGenParticles")
201 )
202 
203 genVisTauTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
204  src = cms.InputTag("genVisTaus"),
205  cut = cms.string("pt > 10."),
206  name = cms.string("GenVisTau"),
207  doc = cms.string("gen hadronic taus "),
208  singleton = cms.bool(False), # the number of entries is variable
209  extension = cms.bool(False), # this is the main table for generator level hadronic tau decays
210  variables = cms.PSet(
211  pt = Var("pt", float,precision=8),
212  phi = Var("phi", float,precision=8),
213  eta = Var("eta", float,precision=8),
214  mass = Var("mass", float,precision=8),
215  charge = Var("charge", int),
216  status = Var("status", int, doc="Hadronic tau decay mode. 0=OneProng0PiZero, 1=OneProng1PiZero, 2=OneProng2PiZero, 10=ThreeProng0PiZero, 11=ThreeProng1PiZero, 15=Other"),
217  genPartIdxMother = Var("?numberOfMothers>0?motherRef(0).key():-1", int, doc="index of the mother particle"),
218  )
219 )
220 
221 tausMCMatchLepTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
222  src = tauTable.src, # final reco collection
223  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
224  mcPdgId = cms.vint32(11,13), # one or more PDG ID (11 = electron, 13 = muon); absolute values (see below)
225  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
226  mcStatus = cms.vint32(), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
227  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
228  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
229  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
230  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
231 )
232 
233 tausMCMatchHadTauForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
234  src = tauTable.src, # final reco collection
235  matched = cms.InputTag("genVisTaus"), # generator level hadronic tau decays
236  mcPdgId = cms.vint32(15), # one or more PDG ID (15 = tau); absolute values (see below)
237  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
238  mcStatus = cms.vint32(), # CV: no *not* require certain status code for matching (status code corresponds to decay mode for hadronic tau decays)
239  maxDeltaR = cms.double(0.3), # Maximum deltaR for the match
240  maxDPtRel = cms.double(1.), # Maximum deltaPt/Pt for the match
241  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
242  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
243 )
244 
245 tauMCTable = cms.EDProducer("CandMCMatchTableProducer",
246  src = tauTable.src,
247  mcMap = cms.InputTag("tausMCMatchLepTauForTable"),
248  mcMapVisTau = cms.InputTag("tausMCMatchHadTauForTable"),
249  objName = tauTable.name,
250  objType = tauTable.name, #cms.string("Tau"),
251  branchName = cms.string("genPart"),
252  docString = cms.string("MC matching to status==2 taus"),
253 )
254 
255 
256 tauTask = cms.Task(finalTaus)
257 tauTablesTask = cms.Task(tauTable)
258 
259 genTauTask = cms.Task(tauGenJetsForNano,tauGenJetsSelectorAllHadronsForNano,genVisTaus,genVisTauTable)
260 tauMCTask = cms.Task(genTauTask,tausMCMatchLepTauForTable,tausMCMatchHadTauForTable,tauMCTable)
261 
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
def _tauIdWPMask(pattern, choices, doc="", from_raw=False, wp_thrs=None)
Tables for final output and docs ##########################.
Definition: taus_cff.py:30
Updated tau collection with MVA-based tau-Ids rerun ####### Used only in some eras.
static std::string join(char **cmd)
Definition: RemoteFile.cc:19