CMS 3D CMS Logo

runTauIdMVA.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import FWCore.ParameterSet.Config as cms
3 from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants
4 from RecoTauTag.RecoTau.PATTauDiscriminationByMVAIsolationRun2_cff import patDiscriminationByIsolationMVArun2v1raw, patDiscriminationByIsolationMVArun2v1
5 from RecoTauTag.RecoTau.DeepTau_cfi import DeepTau
6 from RecoTauTag.RecoTau.DeepTauIdSonicProducer_cfi import DeepTauIdSonicProducer
7 from RecoTauTag.RecoTau.tauIdWPsDefs import WORKING_POINTS_v2p1, WORKING_POINTS_v2p5, WORKING_POINTS_PHASEII_v2p5, WORKING_POINTS_BOOSTED_v2p0
8 
9 import os
10 import re
11 
13  """class to rerun the tau seq and acces trainings from the database"""
14  experimentalDiscriminators = [
15  "2017v1", "2017v2", "newDM2017v2", "dR0p32017v2", "2016v1", "newDM2016v1",
16  "againstEle2018"
17  ]
18  availableDiscriminators = experimentalDiscriminators.copy()
19  availableDiscriminators.extend([
20  "mvaIso", "mvaIsoNewDM", "mvaIsoDR0p3", #payloads from GT (2017v2)
21  "againstEle", #payloads from GT (2018)
22  "newDMPhase2v1", #payloads from phase2 GT
23  "againstElePhase2v1", #payloads from phase2 GT
24  "deepTau2017v2", "deepTau2017v2p1", "deepTau2018v2p5", "boostedDeepTauRunIIv2p0", "deepTau2026v2p5"
25  ])
26 
27  def __init__(self, process, debug = False,
28  originalTauName = "slimmedTaus",
29  updatedTauName = "slimmedTausNewID",
30  postfix = "",
31  toKeep = ["deepTau2017v2p1", "deepTau2018v2p5", "deepTau2026v2p5"],
32  conditionDB = "" # preparational DB: 'frontier://FrontierPrep/CMS_CONDITIONS'
33  ):
34  super(TauIDEmbedder, self).__init__()
35  self.process = process
36  self.debug = debug
37  self.originalTauName = originalTauName
38  self.updatedTauName = updatedTauName
39  self.postfix = postfix
40 
41  for discr in toKeep:
42  if discr not in TauIDEmbedder.availableDiscriminators:
43  raise RuntimeError('TauIDEmbedder: discriminator "{}" is not supported'.format(discr))
44  self.toKeep = toKeep
45  if not set(toKeep).isdisjoint(TauIDEmbedder.experimentalDiscriminators):
46  print('There are experimental tauIDs not from GT')
47  self.process.load('RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi')
48  if len(conditionDB) != 0:
49  self.process.CondDBTauConnection.connect = cms.string(conditionDB)
50  self.process.loadRecoTauTagMVAsFromPrepDB.connect = cms.string(conditionDB)
51  # if debug:
52  # print self.process.CondDBTauConnection.connect
53  # print dir(self.process.loadRecoTauTagMVAsFromPrepDB)
54  # print self.process.loadRecoTauTagMVAsFromPrepDB.parameterNames_
55 
56  @staticmethod
57  def get_cmssw_version(debug = False):
58  """returns 'CMSSW_X_Y_Z'"""
59  cmssw_version = os.environ["CMSSW_VERSION"]
60  if debug: print ("get_cmssw_version:", cmssw_version)
61  return cmssw_version
62 
63  @classmethod
64  def get_cmssw_version_number(klass, debug = False):
65  """returns '(release, subversion, patch)' (without 'CMSSW_')"""
66  v = klass.get_cmssw_version().split("CMSSW_")[1].split("_")[0:3]
67  if debug: print ("get_cmssw_version_number:", v)
68  try:
69  patch = int(v[2])
70  except:
71  patch = -1
72  return int(v[0]), int(v[1]), patch
73 
74  @staticmethod
75  def versionToInt(release=9, subversion=4, patch=0, debug = False):
76  version = release * 10000 + subversion * 100 + patch + 1 # shifted by one to account for pre-releases.
77  if debug: print ("versionToInt:", version)
78  return version
79 
80 
81  @classmethod
82  def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug = False):
83  split_cmssw_version = klass.get_cmssw_version_number()
84  if klass.versionToInt(release, subversion, patch) > klass.versionToInt(split_cmssw_version[0], split_cmssw_version[1], split_cmssw_version[2]):
85  if debug: print ("is_above_cmssw_version:", False)
86  return False
87  else:
88  if debug: print ("is_above_cmssw_version:", True)
89  return True
90 
91  def tauIDMVAinputs(self, module, wp):
92  return cms.PSet(inputTag = cms.InputTag(module), workingPointIndex = cms.int32(-1 if wp=="raw" else -2 if wp=="category" else getattr(self.process, module).workingPoints.index(wp)))
93 
95  if self.debug: print ("loadMVA_WPs_run2_2017: performed")
96  global cms
97  for training, gbrForestName in self.tauIdDiscrMVA_trainings_run2_2017.items():
98 
99  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
100  cms.PSet(
101  record = cms.string('GBRWrapperRcd'),
102  tag = cms.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
103  label = cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
104  )
105  )
106 
107  for WP in self.tauIdDiscrMVA_WPs_run2_2017[training].keys():
108  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
109  cms.PSet(
110  record = cms.string('PhysicsTGraphPayloadRcd'),
111  tag = cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)),
112  label = cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP))
113  )
114  )
115 
116  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
117  cms.PSet(
118  record = cms.string('PhysicsTFormulaPayloadRcd'),
119  tag = cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
120  label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
121  )
122  )
123 
125  if self.debug: print ("load_againstElectronMVA6: performed")
126  global cms
127  antiElectronDiscrMVA6_categories = {
128  '0' : "gbr_NoEleMatch_woGwoGSF_BL",
129  '2' : "gbr_NoEleMatch_wGwoGSF_BL",
130  '5' : "gbr_woGwGSF_BL",
131  '7' : "gbr_wGwGSF_BL",
132  '8' : "gbr_NoEleMatch_woGwoGSF_EC",
133  '10' : "gbr_NoEleMatch_wGwoGSF_EC",
134  '13' : "gbr_woGwGSF_EC",
135  '15' : "gbr_wGwGSF_EC"
136  }
137  for category, gbrForestName in antiElectronDiscrMVA6_categories.items():
138  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
139  cms.PSet(
140  record = cms.string('GBRWrapperRcd'),
141  tag = cms.string("RecoTauTag_antiElectronMVA6%s_%s" % (self.antiElectronDiscrMVA6_version, gbrForestName)),
142  label = cms.untracked.string("RecoTauTag_antiElectronMVA6%s_%s" % (self.antiElectronDiscrMVA6_version, gbrForestName))
143  )
144  )
145  for WP in self.antiElectronDiscrMVA6_WPs:
146  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
147  cms.PSet(
148  record = cms.string('PhysicsTGraphPayloadRcd'),
149  tag = cms.string("RecoTauTag_antiElectronMVA6%s_%s_WP%s" % (self.antiElectronDiscrMVA6_version, gbrForestName, WP)),
150  label = cms.untracked.string("RecoTauTag_antiElectronMVA6%s_%s_WP%s" % (self.antiElectronDiscrMVA6_version, gbrForestName, WP))
151  )
152  )
153 
154  def runTauID(self):
155  _rerunMvaIsolationTask = cms.Task()
156  _rerunMvaIsolationSequence = cms.Sequence()
157  tauIDSources = cms.PSet()
158 
159  # MVAIso tauIDs with version given by payloads in GT (2017v2)
160  if "mvaIso" in self.toKeep:
161  _byIsolationOldDMMVAraw = "rerunDiscriminationByIsolationOldDMMVAraw"+self.postfix
162  setattr(self.process,_byIsolationOldDMMVAraw,patDiscriminationByIsolationMVArun2v1raw.clone(
163  PATTauProducer = self.originalTauName,
164  Prediscriminants = noPrediscriminants,
165  loadMVAfromDB = cms.bool(True),
166  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT"),
167  mvaOpt = cms.string("DBoldDMwLTwGJ"),
168  verbosity = cms.int32(0)
169  ))
170 
171  _byIsolationOldDMMVA = "rerunDiscriminationByIsolationOldDMMVA"+self.postfix
172  setattr(self.process,_byIsolationOldDMMVA,patDiscriminationByIsolationMVArun2v1.clone(
173  PATTauProducer = self.originalTauName,
174  Prediscriminants = noPrediscriminants,
175  toMultiplex = _byIsolationOldDMMVAraw,
176  loadMVAfromDB = cms.bool(True),
177  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
178  mapping = cms.VPSet(
179  cms.PSet(
180  category = cms.uint32(0),
181  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT"), #writeTauIdDiscrWPs
182  variable = cms.string("pt"),
183  )
184  ),
185  workingPoints = cms.vstring(
186  "_VVLoose",
187  "_VLoose",
188  "_Loose",
189  "_Medium",
190  "_Tight",
191  "_VTight",
192  "_VVTight"
193  )
194  ))
195 
196  _rerunIsolationOldDMMVATask = cms.Task(
197  getattr(self.process,_byIsolationOldDMMVAraw),
198  getattr(self.process,_byIsolationOldDMMVA)
199  )
200  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVATask)
201  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVATask)
202 
203  tauIDSources.byIsolationMVArun2DBoldDMwLTraw = self.tauIDMVAinputs(_byIsolationOldDMMVA, "raw")
204  tauIDSources.byVVLooseIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VVLoose")
205  tauIDSources.byVLooseIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VLoose")
206  tauIDSources.byLooseIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_Loose")
207  tauIDSources.byMediumIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_Medium")
208  tauIDSources.byTightIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_Tight")
209  tauIDSources.byVTightIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VTight")
210  tauIDSources.byVVTightIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VVTight")
211 
212  if "mvaIsoNewDM" in self.toKeep:
213  _byIsolationNewDMMVAraw = "rerunDiscriminationByIsolationNewDMMVAraw"+self.postfix
214  setattr(self.process,_byIsolationNewDMMVAraw,patDiscriminationByIsolationMVArun2v1raw.clone(
215  PATTauProducer = self.originalTauName,
216  Prediscriminants = noPrediscriminants,
217  loadMVAfromDB = cms.bool(True),
218  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT"),
219  mvaOpt = cms.string("DBnewDMwLTwGJ"),
220  verbosity = cms.int32(0)
221  ))
222 
223  _byIsolationNewDMMVA = "rerunDiscriminationByIsolationNewDMMVA"+self.postfix
224  setattr(self.process,_byIsolationNewDMMVA,patDiscriminationByIsolationMVArun2v1.clone(
225  PATTauProducer = self.originalTauName,
226  Prediscriminants = noPrediscriminants,
227  toMultiplex = _byIsolationNewDMMVAraw,
228  loadMVAfromDB = cms.bool(True),
229  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
230  mapping = cms.VPSet(
231  cms.PSet(
232  category = cms.uint32(0),
233  cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT"), #writeTauIdDiscrWPs
234  variable = cms.string("pt"),
235  )
236  ),
237  workingPoints = cms.vstring(
238  "_VVLoose",
239  "_VLoose",
240  "_Loose",
241  "_Medium",
242  "_Tight",
243  "_VTight",
244  "_VVTight"
245  )
246  ))
247 
248  _rerunIsolationNewDMMVATask = cms.Task(
249  getattr(self.process,_byIsolationNewDMMVAraw),
250  getattr(self.process,_byIsolationNewDMMVA)
251  )
252  _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVATask)
253  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVATask)
254 
255  tauIDSources.byIsolationMVArun2DBnewDMwLTraw = self.tauIDMVAinputs(_byIsolationNewDMMVA, "raw")
256  tauIDSources.byVVLooseIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VVLoose")
257  tauIDSources.byVLooseIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VLoose")
258  tauIDSources.byLooseIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_Loose")
259  tauIDSources.byMediumIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_Medium")
260  tauIDSources.byTightIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_Tight")
261  tauIDSources.byVTightIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VTight")
262  tauIDSources.byVVTightIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VVTight")
263 
264  if "mvaIsoDR0p3" in self.toKeep:
265  _byIsolationOldDMdR0p3MVAraw = "rerunDiscriminationByIsolationOldDMdR0p3MVAraw"+self.postfix
266  setattr(self.process,_byIsolationOldDMdR0p3MVAraw,patDiscriminationByIsolationMVArun2v1raw.clone(
267  PATTauProducer = self.originalTauName,
268  Prediscriminants = noPrediscriminants,
269  loadMVAfromDB = cms.bool(True),
270  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT"),
271  mvaOpt = cms.string("DBoldDMwLTwGJ"),
272  srcChargedIsoPtSum = cms.string('chargedIsoPtSumdR03'),
273  srcFootprintCorrection = cms.string('footprintCorrectiondR03'),
274  srcNeutralIsoPtSum = cms.string('neutralIsoPtSumdR03'),
275  srcPhotonPtSumOutsideSignalCone = cms.string('photonPtSumOutsideSignalConedR03'),
276  verbosity = cms.int32(0)
277  ))
278 
279  _byIsolationOldDMdR0p3MVA = "rerunDiscriminationByIsolationOldDMdR0p3MVA"+self.postfix
280  setattr(self.process,_byIsolationOldDMdR0p3MVA,patDiscriminationByIsolationMVArun2v1.clone(
281  PATTauProducer = self.originalTauName,
282  Prediscriminants = noPrediscriminants,
283  toMultiplex = _byIsolationOldDMdR0p3MVAraw,
284  loadMVAfromDB = cms.bool(True),
285  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
286  mapping = cms.VPSet(
287  cms.PSet(
288  category = cms.uint32(0),
289  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT"), #writeTauIdDiscrWPs
290  variable = cms.string("pt"),
291  )
292  ),
293  workingPoints = cms.vstring(
294  "_VVLoose",
295  "_VLoose",
296  "_Loose",
297  "_Medium",
298  "_Tight",
299  "_VTight",
300  "_VVTight"
301  )
302  ))
303 
304  _rerunIsolationOldDMdR0p3MVATask = cms.Task(
305  getattr(self.process,_byIsolationOldDMdR0p3MVAraw),
306  getattr(self.process,_byIsolationOldDMdR0p3MVA)
307  )
308  _rerunMvaIsolationTask.add(_rerunIsolationOldDMdR0p3MVATask)
309  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMdR0p3MVATask)
310 
311  tauIDSources.byIsolationMVArun2DBoldDMdR0p3wLTraw = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "raw")
312  tauIDSources.byVVLooseIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VVLoose")
313  tauIDSources.byVLooseIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VLoose")
314  tauIDSources.byLooseIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_Loose")
315  tauIDSources.byMediumIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_Medium")
316  tauIDSources.byTightIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_Tight")
317  tauIDSources.byVTightIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VTight")
318  tauIDSources.byVVTightIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VVTight")
319 
320  # rerun the seq to obtain the 2017 nom training with 0.5 iso cone, old DM, ptph>1, trained on 2017MCv1
321  if "2017v1" in self.toKeep:
324  'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
325  }
327  'tauIdMVAIsoDBoldDMwLT2017' : {
328  'Eff95' : "DBoldDMwLTEff95",
329  'Eff90' : "DBoldDMwLTEff90",
330  'Eff80' : "DBoldDMwLTEff80",
331  'Eff70' : "DBoldDMwLTEff70",
332  'Eff60' : "DBoldDMwLTEff60",
333  'Eff50' : "DBoldDMwLTEff50",
334  'Eff40' : "DBoldDMwLTEff40"
335  }
336  }
337  # update the list of available in DB samples
338  if self.debug: print ("runTauID: Will update the list of available in DB samples to access 2017v1")
339  self.loadMVA_WPs_run2_2017()
340 
341  _byIsolationOldDMMVArun2017v1raw = "rerunDiscriminationByIsolationOldDMMVArun2017v1raw"+self.postfix
342  setattr(self.process,_byIsolationOldDMMVArun2017v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
343  PATTauProducer = self.originalTauName,
344  Prediscriminants = noPrediscriminants,
345  loadMVAfromDB = cms.bool(True),
346  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"),
347  mvaOpt = cms.string("DBoldDMwLTwGJ"),
348  verbosity = cms.int32(0)
349  ))
350 
351  _byIsolationOldDMMVArun2017v1 = "rerunDiscriminationByIsolationOldDMMVArun2017v1"+self.postfix
352  setattr(self.process,_byIsolationOldDMMVArun2017v1,patDiscriminationByIsolationMVArun2v1.clone(
353  PATTauProducer = self.originalTauName,
354  Prediscriminants = noPrediscriminants,
355  toMultiplex = _byIsolationOldDMMVArun2017v1raw,
356  loadMVAfromDB = cms.bool(True),
357  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
358  mapping = cms.VPSet(
359  cms.PSet(
360  category = cms.uint32(0),
361  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"), #writeTauIdDiscrWPs
362  variable = cms.string("pt"),
363  )
364  ),
365  workingPoints = cms.vstring(
366  "_WPEff95",
367  "_WPEff90",
368  "_WPEff80",
369  "_WPEff70",
370  "_WPEff60",
371  "_WPEff50",
372  "_WPEff40"
373  )
374  ))
375 
376  _rerunIsolationOldDMMVArun2017v1Task = cms.Task(
377  getattr(self.process,_byIsolationOldDMMVArun2017v1raw),
378  getattr(self.process,_byIsolationOldDMMVArun2017v1)
379  )
380  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v1Task)
381  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2017v1Task)
382 
383  tauIDSources.byIsolationMVArun2017v1DBoldDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "raw")
384  tauIDSources.byVVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff95")
385  tauIDSources.byVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff90")
386  tauIDSources.byLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff80")
387  tauIDSources.byMediumIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff70")
388  tauIDSources.byTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff60")
389  tauIDSources.byVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff50")
390  tauIDSources.byVVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff40")
391 
392  if "2017v2" in self.toKeep:
393  self.tauIdDiscrMVA_2017_version = "v2"
395  'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
396  }
398  'tauIdMVAIsoDBoldDMwLT2017' : {
399  'Eff95' : "DBoldDMwLTEff95",
400  'Eff90' : "DBoldDMwLTEff90",
401  'Eff80' : "DBoldDMwLTEff80",
402  'Eff70' : "DBoldDMwLTEff70",
403  'Eff60' : "DBoldDMwLTEff60",
404  'Eff50' : "DBoldDMwLTEff50",
405  'Eff40' : "DBoldDMwLTEff40"
406  }
407  }
408 
409  if self.debug: print ("runTauID: Will update the list of available in DB samples to access 2017v2")
410  self.loadMVA_WPs_run2_2017()
411 
412  _byIsolationOldDMMVArun2017v2raw = "rerunDiscriminationByIsolationOldDMMVArun2017v2raw"+self.postfix
413  setattr(self.process,_byIsolationOldDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
414  PATTauProducer = self.originalTauName,
415  Prediscriminants = noPrediscriminants,
416  loadMVAfromDB = cms.bool(True),
417  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"),
418  mvaOpt = cms.string("DBoldDMwLTwGJ"),
419  verbosity = cms.int32(0)
420  ))
421 
422  _byIsolationOldDMMVArun2017v2 = "rerunDiscriminationByIsolationOldDMMVArun2017v2"+self.postfix
423  setattr(self.process,_byIsolationOldDMMVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
424  PATTauProducer = self.originalTauName,
425  Prediscriminants = noPrediscriminants,
426  toMultiplex = _byIsolationOldDMMVArun2017v2raw,
427  loadMVAfromDB = cms.bool(True),
428  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
429  mapping = cms.VPSet(
430  cms.PSet(
431  category = cms.uint32(0),
432  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"), #writeTauIdDiscrWPs
433  variable = cms.string("pt"),
434  )
435  ),
436  workingPoints = cms.vstring(
437  "_WPEff95",
438  "_WPEff90",
439  "_WPEff80",
440  "_WPEff70",
441  "_WPEff60",
442  "_WPEff50",
443  "_WPEff40"
444  ),
445  verbosity = cms.int32(0)
446  ))
447 
448  _rerunIsolationOldDMMVArun2017v2Task = cms.Task(
449  getattr(self.process,_byIsolationOldDMMVArun2017v2raw),
450  getattr(self.process,_byIsolationOldDMMVArun2017v2)
451  )
452  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v2Task)
453  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2017v2Task)
454 
455  tauIDSources.byIsolationMVArun2017v2DBoldDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "raw")
456  tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff95")
457  tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff90")
458  tauIDSources.byLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff80")
459  tauIDSources.byMediumIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff70")
460  tauIDSources.byTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff60")
461  tauIDSources.byVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff50")
462  tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff40")
463 
464  if "newDM2017v2" in self.toKeep:
465  self.tauIdDiscrMVA_2017_version = "v2"
467  'tauIdMVAIsoDBnewDMwLT2017' : "tauIdMVAIsoDBnewDMwLT2017",
468  }
470  'tauIdMVAIsoDBnewDMwLT2017' : {
471  'Eff95' : "DBnewDMwLTEff95",
472  'Eff90' : "DBnewDMwLTEff90",
473  'Eff80' : "DBnewDMwLTEff80",
474  'Eff70' : "DBnewDMwLTEff70",
475  'Eff60' : "DBnewDMwLTEff60",
476  'Eff50' : "DBnewDMwLTEff50",
477  'Eff40' : "DBnewDMwLTEff40"
478  }
479  }
480 
481  if self.debug: print ("runTauID: Will update the list of available in DB samples to access newDM2017v2")
482  self.loadMVA_WPs_run2_2017()
483 
484  _byIsolationNewDMMVArun2017v2raw = "rerunDiscriminationByIsolationNewDMMVArun2017v2raw"+self.postfix
485  setattr(self.process,_byIsolationNewDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
486  PATTauProducer = self.originalTauName,
487  Prediscriminants = noPrediscriminants,
488  loadMVAfromDB = cms.bool(True),
489  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"),
490  mvaOpt = cms.string("DBnewDMwLTwGJ"),
491  verbosity = cms.int32(0)
492  ))
493 
494  _byIsolationNewDMMVArun2017v2 = "rerunDiscriminationByIsolationNewDMMVArun2017v2"+self.postfix
495  setattr(self.process,_byIsolationNewDMMVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
496  PATTauProducer = self.originalTauName,
497  Prediscriminants = noPrediscriminants,
498  toMultiplex = _byIsolationNewDMMVArun2017v2raw,
499  loadMVAfromDB = cms.bool(True),
500  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
501  mapping = cms.VPSet(
502  cms.PSet(
503  category = cms.uint32(0),
504  cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"), #writeTauIdDiscrWPs
505  variable = cms.string("pt"),
506  )
507  ),
508  workingPoints = cms.vstring(
509  "_WPEff95",
510  "_WPEff90",
511  "_WPEff80",
512  "_WPEff70",
513  "_WPEff60",
514  "_WPEff50",
515  "_WPEff40"
516  ),
517  verbosity = cms.int32(0)
518  ))
519 
520  _rerunIsolationNewDMMVArun2017v2Task = cms.Task(
521  getattr(self.process,_byIsolationNewDMMVArun2017v2raw),
522  getattr(self.process,_byIsolationNewDMMVArun2017v2)
523  )
524  _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2017v2Task)
525  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVArun2017v2Task)
526 
527  tauIDSources.byIsolationMVArun2017v2DBnewDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "raw")
528  tauIDSources.byVVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff95")
529  tauIDSources.byVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff90")
530  tauIDSources.byLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff80")
531  tauIDSources.byMediumIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff70")
532  tauIDSources.byTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff60")
533  tauIDSources.byVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff50")
534  tauIDSources.byVVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff40")
535 
536  if "dR0p32017v2" in self.toKeep:
537  self.tauIdDiscrMVA_2017_version = "v2"
539  'tauIdMVAIsoDBoldDMdR0p3wLT2017' : "tauIdMVAIsoDBoldDMdR0p3wLT2017",
540  }
542  'tauIdMVAIsoDBoldDMdR0p3wLT2017' : {
543  'Eff95' : "DBoldDMdR0p3wLTEff95",
544  'Eff90' : "DBoldDMdR0p3wLTEff90",
545  'Eff80' : "DBoldDMdR0p3wLTEff80",
546  'Eff70' : "DBoldDMdR0p3wLTEff70",
547  'Eff60' : "DBoldDMdR0p3wLTEff60",
548  'Eff50' : "DBoldDMdR0p3wLTEff50",
549  'Eff40' : "DBoldDMdR0p3wLTEff40"
550  }
551  }
552 
553  if self.debug: print ("runTauID: Will update the list of available in DB samples to access dR0p32017v2")
554  self.loadMVA_WPs_run2_2017()
555 
556  _byIsolationOldDMdR0p3MVArun2017v2raw = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw"+self.postfix
557  setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
558  PATTauProducer = self.originalTauName,
559  Prediscriminants = noPrediscriminants,
560  loadMVAfromDB = cms.bool(True),
561  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"),
562  mvaOpt = cms.string("DBoldDMwLTwGJ"),
563  srcChargedIsoPtSum = cms.string('chargedIsoPtSumdR03'),
564  srcFootprintCorrection = cms.string('footprintCorrectiondR03'),
565  srcNeutralIsoPtSum = cms.string('neutralIsoPtSumdR03'),
566  srcPhotonPtSumOutsideSignalCone = cms.string('photonPtSumOutsideSignalConedR03'),
567  verbosity = cms.int32(0)
568  ))
569 
570  _byIsolationOldDMdR0p3MVArun2017v2 = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2"+self.postfix
571  setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
572  PATTauProducer = self.originalTauName,
573  Prediscriminants = noPrediscriminants,
574  toMultiplex = _byIsolationOldDMdR0p3MVArun2017v2raw,
575  loadMVAfromDB = cms.bool(True),
576  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
577  mapping = cms.VPSet(
578  cms.PSet(
579  category = cms.uint32(0),
580  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"), #writeTauIdDiscrWPs
581  variable = cms.string("pt"),
582  )
583  ),
584  workingPoints = cms.vstring(
585  "_WPEff95",
586  "_WPEff90",
587  "_WPEff80",
588  "_WPEff70",
589  "_WPEff60",
590  "_WPEff50",
591  "_WPEff40"
592  ),
593  verbosity = cms.int32(0)
594  ))
595 
596  _rerunIsolationOldDMdR0p3MVArun2017v2Task = cms.Task(
597  getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw),
598  getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2)
599  )
600  _rerunMvaIsolationTask.add(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
601  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
602 
603  tauIDSources.byIsolationMVArun2017v2DBoldDMdR0p3wLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "raw")
604  tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff95")
605  tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff90")
606  tauIDSources.byLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff80")
607  tauIDSources.byMediumIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff70")
608  tauIDSources.byTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff60")
609  tauIDSources.byVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff50")
610  tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff40")
611 
612  # 2016 training strategy(v2) - essentially the same as 2017 training strategy (v1), trained on 2016MC, old DM - currently not implemented in the tau sequence of any release
613  # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2raw = patDiscriminationByIsolationMVArun2v1raw.clone(
614  # PATTauProducer = self.originalTauName,
615  # Prediscriminants = noPrediscriminants,
616  # loadMVAfromDB = cms.bool(True),
617  # mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2"),
618  # mvaOpt = cms.string("DBoldDMwLTwGJ"),
619  # verbosity = cms.int32(0)
620  # )
621  # #
622  # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2VLoose = patDiscriminationByIsolationMVArun2v1VLoose.clone(
623  # PATTauProducer = self.originalTauName,
624  # Prediscriminants = noPrediscriminants,
625  # toMultiplex = 'rerunDiscriminationByIsolationOldDMMVArun2v2raw',
626  # key = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw:category'),#?
627  # loadMVAfromDB = cms.bool(True),
628  # mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
629  # mapping = cms.VPSet(
630  # cms.PSet(
631  # category = cms.uint32(0),
632  # cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_WPEff90"), #writeTauIdDiscrWPs
633  # variable = cms.string("pt"),
634  # )
635  # )
636  # )
637 
638  # 2016 training strategy(v1), trained on 2016MC, old DM
639  if "2016v1" in self.toKeep:
640  _byIsolationOldDMMVArun2016v1raw = "rerunDiscriminationByIsolationOldDMMVArun2v1raw"+self.postfix
641  setattr(self.process,_byIsolationOldDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
642  PATTauProducer = self.originalTauName,
643  Prediscriminants = noPrediscriminants,
644  loadMVAfromDB = cms.bool(True),
645  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"),
646  mvaOpt = cms.string("DBoldDMwLT"),
647  verbosity = cms.int32(0)
648  ))
649 
650  _byIsolationOldDMMVArun2016v1 = "rerunDiscriminationByIsolationOldDMMVArun2v1"+self.postfix
651  setattr(self.process,_byIsolationOldDMMVArun2016v1,patDiscriminationByIsolationMVArun2v1.clone(
652  PATTauProducer = self.originalTauName,
653  Prediscriminants = noPrediscriminants,
654  toMultiplex = _byIsolationOldDMMVArun2016v1raw,
655  loadMVAfromDB = cms.bool(True),
656  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_mvaOutput_normalization"),
657  mapping = cms.VPSet(
658  cms.PSet(
659  category = cms.uint32(0),
660  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"),
661  variable = cms.string("pt"),
662  )
663  ),
664  workingPoints = cms.vstring(
665  "_WPEff90",
666  "_WPEff80",
667  "_WPEff70",
668  "_WPEff60",
669  "_WPEff50",
670  "_WPEff40"
671  )
672  ))
673 
674  self.tauIdDiscrMVA_2017_version = "v1"
676  'tauIdMVAIsoDBoldDMwLT2016' : "tauIdMVAIsoDBoldDMwLT2016",
677  }
679  'tauIdMVAIsoDBoldDMwLT2016' : {
680  'Eff90' : "DBoldDMwLT2016Eff90",
681  'Eff80' : "DBoldDMwLT2016Eff80",
682  'Eff70' : "DBoldDMwLT2016Eff70",
683  'Eff60' : "DBoldDMwLT2016Eff60",
684  'Eff50' : "DBoldDMwLT2016Eff50",
685  'Eff40' : "DBoldDMwLT2016Eff40"
686  }
687  }
688  if self.debug: print ("runTauID: Will update the list of available in DB samples to access 2016v1")
689  self.loadMVA_WPs_run2_2017()
690 
691  _rerunIsolationOldDMMVArun2016v1Task = cms.Task(
692  getattr(self.process,_byIsolationOldDMMVArun2016v1raw),
693  getattr(self.process,_byIsolationOldDMMVArun2016v1)
694  )
695  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2016v1Task)
696  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2016v1Task)
697 
698  tauIDSources.byIsolationMVArun2v1DBoldDMwLTraw2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "raw")
699  tauIDSources.byVLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff90")
700  tauIDSources.byLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff80")
701  tauIDSources.byMediumIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff70")
702  tauIDSources.byTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff60")
703  tauIDSources.byVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff50")
704  tauIDSources.byVVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff40")
705 
706  # 2016 training strategy(v1), trained on 2016MC, new DM
707  if "newDM2016v1" in self.toKeep:
708  _byIsolationNewDMMVArun2016v1raw = "rerunDiscriminationByIsolationNewDMMVArun2v1raw"+self.postfix
709  setattr(self.process,_byIsolationNewDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
710  PATTauProducer = self.originalTauName,
711  Prediscriminants = noPrediscriminants,
712  loadMVAfromDB = cms.bool(True),
713  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"),
714  mvaOpt = cms.string("DBnewDMwLT"),
715  verbosity = cms.int32(0)
716  ))
717 
718  _byIsolationNewDMMVArun2016v1 = "rerunDiscriminationByIsolationNewDMMVArun2v1"+self.postfix
719  setattr(self.process,_byIsolationNewDMMVArun2016v1,patDiscriminationByIsolationMVArun2v1.clone(
720  PATTauProducer = self.originalTauName,
721  Prediscriminants = noPrediscriminants,
722  toMultiplex = _byIsolationNewDMMVArun2016v1raw,
723  loadMVAfromDB = cms.bool(True),
724  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_mvaOutput_normalization"),
725  mapping = cms.VPSet(
726  cms.PSet(
727  category = cms.uint32(0),
728  cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"),
729  variable = cms.string("pt"),
730  )
731  ),
732  workingPoints = cms.vstring(
733  "_WPEff90",
734  "_WPEff80",
735  "_WPEff70",
736  "_WPEff60",
737  "_WPEff50",
738  "_WPEff40"
739  )
740  ))
741 
742  self.tauIdDiscrMVA_2017_version = "v1"
744  'tauIdMVAIsoDBnewDMwLT2016' : "tauIdMVAIsoDBnewDMwLT2016",
745  }
747  'tauIdMVAIsoDBnewDMwLT2016' : {
748  'Eff90' : "DBnewDMwLT2016Eff90",
749  'Eff80' : "DBnewDMwLT2016Eff80",
750  'Eff70' : "DBnewDMwLT2016Eff70",
751  'Eff60' : "DBnewDMwLT2016Eff60",
752  'Eff50' : "DBnewDMwLT2016Eff50",
753  'Eff40' : "DBnewDMwLT2016Eff40"
754  }
755  }
756  if self.debug: print ("runTauID: Will update the list of available in DB samples to access newDM2016v1")
757  self.loadMVA_WPs_run2_2017()
758 
759  _rerunIsolationNewDMMVArun2016v1Task = cms.Task(
760  getattr(self.process,_byIsolationNewDMMVArun2016v1raw),
761  getattr(self.process,_byIsolationNewDMMVArun2016v1)
762  )
763  _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2016v1Task)
764  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVArun2016v1Task)
765 
766  tauIDSources.byIsolationMVArun2v1DBnewDMwLTraw2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "raw")
767  tauIDSources.byVLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff90")
768  tauIDSources.byLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff80")
769  tauIDSources.byMediumIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff70")
770  tauIDSources.byTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff60")
771  tauIDSources.byVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff50")
772  tauIDSources.byVVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff40")
773 
774  if "deepTau2017v2" in self.toKeep:
775  if self.debug: print ("Adding DeepTau v2 IDs")
776 
777  _deepTauName = "deepTau2017v2"
778  workingPoints_ = WORKING_POINTS_v2p1
779 
780  file_names = [
781  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
782  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
783  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
784  ]
785  full_version = self.getDeepTauVersion(file_names[0])
786  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
787  Prediscriminants = noPrediscriminants,
788  taus = self.originalTauName,
789  graph_file = file_names,
790  year = full_version[0],
791  version = full_version[1],
792  sub_version = 1 #MB: subversion cannot be properly deduced from file names; it should be 1 also for v2
793  ))
794 
795  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
796 
797  from Configuration.ProcessModifiers.deepTauSonicTriton_cff import deepTauSonicTriton
798  deepTauSonicTriton.toReplaceWith(_deepTauProducer, DeepTauIdSonicProducer.clone(
799  Client = cms.PSet(
800  mode = cms.string('PseudoAsync'),
801  allowedTries = cms.untracked.uint32(0),
802  verbose = cms.untracked.bool(False),
803  modelName = cms.string("deeptau_2017v2p1"),
804  modelVersion = cms.string(''),
805  modelConfigPath = cms.FileInPath("RecoTauTag/TrainingFiles/data/DeepTauIdSONIC/deeptau_2017v2p1/config.pbtxt"),
806  preferredServer = cms.untracked.string(''),
807  timeout = cms.untracked.uint32(300),
808  useSharedMemory = cms.untracked.bool(True),
809  compression = cms.untracked.string(''),
810  outputs = cms.untracked.vstring()
811  ),
812  Prediscriminants = noPrediscriminants,
813  taus = self.originalTauName,
814  year = full_version[0],
815  version = full_version[1],
816  sub_version = 1, #MB: subversion cannot be properly deduced from file names
817  ))
818 
819  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
820 
821  _rerunMvaIsolationTask.add(_deepTauProducer)
822  _rerunMvaIsolationSequence += _deepTauProducer
823 
824 
825  if "deepTau2017v2p1" in self.toKeep:
826  if self.debug: print ("Adding DeepTau v2p1 IDs")
827 
828  _deepTauName = "deepTau2017v2p1"
829  workingPoints_ = WORKING_POINTS_v2p1
830 
831  file_names = [
832  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
833  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
834  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
835  ]
836  full_version = self.getDeepTauVersion(file_names[0])
837  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
838  Prediscriminants = noPrediscriminants,
839  taus = self.originalTauName,
840  graph_file = file_names,
841  year = full_version[0],
842  version = full_version[1],
843  sub_version = 1, #MB: subversion cannot be properly deduced from file names
844  disable_dxy_pca = True
845  ))
846 
847  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
848 
849  from Configuration.ProcessModifiers.deepTauSonicTriton_cff import deepTauSonicTriton
850  deepTauSonicTriton.toReplaceWith(_deepTauProducer, DeepTauIdSonicProducer.clone(
851  Client = cms.PSet(
852  mode = cms.string('PseudoAsync'),
853  allowedTries = cms.untracked.uint32(0),
854  verbose = cms.untracked.bool(False),
855  modelName = cms.string("deeptau_2017v2p1"),
856  modelVersion = cms.string(''),
857  modelConfigPath = cms.FileInPath("RecoTauTag/TrainingFiles/data/DeepTauIdSONIC/deeptau_2017v2p1/config.pbtxt"),
858  preferredServer = cms.untracked.string(''),
859  timeout = cms.untracked.uint32(300),
860  useSharedMemory = cms.untracked.bool(True),
861  compression = cms.untracked.string(''),
862  outputs = cms.untracked.vstring()
863  ),
864  Prediscriminants = noPrediscriminants,
865  taus = self.originalTauName,
866  year = full_version[0],
867  version = full_version[1],
868  sub_version = 1, #MB: subversion cannot be properly deduced from file names
869  disable_dxy_pca = True
870  ))
871 
872  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
873 
874  _rerunMvaIsolationTask.add(_deepTauProducer)
875  _rerunMvaIsolationSequence += _deepTauProducer
876 
877  if "deepTau2018v2p5" in self.toKeep:
878  if self.debug: print ("Adding DeepTau v2p5 IDs")
879 
880  _deepTauName = "deepTau2018v2p5"
881  workingPoints_ = WORKING_POINTS_v2p5
882 
883  file_names = [
884  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_core.pb',
885  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_inner.pb',
886  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_outer.pb',
887  ]
888  full_version = self.getDeepTauVersion(file_names[0])
889  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
890  Prediscriminants = noPrediscriminants,
891  taus = self.originalTauName,
892  graph_file = file_names,
893  year = full_version[0],
894  version = full_version[1],
895  sub_version = full_version[2],
896  disable_dxy_pca = True,
897  disable_hcalFraction_workaround = True,
898  disable_CellIndex_workaround = True
899  ))
900 
901  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
902 
903  from Configuration.ProcessModifiers.deepTauSonicTriton_cff import deepTauSonicTriton
904  deepTauSonicTriton.toReplaceWith(_deepTauProducer, DeepTauIdSonicProducer.clone(
905  Client = cms.PSet(
906  mode = cms.string('PseudoAsync'),
907  allowedTries = cms.untracked.uint32(0),
908  verbose = cms.untracked.bool(False),
909  modelName = cms.string("deeptau_2018v2p5"),
910  modelVersion = cms.string(''),
911  modelConfigPath = cms.FileInPath("RecoTauTag/TrainingFiles/data/DeepTauIdSONIC/deeptau_2018v2p5/config.pbtxt"),
912  preferredServer = cms.untracked.string(''),
913  timeout = cms.untracked.uint32(300),
914  useSharedMemory = cms.untracked.bool(True),
915  compression = cms.untracked.string(''),
916  outputs = cms.untracked.vstring(),
917  ),
918  Prediscriminants = noPrediscriminants,
919  taus = self.originalTauName,
920  year = full_version[0],
921  version = full_version[1],
922  sub_version = full_version[2],
923  disable_dxy_pca = True,
924  disable_hcalFraction_workaround = True,
925  disable_CellIndex_workaround = True
926  ))
927 
928  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
929 
930  _rerunMvaIsolationTask.add(_deepTauProducer)
931  _rerunMvaIsolationSequence += _deepTauProducer
932 
933  if "boostedDeepTauRunIIv2p0" in self.toKeep:
934  if self.debug: print ("Adding BoostedDeepTau v2p0 IDs for boostedTaus")
935 
936  _deepTauName = "boostedDeepTau20161718v2p0"
937  workingPoints_ = WORKING_POINTS_BOOSTED_v2p0
938 
939  file_names = [
940  'core:RecoTauTag/TrainingFiles/data/BoostedDeepTauId/boosteddeepTau_RunIIv2p0_core.pb',
941  'inner:RecoTauTag/TrainingFiles/data/BoostedDeepTauId/boosteddeepTau_RunIIv2p0_inner.pb',
942  'outer:RecoTauTag/TrainingFiles/data/BoostedDeepTauId/boosteddeepTau_RunIIv2p0_outer.pb',
943  ]
944  full_version = self.getDeepTauVersion(file_names[0])
945  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
946  Prediscriminants = noPrediscriminants,
947  taus = self.originalTauName,
948  graph_file = file_names,
949  year = full_version[0],
950  version = full_version[1],
951  sub_version = full_version[2],
952  disable_dxy_pca = True,
953  disable_hcalFraction_workaround = True,
954  save_inputs = False,
955  disable_CellIndex_workaround = True
956  ))
957 
958  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
959 
960  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
961  _rerunMvaIsolationTask.add(_deepTauProducer)
962  _rerunMvaIsolationSequence += _deepTauProducer
963 
964  if "deepTau2026v2p5" in self.toKeep:
965  if self.debug: print ("Adding Phase2 DeepTau v2p5 IDs")
966 
967  _deepTauName = "deepTau2026v2p5"
968  workingPoints_ = WORKING_POINTS_PHASEII_v2p5
969 
970  file_names = [
971  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_core.pb',
972  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_inner.pb',
973  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_outer.pb',
974  ]
975  full_version = self.getDeepTauVersion(file_names[0])
976  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
977  Prediscriminants = noPrediscriminants,
978  taus = self.originalTauName,
979  graph_file = file_names,
980  year = full_version[0],
981  version = full_version[1],
982  sub_version = full_version[2],
983  disable_dxy_pca = True,
984  disable_hcalFraction_workaround = True,
985  disable_CellIndex_workaround = True
986  ))
987 
988  from RecoTauTag.RecoTau.mergedPhase2SlimmedElectronsForTauId_cff import mergedSlimmedElectronsForTauId
989  if not hasattr(self.process,"mergedSlimmedElectronsForTauId"):
990  self.process.mergedSlimmedElectronsForTauId = mergedSlimmedElectronsForTauId
991  setattr(getattr(self.process, _deepTauName+self.postfix), "electrons", cms.InputTag("mergedSlimmedElectronsForTauId"))
992  setattr(getattr(self.process, _deepTauName+self.postfix), "vertices", cms.InputTag("offlineSlimmedPrimaryVertices4D"))
993 
994  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
995 
996  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
997  _rerunMvaIsolationTask.add(self.process.mergedSlimmedElectronsForTauId)
998  _rerunMvaIsolationTask.add(_deepTauProducer)
999  _rerunMvaIsolationSequence += self.process.mergedSlimmedElectronsForTauId
1000  _rerunMvaIsolationSequence += _deepTauProducer
1001 
1002  if "againstEle2018" in self.toKeep:
1003  self.antiElectronDiscrMVA6_version = "v3_noeveto"
1004  self.antiElectronDiscrMVA6_WPs = [ "eff98", "eff90", "eff80", "eff70", "eff60" ]
1005 
1007  from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6
1008  _byElectronRejectionMVA62018Raw = "patTauDiscriminationByElectronRejectionMVA62018Raw"+self.postfix
1009  setattr(self.process,_byElectronRejectionMVA62018Raw,patTauDiscriminationAgainstElectronMVA6.clone(
1010  PATTauProducer = self.originalTauName,
1011  Prediscriminants = noPrediscriminants, #already selected for MiniAOD
1012  srcElectrons = cms.InputTag('slimmedElectrons'),
1013  vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks
1014  mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL',
1015  mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC',
1016  mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL',
1017  mvaName_NoEleMatch_woGwoGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC',
1018  mvaName_wGwGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL',
1019  mvaName_wGwGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC',
1020  mvaName_woGwGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL',
1021  mvaName_woGwGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'
1022  ))
1023 
1024  from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer
1025  _byElectronRejectionMVA62018 = "patTauDiscriminationByElectronRejectionMVA62018"+self.postfix
1026  setattr(self.process,"patTauDiscriminationByElectronRejectionMVA62018"+self.postfix,patTauDiscriminantCutMultiplexer.clone(
1027  PATTauProducer = self.originalTauName,
1028  Prediscriminants = noPrediscriminants,
1029  toMultiplex = _byElectronRejectionMVA62018Raw,
1030  mapping = cms.VPSet(
1031  cms.PSet(
1032  category = cms.uint32(0),
1033  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL'),
1034  variable = cms.string('pt')
1035  ),
1036  cms.PSet(
1037  category = cms.uint32(2),
1038  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL'),
1039  variable = cms.string('pt')
1040  ),
1041  cms.PSet(
1042  category = cms.uint32(5),
1043  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL'),
1044  variable = cms.string('pt')
1045  ),
1046  cms.PSet(
1047  category = cms.uint32(7),
1048  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL'),
1049  variable = cms.string('pt')
1050  ),
1051  cms.PSet(
1052  category = cms.uint32(8),
1053  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC'),
1054  variable = cms.string('pt')
1055  ),
1056  cms.PSet(
1057  category = cms.uint32(10),
1058  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC'),
1059  variable = cms.string('pt')
1060  ),
1061  cms.PSet(
1062  category = cms.uint32(13),
1063  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'),
1064  variable = cms.string('pt')
1065  ),
1066  cms.PSet(
1067  category = cms.uint32(15),
1068  cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC'),
1069  variable = cms.string('pt')
1070  )
1071  ),
1072  workingPoints = cms.vstring(
1073  "_WPeff98",
1074  "_WPeff90",
1075  "_WPeff80",
1076  "_WPeff70",
1077  "_WPeff60"
1078  )
1079  ))
1080 
1081  if self.debug: print ("runTauID: Will update the list of available in DB samples to access againstEle 2018")
1083 
1084 
1085  _patTauDiscriminationByElectronRejectionMVA62018Task = cms.Task(
1086  getattr(self.process,_byElectronRejectionMVA62018Raw),
1087  getattr(self.process,_byElectronRejectionMVA62018)
1088  )
1089  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA62018Task)
1090  _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA62018Task)
1091 
1092  _againstElectronTauIDSources = cms.PSet(
1093  againstElectronMVA6Raw2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "raw"),
1094  againstElectronMVA6category2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "category"),
1095  againstElectronVLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff98"),
1096  againstElectronLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff90"),
1097  againstElectronMediumMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff80"),
1098  againstElectronTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff70"),
1099  againstElectronVTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff60")
1100  )
1101  _tauIDSourcesWithAgainistEle = cms.PSet(
1102  tauIDSources.clone(),
1103  _againstElectronTauIDSources
1104  )
1105  tauIDSources =_tauIDSourcesWithAgainistEle.clone()
1106 
1107  if "againstEle" in self.toKeep:
1108 
1110  from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6
1111  _byElectronRejectionMVA6Raw = "patTauDiscriminationByElectronRejectionMVA6Raw"+self.postfix
1112  setattr(self.process,_byElectronRejectionMVA6Raw,patTauDiscriminationAgainstElectronMVA6.clone(
1113  PATTauProducer = self.originalTauName,
1114  Prediscriminants = noPrediscriminants, #already selected for MiniAOD
1115  srcElectrons = cms.InputTag('slimmedElectrons'),
1116  vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks
1117  mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_BL',
1118  mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_EC',
1119  mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_BL',
1120  mvaName_NoEleMatch_woGwoGSF_EC = 'RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_EC',
1121  mvaName_wGwGSF_BL = 'RecoTauTag_antiElectronMVA_wGwGSF_BL',
1122  mvaName_wGwGSF_EC = 'RecoTauTag_antiElectronMVA_wGwGSF_EC',
1123  mvaName_woGwGSF_BL = 'RecoTauTag_antiElectronMVA_woGwGSF_BL',
1124  mvaName_woGwGSF_EC = 'RecoTauTag_antiElectronMVA_woGwGSF_EC'
1125  ))
1126 
1127  from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer
1128  _byElectronRejectionMVA6 = "patTauDiscriminationByElectronRejectionMVA6"+self.postfix
1129  setattr(self.process,"patTauDiscriminationByElectronRejectionMVA6"+self.postfix,patTauDiscriminantCutMultiplexer.clone(
1130  PATTauProducer = self.originalTauName,
1131  Prediscriminants = noPrediscriminants,
1132  toMultiplex = _byElectronRejectionMVA6Raw,
1133  mapping = cms.VPSet(
1134  cms.PSet(
1135  category = cms.uint32(0),
1136  cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_BL'),
1137  variable = cms.string('pt')
1138  ),
1139  cms.PSet(
1140  category = cms.uint32(2),
1141  cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_BL'),
1142  variable = cms.string('pt')
1143  ),
1144  cms.PSet(
1145  category = cms.uint32(5),
1146  cut = cms.string('RecoTauTag_antiElectronMVA_woGwGSF_BL'),
1147  variable = cms.string('pt')
1148  ),
1149  cms.PSet(
1150  category = cms.uint32(7),
1151  cut = cms.string('RecoTauTag_antiElectronMVA_wGwGSF_BL'),
1152  variable = cms.string('pt')
1153  ),
1154  cms.PSet(
1155  category = cms.uint32(8),
1156  cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_EC'),
1157  variable = cms.string('pt')
1158  ),
1159  cms.PSet(
1160  category = cms.uint32(10),
1161  cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_EC'),
1162  variable = cms.string('pt')
1163  ),
1164  cms.PSet(
1165  category = cms.uint32(13),
1166  cut = cms.string('RecoTauTag_antiElectronMVA_woGwGSF_EC'),
1167  variable = cms.string('pt')
1168  ),
1169  cms.PSet(
1170  category = cms.uint32(15),
1171  cut = cms.string('RecoTauTag_antiElectronMVA_wGwGSF_EC'),
1172  variable = cms.string('pt')
1173  )
1174  ),
1175  workingPoints = cms.vstring(
1176  "_VLoose",
1177  "_Loose",
1178  "_Medium",
1179  "_Tight",
1180  "_VTight"
1181  )
1182  ))
1183 
1184  _patTauDiscriminationByElectronRejectionMVA6Task = cms.Task(
1185  getattr(self.process,_byElectronRejectionMVA6Raw),
1186  getattr(self.process,_byElectronRejectionMVA6)
1187  )
1188  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA6Task)
1189  _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA6Task)
1190 
1191  _againstElectronTauIDSources = cms.PSet(
1192  againstElectronMVA6Raw = self.tauIDMVAinputs(_byElectronRejectionMVA6, "raw"),
1193  againstElectronMVA6category = self.tauIDMVAinputs(_byElectronRejectionMVA6, "category"),
1194  againstElectronVLooseMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_VLoose"),
1195  againstElectronLooseMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_Loose"),
1196  againstElectronMediumMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_Medium"),
1197  againstElectronTightMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_Tight"),
1198  againstElectronVTightMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_VTight")
1199  )
1200  _tauIDSourcesWithAgainistEle = cms.PSet(
1201  tauIDSources.clone(),
1202  _againstElectronTauIDSources
1203  )
1204  tauIDSources =_tauIDSourcesWithAgainistEle.clone()
1205 
1206  if "newDMPhase2v1" in self.toKeep:
1207  if self.debug: print ("Adding newDMPhase2v1 ID")
1208  def tauIDMVAinputs(module, wp):
1209  return cms.PSet(inputTag = cms.InputTag(module), workingPointIndex = cms.int32(-1 if wp=="raw" else -2 if wp=="category" else getattr(self.process, module).workingPoints.index(wp)))
1210  _byIsolationNewDMMVAPhase2raw = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2raw"+self.postfix
1211  setattr(self.process,_byIsolationNewDMMVAPhase2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
1212  PATTauProducer = self.originalTauName,
1213  Prediscriminants = noPrediscriminants,
1214  loadMVAfromDB = True,
1215  mvaName = 'RecoTauTag_tauIdMVAIsoPhase2',
1216  mvaOpt = 'DBnewDMwLTwGJPhase2',
1217  verbosity = 0
1218  ))
1219 
1220  _byIsolationNewDMMVAPhase2 = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2"+self.postfix
1221  setattr(self.process,_byIsolationNewDMMVAPhase2,patDiscriminationByIsolationMVArun2v1.clone(
1222  PATTauProducer = self.originalTauName,
1223  Prediscriminants = noPrediscriminants,
1224  toMultiplex = _byIsolationNewDMMVAPhase2raw,
1225  loadMVAfromDB = True,
1226  mvaOutput_normalization = 'RecoTauTag_tauIdMVAIsoPhase2_mvaOutput_normalization',
1227  mapping = cms.VPSet(
1228  cms.PSet(
1229  category = cms.uint32(0),
1230  cut = cms.string("RecoTauTag_tauIdMVAIsoPhase2"),
1231  variable = cms.string("pt"),
1232  )
1233  ),
1234  workingPoints = cms.vstring(
1235  "_VVLoose",
1236  "_VLoose",
1237  "_Loose",
1238  "_Medium",
1239  "_Tight",
1240  "_VTight",
1241  "_VVTight"
1242  )
1243  ))
1244  _rerunIsolationMVADBnewDMwLTPhase2Task = cms.Task(
1245  getattr(self.process,_byIsolationNewDMMVAPhase2raw),
1246  getattr(self.process,_byIsolationNewDMMVAPhase2)
1247  )
1248  _rerunMvaIsolationTask.add(_rerunIsolationMVADBnewDMwLTPhase2Task)
1249  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationMVADBnewDMwLTPhase2Task)
1250 
1251  tauIDSources.byIsolationMVADBnewDMwLTPhase2raw = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "raw")
1252  tauIDSources.byVVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVLoose")
1253  tauIDSources.byVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VLoose")
1254  tauIDSources.byLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Loose")
1255  tauIDSources.byMediumIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Medium")
1256  tauIDSources.byTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Tight")
1257  tauIDSources.byVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VTight")
1258  tauIDSources.byVVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVTight")
1259 
1260  if "againstElePhase2v1" in self.toKeep:
1261  if self.debug: print ("Adding anti-e Phase2v1 ID")
1262 
1264  from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6Phase2_cff import patTauDiscriminationAgainstElectronMVA6Phase2Raw, patTauDiscriminationAgainstElectronMVA6Phase2, mergedSlimmedElectronsForTauId
1265  _byElectronRejectionMVA6Phase2v1Raw = "patTauDiscriminationByElectronRejectionMVA6Phase2v1Raw"+self.postfix
1266  setattr(self.process,_byElectronRejectionMVA6Phase2v1Raw,patTauDiscriminationAgainstElectronMVA6Phase2Raw.clone(
1267  PATTauProducer = self.originalTauName,
1268  Prediscriminants = noPrediscriminants #already selected for MiniAOD
1269  ))
1270 
1271  _byElectronRejectionMVA6Phase2v1 = "patTauDiscriminationByElectronRejectionMVA6Phase2v1"+self.postfix
1272  setattr(self.process,_byElectronRejectionMVA6Phase2v1,patTauDiscriminationAgainstElectronMVA6Phase2.clone(
1273  PATTauProducer = self.originalTauName,
1274  Prediscriminants = noPrediscriminants,
1275  toMultiplex = _byElectronRejectionMVA6Phase2v1Raw
1276  ))
1277 
1278  if not hasattr(self.process,"mergedSlimmedElectronsForTauId"):
1279  self.process.mergedSlimmedElectronsForTauId = mergedSlimmedElectronsForTauId
1280  _patTauDiscriminationByElectronRejectionMVA6Phase2v1Task = cms.Task(
1281  self.process.mergedSlimmedElectronsForTauId,
1282  getattr(self.process,_byElectronRejectionMVA6Phase2v1Raw),
1283  getattr(self.process,_byElectronRejectionMVA6Phase2v1)
1284  )
1285  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
1286  _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
1287 
1288  _againstElectronTauIDPhase2v1Sources = cms.PSet(
1289  againstElectronMVA6RawPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "raw"),
1290  againstElectronMVA6categoryPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "category"),
1291  againstElectronVLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VLoose"),
1292  againstElectronLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Loose"),
1293  againstElectronMediumMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Medium"),
1294  againstElectronTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Tight"),
1295  againstElectronVTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VTight")
1296  )
1297  _tauIDSourcesWithAgainistElePhase2v1 = cms.PSet(
1298  tauIDSources.clone(),
1299  _againstElectronTauIDPhase2v1Sources
1300  )
1301  tauIDSources =_tauIDSourcesWithAgainistElePhase2v1.clone()
1302 
1303  if self.debug: print('Embedding new TauIDs into \"'+self.updatedTauName+'\"')
1304  if not hasattr(self.process, self.updatedTauName):
1305  embedID = cms.EDProducer("PATTauIDEmbedder",
1306  src = cms.InputTag(self.originalTauName),
1307  tauIDSources = tauIDSources
1308  )
1309  setattr(self.process, self.updatedTauName, embedID)
1310  else: #assume same type
1311  tauIDSources = cms.PSet(
1312  getattr(self.process, self.updatedTauName).tauIDSources,
1313  tauIDSources)
1314  getattr(self.process, self.updatedTauName).tauIDSources = tauIDSources
1315  if not hasattr(self.process,"rerunMvaIsolationTask"+self.postfix):
1316  setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_rerunMvaIsolationTask)
1317  else:
1318  _updatedRerunMvaIsolationTask = getattr(self.process,"rerunMvaIsolationTask"+self.postfix)
1319  _updatedRerunMvaIsolationTask.add(_rerunMvaIsolationTask)
1320  setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_updatedRerunMvaIsolationTask)
1321  if not hasattr(self.process,"rerunMvaIsolationSequence"+self.postfix):
1322  setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_rerunMvaIsolationSequence)
1323  else:
1324  _updatedRerunMvaIsolationSequence = getattr(self.process,"rerunMvaIsolationSequence"+self.postfix)
1325  _updatedRerunMvaIsolationSequence += _rerunMvaIsolationSequence
1326  setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_updatedRerunMvaIsolationSequence)
1327 
1328 
1329  def processDeepProducer(self, producer_name, tauIDSources, workingPoints_):
1330  for target,points in workingPoints_.items():
1331  setattr(tauIDSources, 'by{}VS{}raw'.format(producer_name[0].upper()+producer_name[1:], target),
1332  cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(-1)))
1333 
1334  cut_expressions = []
1335  for index, (point,cut) in enumerate(points.items()):
1336  cut_expressions.append(str(cut))
1337 
1338  setattr(tauIDSources, 'by{}{}VS{}'.format(point, producer_name[0].upper()+producer_name[1:], target),
1339  cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(index)))
1340  if len(cut_expressions) > 0:
1341  setattr(getattr(self.process, producer_name+self.postfix), 'VS{}WP'.format(target), cms.vstring(*cut_expressions))
1342 
1343 
1344  def getDeepTauVersion(self, file_name):
1345  """returns the DeepTau year, version, subversion. File name should contain a version label with data takig year \
1346  (2011-2, 2015-8), version number (vX) and subversion (pX), e.g. 2017v0p6, in general the following format: \
1347  {year}v{version}p{subversion}"""
1348  version_search = re.search('(20[1,2][125678]|RunII)v([0-9]+)(p[0-9]+|)[\\._]', file_name)
1349  if not version_search:
1350  raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}p{subversion}". \
1351  Unable to extract version number.'.format(file_name))
1352  year = version_search.group(1)
1353  if year == 'RunII': year = 20161718
1354  version = version_search.group(2)
1355  subversion = version_search.group(3)
1356  if len(subversion) > 0:
1357  subversion = subversion[1:]
1358  else:
1359  subversion = 0
1360  return int(year), int(version), int(subversion)
def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug=False)
Definition: runTauIdMVA.py:82
def getDeepTauVersion(self, file_name)
def get_cmssw_version_number(klass, debug=False)
Definition: runTauIdMVA.py:64
def get_cmssw_version(debug=False)
Definition: runTauIdMVA.py:57
def loadMVA_WPs_run2_2017(self)
Definition: runTauIdMVA.py:94
def processDeepProducer(self, producer_name, tauIDSources, workingPoints_)
def __init__(self, process, debug=False, originalTauName="slimmedTaus", updatedTauName="slimmedTausNewID", postfix="", toKeep=["deepTau2017v2p1", deepTau2018v2p5, deepTau2026v2p5, conditionDB="" # preparational DB:'frontier://FrontierPrep/CMS_CONDITIONS')
Definition: runTauIdMVA.py:33
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def load(fileName)
Definition: svgfig.py:547
def load_againstElectronMVA6(self)
Definition: runTauIdMVA.py:124
def tauIDMVAinputs(self, module, wp)
Definition: runTauIdMVA.py:91
def versionToInt(release=9, subversion=4, patch=0, debug=False)
Definition: runTauIdMVA.py:75
#define str(s)