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 import os
7 import re
8 
10  """class to rerun the tau seq and acces trainings from the database"""
11  availableDiscriminators = [
12  "2017v1", "2017v2", "newDM2017v2", "dR0p32017v2", "2016v1", "newDM2016v1",
13  "deepTau2017v2", "deepTau2017v2p1", "deepTau2018v2p5",
14  "againstEle2018",
15  "newDMPhase2v1",
16  "againstElePhase2v1"
17  ]
18 
19  def __init__(self, process, debug = False,
20  originalTauName = "slimmedTaus",
21  updatedTauName = "slimmedTausNewID",
22  postfix = "",
23  toKeep = ["deepTau2017v2p1", "deepTau2018v2p5"],
24  tauIdDiscrMVA_trainings_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017", },
25  tauIdDiscrMVA_WPs_run2_2017 = {
26  'tauIdMVAIsoDBoldDMwLT2017' : {
27  'Eff95' : "DBoldDMwLTEff95",
28  'Eff90' : "DBoldDMwLTEff90",
29  'Eff80' : "DBoldDMwLTEff80",
30  'Eff70' : "DBoldDMwLTEff70",
31  'Eff60' : "DBoldDMwLTEff60",
32  'Eff50' : "DBoldDMwLTEff50",
33  'Eff40' : "DBoldDMwLTEff40"
34  }
35  },
36  tauIdDiscrMVA_2017_version = "v1",
37  conditionDB = "" # preparational DB: 'frontier://FrontierPrep/CMS_CONDITIONS'
38  ):
39  super(TauIDEmbedder, self).__init__()
40  self.process = process
41  self.debug = debug
42  self.originalTauName = originalTauName
43  self.updatedTauName = updatedTauName
44  self.postfix = postfix
45  self.process.load('RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi')
46  if len(conditionDB) != 0:
47  self.process.CondDBTauConnection.connect = cms.string(conditionDB)
48  self.process.loadRecoTauTagMVAsFromPrepDB.connect = cms.string(conditionDB)
49  # if debug:
50  # print self.process.CondDBTauConnection.connect
51  # print dir(self.process.loadRecoTauTagMVAsFromPrepDB)
52  # print self.process.loadRecoTauTagMVAsFromPrepDB.parameterNames_
53 
54  self.tauIdDiscrMVA_trainings_run2_2017 = tauIdDiscrMVA_trainings_run2_2017
55  self.tauIdDiscrMVA_WPs_run2_2017 = tauIdDiscrMVA_WPs_run2_2017
56  self.tauIdDiscrMVA_2017_version = tauIdDiscrMVA_2017_version
57  for discr in toKeep:
58  if discr not in TauIDEmbedder.availableDiscriminators:
59  raise RuntimeError('TauIDEmbedder: discriminator "{}" is not supported'.format(discr))
60  self.toKeep = toKeep
61 
62 
63  @staticmethod
64  def get_cmssw_version(debug = False):
65  """returns 'CMSSW_X_Y_Z'"""
66  cmssw_version = os.environ["CMSSW_VERSION"]
67  if debug: print ("get_cmssw_version:", cmssw_version)
68  return cmssw_version
69 
70  @classmethod
71  def get_cmssw_version_number(klass, debug = False):
72  """returns '(release, subversion, patch)' (without 'CMSSW_')"""
73  v = klass.get_cmssw_version().split("CMSSW_")[1].split("_")[0:3]
74  if debug: print ("get_cmssw_version_number:", v)
75  try:
76  patch = int(v[2])
77  except:
78  patch = -1
79  return int(v[0]), int(v[1]), patch
80 
81  @staticmethod
82  def versionToInt(release=9, subversion=4, patch=0, debug = False):
83  version = release * 10000 + subversion * 100 + patch + 1 # shifted by one to account for pre-releases.
84  if debug: print ("versionToInt:", version)
85  return version
86 
87 
88  @classmethod
89  def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug = False):
90  split_cmssw_version = klass.get_cmssw_version_number()
91  if klass.versionToInt(release, subversion, patch) > klass.versionToInt(split_cmssw_version[0], split_cmssw_version[1], split_cmssw_version[2]):
92  if debug: print ("is_above_cmssw_version:", False)
93  return False
94  else:
95  if debug: print ("is_above_cmssw_version:", True)
96  return True
97 
98  def tauIDMVAinputs(self, module, wp):
99  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)))
100 
102  if self.debug: print ("loadMVA_WPs_run2_2017: performed")
103  global cms
104  for training, gbrForestName in self.tauIdDiscrMVA_trainings_run2_2017.items():
105 
106  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
107  cms.PSet(
108  record = cms.string('GBRWrapperRcd'),
109  tag = cms.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
110  label = cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
111  )
112  )
113 
114  for WP in self.tauIdDiscrMVA_WPs_run2_2017[training].keys():
115  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
116  cms.PSet(
117  record = cms.string('PhysicsTGraphPayloadRcd'),
118  tag = cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)),
119  label = cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP))
120  )
121  )
122 
123  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
124  cms.PSet(
125  record = cms.string('PhysicsTFormulaPayloadRcd'),
126  tag = cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
127  label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
128  )
129  )
130 
131  def runTauID(self):
132  _rerunMvaIsolationTask = cms.Task()
133  _rerunMvaIsolationSequence = cms.Sequence()
134  tauIDSources = cms.PSet()
135 
136  # rerun the seq to obtain the 2017 nom training with 0.5 iso cone, old DM, ptph>1, trained on 2017MCv1
137  if "2017v1" in self.toKeep:
138  self.tauIdDiscrMVA_2017_version = "v1"
140  'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
141  }
143  'tauIdMVAIsoDBoldDMwLT2017' : {
144  'Eff95' : "DBoldDMwLTEff95",
145  'Eff90' : "DBoldDMwLTEff90",
146  'Eff80' : "DBoldDMwLTEff80",
147  'Eff70' : "DBoldDMwLTEff70",
148  'Eff60' : "DBoldDMwLTEff60",
149  'Eff50' : "DBoldDMwLTEff50",
150  'Eff40' : "DBoldDMwLTEff40"
151  }
152  }
153  # update the list of available in DB samples
154  if not self.is_above_cmssw_version(9, 4, 4, self.debug):
155  if self.debug: print ("runTauID: not is_above_cmssw_version(9, 4, 4). Will update the list of available in DB samples to access 2017v1")
156  self.loadMVA_WPs_run2_2017()
157 
158  _byIsolationOldDMMVArun2017v1raw = "rerunDiscriminationByIsolationOldDMMVArun2017v1raw"+self.postfix
159  setattr(self.process,_byIsolationOldDMMVArun2017v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
160  PATTauProducer = self.originalTauName,
161  Prediscriminants = noPrediscriminants,
162  loadMVAfromDB = cms.bool(True),
163  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"),
164  mvaOpt = cms.string("DBoldDMwLTwGJ"),
165  verbosity = cms.int32(0)
166  ))
167 
168  _byIsolationOldDMMVArun2017v1 = "rerunDiscriminationByIsolationOldDMMVArun2017v1"+self.postfix
169  setattr(self.process,_byIsolationOldDMMVArun2017v1,patDiscriminationByIsolationMVArun2v1.clone(
170  PATTauProducer = self.originalTauName,
171  Prediscriminants = noPrediscriminants,
172  toMultiplex = _byIsolationOldDMMVArun2017v1raw,
173  loadMVAfromDB = cms.bool(True),
174  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
175  mapping = cms.VPSet(
176  cms.PSet(
177  category = cms.uint32(0),
178  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"), #writeTauIdDiscrWPs
179  variable = cms.string("pt"),
180  )
181  ),
182  workingPoints = cms.vstring(
183  "_WPEff95",
184  "_WPEff90",
185  "_WPEff80",
186  "_WPEff70",
187  "_WPEff60",
188  "_WPEff50",
189  "_WPEff40"
190  )
191  ))
192 
193  _rerunIsolationOldDMMVArun2017v1Task = cms.Task(
194  getattr(self.process,_byIsolationOldDMMVArun2017v1raw),
195  getattr(self.process,_byIsolationOldDMMVArun2017v1)
196  )
197  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v1Task)
198  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2017v1Task)
199 
200  tauIDSources.byIsolationMVArun2017v1DBoldDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "raw")
201  tauIDSources.byVVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff95")
202  tauIDSources.byVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff90")
203  tauIDSources.byLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff80")
204  tauIDSources.byMediumIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff70")
205  tauIDSources.byTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff60")
206  tauIDSources.byVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff50")
207  tauIDSources.byVVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff40")
208 
209 
210  if "2017v2" in self.toKeep:
211  self.tauIdDiscrMVA_2017_version = "v2"
213  'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
214  }
216  'tauIdMVAIsoDBoldDMwLT2017' : {
217  'Eff95' : "DBoldDMwLTEff95",
218  'Eff90' : "DBoldDMwLTEff90",
219  'Eff80' : "DBoldDMwLTEff80",
220  'Eff70' : "DBoldDMwLTEff70",
221  'Eff60' : "DBoldDMwLTEff60",
222  'Eff50' : "DBoldDMwLTEff50",
223  'Eff40' : "DBoldDMwLTEff40"
224  }
225  }
226 
227  if not self.is_above_cmssw_version(9, 4, 5, self.debug):
228  if self.debug: print ("runTauID: not is_above_cmssw_version(9, 4, 5). Will update the list of available in DB samples to access 2017v2")
229  self.loadMVA_WPs_run2_2017()
230 
231  _byIsolationOldDMMVArun2017v2raw = "rerunDiscriminationByIsolationOldDMMVArun2017v2raw"+self.postfix
232  setattr(self.process,_byIsolationOldDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
233  PATTauProducer = self.originalTauName,
234  Prediscriminants = noPrediscriminants,
235  loadMVAfromDB = cms.bool(True),
236  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"),
237  mvaOpt = cms.string("DBoldDMwLTwGJ"),
238  verbosity = cms.int32(0)
239  ))
240 
241  _byIsolationOldDMMVArun2017v2 = "rerunDiscriminationByIsolationOldDMMVArun2017v2"+self.postfix
242  setattr(self.process,_byIsolationOldDMMVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
243  PATTauProducer = self.originalTauName,
244  Prediscriminants = noPrediscriminants,
245  toMultiplex = _byIsolationOldDMMVArun2017v2raw,
246  loadMVAfromDB = cms.bool(True),
247  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
248  mapping = cms.VPSet(
249  cms.PSet(
250  category = cms.uint32(0),
251  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"), #writeTauIdDiscrWPs
252  variable = cms.string("pt"),
253  )
254  ),
255  workingPoints = cms.vstring(
256  "_WPEff95",
257  "_WPEff90",
258  "_WPEff80",
259  "_WPEff70",
260  "_WPEff60",
261  "_WPEff50",
262  "_WPEff40"
263  ),
264  verbosity = cms.int32(0)
265  ))
266 
267  _rerunIsolationOldDMMVArun2017v2Task = cms.Task(
268  getattr(self.process,_byIsolationOldDMMVArun2017v2raw),
269  getattr(self.process,_byIsolationOldDMMVArun2017v2)
270  )
271  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v2Task)
272  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2017v2Task)
273 
274  tauIDSources.byIsolationMVArun2017v2DBoldDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "raw")
275  tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff95")
276  tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff90")
277  tauIDSources.byLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff80")
278  tauIDSources.byMediumIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff70")
279  tauIDSources.byTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff60")
280  tauIDSources.byVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff50")
281  tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff40")
282 
283  if "newDM2017v2" in self.toKeep:
284  self.tauIdDiscrMVA_2017_version = "v2"
286  'tauIdMVAIsoDBnewDMwLT2017' : "tauIdMVAIsoDBnewDMwLT2017",
287  }
289  'tauIdMVAIsoDBnewDMwLT2017' : {
290  'Eff95' : "DBnewDMwLTEff95",
291  'Eff90' : "DBnewDMwLTEff90",
292  'Eff80' : "DBnewDMwLTEff80",
293  'Eff70' : "DBnewDMwLTEff70",
294  'Eff60' : "DBnewDMwLTEff60",
295  'Eff50' : "DBnewDMwLTEff50",
296  'Eff40' : "DBnewDMwLTEff40"
297  }
298  }
299 
300  if not self.is_above_cmssw_version(9, 4, 5, self.debug):
301  if self.debug: print ("runTauID: not is_above_cmssw_version(9, 4, 5). Will update the list of available in DB samples to access newDM2017v2")
302  self.loadMVA_WPs_run2_2017()
303 
304  _byIsolationNewDMMVArun2017v2raw = "rerunDiscriminationByIsolationNewDMMVArun2017v2raw"+self.postfix
305  setattr(self.process,_byIsolationNewDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
306  PATTauProducer = self.originalTauName,
307  Prediscriminants = noPrediscriminants,
308  loadMVAfromDB = cms.bool(True),
309  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"),
310  mvaOpt = cms.string("DBnewDMwLTwGJ"),
311  verbosity = cms.int32(0)
312  ))
313 
314  _byIsolationNewDMMVArun2017v2 = "rerunDiscriminationByIsolationNewDMMVArun2017v2"+self.postfix
315  setattr(self.process,_byIsolationNewDMMVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
316  PATTauProducer = self.originalTauName,
317  Prediscriminants = noPrediscriminants,
318  toMultiplex = _byIsolationNewDMMVArun2017v2raw,
319  loadMVAfromDB = cms.bool(True),
320  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
321  mapping = cms.VPSet(
322  cms.PSet(
323  category = cms.uint32(0),
324  cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"), #writeTauIdDiscrWPs
325  variable = cms.string("pt"),
326  )
327  ),
328  workingPoints = cms.vstring(
329  "_WPEff95",
330  "_WPEff90",
331  "_WPEff80",
332  "_WPEff70",
333  "_WPEff60",
334  "_WPEff50",
335  "_WPEff40"
336  ),
337  verbosity = cms.int32(0)
338  ))
339 
340  _rerunIsolationNewDMMVArun2017v2Task = cms.Task(
341  getattr(self.process,_byIsolationNewDMMVArun2017v2raw),
342  getattr(self.process,_byIsolationNewDMMVArun2017v2)
343  )
344  _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2017v2Task)
345  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVArun2017v2Task)
346 
347  tauIDSources.byIsolationMVArun2017v2DBnewDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "raw")
348  tauIDSources.byVVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff95")
349  tauIDSources.byVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff90")
350  tauIDSources.byLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff80")
351  tauIDSources.byMediumIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff70")
352  tauIDSources.byTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff60")
353  tauIDSources.byVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff50")
354  tauIDSources.byVVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff40")
355 
356  if "dR0p32017v2" in self.toKeep:
357  self.tauIdDiscrMVA_2017_version = "v2"
359  'tauIdMVAIsoDBoldDMdR0p3wLT2017' : "tauIdMVAIsoDBoldDMdR0p3wLT2017",
360  }
362  'tauIdMVAIsoDBoldDMdR0p3wLT2017' : {
363  'Eff95' : "DBoldDMdR0p3wLTEff95",
364  'Eff90' : "DBoldDMdR0p3wLTEff90",
365  'Eff80' : "DBoldDMdR0p3wLTEff80",
366  'Eff70' : "DBoldDMdR0p3wLTEff70",
367  'Eff60' : "DBoldDMdR0p3wLTEff60",
368  'Eff50' : "DBoldDMdR0p3wLTEff50",
369  'Eff40' : "DBoldDMdR0p3wLTEff40"
370  }
371  }
372 
373  if not self.is_above_cmssw_version(9, 4, 5, self.debug):
374  if self.debug: print ("runTauID: not is_above_cmssw_version(9, 4, 5). Will update the list of available in DB samples to access dR0p32017v2")
375  self.loadMVA_WPs_run2_2017()
376 
377  _byIsolationOldDMdR0p3MVArun2017v2raw = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw"+self.postfix
378  setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
379  PATTauProducer = self.originalTauName,
380  Prediscriminants = noPrediscriminants,
381  loadMVAfromDB = cms.bool(True),
382  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"),
383  mvaOpt = cms.string("DBoldDMwLTwGJ"),
384  srcChargedIsoPtSum = cms.string('chargedIsoPtSumdR03'),
385  srcFootprintCorrection = cms.string('footprintCorrectiondR03'),
386  srcNeutralIsoPtSum = cms.string('neutralIsoPtSumdR03'),
387  srcPhotonPtSumOutsideSignalCone = cms.string('photonPtSumOutsideSignalConedR03'),
388  verbosity = cms.int32(0)
389  ))
390 
391  _byIsolationOldDMdR0p3MVArun2017v2 = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2"+self.postfix
392  setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
393  PATTauProducer = self.originalTauName,
394  Prediscriminants = noPrediscriminants,
395  toMultiplex = _byIsolationOldDMdR0p3MVArun2017v2raw,
396  loadMVAfromDB = cms.bool(True),
397  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
398  mapping = cms.VPSet(
399  cms.PSet(
400  category = cms.uint32(0),
401  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"), #writeTauIdDiscrWPs
402  variable = cms.string("pt"),
403  )
404  ),
405  workingPoints = cms.vstring(
406  "_WPEff95",
407  "_WPEff90",
408  "_WPEff80",
409  "_WPEff70",
410  "_WPEff60",
411  "_WPEff50",
412  "_WPEff40"
413  ),
414  verbosity = cms.int32(0)
415  ))
416 
417  _rerunIsolationOldDMdR0p3MVArun2017v2Task = cms.Task(
418  getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw),
419  getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2)
420  )
421  _rerunMvaIsolationTask.add(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
422  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
423 
424  tauIDSources.byIsolationMVArun2017v2DBoldDMdR0p3wLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "raw")
425  tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff95")
426  tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff90")
427  tauIDSources.byLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff80")
428  tauIDSources.byMediumIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff70")
429  tauIDSources.byTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff60")
430  tauIDSources.byVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff50")
431  tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff40")
432 
433  # 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
434  # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2raw = patDiscriminationByIsolationMVArun2v1raw.clone(
435  # PATTauProducer = self.originalTauName,
436  # Prediscriminants = noPrediscriminants,
437  # loadMVAfromDB = cms.bool(True),
438  # mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2"),
439  # mvaOpt = cms.string("DBoldDMwLTwGJ"),
440  # verbosity = cms.int32(0)
441  # )
442  # #
443  # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2VLoose = patDiscriminationByIsolationMVArun2v1VLoose.clone(
444  # PATTauProducer = self.originalTauName,
445  # Prediscriminants = noPrediscriminants,
446  # toMultiplex = 'rerunDiscriminationByIsolationOldDMMVArun2v2raw',
447  # key = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw:category'),#?
448  # loadMVAfromDB = cms.bool(True),
449  # mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
450  # mapping = cms.VPSet(
451  # cms.PSet(
452  # category = cms.uint32(0),
453  # cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_WPEff90"), #writeTauIdDiscrWPs
454  # variable = cms.string("pt"),
455  # )
456  # )
457  # )
458 
459  # 2016 training strategy(v1), trained on 2016MC, old DM
460  if "2016v1" in self.toKeep:
461  _byIsolationOldDMMVArun2016v1raw = "rerunDiscriminationByIsolationOldDMMVArun2v1raw"+self.postfix
462  setattr(self.process,_byIsolationOldDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
463  PATTauProducer = self.originalTauName,
464  Prediscriminants = noPrediscriminants,
465  loadMVAfromDB = cms.bool(True),
466  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"),
467  mvaOpt = cms.string("DBoldDMwLT"),
468  verbosity = cms.int32(0)
469  ))
470 
471  _byIsolationOldDMMVArun2016v1 = "rerunDiscriminationByIsolationOldDMMVArun2v1"+self.postfix
472  setattr(self.process,_byIsolationOldDMMVArun2016v1,patDiscriminationByIsolationMVArun2v1.clone(
473  PATTauProducer = self.originalTauName,
474  Prediscriminants = noPrediscriminants,
475  toMultiplex = _byIsolationOldDMMVArun2016v1raw,
476  loadMVAfromDB = cms.bool(True),
477  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_mvaOutput_normalization"),
478  mapping = cms.VPSet(
479  cms.PSet(
480  category = cms.uint32(0),
481  cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"),
482  variable = cms.string("pt"),
483  )
484  ),
485  workingPoints = cms.vstring(
486  "_WPEff90",
487  "_WPEff80",
488  "_WPEff70",
489  "_WPEff60",
490  "_WPEff50",
491  "_WPEff40"
492  )
493  ))
494 
495  _rerunIsolationOldDMMVArun2016v1Task = cms.Task(
496  getattr(self.process,_byIsolationOldDMMVArun2016v1raw),
497  getattr(self.process,_byIsolationOldDMMVArun2016v1)
498  )
499  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2016v1Task)
500  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2016v1Task)
501 
502  tauIDSources.byIsolationMVArun2v1DBoldDMwLTraw2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "raw")
503  tauIDSources.byVLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff90")
504  tauIDSources.byLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff80")
505  tauIDSources.byMediumIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff70")
506  tauIDSources.byTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff60")
507  tauIDSources.byVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff50")
508  tauIDSources.byVVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff40")
509 
510  # 2016 training strategy(v1), trained on 2016MC, new DM
511  if "newDM2016v1" in self.toKeep:
512  _byIsolationNewDMMVArun2016v1raw = "rerunDiscriminationByIsolationNewDMMVArun2v1raw"+self.postfix
513  setattr(self.process,_byIsolationNewDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
514  PATTauProducer = self.originalTauName,
515  Prediscriminants = noPrediscriminants,
516  loadMVAfromDB = cms.bool(True),
517  mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"),
518  mvaOpt = cms.string("DBnewDMwLT"),
519  verbosity = cms.int32(0)
520  ))
521 
522  _byIsolationNewDMMVArun2016v1 = "rerunDiscriminationByIsolationNewDMMVArun2v1"+self.postfix
523  setattr(self.process,_byIsolationNewDMMVArun2016v1,patDiscriminationByIsolationMVArun2v1.clone(
524  PATTauProducer = self.originalTauName,
525  Prediscriminants = noPrediscriminants,
526  toMultiplex = _byIsolationNewDMMVArun2016v1raw,
527  loadMVAfromDB = cms.bool(True),
528  mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_mvaOutput_normalization"),
529  mapping = cms.VPSet(
530  cms.PSet(
531  category = cms.uint32(0),
532  cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_WPEff90"),
533  variable = cms.string("pt"),
534  )
535  ),
536  workingPoints = cms.vstring(
537  "_WPEff90",
538  "_WPEff80",
539  "_WPEff70",
540  "_WPEff60",
541  "_WPEff50",
542  "_WPEff40"
543  )
544  ))
545 
546  _rerunIsolationNewDMMVArun2016v1Task = cms.Task(
547  getattr(self.process,_byIsolationNewDMMVArun2016v1raw),
548  getattr(self.process,_byIsolationNewDMMVArun2016v1)
549  )
550  _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2016v1Task)
551  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVArun2016v1Task)
552 
553  tauIDSources.byIsolationMVArun2v1DBnewDMwLTraw2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "raw")
554  tauIDSources.byVLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff90")
555  tauIDSources.byLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff80")
556  tauIDSources.byMediumIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff70")
557  tauIDSources.byTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff60")
558  tauIDSources.byVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff50")
559  tauIDSources.byVVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff40")
560 
561  if "deepTau2017v2" in self.toKeep:
562  if self.debug: print ("Adding DeepTau IDs")
563 
564  _deepTauName = "deepTau2017v2"
565  workingPoints_ = {
566  "e": {
567  "VVVLoose": 0.0630386,
568  "VVLoose": 0.1686942,
569  "VLoose": 0.3628130,
570  "Loose": 0.6815435,
571  "Medium": 0.8847544,
572  "Tight": 0.9675541,
573  "VTight": 0.9859251,
574  "VVTight": 0.9928449,
575  },
576  "mu": {
577  "VLoose": 0.1058354,
578  "Loose": 0.2158633,
579  "Medium": 0.5551894,
580  "Tight": 0.8754835,
581  },
582  "jet": {
583  "VVVLoose": 0.2599605,
584  "VVLoose": 0.4249705,
585  "VLoose": 0.5983682,
586  "Loose": 0.7848675,
587  "Medium": 0.8834768,
588  "Tight": 0.9308689,
589  "VTight": 0.9573137,
590  "VVTight": 0.9733927,
591  },
592  }
593 
594  file_names = [
595  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
596  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
597  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
598  ]
599  full_version = self.getDeepTauVersion(file_names[0])
600  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
601  Prediscriminants = noPrediscriminants,
602  taus = self.originalTauName,
603  graph_file = file_names,
604  version = full_version[1],
605  sub_version = 0 #MB: subversion cannot be properly deduced from file names
606  ))
607 
608  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
609 
610  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
611  _rerunMvaIsolationTask.add(_deepTauProducer)
612  _rerunMvaIsolationSequence += _deepTauProducer
613 
614 
615  if "deepTau2017v2p1" in self.toKeep:
616  if self.debug: print ("Adding DeepTau IDs")
617 
618  _deepTauName = "deepTau2017v2p1"
619  workingPoints_ = {
620  "e": {
621  "VVVLoose": 0.0630386,
622  "VVLoose": 0.1686942,
623  "VLoose": 0.3628130,
624  "Loose": 0.6815435,
625  "Medium": 0.8847544,
626  "Tight": 0.9675541,
627  "VTight": 0.9859251,
628  "VVTight": 0.9928449,
629  },
630  "mu": {
631  "VLoose": 0.1058354,
632  "Loose": 0.2158633,
633  "Medium": 0.5551894,
634  "Tight": 0.8754835,
635  },
636  "jet": {
637  "VVVLoose": 0.2599605,
638  "VVLoose": 0.4249705,
639  "VLoose": 0.5983682,
640  "Loose": 0.7848675,
641  "Medium": 0.8834768,
642  "Tight": 0.9308689,
643  "VTight": 0.9573137,
644  "VVTight": 0.9733927,
645  },
646  }
647 
648  file_names = [
649  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
650  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
651  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
652  ]
653  full_version = self.getDeepTauVersion(file_names[0])
654  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
655  Prediscriminants = noPrediscriminants,
656  taus = self.originalTauName,
657  graph_file = file_names,
658  version = full_version[1],
659  sub_version = 1, #MB: subversion cannot be properly deduced from file names
660  disable_dxy_pca = True
661  ))
662 
663  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
664 
665  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
666  _rerunMvaIsolationTask.add(_deepTauProducer)
667  _rerunMvaIsolationSequence += _deepTauProducer
668 
669  if "deepTau2018v2p5" in self.toKeep:
670  if self.debug: print ("Adding DeepTau IDs")
671 
672  _deepTauName = "deepTau2018v2p5"
673  workingPoints_ = {
674  "e": {},
675  "mu": {},
676  "jet": {},
677  }
678 
679  file_names = [
680  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_core.pb',
681  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_inner.pb',
682  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_outer.pb',
683  ]
684  full_version = self.getDeepTauVersion(file_names[0])
685  setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
686  Prediscriminants = noPrediscriminants,
687  taus = self.originalTauName,
688  graph_file = file_names,
689  version = full_version[1],
690  sub_version = full_version[2],
691  disable_dxy_pca = True,
692  disable_hcalFraction_workaround = True,
693  disable_CellIndex_workaround = True
694  ))
695 
696  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
697 
698  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
699  _rerunMvaIsolationTask.add(_deepTauProducer)
700  _rerunMvaIsolationSequence += _deepTauProducer
701 
702  if "againstEle2018" in self.toKeep:
703  antiElectronDiscrMVA6_version = "MVA6v3_noeveto"
704 
706  from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6
707  _byElectronRejectionMVA62018Raw = "patTauDiscriminationByElectronRejectionMVA62018Raw"+self.postfix
708  setattr(self.process,_byElectronRejectionMVA62018Raw,patTauDiscriminationAgainstElectronMVA6.clone(
709  PATTauProducer = self.originalTauName,
710  Prediscriminants = noPrediscriminants, #already selected for MiniAOD
711  srcElectrons = cms.InputTag('slimmedElectrons'),
712  vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks
713  mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL',
714  mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC',
715  mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL',
716  mvaName_NoEleMatch_woGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC',
717  mvaName_wGwGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL',
718  mvaName_wGwGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC',
719  mvaName_woGwGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL',
720  mvaName_woGwGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'
721  ))
722 
723  from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer
724  _byElectronRejectionMVA62018 = "patTauDiscriminationByElectronRejectionMVA62018"+self.postfix
725  setattr(self.process,"patTauDiscriminationByElectronRejectionMVA62018"+self.postfix,patTauDiscriminantCutMultiplexer.clone(
726  PATTauProducer = self.originalTauName,
727  Prediscriminants = noPrediscriminants,
728  toMultiplex = _byElectronRejectionMVA62018Raw,
729  mapping = cms.VPSet(
730  cms.PSet(
731  category = cms.uint32(0),
732  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL'),
733  variable = cms.string('pt')
734  ),
735  cms.PSet(
736  category = cms.uint32(2),
737  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL'),
738  variable = cms.string('pt')
739  ),
740  cms.PSet(
741  category = cms.uint32(5),
742  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL'),
743  variable = cms.string('pt')
744  ),
745  cms.PSet(
746  category = cms.uint32(7),
747  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL'),
748  variable = cms.string('pt')
749  ),
750  cms.PSet(
751  category = cms.uint32(8),
752  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC'),
753  variable = cms.string('pt')
754  ),
755  cms.PSet(
756  category = cms.uint32(10),
757  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC'),
758  variable = cms.string('pt')
759  ),
760  cms.PSet(
761  category = cms.uint32(13),
762  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'),
763  variable = cms.string('pt')
764  ),
765  cms.PSet(
766  category = cms.uint32(15),
767  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC'),
768  variable = cms.string('pt')
769  )
770  ),
771  workingPoints = cms.vstring(
772  "_WPeff98",
773  "_WPeff90",
774  "_WPeff80",
775  "_WPeff70",
776  "_WPeff60"
777  )
778  ))
779 
780  _patTauDiscriminationByElectronRejectionMVA62018Task = cms.Task(
781  getattr(self.process,_byElectronRejectionMVA62018Raw),
782  getattr(self.process,_byElectronRejectionMVA62018)
783  )
784  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA62018Task)
785  _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA62018Task)
786 
787  _againstElectronTauIDSources = cms.PSet(
788  againstElectronMVA6Raw2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "raw"),
789  againstElectronMVA6category2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "category"),
790  againstElectronVLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff98"),
791  againstElectronLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff90"),
792  againstElectronMediumMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff80"),
793  againstElectronTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff70"),
794  againstElectronVTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff60")
795  )
796  _tauIDSourcesWithAgainistEle = cms.PSet(
797  tauIDSources.clone(),
798  _againstElectronTauIDSources
799  )
800  tauIDSources =_tauIDSourcesWithAgainistEle.clone()
801 
802  if "newDMPhase2v1" in self.toKeep:
803  if self.debug: print ("Adding newDMPhase2v1 ID")
804  def tauIDMVAinputs(module, wp):
805  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)))
806  _byIsolationNewDMMVAPhase2raw = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2raw"+self.postfix
807  setattr(self.process,_byIsolationNewDMMVAPhase2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
808  PATTauProducer = self.originalTauName,
809  Prediscriminants = noPrediscriminants,
810  loadMVAfromDB = True,
811  mvaName = 'RecoTauTag_tauIdMVAIsoPhase2',
812  mvaOpt = 'DBnewDMwLTwGJPhase2',
813  verbosity = 0
814  ))
815 
816  _byIsolationNewDMMVAPhase2 = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2"+self.postfix
817  setattr(self.process,_byIsolationNewDMMVAPhase2,patDiscriminationByIsolationMVArun2v1.clone(
818  PATTauProducer = self.originalTauName,
819  Prediscriminants = noPrediscriminants,
820  toMultiplex = _byIsolationNewDMMVAPhase2raw,
821  loadMVAfromDB = True,
822  mvaOutput_normalization = 'RecoTauTag_tauIdMVAIsoPhase2_mvaOutput_normalization',
823  mapping = cms.VPSet(
824  cms.PSet(
825  category = cms.uint32(0),
826  cut = cms.string("RecoTauTag_tauIdMVAIsoPhase2"),
827  variable = cms.string("pt"),
828  )
829  ),
830  workingPoints = cms.vstring(
831  "_VVLoose",
832  "_VLoose",
833  "_Loose",
834  "_Medium",
835  "_Tight",
836  "_VTight",
837  "_VVTight"
838  )
839  ))
840  _rerunIsolationMVADBnewDMwLTPhase2Task = cms.Task(
841  getattr(self.process,_byIsolationNewDMMVAPhase2raw),
842  getattr(self.process,_byIsolationNewDMMVAPhase2)
843  )
844  _rerunMvaIsolationTask.add(_rerunIsolationMVADBnewDMwLTPhase2Task)
845  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationMVADBnewDMwLTPhase2Task)
846 
847  tauIDSources.byIsolationMVADBnewDMwLTPhase2raw = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "raw")
848  tauIDSources.byVVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVLoose")
849  tauIDSources.byVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VLoose")
850  tauIDSources.byLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Loose")
851  tauIDSources.byMediumIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Medium")
852  tauIDSources.byTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Tight")
853  tauIDSources.byVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VTight")
854  tauIDSources.byVVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVTight")
855 
856  if "againstElePhase2v1" in self.toKeep:
857  if self.debug: print ("Adding anti-e Phase2v1 ID")
858 
860  from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6Phase2_cff import patTauDiscriminationAgainstElectronMVA6Phase2Raw, patTauDiscriminationAgainstElectronMVA6Phase2, mergedSlimmedElectronsForTauId
861  _byElectronRejectionMVA6Phase2v1Raw = "patTauDiscriminationByElectronRejectionMVA6Phase2v1Raw"+self.postfix
862  setattr(self.process,_byElectronRejectionMVA6Phase2v1Raw,patTauDiscriminationAgainstElectronMVA6Phase2Raw.clone(
863  PATTauProducer = self.originalTauName,
864  Prediscriminants = noPrediscriminants #already selected for MiniAOD
865  ))
866 
867  _byElectronRejectionMVA6Phase2v1 = "patTauDiscriminationByElectronRejectionMVA6Phase2v1"+self.postfix
868  setattr(self.process,_byElectronRejectionMVA6Phase2v1,patTauDiscriminationAgainstElectronMVA6Phase2.clone(
869  PATTauProducer = self.originalTauName,
870  Prediscriminants = noPrediscriminants,
871  toMultiplex = _byElectronRejectionMVA6Phase2v1Raw
872  ))
873 
874  if not hasattr(self.process,"mergedSlimmedElectronsForTauId"):
875  self.process.mergedSlimmedElectronsForTauId = mergedSlimmedElectronsForTauId
876  _patTauDiscriminationByElectronRejectionMVA6Phase2v1Task = cms.Task(
877  self.process.mergedSlimmedElectronsForTauId,
878  getattr(self.process,_byElectronRejectionMVA6Phase2v1Raw),
879  getattr(self.process,_byElectronRejectionMVA6Phase2v1)
880  )
881  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
882  _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
883 
884  _againstElectronTauIDPhase2v1Sources = cms.PSet(
885  againstElectronMVA6RawPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "raw"),
886  againstElectronMVA6categoryPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "category"),
887  againstElectronVLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VLoose"),
888  againstElectronLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Loose"),
889  againstElectronMediumMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Medium"),
890  againstElectronTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Tight"),
891  againstElectronVTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VTight")
892  )
893  _tauIDSourcesWithAgainistElePhase2v1 = cms.PSet(
894  tauIDSources.clone(),
895  _againstElectronTauIDPhase2v1Sources
896  )
897  tauIDSources =_tauIDSourcesWithAgainistElePhase2v1.clone()
898 
899  if self.debug: print('Embedding new TauIDs into \"'+self.updatedTauName+'\"')
900  if not hasattr(self.process, self.updatedTauName):
901  embedID = cms.EDProducer("PATTauIDEmbedder",
902  src = cms.InputTag(self.originalTauName),
903  tauIDSources = tauIDSources
904  )
905  setattr(self.process, self.updatedTauName, embedID)
906  else: #assume same type
907  tauIDSources = cms.PSet(
908  getattr(self.process, self.updatedTauName).tauIDSources,
909  tauIDSources)
910  getattr(self.process, self.updatedTauName).tauIDSources = tauIDSources
911  if not hasattr(self.process,"rerunMvaIsolationTask"+self.postfix):
912  setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_rerunMvaIsolationTask)
913  else:
914  _updatedRerunMvaIsolationTask = getattr(self.process,"rerunMvaIsolationTask"+self.postfix)
915  _updatedRerunMvaIsolationTask.add(_rerunMvaIsolationTask)
916  setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_updatedRerunMvaIsolationTask)
917  if not hasattr(self.process,"rerunMvaIsolationSequence"+self.postfix):
918  setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_rerunMvaIsolationSequence)
919  else:
920  _updatedRerunMvaIsolationSequence = getattr(self.process,"rerunMvaIsolationSequence"+self.postfix)
921  _updatedRerunMvaIsolationSequence += _rerunMvaIsolationSequence
922  setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_updatedRerunMvaIsolationSequence)
923 
924 
925  def processDeepProducer(self, producer_name, tauIDSources, workingPoints_):
926  for target,points in workingPoints_.items():
927  setattr(tauIDSources, 'by{}VS{}raw'.format(producer_name[0].upper()+producer_name[1:], target),
928  cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(-1)))
929 
930  cut_expressions = []
931  for index, (point,cut) in enumerate(points.items()):
932  cut_expressions.append(str(cut))
933 
934  setattr(tauIDSources, 'by{}{}VS{}'.format(point, producer_name[0].upper()+producer_name[1:], target),
935  cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(index)))
936  if len(cut_expressions) > 0:
937  setattr(getattr(self.process, producer_name+self.postfix), 'VS{}WP'.format(target), cms.vstring(*cut_expressions))
938 
939 
940  def getDeepTauVersion(self, file_name):
941  """returns the DeepTau year, version, subversion. File name should contain a version label with data takig year \
942  (2011-2, 2015-8), version number (vX) and subversion (pX), e.g. 2017v0p6, in general the following format: \
943  {year}v{version}p{subversion}"""
944  version_search = re.search('(20[1,2][125678])v([0-9]+)(p[0-9]+|)[\._]', file_name)
945  if not version_search:
946  raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}p{subversion}". \
947  Unable to extract version number.'.format(file_name))
948  year = version_search.group(1)
949  version = version_search.group(2)
950  subversion = version_search.group(3)
951  if len(subversion) > 0:
952  subversion = subversion[1:]
953  else:
954  subversion = 0
955  return int(year), int(version), int(subversion)
def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug=False)
Definition: runTauIdMVA.py:89
def getDeepTauVersion(self, file_name)
Definition: runTauIdMVA.py:940
def get_cmssw_version_number(klass, debug=False)
Definition: runTauIdMVA.py:71
def get_cmssw_version(debug=False)
Definition: runTauIdMVA.py:64
def processDeepProducer(self, producer_name, tauIDSources, workingPoints_)
Definition: runTauIdMVA.py:925
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def load(fileName)
Definition: svgfig.py:547
def tauIDMVAinputs(self, module, wp)
Definition: runTauIdMVA.py:98
def versionToInt(release=9, subversion=4, patch=0, debug=False)
Definition: runTauIdMVA.py:82
#define str(s)