1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
12 if hasattr(process, label+postfix):
13 result = getattr(process, label + postfix)
15 raise ValueError(
"Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
20 tauSource = cms.InputTag(
'caloRecoTauProducer'),
23 print(
' switching PAT Tau input to: ', tauSource)
25 applyPostfix(process,
"tauMatch" + patTauLabel, postfix).src = tauSource
26 applyPostfix(process,
"tauGenJetMatch"+ patTauLabel, postfix).src = tauSource
28 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauSource = tauSource
30 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource =
"" 34 print(
"NO PF Isolation will be computed for CaloTau (this could be improved later)")
35 applyPostfix(process,
"patTaus" + patTauLabel, postfix).isolation = cms.PSet()
36 applyPostfix(process,
"patTaus" + patTauLabel, postfix).isoDeposits = cms.PSet()
37 applyPostfix(process,
"patTaus" + patTauLabel, postfix).userIsolation = cms.PSet()
40 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
41 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = preselection
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 = preselection
84 classicTauIDSources = [
85 (
"leadingTrackFinding",
"DiscriminationByLeadingTrackFinding"),
86 (
"leadingTrackPtCut",
"DiscriminationByLeadingTrackPtCut"),
87 (
"trackIsolation",
"DiscriminationByTrackIsolation"),
88 (
"ecalIsolation",
"DiscriminationByECALIsolation"),
89 (
"byIsolation",
"DiscriminationByIsolation"),
90 (
"againstElectron",
"DiscriminationAgainstElectron"),
91 (
"againstMuon",
"DiscriminationAgainstMuon")
94 classicPFTauIDSources = [
95 (
"leadingPionPtCut",
"DiscriminationByLeadingPionPtCut"),
96 (
"trackIsolationUsingLeadingPion",
"DiscriminationByTrackIsolationUsingLeadingPion"),
97 (
"ecalIsolationUsingLeadingPion",
"DiscriminationByECALIsolationUsingLeadingPion"),
98 (
"byIsolationUsingLeadingPion",
"DiscriminationByIsolationUsingLeadingPion")
103 (
"decayModeFindingNewDMs",
"DiscriminationByDecayModeFindingNewDMs"),
104 (
"decayModeFinding",
"DiscriminationByDecayModeFinding"),
105 (
"byLooseCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"),
106 (
"byMediumCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"),
107 (
"byTightCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"),
108 (
"byCombinedIsolationDeltaBetaCorrRaw3Hits",
"DiscriminationByRawCombinedIsolationDBSumPtCorr3Hits"),
109 (
"byLooseCombinedIsolationDeltaBetaCorr3HitsdR03",
"DiscriminationByLooseCombinedIsolationDBSumPtCorr3HitsdR03"),
110 (
"byMediumCombinedIsolationDeltaBetaCorr3HitsdR03",
"DiscriminationByMediumCombinedIsolationDBSumPtCorr3HitsdR03"),
111 (
"byTightCombinedIsolationDeltaBetaCorr3HitsdR03",
"DiscriminationByTightCombinedIsolationDBSumPtCorr3HitsdR03"),
112 (
"byPhotonPtSumOutsideSignalCone",
"DiscriminationByPhotonPtSumOutsideSignalCone"),
113 (
"chargedIsoPtSum",
"ChargedIsoPtSum"),
114 (
"neutralIsoPtSum",
"NeutralIsoPtSum"),
115 (
"puCorrPtSum",
"PUcorrPtSum"),
116 (
"neutralIsoPtSumWeight",
"NeutralIsoPtSumWeight"),
117 (
"footprintCorrection",
"FootprintCorrection"),
118 (
"photonPtSumOutsideSignalCone",
"PhotonPtSumOutsideSignalCone"),
119 (
"againstMuonLoose3",
"DiscriminationByLooseMuonRejection3"),
120 (
"againstMuonTight3",
"DiscriminationByTightMuonRejection3"),
121 (
"byIsolationMVArun2v1DBoldDMwLTraw",
"DiscriminationByIsolationMVArun2v1DBoldDMwLTraw"),
122 (
"byVVLooseIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLT"),
123 (
"byVLooseIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1DBoldDMwLT"),
124 (
"byLooseIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1DBoldDMwLT"),
125 (
"byMediumIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1DBoldDMwLT"),
126 (
"byTightIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByTightIsolationMVArun2v1DBoldDMwLT"),
127 (
"byVTightIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1DBoldDMwLT"),
128 (
"byVVTightIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1DBoldDMwLT"),
129 (
"byIsolationMVArun2v1DBnewDMwLTraw",
"DiscriminationByIsolationMVArun2v1DBnewDMwLTraw"),
130 (
"byVVLooseIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVVLooseIsolationMVArun2v1DBnewDMwLT"),
131 (
"byVLooseIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1DBnewDMwLT"),
132 (
"byLooseIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByLooseIsolationMVArun2v1DBnewDMwLT"),
133 (
"byMediumIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByMediumIsolationMVArun2v1DBnewDMwLT"),
134 (
"byTightIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByTightIsolationMVArun2v1DBnewDMwLT"),
135 (
"byVTightIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVTightIsolationMVArun2v1DBnewDMwLT"),
136 (
"byVVTightIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1DBnewDMwLT"),
137 (
"byIsolationMVArun2v1PWoldDMwLTraw",
"DiscriminationByIsolationMVArun2v1PWoldDMwLTraw"),
138 (
"byVLooseIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1PWoldDMwLT"),
139 (
"byLooseIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1PWoldDMwLT"),
140 (
"byMediumIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1PWoldDMwLT"),
141 (
"byTightIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByTightIsolationMVArun2v1PWoldDMwLT"),
142 (
"byVTightIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1PWoldDMwLT"),
143 (
"byVVTightIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1PWoldDMwLT"),
144 (
"byIsolationMVArun2v1PWnewDMwLTraw",
"DiscriminationByIsolationMVArun2v1PWnewDMwLTraw"),
145 (
"byVLooseIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1PWnewDMwLT"),
146 (
"byLooseIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByLooseIsolationMVArun2v1PWnewDMwLT"),
147 (
"byMediumIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByMediumIsolationMVArun2v1PWnewDMwLT"),
148 (
"byTightIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByTightIsolationMVArun2v1PWnewDMwLT"),
149 (
"byVTightIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByVTightIsolationMVArun2v1PWnewDMwLT"),
150 (
"byVVTightIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1PWnewDMwLT"),
151 (
"chargedIsoPtSumdR03",
"ChargedIsoPtSumdR03"),
152 (
"neutralIsoPtSumdR03",
"NeutralIsoPtSumdR03"),
153 (
"neutralIsoPtSumWeightdR03",
"NeutralIsoPtSumWeightdR03"),
154 (
"footprintCorrectiondR03",
"FootprintCorrectiondR03"),
155 (
"photonPtSumOutsideSignalConedR03",
"PhotonPtSumOutsideSignalConedR03"),
156 (
"byIsolationMVArun2v1DBdR03oldDMwLTraw",
"DiscriminationByIsolationMVArun2v1DBdR03oldDMwLTraw"),
157 (
"byVVLooseIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVVLooseIsolationMVArun2v1DBdR03oldDMwLT"),
158 (
"byVLooseIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1DBdR03oldDMwLT"),
159 (
"byLooseIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1DBdR03oldDMwLT"),
160 (
"byMediumIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1DBdR03oldDMwLT"),
161 (
"byTightIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByTightIsolationMVArun2v1DBdR03oldDMwLT"),
162 (
"byVTightIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1DBdR03oldDMwLT"),
163 (
"byVVTightIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1DBdR03oldDMwLT"),
164 (
"byIsolationMVArun2v1PWdR03oldDMwLTraw",
"DiscriminationByIsolationMVArun2v1PWdR03oldDMwLTraw"),
165 (
"byVLooseIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1PWdR03oldDMwLT"),
166 (
"byLooseIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1PWdR03oldDMwLT"),
167 (
"byMediumIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1PWdR03oldDMwLT"),
168 (
"byTightIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByTightIsolationMVArun2v1PWdR03oldDMwLT"),
169 (
"byVTightIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1PWdR03oldDMwLT"),
170 (
"byVVTightIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1PWdR03oldDMwLT"),
171 (
"againstElectronMVA6Raw",
"DiscriminationByMVA6rawElectronRejection"),
172 (
"againstElectronMVA6category",
"DiscriminationByMVA6rawElectronRejection:category"),
173 (
"againstElectronVLooseMVA6",
"DiscriminationByMVA6VLooseElectronRejection"),
174 (
"againstElectronLooseMVA6",
"DiscriminationByMVA6LooseElectronRejection"),
175 (
"againstElectronMediumMVA6",
"DiscriminationByMVA6MediumElectronRejection"),
176 (
"againstElectronTightMVA6",
"DiscriminationByMVA6TightElectronRejection"),
177 (
"againstElectronVTightMVA6",
"DiscriminationByMVA6VTightElectronRejection"),
182 tauSource = cms.InputTag(
'fixedConePFTauProducer'),
185 fixedConeIDSources = copy.copy(classicTauIDSources)
186 fixedConeIDSources.extend(classicPFTauIDSources)
188 _switchToPFTau(process, tauSource,
'fixedConePFTau', fixedConeIDSources,
189 patTauLabel = patTauLabel, postfix = postfix)
193 tauSource = cms.InputTag(
'shrinkingConePFTauProducer'),
196 shrinkingIDSources = copy.copy(classicTauIDSources)
197 shrinkingIDSources.extend(classicPFTauIDSources)
199 _switchToPFTau(process, tauSource,
'shrinkingConePFTau', shrinkingIDSources,
200 patTauLabel = patTauLabel, postfix = postfix)
204 tauSource = cms.InputTag(
'hpsPFTauProducer'),
210 patTauLabel = patTauLabel, postfix = postfix)
213 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = tauSource.value().
replace(
"Producer",
"TransverseImpactParameters")
216 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
217 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = preselection
222 tauSource = cms.InputTag(
'hpsPFTauProducer'),
226 'shrinkingConePFTau' : switchToPFTauShrinkingCone,
227 'fixedConePFTau' : switchToPFTauFixedCone,
228 'hpsPFTau' : switchToPFTauHPS,
229 'caloRecoTau' : switchToCaloTau
231 if not pfTauType
in mapping.keys():
232 raise ValueError(
"Error in <switchToPFTauByType>: Undefined pfTauType = %s !!" % pfTauType)
234 mapping[pfTauType](process, tauSource = tauSource,
235 patTauLabel = patTauLabel, postfix = postfix)
239 """ Add a new collection of taus. Takes the configuration from the 240 already configured standard tau collection as starting point; 241 replaces before calling addTauCollection will also affect the 244 _label=
'addTauCollection' 245 _defaultParameters=dicttypes.SortedKeysDict()
247 ConfigToolBase.__init__(self)
249 self._defaultValue,
'Input tau collection', cms.InputTag)
251 self._defaultValue,
"label to indicate the tau algorithm (e.g.'hps')", str)
253 self._defaultValue,
"label to indicate the type of constituents (either 'PFTau' or 'Tau')", str)
255 True,
"run sequence for computing particle-flow based IsoDeposits")
257 "hps",
"standard algorithm label of the collection from which the clones " \
258 +
"for the new tau collection will be taken from " \
259 +
"(note that this tau collection has to be available in the event before hand)")
261 "PFTau",
"standard constituent type label of the collection from which the clones " \
262 +
" for the new tau collection will be taken from "\
263 +
"(note that this tau collection has to be available in the event before hand)")
272 tauCollection =
None,
275 doPFIsoDeposits =
None,
278 standardType =
None):
280 if tauCollection
is None:
282 if algoLabel
is None:
284 if typeLabel
is None:
286 if doPFIsoDeposits
is None:
288 if standardAlgo
is None:
290 if standardType
is None:
293 self.setParameter(
'tauCollection', tauCollection)
294 self.setParameter(
'algoLabel', algoLabel)
295 self.setParameter(
'typeLabel', typeLabel)
296 self.setParameter(
'doPFIsoDeposits', doPFIsoDeposits)
297 self.setParameter(
'standardAlgo', standardAlgo)
298 self.setParameter(
'standardType', standardType)
303 tauCollection = self.
_parameters[
'tauCollection'].value
306 doPFIsoDeposits = self.
_parameters[
'doPFIsoDeposits'].value
307 standardAlgo = self.
_parameters[
'standardAlgo'].value
308 standardType = self.
_parameters[
'standardType'].value
312 if typeLabel ==
'Tau':
313 print(
"NO PF Isolation will be computed for CaloTau (this could be improved later)")
314 doPFIsoDeposits =
False 318 def oldLabel(prefix = ''):
322 return prefix +
"PatTaus" 327 def capitalize(label):
328 return label[0].capitalize() + label[1:]
332 def newLabel(oldLabel):
334 if ( oldLabel.find(standardAlgo) >= 0
and oldLabel.find(standardType) >= 0 ):
335 oldLabel = oldLabel.replace(standardAlgo, algoLabel).
replace(standardType, typeLabel)
337 oldLabel = oldLabel + capitalize(algoLabel + typeLabel)
341 def addClone(hook, **replaceStatements):
344 newModule = getattr(process, hook).
clone(**replaceStatements)
347 def addPFIsoDepositClone(hook, **replaceStatements):
348 newModule = getattr(process, hook).
clone(**replaceStatements)
349 newModuleIsoDepositExtractor = getattr(newModule,
"ExtractorPSet")
350 setattr(newModuleIsoDepositExtractor,
"tauSource", getattr(newModule,
"src"))
353 addClone(oldLabel(), tauSource = tauCollection)
356 addClone(oldLabel(
'selected'), src = cms.InputTag(newLabel(oldLabel())))
359 addClone(oldLabel(
'clean'), src=cms.InputTag(newLabel(oldLabel(
'selected'))))
362 newTaus = getattr(process, newLabel(oldLabel()))
365 addClone(
'tauMatch', src = tauCollection)
366 addClone(
'tauGenJetMatch', src = tauCollection)
370 addPFIsoDepositClone(
'tauIsoDepositPFCandidates', src = tauCollection)
371 addPFIsoDepositClone(
'tauIsoDepositPFChargedHadrons', src = tauCollection)
372 addPFIsoDepositClone(
'tauIsoDepositPFNeutralHadrons', src = tauCollection)
373 addPFIsoDepositClone(
'tauIsoDepositPFGammas', src = tauCollection)
377 x.setModuleLabel(newLabel(x.moduleLabel))
380 fixInputTag(newTaus.genParticleMatch)
381 fixInputTag(newTaus.genJetMatch)
382 fixInputTag(newTaus.isoDeposits.pfAllParticles)
383 fixInputTag(newTaus.isoDeposits.pfNeutralHadron)
384 fixInputTag(newTaus.isoDeposits.pfChargedHadron)
385 fixInputTag(newTaus.isoDeposits.pfGamma)
386 fixInputTag(newTaus.userIsolation.pfAllParticles.src)
387 fixInputTag(newTaus.userIsolation.pfNeutralHadron.src)
388 fixInputTag(newTaus.userIsolation.pfChargedHadron.src)
389 fixInputTag(newTaus.userIsolation.pfGamma.src)
393 oldTaus = getattr(process, oldLabel())
394 if typeLabel ==
'Tau':
396 tauSource = getattr(newTaus,
"tauSource"),
397 patTauLabel = capitalize(algoLabel + typeLabel))
400 tauSource = getattr(newTaus,
"tauSource"),
401 patTauLabel = capitalize(algoLabel + typeLabel))
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)