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))
19 """ Build a PSet defining the tau ID sources to embed into the pat::Tau """
21 for label, discriminator
in idSources:
23 if ";" in discriminator:
24 discriminator, wp_str = discriminator.split(
";")
27 id.inputTag = cms.InputTag(discriminator.replace(
":", postfix +
":"))
28 id.provenanceConfigLabel=cms.string(
"")
29 id.idLabel=cms.string(
"")
30 setattr(output, label, id)
39 """internal auxiliary function to switch to **any** PFTau collection"""
40 print(
' switching PAT Tau input to: ', tauSource)
42 applyPostfix(process,
"tauMatch" + patTauLabel, postfix).src = tauSource
43 applyPostfix(process,
"tauGenJetMatch" + patTauLabel, postfix).src = tauSource
45 applyPostfix(process,
"tauIsoDepositPFCandidates" + patTauLabel, postfix).src = tauSource
46 applyPostfix(process,
"tauIsoDepositPFCandidates" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
47 applyPostfix(process,
"tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).src = tauSource
48 applyPostfix(process,
"tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
49 applyPostfix(process,
"tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).src = tauSource
50 applyPostfix(process,
"tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
51 applyPostfix(process,
"tauIsoDepositPFGammas" + patTauLabel, postfix).src = tauSource
52 applyPostfix(process,
"tauIsoDepositPFGammas" + patTauLabel, postfix).ExtractorPSet.tauSource = tauSource
54 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauSource = tauSource
56 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource =
""
59 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
60 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = preselection
63 classicTauIDSources = [
64 (
"leadingTrackFinding",
"DiscriminationByLeadingTrackFinding"),
65 (
"leadingTrackPtCut",
"DiscriminationByLeadingTrackPtCut"),
66 (
"trackIsolation",
"DiscriminationByTrackIsolation"),
67 (
"ecalIsolation",
"DiscriminationByECALIsolation"),
68 (
"byIsolation",
"DiscriminationByIsolation"),
69 (
"againstElectron",
"DiscriminationAgainstElectron"),
70 (
"againstMuon",
"DiscriminationAgainstMuon")
73 classicPFTauIDSources = [
74 (
"leadingPionPtCut",
"DiscriminationByLeadingPionPtCut"),
75 (
"trackIsolationUsingLeadingPion",
"DiscriminationByTrackIsolationUsingLeadingPion"),
76 (
"ecalIsolationUsingLeadingPion",
"DiscriminationByECALIsolationUsingLeadingPion"),
77 (
"byIsolationUsingLeadingPion",
"DiscriminationByIsolationUsingLeadingPion")
82 (
"decayModeFindingNewDMs",
"DiscriminationByDecayModeFindingNewDMs"),
83 (
"decayModeFinding",
"DiscriminationByDecayModeFinding"),
84 (
"byLooseCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"),
85 (
"byMediumCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"),
86 (
"byTightCombinedIsolationDeltaBetaCorr3Hits",
"DiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"),
87 (
"byCombinedIsolationDeltaBetaCorrRaw3Hits",
"DiscriminationByRawCombinedIsolationDBSumPtCorr3Hits"),
88 (
"byLooseCombinedIsolationDeltaBetaCorr3HitsdR03",
"DiscriminationByLooseCombinedIsolationDBSumPtCorr3HitsdR03"),
89 (
"byMediumCombinedIsolationDeltaBetaCorr3HitsdR03",
"DiscriminationByMediumCombinedIsolationDBSumPtCorr3HitsdR03"),
90 (
"byTightCombinedIsolationDeltaBetaCorr3HitsdR03",
"DiscriminationByTightCombinedIsolationDBSumPtCorr3HitsdR03"),
91 (
"byPhotonPtSumOutsideSignalCone",
"DiscriminationByPhotonPtSumOutsideSignalCone"),
92 (
"chargedIsoPtSum",
"ChargedIsoPtSum"),
93 (
"neutralIsoPtSum",
"NeutralIsoPtSum"),
94 (
"puCorrPtSum",
"PUcorrPtSum"),
95 (
"neutralIsoPtSumWeight",
"NeutralIsoPtSumWeight"),
96 (
"footprintCorrection",
"FootprintCorrection"),
97 (
"photonPtSumOutsideSignalCone",
"PhotonPtSumOutsideSignalCone"),
98 (
"againstMuonLoose3",
"DiscriminationByLooseMuonRejection3"),
99 (
"againstMuonTight3",
"DiscriminationByTightMuonRejection3"),
100 (
"byIsolationMVArun2v1DBoldDMwLTraw",
"DiscriminationByIsolationMVArun2v1DBoldDMwLTraw"),
101 (
"byVVLooseIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLT"),
102 (
"byVLooseIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1DBoldDMwLT"),
103 (
"byLooseIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1DBoldDMwLT"),
104 (
"byMediumIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1DBoldDMwLT"),
105 (
"byTightIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByTightIsolationMVArun2v1DBoldDMwLT"),
106 (
"byVTightIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1DBoldDMwLT"),
107 (
"byVVTightIsolationMVArun2v1DBoldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1DBoldDMwLT"),
108 (
"byIsolationMVArun2v1DBnewDMwLTraw",
"DiscriminationByIsolationMVArun2v1DBnewDMwLTraw"),
109 (
"byVVLooseIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVVLooseIsolationMVArun2v1DBnewDMwLT"),
110 (
"byVLooseIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1DBnewDMwLT"),
111 (
"byLooseIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByLooseIsolationMVArun2v1DBnewDMwLT"),
112 (
"byMediumIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByMediumIsolationMVArun2v1DBnewDMwLT"),
113 (
"byTightIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByTightIsolationMVArun2v1DBnewDMwLT"),
114 (
"byVTightIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVTightIsolationMVArun2v1DBnewDMwLT"),
115 (
"byVVTightIsolationMVArun2v1DBnewDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1DBnewDMwLT"),
116 (
"byIsolationMVArun2v1PWoldDMwLTraw",
"DiscriminationByIsolationMVArun2v1PWoldDMwLTraw"),
117 (
"byVLooseIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1PWoldDMwLT"),
118 (
"byLooseIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1PWoldDMwLT"),
119 (
"byMediumIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1PWoldDMwLT"),
120 (
"byTightIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByTightIsolationMVArun2v1PWoldDMwLT"),
121 (
"byVTightIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1PWoldDMwLT"),
122 (
"byVVTightIsolationMVArun2v1PWoldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1PWoldDMwLT"),
123 (
"byIsolationMVArun2v1PWnewDMwLTraw",
"DiscriminationByIsolationMVArun2v1PWnewDMwLTraw"),
124 (
"byVLooseIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1PWnewDMwLT"),
125 (
"byLooseIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByLooseIsolationMVArun2v1PWnewDMwLT"),
126 (
"byMediumIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByMediumIsolationMVArun2v1PWnewDMwLT"),
127 (
"byTightIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByTightIsolationMVArun2v1PWnewDMwLT"),
128 (
"byVTightIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByVTightIsolationMVArun2v1PWnewDMwLT"),
129 (
"byVVTightIsolationMVArun2v1PWnewDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1PWnewDMwLT"),
130 (
"chargedIsoPtSumdR03",
"ChargedIsoPtSumdR03"),
131 (
"neutralIsoPtSumdR03",
"NeutralIsoPtSumdR03"),
132 (
"neutralIsoPtSumWeightdR03",
"NeutralIsoPtSumWeightdR03"),
133 (
"footprintCorrectiondR03",
"FootprintCorrectiondR03"),
134 (
"photonPtSumOutsideSignalConedR03",
"PhotonPtSumOutsideSignalConedR03"),
135 (
"byIsolationMVArun2v1DBdR03oldDMwLTraw",
"DiscriminationByIsolationMVArun2v1DBdR03oldDMwLTraw"),
136 (
"byVVLooseIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVVLooseIsolationMVArun2v1DBdR03oldDMwLT"),
137 (
"byVLooseIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1DBdR03oldDMwLT"),
138 (
"byLooseIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1DBdR03oldDMwLT"),
139 (
"byMediumIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1DBdR03oldDMwLT"),
140 (
"byTightIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByTightIsolationMVArun2v1DBdR03oldDMwLT"),
141 (
"byVTightIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1DBdR03oldDMwLT"),
142 (
"byVVTightIsolationMVArun2v1DBdR03oldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1DBdR03oldDMwLT"),
143 (
"byIsolationMVArun2v1PWdR03oldDMwLTraw",
"DiscriminationByIsolationMVArun2v1PWdR03oldDMwLTraw"),
144 (
"byVLooseIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByVLooseIsolationMVArun2v1PWdR03oldDMwLT"),
145 (
"byLooseIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByLooseIsolationMVArun2v1PWdR03oldDMwLT"),
146 (
"byMediumIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByMediumIsolationMVArun2v1PWdR03oldDMwLT"),
147 (
"byTightIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByTightIsolationMVArun2v1PWdR03oldDMwLT"),
148 (
"byVTightIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByVTightIsolationMVArun2v1PWdR03oldDMwLT"),
149 (
"byVVTightIsolationMVArun2v1PWdR03oldDMwLT",
"DiscriminationByVVTightIsolationMVArun2v1PWdR03oldDMwLT"),
150 (
"againstElectronMVA6Raw",
"DiscriminationByMVA6rawElectronRejection"),
151 (
"againstElectronMVA6category",
"DiscriminationByMVA6rawElectronRejection:category"),
152 (
"againstElectronVLooseMVA6",
"DiscriminationByMVA6VLooseElectronRejection"),
153 (
"againstElectronLooseMVA6",
"DiscriminationByMVA6LooseElectronRejection"),
154 (
"againstElectronMediumMVA6",
"DiscriminationByMVA6MediumElectronRejection"),
155 (
"againstElectronTightMVA6",
"DiscriminationByMVA6TightElectronRejection"),
156 (
"againstElectronVTightMVA6",
"DiscriminationByMVA6VTightElectronRejection"),
157 (
"againstElectronDeadECAL",
"DiscriminationByDeadECALElectronRejection"),
162 tauSource = cms.InputTag(
'fixedConePFTauProducer'),
165 fixedConeIDSources = copy.copy(classicTauIDSources)
166 fixedConeIDSources.extend(classicPFTauIDSources)
168 _switchToPFTau(process, tauSource,
'fixedConePFTau', fixedConeIDSources,
169 patTauLabel = patTauLabel, postfix = postfix)
173 tauSource = cms.InputTag(
'shrinkingConePFTauProducer'),
176 shrinkingIDSources = copy.copy(classicTauIDSources)
177 shrinkingIDSources.extend(classicPFTauIDSources)
179 _switchToPFTau(process, tauSource,
'shrinkingConePFTau', shrinkingIDSources,
180 patTauLabel = patTauLabel, postfix = postfix)
184 tauSource = cms.InputTag(
'hpsPFTauProducer'),
190 patTauLabel = patTauLabel, postfix = postfix)
193 applyPostfix(process,
"patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = tauSource.value().
replace(
"Producer",
"TransverseImpactParameters")
196 if hasattr(process,
"cleanPatTaus" + patTauLabel + postfix):
197 getattr(process,
"cleanPatTaus" + patTauLabel + postfix).preselection = preselection
202 tauSource = cms.InputTag(
'hpsPFTauProducer'),
206 'shrinkingConePFTau' : switchToPFTauShrinkingCone,
207 'fixedConePFTau' : switchToPFTauFixedCone,
208 'hpsPFTau' : switchToPFTauHPS
210 if not pfTauType
in mapping.keys():
211 raise ValueError(
"Error in <switchToPFTauByType>: Undefined pfTauType = %s !!" % pfTauType)
213 mapping[pfTauType](process, tauSource = tauSource,
214 patTauLabel = patTauLabel, postfix = postfix)
218 """ Add a new collection of taus. Takes the configuration from the
219 already configured standard tau collection as starting point;
220 replaces before calling addTauCollection will also affect the
223 _label=
'addTauCollection'
224 _defaultParameters=dicttypes.SortedKeysDict()
226 ConfigToolBase.__init__(self)
228 self._defaultValue,
'Input tau collection', cms.InputTag)
230 self._defaultValue,
"label to indicate the tau algorithm (e.g.'hps')", str)
232 self._defaultValue,
"label to indicate the type of constituents (either 'PFTau' or 'Tau')", str)
234 True,
"run sequence for computing particle-flow based IsoDeposits")
236 "hps",
"standard algorithm label of the collection from which the clones " \
237 +
"for the new tau collection will be taken from " \
238 +
"(note that this tau collection has to be available in the event before hand)")
240 "PFTau",
"standard constituent type label of the collection from which the clones " \
241 +
" for the new tau collection will be taken from "\
242 +
"(note that this tau collection has to be available in the event before hand)")
251 tauCollection =
None,
254 doPFIsoDeposits =
None,
257 standardType =
None):
259 if tauCollection
is None:
261 if algoLabel
is None:
263 if typeLabel
is None:
265 if doPFIsoDeposits
is None:
267 if standardAlgo
is None:
269 if standardType
is None:
272 self.setParameter(
'tauCollection', tauCollection)
273 self.setParameter(
'algoLabel', algoLabel)
274 self.setParameter(
'typeLabel', typeLabel)
275 self.setParameter(
'doPFIsoDeposits', doPFIsoDeposits)
276 self.setParameter(
'standardAlgo', standardAlgo)
277 self.setParameter(
'standardType', standardType)
282 tauCollection = self.
_parameters[
'tauCollection'].value
285 doPFIsoDeposits = self.
_parameters[
'doPFIsoDeposits'].value
286 standardAlgo = self.
_parameters[
'standardAlgo'].value
287 standardType = self.
_parameters[
'standardType'].value
291 if typeLabel ==
'Tau':
292 print(
"NO PF Isolation will be computed for CaloTau (this could be improved later)")
293 doPFIsoDeposits =
False
297 def oldLabel(prefix = ''):
301 return prefix +
"PatTaus"
306 def capitalize(label):
307 return label[0].capitalize() + label[1:]
311 def newLabel(oldLabel):
313 if ( oldLabel.find(standardAlgo) >= 0
and oldLabel.find(standardType) >= 0 ):
314 oldLabel = oldLabel.replace(standardAlgo, algoLabel).
replace(standardType, typeLabel)
316 oldLabel = oldLabel + capitalize(algoLabel + typeLabel)
320 def addClone(hook, **replaceStatements):
323 newModule = getattr(process, hook).
clone(**replaceStatements)
326 def addPFIsoDepositClone(hook, **replaceStatements):
327 newModule = getattr(process, hook).
clone(**replaceStatements)
328 newModuleIsoDepositExtractor = getattr(newModule,
"ExtractorPSet")
329 setattr(newModuleIsoDepositExtractor,
"tauSource", getattr(newModule,
"src"))
332 addClone(oldLabel(), tauSource = tauCollection)
335 addClone(oldLabel(
'selected'), src = cms.InputTag(newLabel(oldLabel())))
338 addClone(oldLabel(
'clean'), src=cms.InputTag(newLabel(oldLabel(
'selected'))))
341 newTaus = getattr(process, newLabel(oldLabel()))
344 addClone(
'tauMatch', src = tauCollection)
345 addClone(
'tauGenJetMatch', src = tauCollection)
349 addPFIsoDepositClone(
'tauIsoDepositPFCandidates', src = tauCollection)
350 addPFIsoDepositClone(
'tauIsoDepositPFChargedHadrons', src = tauCollection)
351 addPFIsoDepositClone(
'tauIsoDepositPFNeutralHadrons', src = tauCollection)
352 addPFIsoDepositClone(
'tauIsoDepositPFGammas', src = tauCollection)
356 x.setModuleLabel(newLabel(x.moduleLabel))
359 fixInputTag(newTaus.genParticleMatch)
360 fixInputTag(newTaus.genJetMatch)
361 fixInputTag(newTaus.isoDeposits.pfAllParticles)
362 fixInputTag(newTaus.isoDeposits.pfNeutralHadron)
363 fixInputTag(newTaus.isoDeposits.pfChargedHadron)
364 fixInputTag(newTaus.isoDeposits.pfGamma)
365 fixInputTag(newTaus.userIsolation.pfAllParticles.src)
366 fixInputTag(newTaus.userIsolation.pfNeutralHadron.src)
367 fixInputTag(newTaus.userIsolation.pfChargedHadron.src)
368 fixInputTag(newTaus.userIsolation.pfGamma.src)
372 oldTaus = getattr(process, oldLabel())
374 tauSource = getattr(newTaus,
"tauSource"),
375 patTauLabel = capitalize(algoLabel + typeLabel))
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)