Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-15 22:39:33

0001 from __future__ import print_function
0002 import FWCore.ParameterSet.Config as cms
0003 from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants
0004 from RecoTauTag.RecoTau.PATTauDiscriminationByMVAIsolationRun2_cff import patDiscriminationByIsolationMVArun2v1raw, patDiscriminationByIsolationMVArun2v1
0005 from RecoTauTag.RecoTau.DeepTau_cfi import DeepTau
0006 from RecoTauTag.RecoTau.DeepTauIdSonicProducer_cfi import DeepTauIdSonicProducer
0007 from RecoTauTag.RecoTau.tauIdWPsDefs import WORKING_POINTS_v2p1, WORKING_POINTS_v2p5, WORKING_POINTS_PHASEII_v2p5
0008 
0009 import os
0010 import re
0011 
0012 class TauIDEmbedder(object):
0013     """class to rerun the tau seq and acces trainings from the database"""
0014     experimentalDiscriminators = [
0015         "2017v1", "2017v2", "newDM2017v2", "dR0p32017v2", "2016v1", "newDM2016v1",
0016         "againstEle2018"
0017     ]
0018     availableDiscriminators = experimentalDiscriminators.copy()
0019     availableDiscriminators.extend([
0020         "mvaIso", "mvaIsoNewDM", "mvaIsoDR0p3", #payloads from GT (2017v2)
0021         "againstEle", #payloads from GT (2018)
0022         "newDMPhase2v1", #payloads from phase2 GT
0023         "againstElePhase2v1", #payloads from phase2 GT
0024         "deepTau2017v2", "deepTau2017v2p1", "deepTau2018v2p5", "deepTau2026v2p5"
0025     ])
0026 
0027     def __init__(self, process, debug = False,
0028                  originalTauName = "slimmedTaus",
0029                  updatedTauName = "slimmedTausNewID",
0030                  postfix = "",
0031                  toKeep =  ["deepTau2017v2p1", "deepTau2018v2p5", "deepTau2026v2p5"],
0032                  conditionDB = "" # preparational DB: 'frontier://FrontierPrep/CMS_CONDITIONS'
0033                  ):
0034         super(TauIDEmbedder, self).__init__()
0035         self.process = process
0036         self.debug = debug
0037         self.originalTauName = originalTauName
0038         self.updatedTauName = updatedTauName
0039         self.postfix = postfix
0040 
0041         for discr in toKeep:
0042             if discr not in TauIDEmbedder.availableDiscriminators:
0043                 raise RuntimeError('TauIDEmbedder: discriminator "{}" is not supported'.format(discr))
0044         self.toKeep = toKeep
0045         if not set(toKeep).isdisjoint(TauIDEmbedder.experimentalDiscriminators):
0046             print('There are experimental tauIDs not from GT')
0047             self.process.load('RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi')
0048             if len(conditionDB) != 0:
0049                 self.process.CondDBTauConnection.connect = cms.string(conditionDB)
0050                 self.process.loadRecoTauTagMVAsFromPrepDB.connect = cms.string(conditionDB)
0051             # if debug:
0052             #   print self.process.CondDBTauConnection.connect
0053             #   print dir(self.process.loadRecoTauTagMVAsFromPrepDB)
0054             #   print self.process.loadRecoTauTagMVAsFromPrepDB.parameterNames_
0055     
0056     @staticmethod
0057     def get_cmssw_version(debug = False):
0058         """returns 'CMSSW_X_Y_Z'"""
0059         cmssw_version = os.environ["CMSSW_VERSION"]
0060         if debug: print ("get_cmssw_version:", cmssw_version)
0061         return cmssw_version
0062 
0063     @classmethod
0064     def get_cmssw_version_number(klass, debug = False):
0065         """returns '(release, subversion, patch)' (without 'CMSSW_')"""
0066         v = klass.get_cmssw_version().split("CMSSW_")[1].split("_")[0:3]
0067         if debug: print ("get_cmssw_version_number:", v)
0068         try:
0069             patch = int(v[2])
0070         except:
0071             patch = -1
0072         return int(v[0]), int(v[1]), patch
0073 
0074     @staticmethod
0075     def versionToInt(release=9, subversion=4, patch=0, debug = False):
0076         version = release * 10000 + subversion * 100 + patch + 1 # shifted by one to account for pre-releases.
0077         if debug: print ("versionToInt:", version)
0078         return version
0079 
0080 
0081     @classmethod
0082     def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug = False):
0083         split_cmssw_version = klass.get_cmssw_version_number()
0084         if klass.versionToInt(release, subversion, patch) > klass.versionToInt(split_cmssw_version[0], split_cmssw_version[1], split_cmssw_version[2]):
0085             if debug: print ("is_above_cmssw_version:", False)
0086             return False
0087         else:
0088             if debug: print ("is_above_cmssw_version:", True)
0089             return True
0090 
0091     def tauIDMVAinputs(self, module, wp):
0092         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)))
0093 
0094     def loadMVA_WPs_run2_2017(self):
0095         if self.debug: print ("loadMVA_WPs_run2_2017: performed")
0096         global cms
0097         for training, gbrForestName in self.tauIdDiscrMVA_trainings_run2_2017.items():
0098 
0099             self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
0100                 cms.PSet(
0101                     record = cms.string('GBRWrapperRcd'),
0102                     tag = cms.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
0103                     label = cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
0104                 )
0105             )
0106 
0107             for WP in self.tauIdDiscrMVA_WPs_run2_2017[training].keys():
0108                 self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
0109                     cms.PSet(
0110                         record = cms.string('PhysicsTGraphPayloadRcd'),
0111                         tag = cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)),
0112                         label = cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP))
0113                     )
0114                 )
0115 
0116             self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
0117                 cms.PSet(
0118                     record = cms.string('PhysicsTFormulaPayloadRcd'),
0119                     tag = cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)),
0120                     label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version))
0121                 )
0122             )
0123 
0124     def load_againstElectronMVA6(self):
0125         if self.debug: print ("load_againstElectronMVA6: performed")
0126         global cms
0127         antiElectronDiscrMVA6_categories = {
0128             '0' : "gbr_NoEleMatch_woGwoGSF_BL",
0129             '2' : "gbr_NoEleMatch_wGwoGSF_BL",
0130             '5' : "gbr_woGwGSF_BL",
0131             '7' : "gbr_wGwGSF_BL",
0132             '8' : "gbr_NoEleMatch_woGwoGSF_EC",
0133             '10' : "gbr_NoEleMatch_wGwoGSF_EC",
0134             '13' : "gbr_woGwGSF_EC",
0135             '15' : "gbr_wGwGSF_EC"
0136         }
0137         for category, gbrForestName in antiElectronDiscrMVA6_categories.items():
0138             self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
0139                 cms.PSet(
0140                     record = cms.string('GBRWrapperRcd'),
0141                     tag = cms.string("RecoTauTag_antiElectronMVA6%s_%s" % (self.antiElectronDiscrMVA6_version, gbrForestName)),
0142                     label = cms.untracked.string("RecoTauTag_antiElectronMVA6%s_%s" % (self.antiElectronDiscrMVA6_version, gbrForestName))
0143                 )
0144             )
0145             for WP in self.antiElectronDiscrMVA6_WPs:
0146                 self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append(
0147                     cms.PSet(
0148                         record = cms.string('PhysicsTGraphPayloadRcd'),
0149                         tag = cms.string("RecoTauTag_antiElectronMVA6%s_%s_WP%s" % (self.antiElectronDiscrMVA6_version, gbrForestName, WP)),
0150                         label = cms.untracked.string("RecoTauTag_antiElectronMVA6%s_%s_WP%s" % (self.antiElectronDiscrMVA6_version, gbrForestName, WP))
0151                     )
0152                 )
0153 
0154     def runTauID(self):
0155         _rerunMvaIsolationTask = cms.Task()
0156         _rerunMvaIsolationSequence = cms.Sequence()
0157         tauIDSources = cms.PSet()
0158 
0159         # MVAIso tauIDs with version given by payloads in GT (2017v2)
0160         if "mvaIso" in self.toKeep:
0161             _byIsolationOldDMMVAraw = "rerunDiscriminationByIsolationOldDMMVAraw"+self.postfix
0162             setattr(self.process,_byIsolationOldDMMVAraw,patDiscriminationByIsolationMVArun2v1raw.clone(
0163                 PATTauProducer = self.originalTauName,
0164                 Prediscriminants = noPrediscriminants,
0165                 loadMVAfromDB = cms.bool(True),
0166                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT"),
0167                 mvaOpt = cms.string("DBoldDMwLTwGJ"),
0168                 verbosity = cms.int32(0)
0169             ))
0170 
0171             _byIsolationOldDMMVA = "rerunDiscriminationByIsolationOldDMMVA"+self.postfix
0172             setattr(self.process,_byIsolationOldDMMVA,patDiscriminationByIsolationMVArun2v1.clone(
0173                 PATTauProducer = self.originalTauName,
0174                 Prediscriminants = noPrediscriminants,
0175                 toMultiplex = _byIsolationOldDMMVAraw,
0176                 loadMVAfromDB = cms.bool(True),
0177                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0178                 mapping = cms.VPSet(
0179                     cms.PSet(
0180                         category = cms.uint32(0),
0181                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT"), #writeTauIdDiscrWPs
0182                         variable = cms.string("pt"),
0183                     )
0184                 ),
0185                 workingPoints = cms.vstring(
0186                     "_VVLoose",
0187                     "_VLoose",
0188                     "_Loose",
0189                     "_Medium",
0190                     "_Tight",
0191                     "_VTight",
0192                     "_VVTight"
0193                 )
0194             ))
0195 
0196             _rerunIsolationOldDMMVATask =  cms.Task(
0197                 getattr(self.process,_byIsolationOldDMMVAraw),
0198                 getattr(self.process,_byIsolationOldDMMVA)
0199             )
0200             _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVATask)
0201             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVATask)
0202 
0203             tauIDSources.byIsolationMVArun2DBoldDMwLTraw = self.tauIDMVAinputs(_byIsolationOldDMMVA, "raw")
0204             tauIDSources.byVVLooseIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VVLoose")
0205             tauIDSources.byVLooseIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VLoose")
0206             tauIDSources.byLooseIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_Loose")
0207             tauIDSources.byMediumIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_Medium")
0208             tauIDSources.byTightIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_Tight")
0209             tauIDSources.byVTightIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VTight")
0210             tauIDSources.byVVTightIsolationMVArun2DBoldDMwLT = self.tauIDMVAinputs(_byIsolationOldDMMVA, "_VVTight")
0211 
0212         if "mvaIsoNewDM" in self.toKeep:
0213             _byIsolationNewDMMVAraw = "rerunDiscriminationByIsolationNewDMMVAraw"+self.postfix
0214             setattr(self.process,_byIsolationNewDMMVAraw,patDiscriminationByIsolationMVArun2v1raw.clone(
0215                 PATTauProducer = self.originalTauName,
0216                 Prediscriminants = noPrediscriminants,
0217                 loadMVAfromDB = cms.bool(True),
0218                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT"),
0219                 mvaOpt = cms.string("DBnewDMwLTwGJ"),
0220                 verbosity = cms.int32(0)
0221             ))
0222 
0223             _byIsolationNewDMMVA = "rerunDiscriminationByIsolationNewDMMVA"+self.postfix
0224             setattr(self.process,_byIsolationNewDMMVA,patDiscriminationByIsolationMVArun2v1.clone(
0225                 PATTauProducer = self.originalTauName,
0226                 Prediscriminants = noPrediscriminants,
0227                 toMultiplex = _byIsolationNewDMMVAraw,
0228                 loadMVAfromDB = cms.bool(True),
0229                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0230                 mapping = cms.VPSet(
0231                     cms.PSet(
0232                         category = cms.uint32(0),
0233                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT"), #writeTauIdDiscrWPs
0234                         variable = cms.string("pt"),
0235                     )
0236                 ),
0237                 workingPoints = cms.vstring(
0238                     "_VVLoose",
0239                     "_VLoose",
0240                     "_Loose",
0241                     "_Medium",
0242                     "_Tight",
0243                     "_VTight",
0244                     "_VVTight"
0245                 )
0246             ))
0247 
0248             _rerunIsolationNewDMMVATask =  cms.Task(
0249                 getattr(self.process,_byIsolationNewDMMVAraw),
0250                 getattr(self.process,_byIsolationNewDMMVA)
0251             )
0252             _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVATask)
0253             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVATask)
0254 
0255             tauIDSources.byIsolationMVArun2DBnewDMwLTraw = self.tauIDMVAinputs(_byIsolationNewDMMVA, "raw")
0256             tauIDSources.byVVLooseIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VVLoose")
0257             tauIDSources.byVLooseIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VLoose")
0258             tauIDSources.byLooseIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_Loose")
0259             tauIDSources.byMediumIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_Medium")
0260             tauIDSources.byTightIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_Tight")
0261             tauIDSources.byVTightIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VTight")
0262             tauIDSources.byVVTightIsolationMVArun2DBnewDMwLT = self.tauIDMVAinputs(_byIsolationNewDMMVA, "_VVTight")
0263 
0264         if "mvaIsoDR0p3" in self.toKeep:
0265             _byIsolationOldDMdR0p3MVAraw = "rerunDiscriminationByIsolationOldDMdR0p3MVAraw"+self.postfix
0266             setattr(self.process,_byIsolationOldDMdR0p3MVAraw,patDiscriminationByIsolationMVArun2v1raw.clone(
0267                 PATTauProducer = self.originalTauName,
0268                 Prediscriminants = noPrediscriminants,
0269                 loadMVAfromDB = cms.bool(True),
0270                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT"),
0271                 mvaOpt = cms.string("DBoldDMwLTwGJ"),
0272                 srcChargedIsoPtSum = cms.string('chargedIsoPtSumdR03'),
0273                 srcFootprintCorrection = cms.string('footprintCorrectiondR03'),
0274                 srcNeutralIsoPtSum = cms.string('neutralIsoPtSumdR03'),
0275                 srcPhotonPtSumOutsideSignalCone = cms.string('photonPtSumOutsideSignalConedR03'),
0276                 verbosity = cms.int32(0)
0277             ))
0278 
0279             _byIsolationOldDMdR0p3MVA = "rerunDiscriminationByIsolationOldDMdR0p3MVA"+self.postfix
0280             setattr(self.process,_byIsolationOldDMdR0p3MVA,patDiscriminationByIsolationMVArun2v1.clone(
0281                 PATTauProducer = self.originalTauName,
0282                 Prediscriminants = noPrediscriminants,
0283                 toMultiplex = _byIsolationOldDMdR0p3MVAraw,
0284                 loadMVAfromDB = cms.bool(True),
0285                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0286                 mapping = cms.VPSet(
0287                     cms.PSet(
0288                         category = cms.uint32(0),
0289                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT"), #writeTauIdDiscrWPs
0290                         variable = cms.string("pt"),
0291                     )
0292                 ),
0293                 workingPoints = cms.vstring(
0294                     "_VVLoose",
0295                     "_VLoose",
0296                     "_Loose",
0297                     "_Medium",
0298                     "_Tight",
0299                     "_VTight",
0300                     "_VVTight"
0301                 )
0302             ))
0303 
0304             _rerunIsolationOldDMdR0p3MVATask =  cms.Task(
0305                 getattr(self.process,_byIsolationOldDMdR0p3MVAraw),
0306                 getattr(self.process,_byIsolationOldDMdR0p3MVA)
0307             )
0308             _rerunMvaIsolationTask.add(_rerunIsolationOldDMdR0p3MVATask)
0309             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMdR0p3MVATask)
0310 
0311             tauIDSources.byIsolationMVArun2DBoldDMdR0p3wLTraw = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "raw")
0312             tauIDSources.byVVLooseIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VVLoose")
0313             tauIDSources.byVLooseIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VLoose")
0314             tauIDSources.byLooseIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_Loose")
0315             tauIDSources.byMediumIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_Medium")
0316             tauIDSources.byTightIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_Tight")
0317             tauIDSources.byVTightIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VTight")
0318             tauIDSources.byVVTightIsolationMVArun2DBoldDMdR0p3wLT = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVA, "_VVTight")
0319 
0320         # rerun the seq to obtain the 2017 nom training with 0.5 iso cone, old DM, ptph>1, trained on 2017MCv1
0321         if "2017v1" in self.toKeep:
0322             self.tauIdDiscrMVA_2017_version = "v1"
0323             self.tauIdDiscrMVA_trainings_run2_2017 = {
0324                 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
0325             }
0326             self.tauIdDiscrMVA_WPs_run2_2017 = {
0327                 'tauIdMVAIsoDBoldDMwLT2017' : {
0328                     'Eff95' : "DBoldDMwLTEff95",
0329                     'Eff90' : "DBoldDMwLTEff90",
0330                     'Eff80' : "DBoldDMwLTEff80",
0331                     'Eff70' : "DBoldDMwLTEff70",
0332                     'Eff60' : "DBoldDMwLTEff60",
0333                     'Eff50' : "DBoldDMwLTEff50",
0334                     'Eff40' : "DBoldDMwLTEff40"
0335                 }
0336             }
0337             # update the list of available in DB samples
0338             if self.debug: print ("runTauID: Will update the list of available in DB samples to access 2017v1")
0339             self.loadMVA_WPs_run2_2017()
0340 
0341             _byIsolationOldDMMVArun2017v1raw = "rerunDiscriminationByIsolationOldDMMVArun2017v1raw"+self.postfix
0342             setattr(self.process,_byIsolationOldDMMVArun2017v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
0343                 PATTauProducer = self.originalTauName,
0344                 Prediscriminants = noPrediscriminants,
0345                 loadMVAfromDB = cms.bool(True),
0346                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"),
0347                 mvaOpt = cms.string("DBoldDMwLTwGJ"),
0348                 verbosity = cms.int32(0)
0349             ))
0350 
0351             _byIsolationOldDMMVArun2017v1 = "rerunDiscriminationByIsolationOldDMMVArun2017v1"+self.postfix
0352             setattr(self.process,_byIsolationOldDMMVArun2017v1,patDiscriminationByIsolationMVArun2v1.clone(
0353                 PATTauProducer = self.originalTauName,
0354                 Prediscriminants = noPrediscriminants,
0355                 toMultiplex = _byIsolationOldDMMVArun2017v1raw,
0356                 loadMVAfromDB = cms.bool(True),
0357                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0358                 mapping = cms.VPSet(
0359                     cms.PSet(
0360                         category = cms.uint32(0),
0361                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"), #writeTauIdDiscrWPs
0362                         variable = cms.string("pt"),
0363                     )
0364                 ),
0365                 workingPoints = cms.vstring(
0366                     "_WPEff95",
0367                     "_WPEff90",
0368                     "_WPEff80",
0369                     "_WPEff70",
0370                     "_WPEff60",
0371                     "_WPEff50",
0372                     "_WPEff40"
0373                 )
0374             ))
0375 
0376             _rerunIsolationOldDMMVArun2017v1Task =  cms.Task(
0377                 getattr(self.process,_byIsolationOldDMMVArun2017v1raw),
0378                 getattr(self.process,_byIsolationOldDMMVArun2017v1)
0379             )
0380             _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v1Task)
0381             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2017v1Task)
0382 
0383             tauIDSources.byIsolationMVArun2017v1DBoldDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "raw")
0384             tauIDSources.byVVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff95")
0385             tauIDSources.byVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff90")
0386             tauIDSources.byLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff80")
0387             tauIDSources.byMediumIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff70")
0388             tauIDSources.byTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff60")
0389             tauIDSources.byVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff50")
0390             tauIDSources.byVVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v1, "_WPEff40")
0391 
0392         if "2017v2" in self.toKeep:
0393             self.tauIdDiscrMVA_2017_version = "v2"
0394             self.tauIdDiscrMVA_trainings_run2_2017 = {
0395                 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
0396             }
0397             self.tauIdDiscrMVA_WPs_run2_2017 = {
0398                 'tauIdMVAIsoDBoldDMwLT2017' : {
0399                     'Eff95' : "DBoldDMwLTEff95",
0400                     'Eff90' : "DBoldDMwLTEff90",
0401                     'Eff80' : "DBoldDMwLTEff80",
0402                     'Eff70' : "DBoldDMwLTEff70",
0403                     'Eff60' : "DBoldDMwLTEff60",
0404                     'Eff50' : "DBoldDMwLTEff50",
0405                     'Eff40' : "DBoldDMwLTEff40"
0406                 }
0407             }
0408 
0409             if self.debug: print ("runTauID: Will update the list of available in DB samples to access 2017v2")
0410             self.loadMVA_WPs_run2_2017()
0411 
0412             _byIsolationOldDMMVArun2017v2raw = "rerunDiscriminationByIsolationOldDMMVArun2017v2raw"+self.postfix
0413             setattr(self.process,_byIsolationOldDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
0414                 PATTauProducer = self.originalTauName,
0415                 Prediscriminants = noPrediscriminants,
0416                 loadMVAfromDB = cms.bool(True),
0417                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"),
0418                 mvaOpt = cms.string("DBoldDMwLTwGJ"),
0419                 verbosity = cms.int32(0)
0420             ))
0421 
0422             _byIsolationOldDMMVArun2017v2 = "rerunDiscriminationByIsolationOldDMMVArun2017v2"+self.postfix
0423             setattr(self.process,_byIsolationOldDMMVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
0424                 PATTauProducer = self.originalTauName,
0425                 Prediscriminants = noPrediscriminants,
0426                 toMultiplex = _byIsolationOldDMMVArun2017v2raw,
0427                 loadMVAfromDB = cms.bool(True),
0428                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0429                 mapping = cms.VPSet(
0430                     cms.PSet(
0431                         category = cms.uint32(0),
0432                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"), #writeTauIdDiscrWPs
0433                         variable = cms.string("pt"),
0434                     )
0435                 ),
0436                 workingPoints = cms.vstring(
0437                     "_WPEff95",
0438                     "_WPEff90",
0439                     "_WPEff80",
0440                     "_WPEff70",
0441                     "_WPEff60",
0442                     "_WPEff50",
0443                     "_WPEff40"
0444                 ),
0445                 verbosity = cms.int32(0)
0446             ))
0447 
0448             _rerunIsolationOldDMMVArun2017v2Task = cms.Task(
0449                 getattr(self.process,_byIsolationOldDMMVArun2017v2raw),
0450                 getattr(self.process,_byIsolationOldDMMVArun2017v2)
0451             )
0452             _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2017v2Task)
0453             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2017v2Task)
0454 
0455             tauIDSources.byIsolationMVArun2017v2DBoldDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "raw")
0456             tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff95")
0457             tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff90")
0458             tauIDSources.byLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff80")
0459             tauIDSources.byMediumIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff70")
0460             tauIDSources.byTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff60")
0461             tauIDSources.byVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff50")
0462             tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2017v2, "_WPEff40")
0463 
0464         if "newDM2017v2" in self.toKeep:
0465             self.tauIdDiscrMVA_2017_version = "v2"
0466             self.tauIdDiscrMVA_trainings_run2_2017 = {
0467                 'tauIdMVAIsoDBnewDMwLT2017' : "tauIdMVAIsoDBnewDMwLT2017",
0468             }
0469             self.tauIdDiscrMVA_WPs_run2_2017 = {
0470                 'tauIdMVAIsoDBnewDMwLT2017' : {
0471                     'Eff95' : "DBnewDMwLTEff95",
0472                     'Eff90' : "DBnewDMwLTEff90",
0473                     'Eff80' : "DBnewDMwLTEff80",
0474                     'Eff70' : "DBnewDMwLTEff70",
0475                     'Eff60' : "DBnewDMwLTEff60",
0476                     'Eff50' : "DBnewDMwLTEff50",
0477                     'Eff40' : "DBnewDMwLTEff40"
0478                 }
0479             }
0480 
0481             if self.debug: print ("runTauID: Will update the list of available in DB samples to access newDM2017v2")
0482             self.loadMVA_WPs_run2_2017()
0483 
0484             _byIsolationNewDMMVArun2017v2raw = "rerunDiscriminationByIsolationNewDMMVArun2017v2raw"+self.postfix
0485             setattr(self.process,_byIsolationNewDMMVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
0486                 PATTauProducer = self.originalTauName,
0487                 Prediscriminants = noPrediscriminants,
0488                 loadMVAfromDB = cms.bool(True),
0489                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"),
0490                 mvaOpt = cms.string("DBnewDMwLTwGJ"),
0491                 verbosity = cms.int32(0)
0492             ))
0493 
0494             _byIsolationNewDMMVArun2017v2 = "rerunDiscriminationByIsolationNewDMMVArun2017v2"+self.postfix
0495             setattr(self.process,_byIsolationNewDMMVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
0496                 PATTauProducer = self.originalTauName,
0497                 Prediscriminants = noPrediscriminants,
0498                 toMultiplex = _byIsolationNewDMMVArun2017v2raw,
0499                 loadMVAfromDB = cms.bool(True),
0500                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0501                 mapping = cms.VPSet(
0502                     cms.PSet(
0503                         category = cms.uint32(0),
0504                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"), #writeTauIdDiscrWPs
0505                         variable = cms.string("pt"),
0506                     )
0507                 ),
0508                 workingPoints = cms.vstring(
0509                     "_WPEff95",
0510                     "_WPEff90",
0511                     "_WPEff80",
0512                     "_WPEff70",
0513                     "_WPEff60",
0514                     "_WPEff50",
0515                     "_WPEff40"
0516                 ),
0517                 verbosity = cms.int32(0)
0518             ))
0519 
0520             _rerunIsolationNewDMMVArun2017v2Task = cms.Task(
0521                 getattr(self.process,_byIsolationNewDMMVArun2017v2raw),
0522                 getattr(self.process,_byIsolationNewDMMVArun2017v2)
0523             )
0524             _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2017v2Task)
0525             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVArun2017v2Task)
0526 
0527             tauIDSources.byIsolationMVArun2017v2DBnewDMwLTraw2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "raw")
0528             tauIDSources.byVVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff95")
0529             tauIDSources.byVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff90")
0530             tauIDSources.byLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff80")
0531             tauIDSources.byMediumIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff70")
0532             tauIDSources.byTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff60")
0533             tauIDSources.byVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff50")
0534             tauIDSources.byVVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2017v2, "_WPEff40")
0535 
0536         if "dR0p32017v2" in self.toKeep:
0537             self.tauIdDiscrMVA_2017_version = "v2"
0538             self.tauIdDiscrMVA_trainings_run2_2017 = {
0539                 'tauIdMVAIsoDBoldDMdR0p3wLT2017' : "tauIdMVAIsoDBoldDMdR0p3wLT2017",
0540             }
0541             self.tauIdDiscrMVA_WPs_run2_2017 = {
0542                 'tauIdMVAIsoDBoldDMdR0p3wLT2017' : {
0543                     'Eff95' : "DBoldDMdR0p3wLTEff95",
0544                     'Eff90' : "DBoldDMdR0p3wLTEff90",
0545                     'Eff80' : "DBoldDMdR0p3wLTEff80",
0546                     'Eff70' : "DBoldDMdR0p3wLTEff70",
0547                     'Eff60' : "DBoldDMdR0p3wLTEff60",
0548                     'Eff50' : "DBoldDMdR0p3wLTEff50",
0549                     'Eff40' : "DBoldDMdR0p3wLTEff40"
0550                 }
0551             }
0552 
0553             if self.debug: print ("runTauID: Will update the list of available in DB samples to access dR0p32017v2")
0554             self.loadMVA_WPs_run2_2017()
0555 
0556             _byIsolationOldDMdR0p3MVArun2017v2raw = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw"+self.postfix
0557             setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
0558                 PATTauProducer = self.originalTauName,
0559                 Prediscriminants = noPrediscriminants,
0560                 loadMVAfromDB = cms.bool(True),
0561                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"),
0562                 mvaOpt = cms.string("DBoldDMwLTwGJ"),
0563                 srcChargedIsoPtSum = cms.string('chargedIsoPtSumdR03'),
0564                 srcFootprintCorrection = cms.string('footprintCorrectiondR03'),
0565                 srcNeutralIsoPtSum = cms.string('neutralIsoPtSumdR03'),
0566                 srcPhotonPtSumOutsideSignalCone = cms.string('photonPtSumOutsideSignalConedR03'),
0567                 verbosity = cms.int32(0)
0568             ))
0569 
0570             _byIsolationOldDMdR0p3MVArun2017v2 = "rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2"+self.postfix
0571             setattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2,patDiscriminationByIsolationMVArun2v1.clone(
0572                 PATTauProducer = self.originalTauName,
0573                 Prediscriminants = noPrediscriminants,
0574                 toMultiplex = _byIsolationOldDMdR0p3MVArun2017v2raw,
0575                 loadMVAfromDB = cms.bool(True),
0576                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0577                 mapping = cms.VPSet(
0578                     cms.PSet(
0579                         category = cms.uint32(0),
0580                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"), #writeTauIdDiscrWPs
0581                         variable = cms.string("pt"),
0582                     )
0583                 ),
0584                 workingPoints = cms.vstring(
0585                     "_WPEff95",
0586                     "_WPEff90",
0587                     "_WPEff80",
0588                     "_WPEff70",
0589                     "_WPEff60",
0590                     "_WPEff50",
0591                     "_WPEff40"
0592                 ),
0593                 verbosity = cms.int32(0)
0594             ))
0595 
0596             _rerunIsolationOldDMdR0p3MVArun2017v2Task = cms.Task(
0597                 getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2raw),
0598                 getattr(self.process,_byIsolationOldDMdR0p3MVArun2017v2)
0599             )
0600             _rerunMvaIsolationTask.add(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
0601             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMdR0p3MVArun2017v2Task)
0602 
0603             tauIDSources.byIsolationMVArun2017v2DBoldDMdR0p3wLTraw2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "raw")
0604             tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff95")
0605             tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff90")
0606             tauIDSources.byLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff80")
0607             tauIDSources.byMediumIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff70")
0608             tauIDSources.byTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff60")
0609             tauIDSources.byVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff50")
0610             tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs(_byIsolationOldDMdR0p3MVArun2017v2, "_WPEff40")
0611 
0612         # 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
0613         # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2raw = patDiscriminationByIsolationMVArun2v1raw.clone(
0614         #     PATTauProducer = self.originalTauName,
0615         #     Prediscriminants = noPrediscriminants,
0616         #     loadMVAfromDB = cms.bool(True),
0617         #     mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2"),
0618         #     mvaOpt = cms.string("DBoldDMwLTwGJ"),
0619         #     verbosity = cms.int32(0)
0620         # )
0621         # #
0622         # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2VLoose = patDiscriminationByIsolationMVArun2v1VLoose.clone(
0623         #     PATTauProducer = self.originalTauName,
0624         #     Prediscriminants = noPrediscriminants,
0625         #     toMultiplex = 'rerunDiscriminationByIsolationOldDMMVArun2v2raw',
0626         #     key = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw:category'),#?
0627         #     loadMVAfromDB = cms.bool(True),
0628         #     mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations
0629         #     mapping = cms.VPSet(
0630         #         cms.PSet(
0631         #             category = cms.uint32(0),
0632         #             cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_WPEff90"), #writeTauIdDiscrWPs
0633         #             variable = cms.string("pt"),
0634         #         )
0635         #     )
0636         # )
0637 
0638         # 2016 training strategy(v1), trained on 2016MC, old DM
0639         if "2016v1" in self.toKeep:
0640             _byIsolationOldDMMVArun2016v1raw = "rerunDiscriminationByIsolationOldDMMVArun2v1raw"+self.postfix
0641             setattr(self.process,_byIsolationOldDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
0642                 PATTauProducer = self.originalTauName,
0643                 Prediscriminants = noPrediscriminants,
0644                 loadMVAfromDB = cms.bool(True),
0645                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"),
0646                 mvaOpt = cms.string("DBoldDMwLT"),
0647                 verbosity = cms.int32(0)
0648             ))
0649 
0650             _byIsolationOldDMMVArun2016v1 = "rerunDiscriminationByIsolationOldDMMVArun2v1"+self.postfix
0651             setattr(self.process,_byIsolationOldDMMVArun2016v1,patDiscriminationByIsolationMVArun2v1.clone(
0652                     PATTauProducer = self.originalTauName,
0653                     Prediscriminants = noPrediscriminants,
0654                     toMultiplex = _byIsolationOldDMMVArun2016v1raw,
0655                     loadMVAfromDB = cms.bool(True),
0656                     mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_mvaOutput_normalization"),
0657                     mapping = cms.VPSet(
0658                         cms.PSet(
0659                             category = cms.uint32(0),
0660                             cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"),
0661                             variable = cms.string("pt"),
0662                         )
0663                     ),
0664                     workingPoints = cms.vstring(
0665                         "_WPEff90",
0666                         "_WPEff80",
0667                         "_WPEff70",
0668                         "_WPEff60",
0669                         "_WPEff50",
0670                         "_WPEff40"
0671                     )
0672                 ))
0673 
0674             self.tauIdDiscrMVA_2017_version = "v1"
0675             self.tauIdDiscrMVA_trainings_run2_2017 = {
0676                 'tauIdMVAIsoDBoldDMwLT2016' : "tauIdMVAIsoDBoldDMwLT2016",
0677             }
0678             self.tauIdDiscrMVA_WPs_run2_2017 = {
0679                 'tauIdMVAIsoDBoldDMwLT2016' : {
0680                     'Eff90' : "DBoldDMwLT2016Eff90",
0681                     'Eff80' : "DBoldDMwLT2016Eff80",
0682                     'Eff70' : "DBoldDMwLT2016Eff70",
0683                     'Eff60' : "DBoldDMwLT2016Eff60",
0684                     'Eff50' : "DBoldDMwLT2016Eff50",
0685                     'Eff40' : "DBoldDMwLT2016Eff40"
0686                 }
0687             }
0688             if self.debug: print ("runTauID: Will update the list of available in DB samples to access 2016v1")
0689             self.loadMVA_WPs_run2_2017()
0690 
0691             _rerunIsolationOldDMMVArun2016v1Task = cms.Task(
0692                 getattr(self.process,_byIsolationOldDMMVArun2016v1raw),
0693                 getattr(self.process,_byIsolationOldDMMVArun2016v1)
0694             )
0695             _rerunMvaIsolationTask.add(_rerunIsolationOldDMMVArun2016v1Task)
0696             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationOldDMMVArun2016v1Task)
0697 
0698             tauIDSources.byIsolationMVArun2v1DBoldDMwLTraw2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "raw")
0699             tauIDSources.byVLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff90")
0700             tauIDSources.byLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff80")
0701             tauIDSources.byMediumIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff70")
0702             tauIDSources.byTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff60")
0703             tauIDSources.byVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff50")
0704             tauIDSources.byVVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs(_byIsolationOldDMMVArun2016v1, "_WPEff40")
0705 
0706         # 2016 training strategy(v1), trained on 2016MC, new DM
0707         if "newDM2016v1" in self.toKeep:
0708             _byIsolationNewDMMVArun2016v1raw = "rerunDiscriminationByIsolationNewDMMVArun2v1raw"+self.postfix
0709             setattr(self.process,_byIsolationNewDMMVArun2016v1raw,patDiscriminationByIsolationMVArun2v1raw.clone(
0710                 PATTauProducer = self.originalTauName,
0711                 Prediscriminants = noPrediscriminants,
0712                 loadMVAfromDB = cms.bool(True),
0713                 mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"),
0714                 mvaOpt = cms.string("DBnewDMwLT"),
0715                 verbosity = cms.int32(0)
0716             ))
0717 
0718             _byIsolationNewDMMVArun2016v1 = "rerunDiscriminationByIsolationNewDMMVArun2v1"+self.postfix
0719             setattr(self.process,_byIsolationNewDMMVArun2016v1,patDiscriminationByIsolationMVArun2v1.clone(
0720                 PATTauProducer = self.originalTauName,
0721                 Prediscriminants = noPrediscriminants,
0722                 toMultiplex = _byIsolationNewDMMVArun2016v1raw,
0723                 loadMVAfromDB = cms.bool(True),
0724                 mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_mvaOutput_normalization"),
0725                 mapping = cms.VPSet(
0726                     cms.PSet(
0727                         category = cms.uint32(0),
0728                         cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"),
0729                         variable = cms.string("pt"),
0730                     )
0731                 ),
0732                 workingPoints = cms.vstring(
0733                     "_WPEff90",
0734                     "_WPEff80",
0735                     "_WPEff70",
0736                     "_WPEff60",
0737                     "_WPEff50",
0738                     "_WPEff40"
0739                 )
0740             ))
0741 
0742             self.tauIdDiscrMVA_2017_version = "v1"
0743             self.tauIdDiscrMVA_trainings_run2_2017 = {
0744                 'tauIdMVAIsoDBnewDMwLT2016' : "tauIdMVAIsoDBnewDMwLT2016",
0745             }
0746             self.tauIdDiscrMVA_WPs_run2_2017 = {
0747                 'tauIdMVAIsoDBnewDMwLT2016' : {
0748                     'Eff90' : "DBnewDMwLT2016Eff90",
0749                     'Eff80' : "DBnewDMwLT2016Eff80",
0750                     'Eff70' : "DBnewDMwLT2016Eff70",
0751                     'Eff60' : "DBnewDMwLT2016Eff60",
0752                     'Eff50' : "DBnewDMwLT2016Eff50",
0753                     'Eff40' : "DBnewDMwLT2016Eff40"
0754                 }
0755             }
0756             if self.debug: print ("runTauID: Will update the list of available in DB samples to access newDM2016v1")
0757             self.loadMVA_WPs_run2_2017()
0758 
0759             _rerunIsolationNewDMMVArun2016v1Task = cms.Task(
0760                 getattr(self.process,_byIsolationNewDMMVArun2016v1raw),
0761                 getattr(self.process,_byIsolationNewDMMVArun2016v1)
0762             )
0763             _rerunMvaIsolationTask.add(_rerunIsolationNewDMMVArun2016v1Task)
0764             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationNewDMMVArun2016v1Task)
0765 
0766             tauIDSources.byIsolationMVArun2v1DBnewDMwLTraw2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "raw")
0767             tauIDSources.byVLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff90")
0768             tauIDSources.byLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff80")
0769             tauIDSources.byMediumIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff70")
0770             tauIDSources.byTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff60")
0771             tauIDSources.byVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff50")
0772             tauIDSources.byVVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff40")
0773 
0774         if "deepTau2017v2" in self.toKeep:
0775             if self.debug: print ("Adding DeepTau v2 IDs")
0776 
0777             _deepTauName = "deepTau2017v2"
0778             workingPoints_ = WORKING_POINTS_v2p1
0779 
0780             file_names = [
0781                 'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
0782                 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
0783                 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
0784             ]
0785             full_version = self.getDeepTauVersion(file_names[0])
0786             setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
0787                 Prediscriminants = noPrediscriminants,
0788                 taus             = self.originalTauName,
0789                 graph_file       = file_names,
0790                 year             = full_version[0],
0791                 version          = full_version[1],
0792                 sub_version      = 1 #MB: subversion cannot be properly deduced from file names; it should be 1 also for v2
0793             ))
0794 
0795             _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
0796 
0797             from Configuration.ProcessModifiers.deepTauSonicTriton_cff import deepTauSonicTriton
0798             deepTauSonicTriton.toReplaceWith(_deepTauProducer, DeepTauIdSonicProducer.clone(
0799                 Client = cms.PSet(
0800                   mode = cms.string('PseudoAsync'),
0801                   allowedTries = cms.untracked.uint32(0),
0802                   verbose = cms.untracked.bool(False),
0803                   modelName = cms.string("deeptau_2017v2p1"),
0804                   modelVersion = cms.string(''),
0805                   modelConfigPath = cms.FileInPath("RecoTauTag/TrainingFiles/data/DeepTauIdSONIC/deeptau_2017v2p1/config.pbtxt"),
0806                   preferredServer = cms.untracked.string(''),
0807                   timeout = cms.untracked.uint32(300),
0808                   useSharedMemory = cms.untracked.bool(True),
0809                   compression = cms.untracked.string(''),
0810                   outputs = cms.untracked.vstring()
0811                 ),
0812                 Prediscriminants = noPrediscriminants,
0813                 taus             = self.originalTauName,
0814                 year             = full_version[0],
0815                 version          = full_version[1],
0816                 sub_version      = 1, #MB: subversion cannot be properly deduced from file names
0817             ))
0818 
0819             self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
0820 
0821             _rerunMvaIsolationTask.add(_deepTauProducer)
0822             _rerunMvaIsolationSequence += _deepTauProducer
0823 
0824 
0825         if "deepTau2017v2p1" in self.toKeep:
0826             if self.debug: print ("Adding DeepTau v2p1 IDs")
0827 
0828             _deepTauName = "deepTau2017v2p1"
0829             workingPoints_ = WORKING_POINTS_v2p1
0830 
0831             file_names = [
0832                 'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
0833                 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
0834                 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
0835             ]
0836             full_version = self.getDeepTauVersion(file_names[0])
0837             setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
0838                 Prediscriminants = noPrediscriminants,
0839                 taus             = self.originalTauName,
0840                 graph_file       = file_names,
0841                 year             = full_version[0],
0842                 version          = full_version[1],
0843                 sub_version      = 1, #MB: subversion cannot be properly deduced from file names
0844                 disable_dxy_pca  = True
0845             ))
0846 
0847             _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
0848 
0849             from Configuration.ProcessModifiers.deepTauSonicTriton_cff import deepTauSonicTriton
0850             deepTauSonicTriton.toReplaceWith(_deepTauProducer, DeepTauIdSonicProducer.clone(
0851                 Client = cms.PSet(
0852                   mode = cms.string('PseudoAsync'),
0853                   allowedTries = cms.untracked.uint32(0),
0854                   verbose = cms.untracked.bool(False),
0855                   modelName = cms.string("deeptau_2017v2p1"),
0856                   modelVersion = cms.string(''),
0857                   modelConfigPath = cms.FileInPath("RecoTauTag/TrainingFiles/data/DeepTauIdSONIC/deeptau_2017v2p1/config.pbtxt"),
0858                   preferredServer = cms.untracked.string(''),
0859                   timeout = cms.untracked.uint32(300),
0860                   useSharedMemory = cms.untracked.bool(True),
0861                   compression = cms.untracked.string(''),
0862                   outputs = cms.untracked.vstring()
0863                 ),
0864                 Prediscriminants = noPrediscriminants,
0865                 taus             = self.originalTauName,
0866                 year             = full_version[0],
0867                 version          = full_version[1],
0868                 sub_version      = 1, #MB: subversion cannot be properly deduced from file names
0869                 disable_dxy_pca  = True
0870             ))
0871 
0872             self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
0873 
0874             _rerunMvaIsolationTask.add(_deepTauProducer)
0875             _rerunMvaIsolationSequence += _deepTauProducer
0876 
0877         if "deepTau2018v2p5" in self.toKeep:
0878             if self.debug: print ("Adding DeepTau v2p5 IDs")
0879 
0880             _deepTauName = "deepTau2018v2p5"
0881             workingPoints_ = WORKING_POINTS_v2p5
0882 
0883             file_names = [
0884                 'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_core.pb',
0885                 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_inner.pb',
0886                 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_outer.pb',
0887             ]
0888             full_version = self.getDeepTauVersion(file_names[0])
0889             setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
0890                 Prediscriminants                = noPrediscriminants,
0891                 taus                            = self.originalTauName,
0892                 graph_file                      = file_names,
0893                 year                            = full_version[0],
0894                 version                         = full_version[1],
0895                 sub_version                     = full_version[2],
0896                 disable_dxy_pca                 = True,
0897                 disable_hcalFraction_workaround = True,
0898                 disable_CellIndex_workaround    = True
0899             ))
0900 
0901             _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
0902 
0903             from Configuration.ProcessModifiers.deepTauSonicTriton_cff import deepTauSonicTriton
0904             deepTauSonicTriton.toReplaceWith(_deepTauProducer, DeepTauIdSonicProducer.clone(
0905                 Client = cms.PSet(
0906                   mode = cms.string('PseudoAsync'),
0907                   allowedTries = cms.untracked.uint32(0),
0908                   verbose = cms.untracked.bool(False),
0909                   modelName = cms.string("deeptau_2018v2p5"),
0910                   modelVersion = cms.string(''),
0911                   modelConfigPath = cms.FileInPath("RecoTauTag/TrainingFiles/data/DeepTauIdSONIC/deeptau_2018v2p5/config.pbtxt"),
0912                   preferredServer = cms.untracked.string(''),
0913                   timeout = cms.untracked.uint32(300),
0914                   useSharedMemory = cms.untracked.bool(True),
0915                   compression = cms.untracked.string(''),
0916                   outputs = cms.untracked.vstring(),
0917                 ),
0918                 Prediscriminants                = noPrediscriminants,
0919                 taus                            = self.originalTauName,
0920                 year                            = full_version[0],
0921                 version                         = full_version[1],
0922                 sub_version                     = full_version[2],
0923                 disable_dxy_pca                 = True,
0924                 disable_hcalFraction_workaround = True,
0925                 disable_CellIndex_workaround    = True
0926             ))
0927 
0928             self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
0929 
0930             _rerunMvaIsolationTask.add(_deepTauProducer)
0931             _rerunMvaIsolationSequence += _deepTauProducer
0932 
0933         if "deepTau2026v2p5" in self.toKeep:
0934             if self.debug: print ("Adding Phase2 DeepTau v2p5 IDs")
0935 
0936             _deepTauName = "deepTau2026v2p5"
0937             workingPoints_ = WORKING_POINTS_PHASEII_v2p5
0938 
0939             file_names = [
0940                 'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_core.pb',
0941                 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_inner.pb',
0942                 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_outer.pb',
0943             ]
0944             full_version = self.getDeepTauVersion(file_names[0])
0945             setattr(self.process,_deepTauName+self.postfix,DeepTau.clone(
0946                 Prediscriminants                = noPrediscriminants,
0947                 taus                            = self.originalTauName,
0948                 graph_file                      = file_names,
0949                 year                            = full_version[0],
0950                 version                         = full_version[1],
0951                 sub_version                     = full_version[2],
0952                 disable_dxy_pca                 = True,
0953                 disable_hcalFraction_workaround = True,
0954                 disable_CellIndex_workaround    = True
0955             ))
0956 
0957             from RecoTauTag.RecoTau.mergedPhase2SlimmedElectronsForTauId_cff import mergedSlimmedElectronsForTauId
0958             if not hasattr(self.process,"mergedSlimmedElectronsForTauId"):
0959                 self.process.mergedSlimmedElectronsForTauId = mergedSlimmedElectronsForTauId
0960             setattr(getattr(self.process, _deepTauName+self.postfix), "electrons", cms.InputTag("mergedSlimmedElectronsForTauId"))
0961             setattr(getattr(self.process, _deepTauName+self.postfix), "vertices", cms.InputTag("offlineSlimmedPrimaryVertices4D"))
0962 
0963             self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_)
0964 
0965             _deepTauProducer = getattr(self.process,_deepTauName+self.postfix)
0966             _rerunMvaIsolationTask.add(self.process.mergedSlimmedElectronsForTauId)
0967             _rerunMvaIsolationTask.add(_deepTauProducer)
0968             _rerunMvaIsolationSequence += self.process.mergedSlimmedElectronsForTauId
0969             _rerunMvaIsolationSequence += _deepTauProducer
0970 
0971         if "againstEle2018" in self.toKeep:
0972             self.antiElectronDiscrMVA6_version = "v3_noeveto"
0973             self.antiElectronDiscrMVA6_WPs = [ "eff98", "eff90", "eff80", "eff70", "eff60" ]
0974             ### Define new anti-e discriminants
0975             ## Raw
0976             from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6
0977             _byElectronRejectionMVA62018Raw = "patTauDiscriminationByElectronRejectionMVA62018Raw"+self.postfix
0978             setattr(self.process,_byElectronRejectionMVA62018Raw,patTauDiscriminationAgainstElectronMVA6.clone(
0979                 PATTauProducer = self.originalTauName,
0980                 Prediscriminants = noPrediscriminants, #already selected for MiniAOD
0981                 srcElectrons = cms.InputTag('slimmedElectrons'),
0982                 vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks
0983                 mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL',
0984                 mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC',
0985                 mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL',
0986                 mvaName_NoEleMatch_woGwoGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC',
0987                 mvaName_wGwGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL',
0988                 mvaName_wGwGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC',
0989                 mvaName_woGwGSF_BL = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL',
0990                 mvaName_woGwGSF_EC = 'RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'
0991             ))
0992             ## WPs
0993             from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer
0994             _byElectronRejectionMVA62018 = "patTauDiscriminationByElectronRejectionMVA62018"+self.postfix
0995             setattr(self.process,"patTauDiscriminationByElectronRejectionMVA62018"+self.postfix,patTauDiscriminantCutMultiplexer.clone(
0996                 PATTauProducer = self.originalTauName,
0997                 Prediscriminants = noPrediscriminants,
0998                 toMultiplex = _byElectronRejectionMVA62018Raw,
0999                 mapping = cms.VPSet(
1000                     cms.PSet(
1001                         category = cms.uint32(0),
1002                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL'),
1003                         variable = cms.string('pt')
1004                     ),
1005                     cms.PSet(
1006                         category = cms.uint32(2),
1007                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL'),
1008                         variable = cms.string('pt')
1009                     ),
1010                     cms.PSet(
1011                         category = cms.uint32(5),
1012                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL'),
1013                         variable = cms.string('pt')
1014                     ),
1015                     cms.PSet(
1016                         category = cms.uint32(7),
1017                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL'),
1018                         variable = cms.string('pt')
1019                     ),
1020                     cms.PSet(
1021                         category = cms.uint32(8),
1022                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC'),
1023                         variable = cms.string('pt')
1024                     ),
1025                     cms.PSet(
1026                         category = cms.uint32(10),
1027                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC'),
1028                         variable = cms.string('pt')
1029                     ),
1030                     cms.PSet(
1031                         category = cms.uint32(13),
1032                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'),
1033                         variable = cms.string('pt')
1034                     ),
1035                     cms.PSet(
1036                         category = cms.uint32(15),
1037                         cut = cms.string('RecoTauTag_antiElectronMVA6'+self.antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC'),
1038                         variable = cms.string('pt')
1039                     )
1040                 ),
1041                 workingPoints = cms.vstring(
1042                     "_WPeff98",
1043                     "_WPeff90",
1044                     "_WPeff80",
1045                     "_WPeff70",
1046                     "_WPeff60"
1047                 )
1048             ))
1049 
1050             if self.debug: print ("runTauID: Will update the list of available in DB samples to access againstEle 2018")
1051             self.load_againstElectronMVA6()
1052 
1053             ### Put all new anti-e discrminats to a sequence
1054             _patTauDiscriminationByElectronRejectionMVA62018Task = cms.Task(
1055                 getattr(self.process,_byElectronRejectionMVA62018Raw),
1056                 getattr(self.process,_byElectronRejectionMVA62018)
1057             )
1058             _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA62018Task)
1059             _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA62018Task)
1060 
1061             _againstElectronTauIDSources = cms.PSet(
1062                 againstElectronMVA6Raw2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "raw"),
1063                 againstElectronMVA6category2018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "category"),
1064                 againstElectronVLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff98"),
1065                 againstElectronLooseMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff90"),
1066                 againstElectronMediumMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff80"),
1067                 againstElectronTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff70"),
1068                 againstElectronVTightMVA62018 = self.tauIDMVAinputs(_byElectronRejectionMVA62018, "_WPeff60")
1069             )
1070             _tauIDSourcesWithAgainistEle = cms.PSet(
1071                 tauIDSources.clone(),
1072                 _againstElectronTauIDSources
1073             )
1074             tauIDSources =_tauIDSourcesWithAgainistEle.clone()
1075 
1076         if "againstEle" in self.toKeep:
1077             ### Define new anti-e discriminants
1078             ## Raw
1079             from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6
1080             _byElectronRejectionMVA6Raw = "patTauDiscriminationByElectronRejectionMVA6Raw"+self.postfix
1081             setattr(self.process,_byElectronRejectionMVA6Raw,patTauDiscriminationAgainstElectronMVA6.clone(
1082                 PATTauProducer = self.originalTauName,
1083                 Prediscriminants = noPrediscriminants, #already selected for MiniAOD
1084                 srcElectrons = cms.InputTag('slimmedElectrons'),
1085                 vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks
1086                 mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_BL',
1087                 mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_EC',
1088                 mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_BL',
1089                 mvaName_NoEleMatch_woGwoGSF_EC = 'RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_EC',
1090                 mvaName_wGwGSF_BL = 'RecoTauTag_antiElectronMVA_wGwGSF_BL',
1091                 mvaName_wGwGSF_EC = 'RecoTauTag_antiElectronMVA_wGwGSF_EC',
1092                 mvaName_woGwGSF_BL = 'RecoTauTag_antiElectronMVA_woGwGSF_BL',
1093                 mvaName_woGwGSF_EC = 'RecoTauTag_antiElectronMVA_woGwGSF_EC'
1094             ))
1095             ## WPs
1096             from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer
1097             _byElectronRejectionMVA6 = "patTauDiscriminationByElectronRejectionMVA6"+self.postfix
1098             setattr(self.process,"patTauDiscriminationByElectronRejectionMVA6"+self.postfix,patTauDiscriminantCutMultiplexer.clone(
1099                 PATTauProducer = self.originalTauName,
1100                 Prediscriminants = noPrediscriminants,
1101                 toMultiplex = _byElectronRejectionMVA6Raw,
1102                 mapping = cms.VPSet(
1103                     cms.PSet(
1104                         category = cms.uint32(0),
1105                         cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_BL'),
1106                         variable = cms.string('pt')
1107                     ),
1108                     cms.PSet(
1109                         category = cms.uint32(2),
1110                         cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_BL'),
1111                         variable = cms.string('pt')
1112                     ),
1113                     cms.PSet(
1114                         category = cms.uint32(5),
1115                         cut = cms.string('RecoTauTag_antiElectronMVA_woGwGSF_BL'),
1116                         variable = cms.string('pt')
1117                     ),
1118                     cms.PSet(
1119                         category = cms.uint32(7),
1120                         cut = cms.string('RecoTauTag_antiElectronMVA_wGwGSF_BL'),
1121                         variable = cms.string('pt')
1122                     ),
1123                     cms.PSet(
1124                         category = cms.uint32(8),
1125                         cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_woGwoGSF_EC'),
1126                         variable = cms.string('pt')
1127                     ),
1128                     cms.PSet(
1129                         category = cms.uint32(10),
1130                         cut = cms.string('RecoTauTag_antiElectronMVA_NoEleMatch_wGwoGSF_EC'),
1131                         variable = cms.string('pt')
1132                     ),
1133                     cms.PSet(
1134                         category = cms.uint32(13),
1135                         cut = cms.string('RecoTauTag_antiElectronMVA_woGwGSF_EC'),
1136                         variable = cms.string('pt')
1137                     ),
1138                     cms.PSet(
1139                         category = cms.uint32(15),
1140                         cut = cms.string('RecoTauTag_antiElectronMVA_wGwGSF_EC'),
1141                         variable = cms.string('pt')
1142                     )
1143                 ),
1144                 workingPoints = cms.vstring(
1145                     "_VLoose",
1146                     "_Loose",
1147                     "_Medium",
1148                     "_Tight",
1149                     "_VTight"
1150                 )
1151             ))
1152             ### Put all new anti-e discrminats to a sequence
1153             _patTauDiscriminationByElectronRejectionMVA6Task = cms.Task(
1154                 getattr(self.process,_byElectronRejectionMVA6Raw),
1155                 getattr(self.process,_byElectronRejectionMVA6)
1156             )
1157             _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA6Task)
1158             _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA6Task)
1159 
1160             _againstElectronTauIDSources = cms.PSet(
1161                 againstElectronMVA6Raw = self.tauIDMVAinputs(_byElectronRejectionMVA6, "raw"),
1162                 againstElectronMVA6category = self.tauIDMVAinputs(_byElectronRejectionMVA6, "category"),
1163                 againstElectronVLooseMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_VLoose"),
1164                 againstElectronLooseMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_Loose"),
1165                 againstElectronMediumMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_Medium"),
1166                 againstElectronTightMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_Tight"),
1167                 againstElectronVTightMVA6 = self.tauIDMVAinputs(_byElectronRejectionMVA6, "_VTight")
1168             )
1169             _tauIDSourcesWithAgainistEle = cms.PSet(
1170                 tauIDSources.clone(),
1171                 _againstElectronTauIDSources
1172             )
1173             tauIDSources =_tauIDSourcesWithAgainistEle.clone()
1174 
1175         if "newDMPhase2v1" in self.toKeep:
1176             if self.debug: print ("Adding newDMPhase2v1 ID")
1177             def tauIDMVAinputs(module, wp):
1178                 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)))
1179             _byIsolationNewDMMVAPhase2raw = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2raw"+self.postfix
1180             setattr(self.process,_byIsolationNewDMMVAPhase2raw,patDiscriminationByIsolationMVArun2v1raw.clone(
1181                 PATTauProducer = self.originalTauName,
1182                 Prediscriminants = noPrediscriminants,
1183                 loadMVAfromDB = True,
1184                 mvaName = 'RecoTauTag_tauIdMVAIsoPhase2',
1185                 mvaOpt = 'DBnewDMwLTwGJPhase2',
1186                 verbosity = 0
1187             ))
1188 
1189             _byIsolationNewDMMVAPhase2 = "rerunDiscriminationByIsolationMVADBnewDMwLTPhase2"+self.postfix
1190             setattr(self.process,_byIsolationNewDMMVAPhase2,patDiscriminationByIsolationMVArun2v1.clone(
1191                 PATTauProducer = self.originalTauName,
1192                 Prediscriminants = noPrediscriminants,
1193                 toMultiplex = _byIsolationNewDMMVAPhase2raw,
1194                 loadMVAfromDB = True,
1195                 mvaOutput_normalization = 'RecoTauTag_tauIdMVAIsoPhase2_mvaOutput_normalization',
1196                 mapping = cms.VPSet(
1197                     cms.PSet(
1198                         category = cms.uint32(0),
1199                         cut = cms.string("RecoTauTag_tauIdMVAIsoPhase2"),
1200                         variable = cms.string("pt"),
1201                     )
1202                 ),
1203                 workingPoints = cms.vstring(
1204                     "_VVLoose",
1205                     "_VLoose",
1206                     "_Loose",
1207                     "_Medium",
1208                     "_Tight",
1209                     "_VTight",
1210                     "_VVTight"
1211                 )
1212             ))
1213             _rerunIsolationMVADBnewDMwLTPhase2Task = cms.Task(
1214                 getattr(self.process,_byIsolationNewDMMVAPhase2raw),
1215                 getattr(self.process,_byIsolationNewDMMVAPhase2)
1216             )
1217             _rerunMvaIsolationTask.add(_rerunIsolationMVADBnewDMwLTPhase2Task)
1218             _rerunMvaIsolationSequence += cms.Sequence(_rerunIsolationMVADBnewDMwLTPhase2Task)
1219 
1220             tauIDSources.byIsolationMVADBnewDMwLTPhase2raw = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "raw")
1221             tauIDSources.byVVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVLoose")
1222             tauIDSources.byVLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VLoose")
1223             tauIDSources.byLooseIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Loose")
1224             tauIDSources.byMediumIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Medium")
1225             tauIDSources.byTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_Tight")
1226             tauIDSources.byVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VTight")
1227             tauIDSources.byVVTightIsolationMVADBnewDMwLTPhase2 = tauIDMVAinputs(_byIsolationNewDMMVAPhase2, "_VVTight")
1228 
1229         if "againstElePhase2v1" in self.toKeep:
1230             if self.debug: print ("Adding anti-e Phase2v1 ID")
1231             ### Define new anti-e discriminants for Phase2
1232             ## Raw
1233             from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6Phase2_cff import patTauDiscriminationAgainstElectronMVA6Phase2Raw, patTauDiscriminationAgainstElectronMVA6Phase2, mergedSlimmedElectronsForTauId
1234             _byElectronRejectionMVA6Phase2v1Raw = "patTauDiscriminationByElectronRejectionMVA6Phase2v1Raw"+self.postfix
1235             setattr(self.process,_byElectronRejectionMVA6Phase2v1Raw,patTauDiscriminationAgainstElectronMVA6Phase2Raw.clone(
1236                 PATTauProducer = self.originalTauName,
1237                 Prediscriminants = noPrediscriminants #already selected for MiniAOD
1238             ))
1239             ## WPs
1240             _byElectronRejectionMVA6Phase2v1 = "patTauDiscriminationByElectronRejectionMVA6Phase2v1"+self.postfix
1241             setattr(self.process,_byElectronRejectionMVA6Phase2v1,patTauDiscriminationAgainstElectronMVA6Phase2.clone(
1242                 PATTauProducer = self.originalTauName,
1243                 Prediscriminants = noPrediscriminants,
1244                 toMultiplex = _byElectronRejectionMVA6Phase2v1Raw
1245             ))
1246             ### Put all new phase2 anti-e discrminats to a sequence
1247             if not hasattr(self.process,"mergedSlimmedElectronsForTauId"):
1248                 self.process.mergedSlimmedElectronsForTauId = mergedSlimmedElectronsForTauId
1249             _patTauDiscriminationByElectronRejectionMVA6Phase2v1Task = cms.Task(
1250                 self.process.mergedSlimmedElectronsForTauId,
1251                 getattr(self.process,_byElectronRejectionMVA6Phase2v1Raw),
1252                 getattr(self.process,_byElectronRejectionMVA6Phase2v1)
1253             )
1254             _rerunMvaIsolationTask.add(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
1255             _rerunMvaIsolationSequence += cms.Sequence(_patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
1256 
1257             _againstElectronTauIDPhase2v1Sources = cms.PSet(
1258                 againstElectronMVA6RawPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "raw"),
1259                 againstElectronMVA6categoryPhase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "category"),
1260                 againstElectronVLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VLoose"),
1261                 againstElectronLooseMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Loose"),
1262                 againstElectronMediumMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Medium"),
1263                 againstElectronTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_Tight"),
1264                 againstElectronVTightMVA6Phase2v1 = self.tauIDMVAinputs(_byElectronRejectionMVA6Phase2v1, "_VTight")
1265             )
1266             _tauIDSourcesWithAgainistElePhase2v1 = cms.PSet(
1267                 tauIDSources.clone(),
1268                 _againstElectronTauIDPhase2v1Sources
1269             )
1270             tauIDSources =_tauIDSourcesWithAgainistElePhase2v1.clone()
1271         ##
1272         if self.debug: print('Embedding new TauIDs into \"'+self.updatedTauName+'\"')
1273         if not hasattr(self.process, self.updatedTauName):
1274             embedID = cms.EDProducer("PATTauIDEmbedder",
1275                src = cms.InputTag(self.originalTauName),
1276                tauIDSources = tauIDSources
1277             )
1278             setattr(self.process, self.updatedTauName, embedID)
1279         else: #assume same type
1280             tauIDSources = cms.PSet(
1281                 getattr(self.process, self.updatedTauName).tauIDSources,
1282                 tauIDSources)
1283             getattr(self.process, self.updatedTauName).tauIDSources = tauIDSources
1284         if not hasattr(self.process,"rerunMvaIsolationTask"+self.postfix):
1285             setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_rerunMvaIsolationTask)
1286         else:
1287             _updatedRerunMvaIsolationTask = getattr(self.process,"rerunMvaIsolationTask"+self.postfix)
1288             _updatedRerunMvaIsolationTask.add(_rerunMvaIsolationTask)
1289             setattr(self.process,"rerunMvaIsolationTask"+self.postfix,_updatedRerunMvaIsolationTask)
1290         if not hasattr(self.process,"rerunMvaIsolationSequence"+self.postfix):
1291             setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_rerunMvaIsolationSequence)
1292         else:
1293             _updatedRerunMvaIsolationSequence = getattr(self.process,"rerunMvaIsolationSequence"+self.postfix)
1294             _updatedRerunMvaIsolationSequence += _rerunMvaIsolationSequence
1295             setattr(self.process,"rerunMvaIsolationSequence"+self.postfix,_updatedRerunMvaIsolationSequence)
1296 
1297 
1298     def processDeepProducer(self, producer_name, tauIDSources, workingPoints_):
1299         for target,points in workingPoints_.items():
1300             setattr(tauIDSources, 'by{}VS{}raw'.format(producer_name[0].upper()+producer_name[1:], target),
1301                         cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(-1)))
1302             
1303             cut_expressions = []
1304             for index, (point,cut) in enumerate(points.items()):
1305                 cut_expressions.append(str(cut))
1306 
1307                 setattr(tauIDSources, 'by{}{}VS{}'.format(point, producer_name[0].upper()+producer_name[1:], target),
1308                         cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(index)))
1309             if len(cut_expressions) > 0:
1310                 setattr(getattr(self.process, producer_name+self.postfix), 'VS{}WP'.format(target), cms.vstring(*cut_expressions))
1311 
1312 
1313     def getDeepTauVersion(self, file_name):
1314         """returns the DeepTau year, version, subversion. File name should contain a version label with data takig year \
1315         (2011-2, 2015-8), version number (vX) and subversion (pX), e.g. 2017v0p6, in general the following format: \
1316         {year}v{version}p{subversion}"""
1317         version_search = re.search('(20[1,2][125678])v([0-9]+)(p[0-9]+|)[\._]', file_name)
1318         if not version_search:
1319             raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}p{subversion}". \
1320                                 Unable to extract version number.'.format(file_name))
1321         year = version_search.group(1)
1322         version = version_search.group(2)
1323         subversion = version_search.group(3)
1324         if len(subversion) > 0:
1325             subversion = subversion[1:]
1326         else:
1327             subversion = 0
1328         return int(year), int(version), int(subversion)