parameters: (self, process)
docstring: Tool code implementation
docstring_summary: Tool code implementation
docstring_tokens: Tool code implementation
function: def toolCode(self, process):
          """
          Tool code implementation
          """
          ## initialize parameters
          labelName=self._parameters['labelName'].value
          postfix=self._parameters['postfix'].value
          btagPrefix=self._parameters['btagPrefix'].value
          jetSource=self._parameters['jetSource'].value
          pfCandidates=self._parameters['pfCandidates'].value
          explicitJTA=self._parameters['explicitJTA'].value
          pvSource=self._parameters['pvSource'].value
          svSource=self._parameters['svSource'].value
          elSource=self._parameters['elSource'].value
          muSource=self._parameters['muSource'].value
          runIVF=self._parameters['runIVF'].value
          tightBTagNTkHits=self._parameters['tightBTagNTkHits'].value
          loadStdRecoBTag=self._parameters['loadStdRecoBTag'].value
          svClustering=self._parameters['svClustering'].value
          fatJets=self._parameters['fatJets'].value
          groomedFatJets=self._parameters['groomedFatJets'].value
          algo=self._parameters['algo'].value
          rParam=self._parameters['rParam'].value
          sortByPt=self._parameters['sortByPt'].value
          printWarning=self._parameters['printWarning'].value
          jetCorrections=self._parameters['jetCorrections'].value
          btagDiscriminators=list(self._parameters['btagDiscriminators'].value)
          btagInfos=list(self._parameters['btagInfos'].value)
  
          ## a list of all producer modules, which are already known to process
          knownModules = process.producerNames().split()
          ## determine whether btagging information is required or not
          if btagDiscriminators.count('None')>0:
              btagDiscriminators.remove('None')
          if btagInfos.count('None')>0:
              btagInfos.remove('None')
          bTagging=(len(btagDiscriminators)>0 or len(btagInfos)>0)
  
          ## construct postfix label for auxiliary modules; this postfix
          ## label will start with a capitalized first letter following
          ## the CMS naming conventions and for improved readablility
          _labelName=labelName[:1].upper()+labelName[1:]
  
          ## supported algo types are ak, ca, and kt
          _algo=''
          for x in ["ak", "ca", "kt"]:
              if x in algo.lower():
                  _algo=supportedJetAlgos[x]
                  break
          if _algo=='':
              unsupportedJetAlgorithm(self)
  
          task = getPatAlgosToolsTask(process)
  
          ## add new updatedPatJets to process (keep instance for later further modifications)
          from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import updatedPatJets
          if not sortByPt: # default is True
              updatedPatJets.sort = cms.bool(False)
          if 'updatedPatJets'+_labelName+postfix in knownModules :
              _newPatJets=getattr(process, 'updatedPatJets'+_labelName+postfix)
              _newPatJets.jetSource=jetSource
          else :
              addToProcessAndTask('updatedPatJets'+_labelName+postfix,
                                  updatedPatJets.clone(jetSource=jetSource,
                                  printWarning=printWarning), process, task)
              _newPatJets=getattr(process, 'updatedPatJets'+_labelName+postfix)
              knownModules.append('updatedPatJets'+_labelName+postfix)
          ## add new selectedUpdatedPatJets to process
          from PhysicsTools.PatAlgos.selectionLayer1.jetSelector_cfi import selectedPatJets
          if 'selectedUpdatedPatJets'+_labelName+postfix in knownModules :
              _newSelectedPatJets=getattr(process, 'selectedUpdatedPatJets'+_labelName+postfix)
              _newSelectedPatJets.src='updatedPatJets'+_labelName+postfix
          else :
              addToProcessAndTask('selectedUpdatedPatJets'+_labelName+postfix,
                                  selectedPatJets.clone(src='updatedPatJets'+_labelName+postfix),
                                  process, task)
              knownModules.append('selectedUpdatedPatJets'+_labelName+postfix)
  
          ## run btagging if required by user
          if (bTagging):
              if printWarning:
                 sys.stderr.write("**************************************************************\n")
                 sys.stderr.write("b tagging needs to be run on uncorrected jets. Hence, the JECs\n")
                 sys.stderr.write("will first be undone for 'updatedPatJets%s' and then applied to\n" % (_labelName+postfix) )
                 sys.stderr.write("'updatedPatJetsTransientCorrected%s'.\n" % (_labelName+postfix) )
                 sys.stderr.write("**************************************************************\n")
              _jetSource = cms.InputTag('updatedPatJets'+_labelName+postfix)
              ## insert new jet collection with jet corrections applied and btag info added
              self(
                  process,
                  labelName = ('TransientCorrected'+_labelName),
                  jetSource = _jetSource,
                  pfCandidates=pfCandidates,
                  explicitJTA=explicitJTA,
                  pvSource=pvSource,
                  svSource=svSource,
                  elSource=elSource,
                  muSource=muSource,
                  runIVF=runIVF,
                  tightBTagNTkHits=tightBTagNTkHits,
                  loadStdRecoBTag=loadStdRecoBTag,
                  svClustering=svClustering,
                  fatJets=fatJets,
                  groomedFatJets=groomedFatJets,
                  algo=algo,
                  rParam=rParam,
                  jetCorrections = jetCorrections,
                  btagPrefix = btagPrefix,
                  postfix = postfix
              )
              ## setup btagging
              _patJets=getattr(process, 'updatedPatJetsTransientCorrected'+_labelName+postfix)
              setupBTagging(process, _jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, tightBTagNTkHits, loadStdRecoBTag, svClustering, fatJets, groomedFatJets,
                            _algo, rParam, btagDiscriminators, btagInfos, _patJets, _labelName, btagPrefix, postfix)
              ## update final selected jets
              _newSelectedPatJets=getattr(process, 'selectedUpdatedPatJets'+_labelName+postfix)
              _newSelectedPatJets.src='updatedPatJetsTransientCorrected'+_labelName+postfix
              ## remove automatically added but redundant 'TransientCorrected' selected jets
              delattr(process, 'selectedUpdatedPatJetsTransientCorrected'+_labelName+postfix)
          else:
              _newPatJets.addBTagInfo = False
              _newPatJets.addTagInfos = False
  
          ## add jet correction factors if required by user
          if (jetCorrections is not None or bTagging):
              ## check the jet corrections format
              if jetCorrections is None and bTagging:
                  raise ValueError("Passing jetCorrections = None while running bTagging is likely not intended.")
              else:
                  checkJetCorrectionsFormat(jetCorrections)
              ## reset MET corrrection
              if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '':
                  sys.stderr.write("-------------------------------------------------------------------\n")
                  sys.stderr.write(" Warning: MET correction was set to " + jetCorrections[2] + " but\n")
                  sys.stderr.write("          will be ignored. Please set it to \"None\" to avoid\n")
                  sys.stderr.write("          getting this warning.\n")
                  sys.stderr.write("-------------------------------------------------------------------\n")
                  jetCorrectionsList = list(jetCorrections)
                  jetCorrectionsList[2] = 'None'
                  jetCorrections = tuple(jetCorrectionsList)
              ## if running b tagging, need to use uncorrected jets
              if (bTagging):
                  jetCorrections = ('AK4PFchs', cms.vstring([]), 'None')
              ## setup jet energy corrections
              setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, _newPatJets, _labelName, postfix)
          else:
              ## switch jetCorrFactors off
              _newPatJets.addJetCorrFactors=False
function_tokens: def toolCode ( self , process ) : ## initialize parameters labelName = self . _parameters [ 'labelName' ] . value postfix = self . _parameters [ 'postfix' ] . value btagPrefix = self . _parameters [ 'btagPrefix' ] . value jetSource = self . _parameters [ 'jetSource' ] . value pfCandidates = self . _parameters [ 'pfCandidates' ] . value explicitJTA = self . _parameters [ 'explicitJTA' ] . value pvSource = self . _parameters [ 'pvSource' ] . value svSource = self . _parameters [ 'svSource' ] . value elSource = self . _parameters [ 'elSource' ] . value muSource = self . _parameters [ 'muSource' ] . value runIVF = self . _parameters [ 'runIVF' ] . value tightBTagNTkHits = self . _parameters [ 'tightBTagNTkHits' ] . value loadStdRecoBTag = self . _parameters [ 'loadStdRecoBTag' ] . value svClustering = self . _parameters [ 'svClustering' ] . value fatJets = self . _parameters [ 'fatJets' ] . value groomedFatJets = self . _parameters [ 'groomedFatJets' ] . value algo = self . _parameters [ 'algo' ] . value rParam = self . _parameters [ 'rParam' ] . value sortByPt = self . _parameters [ 'sortByPt' ] . value printWarning = self . _parameters [ 'printWarning' ] . value jetCorrections = self . _parameters [ 'jetCorrections' ] . value btagDiscriminators = list ( self . _parameters [ 'btagDiscriminators' ] . value ) btagInfos = list ( self . _parameters [ 'btagInfos' ] . value ) ## a list of all producer modules, which are already known to process knownModules = process . producerNames ( ) . split ( ) ## determine whether btagging information is required or not if btagDiscriminators . count ( 'None' ) > 0 : btagDiscriminators . remove ( 'None' ) if btagInfos . count ( 'None' ) > 0 : btagInfos . remove ( 'None' ) bTagging = ( len ( btagDiscriminators ) > 0 or len ( btagInfos ) > 0 ) ## construct postfix label for auxiliary modules; this postfix ## label will start with a capitalized first letter following ## the CMS naming conventions and for improved readablility _labelName = labelName [ : 1 ] . upper ( ) + labelName [ 1 : ] ## supported algo types are ak, ca, and kt _algo = '' for x in [ "ak" , "ca" , "kt" ] : if x in algo . lower ( ) : _algo = supportedJetAlgos [ x ] break if _algo == '' : unsupportedJetAlgorithm ( self ) task = getPatAlgosToolsTask ( process ) ## add new updatedPatJets to process (keep instance for later further modifications) from PhysicsTools . PatAlgos . producersLayer1 . jetUpdater_cfi import updatedPatJets if not sortByPt : # default is True updatedPatJets . sort = cms . bool ( False ) if 'updatedPatJets' + _labelName + postfix in knownModules : _newPatJets = getattr ( process , 'updatedPatJets' + _labelName + postfix ) _newPatJets . jetSource = jetSource else : addToProcessAndTask ( 'updatedPatJets' + _labelName + postfix , updatedPatJets . clone ( jetSource = jetSource , printWarning = printWarning ) , process , task ) _newPatJets = getattr ( process , 'updatedPatJets' + _labelName + postfix ) knownModules . append ( 'updatedPatJets' + _labelName + postfix ) ## add new selectedUpdatedPatJets to process from PhysicsTools . PatAlgos . selectionLayer1 . jetSelector_cfi import selectedPatJets if 'selectedUpdatedPatJets' + _labelName + postfix in knownModules : _newSelectedPatJets = getattr ( process , 'selectedUpdatedPatJets' + _labelName + postfix ) _newSelectedPatJets . src = 'updatedPatJets' + _labelName + postfix else : addToProcessAndTask ( 'selectedUpdatedPatJets' + _labelName + postfix , selectedPatJets . clone ( src = 'updatedPatJets' + _labelName + postfix ) , process , task ) knownModules . append ( 'selectedUpdatedPatJets' + _labelName + postfix ) ## run btagging if required by user if ( bTagging ) : if printWarning : sys . stderr . write ( "**************************************************************\n" ) sys . stderr . write ( "b tagging needs to be run on uncorrected jets. Hence, the JECs\n" ) sys . stderr . write ( "will first be undone for 'updatedPatJets%s' and then applied to\n" % ( _labelName + postfix ) ) sys . stderr . write ( "'updatedPatJetsTransientCorrected%s'.\n" % ( _labelName + postfix ) ) sys . stderr . write ( "**************************************************************\n" ) _jetSource = cms . InputTag ( 'updatedPatJets' + _labelName + postfix ) ## insert new jet collection with jet corrections applied and btag info added self ( process , labelName = ( 'TransientCorrected' + _labelName ) , jetSource = _jetSource , pfCandidates = pfCandidates , explicitJTA = explicitJTA , pvSource = pvSource , svSource = svSource , elSource = elSource , muSource = muSource , runIVF = runIVF , tightBTagNTkHits = tightBTagNTkHits , loadStdRecoBTag = loadStdRecoBTag , svClustering = svClustering , fatJets = fatJets , groomedFatJets = groomedFatJets , algo = algo , rParam = rParam , jetCorrections = jetCorrections , btagPrefix = btagPrefix , postfix = postfix ) ## setup btagging _patJets = getattr ( process , 'updatedPatJetsTransientCorrected' + _labelName + postfix ) setupBTagging ( process , _jetSource , pfCandidates , explicitJTA , pvSource , svSource , elSource , muSource , runIVF , tightBTagNTkHits , loadStdRecoBTag , svClustering , fatJets , groomedFatJets , _algo , rParam , btagDiscriminators , btagInfos , _patJets , _labelName , btagPrefix , postfix ) ## update final selected jets _newSelectedPatJets = getattr ( process , 'selectedUpdatedPatJets' + _labelName + postfix ) _newSelectedPatJets . src = 'updatedPatJetsTransientCorrected' + _labelName + postfix ## remove automatically added but redundant 'TransientCorrected' selected jets delattr ( process , 'selectedUpdatedPatJetsTransientCorrected' + _labelName + postfix ) else : _newPatJets . addBTagInfo = False _newPatJets . addTagInfos = False ## add jet correction factors if required by user if ( jetCorrections is not None or bTagging ) : ## check the jet corrections format if jetCorrections is None and bTagging : raise ValueError ( "Passing jetCorrections = None while running bTagging is likely not intended." ) else : checkJetCorrectionsFormat ( jetCorrections ) ## reset MET corrrection if jetCorrections [ 2 ] . lower ( ) != 'none' and jetCorrections [ 2 ] != '' : sys . stderr . write ( "-------------------------------------------------------------------\n" ) sys . stderr . write ( " Warning: MET correction was set to " + jetCorrections [ 2 ] + " but\n" ) sys . stderr . write ( "          will be ignored. Please set it to \"None\" to avoid\n" ) sys . stderr . write ( "          getting this warning.\n" ) sys . stderr . write ( "-------------------------------------------------------------------\n" ) jetCorrectionsList = list ( jetCorrections ) jetCorrectionsList [ 2 ] = 'None' jetCorrections = tuple ( jetCorrectionsList ) ## if running b tagging, need to use uncorrected jets if ( bTagging ) : jetCorrections = ( 'AK4PFchs' , cms . vstring ( [ ] ) , 'None' ) ## setup jet energy corrections setupJetCorrections ( process , knownModules , jetCorrections , jetSource , pvSource , _newPatJets , _labelName , postfix ) else : ## switch jetCorrFactors off _newPatJets . addJetCorrFactors = False