10 if hasattr(process, label+postfix):
11 result = getattr(process, label + postfix)
13 raise ValueError(
"Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
18 tauSource = cms.InputTag(
'caloRecoTauProducer'),
21 print ' switching PAT Tau input to: ', tauSource
23 applyPostfix(process,
"tauMatch" + patTauLabel, postfix).src = tauSource
24 applyPostfix(process,
"tauGenJetMatch"+ patTauLabel, postfix).src = tauSource
26 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauSource = tauSource
28 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource =
""
32 print "NO PF Isolation will be computed for CaloTau (this could be improved later)"
33 applyPostfix(process,
"patTaus" + patTauLabel, postfix).isolation = cms.PSet()
34 applyPostfix(process,
"patTaus" + patTauLabel, postfix).isoDeposits = cms.PSet()
35 applyPostfix(process,
"patTaus" + patTauLabel, postfix).userIsolation = cms.PSet()
38 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
39 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = \
40 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingTrackPtCut") > 0.5' \
41 +
' & tauID("byIsolation") > 0.5 & tauID("againstElectron") > 0.5 & (signalTracks.size() = 1 | signalTracks.size() = 3)'
44 """ Build a PSet defining the tau ID sources to embed into the pat::Tau """
46 for label, discriminator
in idSources:
47 if ":" in discriminator:
48 discr = discriminator.split(
":")
49 setattr(output, label, cms.InputTag(tauType + discr[0] + postfix +
":" + discr[1]))
51 setattr(output, label, cms.InputTag(tauType + discriminator + postfix))
60 """internal auxiliary function to switch to **any** PFTau collection"""
61 print ' switching PAT Tau input to: ', tauSource
63 applyPostfix(process,
"tauMatch" + patTauLabel, postfix).src = tauSource
64 applyPostfix(process,
"tauGenJetMatch" + patTauLabel, postfix).src = tauSource
66 applyPostfix(process,
"tauIsoDepositPFCandidates" + patTauLabel, postfix).src = tauSource
67 applyPostfix(process,
"tauIsoDepositPFCandidates" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
68 applyPostfix(process,
"tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).src = tauSource
69 applyPostfix(process,
"tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
70 applyPostfix(process,
"tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).src = tauSource
71 applyPostfix(process,
"tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
72 applyPostfix(process,
"tauIsoDepositPFGammas" + patTauLabel, postfix).src = tauSource
73 applyPostfix(process,
"tauIsoDepositPFGammas" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
75 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauSource = tauSource
77 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource =
""
80 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
81 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = \
82 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingPionPtCut") > 0.5 & tauID("byIsolationUsingLeadingPion") > 0.5' \
83 +
' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5' \
84 +
' & (signalPFChargedHadrCands.size() = 1 | signalPFChargedHadrCands.size() = 3)'
87 classicTauIDSources = [
88 (
"leadingTrackFinding",
"DiscriminationByLeadingTrackFinding"),
89 (
"leadingTrackPtCut",
"DiscriminationByLeadingTrackPtCut"),
90 (
"trackIsolation",
"DiscriminationByTrackIsolation"),
91 (
"ecalIsolation",
"DiscriminationByECALIsolation"),
92 (
"byIsolation",
"DiscriminationByIsolation"),
93 (
"againstElectron",
"DiscriminationAgainstElectron"),
94 (
"againstMuon",
"DiscriminationAgainstMuon") ]
96 classicPFTauIDSources = [
97 (
"leadingPionPtCut",
"DiscriminationByLeadingPionPtCut"),
98 (
"trackIsolationUsingLeadingPion",
"DiscriminationByTrackIsolationUsingLeadingPion"),
99 (
"ecalIsolationUsingLeadingPion",
"DiscriminationByECALIsolationUsingLeadingPion"),
100 (
"byIsolationUsingLeadingPion",
"DiscriminationByIsolationUsingLeadingPion")]
104 (
"decayModeFindingNewDMs",
"DiscriminationByDecayModeFindingNewDMs"),
105 (
"decayModeFindingOldDMs",
"DiscriminationByDecayModeFindingOldDMs"),
106 (
"decayModeFinding",
"DiscriminationByDecayModeFinding"),
107 (
"byLooseIsolation",
"DiscriminationByLooseIsolation"),
108 (
"byVLooseCombinedIsolationDeltaBetaCorr",
"DiscriminationByVLooseCombinedIsolationDBSumPtCorr"),
109 (
"byLooseCombinedIsolationDeltaBetaCorr",
"DiscriminationByLooseCombinedIsolationDBSumPtCorr"),
110 (
"byMediumCombinedIsolationDeltaBetaCorr",
"DiscriminationByMediumCombinedIsolationDBSumPtCorr"),
111 (
"byTightCombinedIsolationDeltaBetaCorr",
"DiscriminationByTightCombinedIsolationDBSumPtCorr"),
112 (
"byCombinedIsolationDeltaBetaCorrRaw",
"DiscriminationByRawCombinedIsolationDBSumPtCorr"),
113 (
"byLooseCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"),
114 (
"byMediumCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"),
115 (
"byTightCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"),
116 (
"byCombinedIsolationDeltaBetaCorrRaw3Hits",
"DiscriminationByRawCombinedIsolationDBSumPtCorr3Hits"),
117 (
"chargedIsoPtSum",
"MVA3IsolationChargedIsoPtSum"),
118 (
"neutralIsoPtSum",
"MVA3IsolationNeutralIsoPtSum"),
119 (
"puCorrPtSum",
"MVA3IsolationPUcorrPtSum"),
120 (
"byIsolationMVA3oldDMwoLTraw",
"DiscriminationByIsolationMVA3oldDMwoLTraw"),
121 (
"byVLooseIsolationMVA3oldDMwoLT",
"DiscriminationByVLooseIsolationMVA3oldDMwoLT"),
122 (
"byLooseIsolationMVA3oldDMwoLT",
"DiscriminationByLooseIsolationMVA3oldDMwoLT"),
123 (
"byMediumIsolationMVA3oldDMwoLT",
"DiscriminationByMediumIsolationMVA3oldDMwoLT"),
124 (
"byTightIsolationMVA3oldDMwoLT",
"DiscriminationByTightIsolationMVA3oldDMwoLT"),
125 (
"byVTightIsolationMVA3oldDMwoLT",
"DiscriminationByVTightIsolationMVA3oldDMwoLT"),
126 (
"byVVTightIsolationMVA3oldDMwoLT",
"DiscriminationByVVTightIsolationMVA3oldDMwoLT"),
127 (
"byIsolationMVA3oldDMwLTraw",
"DiscriminationByIsolationMVA3oldDMwLTraw"),
128 (
"byVLooseIsolationMVA3oldDMwLT",
"DiscriminationByVLooseIsolationMVA3oldDMwLT"),
129 (
"byLooseIsolationMVA3oldDMwLT",
"DiscriminationByLooseIsolationMVA3oldDMwLT"),
130 (
"byMediumIsolationMVA3oldDMwLT",
"DiscriminationByMediumIsolationMVA3oldDMwLT"),
131 (
"byTightIsolationMVA3oldDMwLT",
"DiscriminationByTightIsolationMVA3oldDMwLT"),
132 (
"byVTightIsolationMVA3oldDMwLT",
"DiscriminationByVTightIsolationMVA3oldDMwLT"),
133 (
"byVVTightIsolationMVA3oldDMwLT",
"DiscriminationByVVTightIsolationMVA3oldDMwLT"),
134 (
"byIsolationMVA3newDMwoLTraw",
"DiscriminationByIsolationMVA3newDMwoLTraw"),
135 (
"byVLooseIsolationMVA3newDMwoLT",
"DiscriminationByVLooseIsolationMVA3newDMwoLT"),
136 (
"byLooseIsolationMVA3newDMwoLT",
"DiscriminationByLooseIsolationMVA3newDMwoLT"),
137 (
"byMediumIsolationMVA3newDMwoLT",
"DiscriminationByMediumIsolationMVA3newDMwoLT"),
138 (
"byTightIsolationMVA3newDMwoLT",
"DiscriminationByTightIsolationMVA3newDMwoLT"),
139 (
"byVTightIsolationMVA3newDMwoLT",
"DiscriminationByVTightIsolationMVA3newDMwoLT"),
140 (
"byVVTightIsolationMVA3newDMwoLT",
"DiscriminationByVVTightIsolationMVA3newDMwoLT"),
141 (
"byIsolationMVA3newDMwLTraw",
"DiscriminationByIsolationMVA3newDMwLTraw"),
142 (
"byVLooseIsolationMVA3newDMwLT",
"DiscriminationByVLooseIsolationMVA3newDMwLT"),
143 (
"byLooseIsolationMVA3newDMwLT",
"DiscriminationByLooseIsolationMVA3newDMwLT"),
144 (
"byMediumIsolationMVA3newDMwLT",
"DiscriminationByMediumIsolationMVA3newDMwLT"),
145 (
"byTightIsolationMVA3newDMwLT",
"DiscriminationByTightIsolationMVA3newDMwLT"),
146 (
"byVTightIsolationMVA3newDMwLT",
"DiscriminationByVTightIsolationMVA3newDMwLT"),
147 (
"byVVTightIsolationMVA3newDMwLT",
"DiscriminationByVVTightIsolationMVA3newDMwLT"),
148 (
"againstElectronLoose",
"DiscriminationByLooseElectronRejection"),
149 (
"againstElectronMedium",
"DiscriminationByMediumElectronRejection"),
150 (
"againstElectronTight",
"DiscriminationByTightElectronRejection"),
151 (
"againstElectronMVA5raw",
"DiscriminationByMVA5rawElectronRejection"),
152 (
"againstElectronMVA5category",
"DiscriminationByMVA5rawElectronRejection:category"),
153 (
"againstElectronVLooseMVA5",
"DiscriminationByMVA5VLooseElectronRejection"),
154 (
"againstElectronLooseMVA5",
"DiscriminationByMVA5LooseElectronRejection"),
155 (
"againstElectronMediumMVA5",
"DiscriminationByMVA5MediumElectronRejection"),
156 (
"againstElectronTightMVA5",
"DiscriminationByMVA5TightElectronRejection"),
157 (
"againstElectronVTightMVA5",
"DiscriminationByMVA5VTightElectronRejection"),
158 (
"againstElectronDeadECAL",
"DiscriminationByDeadECALElectronRejection"),
159 (
"againstMuonLoose",
"DiscriminationByLooseMuonRejection"),
160 (
"againstMuonMedium",
"DiscriminationByMediumMuonRejection"),
161 (
"againstMuonTight",
"DiscriminationByTightMuonRejection"),
162 (
"againstMuonLoose2",
"DiscriminationByLooseMuonRejection2"),
163 (
"againstMuonMedium2",
"DiscriminationByMediumMuonRejection2"),
164 (
"againstMuonTight2",
"DiscriminationByTightMuonRejection2"),
165 (
"againstMuonLoose3",
"DiscriminationByLooseMuonRejection3"),
166 (
"againstMuonTight3",
"DiscriminationByTightMuonRejection3"),
167 (
"againstMuonMVAraw",
"DiscriminationByMVArawMuonRejection"),
168 (
"againstMuonLooseMVA",
"DiscriminationByMVALooseMuonRejection"),
169 (
"againstMuonMediumMVA",
"DiscriminationByMVAMediumMuonRejection"),
170 (
"againstMuonTightMVA",
"DiscriminationByMVATightMuonRejection") ]
175 tauSource = cms.InputTag(
'fixedConePFTauProducer'),
178 fixedConeIDSources = copy.copy(classicTauIDSources)
179 fixedConeIDSources.extend(classicPFTauIDSources)
181 _switchToPFTau(process, tauSource,
'fixedConePFTau', fixedConeIDSources,
182 patTauLabel = patTauLabel, postfix = postfix)
186 tauSource = cms.InputTag(
'shrinkingConePFTauProducer'),
189 shrinkingIDSources = copy.copy(classicTauIDSources)
190 shrinkingIDSources.extend(classicPFTauIDSources)
192 _switchToPFTau(process, tauSource,
'shrinkingConePFTau', shrinkingIDSources,
193 patTauLabel = patTauLabel, postfix = postfix)
197 tauSource = cms.InputTag(
'hpsPFTauProducer'),
203 patTauLabel = patTauLabel, postfix = postfix)
206 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = tauSource.value().
replace(
"Producer",
"TransverseImpactParameters")
209 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
210 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = \
211 'pt > 20 & abs(eta) < 2.3 & tauID("decayModeFindingOldDMs") > 0.5 & tauID("byLooseCombinedIsolationDeltaBetaCorr3Hits") > 0.5' \
212 +
' & tauID("againstMuonTight3") > 0.5 & tauID("againstElectronLoose") > 0.5'
217 tauSource = cms.InputTag(
'hpsPFTauProducer'),
221 'shrinkingConePFTau' : switchToPFTauShrinkingCone,
222 'fixedConePFTau' : switchToPFTauFixedCone,
223 'hpsPFTau' : switchToPFTauHPS,
224 'caloRecoTau' : switchToCaloTau
226 if not pfTauType
in mapping.keys():
227 raise ValueError(
"Error in <switchToPFTauByType>: Undefined pfTauType = %s !!" % pfTauType)
229 mapping[pfTauType](process, tauSource = tauSource,
230 patTauLabel = patTauLabel, postfix = postfix)
234 """ Add a new collection of taus. Takes the configuration from the
235 already configured standard tau collection as starting point;
236 replaces before calling addTauCollection will also affect the
239 _label=
'addTauCollection'
240 _defaultParameters=dicttypes.SortedKeysDict()
242 ConfigToolBase.__init__(self)
244 self._defaultValue,
'Input tau collection', cms.InputTag)
246 self._defaultValue,
"label to indicate the tau algorithm (e.g.'hps')", str)
248 self._defaultValue,
"label to indicate the type of constituents (either 'PFTau' or 'Tau')", str)
250 True,
"run sequence for computing particle-flow based IsoDeposits")
252 "hps",
"standard algorithm label of the collection from which the clones " \
253 +
"for the new tau collection will be taken from " \
254 +
"(note that this tau collection has to be available in the event before hand)")
256 "PFTau",
"standard constituent type label of the collection from which the clones " \
257 +
" for the new tau collection will be taken from "\
258 +
"(note that this tau collection has to be available in the event before hand)")
267 tauCollection =
None,
270 doPFIsoDeposits =
None,
273 standardType =
None):
275 if tauCollection
is None:
277 if algoLabel
is None:
279 if typeLabel
is None:
281 if doPFIsoDeposits
is None:
283 if standardAlgo
is None:
285 if standardType
is None:
288 self.setParameter(
'tauCollection', tauCollection)
289 self.setParameter(
'algoLabel', algoLabel)
290 self.setParameter(
'typeLabel', typeLabel)
291 self.setParameter(
'doPFIsoDeposits', doPFIsoDeposits)
292 self.setParameter(
'standardAlgo', standardAlgo)
293 self.setParameter(
'standardType', standardType)
298 tauCollection = self.
_parameters[
'tauCollection'].value
301 doPFIsoDeposits = self.
_parameters[
'doPFIsoDeposits'].value
302 standardAlgo = self.
_parameters[
'standardAlgo'].value
303 standardType = self.
_parameters[
'standardType'].value
307 if typeLabel ==
'Tau':
308 print "NO PF Isolation will be computed for CaloTau (this could be improved later)"
309 doPFIsoDeposits =
False
313 def oldLabel(prefix = ''):
317 return prefix +
"PatTaus"
322 def capitalize(label):
323 return label[0].capitalize() + label[1:]
327 def newLabel(oldLabel):
329 if ( oldLabel.find(standardAlgo) >= 0
and oldLabel.find(standardType) >= 0 ):
330 oldLabel = oldLabel.replace(standardAlgo, algoLabel).
replace(standardType, typeLabel)
332 oldLabel = oldLabel + capitalize(algoLabel + typeLabel)
336 def addClone(hook, **replaceStatements):
339 newModule = getattr(process, hook).
clone(**replaceStatements)
342 def addPFIsoDepositClone(hook, **replaceStatements):
343 newModule = getattr(process, hook).
clone(**replaceStatements)
344 newModuleIsoDepositExtractor = getattr(newModule,
"ExtractorPSet")
345 setattr(newModuleIsoDepositExtractor,
"tauSource", getattr(newModule,
"src"))
348 addClone(oldLabel(), tauSource = tauCollection)
351 addClone(oldLabel(
'selected'), src = cms.InputTag(newLabel(oldLabel())))
354 addClone(oldLabel(
'clean'), src=cms.InputTag(newLabel(oldLabel(
'selected'))))
357 newTaus = getattr(process, newLabel(oldLabel()))
360 addClone(
'tauMatch', src = tauCollection)
361 addClone(
'tauGenJetMatch', src = tauCollection)
365 addPFIsoDepositClone(
'tauIsoDepositPFCandidates', src = tauCollection)
366 addPFIsoDepositClone(
'tauIsoDepositPFChargedHadrons', src = tauCollection)
367 addPFIsoDepositClone(
'tauIsoDepositPFNeutralHadrons', src = tauCollection)
368 addPFIsoDepositClone(
'tauIsoDepositPFGammas', src = tauCollection)
372 x.setModuleLabel(newLabel(x.moduleLabel))
375 fixInputTag(newTaus.genParticleMatch)
376 fixInputTag(newTaus.genJetMatch)
377 fixInputTag(newTaus.isoDeposits.pfAllParticles)
378 fixInputTag(newTaus.isoDeposits.pfNeutralHadron)
379 fixInputTag(newTaus.isoDeposits.pfChargedHadron)
380 fixInputTag(newTaus.isoDeposits.pfGamma)
381 fixInputTag(newTaus.userIsolation.pfAllParticles.src)
382 fixInputTag(newTaus.userIsolation.pfNeutralHadron.src)
383 fixInputTag(newTaus.userIsolation.pfChargedHadron.src)
384 fixInputTag(newTaus.userIsolation.pfGamma.src)
388 oldTaus = getattr(process, oldLabel())
389 if typeLabel ==
'Tau':
391 tauSource = getattr(newTaus,
"tauSource"),
392 patTauLabel = capitalize(algoLabel + typeLabel))
395 tauSource = getattr(newTaus,
"tauSource"),
396 patTauLabel = capitalize(algoLabel + typeLabel))