CMS 3D CMS Logo

runTauIdMVA.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants
3 from RecoTauTag.RecoTau.PATTauDiscriminationByMVAIsolationRun2_cff import patDiscriminationByIsolationMVArun2v1raw, patDiscriminationByIsolationMVArun2v1VLoose
4 import os
5 import re
6 import six
7 
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  ]
16 
17  def __init__(self, process, cms, debug = False,
18  originalTauName = "slimmedTaus",
19  updatedTauName = "slimmedTausNewID",
20  postfix = "",
21  toKeep = ["deepTau2017v2p1"],
22  tauIdDiscrMVA_trainings_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017", },
23  tauIdDiscrMVA_WPs_run2_2017 = {
24  'tauIdMVAIsoDBoldDMwLT2017' : {
25  'Eff95' : "DBoldDMwLTEff95",
26  'Eff90' : "DBoldDMwLTEff90",
27  'Eff80' : "DBoldDMwLTEff80",
28  'Eff70' : "DBoldDMwLTEff70",
29  'Eff60' : "DBoldDMwLTEff60",
30  'Eff50' : "DBoldDMwLTEff50",
31  'Eff40' : "DBoldDMwLTEff40"
32  }
33  },
34  tauIdDiscrMVA_2017_version = "v1",
35  conditionDB = "" # preparational DB: 'frontier://FrontierPrep/CMS_CONDITIONS'
36  ):
37  super(TauIDEmbedder, self).__init__()
38  self.process = process
39  self.cms = cms
40  self.debug = debug
41  self.originalTauName = originalTauName
42  self.updatedTauName = updatedTauName
43  self.postfix = postfix
44  self.process.load('RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi')
45  if len(conditionDB) != 0:
46  self.process.CondDBTauConnection.connect = cms.string(conditionDB)
47  self.process.loadRecoTauTagMVAsFromPrepDB.connect = cms.string(conditionDB)
48  # if debug:
49  # print self.process.CondDBTauConnection.connect
50  # print dir(self.process.loadRecoTauTagMVAsFromPrepDB)
51  # print self.process.loadRecoTauTagMVAsFromPrepDB.parameterNames_
52 
53  self.tauIdDiscrMVA_trainings_run2_2017 = tauIdDiscrMVA_trainings_run2_2017
54  self.tauIdDiscrMVA_WPs_run2_2017 = tauIdDiscrMVA_WPs_run2_2017
55  self.tauIdDiscrMVA_2017_version = tauIdDiscrMVA_2017_version
56  for discr in toKeep:
57  if discr not in TauIDEmbedder.availableDiscriminators:
58  raise RuntimeError('TauIDEmbedder: discriminator "{}" is not supported'.format(discr))
59  self.toKeep = toKeep
60 
61 
62  @staticmethod
63  def get_cmssw_version(debug = False):
64  """returns 'CMSSW_X_Y_Z'"""
65  cmssw_version = os.environ["CMSSW_VERSION"]
66  if debug: print ("get_cmssw_version:", cmssw_version)
67  return cmssw_version
68 
69  @classmethod
70  def get_cmssw_version_number(klass, debug = False):
71  """returns '(release, subversion, patch)' (without 'CMSSW_')"""
72  v = klass.get_cmssw_version().split("CMSSW_")[1].split("_")[0:3]
73  if debug: print ("get_cmssw_version_number:", v)
74  if v[2] == "X":
75  patch = -1
76  else:
77  patch = int(v[2])
78  return int(v[0]), int(v[1]), patch
79 
80  @staticmethod
81  def versionToInt(release=9, subversion=4, patch=0, debug = False):
82  version = release * 10000 + subversion * 100 + patch + 1 # shifted by one to account for pre-releases.
83  if debug: print ("versionToInt:", version)
84  return version
85 
86 
87  @classmethod
88  def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug = False):
89  split_cmssw_version = klass.get_cmssw_version_number()
90  if klass.versionToInt(release, subversion, patch) > klass.versionToInt(split_cmssw_version[0], split_cmssw_version[1], split_cmssw_version[2]):
91  if debug: print ("is_above_cmssw_version:", False)
92  return False
93  else:
94  if debug: print ("is_above_cmssw_version:", True)
95  return True
96 
98  if self.debug: print ("loadMVA_WPs_run2_2017: performed")
99  global cms
100  for training, gbrForestName in self.tauIdDiscrMVA_trainings_run2_2017.items():
101 
102  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
103  self.cms.PSet(
104  record = self.cms.string('GBRWrapperRcd'),
105  tag = self.cms.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
106  label = self.cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
107  )
108  )
109 
110  for WP in self.tauIdDiscrMVA_WPs_run2_2017[training].keys():
111  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
112  self.cms.PSet(
113  record = self.cms.string('PhysicsTGraphPayloadRcd'),
114  tag = self.cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)),
115  label = self.cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP))
116  )
117  )
118 
119  self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
120  self.cms.PSet(
121  record = self.cms.string('PhysicsTFormulaPayloadRcd'),
122  tag = self.cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
123  label = self.cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
124  )
125  )
126 
127  def runTauID(self):
128  _rerunMvaIsolationTask = self.cms.Task()
129  _rerunMvaIsolationSequence = self.cms.Sequence()
130  tauIDSources = self.cms.PSet()
131 
132  # rerun the seq to obtain the 2017 nom training with 0.5 iso cone, old DM, ptph>1, trained on 2017MCv1
133  if "2017v1" in self.toKeep:
134  self.tauIdDiscrMVA_2017_version = "v1"
136  'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
137  }
139  'tauIdMVAIsoDBoldDMwLT2017' : {
140  'Eff95' : "DBoldDMwLTEff95",
141  'Eff90' : "DBoldDMwLTEff90",
142  'Eff80' : "DBoldDMwLTEff80",
143  'Eff70' : "DBoldDMwLTEff70",
144  'Eff60' : "DBoldDMwLTEff60",
145  'Eff50' : "DBoldDMwLTEff50",
146  'Eff40' : "DBoldDMwLTEff40"
147  }
148  }
149  # update the list of available in DB samples
150  if not self.is_above_cmssw_version(9, 4, 4, self.debug):
151  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")
152  self.loadMVA_WPs_run2_2017()
153 
154  _byIsolationOldDMMVArun2017v1raw = "rerunDiscriminationByIsolationOldDMMVArun2017v1raw"+self.postfix
155  setattr(self.process,_byIsolationOldDMMVArun2017v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
156  PATTauProducer = self.originalTauName,
157  Prediscriminants = noPrediscriminants,
158  loadMVAfromDB = self.cms.bool(True),
159  mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"),
160  mvaOpt = self.cms.string("DBoldDMwLTwGJ"),
161  verbosity = self.cms.int32(0)
162  ))
163 
164  _byIsolationOldDMMVArun2017v1VLoose = "rerunDiscriminationByIsolationOldDMMVArun2017v1VLoose"+self.postfix
165  setattr(self.process,_byIsolationOldDMMVArun2017v1VLoose,patDiscriminationByIsolationMVArun2v1VLoose.clone(
166  PATTauProducer = self.originalTauName,
167  Prediscriminants = noPrediscriminants,
168  toMultiplex = _byIsolationOldDMMVArun2017v1raw,
169  key = _byIsolationOldDMMVArun2017v1raw+':category',
170  loadMVAfromDB = self.cms.bool(True),
171  mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
172  mapping = self.cms.VPSet(
173  self.cms.PSet(
174  category = self.cms.uint32(0),
175  cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff90"), #writeTauIdDiscrWPs
176  variable = self.cms.string("pt"),
177  )
178  )
179  ))
180  _byIsolationOldDMMVArun2017v1VLooseProd = getattr(self.process,_byIsolationOldDMMVArun2017v1VLoose)
181 
182  _rerunIsolationOldDMMVArun2017v1Task = self.cms.Task(
183  getattr(self.process,_byIsolationOldDMMVArun2017v1raw),
184  _byIsolationOldDMMVArun2017v1VLooseProd
185  )
186  tauIDSources.byIsolationMVArun2017v1DBoldDMwLTraw2017 = self.cms.InputTag(_byIsolationOldDMMVArun2017v1raw)
187  tauIDSources.byVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.cms.InputTag(_byIsolationOldDMMVArun2017v1VLoose)
188 
189  wp_to_eff_match = {
190  "VVLoose" : "WPEff95",
191  "Loose" : "WPEff80",
192  "Medium" : "WPEff70",
193  "Tight" : "WPEff60",
194  "VTight" : "WPEff50",
195  "VVTight" : "WPEff40"
196  }
197  for wp,wpEff in wp_to_eff_match.items():
198  _aWP = "rerunDiscriminationByIsolationOldDMMVArun2017v1"+wp+self.postfix
199  setattr(self.process,_aWP,_byIsolationOldDMMVArun2017v1VLooseProd.clone())
200  _aWPProd = getattr(self.process,_aWP)
201  _aWPProd.mapping[0].cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_"+wpEff)
202  _rerunIsolationOldDMMVArun2017v1Task.add(_aWPProd)
203  setattr(tauIDSources,"by"+wp+"IsolationMVArun2017v1DBoldDMwLT2017",self.cms.InputTag(_aWP))
204 
205  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v1Task)
206  _rerunMvaIsolationSequence += self.cms.Sequence(_rerunIsolationOldDMMVArun2017v1Task)
207 
208  if "2017v2" in self.toKeep:
209  self.tauIdDiscrMVA_2017_version = "v2"
211  'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
212  }
214  'tauIdMVAIsoDBoldDMwLT2017' : {
215  'Eff95' : "DBoldDMwLTEff95",
216  'Eff90' : "DBoldDMwLTEff90",
217  'Eff80' : "DBoldDMwLTEff80",
218  'Eff70' : "DBoldDMwLTEff70",
219  'Eff60' : "DBoldDMwLTEff60",
220  'Eff50' : "DBoldDMwLTEff50",
221  'Eff40' : "DBoldDMwLTEff40"
222  }
223  }
224 
225  if not self.is_above_cmssw_version(9, 4, 5, self.debug):
226  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")
227  self.loadMVA_WPs_run2_2017()
228 
229  _byIsolationOldDMMVArun2017v2raw = "rerunDiscriminationByIsolationOldDMMVArun2017v2raw"+self.postfix
230  setattr(self.process,_byIsolationOldDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
231  PATTauProducer = self.originalTauName,
232  Prediscriminants = noPrediscriminants,
233  loadMVAfromDB = self.cms.bool(True),
234  mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"),
235  mvaOpt = self.cms.string("DBoldDMwLTwGJ"),
236  verbosity = self.cms.int32(0)
237  ))
238 
239  _byIsolationOldDMMVArun2017v2VLoose = "rerunDiscriminationByIsolationOldDMMVArun2017v2VLoose"+self.postfix
240  setattr(self.process,_byIsolationOldDMMVArun2017v2VLoose,patDiscriminationByIsolationMVArun2v1VLoose.clone(
241  PATTauProducer = self.originalTauName,
242  Prediscriminants = noPrediscriminants,
243  toMultiplex = _byIsolationOldDMMVArun2017v2raw,
244  key = _byIsolationOldDMMVArun2017v2raw+':category',
245  loadMVAfromDB = self.cms.bool(True),
246  mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
247  mapping = self.cms.VPSet(
248  self.cms.PSet(
249  category = self.cms.uint32(0),
250  cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_WPEff90"), #writeTauIdDiscrWPs
251  variable = self.cms.string("pt"),
252  )
253  ),
254  verbosity = self.cms.int32(0)
255  ))
256  _byIsolationOldDMMVArun2017v2VLooseProd = getattr(self.process,_byIsolationOldDMMVArun2017v2VLoose)
257 
258  _rerunIsolationOldDMMVArun2017v2Task = self.cms.Task(
259  getattr(self.process,_byIsolationOldDMMVArun2017v2raw),
260  _byIsolationOldDMMVArun2017v2VLooseProd
261  )
262  tauIDSources.byIsolationMVArun2017v2DBoldDMwLTraw2017 = self.cms.InputTag(_byIsolationOldDMMVArun2017v2raw)
263  tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.cms.InputTag(_byIsolationOldDMMVArun2017v2VLoose)
264 
265  wp_to_eff_match = {
266  "VVLoose" : "WPEff95",
267  "Loose" : "WPEff80",
268  "Medium" : "WPEff70",
269  "Tight" : "WPEff60",
270  "VTight" : "WPEff50",
271  "VVTight" : "WPEff40"
272  }
273  for wp,wpEff in wp_to_eff_match.items():
274  _aWP = "rerunDiscriminationByIsolationOldDMMVArun2017v2"+wp+self.postfix
275  setattr(self.process,_aWP,_byIsolationOldDMMVArun2017v2VLooseProd.clone())
276  _aWPProd = getattr(self.process,_aWP)
277  _aWPProd.mapping[0].cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_"+wpEff)
278  _rerunIsolationOldDMMVArun2017v2Task.add(_aWPProd)
279  setattr(tauIDSources,"by"+wp+"IsolationMVArun2017v2DBoldDMwLT2017",self.cms.InputTag(_aWP))
280 
281  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v2Task)
282  _rerunMvaIsolationSequence += self.cms.Sequence(_rerunIsolationOldDMMVArun2017v2Task)
283 
284  if "newDM2017v2" in self.toKeep:
285  self.tauIdDiscrMVA_2017_version = "v2"
287  'tauIdMVAIsoDBnewDMwLT2017' : "tauIdMVAIsoDBnewDMwLT2017",
288  }
290  'tauIdMVAIsoDBnewDMwLT2017' : {
291  'Eff95' : "DBnewDMwLTEff95",
292  'Eff90' : "DBnewDMwLTEff90",
293  'Eff80' : "DBnewDMwLTEff80",
294  'Eff70' : "DBnewDMwLTEff70",
295  'Eff60' : "DBnewDMwLTEff60",
296  'Eff50' : "DBnewDMwLTEff50",
297  'Eff40' : "DBnewDMwLTEff40"
298  }
299  }
300 
301  if not self.is_above_cmssw_version(9, 4, 5, self.debug):
302  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")
303  self.loadMVA_WPs_run2_2017()
304 
305  _byIsolationNewDMMVArun2017v2raw = "rerunDiscriminationByIsolationNewDMMVArun2017v2raw"+self.postfix
306  setattr(self.process,_byIsolationNewDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
307  PATTauProducer = self.originalTauName,
308  Prediscriminants = noPrediscriminants,
309  loadMVAfromDB = self.cms.bool(True),
310  mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"),
311  mvaOpt = self.cms.string("DBnewDMwLTwGJ"),
312  verbosity = self.cms.int32(0)
313  ))
314 
315  _byIsolationNewDMMVArun2017v2VLoose = "rerunDiscriminationByIsolationNewDMMVArun2017v2VLoose"+self.postfix
316  setattr(self.process,_byIsolationNewDMMVArun2017v2VLoose,patDiscriminationByIsolationMVArun2v1VLoose.clone(
317  PATTauProducer = self.originalTauName,
318  Prediscriminants = noPrediscriminants,
319  toMultiplex = _byIsolationNewDMMVArun2017v2raw,
320  key = _byIsolationNewDMMVArun2017v2raw+':category',
321  loadMVAfromDB = self.cms.bool(True),
322  mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
323  mapping = self.cms.VPSet(
324  self.cms.PSet(
325  category = self.cms.uint32(0),
326  cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_WPEff90"), #writeTauIdDiscrWPs
327  variable = self.cms.string("pt"),
328  )
329  ),
330  verbosity = self.cms.int32(0)
331  ))
332  _byIsolationNewDMMVArun2017v2VLooseProd = getattr(self.process,_byIsolationNewDMMVArun2017v2VLoose)
333 
334  _rerunIsolationNewDMMVArun2017v2Task = self.cms.Task(
335  getattr(self.process,_byIsolationNewDMMVArun2017v2raw),
336  _byIsolationNewDMMVArun2017v2VLooseProd
337  )
338  tauIDSources.byIsolationMVArun2017v2DBnewDMwLTraw2017 = self.cms.InputTag(_byIsolationNewDMMVArun2017v2raw)
339  tauIDSources.byVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.cms.InputTag(_byIsolationNewDMMVArun2017v2VLoose)
340 
341  wp_to_eff_match = {
342  "VVLoose" : "WPEff95",
343  "Loose" : "WPEff80",
344  "Medium" : "WPEff70",
345  "Tight" : "WPEff60",
346  "VTight" : "WPEff50",
347  "VVTight" : "WPEff40"
348  }
349  for wp,wpEff in wp_to_eff_match.items():
350  _aWP = "rerunDiscriminationByIsolationNewDMMVArun2017v2"+wp+self.postfix
351  setattr(self.process,_aWP,_byIsolationNewDMMVArun2017v2VLooseProd.clone())
352  _aWPProd = getattr(self.process,_aWP)
353  _aWPProd.mapping[0].cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_"+wpEff)
354  _rerunIsolationNewDMMVArun2017v2Task.add(_aWPProd)
355  setattr(tauIDSources,"by"+wp+"IsolationMVArun2017v2DBnewDMwLT2017",self.cms.InputTag(_aWP))
356 
357  _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2017v2Task)
358  _rerunMvaIsolationSequence += self.cms.Sequence(_rerunIsolationNewDMMVArun2017v2Task)
359 
360  if "dR0p32017v2" in self.toKeep:
361  self.tauIdDiscrMVA_2017_version = "v2"
363  'tauIdMVAIsoDBoldDMdR0p3wLT2017' : "tauIdMVAIsoDBoldDMdR0p3wLT2017",
364  }
366  'tauIdMVAIsoDBoldDMdR0p3wLT2017' : {
367  'Eff95' : "DBoldDMdR0p3wLTEff95",
368  'Eff90' : "DBoldDMdR0p3wLTEff90",
369  'Eff80' : "DBoldDMdR0p3wLTEff80",
370  'Eff70' : "DBoldDMdR0p3wLTEff70",
371  'Eff60' : "DBoldDMdR0p3wLTEff60",
372  'Eff50' : "DBoldDMdR0p3wLTEff50",
373  'Eff40' : "DBoldDMdR0p3wLTEff40"
374  }
375  }
376 
377  if not self.is_above_cmssw_version(9, 4, 5, self.debug):
378  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")
379  self.loadMVA_WPs_run2_2017()
380 
381  _byIsolationOldDMdR0p3MVArun2017v2raw = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw"+self.postfix
382  setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
383  PATTauProducer = self.originalTauName,
384  Prediscriminants = noPrediscriminants,
385  loadMVAfromDB = self.cms.bool(True),
386  mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"),
387  mvaOpt = self.cms.string("DBoldDMwLTwGJ"),
388  srcChargedIsoPtSum = self.cms.string('chargedIsoPtSumdR03'),
389  srcFootprintCorrection = self.cms.string('footprintCorrectiondR03'),
390  srcNeutralIsoPtSum = self.cms.string('neutralIsoPtSumdR03'),
391  srcPhotonPtSumOutsideSignalCone = self.cms.string('photonPtSumOutsideSignalConedR03'),
392  verbosity = self.cms.int32(0)
393  ))
394 
395  _byIsolationOldDMdR0p3MVArun2017v2VLoose = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2VLoose"+self.postfix
396  setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2VLoose,patDiscriminationByIsolationMVArun2v1VLoose.clone(
397  PATTauProducer = self.originalTauName,
398  Prediscriminants = noPrediscriminants,
399  toMultiplex = _byIsolationOldDMdR0p3MVArun2017v2raw,
400  key = _byIsolationOldDMdR0p3MVArun2017v2raw+':category',
401  loadMVAfromDB = self.cms.bool(True),
402  mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
403  mapping = self.cms.VPSet(
404  self.cms.PSet(
405  category = self.cms.uint32(0),
406  cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_WPEff90"), #writeTauIdDiscrWPs
407  variable = self.cms.string("pt"),
408  )
409  ),
410  verbosity = self.cms.int32(0)
411  ))
412  _byIsolationOldDMdR0p3MVArun2017v2VLooseProd = getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2VLoose)
413 
414  _rerunIsolationOldDMdR0p3MVArun2017v2Task = self.cms.Task(
415  getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw),
416  _byIsolationOldDMdR0p3MVArun2017v2VLooseProd
417  )
418  tauIDSources.byIsolationMVArun2017v2DBoldDMdR0p3wLTraw2017 = self.cms.InputTag(_byIsolationOldDMdR0p3MVArun2017v2raw)
419  tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.cms.InputTag(_byIsolationOldDMdR0p3MVArun2017v2VLoose)
420 
421  wp_to_eff_match = {
422  "VVLoose" : "WPEff95",
423  "Loose" : "WPEff80",
424  "Medium" : "WPEff70",
425  "Tight" : "WPEff60",
426  "VTight" : "WPEff50",
427  "VVTight" : "WPEff40"
428  }
429  for wp,wpEff in wp_to_eff_match.items():
430  _aWP = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2"+wp+self.postfix
431  setattr(self.process,_aWP,_byIsolationOldDMdR0p3MVArun2017v2VLooseProd.clone())
432  _aWPProd = getattr(self.process,_aWP)
433  _aWPProd.mapping[0].cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_"+wpEff)
434  _rerunIsolationOldDMdR0p3MVArun2017v2Task.add(_aWPProd)
435  setattr(tauIDSources,"by"+wp+"IsolationMVArun2017v2DBoldDMdR0p3wLT2017",self.cms.InputTag(_aWP))
436 
437  _rerunMvaIsolationTask.add(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
438  _rerunMvaIsolationSequence += self.cms.Sequence(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
439 
440  # 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
441  # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2raw = patDiscriminationByIsolationMVArun2v1raw.clone(
442  # PATTauProducer = self.originalTauName,
443  # Prediscriminants = noPrediscriminants,
444  # loadMVAfromDB = self.cms.bool(True),
445  # mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2"),
446  # mvaOpt = self.cms.string("DBoldDMwLTwGJ"),
447  # verbosity = self.cms.int32(0)
448  # )
449  # #
450  # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2VLoose = patDiscriminationByIsolationMVArun2v1VLoose.clone(
451  # PATTauProducer = self.originalTauName,
452  # Prediscriminants = noPrediscriminants,
453  # toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw'),
454  # key = self.cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw:category'),#?
455  # loadMVAfromDB = self.cms.bool(True),
456  # mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
457  # mapping = self.cms.VPSet(
458  # self.cms.PSet(
459  # category = self.cms.uint32(0),
460  # cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_WPEff90"), #writeTauIdDiscrWPs
461  # variable = self.cms.string("pt"),
462  # )
463  # )
464  # )
465 
466  # 2016 training strategy(v1), trained on 2016MC, old DM
467  if "2016v1" in self.toKeep:
468  _byIsolationOldDMMVArun2016v1raw = "rerunDiscriminationByIsolationOldDMMVArun2v1raw"+self.postfix
469  setattr(self.process,_byIsolationOldDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
470  PATTauProducer = self.originalTauName,
471  Prediscriminants = noPrediscriminants,
472  loadMVAfromDB = self.cms.bool(True),
473  mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"),
474  mvaOpt = self.cms.string("DBoldDMwLT"),
475  verbosity = self.cms.int32(0)
476  ))
477 
478  _byIsolationOldDMMVArun2016v1VLoose = "rerunDiscriminationByIsolationOldDMMVArun2v1VLoose"+self.postfix
479  setattr(self.process,_byIsolationOldDMMVArun2016v1VLoose,patDiscriminationByIsolationMVArun2v1VLoose.clone(
480  PATTauProducer = self.originalTauName,
481  Prediscriminants = noPrediscriminants,
482  toMultiplex = _byIsolationOldDMMVArun2016v1raw,
483  key = _byIsolationOldDMMVArun2016v1raw+':category',
484  loadMVAfromDB = self.cms.bool(True),
485  mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_mvaOutput_normalization"),
486  mapping = self.cms.VPSet(
487  self.cms.PSet(
488  category = self.cms.uint32(0),
489  cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_WPEff90"),
490  variable = self.cms.string("pt"),
491  )
492  )
493  ))
494  _byIsolationOldDMMVArun2016v1VLooseProd = getattr(self.process,_byIsolationOldDMMVArun2016v1VLoose)
495 
496  _rerunIsolationOldDMMVArun2016v1Task = self.cms.Task(
497  getattr(self.process,_byIsolationOldDMMVArun2016v1raw),
498  _byIsolationOldDMMVArun2016v1VLooseProd
499  )
500  tauIDSources.byIsolationMVArun2v1DBoldDMwLTraw2016 = self.cms.InputTag(_byIsolationOldDMMVArun2016v1raw)
501  tauIDSources.byVLooseIsolationMVArun2v2DBoldDMwLT2016 = self.cms.InputTag(_byIsolationOldDMMVArun2016v1VLoose)
502 
503  wp_to_eff_match = {
504  "Loose" : "WPEff80",
505  "Medium" : "WPEff70",
506  "Tight" : "WPEff60",
507  "VTight" : "WPEff50",
508  "VVTight" : "WPEff40"
509  }
510  for wp,wpEff in wp_to_eff_match.items():
511  _aWP = "rerunDiscriminationByIsolationOldDMMVArun2v1"+wp+self.postfix
512  setattr(self.process,_aWP,_byIsolationOldDMMVArun2016v1VLooseProd.clone())
513  _aWPProd = getattr(self.process,_aWP)
514  _aWPProd.mapping[0].cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_"+wpEff)
515  _rerunIsolationOldDMMVArun2016v1Task.add(_aWPProd)
516  setattr(tauIDSources,"by"+wp+"IsolationMVArun2v1DBoldDMwLT2016",self.cms.InputTag(_aWP))
517 
518  _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2016v1Task)
519  _rerunMvaIsolationSequence += self.cms.Sequence(_rerunIsolationOldDMMVArun2016v1Task)
520 
521  # 2016 training strategy(v1), trained on 2016MC, new DM
522  if "newDM2016v1" in self.toKeep:
523  _byIsolationNewDMMVArun2016v1raw = "rerunDiscriminationByIsolationNewDMMVArun2v1raw"+self.postfix
524  setattr(self.process,_byIsolationNewDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
525  PATTauProducer = self.originalTauName,
526  Prediscriminants = noPrediscriminants,
527  loadMVAfromDB = self.cms.bool(True),
528  mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"),
529  mvaOpt = self.cms.string("DBnewDMwLT"),
530  verbosity = self.cms.int32(0)
531  ))
532 
533  _byIsolationNewDMMVArun2016v1VLoose = "rerunDiscriminationByIsolationNewDMMVArun2v1VLoose"+self.postfix
534  setattr(self.process,_byIsolationNewDMMVArun2016v1VLoose,patDiscriminationByIsolationMVArun2v1VLoose.clone(
535  PATTauProducer = self.originalTauName,
536  Prediscriminants = noPrediscriminants,
537  toMultiplex = _byIsolationNewDMMVArun2016v1raw,
538  key = _byIsolationNewDMMVArun2016v1raw+':category',
539  loadMVAfromDB = self.cms.bool(True),
540  mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_mvaOutput_normalization"),
541  mapping = self.cms.VPSet(
542  self.cms.PSet(
543  category = self.cms.uint32(0),
544  cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_WPEff90"),
545  variable = self.cms.string("pt"),
546  )
547  )
548  ))
549  _byIsolationNewDMMVArun2016v1VLooseProd = getattr(self.process,_byIsolationNewDMMVArun2016v1VLoose)
550 
551  _rerunIsolationNewDMMVArun2016v1Task = self.cms.Task(
552  getattr(self.process,_byIsolationNewDMMVArun2016v1raw),
553  _byIsolationNewDMMVArun2016v1VLooseProd
554  )
555  tauIDSources.byIsolationMVArun2v1DBnewDMwLTraw2016 = self.cms.InputTag(_byIsolationNewDMMVArun2016v1raw)
556  tauIDSources.byVLooseIsolationMVArun2v2DBnewDMwLT2016 = self.cms.InputTag(_byIsolationNewDMMVArun2016v1VLoose)
557 
558  wp_to_eff_match = {
559  "Loose" : "WPEff80",
560  "Medium" : "WPEff70",
561  "Tight" : "WPEff60",
562  "VTight" : "WPEff50",
563  "VVTight" : "WPEff40"
564  }
565  for wp,wpEff in wp_to_eff_match.items():
566  _aWP = "rerunDiscriminationByIsolationNewDMMVArun2v1"+wp+self.postfix
567  setattr(self.process,_aWP,_byIsolationNewDMMVArun2016v1VLooseProd.clone())
568  _aWPProd = getattr(self.process,_aWP)
569  _aWPProd.mapping[0].cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_"+wpEff)
570  _rerunIsolationNewDMMVArun2016v1Task.add(_aWPProd)
571  setattr(tauIDSources,"by"+wp+"IsolationMVArun2v1DBnewDMwLT2016",self.cms.InputTag(_aWP))
572 
573  _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2016v1Task)
574  _rerunMvaIsolationSequence += self.cms.Sequence(_rerunIsolationNewDMMVArun2016v1Task)
575 
576  if "deepTau2017v1" in self.toKeep:
577  if self.debug: print ("Adding DeepTau IDs")
578 
579  _deepTauName = "deepTau2017v1"
580  workingPoints_ = {
581  "e": {
582  "VVVLoose" : 0.96424,
583  "VVLoose" : 0.98992,
584  "VLoose" : 0.99574,
585  "Loose": 0.99831,
586  "Medium": 0.99868,
587  "Tight": 0.99898,
588  "VTight": 0.99911,
589  "VVTight": 0.99918
590  },
591  "mu": {
592  "VVVLoose" : 0.959619,
593  "VVLoose" : 0.997687,
594  "VLoose" : 0.999392,
595  "Loose": 0.999755,
596  "Medium": 0.999854,
597  "Tight": 0.999886,
598  "VTight": 0.999944,
599  "VVTight": 0.9999971
600  },
601 
602  "jet": {
603  "VVVLoose" : 0.5329,
604  "VVLoose" : 0.7645,
605  "VLoose" : 0.8623,
606  "Loose": 0.9140,
607  "Medium": 0.9464,
608  "Tight": 0.9635,
609  "VTight": 0.9760,
610  "VVTight": 0.9859
611  }
612  }
613  file_names = ['RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v1_20L1024N_quantized.pb']
614  setattr(self.process,_deepTauName+self.postfix,self.cms.EDProducer("DeepTauId",
615  electrons = self.cms.InputTag('slimmedElectrons'),
616  muons = self.cms.InputTag('slimmedMuons'),
617  taus = self.cms.InputTag(self.originalTauName),
618  pfcands = self.cms.InputTag('packedPFCandidates'),
619  vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'),
620  rho = self.cms.InputTag('fixedGridRhoAll'),
621  graph_file = self.cms.vstring(file_names),
622  mem_mapped = self.cms.bool(False),
623  version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
624  debug_level = self.cms.int32(0),
625  disable_dxy_pca = self.cms.bool(False)
626 
627  ))
628 
629  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
630 
631  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
632  _rerunMvaIsolationTask.add(_deepTauProducer)
633  _rerunMvaIsolationSequence += _deepTauProducer
634 
635  if "deepTau2017v2" in self.toKeep:
636  if self.debug: print ("Adding DeepTau IDs")
637 
638  _deepTauName = "deepTau2017v2"
639  workingPoints_ = {
640  "e": {
641  "VVVLoose": 0.0630386,
642  "VVLoose": 0.1686942,
643  "VLoose": 0.3628130,
644  "Loose": 0.6815435,
645  "Medium": 0.8847544,
646  "Tight": 0.9675541,
647  "VTight": 0.9859251,
648  "VVTight": 0.9928449,
649  },
650  "mu": {
651  "VLoose": 0.1058354,
652  "Loose": 0.2158633,
653  "Medium": 0.5551894,
654  "Tight": 0.8754835,
655  },
656  "jet": {
657  "VVVLoose": 0.2599605,
658  "VVLoose": 0.4249705,
659  "VLoose": 0.5983682,
660  "Loose": 0.7848675,
661  "Medium": 0.8834768,
662  "Tight": 0.9308689,
663  "VTight": 0.9573137,
664  "VVTight": 0.9733927,
665  },
666  }
667 
668  file_names = [
669  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
670  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
671  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
672  ]
673  setattr(self.process,_deepTauName+self.postfix,self.cms.EDProducer("DeepTauId",
674  electrons = self.cms.InputTag('slimmedElectrons'),
675  muons = self.cms.InputTag('slimmedMuons'),
676  taus = self.cms.InputTag(self.originalTauName),
677  pfcands = self.cms.InputTag('packedPFCandidates'),
678  vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'),
679  rho = self.cms.InputTag('fixedGridRhoAll'),
680  graph_file = self.cms.vstring(file_names),
681  mem_mapped = self.cms.bool(True),
682  version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
683  debug_level = self.cms.int32(0),
684  disable_dxy_pca = self.cms.bool(False)
685 
686  ))
687 
688  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
689 
690  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
691  _rerunMvaIsolationTask.add(_deepTauProducer)
692  _rerunMvaIsolationSequence += _deepTauProducer
693 
694  if "deepTau2017v2p1" in self.toKeep:
695  if self.debug: print ("Adding DeepTau IDs")
696 
697  _deepTauName = "deepTau2017v2p1"
698  workingPoints_ = {
699  "e": {
700  "VVVLoose": 0.0630386,
701  "VVLoose": 0.1686942,
702  "VLoose": 0.3628130,
703  "Loose": 0.6815435,
704  "Medium": 0.8847544,
705  "Tight": 0.9675541,
706  "VTight": 0.9859251,
707  "VVTight": 0.9928449,
708  },
709  "mu": {
710  "VLoose": 0.1058354,
711  "Loose": 0.2158633,
712  "Medium": 0.5551894,
713  "Tight": 0.8754835,
714  },
715  "jet": {
716  "VVVLoose": 0.2599605,
717  "VVLoose": 0.4249705,
718  "VLoose": 0.5983682,
719  "Loose": 0.7848675,
720  "Medium": 0.8834768,
721  "Tight": 0.9308689,
722  "VTight": 0.9573137,
723  "VVTight": 0.9733927,
724  },
725  }
726 
727  file_names = [
728  'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
729  'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
730  'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
731  ]
732  setattr(self.process,_deepTauName+self.postfix,self.cms.EDProducer("DeepTauId",
733  electrons = self.cms.InputTag('slimmedElectrons'),
734  muons = self.cms.InputTag('slimmedMuons'),
735  taus = self.cms.InputTag(self.originalTauName),
736  pfcands = self.cms.InputTag('packedPFCandidates'),
737  vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'),
738  rho = self.cms.InputTag('fixedGridRhoAll'),
739  graph_file = self.cms.vstring(file_names),
740  mem_mapped = self.cms.bool(True),
741  version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
742  debug_level = self.cms.int32(0),
743  disable_dxy_pca = self.cms.bool(True)
744 
745  ))
746 
747  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
748 
749  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
750  _rerunMvaIsolationTask.add(_deepTauProducer)
751  _rerunMvaIsolationSequence += _deepTauProducer
752 
753  if "DPFTau_2016_v0" in self.toKeep:
754  if self.debug: print ("Adding DPFTau isolation (v0)")
755 
756  _deepTauName = "DPFTau_2016_v0"
757  workingPoints_ = {
758  "all": {
759  "Tight" : "if(decayMode == 0) return (0.898328 - 0.000160992 * pt);" + \
760  "if(decayMode == 1) return (0.910138 - 0.000229923 * pt);" + \
761  "if(decayMode == 10) return (0.873958 - 0.0002328 * pt);" + \
762  "return 99.0;"
763  #"Tight" : "? decayMode == 0 ? (0.898328 - 0.000160992 * pt) : " +
764  # "(? decayMode == 1 ? 0.910138 - 0.000229923 * pt : " +
765  # "(? decayMode == 10 ? (0.873958 - 0.0002328 * pt) : 1))"
766  # "Tight" : "(decayMode == 0) * (0.898328 - 0.000160992 * pt) + \
767  # (decayMode == 1) * (0.910138 - 0.000229923 * pt) + \
768  # (decayMode == 10) * (0.873958 - 0.0002328 * pt) "
769  }
770  }
771  file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v0_quantized.pb' ]
772  setattr(self.process,_deepTauName+self.postfix,self.cms.EDProducer("DPFIsolation",
773  pfcands = self.cms.InputTag('packedPFCandidates'),
774  taus = self.cms.InputTag(self.originalTauName),
775  vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'),
776  graph_file = self.cms.vstring(file_names),
777  version = self.cms.uint32(self.getDpfTauVersion(file_names[0])),
778  mem_mapped = self.cms.bool(False)
779  ))
780 
781  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
782 
783  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
784  _rerunMvaIsolationTask.add(_deepTauProducer)
785  _rerunMvaIsolationSequence += _deepTauProducer
786 
787  if "DPFTau_2016_v1" in self.toKeep:
788  print ("Adding DPFTau isolation (v1)")
789  print ("WARNING: WPs are not defined for DPFTau_2016_v1")
790  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).")
791 
792  _deepTauName = "DPFTau_2016_v1"
793  workingPoints_ = {
794  "all": {"Tight" : 0.123} #FIXME: define WP
795  }
796 
797  file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v1_quantized.pb' ]
798  setattr(self.process,_deepTauName+self.postfix,self.cms.EDProducer("DPFIsolation",
799  pfcands = self.cms.InputTag('packedPFCandidates'),
800  taus = self.cms.InputTag(self.originalTauName),
801  vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'),
802  graph_file = self.cms.vstring(file_names),
803  version = self.cms.uint32(self.getDpfTauVersion(file_names[0])),
804  mem_mapped = self.cms.bool(False)
805  ))
806 
807  self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
808 
809  _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
810  _rerunMvaIsolationTask.add(_deepTauProducer)
811  _rerunMvaIsolationSequence += _deepTauProducer
812 
813  if "againstEle2018" in self.toKeep:
814  antiElectronDiscrMVA6_version = "MVA6v3_noeveto"
815  ### Define new anti-e discriminants
816  ## Raw
817  from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6
818  _byElectronRejectionMVA62018Raw = "patTauDiscriminationByElectronRejectionMVA62018Raw"+self.postfix
819  setattr(self.process,_byElectronRejectionMVA62018Raw,patTauDiscriminationAgainstElectronMVA6.clone(
820  PATTauProducer = self.originalTauName,
821  Prediscriminants = noPrediscriminants, #already selected for MiniAOD
822  vetoEcalCracks = self.cms.bool(False), #keep taus in EB-EE cracks
823  mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL',
824  mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC',
825  mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL',
826  mvaName_NoEleMatch_woGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC',
827  mvaName_wGwGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL',
828  mvaName_wGwGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC',
829  mvaName_woGwGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL',
830  mvaName_woGwGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'
831  ))
832  ## WPs
833  from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer
834  # VLoose
835  _byElectronRejectionMVA62018VLoose = "patTauDiscriminationByVLooseElectronRejectionMVA62018"+self.postfix
836  setattr(self.process,_byElectronRejectionMVA62018VLoose,patTauDiscriminantCutMultiplexer.clone(
837  PATTauProducer = self.originalTauName,
838  Prediscriminants = noPrediscriminants,
839  toMultiplex = _byElectronRejectionMVA62018Raw,
840  key = _byElectronRejectionMVA62018Raw+":category",
841  mapping = self.cms.VPSet(
842  self.cms.PSet(
843  category = self.cms.uint32(0),
844  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL_WPeff98'),
845  variable = self.cms.string('pt')
846  ),
847  self.cms.PSet(
848  category = self.cms.uint32(2),
849  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL_WPeff98'),
850  variable = self.cms.string('pt')
851  ),
852  self.cms.PSet(
853  category = self.cms.uint32(5),
854  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL_WPeff98'),
855  variable = self.cms.string('pt')
856  ),
857  self.cms.PSet(
858  category = self.cms.uint32(7),
859  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL_WPeff98'),
860  variable = self.cms.string('pt')
861  ),
862  self.cms.PSet(
863  category = self.cms.uint32(8),
864  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC_WPeff98'),
865  variable = self.cms.string('pt')
866  ),
867  self.cms.PSet(
868  category = self.cms.uint32(10),
869  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC_WPeff98'),
870  variable = self.cms.string('pt')
871  ),
872  self.cms.PSet(
873  category = self.cms.uint32(13),
874  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC_WPeff98'),
875  variable = self.cms.string('pt')
876  ),
877  self.cms.PSet(
878  category = self.cms.uint32(15),
879  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC_WPeff98'),
880  variable = self.cms.string('pt')
881  )
882  )
883  ))
884  _byElectronRejectionMVA62018VLooseProd = getattr(self.process,_byElectronRejectionMVA62018VLoose)
885 
886  _patTauDiscriminationByElectronRejectionMVA62018Task = self.cms.Task(
887  getattr(self.process,_byElectronRejectionMVA62018Raw),
888  _byElectronRejectionMVA62018VLooseProd
889  )
890  _againstElectronTauIDSources = self.cms.PSet(
891  againstElectronMVA6Raw2018 = self.cms.InputTag(_byElectronRejectionMVA62018Raw),
892  againstElectronMVA6category2018 = self.cms.InputTag(_byElectronRejectionMVA62018Raw,"category"),
893  againstElectronVLooseMVA62018 = self.cms.InputTag(_byElectronRejectionMVA62018VLoose)
894  )
895  # Other WPs
896  wp_to_eff_match = {
897  "Loose" : "WPeff90",
898  "Medium" : "WPeff80",
899  "Tight" : "WPeff70",
900  "VTight" : "WPeff60",
901  }
902  for wp,wpEff in wp_to_eff_match.items():
903  _aWP = "patTauDiscriminationBy"+wp+"ElectronRejectionMVA62018"+self.postfix
904  setattr(self.process,_aWP,_byElectronRejectionMVA62018VLooseProd.clone(
905  mapping = self.cms.VPSet(
906  self.cms.PSet(
907  category = self.cms.uint32(0),
908  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL_'+wpEff),
909  variable = self.cms.string('pt')
910  ),
911  self.cms.PSet(
912  category = self.cms.uint32(2),
913  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL_'+wpEff),
914  variable = self.cms.string('pt')
915  ),
916  self.cms.PSet(
917  category = self.cms.uint32(5),
918  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL_'+wpEff),
919  variable = self.cms.string('pt')
920  ),
921  self.cms.PSet(
922  category = self.cms.uint32(7),
923  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL_'+wpEff),
924  variable = self.cms.string('pt')
925  ),
926  self.cms.PSet(
927  category = self.cms.uint32(8),
928  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC_'+wpEff),
929  variable = self.cms.string('pt')
930  ),
931  self.cms.PSet(
932  category = self.cms.uint32(10),
933  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC_'+wpEff),
934  variable = self.cms.string('pt')
935  ),
936  self.cms.PSet(
937  category = self.cms.uint32(13),
938  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC_'+wpEff),
939  variable = self.cms.string('pt')
940  ),
941  self.cms.PSet(
942  category = self.cms.uint32(15),
943  cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC_'+wpEff),
944  variable = self.cms.string('pt')
945  )
946  )
947  ))
948  _patTauDiscriminationByElectronRejectionMVA62018Task.add(getattr(self.process,_aWP))
949  setattr(_againstElectronTauIDSources,"againstElectron"+wp+"MVA62018",self.cms.InputTag(_aWP))
950 
951  _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA62018Task)
952  _rerunMvaIsolationSequence += self.cms.Sequence(_patTauDiscriminationByElectronRejectionMVA62018Task)
953 
954  _tauIDSourcesWithAgainistEle = self.cms.PSet(
955  tauIDSources.clone(),
956  _againstElectronTauIDSources
957  )
958  tauIDSources =_tauIDSourcesWithAgainistEle.clone()
959 
960 
961  if self.debug: print('Embedding new TauIDs into \"'+self.updatedTauName+'\"')
962  if not hasattr(self.process, self.updatedTauName):
963  embedID = self.cms.EDProducer("PATTauIDEmbedder",
964  src = self.cms.InputTag(self.originalTauName),
965  tauIDSources = tauIDSources
966  )
967  setattr(self.process, self.updatedTauName, embedID)
968  else: #assume same type
969  tauIDSources = self.cms.PSet(
970  getattr(self.process, self.updatedTauName).tauIDSources,
971  tauIDSources)
972  getattr(self.process, self.updatedTauName).tauIDSources = tauIDSources
973  setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_rerunMvaIsolationTask)
974  setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_rerunMvaIsolationSequence)
975 
976 
977  def processDeepProducer(self, producer_name, tauIDSources, workingPoints_):
978  for target,points in six.iteritems(workingPoints_):
979  cuts = self.cms.PSet()
980  setattr(tauIDSources, 'by{}VS{}raw'.format(producer_name[0].upper()+producer_name[1:], target),
981  self.cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)))
982  for point,cut in six.iteritems(points):
983  setattr(cuts, point, self.cms.string(str(cut)))
984 
985  setattr(tauIDSources, 'by{}{}VS{}'.format(point, producer_name[0].upper()+producer_name[1:], target),
986  self.cms.InputTag(producer_name+self.postfix, 'VS{}{}'.format(target, point)))
987 
988  setattr(getattr(self.process, producer_name+self.postfix), 'VS{}WP'.format(target), cuts)
989 
990 
991  def getDpfTauVersion(self, file_name):
992  """returns the DNN version. File name should contain a version label with data takig year (2011-2, 2015-8) and \
993  version number (vX), e.g. 2017v0, in general the following format: {year}v{version}"""
994  version_search = re.search('201[125678]v([0-9]+)[\._]', file_name)
995  if not version_search:
996  raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}". \
997  Unable to extract version number.'.format(file_name))
998  version = version_search.group(1)
999  return int(version)
1000 
1001  def getDeepTauVersion(self, file_name):
1002  """returns the DeepTau year, version, subversion. File name should contain a version label with data takig year \
1003  (2011-2, 2015-8), version number (vX) and subversion (pX), e.g. 2017v0p6, in general the following format: \
1004  {year}v{version}p{subversion}"""
1005  version_search = re.search('(201[125678])v([0-9]+)(p[0-9]+|)[\._]', file_name)
1006  if not version_search:
1007  raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}p{subversion}". \
1008  Unable to extract version number.'.format(file_name))
1009  year = version_search.group(1)
1010  version = version_search.group(2)
1011  subversion = version_search.group(3)
1012  if len(subversion) > 0:
1013  subversion = subversion[1:]
1014  else:
1015  subversion = 0
1016  return int(year), int(version), int(subversion)
def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug=False)
Definition: runTauIdMVA.py:88
def getDeepTauVersion(self, file_name)
def get_cmssw_version_number(klass, debug=False)
Definition: runTauIdMVA.py:70
def get_cmssw_version(debug=False)
Definition: runTauIdMVA.py:63
def getDpfTauVersion(self, file_name)
Definition: runTauIdMVA.py:991
def loadMVA_WPs_run2_2017(self)
Definition: runTauIdMVA.py:97
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def processDeepProducer(self, producer_name, tauIDSources, workingPoints_)
Definition: runTauIdMVA.py:977
def versionToInt(release=9, subversion=4, patch=0, debug=False)
Definition: runTauIdMVA.py:81
#define str(s)
double split
Definition: MVATrainer.cc:139