10 oldPFTauLabel = cms.InputTag(
'shrinkingConePFTauProducer'),
11 newPFTauLabel = cms.InputTag(
'shrinkingConePFTauProducer'),
12 tauType =
'shrinkingConePFTau', postfix =
""):
13 print 'Tau discriminators: ', oldPFTauLabel,
'->', newPFTauLabel
14 print 'Tau type: ', tauType
16 tauSrc =
'PFTauProducer'
18 tauDiscriminationSequence =
None
20 if tauType ==
'hpsPFTau':
21 process.patHPSPFTauDiscrimination = process.produceAndDiscriminateHPSPFTaus.copy()
23 for iname
in process.patHPSPFTauDiscrimination.moduleNames():
24 if not (iname.find(
"DiscriminationBy")>-1
or iname.find(
"DiscriminationAgainst")>-1):
25 process.patHPSPFTauDiscrimination.remove(getattr(process,iname) )
28 elif tauType ==
'hpsTancTaus':
29 process.patHPSTaNCPFTauDiscrimination = process.hpsTancTauInitialSequence.copy()
30 process.patHPSTaNCPFTauDiscrimination *= process.hpsTancTauDiscriminantSequence
32 for iname
in process.patHPSTaNCPFTauDiscrimination.moduleNames():
33 if not (iname.find(
"DiscriminationBy")>-1
or iname.find(
"DiscriminationAgainst")>-1):
34 process.patHPSTaNCPFTauDiscrimination.remove(getattr(process,iname) )
35 tauDiscriminationSequence =
cloneProcessingSnippet(process, process.patHPSTaNCPFTauDiscrimination, postfix)
37 elif tauType ==
'fixedConePFTau':
38 process.patFixedConePFTauDiscrimination = process.produceAndDiscriminateFixedConePFTaus.copy()
40 for iname
in process.patFixedConePFTauDiscrimination.moduleNames():
41 if not (iname.find(
"DiscriminationBy")>-1
or iname.find(
"DiscriminationAgainst")>-1):
42 process.patFixedConePFTauDiscrimination.remove(getattr(process,iname) )
43 tauDiscriminationSequence =
cloneProcessingSnippet(process, process.patFixedConePFTauDiscrimination, postfix)
45 elif tauType ==
'shrinkingConePFTau':
46 process.patShrinkingConePFTauDiscrimination = process.produceAndDiscriminateShrinkingConePFTaus.copy()
47 process.patShrinkingConePFTauDiscrimination *= process.produceShrinkingConeDiscriminationByTauNeuralClassifier
49 for iname
in process.patShrinkingConePFTauDiscrimination.moduleNames():
50 if not (iname.find(
"DiscriminationBy")>-1
or iname.find(
"DiscriminationAgainst")>-1):
51 process.patShrinkingConePFTauDiscrimination.remove(getattr(process,iname) )
52 tauDiscriminationSequence =
cloneProcessingSnippet(process, process.patShrinkingConePFTauDiscrimination, postfix)
54 elif tauType ==
'caloTau':
56 process.patCaloTauDiscrimination = process.tautagging.copy()
58 for iname
in process.patCaloTauDiscrimination.moduleNames():
59 if not (iname.find(
"DiscriminationBy")>-1
or iname.find(
"DiscriminationAgainst")>-1):
60 process.patCaloTauDiscrimination.remove(getattr(process,iname) )
62 tauSrc =
'CaloTauProducer'
64 raise StandardError,
"Unkown tauType: '%s'"%tauType
68 tauDiscriminationSequence*
applyPostfix(process,
"patTaus",postfix)
75 pfTauLabelOld = cms.InputTag(
'shrinkingConePFTauProducer'),
76 pfTauLabelNew = cms.InputTag(
'caloRecoTauProducer'),
79 print ' Taus: ', pfTauLabelOld,
'->', pfTauLabelNew
81 caloTauLabel = pfTauLabelNew
82 applyPostfix(process,
"tauMatch" + patTauLabel, postfix).src = caloTauLabel
83 applyPostfix(process,
"tauGenJetMatch"+ patTauLabel, postfix).src = caloTauLabel
85 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauSource = caloTauLabel
97 print "NO PF Isolation will be computed for CaloTau (this could be improved later)"
98 applyPostfix(process,
"patTaus" + patTauLabel, postfix).isolation = cms.PSet()
99 applyPostfix(process,
"patTaus" + patTauLabel, postfix).isoDeposits = cms.PSet()
100 applyPostfix(process,
"patTaus" + patTauLabel, postfix).userIsolation = cms.PSet()
103 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
104 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = \
105 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingTrackPtCut") > 0.5' \
106 +
' & tauID("byIsolation") > 0.5 & tauID("againstElectron") > 0.5 & (signalTracks.size() = 1 | signalTracks.size() = 3)'
109 """ Build a PSet defining the tau ID sources to embed into the pat::Tau """
111 for label, discriminator
in idSources:
112 setattr(output, label, cms.InputTag(pfTauType + discriminator + postfix))
122 """internal auxiliary function to switch to **any** PFTau collection"""
123 print ' Taus: ', pfTauLabelOld,
'->', pfTauLabelNew
125 applyPostfix(process,
"tauMatch" + patTauLabel, postfix).src = pfTauLabelNew
126 applyPostfix(process,
"tauGenJetMatch" + patTauLabel, postfix).src = pfTauLabelNew
128 applyPostfix(process,
"tauIsoDepositPFCandidates" + patTauLabel, postfix).src = pfTauLabelNew
129 applyPostfix(process,
"tauIsoDepositPFCandidates" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
130 applyPostfix(process,
"tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).src = pfTauLabelNew
131 applyPostfix(process,
"tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
132 applyPostfix(process,
"tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).src = pfTauLabelNew
133 applyPostfix(process,
"tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
134 applyPostfix(process,
"tauIsoDepositPFGammas" + patTauLabel, postfix).src = pfTauLabelNew
135 applyPostfix(process,
"tauIsoDepositPFGammas" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
137 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauSource = pfTauLabelNew
140 applyPostfix(process,
"cleanPatTaus" + patTauLabel, postfix).preselection = \
141 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingPionPtCut") > 0.5 & tauID("byIsolationUsingLeadingPion") > 0.5' \
142 +
' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5' \
143 +
' & (signalPFChargedHadrCands.size() = 1 | signalPFChargedHadrCands.size() = 3)'
146 classicTauIDSources = [
147 (
"leadingTrackFinding",
"DiscriminationByLeadingTrackFinding"),
148 (
"leadingTrackPtCut",
"DiscriminationByLeadingTrackPtCut"),
149 (
"trackIsolation",
"DiscriminationByTrackIsolation"),
150 (
"ecalIsolation",
"DiscriminationByECALIsolation"),
151 (
"byIsolation",
"DiscriminationByIsolation"),
152 (
"againstElectron",
"DiscriminationAgainstElectron"),
153 (
"againstMuon",
"DiscriminationAgainstMuon") ]
155 classicPFTauIDSources = [
156 (
"leadingPionPtCut",
"DiscriminationByLeadingPionPtCut"),
157 (
"trackIsolationUsingLeadingPion",
"DiscriminationByTrackIsolationUsingLeadingPion"),
158 (
"ecalIsolationUsingLeadingPion",
"DiscriminationByECALIsolationUsingLeadingPion"),
159 (
"byIsolationUsingLeadingPion",
"DiscriminationByIsolationUsingLeadingPion")]
163 (
"byTaNC",
"DiscriminationByTaNC"),
164 (
"byTaNCfrOnePercent",
"DiscriminationByTaNCfrOnePercent"),
165 (
"byTaNCfrHalfPercent",
"DiscriminationByTaNCfrHalfPercent"),
166 (
"byTaNCfrQuarterPercent",
"DiscriminationByTaNCfrQuarterPercent"),
167 (
"byTaNCfrTenthPercent",
"DiscriminationByTaNCfrTenthPercent") ]
171 (
"leadingTrackFinding",
"DiscriminationByDecayModeFinding"),
172 (
"byLooseIsolation",
"DiscriminationByLooseIsolation"),
173 (
"byMediumIsolation",
"DiscriminationByMediumIsolation"),
174 (
"byTightIsolation",
"DiscriminationByTightIsolation"),
175 (
"againstElectron",
"DiscriminationAgainstElectron"),
176 (
"againstMuon",
"DiscriminationAgainstMuon")]
179 hpsTancTauIDSources = [
180 (
"leadingTrackFinding",
"DiscriminationByLeadingTrackFinding"),
181 (
"leadingTrackPtCut",
"DiscriminationByLeadingTrackPtCut"),
182 (
"leadingPionPtCut",
"DiscriminationByLeadingPionPtCut"),
183 (
"byTaNCraw",
"DiscriminationByTancRaw"),
184 (
"byTaNC",
"DiscriminationByTanc"),
185 (
"byTaNCvloose",
"DiscriminationByTancVLoose"),
186 (
"byTaNCloose",
"DiscriminationByTancLoose"),
187 (
"byTaNCmedium",
"DiscriminationByTancMedium"),
188 (
"byTaNCtight",
"DiscriminationByTancTight"),
189 (
"byDecayMode",
"DiscriminationByDecayModeSelection"),
190 (
"byHPSvloose",
"DiscriminationByVLooseIsolation"),
191 (
"byHPSloose",
"DiscriminationByLooseIsolation"),
192 (
"byHPSmedium",
"DiscriminationByMediumIsolation"),
193 (
"byHPStight",
"DiscriminationByTightIsolation"),
194 (
"againstElectron",
"DiscriminationAgainstElectron"),
195 (
"againstMuon",
"DiscriminationAgainstMuon"),
196 (
"againstCaloMuon",
"DiscriminationAgainstCaloMuon") ]
200 pfTauLabelOld = cms.InputTag(
'shrinkingConePFTauProducer'),
201 pfTauLabelNew = cms.InputTag(
'fixedConePFTauProducer'),
204 fixedConeIDSources = copy.copy(classicTauIDSources)
205 fixedConeIDSources.extend(classicPFTauIDSources)
207 _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew,
'fixedConePFTau', fixedConeIDSources,
208 patTauLabel = patTauLabel, postfix = postfix)
212 pfTauLabelOld = cms.InputTag(
'shrinkingConePFTauProducer'),
213 pfTauLabelNew = cms.InputTag(
'shrinkingConePFTauProducer'),
216 shrinkingIDSources = copy.copy(classicTauIDSources)
217 shrinkingIDSources.extend(classicPFTauIDSources)
219 shrinkingIDSources.extend(tancTauIDSources)
221 _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew,
'shrinkingConePFTau', shrinkingIDSources,
222 patTauLabel = patTauLabel, postfix = postfix)
226 pfTauLabelOld = cms.InputTag(
'shrinkingConePFTauProducer'),
227 pfTauLabelNew = cms.InputTag(
'hpsPFTauProducer'),
230 _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew,
'hpsPFTau', hpsTauIDSources,
231 patTauLabel = patTauLabel, postfix = postfix)
234 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
235 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = \
236 'pt > 15 & abs(eta) < 2.3 & tauID("leadingTrackFinding") > 0.5 & tauID("byLooseIsolation") > 0.5' \
237 +
' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5'
241 pfTauLabelOld = cms.InputTag(
'shrinkingConePFTauProducer'),
242 pfTauLabelNew = cms.InputTag(
'hpsTancTaus'),
245 _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew,
'hpsTancTaus', hpsTancTauIDSources,
246 patTauLabel = patTauLabel, postfix = postfix)
249 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
250 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = \
251 'pt > 15 & abs(eta) < 2.3 & tauID("leadingPionPtCut") > 0.5 & tauID("byHPSloose") > 0.5' \
252 +
' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5'
257 pfTauLabelNew =
None,
258 pfTauLabelOld = cms.InputTag(
'shrinkingConePFTauProducer'),
261 mapping = {
'shrinkingConePFTau' : switchToPFTauShrinkingCone,
262 'fixedConePFTau' : switchToPFTauFixedCone,
263 'hpsPFTau' : switchToPFTauHPS,
264 'caloRecoTau' : switchToCaloTau,
265 'hpsTancPFTau' : switchToPFTauHPSpTaNC }
266 mapping[pfTauType](process, pfTauLabelOld = pfTauLabelOld, pfTauLabelNew = pfTauLabelNew,
267 patTauLabel = patTauLabel, postfix = postfix)
272 process.cleanPatTaus.preselection = cms.string(
'tauID("byIsolation") > 0')
276 """ Add a new collection of taus. Takes the configuration from the
277 already configured standard tau collection as starting point;
278 replaces before calling addTauCollection will also affect the
281 _label=
'addTauCollection'
282 _defaultParameters=dicttypes.SortedKeysDict()
284 ConfigToolBase.__init__(self)
286 self._defaultValue,
'Input tau collection', cms.InputTag)
288 self._defaultValue,
"label to indicate the tau algorithm (e.g.'shrinkingCone')", str)
290 self._defaultValue,
"label to indicate the type of constituents (either 'PFTau' or 'Tau')", str)
292 True,
"run sequence for computing particle-flow based IsoDeposits")
294 "shrinkingCone",
"standard algorithm label of the collection from which the clones " \
295 +
"for the new tau collection will be taken from " \
296 +
"(note that this tau collection has to be available in the event before hand)")
298 "PFTau",
"standard constituent type label of the collection from which the clones " \
299 +
" for the new tau collection will be taken from "\
300 +
"(note that this tau collection has to be available in the event before hand)")
309 tauCollection =
None,
312 doPFIsoDeposits =
None,
314 standardType =
None):
316 if tauCollection
is None:
318 if algoLabel
is None:
320 if typeLabel
is None:
322 if doPFIsoDeposits
is None:
324 if standardAlgo
is None:
326 if standardType
is None:
329 self.setParameter(
'tauCollection', tauCollection)
330 self.setParameter(
'algoLabel', algoLabel)
331 self.setParameter(
'typeLabel', typeLabel)
332 self.setParameter(
'doPFIsoDeposits', doPFIsoDeposits)
333 self.setParameter(
'standardAlgo', standardAlgo)
334 self.setParameter(
'standardType', standardType)
339 tauCollection = self.
_parameters[
'tauCollection'].value
342 doPFIsoDeposits = self.
_parameters[
'doPFIsoDeposits'].value
343 standardAlgo = self.
_parameters[
'standardAlgo'].value
344 standardType = self.
_parameters[
'standardType'].value
348 if typeLabel ==
'Tau':
350 doPFIsoDeposits =
False
354 def oldLabel(prefix = ''):
358 return prefix +
"PatTaus"
363 def capitalize(label):
364 return label[0].capitalize() + label[1:]
368 def newLabel(oldLabel):
370 if ( oldLabel.find(standardAlgo) >= 0
and oldLabel.find(standardType) >= 0 ):
371 oldLabel = oldLabel.replace(standardAlgo, algoLabel).
replace(standardType, typeLabel)
373 oldLabel = oldLabel + capitalize(algoLabel + typeLabel)
377 def addClone(hook, **replaceStatements):
380 newModule = getattr(process, hook).
clone(**replaceStatements)
382 addModuleToSequence(hook, newModule)
385 def addPFIsoDepositClone(hook, **replaceStatements):
386 newModule = getattr(process, hook).
clone(**replaceStatements)
387 newModuleIsoDepositExtractor = getattr(newModule,
"ExtractorPSet")
388 setattr(newModuleIsoDepositExtractor,
"tauSource", getattr(newModule,
"src"))
389 addModuleToSequence(hook, newModule)
392 def addModuleToSequence(hook, newModule):
393 hookModule = getattr(process, hook)
396 setattr(process, newLabel(hook), newModule)
399 process.patDefaultSequence.replace( hookModule, hookModule*newModule )
402 addClone(oldLabel(), tauSource = tauCollection)
405 addClone(oldLabel(
'selected'), src = cms.InputTag(newLabel(oldLabel())))
408 addClone(oldLabel(
'clean'), src=cms.InputTag(newLabel(oldLabel(
'selected'))))
411 newTaus = getattr(process, newLabel(oldLabel()))
414 addClone(
'tauMatch', src = tauCollection)
415 addClone(
'tauGenJetMatch', src = tauCollection)
419 addPFIsoDepositClone(
'tauIsoDepositPFCandidates', src = tauCollection)
420 addPFIsoDepositClone(
'tauIsoDepositPFChargedHadrons', src = tauCollection)
421 addPFIsoDepositClone(
'tauIsoDepositPFNeutralHadrons', src = tauCollection)
422 addPFIsoDepositClone(
'tauIsoDepositPFGammas', src = tauCollection)
425 def fixInputTag(x): x.setModuleLabel(newLabel(x.moduleLabel))
428 fixInputTag(newTaus.genParticleMatch)
429 fixInputTag(newTaus.genJetMatch)
430 fixInputTag(newTaus.isoDeposits.pfAllParticles)
431 fixInputTag(newTaus.isoDeposits.pfNeutralHadron)
432 fixInputTag(newTaus.isoDeposits.pfChargedHadron)
433 fixInputTag(newTaus.isoDeposits.pfGamma)
434 fixInputTag(newTaus.userIsolation.pfAllParticles.src)
435 fixInputTag(newTaus.userIsolation.pfNeutralHadron.src)
436 fixInputTag(newTaus.userIsolation.pfChargedHadron.src)
437 fixInputTag(newTaus.userIsolation.pfGamma.src)
441 oldTaus = getattr(process, oldLabel())
449 pfTauLabelNew = getattr(newTaus,
"tauSource"),
450 pfTauLabelOld = getattr(oldTaus,
"tauSource"),
451 patTauLabel = capitalize(algoLabel + typeLabel))
def cloneProcessingSnippet
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
def massSearchReplaceParam