CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 import os
6 import re
7 
8 class TauIDEmbedder(object):
9  """class to rerun the tau seq and acces trainings from the database"""
10  availableDiscriminators = [
11  "2017v1", "2017v2", "newDM2017v2", "dR0p32017v2", "2016v1", "newDM2016v1",
12  "deepTau2017v1", "deepTau2017v2", "deepTau2017v2p1",
13  "DPFTau_2016_v0", "DPFTau_2016_v1",
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"],
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 "deepTau2017v1" in self.toKeep:
562  if self.debug: print ("Adding DeepTau IDs")
563 
564  _deepTauName = "deepTau2017v1"
565  workingPoints_ = {
566  "e": {
567  "VVVLoose" : 0.96424,
568  "VVLoose" : 0.98992,
569  "VLoose" : 0.99574,
570  "Loose": 0.99831,
571  "Medium": 0.99868,
572  "Tight": 0.99898,
573  "VTight": 0.99911,
574  "VVTight": 0.99918
575  },
576  "mu": {
577  "VVVLoose" : 0.959619,
578  "VVLoose" : 0.997687,
579  "VLoose" : 0.999392,
580  "Loose": 0.999755,
581  "Medium": 0.999854,
582  "Tight": 0.999886,
583  "VTight": 0.999944,
584  "VVTight": 0.9999971
585  },
586 
587  "jet": {
588  "VVVLoose" : 0.5329,
589  "VVLoose" : 0.7645,
590  "VLoose" : 0.8623,
591  "Loose": 0.9140,
592  "Medium": 0.9464,
593  "Tight": 0.9635,
594  "VTight": 0.9760,
595  "VVTight": 0.9859
596  }
597  }
598  file_names = ['RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v1_20L1024N_quantized.pb']
599  setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DeepTauId",
600  electrons = cms.InputTag('slimmedElectrons'),
601  muons = cms.InputTag('slimmedMuons'),
602  taus = cms.InputTag(self.originalTauName),
603  pfcands = cms.InputTag('packedPFCandidates'),
604  vertices = cms.InputTag('offlineSlimmedPrimaryVertices'),
605  rho = cms.InputTag('fixedGridRhoAll'),
606  graph_file = cms.vstring(file_names),
607  mem_mapped = cms.bool(False),
608  version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
609  debug_level = cms.int32(0),
610  disable_dxy_pca = cms.bool(False)
611  ))
612 
613  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
614 
615  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
616  _rerunMvaIsolationTask.add(_deepTauProducer)
617  _rerunMvaIsolationSequence += _deepTauProducer
618 
619 
620  if "deepTau2017v2" in self.toKeep:
621  if self.debug: print ("Adding DeepTau IDs")
622 
623  _deepTauName = "deepTau2017v2"
624  workingPoints_ = {
625  "e": {
626  "VVVLoose": 0.0630386,
627  "VVLoose": 0.1686942,
628  "VLoose": 0.3628130,
629  "Loose": 0.6815435,
630  "Medium": 0.8847544,
631  "Tight": 0.9675541,
632  "VTight": 0.9859251,
633  "VVTight": 0.9928449,
634  },
635  "mu": {
636  "VLoose": 0.1058354,
637  "Loose": 0.2158633,
638  "Medium": 0.5551894,
639  "Tight": 0.8754835,
640  },
641  "jet": {
642  "VVVLoose": 0.2599605,
643  "VVLoose": 0.4249705,
644  "VLoose": 0.5983682,
645  "Loose": 0.7848675,
646  "Medium": 0.8834768,
647  "Tight": 0.9308689,
648  "VTight": 0.9573137,
649  "VVTight": 0.9733927,
650  },
651  }
652 
653  file_names = [
654  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
655  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
656  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
657  ]
658  setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DeepTauId",
659  electrons = cms.InputTag('slimmedElectrons'),
660  muons = cms.InputTag('slimmedMuons'),
661  taus = cms.InputTag(self.originalTauName),
662  pfcands = cms.InputTag('packedPFCandidates'),
663  vertices = cms.InputTag('offlineSlimmedPrimaryVertices'),
664  rho = cms.InputTag('fixedGridRhoAll'),
665  graph_file = cms.vstring(file_names),
666  mem_mapped = cms.bool(False),
667  version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
668  debug_level = cms.int32(0),
669  disable_dxy_pca = cms.bool(False)
670  ))
671 
672  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
673 
674  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
675  _rerunMvaIsolationTask.add(_deepTauProducer)
676  _rerunMvaIsolationSequence += _deepTauProducer
677 
678 
679  if "deepTau2017v2p1" in self.toKeep:
680  if self.debug: print ("Adding DeepTau IDs")
681 
682  _deepTauName = "deepTau2017v2p1"
683  workingPoints_ = {
684  "e": {
685  "VVVLoose": 0.0630386,
686  "VVLoose": 0.1686942,
687  "VLoose": 0.3628130,
688  "Loose": 0.6815435,
689  "Medium": 0.8847544,
690  "Tight": 0.9675541,
691  "VTight": 0.9859251,
692  "VVTight": 0.9928449,
693  },
694  "mu": {
695  "VLoose": 0.1058354,
696  "Loose": 0.2158633,
697  "Medium": 0.5551894,
698  "Tight": 0.8754835,
699  },
700  "jet": {
701  "VVVLoose": 0.2599605,
702  "VVLoose": 0.4249705,
703  "VLoose": 0.5983682,
704  "Loose": 0.7848675,
705  "Medium": 0.8834768,
706  "Tight": 0.9308689,
707  "VTight": 0.9573137,
708  "VVTight": 0.9733927,
709  },
710  }
711 
712  file_names = [
713  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
714  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
715  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
716  ]
717  setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DeepTauId",
718  electrons = cms.InputTag('slimmedElectrons'),
719  muons = cms.InputTag('slimmedMuons'),
720  taus = cms.InputTag(self.originalTauName),
721  pfcands = cms.InputTag('packedPFCandidates'),
722  vertices = cms.InputTag('offlineSlimmedPrimaryVertices'),
723  rho = cms.InputTag('fixedGridRhoAll'),
724  graph_file = cms.vstring(file_names),
725  mem_mapped = cms.bool(False),
726  version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
727  debug_level = cms.int32(0),
728  disable_dxy_pca = cms.bool(True),
729  is_online = cms.bool(False)
730  ))
731 
732  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
733 
734  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
735  _rerunMvaIsolationTask.add(_deepTauProducer)
736  _rerunMvaIsolationSequence += _deepTauProducer
737 
738 
739  if "DPFTau_2016_v0" in self.toKeep:
740  if self.debug: print ("Adding DPFTau isolation (v0)")
741 
742  _deepTauName = "DPFTau_2016_v0"
743  workingPoints_ = {
744  "all": {
745  "Tight" : "if(decayMode == 0) return (0.898328 - 0.000160992 * pt);" + \
746  "if(decayMode == 1) return (0.910138 - 0.000229923 * pt);" + \
747  "if(decayMode == 10) return (0.873958 - 0.0002328 * pt);" + \
748  "return 99.0;"
749  #"Tight" : "? decayMode == 0 ? (0.898328 - 0.000160992 * pt) : " +
750  # "(? decayMode == 1 ? 0.910138 - 0.000229923 * pt : " +
751  # "(? decayMode == 10 ? (0.873958 - 0.0002328 * pt) : 1))"
752  # "Tight" : "(decayMode == 0) * (0.898328 - 0.000160992 * pt) + \
753  # (decayMode == 1) * (0.910138 - 0.000229923 * pt) + \
754  # (decayMode == 10) * (0.873958 - 0.0002328 * pt) "
755  }
756  }
757  file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v0_quantized.pb' ]
758  setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DPFIsolation",
759  pfcands = cms.InputTag('packedPFCandidates'),
760  taus = cms.InputTag(self.originalTauName),
761  vertices = cms.InputTag('offlineSlimmedPrimaryVertices'),
762  graph_file = cms.vstring(file_names),
763  version = cms.uint32(self.getDpfTauVersion(file_names[0])),
764  mem_mapped = cms.bool(False)
765  ))
766 
767  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
768 
769  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
770  _rerunMvaIsolationTask.add(_deepTauProducer)
771  _rerunMvaIsolationSequence += _deepTauProducer
772 
773 
774  if "DPFTau_2016_v1" in self.toKeep:
775  print ("Adding DPFTau isolation (v1)")
776  print ("WARNING: WPs are not defined for DPFTau_2016_v1")
777  print ("WARNING: The score of DPFTau_2016_v1 is inverted: i.e. for Sig->0, for Bkg->1 with -1 for undefined input (preselection not passed).")
778 
779  _deepTauName = "DPFTau_2016_v1"
780  workingPoints_ = {
781  "all": {"Tight" : 0.123} #FIXME: define WP
782  }
783 
784  file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v1_quantized.pb' ]
785  setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DPFIsolation",
786  pfcands = cms.InputTag('packedPFCandidates'),
787  taus = cms.InputTag(self.originalTauName),
788  vertices = cms.InputTag('offlineSlimmedPrimaryVertices'),
789  graph_file = cms.vstring(file_names),
790  version = cms.uint32(self.getDpfTauVersion(file_names[0])),
791  mem_mapped = cms.bool(False)
792  ))
793 
794  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
795 
796  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
797  _rerunMvaIsolationTask.add(_deepTauProducer)
798  _rerunMvaIsolationSequence += _deepTauProducer
799 
800 
801  if "againstEle2018" in self.toKeep:
802  antiElectronDiscrMVA6_version = "MVA6v3_noeveto"
803  ### Define new anti-e discriminants
804  ## Raw
805  from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6
806  _byElectronRejectionMVA62018Raw = "patTauDiscriminationByElectronRejectionMVA62018Raw"+self.postfix
807  setattr(self.process,_byElectronRejectionMVA62018Raw,patTauDiscriminationAgainstElectronMVA6.clone(
808  PATTauProducer = self.originalTauName,
809  Prediscriminants = noPrediscriminants, #already selected for MiniAOD
810  srcElectrons = cms.InputTag('slimmedElectrons'),
811  vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks
812  mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL',
813  mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC',
814  mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL',
815  mvaName_NoEleMatch_woGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC',
816  mvaName_wGwGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL',
817  mvaName_wGwGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC',
818  mvaName_woGwGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL',
819  mvaName_woGwGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'
820  ))
821  ## WPs
822  from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer
823  _byElectronRejectionMVA62018 = "patTauDiscriminationByElectronRejectionMVA62018"+self.postfix
824  setattr(self.process,"patTauDiscriminationByElectronRejectionMVA62018"+self.postfix,patTauDiscriminantCutMultiplexer.clone(
825  PATTauProducer = self.originalTauName,
826  Prediscriminants = noPrediscriminants,
827  toMultiplex = _byElectronRejectionMVA62018Raw,
828  mapping = cms.VPSet(
829  cms.PSet(
830  category = cms.uint32(0),
831  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL'),
832  variable = cms.string('pt')
833  ),
834  cms.PSet(
835  category = cms.uint32(2),
836  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL'),
837  variable = cms.string('pt')
838  ),
839  cms.PSet(
840  category = cms.uint32(5),
841  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL'),
842  variable = cms.string('pt')
843  ),
844  cms.PSet(
845  category = cms.uint32(7),
846  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL'),
847  variable = cms.string('pt')
848  ),
849  cms.PSet(
850  category = cms.uint32(8),
851  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC'),
852  variable = cms.string('pt')
853  ),
854  cms.PSet(
855  category = cms.uint32(10),
856  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC'),
857  variable = cms.string('pt')
858  ),
859  cms.PSet(
860  category = cms.uint32(13),
861  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'),
862  variable = cms.string('pt')
863  ),
864  cms.PSet(
865  category = cms.uint32(15),
866  cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC'),
867  variable = cms.string('pt')
868  )
869  ),
870  workingPoints = cms.vstring(
871  "_WPeff98",
872  "_WPeff90",
873  "_WPeff80",
874  "_WPeff70",
875  "_WPeff60"
876  )
877  ))
878  ### Put all new anti-e discrminats to a sequence
879  _patTauDiscriminationByElectronRejectionMVA62018Task = cms.Task(
880  getattr(self.process,_byElectronRejectionMVA62018Raw),
881  getattr(self.process,_byElectronRejectionMVA62018)
882  )
883  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA62018Task)
884  _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA62018Task)
885 
886  _againstElectronTauIDSources = cms.PSet(
887  againstElectronMVA6Raw2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "raw"),
888  againstElectronMVA6category2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "category"),
889  againstElectronVLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff98"),
890  againstElectronLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff90"),
891  againstElectronMediumMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff80"),
892  againstElectronTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff70"),
893  againstElectronVTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff60")
894  )
895  _tauIDSourcesWithAgainistEle = cms.PSet(
896  tauIDSources.clone(),
897  _againstElectronTauIDSources
898  )
899  tauIDSources =_tauIDSourcesWithAgainistEle.clone()
900 
901  if "newDMPhase2v1" in self.toKeep:
902  if self.debug: print ("Adding newDMPhase2v1 ID")
903  def tauIDMVAinputs(module, wp):
904  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)))
905  _byIsolationNewDMMVAPhase2raw = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2raw"+self.postfix
906  setattr(self.process,_byIsolationNewDMMVAPhase2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
907  PATTauProducer = self.originalTauName,
908  Prediscriminants = noPrediscriminants,
909  loadMVAfromDB = True,
910  mvaName = 'RecoTauTag_tauIdMVAIsoPhase2',
911  mvaOpt = 'DBnewDMwLTwGJPhase2',
912  verbosity = 0
913  ))
914 
915  _byIsolationNewDMMVAPhase2 = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2"+self.postfix
916  setattr(self.process,_byIsolationNewDMMVAPhase2,patDiscriminationByIsolationMVArun2v1.clone(
917  PATTauProducer = self.originalTauName,
918  Prediscriminants = noPrediscriminants,
919  toMultiplex = _byIsolationNewDMMVAPhase2raw,
920  loadMVAfromDB = True,
921  mvaOutput_normalization = 'RecoTauTag_tauIdMVAIsoPhase2_mvaOutput_normalization',
922  mapping = cms.VPSet(
923  cms.PSet(
924  category = cms.uint32(0),
925  cut = cms.string("RecoTauTag_tauIdMVAIsoPhase2"),
926  variable = cms.string("pt"),
927  )
928  ),
929  workingPoints = cms.vstring(
930  "_VVLoose",
931  "_VLoose",
932  "_Loose",
933  "_Medium",
934  "_Tight",
935  "_VTight",
936  "_VVTight"
937  )
938  ))
939  _rerunIsolationMVADBnewDMwLTPhase2Task = cms.Task(
940  getattr(self.process,_byIsolationNewDMMVAPhase2raw),
941  getattr(self.process,_byIsolationNewDMMVAPhase2)
942  )
943  _rerunMvaIsolationTask.add(_rerunIsolationMVADBnewDMwLTPhase2Task)
944  _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationMVADBnewDMwLTPhase2Task)
945 
946  tauIDSources.byIsolationMVADBnewDMwLTPhase2raw = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "raw")
947  tauIDSources.byVVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVLoose")
948  tauIDSources.byVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VLoose")
949  tauIDSources.byLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Loose")
950  tauIDSources.byMediumIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Medium")
951  tauIDSources.byTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Tight")
952  tauIDSources.byVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VTight")
953  tauIDSources.byVVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVTight")
954 
955  if "againstElePhase2v1" in self.toKeep:
956  if self.debug: print ("Adding anti-e Phase2v1 ID")
957  ### Define new anti-e discriminants for Phase2
958  ## Raw
959  from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6Phase2_cff import patTauDiscriminationAgainstElectronMVA6Phase2Raw, patTauDiscriminationAgainstElectronMVA6Phase2, mergedSlimmedElectronsForTauId
960  _byElectronRejectionMVA6Phase2v1Raw = "patTauDiscriminationByElectronRejectionMVA6Phase2v1Raw"+self.postfix
961  setattr(self.process,_byElectronRejectionMVA6Phase2v1Raw,patTauDiscriminationAgainstElectronMVA6Phase2Raw.clone(
962  PATTauProducer = self.originalTauName,
963  Prediscriminants = noPrediscriminants #already selected for MiniAOD
964  ))
965  ## WPs
966  _byElectronRejectionMVA6Phase2v1 = "patTauDiscriminationByElectronRejectionMVA6Phase2v1"+self.postfix
967  setattr(self.process,_byElectronRejectionMVA6Phase2v1,patTauDiscriminationAgainstElectronMVA6Phase2.clone(
968  PATTauProducer = self.originalTauName,
969  Prediscriminants = noPrediscriminants,
970  toMultiplex = _byElectronRejectionMVA6Phase2v1Raw
971  ))
972  ### Put all new phase2 anti-e discrminats to a sequence
973  if not hasattr(self.process,"mergedSlimmedElectronsForTauId"):
974  self.process.mergedSlimmedElectronsForTauId = mergedSlimmedElectronsForTauId
975  _patTauDiscriminationByElectronRejectionMVA6Phase2v1Task = cms.Task(
976  self.process.mergedSlimmedElectronsForTauId,
977  getattr(self.process,_byElectronRejectionMVA6Phase2v1Raw),
978  getattr(self.process,_byElectronRejectionMVA6Phase2v1)
979  )
980  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
981  _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
982 
983  _againstElectronTauIDPhase2v1Sources = cms.PSet(
984  againstElectronMVA6RawPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "raw"),
985  againstElectronMVA6categoryPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "category"),
986  againstElectronVLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VLoose"),
987  againstElectronLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Loose"),
988  againstElectronMediumMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Medium"),
989  againstElectronTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Tight"),
990  againstElectronVTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VTight")
991  )
992  _tauIDSourcesWithAgainistElePhase2v1 = cms.PSet(
993  tauIDSources.clone(),
994  _againstElectronTauIDPhase2v1Sources
995  )
996  tauIDSources =_tauIDSourcesWithAgainistElePhase2v1.clone()
997  ##
998  if self.debug: print('Embedding new TauIDs into \"'+self.updatedTauName+'\"')
999  if not hasattr(self.process, self.updatedTauName):
1000  embedID = cms.EDProducer("PATTauIDEmbedder",
1001  src = cms.InputTag(self.originalTauName),
1002  tauIDSources = tauIDSources
1003  )
1004  setattr(self.process, self.updatedTauName, embedID)
1005  else: #assume same type
1006  tauIDSources = cms.PSet(
1007  getattr(self.process, self.updatedTauName).tauIDSources,
1008  tauIDSources)
1009  getattr(self.process, self.updatedTauName).tauIDSources = tauIDSources
1010  setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_rerunMvaIsolationTask)
1011  setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_rerunMvaIsolationSequence)
1012 
1013 
1014  def processDeepProducer(self, producer_name, tauIDSources, workingPoints_):
1015  for target,points in workingPoints_.items():
1016  setattr(tauIDSources, 'by{}VS{}raw'.format(producer_name[0].upper()+producer_name[1:], target),
1017  cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(-1)))
1018 
1019  cut_expressions = []
1020  for index, (point,cut) in enumerate(points.items()):
1021  cut_expressions.append(str(cut))
1022 
1023  setattr(tauIDSources, 'by{}{}VS{}'.format(point, producer_name[0].upper()+producer_name[1:], target),
1024  cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(index)))
1025 
1026  setattr(getattr(self.process, producer_name+self.postfix), 'VS{}WP'.format(target), cms.vstring(*cut_expressions))
1027 
1028 
1029  def getDpfTauVersion(self, file_name):
1030  """returns the DNN version. File name should contain a version label with data takig year (2011-2, 2015-8) and \
1031  version number (vX), e.g. 2017v0, in general the following format: {year}v{version}"""
1032  version_search = re.search('201[125678]v([0-9]+)[\._]', file_name)
1033  if not version_search:
1034  raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}". \
1035  Unable to extract version number.'.format(file_name))
1036  version = version_search.group(1)
1037  return int(version)
1038 
1039  def getDeepTauVersion(self, file_name):
1040  """returns the DeepTau year, version, subversion. File name should contain a version label with data takig year \
1041  (2011-2, 2015-8), version number (vX) and subversion (pX), e.g. 2017v0p6, in general the following format: \
1042  {year}v{version}p{subversion}"""
1043  version_search = re.search('(201[125678])v([0-9]+)(p[0-9]+|)[\._]', file_name)
1044  if not version_search:
1045  raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}p{subversion}". \
1046  Unable to extract version number.'.format(file_name))
1047  year = version_search.group(1)
1048  version = version_search.group(2)
1049  subversion = version_search.group(3)
1050  if len(subversion) > 0:
1051  subversion = subversion[1:]
1052  else:
1053  subversion = 0
1054  return int(year), int(version), int(subversion)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)