test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
tauTools.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
4 from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
6 
7 # applyPostFix function adapted to unscheduled mode
8 def applyPostfix(process, label, postfix):
9  result = None
10  if hasattr(process, label+postfix):
11  result = getattr(process, label + postfix)
12  else:
13  raise ValueError("Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
14  return result
15 
16 # switch to CaloTau collection
17 def switchToCaloTau(process,
18  tauSource = cms.InputTag('caloRecoTauProducer'),
19  patTauLabel = "",
20  postfix = ""):
21  print ' switching PAT Tau input to: ', tauSource
22 
23  applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = tauSource
24  applyPostfix(process, "tauGenJetMatch"+ patTauLabel, postfix).src = tauSource
25 
26  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = tauSource
27  # CV: reconstruction of tau lifetime information not implemented for CaloTaus yet
28  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = ""
29  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet('caloRecoTau', classicTauIDSources, postfix)
30 
31  ## Isolation is somewhat an issue, so we start just by turning it off
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()
36 
37  ## adapt cleanPatTaus
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)'
42 
43 def _buildIDSourcePSet(tauType, idSources, postfix =""):
44  """ Build a PSet defining the tau ID sources to embed into the pat::Tau """
45  output = cms.PSet()
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]))
50  else:
51  setattr(output, label, cms.InputTag(tauType + discriminator + postfix))
52  return output
53 
54 def _switchToPFTau(process,
55  tauSource,
56  pfTauType,
57  idSources,
58  patTauLabel = "",
59  postfix = ""):
60  """internal auxiliary function to switch to **any** PFTau collection"""
61  print ' switching PAT Tau input to: ', tauSource
62 
63  applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = tauSource
64  applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = tauSource
65 
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
74 
75  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = tauSource
76  # CV: reconstruction of tau lifetime information not enabled for tau collections other than 'hpsPFTauProducer' yet
77  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = ""
78  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet(pfTauType, idSources, postfix)
79 
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)'
85 
86 # Name mapping for classic tau ID sources (present for fixed and shrinkingCones)
87 classicTauIDSources = [
88  ("leadingTrackFinding", "DiscriminationByLeadingTrackFinding"),
89  ("leadingTrackPtCut", "DiscriminationByLeadingTrackPtCut"),
90  ("trackIsolation", "DiscriminationByTrackIsolation"),
91  ("ecalIsolation", "DiscriminationByECALIsolation"),
92  ("byIsolation", "DiscriminationByIsolation"),
93  ("againstElectron", "DiscriminationAgainstElectron"),
94  ("againstMuon", "DiscriminationAgainstMuon")
95 ]
96 
97 classicPFTauIDSources = [
98  ("leadingPionPtCut", "DiscriminationByLeadingPionPtCut"),
99  ("trackIsolationUsingLeadingPion", "DiscriminationByTrackIsolationUsingLeadingPion"),
100  ("ecalIsolationUsingLeadingPion", "DiscriminationByECALIsolationUsingLeadingPion"),
101  ("byIsolationUsingLeadingPion", "DiscriminationByIsolationUsingLeadingPion")
102 ]
103 
104 # Hadron-plus-strip(s) (HPS) Tau Discriminators
105 hpsTauIDSources = [
106  ("decayModeFindingNewDMs", "DiscriminationByDecayModeFindingNewDMs"),
107  ("decayModeFinding", "DiscriminationByDecayModeFinding"), # CV: kept for backwards compatibility
108  ("byLooseCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"),
109  ("byMediumCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"),
110  ("byTightCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"),
111  ("byCombinedIsolationDeltaBetaCorrRaw3Hits", "DiscriminationByRawCombinedIsolationDBSumPtCorr3Hits"),
112  ("byLoosePileupWeightedIsolation3Hits", "DiscriminationByLoosePileupWeightedIsolation3Hits"),
113  ("byMediumPileupWeightedIsolation3Hits", "DiscriminationByMediumPileupWeightedIsolation3Hits"),
114  ("byTightPileupWeightedIsolation3Hits", "DiscriminationByTightPileupWeightedIsolation3Hits"),
115  ("byPhotonPtSumOutsideSignalCone", "DiscriminationByPhotonPtSumOutsideSignalCone"),
116  ("byPileupWeightedIsolationRaw3Hits", "DiscriminationByRawPileupWeightedIsolation3Hits"),
117  ("chargedIsoPtSum", "ChargedIsoPtSum"),
118  ("neutralIsoPtSum", "NeutralIsoPtSum"),
119  ("puCorrPtSum", "PUcorrPtSum"),
120  ("neutralIsoPtSumWeight", "NeutralIsoPtSumWeight"),
121  ("footprintCorrection", "FootprintCorrection"),
122  ("photonPtSumOutsideSignalCone", "PhotonPtSumOutsideSignalCone"),
123  ##("byIsolationMVA3oldDMwoLTraw", "DiscriminationByIsolationMVA3oldDMwoLTraw"),
124  ##("byVLooseIsolationMVA3oldDMwoLT", "DiscriminationByVLooseIsolationMVA3oldDMwoLT"),
125  ##("byLooseIsolationMVA3oldDMwoLT", "DiscriminationByLooseIsolationMVA3oldDMwoLT"),
126  ##("byMediumIsolationMVA3oldDMwoLT", "DiscriminationByMediumIsolationMVA3oldDMwoLT"),
127  ##("byTightIsolationMVA3oldDMwoLT", "DiscriminationByTightIsolationMVA3oldDMwoLT"),
128  ##("byVTightIsolationMVA3oldDMwoLT", "DiscriminationByVTightIsolationMVA3oldDMwoLT"),
129  ##("byVVTightIsolationMVA3oldDMwoLT", "DiscriminationByVVTightIsolationMVA3oldDMwoLT"),
130  ("byIsolationMVA3oldDMwLTraw", "DiscriminationByIsolationMVA3oldDMwLTraw"),
131  ("byVLooseIsolationMVA3oldDMwLT", "DiscriminationByVLooseIsolationMVA3oldDMwLT"),
132  ("byLooseIsolationMVA3oldDMwLT", "DiscriminationByLooseIsolationMVA3oldDMwLT"),
133  ("byMediumIsolationMVA3oldDMwLT", "DiscriminationByMediumIsolationMVA3oldDMwLT"),
134  ("byTightIsolationMVA3oldDMwLT", "DiscriminationByTightIsolationMVA3oldDMwLT"),
135  ("byVTightIsolationMVA3oldDMwLT", "DiscriminationByVTightIsolationMVA3oldDMwLT"),
136  ("byVVTightIsolationMVA3oldDMwLT", "DiscriminationByVVTightIsolationMVA3oldDMwLT"),
137  ("byIsolationMVA3newDMwoLTraw", "DiscriminationByIsolationMVA3newDMwoLTraw"),
138  ##("byVLooseIsolationMVA3newDMwoLT", "DiscriminationByVLooseIsolationMVA3newDMwoLT"),
139  ##("byLooseIsolationMVA3newDMwoLT", "DiscriminationByLooseIsolationMVA3newDMwoLT"),
140  ##("byMediumIsolationMVA3newDMwoLT", "DiscriminationByMediumIsolationMVA3newDMwoLT"),
141  ##("byTightIsolationMVA3newDMwoLT", "DiscriminationByTightIsolationMVA3newDMwoLT"),
142  ##("byVTightIsolationMVA3newDMwoLT", "DiscriminationByVTightIsolationMVA3newDMwoLT"),
143  ##("byVVTightIsolationMVA3newDMwoLT", "DiscriminationByVVTightIsolationMVA3newDMwoLT"),
144  ("byIsolationMVA3newDMwLTraw", "DiscriminationByIsolationMVA3newDMwLTraw"),
145  ("byVLooseIsolationMVA3newDMwLT", "DiscriminationByVLooseIsolationMVA3newDMwLT"),
146  ("byLooseIsolationMVA3newDMwLT", "DiscriminationByLooseIsolationMVA3newDMwLT"),
147  ("byMediumIsolationMVA3newDMwLT", "DiscriminationByMediumIsolationMVA3newDMwLT"),
148  ("byTightIsolationMVA3newDMwLT", "DiscriminationByTightIsolationMVA3newDMwLT"),
149  ("byVTightIsolationMVA3newDMwLT", "DiscriminationByVTightIsolationMVA3newDMwLT"),
150  ("byVVTightIsolationMVA3newDMwLT", "DiscriminationByVVTightIsolationMVA3newDMwLT"),
151  ##("againstElectronLoose", "DiscriminationByLooseElectronRejection"),
152  ##("againstElectronMedium", "DiscriminationByMediumElectronRejection"),
153  ##("againstElectronTight", "DiscriminationByTightElectronRejection"),
154  ("againstElectronMVA5raw", "DiscriminationByMVA5rawElectronRejection"),
155  ("againstElectronMVA5category", "DiscriminationByMVA5rawElectronRejection:category"),
156  ("againstElectronVLooseMVA5", "DiscriminationByMVA5VLooseElectronRejection"),
157  ("againstElectronLooseMVA5", "DiscriminationByMVA5LooseElectronRejection"),
158  ("againstElectronMediumMVA5", "DiscriminationByMVA5MediumElectronRejection"),
159  ("againstElectronTightMVA5", "DiscriminationByMVA5TightElectronRejection"),
160  ("againstElectronVTightMVA5", "DiscriminationByMVA5VTightElectronRejection"),
161  ##("againstElectronDeadECAL", "DiscriminationByDeadECALElectronRejection"),
162  ##("againstMuonLoose", "DiscriminationByLooseMuonRejection"),
163  ##("againstMuonMedium", "DiscriminationByMediumMuonRejection"),
164  ##("againstMuonTight", "DiscriminationByTightMuonRejection"),
165  ##("againstMuonLoose2", "DiscriminationByLooseMuonRejection2"),
166  ##("againstMuonMedium2", "DiscriminationByMediumMuonRejection2"),
167  ##("againstMuonTight2", "DiscriminationByTightMuonRejection2"),
168  ("againstMuonLoose3", "DiscriminationByLooseMuonRejection3"),
169  ("againstMuonTight3", "DiscriminationByTightMuonRejection3"),
170  ##("againstMuonMVAraw", "DiscriminationByMVArawMuonRejection"),
171  ##("againstMuonLooseMVA", "DiscriminationByMVALooseMuonRejection"),
172  ##("againstMuonMediumMVA", "DiscriminationByMVAMediumMuonRejection"),
173  ##("againstMuonTightMVA", "DiscriminationByMVATightMuonRejection")
174 ]
175 
176 #--------------------------------------------------------------------------------
177 # CV: define list of old and new tau ID discriminators for CMSSW 7_6_x reminiAOD v2
178 hpsTauIDSources76xReMiniAOD = [
179  ("decayModeFindingNewDMs", "DiscriminationByDecayModeFindingNewDMs76xReMiniAOD"),
180  ("decayModeFinding", "DiscriminationByDecayModeFinding76xReMiniAOD"), # CV: kept for backwards compatibility
181  ("byLooseCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits76xReMiniAOD"),
182  ("byMediumCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits76xReMiniAOD"),
183  ("byTightCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByTightCombinedIsolationDBSumPtCorr3Hits76xReMiniAOD"),
184  ("byCombinedIsolationDeltaBetaCorrRaw3Hits", "DiscriminationByRawCombinedIsolationDBSumPtCorr3Hits76xReMiniAOD"),
185  ("byLooseCombinedIsolationDeltaBetaCorr3HitsdR03", "DiscriminationByLooseCombinedIsolationDBSumPtCorr3HitsdR0376xReMiniAOD"),
186  ("byMediumCombinedIsolationDeltaBetaCorr3HitsdR03", "DiscriminationByMediumCombinedIsolationDBSumPtCorr3HitsdR0376xReMiniAOD"),
187  ("byTightCombinedIsolationDeltaBetaCorr3HitsdR03", "DiscriminationByTightCombinedIsolationDBSumPtCorr3HitsdR0376xReMiniAOD"),
188  ("byLoosePileupWeightedIsolation3Hits", "DiscriminationByLoosePileupWeightedIsolation3Hits76xReMiniAOD"),
189  ("byMediumPileupWeightedIsolation3Hits", "DiscriminationByMediumPileupWeightedIsolation3Hits76xReMiniAOD"),
190  ("byTightPileupWeightedIsolation3Hits", "DiscriminationByTightPileupWeightedIsolation3Hits76xReMiniAOD"),
191  ("byPhotonPtSumOutsideSignalCone", "DiscriminationByPhotonPtSumOutsideSignalCone76xReMiniAOD"),
192  ("byPileupWeightedIsolationRaw3Hits", "DiscriminationByRawPileupWeightedIsolation3Hits76xReMiniAOD"),
193  ("chargedIsoPtSum", "ChargedIsoPtSum76xReMiniAOD"),
194  ("neutralIsoPtSum", "NeutralIsoPtSum76xReMiniAOD"),
195  ("puCorrPtSum", "PUcorrPtSum76xReMiniAOD"),
196  ("neutralIsoPtSumWeight", "NeutralIsoPtSumWeight76xReMiniAOD"),
197  ("footprintCorrection", "FootprintCorrection76xReMiniAOD"),
198  ("photonPtSumOutsideSignalCone", "PhotonPtSumOutsideSignalCone76xReMiniAOD"),
199  ("byIsolationMVA3oldDMwLTraw", "DiscriminationByIsolationMVA3oldDMwLTraw76xReMiniAOD"),
200  ("byVLooseIsolationMVA3oldDMwLT", "DiscriminationByVLooseIsolationMVA3oldDMwLT76xReMiniAOD"),
201  ("byLooseIsolationMVA3oldDMwLT", "DiscriminationByLooseIsolationMVA3oldDMwLT76xReMiniAOD"),
202  ("byMediumIsolationMVA3oldDMwLT", "DiscriminationByMediumIsolationMVA3oldDMwLT76xReMiniAOD"),
203  ("byTightIsolationMVA3oldDMwLT", "DiscriminationByTightIsolationMVA3oldDMwLT76xReMiniAOD"),
204  ("byVTightIsolationMVA3oldDMwLT", "DiscriminationByVTightIsolationMVA3oldDMwLT76xReMiniAOD"),
205  ("byVVTightIsolationMVA3oldDMwLT", "DiscriminationByVVTightIsolationMVA3oldDMwLT76xReMiniAOD"),
206  ("byIsolationMVA3newDMwLTraw", "DiscriminationByIsolationMVA3newDMwLTraw76xReMiniAOD"),
207  ("byVLooseIsolationMVA3newDMwLT", "DiscriminationByVLooseIsolationMVA3newDMwLT76xReMiniAOD"),
208  ("byLooseIsolationMVA3newDMwLT", "DiscriminationByLooseIsolationMVA3newDMwLT76xReMiniAOD"),
209  ("byMediumIsolationMVA3newDMwLT", "DiscriminationByMediumIsolationMVA3newDMwLT76xReMiniAOD"),
210  ("byTightIsolationMVA3newDMwLT", "DiscriminationByTightIsolationMVA3newDMwLT76xReMiniAOD"),
211  ("byVTightIsolationMVA3newDMwLT", "DiscriminationByVTightIsolationMVA3newDMwLT76xReMiniAOD"),
212  ("byVVTightIsolationMVA3newDMwLT", "DiscriminationByVVTightIsolationMVA3newDMwLT76xReMiniAOD"),
213  ("againstElectronMVA5raw", "DiscriminationByMVA5rawElectronRejection76xReMiniAOD"),
214  ("againstElectronMVA5category", "DiscriminationByMVA5rawElectronRejection76xReMiniAOD:category"),
215  ("againstElectronVLooseMVA5", "DiscriminationByMVA5VLooseElectronRejection76xReMiniAOD"),
216  ("againstElectronLooseMVA5", "DiscriminationByMVA5LooseElectronRejection76xReMiniAOD"),
217  ("againstElectronMediumMVA5", "DiscriminationByMVA5MediumElectronRejection76xReMiniAOD"),
218  ("againstElectronTightMVA5", "DiscriminationByMVA5TightElectronRejection76xReMiniAOD"),
219  ("againstElectronVTightMVA5", "DiscriminationByMVA5VTightElectronRejection76xReMiniAOD"),
220  ("againstMuonLoose3", "DiscriminationByLooseMuonRejection376xReMiniAOD"),
221  ("againstMuonTight3", "DiscriminationByTightMuonRejection376xReMiniAOD"),
222  ##New Run2 MVA isolation
223  ("byIsolationMVArun2v1DBoldDMwLTraw", "DiscriminationByIsolationMVArun2v1DBoldDMwLTraw76xReMiniAOD"),
224  ("byVLooseIsolationMVArun2v1DBoldDMwLT", "DiscriminationByVLooseIsolationMVArun2v1DBoldDMwLT76xReMiniAOD"),
225  ("byLooseIsolationMVArun2v1DBoldDMwLT", "DiscriminationByLooseIsolationMVArun2v1DBoldDMwLT76xReMiniAOD"),
226  ("byMediumIsolationMVArun2v1DBoldDMwLT", "DiscriminationByMediumIsolationMVArun2v1DBoldDMwLT76xReMiniAOD"),
227  ("byTightIsolationMVArun2v1DBoldDMwLT", "DiscriminationByTightIsolationMVArun2v1DBoldDMwLT76xReMiniAOD"),
228  ("byVTightIsolationMVArun2v1DBoldDMwLT", "DiscriminationByVTightIsolationMVArun2v1DBoldDMwLT76xReMiniAOD"),
229  ("byVVTightIsolationMVArun2v1DBoldDMwLT", "DiscriminationByVVTightIsolationMVArun2v1DBoldDMwLT76xReMiniAOD"),
230  ("byIsolationMVArun2v1DBnewDMwLTraw", "DiscriminationByIsolationMVArun2v1DBnewDMwLTraw76xReMiniAOD"),
231  ("byVLooseIsolationMVArun2v1DBnewDMwLT", "DiscriminationByVLooseIsolationMVArun2v1DBnewDMwLT76xReMiniAOD"),
232  ("byLooseIsolationMVArun2v1DBnewDMwLT", "DiscriminationByLooseIsolationMVArun2v1DBnewDMwLT76xReMiniAOD"),
233  ("byMediumIsolationMVArun2v1DBnewDMwLT", "DiscriminationByMediumIsolationMVArun2v1DBnewDMwLT76xReMiniAOD"),
234  ("byTightIsolationMVArun2v1DBnewDMwLT", "DiscriminationByTightIsolationMVArun2v1DBnewDMwLT76xReMiniAOD"),
235  ("byVTightIsolationMVArun2v1DBnewDMwLT", "DiscriminationByVTightIsolationMVArun2v1DBnewDMwLT76xReMiniAOD"),
236  ("byVVTightIsolationMVArun2v1DBnewDMwLT", "DiscriminationByVVTightIsolationMVArun2v1DBnewDMwLT76xReMiniAOD"),
237  ("byIsolationMVArun2v1PWoldDMwLTraw", "DiscriminationByIsolationMVArun2v1PWoldDMwLTraw76xReMiniAOD"),
238  ("byVLooseIsolationMVArun2v1PWoldDMwLT", "DiscriminationByVLooseIsolationMVArun2v1PWoldDMwLT76xReMiniAOD"),
239  ("byLooseIsolationMVArun2v1PWoldDMwLT", "DiscriminationByLooseIsolationMVArun2v1PWoldDMwLT76xReMiniAOD"),
240  ("byMediumIsolationMVArun2v1PWoldDMwLT", "DiscriminationByMediumIsolationMVArun2v1PWoldDMwLT76xReMiniAOD"),
241  ("byTightIsolationMVArun2v1PWoldDMwLT", "DiscriminationByTightIsolationMVArun2v1PWoldDMwLT76xReMiniAOD"),
242  ("byVTightIsolationMVArun2v1PWoldDMwLT", "DiscriminationByVTightIsolationMVArun2v1PWoldDMwLT76xReMiniAOD"),
243  ("byVVTightIsolationMVArun2v1PWoldDMwLT", "DiscriminationByVVTightIsolationMVArun2v1PWoldDMwLT76xReMiniAOD"),
244  ("byIsolationMVArun2v1PWnewDMwLTraw", "DiscriminationByIsolationMVArun2v1PWnewDMwLTraw76xReMiniAOD"),
245  ("byVLooseIsolationMVArun2v1PWnewDMwLT", "DiscriminationByVLooseIsolationMVArun2v1PWnewDMwLT76xReMiniAOD"),
246  ("byLooseIsolationMVArun2v1PWnewDMwLT", "DiscriminationByLooseIsolationMVArun2v1PWnewDMwLT76xReMiniAOD"),
247  ("byMediumIsolationMVArun2v1PWnewDMwLT", "DiscriminationByMediumIsolationMVArun2v1PWnewDMwLT76xReMiniAOD"),
248  ("byTightIsolationMVArun2v1PWnewDMwLT", "DiscriminationByTightIsolationMVArun2v1PWnewDMwLT76xReMiniAOD"),
249  ("byVTightIsolationMVArun2v1PWnewDMwLT", "DiscriminationByVTightIsolationMVArun2v1PWnewDMwLT76xReMiniAOD"),
250  ("byVVTightIsolationMVArun2v1PWnewDMwLT", "DiscriminationByVVTightIsolationMVArun2v1PWnewDMwLT76xReMiniAOD"),
251  ("chargedIsoPtSumdR03", "ChargedIsoPtSumdR0376xReMiniAOD"),
252  ("neutralIsoPtSumdR03", "NeutralIsoPtSumdR0376xReMiniAOD"),
253  ("puCorrPtSumdR03", "PUcorrPtSumdR0376xReMiniAOD"),
254  ("neutralIsoPtSumWeightdR03", "NeutralIsoPtSumWeightdR0376xReMiniAOD"),
255  ("footprintCorrectiondR03", "FootprintCorrectiondR0376xReMiniAOD"),
256  ("photonPtSumOutsideSignalConedR03", "PhotonPtSumOutsideSignalConedR0376xReMiniAOD"),
257  ("byIsolationMVArun2v1DBdR03oldDMwLTraw", "DiscriminationByIsolationMVArun2v1DBdR03oldDMwLTraw76xReMiniAOD"),
258  ("byVLooseIsolationMVArun2v1DBdR03oldDMwLT", "DiscriminationByVLooseIsolationMVArun2v1DBdR03oldDMwLT76xReMiniAOD"),
259  ("byLooseIsolationMVArun2v1DBdR03oldDMwLT", "DiscriminationByLooseIsolationMVArun2v1DBdR03oldDMwLT76xReMiniAOD"),
260  ("byMediumIsolationMVArun2v1DBdR03oldDMwLT", "DiscriminationByMediumIsolationMVArun2v1DBdR03oldDMwLT76xReMiniAOD"),
261  ("byTightIsolationMVArun2v1DBdR03oldDMwLT", "DiscriminationByTightIsolationMVArun2v1DBdR03oldDMwLT76xReMiniAOD"),
262  ("byVTightIsolationMVArun2v1DBdR03oldDMwLT", "DiscriminationByVTightIsolationMVArun2v1DBdR03oldDMwLT76xReMiniAOD"),
263  ("byVVTightIsolationMVArun2v1DBdR03oldDMwLT", "DiscriminationByVVTightIsolationMVArun2v1DBdR03oldDMwLT76xReMiniAOD"),
264  ("byIsolationMVArun2v1PWdR03oldDMwLTraw", "DiscriminationByIsolationMVArun2v1PWdR03oldDMwLTraw76xReMiniAOD"),
265  ("byVLooseIsolationMVArun2v1PWdR03oldDMwLT", "DiscriminationByVLooseIsolationMVArun2v1PWdR03oldDMwLT76xReMiniAOD"),
266  ("byLooseIsolationMVArun2v1PWdR03oldDMwLT", "DiscriminationByLooseIsolationMVArun2v1PWdR03oldDMwLT76xReMiniAOD"),
267  ("byMediumIsolationMVArun2v1PWdR03oldDMwLT", "DiscriminationByMediumIsolationMVArun2v1PWdR03oldDMwLT76xReMiniAOD"),
268  ("byTightIsolationMVArun2v1PWdR03oldDMwLT", "DiscriminationByTightIsolationMVArun2v1PWdR03oldDMwLT76xReMiniAOD"),
269  ("byVTightIsolationMVArun2v1PWdR03oldDMwLT", "DiscriminationByVTightIsolationMVArun2v1PWdR03oldDMwLT76xReMiniAOD"),
270  ("byVVTightIsolationMVArun2v1PWdR03oldDMwLT", "DiscriminationByVVTightIsolationMVArun2v1PWdR03oldDMwLT76xReMiniAOD"),
271  ##New Run2 MVA discriminator against electrons
272  ("againstElectronMVA6raw", "DiscriminationByMVA6rawElectronRejection76xReMiniAOD"),
273  ("againstElectronMVA6category", "DiscriminationByMVA6rawElectronRejection76xReMiniAOD:category"),
274  ("againstElectronVLooseMVA6", "DiscriminationByMVA6VLooseElectronRejection76xReMiniAOD"),
275  ("againstElectronLooseMVA6", "DiscriminationByMVA6LooseElectronRejection76xReMiniAOD"),
276  ("againstElectronMediumMVA6", "DiscriminationByMVA6MediumElectronRejection76xReMiniAOD"),
277  ("againstElectronTightMVA6", "DiscriminationByMVA6TightElectronRejection76xReMiniAOD"),
278  ("againstElectronVTightMVA6", "DiscriminationByMVA6VTightElectronRejection76xReMiniAOD"),
279 ]
280 #--------------------------------------------------------------------------------
281 
282 # switch to PFTau collection produced for fixed dR = 0.07 signal cone size
283 def switchToPFTauFixedCone(process,
284  tauSource = cms.InputTag('fixedConePFTauProducer'),
285  patTauLabel = "",
286  postfix = ""):
287  fixedConeIDSources = copy.copy(classicTauIDSources)
288  fixedConeIDSources.extend(classicPFTauIDSources)
289 
290  _switchToPFTau(process, tauSource, 'fixedConePFTau', fixedConeIDSources,
291  patTauLabel = patTauLabel, postfix = postfix)
292 
293 # switch to PFTau collection produced for shrinking signal cone of size dR = 5.0/Et(PFTau)
294 def switchToPFTauShrinkingCone(process,
295  tauSource = cms.InputTag('shrinkingConePFTauProducer'),
296  patTauLabel = "",
297  postfix = ""):
298  shrinkingIDSources = copy.copy(classicTauIDSources)
299  shrinkingIDSources.extend(classicPFTauIDSources)
300 
301  _switchToPFTau(process, tauSource, 'shrinkingConePFTau', shrinkingIDSources,
302  patTauLabel = patTauLabel, postfix = postfix)
303 
304 # switch to hadron-plus-strip(s) (HPS) PFTau collection
305 def switchToPFTauHPS(process,
306  tauSource = cms.InputTag('hpsPFTauProducer'),
307  patTauLabel = "",
308  jecLevels = [],
309  postfix = ""):
310 
311  _switchToPFTau(process, tauSource, 'hpsPFTau', hpsTauIDSources,
312  patTauLabel = patTauLabel, postfix = postfix)
313 
314  # CV: enable tau lifetime information for HPS PFTaus
315  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = tauSource.value().replace("Producer", "TransverseImpactParameters")
316 
317  ## adapt cleanPatTaus
318  if hasattr(process, "cleanPatTaus" + patTauLabel + postfix):
319  getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \
320  'pt > 18 & abs(eta) < 2.3 & tauID("decayModeFinding") > 0.5 & tauID("byLooseCombinedIsolationDeltaBetaCorr3Hits") > 0.5' \
321  + ' & tauID("againstMuonTight3") > 0.5 & tauID("againstElectronVLooseMVA5") > 0.5'
322 
323 #--------------------------------------------------------------------------------
324 # CV: function called by PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
325 # to add old and new tau ID discriminators for CMSSW 7_6_x reminiAOD v2
326 def switchToPFTauHPS76xReMiniAOD(process,
327  tauSource = cms.InputTag('hpsPFTauProducer76xReMiniAOD'),
328  patTauLabel = "",
329  jecLevels = [],
330  postfix = ""):
331 
332  _switchToPFTau(process, tauSource, 'hpsPFTau', hpsTauIDSources76xReMiniAOD,
333  patTauLabel = patTauLabel, postfix = postfix)
334 
335  # CV: enable tau lifetime information for HPS PFTaus
336  applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = tauSource.value().replace("Producer", "TransverseImpactParameters")
337 
338  ## adapt cleanPatTaus
339  if hasattr(process, "cleanPatTaus" + patTauLabel + postfix):
340  getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \
341  'pt > 18 & abs(eta) < 2.3 & tauID("decayModeFinding") > 0.5 & tauID("byLooseCombinedIsolationDeltaBetaCorr3Hits") > 0.5' \
342  + ' & tauID("againstMuonTight3") > 0.5 & tauID("againstElectronVLooseMVA6") > 0.5'
343 #--------------------------------------------------------------------------------
344 
345 
346 # Select switcher by string
347 def switchToPFTauByType(process,
348  pfTauType = None,
349  tauSource = cms.InputTag('hpsPFTauProducer'),
350  patTauLabel = "",
351  postfix = "" ):
352  mapping = {
353  'shrinkingConePFTau' : switchToPFTauShrinkingCone,
354  'fixedConePFTau' : switchToPFTauFixedCone,
355  'hpsPFTau' : switchToPFTauHPS,
356  'caloRecoTau' : switchToCaloTau
357  }
358  if not pfTauType in mapping.keys():
359  raise ValueError("Error in <switchToPFTauByType>: Undefined pfTauType = %s !!" % pfTauType)
360 
361  mapping[pfTauType](process, tauSource = tauSource,
362  patTauLabel = patTauLabel, postfix = postfix)
363 
365 
366  """ Add a new collection of taus. Takes the configuration from the
367  already configured standard tau collection as starting point;
368  replaces before calling addTauCollection will also affect the
369  new tau collections
370  """
371  _label='addTauCollection'
372  _defaultParameters=dicttypes.SortedKeysDict()
373  def __init__(self):
374  ConfigToolBase.__init__(self)
375  self.addParameter(self._defaultParameters, 'tauCollection',
376  self._defaultValue, 'Input tau collection', cms.InputTag)
377  self.addParameter(self._defaultParameters, 'algoLabel',
378  self._defaultValue, "label to indicate the tau algorithm (e.g.'hps')", str)
379  self.addParameter(self._defaultParameters, 'typeLabel',
380  self._defaultValue, "label to indicate the type of constituents (either 'PFTau' or 'Tau')", str)
381  self.addParameter(self._defaultParameters, 'doPFIsoDeposits',
382  True, "run sequence for computing particle-flow based IsoDeposits")
383  self.addParameter(self._defaultParameters, 'standardAlgo',
384  "hps", "standard algorithm label of the collection from which the clones " \
385  + "for the new tau collection will be taken from " \
386  + "(note that this tau collection has to be available in the event before hand)")
387  self.addParameter(self._defaultParameters, 'standardType',
388  "PFTau", "standard constituent type label of the collection from which the clones " \
389  + " for the new tau collection will be taken from "\
390  + "(note that this tau collection has to be available in the event before hand)")
391 
392  self._parameters=copy.deepcopy(self._defaultParameters)
393  self._comment = ""
394 
396  return self._defaultParameters
397 
398  def __call__(self,process,
399  tauCollection = None,
400  algoLabel = None,
401  typeLabel = None,
402  doPFIsoDeposits = None,
403  jetCorrLabel = None,
404  standardAlgo = None,
405  standardType = None):
406 
407  if tauCollection is None:
408  tauCollection = self._defaultParameters['tauCollection'].value
409  if algoLabel is None:
410  algoLabel = self._defaultParameters['algoLabel'].value
411  if typeLabel is None:
412  typeLabel = self._defaultParameters['typeLabel'].value
413  if doPFIsoDeposits is None:
414  doPFIsoDeposits = self._defaultParameters['doPFIsoDeposits'].value
415  if standardAlgo is None:
416  standardAlgo = self._defaultParameters['standardAlgo'].value
417  if standardType is None:
418  standardType = self._defaultParameters['standardType'].value
419 
420  self.setParameter('tauCollection', tauCollection)
421  self.setParameter('algoLabel', algoLabel)
422  self.setParameter('typeLabel', typeLabel)
423  self.setParameter('doPFIsoDeposits', doPFIsoDeposits)
424  self.setParameter('standardAlgo', standardAlgo)
425  self.setParameter('standardType', standardType)
426 
427  self.apply(process)
428 
429  def toolCode(self, process):
430  tauCollection = self._parameters['tauCollection'].value
431  algoLabel = self._parameters['algoLabel'].value
432  typeLabel = self._parameters['typeLabel'].value
433  doPFIsoDeposits = self._parameters['doPFIsoDeposits'].value
434  standardAlgo = self._parameters['standardAlgo'].value
435  standardType = self._parameters['standardType'].value
436 
437  ## disable computation of particle-flow based IsoDeposits
438  ## in case tau is of CaloTau type
439  if typeLabel == 'Tau':
440  print "NO PF Isolation will be computed for CaloTau (this could be improved later)"
441  doPFIsoDeposits = False
442 
443  ## create old module label from standardAlgo
444  ## and standardType and return
445  def oldLabel(prefix = ''):
446  if prefix == '':
447  return "patTaus"
448  else:
449  return prefix + "PatTaus"
450 
451  ## capitalize first character of appended part
452  ## when creating new module label
453  ## (giving e.g. "patTausCaloRecoTau")
454  def capitalize(label):
455  return label[0].capitalize() + label[1:]
456 
457  ## create new module label from old module
458  ## label and return
459  def newLabel(oldLabel):
460  newLabel = oldLabel
461  if ( oldLabel.find(standardAlgo) >= 0 and oldLabel.find(standardType) >= 0 ):
462  oldLabel = oldLabel.replace(standardAlgo, algoLabel).replace(standardType, typeLabel)
463  else:
464  oldLabel = oldLabel + capitalize(algoLabel + typeLabel)
465  return oldLabel
466 
467  ## clone module and add it to the patDefaultSequence
468  def addClone(hook, **replaceStatements):
469  ## create a clone of the hook with corresponding
470  ## parameter replacements
471  newModule = getattr(process, hook).clone(**replaceStatements)
472 
473  ## clone module for computing particle-flow IsoDeposits
474  def addPFIsoDepositClone(hook, **replaceStatements):
475  newModule = getattr(process, hook).clone(**replaceStatements)
476  newModuleIsoDepositExtractor = getattr(newModule, "ExtractorPSet")
477  setattr(newModuleIsoDepositExtractor, "tauSource", getattr(newModule, "src"))
478 
479  ## add a clone of patTaus
480  addClone(oldLabel(), tauSource = tauCollection)
481 
482  ## add a clone of selectedPatTaus
483  addClone(oldLabel('selected'), src = cms.InputTag(newLabel(oldLabel())))
484 
485  ## add a clone of cleanPatTaus
486  addClone(oldLabel('clean'), src=cms.InputTag(newLabel(oldLabel('selected'))))
487 
488  ## get attributes of new module
489  newTaus = getattr(process, newLabel(oldLabel()))
490 
491  ## add a clone of gen tau matching
492  addClone('tauMatch', src = tauCollection)
493  addClone('tauGenJetMatch', src = tauCollection)
494 
495  ## add a clone of IsoDeposits computed based on particle-flow
496  if doPFIsoDeposits:
497  addPFIsoDepositClone('tauIsoDepositPFCandidates', src = tauCollection)
498  addPFIsoDepositClone('tauIsoDepositPFChargedHadrons', src = tauCollection)
499  addPFIsoDepositClone('tauIsoDepositPFNeutralHadrons', src = tauCollection)
500  addPFIsoDepositClone('tauIsoDepositPFGammas', src = tauCollection)
501 
502  ## fix label for input tag
503  def fixInputTag(x):
504  x.setModuleLabel(newLabel(x.moduleLabel))
505 
506  ## provide patTau inputs with individual labels
507  fixInputTag(newTaus.genParticleMatch)
508  fixInputTag(newTaus.genJetMatch)
509  fixInputTag(newTaus.isoDeposits.pfAllParticles)
510  fixInputTag(newTaus.isoDeposits.pfNeutralHadron)
511  fixInputTag(newTaus.isoDeposits.pfChargedHadron)
512  fixInputTag(newTaus.isoDeposits.pfGamma)
513  fixInputTag(newTaus.userIsolation.pfAllParticles.src)
514  fixInputTag(newTaus.userIsolation.pfNeutralHadron.src)
515  fixInputTag(newTaus.userIsolation.pfChargedHadron.src)
516  fixInputTag(newTaus.userIsolation.pfGamma.src)
517 
518  ## set discriminators
519  ## (using switchTauCollection functions)
520  oldTaus = getattr(process, oldLabel())
521  if typeLabel == 'Tau':
522  switchToCaloTau(process,
523  tauSource = getattr(newTaus, "tauSource"),
524  patTauLabel = capitalize(algoLabel + typeLabel))
525  else:
526  switchToPFTauByType(process, pfTauType = algoLabel + typeLabel,
527  tauSource = getattr(newTaus, "tauSource"),
528  patTauLabel = capitalize(algoLabel + typeLabel))
529 
530 addTauCollection=AddTauCollection()
def switchToPFTauFixedCone
Definition: tauTools.py:286
def applyPostfix
Definition: tauTools.py:8
def _switchToPFTau
Definition: tauTools.py:59
def switchToCaloTau
Definition: tauTools.py:20
def switchToPFTauHPS76xReMiniAOD
Definition: tauTools.py:330
def _buildIDSourcePSet
Definition: tauTools.py:43
def switchToPFTauHPS
Definition: tauTools.py:309
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def switchToPFTauShrinkingCone
Definition: tauTools.py:297
def switchToPFTauByType
Definition: tauTools.py:351