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 623 of file jetTools.py.
def jetTools::SwitchJetCollection::__init__ | ( | self | ) |
Definition at line 630 of file jetTools.py.
00631 : 00632 ConfigToolBase.__init__(self) 00633 self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag) 00634 self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],Type=list) 00635 self.addParameter(self._defaultParameters,'btagdiscriminators',['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags', 'trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags', 'simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],Type=list) 00636 self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection") 00637 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)') 00638 self.addParameter(self._defaultParameters,'jetCorrLabel',None, "payload and list of new jet correction labels, such as (\'AK5Calo\',[\'L2Relative\', \'L3Absolute\'])", tuple,acceptNoneValue=True ) 00639 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. ") 00640 self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to") 00641 self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection") 00642 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") 00643 self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence") 00644 self.addParameter(self._defaultParameters, 'outputModules', ['out'], "Output module labels, empty list of label indicates no output, default: ['out']") 00645 00646 self._parameters=copy.deepcopy(self._defaultParameters) 00647 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 651 of file jetTools.py.
00666 : 00667 00668 00669 00670 00671 ## stop processing if 'outputModule' exists and show the new alternative 00672 if not outputModule is None: 00673 depricatedOptionOutputModule(self) 00674 if jetCollection is None: 00675 jetCollection=self._defaultParameters['jetCollection'].value 00676 if doJTA is None: 00677 doJTA=self._defaultParameters['doJTA'].value 00678 if doBTagging is None: 00679 doBTagging=self._defaultParameters['doBTagging'].value 00680 if jetCorrLabel is None: 00681 jetCorrLabel=self._defaultParameters['jetCorrLabel'].value 00682 if doType1MET is None: 00683 doType1MET=self._defaultParameters['doType1MET'].value 00684 if genJetCollection is None: 00685 genJetCollection=self._defaultParameters['genJetCollection'].value 00686 if doJetID is None: 00687 doJetID=self._defaultParameters['doJetID'].value 00688 if jetIdLabel is None: 00689 jetIdLabel=self._defaultParameters['jetIdLabel'].value 00690 if outputModules is None: 00691 outputModules=self._defaultParameters['outputModules'].value 00692 if postfix is None: 00693 postfix=self._defaultParameters['postfix'].value 00694 if btagInfo is None: 00695 btagInfo=self._defaultParameters['btagInfo'].value 00696 if btagdiscriminators is None: 00697 btagdiscriminators=self._defaultParameters['btagdiscriminators'].value 00698 00699 00700 00701 00702 self.setParameter('jetCollection',jetCollection) 00703 self.setParameter('doJTA',doJTA) 00704 self.setParameter('doBTagging',doBTagging) 00705 self.setParameter('jetCorrLabel',jetCorrLabel) 00706 self.setParameter('doType1MET',doType1MET) 00707 self.setParameter('genJetCollection',genJetCollection) 00708 self.setParameter('doJetID',doJetID) 00709 self.setParameter('jetIdLabel',jetIdLabel) 00710 self.setParameter('outputModules',outputModules) 00711 self.setParameter('postfix',postfix) 00712 self.setParameter('btagInfo',btagInfo) 00713 self.setParameter('btagdiscriminators',btagdiscriminators) 00714 00715 self.apply(process)
def jetTools::SwitchJetCollection::getDefaultParameters | ( | self | ) |
Definition at line 648 of file jetTools.py.
def jetTools::SwitchJetCollection::toolCode | ( | self, | |
process | |||
) |
Definition at line 716 of file jetTools.py.
00717 : 00718 jetCollection=self._parameters['jetCollection'].value 00719 doJTA=self._parameters['doJTA'].value 00720 doBTagging=self._parameters['doBTagging'].value 00721 jetCorrLabel=self._parameters['jetCorrLabel'].value 00722 doType1MET =self._parameters['doType1MET'].value 00723 genJetCollection=self._parameters['genJetCollection'].value 00724 doJetID=self._parameters['doJetID'].value 00725 jetIdLabel=self._parameters['jetIdLabel'].value 00726 outputModules=self._parameters['outputModules'].value 00727 postfix=self._parameters['postfix'].value 00728 btagInfo=self._parameters['btagInfo'].value 00729 btagdiscriminators=self._parameters['btagdiscriminators'].value 00730 00731 ## save label of old input jet collection 00732 oldLabel = applyPostfix(process, "patJets", postfix).jetSource; 00733 00734 ## replace input jet collection for generator matches if the 00735 ## genJetCollection is no empty 00736 if (process.patJets.addGenPartonMatch): 00737 applyPostfix(process, "patJetPartonMatch", postfix).src = jetCollection 00738 if (process.patJets.addGenJetMatch): 00739 applyPostfix(process, "patJetGenJetMatch", postfix).src = jetCollection 00740 applyPostfix(process, "patJetGenJetMatch", postfix).matched = genJetCollection 00741 if (process.patJets.getJetMCFlavour): 00742 applyPostfix(process, "patJetPartonAssociation", postfix).jets = jetCollection 00743 00744 ## replace input jet collection for pat jet production 00745 applyPostfix(process, "patJets", postfix).jetSource = jetCollection 00746 00747 ## make VInputTag from strings 00748 def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] ) 00749 00750 if (doJTA or doBTagging): 00751 ## replace jet track association 00752 process.load("RecoJets.JetAssociationProducers.ak5JTA_cff") 00753 from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex 00754 setattr(process, "jetTracksAssociatorAtVertex"+postfix, ak5JetTracksAssociatorAtVertex.clone(jets = jetCollection)) 00755 getattr(process, "patDefaultSequence"+postfix).replace( 00756 applyPostfix(process, "patJetCharge", postfix), 00757 getattr(process, "jetTracksAssociatorAtVertex" + postfix) #module with postfix that is not n patDefaultSequence 00758 + applyPostfix(process, "patJetCharge", postfix) 00759 ) 00760 00761 applyPostfix(process, "patJetCharge", postfix).src = 'jetTracksAssociatorAtVertex'+postfix 00762 applyPostfix(process, "patJets", postfix).trackAssociationSource = 'jetTracksAssociatorAtVertex'+postfix 00763 else: 00764 ## remove the jet track association from the std 00765 ## sequence 00766 removeIfInSequence(process, "patJetCharge", "patDefaultSequence", postfix) 00767 ## switch embedding of track association and jet 00768 ## charge estimate to 'False' 00769 applyPostfix(process, "patJets", postfix).addAssociatedTracks = False 00770 applyPostfix(process, "patJets", postfix).addJetCharge = False 00771 00772 if (doBTagging): 00773 ## replace b tagging sequence; add postfix label 'AOD' as crab will 00774 ## crash when confronted with empy labels 00775 ##(btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD',postfix) 00776 (btagSeq, btagLabels) = runBTagging(process, jetCollection,"AOD",postfix,btagInfo,btagdiscriminators) 00777 ## add b tagging sequence before running the allLayer1Jets modules 00778 getattr(process, "patDefaultSequence"+postfix).replace( 00779 getattr( process,"jetTracksAssociatorAtVertex"+postfix), 00780 getattr( process,"jetTracksAssociatorAtVertex"+postfix) + btagSeq 00781 ) 00782 00783 ## replace corresponding tags for pat jet production 00784 applyPostfix(process, "patJets", postfix).trackAssociationSource = btagLabels['jta'] 00785 applyPostfix(process, "patJets", postfix).tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] ) 00786 applyPostfix(process, "patJets", postfix).discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags'] ] ) 00787 else: 00788 ## remove b tagging from the std sequence 00789 removeIfInSequence(process, "secondaryVertexNegativeTagInfos", "patDefaultSequence", postfix) 00790 removeIfInSequence(process, "simpleSecondaryVertexNegativeBJetTags", "patDefaultSequence", postfix) 00791 ## switch embedding of b tagging for pat 00792 ## jet production to 'False' 00793 applyPostfix(process, "patJets", postfix).addBTagInfo = False 00794 ## adjust output 00795 if len(outputModules) > 0: 00796 for outMod in outputModules: 00797 if hasattr(process,outMod): 00798 getattr(process,outMod).outputCommands.append("drop *_selectedPatJets_tagInfos_*") 00799 else: 00800 raise KeyError, "process has no OutModule named", outMod 00801 00802 if (doJetID): 00803 jetIdLabelNew = jetIdLabel + 'JetID' 00804 applyPostfix(process, "patJets", postfix).jetIDMap = cms.InputTag( jetIdLabelNew ) 00805 else: 00806 applyPostfix(process, "patJets", postfix).addJetID = cms.bool(False) 00807 00808 if (jetCorrLabel!=None): 00809 ## replace jet energy corrections; catch 00810 ## a couple of exceptions first 00811 if (jetCorrLabel == False ): 00812 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'" 00813 if (jetCorrLabel == "None"): 00814 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)" 00815 ## check for the correct format 00816 if type(jetCorrLabel) != type(('AK5Calo',['L2Relative'])): 00817 raise ValueError, "In addJetCollection 'jetCorrLabel' must be 'None', or of type ('payload',['correction1', 'correction2'])" 00818 00819 ## switch JEC parameters to the new jet collection 00820 applyPostfix(process, "patJetCorrFactors", postfix).src = jetCollection 00821 switchJetCorrLevels(process, jetCorrLabel = jetCorrLabel, postfix=postfix) 00822 getattr( process, "patJets" + postfix).jetCorrFactorsSource = cms.VInputTag( cms.InputTag("patJetCorrFactors" + postfix ) ) 00823 00824 ## find out type of jet collection, switch type1MET corrections off for JPTJets 00825 jetCollType = '' 00826 if ( 'CaloJets' in jetCollection.getModuleLabel() ): 00827 jetCollType = 'Calo' 00828 elif ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith('pfNo') or jetCollection.getModuleLabel() == 'particleFlow'): 00829 jetCollType = 'PF' 00830 else: 00831 print '=============================================' 00832 print 'Type1MET corrections are switched off for ' 00833 print 'JPT Jets. Users are recommened to use tcMET ' 00834 print 'together with JPT jets. ' 00835 print '=============================================' 00836 doType1MET=False 00837 00838 ## add a clone of the type1MET correction for the new jet collection 00839 if (doType1MET): 00840 ## create jet correctors for MET corrections 00841 from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet, ak5PFL1Offset, ak5PFL2Relative, ak5PFL3Absolute, ak5PFResidual 00842 setattr(process, jetCorrLabel[0]+'L1FastJet' , ak5PFL1Fastjet.clone ( algorithm=jetCorrLabel[0] 00843 , srcRho=cms.InputTag('kt6'+jetCollType+'Jets','rho') ) ) 00844 setattr(process, jetCorrLabel[0]+'L1Offset' , ak5PFL1Offset.clone ( algorithm=jetCorrLabel[0] ) ) 00845 setattr(process, jetCorrLabel[0]+'L2Relative' , ak5PFL2Relative.clone( algorithm=jetCorrLabel[0] ) ) 00846 setattr(process, jetCorrLabel[0]+'L3Absolute' , ak5PFL3Absolute.clone( algorithm=jetCorrLabel[0] ) ) 00847 setattr(process, jetCorrLabel[0]+'L2L3Residual', ak5PFResidual.clone ( algorithm=jetCorrLabel[0] ) ) 00848 ## combinded corrections 00849 setattr(process, jetCorrLabel[0]+'CombinedCorrector', cms.ESProducer( 'JetCorrectionESChain' 00850 , correctors = cms.vstring() ) ) 00851 for corrLbl in jetCorrLabel[1]: 00852 if corrLbl != 'L1FastJet' and corrLbl != 'L1Offset' and corrLbl != 'L2Relative' and corrLbl != 'L3Absolute' and corrLbl != 'L2L3Residual': 00853 print '=========================================' 00854 print ' Type1MET corrections are currently only ' 00855 print ' supported for the following corrections: ' 00856 print ' - L1FastJet' 00857 print ' - L1Offset' 00858 print ' - L2Relative' 00859 print ' - L3Absolute' 00860 print ' - L2L3Residual' 00861 print ' But given was:' 00862 print ' -', corrLbl 00863 print '=============================================' 00864 raise ValueError, 'unsupported JEC for TypeI MET correction: '+corrLbl 00865 else: 00866 getattr(process, jetCorrLabel[0]+'CombinedCorrector').correctors.append(jetCorrLabel[0]+corrLbl) 00867 00868 ## configuration of MET corrections 00869 if jetCollType == 'Calo': 00870 getattr(process, "patMETCorrections"+postfix).remove(getattr(process,"producePFMETCorrections"+postfix)) 00871 getattr(process,'caloJetMETcorr'+postfix).src = cms.InputTag(jetCollection.getModuleLabel()) 00872 00873 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]): 00874 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet') 00875 elif ('L1Offset' in jetCorrLabel[1]): 00876 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset') 00877 else: 00878 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string('') 00879 getattr(process,'caloJetMETcorr'+postfix ).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector') 00880 00881 getattr(process,'caloType1CorrectedMet'+postfix ).srcType1Corrections = cms.VInputTag( 00882 cms.InputTag('caloJetMETcorr'+postfix, 'type1') 00883 ) 00884 00885 getattr(process,'caloType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag( 00886 cms.InputTag('caloJetMETcorr'+postfix, 'type1') 00887 ) 00888 getattr(process,'caloType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag( 00889 cms.InputTag('caloJetMETcorr'+postfix, 'type2'), 00890 cms.InputTag('caloJetMETcorr'+postfix, 'offset'), 00891 cms.InputTag('muonCaloMETcorr') 00892 ) 00893 00894 ## add MET corrections to sequence 00895 getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('caloType1CorrectedMet'+postfix) 00896 getattr(process,'produceCaloMETCorrections'+postfix) 00897 getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'patMETs'+postfix), 00898 getattr(process,'produceCaloMETCorrections'+postfix) 00899 *getattr(process,'patMETs'+postfix) ) 00900 elif jetCollType == 'PF': 00901 getattr(process, "patMETCorrections"+postfix).remove(getattr(process,"produceCaloMETCorrections"+postfix)) 00902 00903 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]): 00904 getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet') 00905 elif ('L1Offset' in jetCorrLabel[1]): 00906 getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset') 00907 else: 00908 getattr(process,'pfJetMETcorr'+postfix).offsetCorrLabel = cms.string('') 00909 getattr(process,'pfJetMETcorr'+postfix).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector') 00910 00911 getattr(process,'pfType1CorrectedMet'+postfix).applyType0Corrections = cms.bool(False) 00912 getattr(process,'pfType1CorrectedMet'+postfix).srcCHSSums = cms.VInputTag( 00913 cms.InputTag("pfchsMETcorr"+postfix,"type0") 00914 ) 00915 getattr(process,'pfType1CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag( 00916 cms.InputTag('pfJetMETcorr'+postfix, 'type1') 00917 ) 00918 00919 getattr(process,'pfType1p2CorrectedMet'+postfix).applyType0Corrections = cms.bool(False) 00920 getattr(process,'pfType1p2CorrectedMet'+postfix).srcCHSSums = cms.VInputTag( 00921 cms.InputTag("pfchsMETcorr"+postfix,"type0") 00922 ) 00923 getattr(process,'pfType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag( 00924 cms.InputTag('pfJetMETcorr'+postfix, 'type1') 00925 ) 00926 getattr(process,'pfType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag( 00927 cms.InputTag('pfJetMETcorr' +postfix, 'type2'), 00928 cms.InputTag('pfJetMETcorr' +postfix, 'offset'), 00929 cms.InputTag('pfCandMETcorr'+postfix) 00930 ) 00931 00932 ## add MET corrections to sequence 00933 getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('pfType1CorrectedMet'+postfix) 00934 getattr(process, 'patMETs'+ postfix).addMuonCorrections = False 00935 00936 else: 00937 ## remove the jetCorrFactors from the std sequence 00938 process.patJetMETCorrections.remove(process.patJetCorrFactors) 00939 ## switch embedding of jetCorrFactors off 00940 ## for pat jet production 00941 applyPostfix(process, "patJets", postfix).addJetCorrFactors = False 00942 applyPostfix(process, "patJets", postfix).jetCorrFactorsSource=[] 00943 00944 ## adjust output when switching to PFJets 00945 if ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith("pfNo") or jetCollection.getModuleLabel() == 'particleFlow' ): 00946 ## in this case we can omit caloTowers and should keep pfCandidates 00947 if len(outputModules) > 0: 00948 for outMod in outputModules: 00949 if hasattr(process,outMod): 00950 getattr(process, outMod).outputCommands.append("keep *_selectedPatJets_pfCandidates_*") 00951 getattr(process, outMod).outputCommands.append("drop *_selectedPatJets_caloTowers_*") 00952 else: 00953 raise KeyError, "process has no OutModule named", outMod 00954 00955 switchJetCollection=SwitchJetCollection() 00956
jetTools::SwitchJetCollection::_comment [private] |
Definition at line 630 of file jetTools.py.
tuple jetTools::SwitchJetCollection::_defaultParameters = dicttypes.SortedKeysDict() [static, private] |
Definition at line 629 of file jetTools.py.
string jetTools::SwitchJetCollection::_label = 'switchJetCollection' [static, private] |
Definition at line 628 of file jetTools.py.
Definition at line 630 of file jetTools.py.