Inherits FWCore::GuiBrowsers::ConfigToolBase::ConfigToolBase.
Public Member Functions | |
def | __call__ |
def | __init__ |
def | getDefaultParameters |
def | toolCode |
Private Attributes | |
_comment | |
_parameters | |
Static Private Attributes | |
tuple | _defaultParameters = dicttypes.SortedKeysDict() |
string | _label = 'switchJetCollection' |
Switch the collection of jets in PAT from the default value to a new jet collection
Definition at line 892 of file jetTools.py.
def jetTools::SwitchJetCollection::__init__ | ( | self | ) |
Definition at line 899 of file jetTools.py.
00900 : 00901 ConfigToolBase.__init__(self) 00902 self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag) 00903 self.addParameter(self._defaultParameters,'btagInfo',_defaultBTagInfos,"input btag info",allowedValues=_allowedBTagInfos,Type=list) 00904 self.addParameter(self._defaultParameters,'btagdiscriminators',_defaultBTagDiscriminators,"input btag discriminators",allowedValues=_allowedBTagDiscriminators,Type=list) 00905 self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection") 00906 self.addParameter(self._defaultParameters,'doBTagging',True, 'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)') 00907 self.addParameter(self._defaultParameters,'jetCorrLabel',None, "payload and list of new jet correction labels, such as (\'AK5Calo\',[\'L2Relative\', \'L3Absolute\'])", tuple,acceptNoneValue=True ) 00908 self.addParameter(self._defaultParameters,'doType1MET',True, "if jetCorrLabel is not 'None', set this to 'True' to redo the Type1 MET correction for the new jet colleection; at the moment it must be 'False' for non CaloJets otherwise the JetMET POG module crashes. ") 00909 self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to") 00910 self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection") 00911 self.addParameter(self._defaultParameters,'jetIdLabel',"ak5", " specify the label prefix of the xxxJetID object; in general it is the jet collection tag like ak5, kt4 sc5, aso. For more information have a look to SWGuidePATTools#add_JetCollection") 00912 self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence") 00913 self.addParameter(self._defaultParameters, 'outputModules', ['out'], "Output module labels, empty list of label indicates no output, default: ['out']") 00914 00915 self._parameters=copy.deepcopy(self._defaultParameters) 00916 self._comment = ""
def jetTools::SwitchJetCollection::__call__ | ( | self, | |
process, | |||
jetCollection = None , |
|||
doJTA = None , |
|||
doBTagging = None , |
|||
jetCorrLabel = None , |
|||
doType1MET = None , |
|||
genJetCollection = None , |
|||
doJetID = None , |
|||
jetIdLabel = None , |
|||
postfix = None , |
|||
outputModule = None , |
|||
outputModules = None , |
|||
btagInfo = None , |
|||
btagdiscriminators = None |
|||
) |
Definition at line 920 of file jetTools.py.
00935 : 00936 00937 00938 00939 00940 ## stop processing if 'outputModule' exists and show the new alternative 00941 if not outputModule is None: 00942 depricatedOptionOutputModule(self) 00943 if jetCollection is None: 00944 jetCollection=self._defaultParameters['jetCollection'].value 00945 if doJTA is None: 00946 doJTA=self._defaultParameters['doJTA'].value 00947 if doBTagging is None: 00948 doBTagging=self._defaultParameters['doBTagging'].value 00949 if jetCorrLabel is None: 00950 jetCorrLabel=self._defaultParameters['jetCorrLabel'].value 00951 if doType1MET is None: 00952 doType1MET=self._defaultParameters['doType1MET'].value 00953 if genJetCollection is None: 00954 genJetCollection=self._defaultParameters['genJetCollection'].value 00955 if doJetID is None: 00956 doJetID=self._defaultParameters['doJetID'].value 00957 if jetIdLabel is None: 00958 jetIdLabel=self._defaultParameters['jetIdLabel'].value 00959 if outputModules is None: 00960 outputModules=self._defaultParameters['outputModules'].value 00961 if postfix is None: 00962 postfix=self._defaultParameters['postfix'].value 00963 if btagInfo is None: 00964 btagInfo=self._defaultParameters['btagInfo'].value 00965 if btagdiscriminators is None: 00966 btagdiscriminators=self._defaultParameters['btagdiscriminators'].value 00967 00968 00969 00970 00971 self.setParameter('jetCollection',jetCollection) 00972 self.setParameter('doJTA',doJTA) 00973 self.setParameter('doBTagging',doBTagging) 00974 self.setParameter('jetCorrLabel',jetCorrLabel) 00975 self.setParameter('doType1MET',doType1MET) 00976 self.setParameter('genJetCollection',genJetCollection) 00977 self.setParameter('doJetID',doJetID) 00978 self.setParameter('jetIdLabel',jetIdLabel) 00979 self.setParameter('outputModules',outputModules) 00980 self.setParameter('postfix',postfix) 00981 self.setParameter('btagInfo',btagInfo) 00982 self.setParameter('btagdiscriminators',btagdiscriminators) 00983 00984 self.apply(process)
def jetTools::SwitchJetCollection::getDefaultParameters | ( | self | ) |
Definition at line 917 of file jetTools.py.
def jetTools::SwitchJetCollection::toolCode | ( | self, | |
process | |||
) |
Definition at line 985 of file jetTools.py.
00986 : 00987 jetCollection=self._parameters['jetCollection'].value 00988 doJTA=self._parameters['doJTA'].value 00989 doBTagging=self._parameters['doBTagging'].value 00990 jetCorrLabel=self._parameters['jetCorrLabel'].value 00991 doType1MET =self._parameters['doType1MET'].value 00992 genJetCollection=self._parameters['genJetCollection'].value 00993 doJetID=self._parameters['doJetID'].value 00994 jetIdLabel=self._parameters['jetIdLabel'].value 00995 outputModules=self._parameters['outputModules'].value 00996 postfix=self._parameters['postfix'].value 00997 btagInfo=self._parameters['btagInfo'].value 00998 btagdiscriminators=self._parameters['btagdiscriminators'].value 00999 01000 ## save label of old input jet collection 01001 oldLabel = applyPostfix(process, "patJets", postfix).jetSource; 01002 01003 ## replace input jet collection for generator matches if the 01004 ## genJetCollection is no empty 01005 if (process.patJets.addGenPartonMatch): 01006 applyPostfix(process, "patJetPartonMatch", postfix).src = jetCollection 01007 if (process.patJets.addGenJetMatch): 01008 applyPostfix(process, "patJetGenJetMatch", postfix).src = jetCollection 01009 applyPostfix(process, "patJetGenJetMatch", postfix).matched = genJetCollection 01010 if (process.patJets.getJetMCFlavour): 01011 applyPostfix(process, "patJetPartonAssociation", postfix).jets = jetCollection 01012 01013 ## replace input jet collection for pat jet production 01014 applyPostfix(process, "patJets", postfix).jetSource = jetCollection 01015 01016 ## make VInputTag from strings 01017 def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] ) 01018 01019 if (doJTA or doBTagging): 01020 ## replace jet track association 01021 ###process.load("RecoJets.JetAssociationProducers.ak5JTA_cff") 01022 from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex 01023 if not hasattr(process, "jetTracksAssociatorAtVertex"+postfix): 01024 setattr(process, "jetTracksAssociatorAtVertex"+postfix, ak5JetTracksAssociatorAtVertex.clone(jets = jetCollection)) 01025 else: 01026 getattr(process, "jetTracksAssociatorAtVertex"+postfix).jets = jetCollection 01027 getattr(process, "patDefaultSequence"+postfix).replace( 01028 applyPostfix(process, "patJetCharge", postfix), 01029 getattr(process, "jetTracksAssociatorAtVertex" + postfix) #module with postfix that is not n patDefaultSequence 01030 + applyPostfix(process, "patJetCharge", postfix) 01031 ) 01032 01033 applyPostfix(process, "patJetCharge", postfix).src = 'jetTracksAssociatorAtVertex'+postfix 01034 applyPostfix(process, "patJets", postfix).trackAssociationSource = 'jetTracksAssociatorAtVertex'+postfix 01035 else: 01036 ## remove the jet track association from the std 01037 ## sequence 01038 removeIfInSequence(process, "patJetCharge", "patDefaultSequence", postfix) 01039 ## switch embedding of track association and jet 01040 ## charge estimate to 'False' 01041 applyPostfix(process, "patJets", postfix).addAssociatedTracks = False 01042 applyPostfix(process, "patJets", postfix).addJetCharge = False 01043 01044 if (doBTagging): 01045 ## replace b tagging sequence; add postfix label 'AOD' as crab will 01046 ## crash when confronted with empy labels 01047 (btagSeq, btagLabels) = runBTagging(process, jetCollection,"AOD",postfix,btagInfo,btagdiscriminators) 01048 ## add b tagging sequence before running the allLayer1Jets modules 01049 ## nedded only after first call to runBTagging(), existing sequence modified in place otherwise 01050 if not btagSeq == None: 01051 getattr(process, "patDefaultSequence"+postfix).replace( 01052 getattr( process,"jetTracksAssociatorAtVertex"+postfix), 01053 getattr( process,"jetTracksAssociatorAtVertex"+postfix) + btagSeq 01054 ) 01055 01056 ## replace corresponding tags for pat jet production 01057 applyPostfix(process, "patJets", postfix).trackAssociationSource = btagLabels['jta'] 01058 applyPostfix(process, "patJets", postfix).tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] ) 01059 applyPostfix(process, "patJets", postfix).discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags'] ] ) 01060 else: 01061 ## remove b tagging from the std sequence 01062 removeIfInSequence(process, "secondaryVertexNegativeTagInfos", "patDefaultSequence", postfix) 01063 removeIfInSequence(process, "simpleSecondaryVertexNegativeBJetTags", "patDefaultSequence", postfix) 01064 ## switch embedding of b tagging for pat 01065 ## jet production to 'False' 01066 applyPostfix(process, "patJets", postfix).addBTagInfo = False 01067 ## adjust output 01068 if len(outputModules) > 0: 01069 for outMod in outputModules: 01070 if hasattr(process,outMod): 01071 getattr(process,outMod).outputCommands.append("drop *_selectedPatJets_tagInfos_*") 01072 else: 01073 raise KeyError, "process has no OutModule named", outMod 01074 01075 if (doJetID): 01076 jetIdLabelNew = jetIdLabel + 'JetID' 01077 applyPostfix(process, "patJets", postfix).jetIDMap = cms.InputTag( jetIdLabelNew ) 01078 else: 01079 applyPostfix(process, "patJets", postfix).addJetID = cms.bool(False) 01080 01081 if (jetCorrLabel!=None): 01082 ## replace jet energy corrections; catch 01083 ## a couple of exceptions first 01084 if (jetCorrLabel == False ): 01085 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'" 01086 if (jetCorrLabel == "None"): 01087 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)" 01088 ## check for the correct format 01089 if type(jetCorrLabel) != type(('AK5Calo',['L2Relative'])): 01090 raise ValueError, "In addJetCollection 'jetCorrLabel' must be 'None', or of type ('payload',['correction1', 'correction2'])" 01091 01092 ## switch JEC parameters to the new jet collection 01093 applyPostfix(process, "patJetCorrFactors", postfix).src = jetCollection 01094 switchJetCorrLevels(process, jetCorrLabel = jetCorrLabel, postfix=postfix) 01095 getattr( process, "patJets" + postfix).jetCorrFactorsSource = cms.VInputTag( cms.InputTag("patJetCorrFactors" + postfix ) ) 01096 01097 ## find out type of jet collection, switch type1MET corrections off for JPTJets 01098 jetCollType = '' 01099 if ( 'CaloJets' in jetCollection.getModuleLabel() ): 01100 jetCollType = 'Calo' 01101 elif ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith('pfNo') or jetCollection.getModuleLabel() == 'particleFlow'): 01102 jetCollType = 'PF' 01103 else: 01104 print '=============================================' 01105 print 'Type1MET corrections are switched off for ' 01106 print 'JPT Jets. Users are recommened to use tcMET ' 01107 print 'together with JPT jets. ' 01108 print '=============================================' 01109 doType1MET=False 01110 01111 ## add a clone of the type1MET correction for the new jet collection 01112 if (doType1MET): 01113 ## create jet correctors for MET corrections 01114 from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet, ak5PFL1Offset, ak5PFL2Relative, ak5PFL3Absolute, ak5PFResidual 01115 setattr(process, jetCorrLabel[0]+'L1FastJet' , ak5PFL1Fastjet.clone ( algorithm=jetCorrLabel[0] 01116 , srcRho=cms.InputTag('kt6'+jetCollType+'Jets','rho') ) ) 01117 setattr(process, jetCorrLabel[0]+'L1Offset' , ak5PFL1Offset.clone ( algorithm=jetCorrLabel[0] ) ) 01118 setattr(process, jetCorrLabel[0]+'L2Relative' , ak5PFL2Relative.clone( algorithm=jetCorrLabel[0] ) ) 01119 setattr(process, jetCorrLabel[0]+'L3Absolute' , ak5PFL3Absolute.clone( algorithm=jetCorrLabel[0] ) ) 01120 setattr(process, jetCorrLabel[0]+'L2L3Residual', ak5PFResidual.clone ( algorithm=jetCorrLabel[0] ) ) 01121 ## combinded corrections 01122 setattr(process, jetCorrLabel[0]+'CombinedCorrector', cms.ESProducer( 'JetCorrectionESChain' 01123 , correctors = cms.vstring() ) ) 01124 for corrLbl in jetCorrLabel[1]: 01125 if corrLbl != 'L1FastJet' and corrLbl != 'L1Offset' and corrLbl != 'L2Relative' and corrLbl != 'L3Absolute' and corrLbl != 'L2L3Residual': 01126 print '=========================================' 01127 print ' Type1MET corrections are currently only ' 01128 print ' supported for the following corrections: ' 01129 print ' - L1FastJet' 01130 print ' - L1Offset' 01131 print ' - L2Relative' 01132 print ' - L3Absolute' 01133 print ' - L2L3Residual' 01134 print ' But given was:' 01135 print ' -', corrLbl 01136 print '=============================================' 01137 raise ValueError, 'unsupported JEC for TypeI MET correction: '+corrLbl 01138 else: 01139 getattr(process, jetCorrLabel[0]+'CombinedCorrector').correctors.append(jetCorrLabel[0]+corrLbl) 01140 01141 ## configuration of MET corrections 01142 if jetCollType == 'Calo': 01143 getattr(process, "patMETCorrections"+postfix).remove(getattr(process,"producePFMETCorrections"+postfix)) 01144 getattr(process,'caloJetMETcorr'+postfix).src = cms.InputTag(jetCollection.getModuleLabel()) 01145 01146 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]): 01147 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet') 01148 elif ('L1Offset' in jetCorrLabel[1]): 01149 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset') 01150 else: 01151 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string('') 01152 getattr(process,'caloJetMETcorr'+postfix ).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector') 01153 01154 getattr(process,'caloType1CorrectedMet'+postfix ).srcType1Corrections = cms.VInputTag( 01155 cms.InputTag('caloJetMETcorr'+postfix, 'type1') 01156 ) 01157 01158 getattr(process,'caloType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag( 01159 cms.InputTag('caloJetMETcorr'+postfix, 'type1') 01160 ) 01161 getattr(process,'caloType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag( 01162 cms.InputTag('caloJetMETcorr'+postfix, 'type2'), 01163 cms.InputTag('caloJetMETcorr'+postfix, 'offset'), 01164 cms.InputTag('muonCaloMETcorr') 01165 ) 01166 01167 ## add MET corrections to sequence 01168 getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('caloType1CorrectedMet'+postfix) 01169 getattr(process,'produceCaloMETCorrections'+postfix) 01170 getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'patMETs'+postfix), 01171 getattr(process,'produceCaloMETCorrections'+postfix) 01172 *getattr(process,'patMETs'+postfix) ) 01173 elif jetCollType == 'PF': 01174 getattr(process, "patMETCorrections"+postfix).remove(getattr(process,"produceCaloMETCorrections"+postfix)) 01175 01176 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]): 01177 getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet') 01178 elif ('L1Offset' in jetCorrLabel[1]): 01179 getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset') 01180 else: 01181 getattr(process,'pfJetMETcorr'+postfix).offsetCorrLabel = cms.string('') 01182 getattr(process,'pfJetMETcorr'+postfix).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector') 01183 01184 getattr(process,'pfType1CorrectedMet'+postfix).applyType0Corrections = cms.bool(False) 01185 getattr(process,'pfType1CorrectedMet'+postfix).srcCHSSums = cms.VInputTag( 01186 cms.InputTag("pfchsMETcorr"+postfix,"type0") 01187 ) 01188 getattr(process,'pfType1CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag( 01189 cms.InputTag('pfJetMETcorr'+postfix, 'type1') 01190 ) 01191 01192 getattr(process,'pfType1p2CorrectedMet'+postfix).applyType0Corrections = cms.bool(False) 01193 getattr(process,'pfType1p2CorrectedMet'+postfix).srcCHSSums = cms.VInputTag( 01194 cms.InputTag("pfchsMETcorr"+postfix,"type0") 01195 ) 01196 getattr(process,'pfType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag( 01197 cms.InputTag('pfJetMETcorr'+postfix, 'type1') 01198 ) 01199 getattr(process,'pfType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag( 01200 cms.InputTag('pfJetMETcorr' +postfix, 'type2'), 01201 cms.InputTag('pfJetMETcorr' +postfix, 'offset'), 01202 cms.InputTag('pfCandMETcorr'+postfix) 01203 ) 01204 01205 ## add MET corrections to sequence 01206 getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('pfType1CorrectedMet'+postfix) 01207 getattr(process, 'patMETs'+ postfix).addMuonCorrections = False 01208 01209 else: 01210 ## remove the jetCorrFactors from the std sequence 01211 process.patJetMETCorrections.remove(process.patJetCorrFactors) 01212 ## switch embedding of jetCorrFactors off 01213 ## for pat jet production 01214 applyPostfix(process, "patJets", postfix).addJetCorrFactors = False 01215 applyPostfix(process, "patJets", postfix).jetCorrFactorsSource=[] 01216 01217 ## adjust output when switching to PFJets 01218 if ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith("pfNo") or jetCollection.getModuleLabel() == 'particleFlow' ): 01219 ## in this case we can omit caloTowers and should keep pfCandidates 01220 if len(outputModules) > 0: 01221 for outMod in outputModules: 01222 if hasattr(process,outMod): 01223 getattr(process, outMod).outputCommands.append("keep *_selectedPatJets_pfCandidates_*") 01224 getattr(process, outMod).outputCommands.append("drop *_selectedPatJets_caloTowers_*") 01225 else: 01226 raise KeyError, "process has no OutModule named", outMod 01227 01228 switchJetCollection=SwitchJetCollection() 01229
jetTools::SwitchJetCollection::_comment [private] |
Definition at line 899 of file jetTools.py.
tuple jetTools::SwitchJetCollection::_defaultParameters = dicttypes.SortedKeysDict() [static, private] |
Definition at line 898 of file jetTools.py.
string jetTools::SwitchJetCollection::_label = 'switchJetCollection' [static, private] |
Definition at line 897 of file jetTools.py.
Definition at line 899 of file jetTools.py.