示例#1
0
    def __call__(self,process,
                 jetCollection,
                 postfixLabel,
                 doJTA        = True,
                 doBTagging   = True,
                 jetCorrLabel = None,
                 doType1MET   = True,
                 doL1Cleaning = True,                     
                 doL1Counters = False,
                 genJetCollection=cms.InputTag("iterativeCone5GenJets")
                 ):

        self.addParameter('process',process, 'The  process')
        self.addParameter('jetCollection',jetCollection, 'Input jet Collection')
        self.addParameter('postfixLabel',postfixLabel, 'Label to identify all modules that work with this jet collection')
        self.addParameter('doJTA',doJTA, 'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)')
        self.addParameter('doBTagging',doBTagging, 'Run b tagging sequence for new jet collection and add it to the new pat jet collection')
        self.addParameter('jetCorrLabel',jetCorrLabel, 'algorithm and type of JEC; use "None" for no JEC; examples are ("IC5","Calo"), ("SC7", "Calo"), ("KT4","PF")')
        self.addParameter('doType1MET',doType1MET, 'Make also a new MET collection (not yet implemented?')
        self.addParameter('doL1Cleaning',doL1Cleaning, 'copy also the producer modules for cleanLayer1 will be set to "True" automatically when doL1Counters is "True"')
        self.addParameter('doL1Counters',doL1Counters, 'copy also the filter modules that accept/reject the event looking at the number of jets')
        self.addParameter('genJetCollection',genJetCollection, 'GenJet collection to match to')
        
        process = self._parameters['process'].value
        jetCollection = self._parameters['jetCollection'].value
        postfixLabel = self._parameters['postfixLabel'].value
        doJTA = self._parameters['doJTA'].value
        doBTagging =self._parameters['doBTagging'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        doType1MET = self._parameters['doType1MET'].value
        doL1Cleaning = self._parameters['doL1Cleaning'].value
        doL1Counters = self._parameters['doL1Counters'].value
        genJetCollection = self._parameters['genJetCollection'].value

        process.disableRecording()
                #process.__dict__['_Process__enableRecording'] +=1
        
        
         
        
        #action = Action("AddJetCollection",copy.copy(self._parameters),self)
        #process.addAction(action)



        ## add module as process to the default sequence
        def addAlso(label, value):
            existing = getattr(process, label)
            setattr( process, label+postfixLabel, value)
            process.patDefaultSequence.replace( existing, existing*value )
            
        ## clone and add a module as process to the
        ## default sequence
        def addClone(label, **replaceStatements):
            new = getattr(process, label).clone(**replaceStatements)
            addAlso(label, new)
        
        ## add a clone of allLayer1Jets
        addClone('allLayer1Jets', jetSource = jetCollection)
        ## add a clone of selectedLayer1Jets    
        addClone('selectedLayer1Jets', src=cms.InputTag('allLayer1Jets'+postfixLabel))
        ## add a clone of cleanLayer1Jets    
        if (doL1Cleaning or doL1Counters):
            addClone('cleanLayer1Jets', src=cms.InputTag('selectedLayer1Jets'+postfixLabel))
        ## add a clone of countLayer1Jets    
        if (doL1Counters):
            addClone('countLayer1Jets', src=cms.InputTag('cleanLayer1Jets'+postfixLabel))

        ## attributes of allLayer1Jets
        l1Jets = getattr(process, 'allLayer1Jets'+postfixLabel)

        ## add a clone of gen jet matching
        addClone('jetPartonMatch', src = jetCollection)
        addClone('jetGenJetMatch', src = jetCollection, matched = genJetCollection)
        ## add a clone of parton and flavour associations
        addClone('jetPartonAssociation', jets = jetCollection)
        addClone('jetFlavourAssociation', srcByReference = cms.InputTag('jetPartonAssociation'+postfixLabel))

        ## fix label for input tag
        def fixInputTag(x): x.setModuleLabel(x.moduleLabel+postfixLabel)
        ## fix label for vector of input tags
        def fixVInputTag(x): x[0].setModuleLabel(x[0].moduleLabel+postfixLabel)

        ## provide allLayer1Jet inputs with individual labels
        fixInputTag(l1Jets.genJetMatch)
        fixInputTag(l1Jets.genPartonMatch)
        fixInputTag(l1Jets.JetPartonMapSource)

        ## find potential triggers for trigMatch 
        ##triggers = MassSearchParamVisitor('src', process.allLayer1Jets.jetSource)
        ##process.patTrigMatch.visit(triggers)
        ##for mod in triggers.modules():
        ##    if (doTrigMatch):
        ##        newmod = mod.clone(src = jetCollection)
        ##        setattr( process, mod.label()+postfixLabel, newmod )
        ##        process.patTrigMatch.replace( mod, mod * newmod )
        ##for it in l1Jets.trigPrimMatch.value(): fixInputTag(it)

        ## make VInputTag from strings 
        def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )

        if (doJTA or doBTagging):
            ## add clone of jet track association        
            process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            ## add jet track association module to processes
            jtaLabel = 'jetTracksAssociatorAtVertex'+postfixLabel
            setattr( process, jtaLabel, ic5JetTracksAssociatorAtVertex.clone(jets = jetCollection) )
            process.makeAllLayer1Jets.replace(process.patJetCharge, getattr(process,jtaLabel)+process.patJetCharge)
            l1Jets.trackAssociationSource = cms.InputTag(jtaLabel)
            addClone('patJetCharge', src=cms.InputTag(jtaLabel)),
            fixInputTag(l1Jets.jetChargeSource)
        else:
            ## switch embedding of track association and jet
            ## charge estimate to 'False'        
            l1Jets.addAssociatedTracks = False
            l1Jets.addJetCharge = False
    
        if (doBTagging):
            ## add b tagging sequence
           
            (btagSeq, btagLabels) = runBTagging(process, jetCollection, postfixLabel)
            ## add b tagging sequence before running the allLayer1Jets modules
            process.makeAllLayer1Jets.replace(getattr(process,jtaLabel), getattr(process,jtaLabel)+btagSeq)

            ## replace corresponding tags for pat jet production
            l1Jets.trackAssociationSource = cms.InputTag(btagLabels['jta'])
            l1Jets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
            l1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
        else:
            ## switch general b tagging info switch off
            l1Jets.addBTagInfo = False
        

        if (jetCorrLabel != None):
            ## add clone of jet energy corrections;
            ## catch a couple of exceptions first
            if (jetCorrLabel == False ):
                raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
            if (jetCorrLabel == "None"):
                raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
            ## check for the correct format
            if type(jetCorrLabel) != type(('IC5','Calo')): 
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"

            ## add clone of jetCorrFactors
            addClone('jetCorrFactors', jetSource = jetCollection)
            switchJECParameters( getattr(process,'jetCorrFactors'+postfixLabel), jetCorrLabel[0], jetCorrLabel[1], oldAlgo='IC5',oldType='Calo' )
            fixVInputTag(l1Jets.jetCorrFactorsSource)

            ## add a clone of the type1MET correction for the new jet collection
            if (doType1MET):
                ## in case there is no jet correction service in the paths add it
                ## as L2L3 if possible, as combined from L2 and L3 otherwise
                if not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel ):
                    setattr( process, 
                             'L2L3JetCorrector%s%s' % jetCorrLabel, 
                             cms.ESSource("JetCorrectionServiceChain",
                                          correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                                   'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                                          label= cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                                          )
                             )
                ## add a clone of the type1MET correction
                ## and the following muonMET correction  
                addClone('metJESCorIC5CaloJet', inputUncorJetsLabel = jetCollection.value(),
                     corrector = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                     )

                addClone('metJESCorIC5CaloJetMuons', uncorMETInputTag = cms.InputTag("metJESCorIC5CaloJet"+postfixLabel))
                addClone('layer1METs', metSource = cms.InputTag("metJESCorIC5CaloJetMuons"+postfixLabel))
                l1MET = getattr(process, 'layer1METs'+postfixLabel)

                ## find potential triggers for trigMatch             
                ##mettriggers = MassSearchParamVisitor('src', process.layer1METs.metSource)
                ##process.patTrigMatch.visit(mettriggers)
                ##for mod in mettriggers.modules():
                ##    if doTrigMatch:
                ##        newmod = mod.clone(src = l1MET.metSource)
                ##        setattr( process, mod.label()+postfixLabel, newmod )
                ##        process.patTrigMatch.replace( mod, mod * newmod )
                ##for it in l1MET.trigPrimMatch.value(): fixInputTag(it)

                ## add new met collections output to the pat summary
                process.allLayer1Summary.candidates += [ cms.InputTag('layer1METs'+postfixLabel) ]
        else:
            ## switch jetCorrFactors off
            l1Jets.addJetCorrFactors = False
        #process.__dict__['_Process__enableRecording'] -=1
        process.enableRecording()
        process.addAction(copy.copy(self))
    rParam   = cms.double(0.4),
    jetPtMin = cms.double(20)
    )

AK6caPFJetsPrunedPuppi = ak5PFJetsPruned.clone(
    src      = cms.InputTag('puppi','Puppi'),
    jetAlgorithm = cms.string("CambridgeAachen"),
    rParam = cms.double(0.4),
    doAreaFastjet = cms.bool(False),
    writeCompound = cms.bool(True),
    jetCollInstanceName=cms.string("SubJets"),
    jetPtMin = cms.double(20)
    )

from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
AK6jetTracksAssociatorAtVertexPuppi          = ic5JetTracksAssociatorAtVertex.clone()
AK6jetTracksAssociatorAtVertexPuppi  .jets   = cms.InputTag('AK6PFJetsPuppi')
AK6jetTracksAssociatorAtVertexPuppi  .tracks = "generalTracks"

AK6jetTracksAssociatorAtVertexSJPuppi        = ic5JetTracksAssociatorAtVertex.clone()
AK6jetTracksAssociatorAtVertexSJPuppi.jets   = cms.InputTag('AK6caPFJetsPrunedPuppi','SubJets')
AK6jetTracksAssociatorAtVertexSJPuppi.tracks = "generalTracks"

from RecoBTag.Configuration.RecoBTag_cff import *
AK6jetImpactParameterTagInfosPuppi                      = impactParameterTagInfos.clone()
AK6jetImpactParameterTagInfosPuppi.jetTracks            = "AK6jetTracksAssociatorAtVertexPuppi"
AK6jetSecondaryVertexTagInfosPuppi                      = secondaryVertexTagInfos.clone()
AK6jetSecondaryVertexTagInfosPuppi.trackIPTagInfos      = "AK6jetImpactParameterTagInfosPuppi"
AK6jetCombinedSecondaryVertexBJetTagsPuppi           = combinedSecondaryVertexBJetTags.clone()
AK6jetCombinedSecondaryVertexBJetTagsPuppi.tagInfos = cms.VInputTag( cms.InputTag("AK6jetImpactParameterTagInfosPuppi"), cms.InputTag("AK6jetSecondaryVertexTagInfosPuppi") )
示例#3
0
    def __call__(self,process,
                 jetCollection,
                 doJTA            = True,
                 doBTagging       = True,
                 jetCorrLabel     = None,
                 doType1MET       = True,
                 genJetCollection = cms.InputTag("iterativeCone5GenJets")
                 ):
   
        ## save label of old jet collection
        
        self.addParameter('process',process, 'The process')
        self.addParameter('jetCollection',jetCollection, ' Input jet collection')
        self.addParameter('doJTA',doJTA, 'Run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom.be true if doBTagging is set to true)')
        self.addParameter('doBTagging',doBTagging, 'Run b tagging sequence for new jet collection and add it to the new pat jet collection')
        self.addParameter('jetCorrLabel',jetCorrLabel, 'Algorithm and type of JEC; use "None" for no JEC; examples are ("IC5","Calo"), ("SC7","Calo"), ("KT4","PF")')
        self.addParameter('doType1MET',doType1MET, 'If jetCorrLabel is not "None", set this to "True" to redo the Type1 MET correction for the new jet colllection; at the moment it must be "False" for non CaloJets otherwise the JetMET POG module crashes.')
        self.addParameter('genJetCollection',genJetCollection, 'GenJet collection to match to')
        
        
        process=self._parameters['process'].value
        oldLabel = process.allLayer1Jets.jetSource;
        jetCollection = self._parameters['jetCollection'].value
        doJTA = self._parameters['doJTA'].value
        doBTagging =self._parameters['doBTagging'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        doType1MET = self._parameters['doType1MET'].value
        genJetCollection = self._parameters['genJetCollection'].value
        ## replace input jet collection for generator matches
        process.jetPartonMatch.src        = jetCollection
        process.jetGenJetMatch.src        = jetCollection
        process.jetGenJetMatch.matched    = genJetCollection
        process.jetPartonAssociation.jets = jetCollection
        
        ## replace input jet collection for trigger matches
        ##massSearchReplaceParam(process.patTrigMatch, 'src', oldLabel, jetCollection)
        
        ## replace input jet collection for pat jet production
        process.allLayer1Jets.jetSource = jetCollection
        process.disableRecording()
        print 'calling tag before'
        print ConfigToolBase._callingFlag
        if not ConfigToolBase._callingFlag:
            process.addAction(copy.copy(self))
            ConfigToolBase._callingFlag=True
            print 'calling tag after'
            print ConfigToolBase._callingFlag

        ## make VInputTag from strings
        def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )

        if (doJTA or doBTagging):
        ## replace jet track association
            process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            process.jetTracksAssociatorAtVertex = ic5JetTracksAssociatorAtVertex.clone(jets = jetCollection)
            process.makeAllLayer1Jets.replace(process.patJetCharge, process.jetTracksAssociatorAtVertex+process.patJetCharge)
            process.patJetCharge.src = 'jetTracksAssociatorAtVertex'
            process.allLayer1Jets.trackAssociationSource = 'jetTracksAssociatorAtVertex'
        else:
            ## remove the jet track association from the std
            ## sequence
            process.makeAllLayer1Jets.remove(process.patJetCharge)
            ## switch embedding of track association and jet
            ## charge estimate to 'False'
            process.allLayer1Jets.addAssociatedTracks = False
            process.allLayer1Jets.addJetCharge = False

        if (doBTagging):
            ## replace b tagging sequence; add postfix label 'AOD' as crab will
            ## crash when confronted with empy labels
            (btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD')
            ## add b tagging sequence before running the allLayer1Jets modules
            process.makeAllLayer1Jets.replace(process.jetTracksAssociatorAtVertex, process.jetTracksAssociatorAtVertex+btagSeq)

            ## replace corresponding tags for pat jet production
            process.allLayer1Jets.trackAssociationSource = btagLabels['jta']
            process.allLayer1Jets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
            process.allLayer1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
        else:
            ## switch embedding of b tagging for pat
            ## jet production to 'False'
            process.allLayer1Jets.addBTagInfo = False

        if (jetCorrLabel!=None):
            ## replace jet energy corrections; catch
            ## a couple of exceptions first
            if (jetCorrLabel == False ):
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
            if (jetCorrLabel == "None"):
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
            ## check for the correct format
            if (type(jetCorrLabel)!=type(('IC5','Calo'))): 
             raise ValueError, "In switchJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"

            ## switch JEC parameters to the new jet collection
            process.jetCorrFactors.jetSource = jetCollection            
            switchJECParameters(process.jetCorrFactors, jetCorrLabel[0], jetCorrLabel[1], oldAlgo='IC5',oldType='Calo')

            ## redo the type1MET correction for the new jet collection
            if (doType1MET):
                ## in case there is no jet correction service in the paths add it
                ## as L2L3 if possible, as combined from L2 and L3 otherwise
                if (not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel )):
                    setattr( process, 
                             'L2L3JetCorrector%s%s' % jetCorrLabel, 
                             cms.ESSource("JetCorrectionServiceChain",
                                          correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                                   'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                                          label = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                                          )
                             )
                ## configure the type1MET correction the following muonMET
                ## corrections have the corMetType1Icone5 as input and are
                ## automatically correct  
                process.metJESCorIC5CaloJet.inputUncorJetsLabel = jetCollection.value()
                process.metJESCorIC5CaloJet.corrector = 'L2L3JetCorrector%s%s' % jetCorrLabel
        else:
            ## remove the jetCorrFactors from the std sequence
            process.patJetMETCorrections.remove(process.jetCorrFactors)
            ## switch embedding of jetCorrFactors off
            ## for pat jet production
            process.allLayer1Jets.addJetCorrFactors = False

        process.enableRecording()
        process.addAction(copy.copy(self))
        ConfigToolBase._callingFlag=False
示例#4
0
    def __call__(self,
                 process,
                 jetCollection,
                 doJTA=True,
                 doBTagging=True,
                 jetCorrLabel=None,
                 doType1MET=True,
                 genJetCollection=cms.InputTag("iterativeCone5GenJets")):

        ## save label of old jet collection

        self.addParameter('process', process, 'The process')
        self.addParameter('jetCollection', jetCollection,
                          ' Input jet collection')
        self.addParameter(
            'doJTA', doJTA,
            'Run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom.be true if doBTagging is set to true)'
        )
        self.addParameter(
            'doBTagging', doBTagging,
            'Run b tagging sequence for new jet collection and add it to the new pat jet collection'
        )
        self.addParameter(
            'jetCorrLabel', jetCorrLabel,
            'Algorithm and type of JEC; use "None" for no JEC; examples are ("IC5","Calo"), ("SC7","Calo"), ("KT4","PF")'
        )
        self.addParameter(
            'doType1MET', doType1MET,
            'If jetCorrLabel is not "None", set this to "True" to redo the Type1 MET correction for the new jet colllection; at the moment it must be "False" for non CaloJets otherwise the JetMET POG module crashes.'
        )
        self.addParameter('genJetCollection', genJetCollection,
                          'GenJet collection to match to')

        process = self._parameters['process'].value
        oldLabel = process.allLayer1Jets.jetSource
        jetCollection = self._parameters['jetCollection'].value
        doJTA = self._parameters['doJTA'].value
        doBTagging = self._parameters['doBTagging'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        doType1MET = self._parameters['doType1MET'].value
        genJetCollection = self._parameters['genJetCollection'].value
        ## replace input jet collection for generator matches
        process.jetPartonMatch.src = jetCollection
        process.jetGenJetMatch.src = jetCollection
        process.jetGenJetMatch.matched = genJetCollection
        process.jetPartonAssociation.jets = jetCollection

        ## replace input jet collection for trigger matches
        ##massSearchReplaceParam(process.patTrigMatch, 'src', oldLabel, jetCollection)

        ## replace input jet collection for pat jet production
        process.allLayer1Jets.jetSource = jetCollection
        process.disableRecording()
        print 'calling tag before'
        print ConfigToolBase._callingFlag
        if not ConfigToolBase._callingFlag:
            process.addAction(copy.copy(self))
            ConfigToolBase._callingFlag = True
            print 'calling tag after'
            print ConfigToolBase._callingFlag

        ## make VInputTag from strings
        def vit(*args):
            return cms.VInputTag(*[cms.InputTag(x) for x in args])

        if (doJTA or doBTagging):
            ## replace jet track association
            process.load(
                "RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi"
            )
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            process.jetTracksAssociatorAtVertex = ic5JetTracksAssociatorAtVertex.clone(
                jets=jetCollection)
            process.makeAllLayer1Jets.replace(
                process.patJetCharge,
                process.jetTracksAssociatorAtVertex + process.patJetCharge)
            process.patJetCharge.src = 'jetTracksAssociatorAtVertex'
            process.allLayer1Jets.trackAssociationSource = 'jetTracksAssociatorAtVertex'
        else:
            ## remove the jet track association from the std
            ## sequence
            process.makeAllLayer1Jets.remove(process.patJetCharge)
            ## switch embedding of track association and jet
            ## charge estimate to 'False'
            process.allLayer1Jets.addAssociatedTracks = False
            process.allLayer1Jets.addJetCharge = False

        if (doBTagging):
            ## replace b tagging sequence; add postfix label 'AOD' as crab will
            ## crash when confronted with empy labels
            (btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD')
            ## add b tagging sequence before running the allLayer1Jets modules
            process.makeAllLayer1Jets.replace(
                process.jetTracksAssociatorAtVertex,
                process.jetTracksAssociatorAtVertex + btagSeq)

            ## replace corresponding tags for pat jet production
            process.allLayer1Jets.trackAssociationSource = btagLabels['jta']
            process.allLayer1Jets.tagInfoSources = cms.VInputTag(
                *[cms.InputTag(x) for x in btagLabels['tagInfos']])
            process.allLayer1Jets.discriminatorSources = cms.VInputTag(
                *[cms.InputTag(x) for x in btagLabels['jetTags']])
        else:
            ## switch embedding of b tagging for pat
            ## jet production to 'False'
            process.allLayer1Jets.addBTagInfo = False

        if (jetCorrLabel != None):
            ## replace jet energy corrections; catch
            ## a couple of exceptions first
            if (jetCorrLabel == False):
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
            if (jetCorrLabel == "None"):
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
            ## check for the correct format
            if (type(jetCorrLabel) != type(('IC5', 'Calo'))):
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"

            ## switch JEC parameters to the new jet collection
            process.jetCorrFactors.jetSource = jetCollection
            switchJECParameters(process.jetCorrFactors,
                                jetCorrLabel[0],
                                jetCorrLabel[1],
                                oldAlgo='IC5',
                                oldType='Calo')

            ## redo the type1MET correction for the new jet collection
            if (doType1MET):
                ## in case there is no jet correction service in the paths add it
                ## as L2L3 if possible, as combined from L2 and L3 otherwise
                if (not hasattr(process,
                                'L2L3JetCorrector%s%s' % jetCorrLabel)):
                    setattr(
                        process, 'L2L3JetCorrector%s%s' % jetCorrLabel,
                        cms.ESSource(
                            "JetCorrectionServiceChain",
                            correctors=cms.vstring(
                                'L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                            label=cms.string('L2L3JetCorrector%s%s' %
                                             jetCorrLabel)))
                ## configure the type1MET correction the following muonMET
                ## corrections have the corMetType1Icone5 as input and are
                ## automatically correct
                process.metJESCorIC5CaloJet.inputUncorJetsLabel = jetCollection.value(
                )
                process.metJESCorIC5CaloJet.corrector = 'L2L3JetCorrector%s%s' % jetCorrLabel
        else:
            ## remove the jetCorrFactors from the std sequence
            process.patJetMETCorrections.remove(process.jetCorrFactors)
            ## switch embedding of jetCorrFactors off
            ## for pat jet production
            process.allLayer1Jets.addJetCorrFactors = False

        process.enableRecording()
        process.addAction(copy.copy(self))
        ConfigToolBase._callingFlag = False
示例#5
0
    def __call__(self,
                 process,
                 jetCollection,
                 postfixLabel,
                 doJTA=True,
                 doBTagging=True,
                 jetCorrLabel=None,
                 doType1MET=True,
                 doL1Cleaning=True,
                 doL1Counters=False,
                 genJetCollection=cms.InputTag("iterativeCone5GenJets")):

        self.addParameter('process', process, 'The  process')
        self.addParameter('jetCollection', jetCollection,
                          'Input jet Collection')
        self.addParameter(
            'postfixLabel', postfixLabel,
            'Label to identify all modules that work with this jet collection')
        self.addParameter(
            'doJTA', doJTA,
            'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)'
        )
        self.addParameter(
            'doBTagging', doBTagging,
            'Run b tagging sequence for new jet collection and add it to the new pat jet collection'
        )
        self.addParameter(
            'jetCorrLabel', jetCorrLabel,
            'algorithm and type of JEC; use "None" for no JEC; examples are ("IC5","Calo"), ("SC7", "Calo"), ("KT4","PF")'
        )
        self.addParameter(
            'doType1MET', doType1MET,
            'Make also a new MET collection (not yet implemented?')
        self.addParameter(
            'doL1Cleaning', doL1Cleaning,
            'copy also the producer modules for cleanLayer1 will be set to "True" automatically when doL1Counters is "True"'
        )
        self.addParameter(
            'doL1Counters', doL1Counters,
            'copy also the filter modules that accept/reject the event looking at the number of jets'
        )
        self.addParameter('genJetCollection', genJetCollection,
                          'GenJet collection to match to')

        process = self._parameters['process'].value
        jetCollection = self._parameters['jetCollection'].value
        postfixLabel = self._parameters['postfixLabel'].value
        doJTA = self._parameters['doJTA'].value
        doBTagging = self._parameters['doBTagging'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        doType1MET = self._parameters['doType1MET'].value
        doL1Cleaning = self._parameters['doL1Cleaning'].value
        doL1Counters = self._parameters['doL1Counters'].value
        genJetCollection = self._parameters['genJetCollection'].value

        process.disableRecording()

        #process.__dict__['_Process__enableRecording'] +=1

        #action = Action("AddJetCollection",copy.copy(self._parameters),self)
        #process.addAction(action)

        ## add module as process to the default sequence
        def addAlso(label, value):
            existing = getattr(process, label)
            setattr(process, label + postfixLabel, value)
            process.patDefaultSequence.replace(existing, existing * value)

        ## clone and add a module as process to the
        ## default sequence
        def addClone(label, **replaceStatements):
            new = getattr(process, label).clone(**replaceStatements)
            addAlso(label, new)

        ## add a clone of allLayer1Jets
        addClone('allLayer1Jets', jetSource=jetCollection)
        ## add a clone of selectedLayer1Jets
        addClone('selectedLayer1Jets',
                 src=cms.InputTag('allLayer1Jets' + postfixLabel))
        ## add a clone of cleanLayer1Jets
        if (doL1Cleaning or doL1Counters):
            addClone('cleanLayer1Jets',
                     src=cms.InputTag('selectedLayer1Jets' + postfixLabel))
        ## add a clone of countLayer1Jets
        if (doL1Counters):
            addClone('countLayer1Jets',
                     src=cms.InputTag('cleanLayer1Jets' + postfixLabel))

        ## attributes of allLayer1Jets
        l1Jets = getattr(process, 'allLayer1Jets' + postfixLabel)

        ## add a clone of gen jet matching
        addClone('jetPartonMatch', src=jetCollection)
        addClone('jetGenJetMatch', src=jetCollection, matched=genJetCollection)
        ## add a clone of parton and flavour associations
        addClone('jetPartonAssociation', jets=jetCollection)
        addClone('jetFlavourAssociation',
                 srcByReference=cms.InputTag('jetPartonAssociation' +
                                             postfixLabel))

        ## fix label for input tag
        def fixInputTag(x):
            x.setModuleLabel(x.moduleLabel + postfixLabel)

        ## fix label for vector of input tags
        def fixVInputTag(x):
            x[0].setModuleLabel(x[0].moduleLabel + postfixLabel)

        ## provide allLayer1Jet inputs with individual labels
        fixInputTag(l1Jets.genJetMatch)
        fixInputTag(l1Jets.genPartonMatch)
        fixInputTag(l1Jets.JetPartonMapSource)

        ## find potential triggers for trigMatch
        ##triggers = MassSearchParamVisitor('src', process.allLayer1Jets.jetSource)
        ##process.patTrigMatch.visit(triggers)
        ##for mod in triggers.modules():
        ##    if (doTrigMatch):
        ##        newmod = mod.clone(src = jetCollection)
        ##        setattr( process, mod.label()+postfixLabel, newmod )
        ##        process.patTrigMatch.replace( mod, mod * newmod )
        ##for it in l1Jets.trigPrimMatch.value(): fixInputTag(it)

        ## make VInputTag from strings
        def vit(*args):
            return cms.VInputTag(*[cms.InputTag(x) for x in args])

        if (doJTA or doBTagging):
            ## add clone of jet track association
            process.load(
                "RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi"
            )
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            ## add jet track association module to processes
            jtaLabel = 'jetTracksAssociatorAtVertex' + postfixLabel
            setattr(process, jtaLabel,
                    ic5JetTracksAssociatorAtVertex.clone(jets=jetCollection))
            process.makeAllLayer1Jets.replace(
                process.patJetCharge,
                getattr(process, jtaLabel) + process.patJetCharge)
            l1Jets.trackAssociationSource = cms.InputTag(jtaLabel)
            addClone('patJetCharge', src=cms.InputTag(jtaLabel)),
            fixInputTag(l1Jets.jetChargeSource)
        else:
            ## switch embedding of track association and jet
            ## charge estimate to 'False'
            l1Jets.addAssociatedTracks = False
            l1Jets.addJetCharge = False

        if (doBTagging):
            ## add b tagging sequence

            (btagSeq, btagLabels) = runBTagging(process, jetCollection,
                                                postfixLabel)
            ## add b tagging sequence before running the allLayer1Jets modules
            process.makeAllLayer1Jets.replace(
                getattr(process, jtaLabel),
                getattr(process, jtaLabel) + btagSeq)

            ## replace corresponding tags for pat jet production
            l1Jets.trackAssociationSource = cms.InputTag(btagLabels['jta'])
            l1Jets.tagInfoSources = cms.VInputTag(
                *[cms.InputTag(x) for x in btagLabels['tagInfos']])
            l1Jets.discriminatorSources = cms.VInputTag(
                *[cms.InputTag(x) for x in btagLabels['jetTags']])
        else:
            ## switch general b tagging info switch off
            l1Jets.addBTagInfo = False

        if (jetCorrLabel != None):
            ## add clone of jet energy corrections;
            ## catch a couple of exceptions first
            if (jetCorrLabel == False):
                raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
            if (jetCorrLabel == "None"):
                raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
            ## check for the correct format
            if type(jetCorrLabel) != type(('IC5', 'Calo')):
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"

            ## add clone of jetCorrFactors
            addClone('jetCorrFactors', jetSource=jetCollection)
            switchJECParameters(getattr(process,
                                        'jetCorrFactors' + postfixLabel),
                                jetCorrLabel[0],
                                jetCorrLabel[1],
                                oldAlgo='IC5',
                                oldType='Calo')
            fixVInputTag(l1Jets.jetCorrFactorsSource)

            ## add a clone of the type1MET correction for the new jet collection
            if (doType1MET):
                ## in case there is no jet correction service in the paths add it
                ## as L2L3 if possible, as combined from L2 and L3 otherwise
                if not hasattr(process, 'L2L3JetCorrector%s%s' % jetCorrLabel):
                    setattr(
                        process, 'L2L3JetCorrector%s%s' % jetCorrLabel,
                        cms.ESSource(
                            "JetCorrectionServiceChain",
                            correctors=cms.vstring(
                                'L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                            label=cms.string('L2L3JetCorrector%s%s' %
                                             jetCorrLabel)))
                ## add a clone of the type1MET correction
                ## and the following muonMET correction
                addClone('metJESCorIC5CaloJet',
                         inputUncorJetsLabel=jetCollection.value(),
                         corrector=cms.string('L2L3JetCorrector%s%s' %
                                              jetCorrLabel))

                addClone('metJESCorIC5CaloJetMuons',
                         uncorMETInputTag=cms.InputTag("metJESCorIC5CaloJet" +
                                                       postfixLabel))
                addClone('layer1METs',
                         metSource=cms.InputTag("metJESCorIC5CaloJetMuons" +
                                                postfixLabel))
                l1MET = getattr(process, 'layer1METs' + postfixLabel)

                ## find potential triggers for trigMatch
                ##mettriggers = MassSearchParamVisitor('src', process.layer1METs.metSource)
                ##process.patTrigMatch.visit(mettriggers)
                ##for mod in mettriggers.modules():
                ##    if doTrigMatch:
                ##        newmod = mod.clone(src = l1MET.metSource)
                ##        setattr( process, mod.label()+postfixLabel, newmod )
                ##        process.patTrigMatch.replace( mod, mod * newmod )
                ##for it in l1MET.trigPrimMatch.value(): fixInputTag(it)

                ## add new met collections output to the pat summary
                process.allLayer1Summary.candidates += [
                    cms.InputTag('layer1METs' + postfixLabel)
                ]
        else:
            ## switch jetCorrFactors off
            l1Jets.addJetCorrFactors = False
        #process.__dict__['_Process__enableRecording'] -=1
        process.enableRecording()
        process.addAction(copy.copy(self))
示例#6
0
def addJetCollection(process,jetCollection,postfixLabel,
                        layers=[0,1],runCleaner="CaloJet",doJTA=True,doBTagging=True,jetCorrLabel=None,doType1MET=True,doL1Counters=False):
    """Add a new collection of jets in PAT from the default value.
          postfixLabel: Postpone this label to the name of all modules that work with these jet collection.
                        it can't be an empty string
          layers      : Determine which PAT layers will be affected ([0], [0,1])   
          runCleaner  : Run the layer 0 jet cleaner. Value is the C++ type of the jet CaloJet, PFJet, BasicJet), or None.
                        The cleaner module will be always called 'allLayer0Jets'.
                        None must be written without quotes!
          doBTagging  : True to run the BTagging sequence on top of this jets, and import it into PAT.
          doJTA       : Run Jet Tracks Association and Jet Charge (will be forced to True if doBTagging is true)
          jetCorrLabel: Name of the algorithm and jet type JEC to pick corrections from, or None for no JEC 
                        Examples are ('IC5','Calo'), ('SC7','Calo'), ('KT4','PF')
                        It tries to find a 'L2L3JetCorrector' + algo + type , or otherwise to create if as a 
                        JetCorrectionServiceChain of 'L2RelativeJetCorrector' and 'L3AbsoluteJetCorrector'
          doType1MET  : Make also a new MET (NOT IMPLEMENTED)
          doL1Counters: copy also the filter modules that accept/reject the event looking at the number of jets

       Notes:
       1)  This takes the configuration from the already-configured layer 0+1 jets, so if you do 
           replaces before calling addJetCollection then they will affect also the new jets
           DON'T DON'T DON'T call this after having switched off cleaning of layer 0 jets!
    
       2)  When turning off the cleaner, bTagging, JTA, jet corrections, MC and Trigger matching will be run directly on jetCollection
             The outputs will still be called 'layer0BTags'+postfixLabel, 'layer0JetTracksAssociatior'+postfixLabel and so on."""
    def addAlso (label,value):
        existing = getattr(process, label)
        setattr( process, label + postfixLabel, value)
        process.patLayer0.replace( existing, existing * value )
        if layers.count(1) != 0 : process.patLayer1.replace( existing, existing * value )
    def addClone(label,**replaceStatements):
        new      = getattr(process, label).clone(**replaceStatements)
        addAlso(label, new)
    # --- L0 ---
    newLabel0 = 'allLayer0Jets' + postfixLabel
    if runCleaner == "CaloJet":
        addClone('allLayer0Jets', jetSource = cms.InputTag(jetCollection))
    elif runCleaner == "PFJet":
        addAlso('allLayer0Jets', process.allLayer0PFJets.clone(jetSource = cms.InputTag(jetCollection)))
    elif runCleaner == "BasicJet":
        from PhysicsTools.PatAlgos.cleaningLayer0.basicJetCleaner_cfi import allLayer0Jets as allLayer0BasicJets;
        addAlso('allLayer0Jets', allLayer0BasicJets.clone(jetSource = cms.InputTag(jetCollection)))
    elif runCleaner == None:
        pass
    elif runCleaner == "None":
        raise ValueError, "In switchJetCollection, the value None for runCleaner must be written without quotes"
    else:
        raise ValueError, ("Cleaner '%s' not known" % (runCleaner,))
    # --- L1 ---
    l1Jets = None
    if layers.count(1) != 0: 
        addClone('allLayer1Jets', jetSource = cms.InputTag(newLabel0))
        l1Jets = getattr(process, 'allLayer1Jets'+postfixLabel)
        addClone('selectedLayer1Jets', src=cms.InputTag('allLayer1Jets'+postfixLabel))
        if doL1Counters:
            addClone('minLayer1Jets',      src=cms.InputTag('selectedLayer1Jets'+postfixLabel))
            addClone('maxLayer1Jets',      src=cms.InputTag('selectedLayer1Jets'+postfixLabel))
        if runCleaner == None:
            l1Jets.jetSource = cms.InputTag(jetCollection)
    if runCleaner != None:
        addClone('jetPartonMatch',       src = cms.InputTag(newLabel0))
        addClone('jetGenJetMatch',       src = cms.InputTag(newLabel0))
        addClone('jetPartonAssociation', jets = cms.InputTag(newLabel0))
        addClone('jetFlavourAssociation',srcByReference = cms.InputTag('jetPartonAssociation' + postfixLabel))
        triggers = MassSearchParamVisitor('src', cms.InputTag("allLayer0Jets"))
        process.patTrigMatch.visit(triggers)
        for mod in triggers.modules():
            newmod = mod.clone(src = cms.InputTag(newLabel0))
            setattr( process, mod.label() + postfixLabel, newmod )
            process.patTrigMatch.replace( mod, mod * newmod )
    else:   
        l1Jets.src = cms.InputTag(jetCollection)
        addClone('jetPartonMatch',       src = cms.InputTag(jetCollection))
        addClone('jetGenJetMatch',       src = cms.InputTag(jetCollection))
        addClone('jetPartonAssociation', jets = cms.InputTag(jetCollection))
        addClone('jetFlavourAssociation',srcByReference = cms.InputTag('jetPartonAssociation' + postfixLabel))
        triggers = MassSearchParamVisitor('src', cms.InputTag("allLayer0Jets"))
        process.patTrigMatch.visit(triggers)
        for mod in triggers.modules():
            newmod = mod.clone(src = cms.InputTag(jetCollection))
            setattr( process, mod.label() + postfixLabel, newmod )
            process.patTrigMatch.replace( mod, mod * newmod )
    def fixInputTag(x): x.setModuleLabel(x.moduleLabel+postfixLabel)
    if l1Jets != None:
        fixInputTag(l1Jets.JetPartonMapSource)
        fixInputTag(l1Jets.genJetMatch)
        fixInputTag(l1Jets.genPartonMatch)
        for it in l1Jets.trigPrimMatch.value(): fixInputTag(it)
    def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
    if doBTagging :
        (btagSeq, btagLabels) = runBTagging(process, jetCollection, postfixLabel)
        process.patLayer0.replace(process.patBeforeLevel0Reco, btagSeq + process.patBeforeLevel0Reco)
        if runCleaner != None:
            addClone('patAODJetTracksAssociator', src=cms.InputTag(jetCollection), 
                                                  tracks=cms.InputTag(btagLabels['jta']))
            addClone('patAODTagInfos'           , collection=cms.InputTag(jetCollection), 
                                                  associations=vit(*btagLabels['tagInfos']))
            addClone('patAODBTags'              , collection=cms.InputTag(jetCollection),
                                                  associations=vit(*btagLabels['jetTags']))
            addClone('layer0JetTracksAssociator', association=cms.InputTag('patAODJetTracksAssociator'+postfixLabel),
                                                  collection=cms.InputTag(newLabel0),
                                                  backrefs=cms.InputTag(newLabel0))
            addClone('layer0JetCharge'          , src=cms.InputTag(newLabel0),
                                                  jetTracksAssociation=cms.InputTag('layer0JetTracksAssociator'+postfixLabel))
            addClone('layer0TagInfos'           , commonLabel=cms.InputTag('patAODTagInfos'+postfixLabel),
                                                  associations=vit(*btagLabels['tagInfos']),
                                                  collection=cms.InputTag(newLabel0),
                                                  backrefs=cms.InputTag(newLabel0))
            addClone('layer0BTags'              , commonLabel=cms.InputTag('patAODBTags'+postfixLabel),
                                                  associations=vit(*btagLabels['jetTags']),
                                                  collection=cms.InputTag(newLabel0),
                                                  backrefs=cms.InputTag(newLabel0))
        else:
            addAlso('layer0JetTracksAssociator',  process.patAODJetTracksAssociator.clone(
                                                      src=cms.InputTag(jetCollection), 
                                                      tracks=cms.InputTag(btagLabels['jta'])))
            addClone('layer0JetCharge'          , src=cms.InputTag(jetCollection),
                                                  jetTracksAssociation=cms.InputTag('layer0JetTracksAssociator'+postfixLabel))
            addAlso('layer0TagInfos'           ,  process.patAODTagInfos.clone(
                                                    collection=cms.InputTag(jetCollection), 
                                                    associations=vit(*btagLabels['tagInfos'])))
            addAlso('layer0BTags'              , process.patAODBTags.clone(
                                                    collection=cms.InputTag(jetCollection),
                                                    associations=vit(*btagLabels['jetTags'])))
        if l1Jets != None:
            fixInputTag(l1Jets.jetChargeSource)
            fixInputTag(l1Jets.trackAssociationSource)
            fixInputTag(l1Jets.tagInfoModule)
            fixInputTag(l1Jets.discriminatorModule)
            if l1Jets.discriminatorNames != cms.vstring("*"): 
                l1Jets.discriminatorNames.setValue([x + postfixLabel for x in l1Jets.discriminatorNames.value()])
            if l1Jets.tagInfoNames != cms.vstring("*"): 
                l1Jets.tagInfoNames.setValue([x + postfixLabel for x in l1Jets.tagInfoNames.value()])
    else:
       if l1Jets != None: l1Jets.addBTagInfo = False 
    if doJTA or doBTagging:
        if not doBTagging:
            process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            jtaLabel = 'jetTracksAssociatorAtVertex' + postfixLabel
            setattr( process, jtaLabel, ic5JetTracksAssociatorAtVertex.clone(jets = cms.InputTag(jetCollection)) )
            process.patLayer0.replace(process.patBeforeLevel0Reco, getattr(process,jtaLabel) + process.patBeforeLevel0Reco)
            if runCleaner != None:
                addClone('patAODJetTracksAssociator', src=cms.InputTag(jetCollection), 
                                                      tracks=cms.InputTag(jtaLabel))
                addClone('layer0JetTracksAssociator', association=cms.InputTag('patAODJetTracksAssociator'+postfixLabel),
                                                      collection=cms.InputTag(newLabel0),
                                                      backrefs=cms.InputTag(newLabel0))
                addClone('layer0JetCharge'          , src=cms.InputTag(newLabel0),
                                                      jetTracksAssociation=cms.InputTag('layer0JetTracksAssociator'+postfixLabel))
            else:
                addAlso('layer0JetTracksAssociator',  process.patAODJetTracksAssociator.clone(
                                                          src=cms.InputTag(jetCollection), 
                                                          tracks=cms.InputTag(jtaLabel)))
                addClone('layer0JetCharge'          , src=cms.InputTag(jetCollection),
                                                      jetTracksAssociation=cms.InputTag('layer0JetTracksAssociator'+postfixLabel))
            if l1Jets != None:
                fixInputTag(l1Jets.jetChargeSource)
                fixInputTag(l1Jets.trackAssociationSource)
    else: ## no JTA
       if l1Jets != None:  
            l1Jets.addAssociatedTracks = False
            l1Jets.addJetCharge = False
    if jetCorrLabel != None:
        if jetCorrLabel == False : raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to None, not False"
        if jetCorrLabel == "None": raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to None (without quotes), not 'None'"
        if type(jetCorrLabel) != type(('IC5','Calo')): 
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be None, or a tuple ('Algo', 'Type')"
        if not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel ):
            setattr( process, 
                        'L2L3JetCorrector%s%s' % jetCorrLabel, 
                        cms.ESSource("JetCorrectionServiceChain",
                            correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                     'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                            label      = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                        )
                    )
        if runCleaner != None:
            addClone('jetCorrFactors',       jetSource           = cms.InputTag(jetCollection), 
                                             defaultJetCorrector = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel))
            addClone('layer0JetCorrFactors', association = cms.InputTag('jetCorrFactors'+postfixLabel),
                                             collection  = cms.InputTag(newLabel0),
                                             backrefs    = cms.InputTag(newLabel0))
            switchJECParameters( getattr(process,'jetCorrFactors'+postfixLabel), jetCorrLabel[0], jetCorrLabel[1], oldalgo='IC5',oldtype='Calo' )
        else:
            addAlso('layer0JetCorrFactors', process.jetCorrFactors.clone(
                                                jetSource           = cms.InputTag(jetCollection),
                                                defaultJetCorrector = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)))
            switchJECParameters( getattr(process,'layer0JetCorrFactors'+postfixLabel), jetCorrLabel[0], jetCorrLabel[1], oldalgo='IC5',oldtype='Calo' )
        if l1Jets != None:
            fixInputTag(l1Jets.jetCorrFactorsSource)
    else:
        if l1Jets != None:
            l1Jets.addJetCorrFactors = False
示例#7
0
def runBTagging(process,
                jetCollection,
                label
                ):
    """
    ------------------------------------------------------------------        
    define sequence to run b tagging on AOD input for a given jet
    collection including a JetTracksAssociatorAtVertex with name
    'jetTracksAssociatorAtVertex' + 'label'

    process       : process       
    jetCollection : input jet collection
    label         : postfix label to identify new sequence/modules

    the sequence is added to the process but not to any path; return
    value is a pair of (sequence, labels) where 'sequence' is the
    cms.Sequence, and 'labels' is a vector with the following entries:
    
     * labels['jta']      = the name of the JetTrackAssociator module
     * labels['tagInfos'] = a list of names of the TagInfo modules
     * labels['jetTags '] = a list of names of the JetTag modules
    ------------------------------------------------------------------        
    """
    if (label == ''):
        ## label is not allowed to be empty
        raise ValueError, "label for re-running b tagging is not allowedc to be empty"

    ## import track associator & b tag configuration
    process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
    from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
    process.load("RecoBTag.Configuration.RecoBTag_cff")
    import RecoBTag.Configuration.RecoBTag_cff as btag
    
    ## define tag info labels (compare with jetProducer_cfi.py)
    jtaLabel  = 'jetTracksAssociatorAtVertex' + label
    ipTILabel = 'impactParameterTagInfos'     + label
    svTILabel = 'secondaryVertexTagInfos'     + label
    seTILabel = 'softElectronTagInfos'        + label
    smTILabel = 'softMuonTagInfos'            + label
    
    ## produce tag infos
    setattr( process, jtaLabel,  ic5JetTracksAssociatorAtVertex.clone(jets = jetCollection))
    setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
    setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
    setattr( process, seTILabel, btag.softElectronTagInfos.clone(jets = jetCollection) )
    setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = jetCollection) )

    ## make VInputTag from strings
    def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
    
    ## produce btags
    setattr( process, 'jetBProbabilityBJetTags'+label, btag.jetBProbabilityBJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'jetProbabilityBJetTags' +label, btag.jetProbabilityBJetTags.clone (tagInfos = vit(ipTILabel)) )
    setattr( process, 'trackCountingHighPurBJetTags'+label, btag.trackCountingHighPurBJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'trackCountingHighEffBJetTags'+label, btag.trackCountingHighEffBJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'impactParameterMVABJetTags'+label, btag.impactParameterMVABJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'simpleSecondaryVertexBJetTags'+label, btag.simpleSecondaryVertexBJetTags.clone(tagInfos = vit(svTILabel)) )
    setattr( process, 'combinedSecondaryVertexBJetTags'+label, btag.combinedSecondaryVertexBJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
    setattr( process, 'combinedSecondaryVertexMVABJetTags'+label, btag.combinedSecondaryVertexMVABJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
    setattr( process, 'softElectronBJetTags'+label, btag.softElectronBJetTags.clone(tagInfos = vit(seTILabel)) )
    setattr( process, 'softMuonBJetTags'+label, btag.softMuonBJetTags.clone(tagInfos = vit(smTILabel)) )
    setattr( process, 'softMuonNoIPBJetTags'+label, btag.softMuonNoIPBJetTags.clone(tagInfos = vit(smTILabel)) )

    ## define vector of (output) labels
    labels = { 'jta'      : jtaLabel, 
               'tagInfos' : (ipTILabel,svTILabel,seTILabel,smTILabel), 
               'jetTags'  : [ (x + label) for x in ('jetBProbabilityBJetTags',
                                                    'jetProbabilityBJetTags',
                                                    'trackCountingHighPurBJetTags',
                                                    'trackCountingHighEffBJetTags',
                                                    'impactParameterMVABJetTags',
                                                    'simpleSecondaryVertexBJetTags',
                                                    'combinedSecondaryVertexBJetTags',
                                                    'combinedSecondaryVertexMVABJetTags',
                                                    'softElectronBJetTags',
                                                    'softMuonBJetTags',
                                                    'softMuonNoIPBJetTags'
                                                    )
                              ]
               }

    ## extend an existing sequence by otherLabels
    def mkseq(process, firstlabel, *otherlabels):
       seq = getattr(process, firstlabel)
       for x in otherlabels: seq += getattr(process, x)
       return cms.Sequence(seq)

    ## add tag infos to the process
    setattr( process, 'btaggingTagInfos'+label, mkseq(process, *(labels['tagInfos']) ) )
    ## add b tags to the process
    setattr( process, 'btaggingJetTags'+label,  mkseq(process, *(labels['jetTags'])  ) )
    ## add a combined sequence to the process
    seq = mkseq(process, jtaLabel, 'btaggingTagInfos'+label, 'btaggingJetTags' + label) 
    setattr( process, 'btagging'+label, seq )
    ## return the combined sequence and the labels defined above
    return (seq, labels)
示例#8
0
    def __call__(self, process,
                 jetCollection=cms.InputTag('sisCone5CaloJets'),
                 label='SCS',
                 doJTA=True,
                 doBTagging=True,
                 jetCorrLabel=None,
                 doType1MET=True,
                 doL1Cleaning = True,
                 doL1Counters = False,
                 genJetCollection = cms.InputTag('sisCone5CaloJets')): 


        self.addParameter('process',process, 'description: process')
        self.addParameter('jetCollection',jetCollection, 'description: InputTag')
        self.addParameter('postfixLabel',label, 'description: label')
        self.addParameter('doJTA',doJTA, 'description: doJTA')
        self.addParameter('doBTagging',doBTagging, 'description: doBTagging')
        self.addParameter('jetCorrLabel',jetCorrLabel, 'description: jetCorrLabel')
        self.addParameter('doType1MET',doType1MET, 'description: doType1MET')
        self.addParameter('doL1Cleaning',doL1Cleaning, 'description: doL1Cleaning')
        self.addParameter('doL1Counters',doL1Counters, 'description: doL1Counters')
        self.addParameter('genJetCollection',genJetCollection, 'description: genJetCollection')

        process = self._parameters['process'].value
        jetCollection = self._parameters['jetCollection'].value
        postfixLabel = self._parameters['postfixLabel'].value
        doJTA = self._parameters['doJTA'].value
        doBTagging =self._parameters['doBTagging'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        doType1MET = self._parameters['doType1MET'].value
        doL1Cleaning = self._parameters['doL1Cleaning'].value
        doL1Counters = self._parameters['doL1Counters'].value
        genJetCollection = self._parameters['genJetCollection'].value            
        
        action = Action("AddJetCollection",copy.copy(self._parameters),self) 
        self.getvalue('process').addAction(action)
        
        #def addJetCollection(process,jetCollection,postfixLabel,
        #               doJTA=True,doBTagging=True,jetCorrLabel=None,doType1MET=True,doL1Counters=False,
        #              genJetCollection=cms.InputTag("iterativeCone5GenJets")):
        """Add a new collection of jets in PAT from the default value.
              postfixLabel: Postpone this label to the name of all modules that work with these jet collection.
                            it can't be an empty string
              doBTagging  : True to run the BTagging sequence on top of this jets, and import it into PAT.
              doJTA       : Run Jet Tracks Association and Jet Charge (will be forced to True if doBTagging is true)
              jetCorrLabel: Name of the algorithm and jet type JEC to pick corrections from, or None for no JEC 
                            Examples are ('IC5','Calo'), ('SC7','Calo'), ('KT4','PF')OB
                            It tries to find a 'L2L3JetCorrector' + algo + type , or otherwise to create if as a 
                            JetCorrectionServiceChain of 'L2RelativeJetCorrector' and 'L3AbsoluteJetCorrector'
              doType1MET  : Make also a new MET (NOT IMPLEMENTED)
              doL1Counters: copy also the filter modules that accept/reject the event looking at the number of jets
              genJetCollection : GenJet collection to match to.

            Note: This takes the configuration from the already-configured jets, so if you do 
                  replaces before calling addJetCollection then they will affect also the new jets
        """
        def addAlso (label,value):
            existing = getattr(process, label)
            setattr( process, label + postfixLabel, value)
            process.patDefaultSequence.replace( existing, existing * value )
        def addClone(label,**replaceStatements):
            new      = getattr(process, label).clone(**replaceStatements)
            addAlso(label, new)
        addClone('allLayer1Jets', jetSource = jetCollection)
        l1Jets = getattr(process, 'allLayer1Jets'+postfixLabel)
        addClone('selectedLayer1Jets', src=cms.InputTag('allLayer1Jets'+postfixLabel))
        addClone('cleanLayer1Jets', src=cms.InputTag('selectedLayer1Jets'+postfixLabel))
        if doL1Counters:
            addClone('countLayer1Jets', src=cms.InputTag('cleanLayer1Jets'+postfixLabel))
        addClone('jetPartonMatch',       src = jetCollection)
        addClone('jetGenJetMatch',       src = jetCollection)
        addClone('jetPartonAssociation', jets = jetCollection)
        addClone('jetFlavourAssociation',srcByReference = cms.InputTag('jetPartonAssociation' + postfixLabel))
        def fixInputTag(x): x.setModuleLabel(x.moduleLabel+postfixLabel)
        def fixVInputTag(x): x[0].setModuleLabel(x[0].moduleLabel+postfixLabel)
        fixInputTag(l1Jets.JetPartonMapSource)
        fixInputTag(l1Jets.genJetMatch)
        fixInputTag(l1Jets.genPartonMatch)
        def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
        if doBTagging :
            (btagSeq, btagLabels) = runBTagging(process,jetCollection,postfixLabel) 
            process.patAODCoreReco += btagSeq  # must add to Core, as it's needed by Extra
            addClone('patJetCharge', src=cms.InputTag(btagLabels['jta']))
            l1Jets.trackAssociationSource = cms.InputTag(btagLabels['jta'])
            l1Jets.tagInfoSources         = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
            l1Jets.discriminatorSources   = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
            fixInputTag(l1Jets.jetChargeSource)
        else:
            l1Jets.addBTagInfo = False 
        if doJTA or doBTagging:
            if not doBTagging:
                process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
                from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
                jtaLabel = 'jetTracksAssociatorAtVertex' + postfixLabel
                setattr( process, jtaLabel, ic5JetTracksAssociatorAtVertex.clone(jets = jetCollection) )
                process.patAODReco.replace(process.patJetTracksCharge, getattr(process,jtaLabel) + process.patJetTracksCharge)
                l1Jets.trackAssociationSource = cms.InputTag(jtaLabel)
                addClone('patJetCharge', src=cms.InputTag(jtaLabel)),
                fixInputTag(l1Jets.jetChargeSource)
        else: ## no JTA
            l1Jets.addAssociatedTracks = False
            l1Jets.addJetCharge = False
        if jetCorrLabel != None:
            if jetCorrLabel == False : raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to None, not False"
            if jetCorrLabel == "None": raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to None (without quotes), not 'None'"
            if type(jetCorrLabel) != type(('IC5','Calo')): 
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be None, or a tuple ('Algo', 'Type')"
            if not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel ):
                setattr( process, 
                         'L2L3JetCorrector%s%s' % jetCorrLabel, 
                         cms.ESSource("JetCorrectionServiceChain",
                                      correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                               'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),

                                      label      = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                                      )
                         )
            addClone('jetCorrFactors',       jetSource           = jetCollection) 
            switchJECParameters( getattr(process,'jetCorrFactors'+postfixLabel), jetCorrLabel[0], jetCorrLabel[1], oldalgo='IC5',oldtype='Calo' )
            fixVInputTag(l1Jets.jetCorrFactorsSource)
            if doType1MET:
                addClone('metJESCorIC5CaloJet', inputUncorJetsLabel = jetCollection.value(),
                         corrector = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel))
                addClone('metJESCorIC5CaloJetMuons', uncorMETInputTag = cms.InputTag("metJESCorIC5CaloJet"+postfixLabel))
                addClone('layer1METs',              metSource = cms.InputTag("metJESCorIC5CaloJetMuons"+postfixLabel))
                l1MET = getattr(process, 'layer1METs'+postfixLabel)
                process.allLayer1Summary.candidates += [ cms.InputTag('layer1METs'+postfixLabel) ]
        else:
            l1Jets.addJetCorrFactors = False
        ## Add this to the summary tables (not strictly needed, but useful)
        if jetCollection not in process.aodSummary.candidates: 
            process.aodSummary.candidates += [ jetCollection ]
        process.allLayer1Summary.candidates      += [ cms.InputTag('allLayer1Jets'+postfixLabel) ]
        process.selectedLayer1Summary.candidates += [ cms.InputTag('selectedLayer1Jets'+postfixLabel) ]
示例#9
0
def switchJetCollection(process,
                        jetCollection,
                        doJTA            = True,
                        doBTagging       = True,
                        jetCorrLabel     = None,
                        doType1MET       = True,
                        genJetCollection = cms.InputTag("iterativeCone5GenJets")
                        ):
    """
    ------------------------------------------------------------------        
    switch the collection of jets in PAT from the default value to a
    new jet collection

    process          : process
    jetCollection    : input jet collection
    doBTagging       : run b tagging sequence for new jet collection
                       and add it to the new pat jet collection
    doJTA            : run JetTracksAssociation and JetCharge and add
                       it to the new pat jet collection (will autom.
                       be true if doBTagging is set to true)
    jetCorrLabel     : algorithm and type of JEC; use 'None' for no
                       JEC; examples are ('IC5','Calo'), ('SC7',
                       'Calo'), ('KT4','PF')
    doType1MET       : if jetCorrLabel is not 'None', set this to
                       'True' to redo the Type1 MET correction for
                       the new jet colllection; at the moment it must
                       be 'False' for non CaloJets otherwise the
                       JetMET POG module crashes.
    genJetCollection : GenJet collection to match to
    ------------------------------------------------------------------        
    """
    ## save label of old jet collection
    oldLabel = process.allLayer1Jets.jetSource;
    
    ## replace input jet collection for generator matches
    process.jetPartonMatch.src        = jetCollection
    process.jetGenJetMatch.src        = jetCollection
    process.jetGenJetMatch.matched    = genJetCollection
    process.jetPartonAssociation.jets = jetCollection
    
    ## replace input jet collection for trigger matches
    massSearchReplaceParam(process.patTrigMatch, 'src', oldLabel, jetCollection)

    ## replace input jet collection for pat jet production
    process.allLayer1Jets.jetSource = jetCollection
    
    ## make VInputTag from strings
    def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )

    if (doBTagging):
        ## replace b tagging sequence
        (btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD')
        ## add b tagging sequence to the patAODCoreReco
        ## sequence as it is also needed by ExtraReco
        process.patAODCoreReco += btagSeq
        ## replace jet charge associator tag patJetCharge
        process.patJetCharge.src = btagLabels['jta']
        ## replace corresponding tags for pat jet production
        process.allLayer1Jets.trackAssociationSource = btagLabels['jta']
        process.allLayer1Jets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
        process.allLayer1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
    else:
        ## remove b tagging from the std sequence
        process.patAODReco.remove(process.patBTagging)
        ## switch embedding of b tagging for pat
        ## jet production to 'False'
        process.allLayer1Jets.addBTagInfo = False
        
    if (doJTA or doBTagging):
        ## replace jet track association
        if (not doBTagging):
            ## in case b tagging is switched off do the 
            ## jet track association production here
            process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            process.jetTracksAssociatorAtVertex = ic5JetTracksAssociatorAtVertex.clone(jets = jetCollection)
            process.patAODReco.replace(process.patJetTracksCharge, process.jetTracksAssociatorAtVertex + process.patJetTracksCharge)
            process.patJetCharge.src = 'jetTracksAssociatorAtVertex'
            process.allLayer1Jets.trackAssociationSource = 'jetTracksAssociatorAtVertex'
    else:
        ## remove the jet track association from the std
        ## sequence
        process.patAODReco.remove(process.patJetTracksCharge)
        ## switch embedding of track association and jet
        ## charge estimate to 'False'
        process.allLayer1Jets.addAssociatedTracks = False
        process.allLayer1Jets.addJetCharge = False
        
    if (jetCorrLabel!=None):
        ## replace jet energy corrections; catch
        ## a couple of exceptions first
        if (jetCorrLabel == False ):
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
        if (jetCorrLabel == "None"):
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
        ## check for the correct format
        if (type(jetCorrLabel)!=type(('IC5','Calo'))): 
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"

        ## switch JEC parameters to the new jet collection
        process.jetCorrFactors.jetSource = jetCollection            
        switchJECParameters(process.jetCorrFactors, jetCorrLabel[0], jetCorrLabel[1], oldAlgo='IC5',oldType='Calo')

        ## redo the type1MET correction for the new jet collection
        if (doType1MET):
            ## in case there is no jet correction service in the paths add it
            ## as L2L3 if possible, as combined from L2 and L3 otherwise
            if (not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel )):
                setattr( process, 
                         'L2L3JetCorrector%s%s' % jetCorrLabel, 
                         cms.ESSource("JetCorrectionServiceChain",
                                      correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                               'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                                      label = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                                      )
                         )
            ## configure the type1MET correction the following muonMET
            ## corrections have the corMetType1Icone5 as input and are
            ## automatically correct  
            process.corMetType1Icone5.inputUncorJetsLabel = jetCollection
            process.corMetType1Icone5.corrector = 'L2L3JetCorrector%s%s' % jetCorrLabel
    else:
        ## remove the jetCorrFactors from the std sequence
        process.patJetMETCorrections.remove(process.jetCorrFactors)
        ## switch embedding of jetCorrFactors off
        ## for pat jet production
        process.allLayer1Jets.addJetCorrFactors = False

    if (oldLabel in process.aodSummary.candidates): 
        ## add the new jet collection to the summary tables
        process.aodSummary.candidates[process.aodSummary.candidates.index(oldLabel)] = jetCollection
    else:
        process.aodSummary.candidates += [jetCollection]
示例#10
0
def runBTagging(process, jetCollection, label):
    """Define a sequence to run BTagging on AOD on top of jet collection 'jetCollection', appending 'label' to module labels.
       The sequence will be called "btaggingAOD" + 'label', and will already be added to the process (but not to any Path)
       The sequence will include a JetTracksAssociatorAtVertex with name "jetTracksAssociatorAtVertex" + 'label'
       The method will return a pair (sequence, labels) where 'sequence' is the cms.Sequence object, and 'labels' contains
         labels["jta"]      = the name of the JetTrackAssociator module
         labels["tagInfos"] = list of names of TagInfo modules
         labels["jetTags "] = list of names of JetTag modules
       these labels are meant to be used for PAT BTagging tools
       NOTE: 'label' MUST NOT BE EMPTY
     """
    if (label == ''):
        raise ValueError, "Label for re-running BTagging can't be empty, it will crash CRAB."
    process.load(
        "RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
    process.load("RecoBTag.Configuration.RecoBTag_cff")
    from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
    import RecoBTag.Configuration.RecoBTag_cff as btag

    # quickly make VInputTag from strings
    def vit(*args):
        return cms.VInputTag(*[cms.InputTag(x) for x in args])

    # define labels
    jtaLabel = 'jetTracksAssociatorAtVertex' + label
    ipTILabel = 'impactParameterTagInfos' + label
    svTILabel = 'secondaryVertexTagInfos' + label
    seTILabel = 'softElectronTagInfos' + label
    smTILabel = 'softMuonTagInfos' + label

    # make JTA and TagInfos
    setattr(
        process, jtaLabel,
        ic5JetTracksAssociatorAtVertex.clone(jets=cms.InputTag(jetCollection)))
    setattr(
        process, ipTILabel,
        btag.impactParameterTagInfos.clone(jetTracks=cms.InputTag(jtaLabel)))
    setattr(
        process, svTILabel,
        btag.secondaryVertexTagInfos.clone(
            trackIPTagInfos=cms.InputTag(ipTILabel)))
    setattr(process, seTILabel,
            btag.softElectronTagInfos.clone(jets=cms.InputTag(jetCollection)))
    setattr(process, smTILabel,
            btag.softMuonTagInfos.clone(jets=cms.InputTag(jetCollection)))
    setattr(process, 'jetBProbabilityBJetTags' + label,
            btag.jetBProbabilityBJetTags.clone(tagInfos=vit(ipTILabel)))
    setattr(process, 'jetProbabilityBJetTags' + label,
            btag.jetProbabilityBJetTags.clone(tagInfos=vit(ipTILabel)))
    setattr(process, 'trackCountingHighPurBJetTags' + label,
            btag.trackCountingHighPurBJetTags.clone(tagInfos=vit(ipTILabel)))
    setattr(process, 'trackCountingHighEffBJetTags' + label,
            btag.trackCountingHighEffBJetTags.clone(tagInfos=vit(ipTILabel)))
    setattr(process, 'impactParameterMVABJetTags' + label,
            btag.impactParameterMVABJetTags.clone(tagInfos=vit(ipTILabel)))
    setattr(process, 'simpleSecondaryVertexBJetTags' + label,
            btag.simpleSecondaryVertexBJetTags.clone(tagInfos=vit(svTILabel)))
    setattr(
        process, 'combinedSecondaryVertexBJetTags' + label,
        btag.combinedSecondaryVertexBJetTags.clone(
            tagInfos=vit(ipTILabel, svTILabel)))
    setattr(
        process, 'combinedSecondaryVertexMVABJetTags' + label,
        btag.combinedSecondaryVertexMVABJetTags.clone(
            tagInfos=vit(ipTILabel, svTILabel)))
    setattr(process, 'softElectronBJetTags' + label,
            btag.softElectronBJetTags.clone(tagInfos=vit(seTILabel)))
    setattr(process, 'softMuonBJetTags' + label,
            btag.softMuonBJetTags.clone(tagInfos=vit(smTILabel)))
    setattr(process, 'softMuonNoIPBJetTags' + label,
            btag.softMuonNoIPBJetTags.clone(tagInfos=vit(smTILabel)))

    def mkseq(process, firstlabel, *otherlabels):
        seq = getattr(process, firstlabel)
        for x in otherlabels:
            seq += getattr(process, x)
        return cms.Sequence(seq)

    labels = {
        'jta':
        jtaLabel,
        'tagInfos': (ipTILabel, svTILabel, seTILabel, smTILabel),
        'jetTags':
        [(x + label)
         for x in ('jetBProbabilityBJetTags', 'jetProbabilityBJetTags',
                   'trackCountingHighPurBJetTags',
                   'trackCountingHighEffBJetTags',
                   'impactParameterMVABJetTags',
                   'simpleSecondaryVertexBJetTags',
                   'combinedSecondaryVertexBJetTags',
                   'combinedSecondaryVertexMVABJetTags',
                   'softElectronBJetTags', 'softMuonBJetTags',
                   'softMuonNoIPBJetTags')]
    }

    setattr(process, 'btaggingTagInfos' + label,
            mkseq(process, *(labels['tagInfos'])))
    setattr(process, 'btaggingJetTags' + label,
            mkseq(process, *(labels['jetTags'])))
    seq = mkseq(process, jtaLabel, 'btaggingTagInfos' + label,
                'btaggingJetTags' + label)
    setattr(process, 'btagging' + label, seq)
    return (seq, labels)
示例#11
0
def addJetCollection(process,
                     jetCollection,
                     postfixLabel,
                     layers=[0, 1],
                     runCleaner="CaloJet",
                     doJTA=True,
                     doBTagging=True,
                     jetCorrLabel=None,
                     doType1MET=True,
                     doL1Counters=False):
    """Add a new collection of jets in PAT from the default value.
          postfixLabel: Postpone this label to the name of all modules that work with these jet collection.
                        it can't be an empty string
          layers      : Determine which PAT layers will be affected ([0], [0,1])   
          runCleaner  : Run the layer 0 jet cleaner. Value is the C++ type of the jet CaloJet, PFJet, BasicJet), or None.
                        The cleaner module will be always called 'allLayer0Jets'.
                        None must be written without quotes!
          doBTagging  : True to run the BTagging sequence on top of this jets, and import it into PAT.
          doJTA       : Run Jet Tracks Association and Jet Charge (will be forced to True if doBTagging is true)
          jetCorrLabel: Name of the algorithm and jet type JEC to pick corrections from, or None for no JEC 
                        Examples are ('IC5','Calo'), ('SC7','Calo'), ('KT4','PF')
                        It tries to find a 'L2L3JetCorrector' + algo + type , or otherwise to create if as a 
                        JetCorrectionServiceChain of 'L2RelativeJetCorrector' and 'L3AbsoluteJetCorrector'
          doType1MET  : Make also a new MET (NOT IMPLEMENTED)
          doL1Counters: copy also the filter modules that accept/reject the event looking at the number of jets

       Notes:
       1)  This takes the configuration from the already-configured layer 0+1 jets, so if you do 
           replaces before calling addJetCollection then they will affect also the new jets
           DON'T DON'T DON'T call this after having switched off cleaning of layer 0 jets!
    
       2)  When turning off the cleaner, bTagging, JTA, jet corrections, MC and Trigger matching will be run directly on jetCollection
             The outputs will still be called 'layer0BTags'+postfixLabel, 'layer0JetTracksAssociatior'+postfixLabel and so on."""
    def addAlso(label, value):
        existing = getattr(process, label)
        setattr(process, label + postfixLabel, value)
        process.patLayer0.replace(existing, existing * value)
        if layers.count(1) != 0:
            process.patLayer1.replace(existing, existing * value)

    def addClone(label, **replaceStatements):
        new = getattr(process, label).clone(**replaceStatements)
        addAlso(label, new)

    # --- L0 ---
    newLabel0 = 'allLayer0Jets' + postfixLabel
    if runCleaner == "CaloJet":
        addClone('allLayer0Jets', jetSource=cms.InputTag(jetCollection))
    elif runCleaner == "PFJet":
        addAlso(
            'allLayer0Jets',
            process.allLayer0PFJets.clone(
                jetSource=cms.InputTag(jetCollection)))
    elif runCleaner == "BasicJet":
        from PhysicsTools.PatAlgos.cleaningLayer0.basicJetCleaner_cfi import allLayer0Jets as allLayer0BasicJets
        addAlso(
            'allLayer0Jets',
            allLayer0BasicJets.clone(jetSource=cms.InputTag(jetCollection)))
    elif runCleaner == None:
        pass
    elif runCleaner == "None":
        raise ValueError, "In switchJetCollection, the value None for runCleaner must be written without quotes"
    else:
        raise ValueError, ("Cleaner '%s' not known" % (runCleaner, ))
    # --- L1 ---
    l1Jets = None
    if layers.count(1) != 0:
        addClone('allLayer1Jets', jetSource=cms.InputTag(newLabel0))
        l1Jets = getattr(process, 'allLayer1Jets' + postfixLabel)
        addClone('selectedLayer1Jets',
                 src=cms.InputTag('allLayer1Jets' + postfixLabel))
        if doL1Counters:
            addClone('minLayer1Jets',
                     src=cms.InputTag('selectedLayer1Jets' + postfixLabel))
            addClone('maxLayer1Jets',
                     src=cms.InputTag('selectedLayer1Jets' + postfixLabel))
        if runCleaner == None:
            l1Jets.jetSource = cms.InputTag(jetCollection)
    if runCleaner != None:
        addClone('jetPartonMatch', src=cms.InputTag(newLabel0))
        addClone('jetGenJetMatch', src=cms.InputTag(newLabel0))
        addClone('jetPartonAssociation', jets=cms.InputTag(newLabel0))
        addClone('jetFlavourAssociation',
                 srcByReference=cms.InputTag('jetPartonAssociation' +
                                             postfixLabel))
        triggers = MassSearchParamVisitor('src', cms.InputTag("allLayer0Jets"))
        process.patTrigMatch.visit(triggers)
        for mod in triggers.modules():
            newmod = mod.clone(src=cms.InputTag(newLabel0))
            setattr(process, mod.label() + postfixLabel, newmod)
            process.patTrigMatch.replace(mod, mod * newmod)
    else:
        l1Jets.src = cms.InputTag(jetCollection)
        addClone('jetPartonMatch', src=cms.InputTag(jetCollection))
        addClone('jetGenJetMatch', src=cms.InputTag(jetCollection))
        addClone('jetPartonAssociation', jets=cms.InputTag(jetCollection))
        addClone('jetFlavourAssociation',
                 srcByReference=cms.InputTag('jetPartonAssociation' +
                                             postfixLabel))
        triggers = MassSearchParamVisitor('src', cms.InputTag("allLayer0Jets"))
        process.patTrigMatch.visit(triggers)
        for mod in triggers.modules():
            newmod = mod.clone(src=cms.InputTag(jetCollection))
            setattr(process, mod.label() + postfixLabel, newmod)
            process.patTrigMatch.replace(mod, mod * newmod)

    def fixInputTag(x):
        x.setModuleLabel(x.moduleLabel + postfixLabel)

    if l1Jets != None:
        fixInputTag(l1Jets.JetPartonMapSource)
        fixInputTag(l1Jets.genJetMatch)
        fixInputTag(l1Jets.genPartonMatch)
        for it in l1Jets.trigPrimMatch.value():
            fixInputTag(it)

    def vit(*args):
        return cms.VInputTag(*[cms.InputTag(x) for x in args])

    if doBTagging:
        (btagSeq, btagLabels) = runBTagging(process, jetCollection,
                                            postfixLabel)
        process.patLayer0.replace(process.patBeforeLevel0Reco,
                                  btagSeq + process.patBeforeLevel0Reco)
        if runCleaner != None:
            addClone('patAODJetTracksAssociator',
                     src=cms.InputTag(jetCollection),
                     tracks=cms.InputTag(btagLabels['jta']))
            addClone('patAODTagInfos',
                     collection=cms.InputTag(jetCollection),
                     associations=vit(*btagLabels['tagInfos']))
            addClone('patAODBTags',
                     collection=cms.InputTag(jetCollection),
                     associations=vit(*btagLabels['jetTags']))
            addClone('layer0JetTracksAssociator',
                     association=cms.InputTag('patAODJetTracksAssociator' +
                                              postfixLabel),
                     collection=cms.InputTag(newLabel0),
                     backrefs=cms.InputTag(newLabel0))
            addClone(
                'layer0JetCharge',
                src=cms.InputTag(newLabel0),
                jetTracksAssociation=cms.InputTag('layer0JetTracksAssociator' +
                                                  postfixLabel))
            addClone('layer0TagInfos',
                     commonLabel=cms.InputTag('patAODTagInfos' + postfixLabel),
                     associations=vit(*btagLabels['tagInfos']),
                     collection=cms.InputTag(newLabel0),
                     backrefs=cms.InputTag(newLabel0))
            addClone('layer0BTags',
                     commonLabel=cms.InputTag('patAODBTags' + postfixLabel),
                     associations=vit(*btagLabels['jetTags']),
                     collection=cms.InputTag(newLabel0),
                     backrefs=cms.InputTag(newLabel0))
        else:
            addAlso(
                'layer0JetTracksAssociator',
                process.patAODJetTracksAssociator.clone(
                    src=cms.InputTag(jetCollection),
                    tracks=cms.InputTag(btagLabels['jta'])))
            addClone(
                'layer0JetCharge',
                src=cms.InputTag(jetCollection),
                jetTracksAssociation=cms.InputTag('layer0JetTracksAssociator' +
                                                  postfixLabel))
            addAlso(
                'layer0TagInfos',
                process.patAODTagInfos.clone(
                    collection=cms.InputTag(jetCollection),
                    associations=vit(*btagLabels['tagInfos'])))
            addAlso(
                'layer0BTags',
                process.patAODBTags.clone(
                    collection=cms.InputTag(jetCollection),
                    associations=vit(*btagLabels['jetTags'])))
        if l1Jets != None:
            fixInputTag(l1Jets.jetChargeSource)
            fixInputTag(l1Jets.trackAssociationSource)
            fixInputTag(l1Jets.tagInfoModule)
            fixInputTag(l1Jets.discriminatorModule)
            if l1Jets.discriminatorNames != cms.vstring("*"):
                l1Jets.discriminatorNames.setValue([
                    x + postfixLabel
                    for x in l1Jets.discriminatorNames.value()
                ])
            if l1Jets.tagInfoNames != cms.vstring("*"):
                l1Jets.tagInfoNames.setValue(
                    [x + postfixLabel for x in l1Jets.tagInfoNames.value()])
    else:
        if l1Jets != None: l1Jets.addBTagInfo = False
    if doJTA or doBTagging:
        if not doBTagging:
            process.load(
                "RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi"
            )
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            jtaLabel = 'jetTracksAssociatorAtVertex' + postfixLabel
            setattr(
                process, jtaLabel,
                ic5JetTracksAssociatorAtVertex.clone(
                    jets=cms.InputTag(jetCollection)))
            process.patLayer0.replace(
                process.patBeforeLevel0Reco,
                getattr(process, jtaLabel) + process.patBeforeLevel0Reco)
            if runCleaner != None:
                addClone('patAODJetTracksAssociator',
                         src=cms.InputTag(jetCollection),
                         tracks=cms.InputTag(jtaLabel))
                addClone('layer0JetTracksAssociator',
                         association=cms.InputTag('patAODJetTracksAssociator' +
                                                  postfixLabel),
                         collection=cms.InputTag(newLabel0),
                         backrefs=cms.InputTag(newLabel0))
                addClone('layer0JetCharge',
                         src=cms.InputTag(newLabel0),
                         jetTracksAssociation=cms.InputTag(
                             'layer0JetTracksAssociator' + postfixLabel))
            else:
                addAlso(
                    'layer0JetTracksAssociator',
                    process.patAODJetTracksAssociator.clone(
                        src=cms.InputTag(jetCollection),
                        tracks=cms.InputTag(jtaLabel)))
                addClone('layer0JetCharge',
                         src=cms.InputTag(jetCollection),
                         jetTracksAssociation=cms.InputTag(
                             'layer0JetTracksAssociator' + postfixLabel))
            if l1Jets != None:
                fixInputTag(l1Jets.jetChargeSource)
                fixInputTag(l1Jets.trackAssociationSource)
    else:  ## no JTA
        if l1Jets != None:
            l1Jets.addAssociatedTracks = False
            l1Jets.addJetCharge = False
    if jetCorrLabel != None:
        if jetCorrLabel == False:
            raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to None, not False"
        if jetCorrLabel == "None":
            raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to None (without quotes), not 'None'"
        if type(jetCorrLabel) != type(('IC5', 'Calo')):
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be None, or a tuple ('Algo', 'Type')"
        if not hasattr(process, 'L2L3JetCorrector%s%s' % jetCorrLabel):
            setattr(
                process, 'L2L3JetCorrector%s%s' % jetCorrLabel,
                cms.ESSource("JetCorrectionServiceChain",
                             correctors=cms.vstring(
                                 'L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                 'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                             label=cms.string('L2L3JetCorrector%s%s' %
                                              jetCorrLabel)))
        if runCleaner != None:
            addClone('jetCorrFactors',
                     jetSource=cms.InputTag(jetCollection),
                     defaultJetCorrector=cms.string('L2L3JetCorrector%s%s' %
                                                    jetCorrLabel))
            addClone('layer0JetCorrFactors',
                     association=cms.InputTag('jetCorrFactors' + postfixLabel),
                     collection=cms.InputTag(newLabel0),
                     backrefs=cms.InputTag(newLabel0))
            switchJECParameters(getattr(process,
                                        'jetCorrFactors' + postfixLabel),
                                jetCorrLabel[0],
                                jetCorrLabel[1],
                                oldalgo='IC5',
                                oldtype='Calo')
        else:
            addAlso(
                'layer0JetCorrFactors',
                process.jetCorrFactors.clone(
                    jetSource=cms.InputTag(jetCollection),
                    defaultJetCorrector=cms.string('L2L3JetCorrector%s%s' %
                                                   jetCorrLabel)))
            switchJECParameters(getattr(process,
                                        'layer0JetCorrFactors' + postfixLabel),
                                jetCorrLabel[0],
                                jetCorrLabel[1],
                                oldalgo='IC5',
                                oldtype='Calo')
        if l1Jets != None:
            fixInputTag(l1Jets.jetCorrFactorsSource)
    else:
        if l1Jets != None:
            l1Jets.addJetCorrFactors = False
示例#12
0
def switchJetCollection(process,
                        jetCollection,
                        layers=[0, 1],
                        runCleaner="CaloJet",
                        doJTA=True,
                        doBTagging=True,
                        jetCorrLabel=None,
                        doType1MET=True):
    """Switch the collection of jets in PAT from the default value.
          layers      : Determine which PAT layers will be affected ([0], [0,1])   
          runCleaner  : Run the layer 0 jet cleaner. Value is the C++ type of the jet CaloJet, PFJet, BasicJet), or None.
                        The cleaner module will be always called 'allLayer0Jets'.
                        None must be written without quotes!
          doBTagging  : True to run the BTagging sequence on top of this jets, and import it into PAT.
          doJTA       : Run Jet Tracks Association and Jet Charge (will be forced to True if doBTagging is true)
          jetCorrLabel: Name of the algorithm and jet type JEC to pick corrections from, or None for no JEC 
                        Examples are ('IC5','Calo'), ('SC7','Calo'), ('KT4','PF')
                        It tries to find a 'L2L3JetCorrector' + algo + type , or otherwise to create if as a 
                        JetCorrectionServiceChain of 'L2RelativeJetCorrector' and 'L3AbsoluteJetCorrector'
          doType1MET  : If jetCorrLabel is not 'None', set this to 'True' to remake Type1 MET from these jets
                        NOTE: at the moment it must be False for non-CaloJets otherwise the JetMET POG module crashes.

       Note: When turning off the cleaner, bTagging, JTA, jet corrections, MC and Trigger matching will be run directly on jetCollection
             The outputs will still be called 'layer0BTags', 'layer0JetTracksAssociatior' and so on.
       Note: Replacing only layer 1 is not a well defined task, so it's not allowed. 
             What you want is probably to replace 0+1 without any cleaning (runCleaner=None), or a simple replace of allLayer1Jets.jetSource"""
    if runCleaner == "CaloJet":
        process.allLayer0Jets.jetSource = jetCollection
    elif runCleaner == "PFJet":
        process.globalReplace(
            'allLayer0Jets',
            process.allLayer0PFJets.clone(
                jetSource=cms.InputTag(jetCollection)))
    elif runCleaner == "BasicJet":
        from PhysicsTools.PatAlgos.cleaningLayer0.basicJetCleaner_cfi import allLayer0Jets as allLayer0BasicJets
        process.globalReplace(
            'allLayer0Jets',
            process.allLayer0BasicJets.clone(
                jetSource=cms.InputTag(jetCollection)))
    elif runCleaner == None:
        process.patLayer0.remove(process.allLayer0Jets)
        # MC match
        process.jetPartonMatch.src = cms.InputTag(jetCollection)
        process.jetGenJetMatch.src = cms.InputTag(jetCollection)
        process.jetPartonAssociation.jets = cms.InputTag(jetCollection)
        massSearchReplaceParam(process.patTrigMatch, 'src',
                               cms.InputTag("allLayer0Jets"),
                               cms.InputTag(jetCollection))
        if layers.count(1) != 0:
            process.allLayer1Jets.jetSource = cms.InputTag(jetCollection)
    elif runCleaner == "None":
        raise ValueError, "In switchJetCollection, the value None for runCleaner must be written without quotes"
    else:
        raise ValueError, ("Cleaner '%s' not known" % (runCleaner, ))
    if doBTagging:
        (btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD')
        process.patLayer0.replace(process.patBeforeLevel0Reco,
                                  btagSeq + process.patBeforeLevel0Reco)
        process.patAODJetTracksAssociator.src = jetCollection
        process.patAODJetTracksAssociator.tracks = btagLabels['jta']
        process.patAODTagInfos.collection = jetCollection
        process.patAODBTags.collection = jetCollection
        process.patAODTagInfos.associations = btagLabels['tagInfos']
        process.patAODBTags.associations = btagLabels['jetTags']
        if runCleaner != None:
            process.layer0TagInfos.associations = btagLabels['tagInfos']
            process.layer0BTags.associations = btagLabels['jetTags']
        else:
            process.globalReplace('layer0JetTracksAssociator',
                                  process.patAODJetTracksAssociator.clone())
            process.globalReplace('layer0TagInfos',
                                  process.patAODTagInfos.clone())
            process.globalReplace('layer0BTags', process.patAODBTags.clone())
            process.patLayer0.remove(process.patAODJetTracksAssociator)
            process.patLayer0.remove(process.patAODBTags)
            process.patLayer0.remove(process.patAODTagInfos)
    else:
        process.patLayer0.remove(process.patAODBTagging)
        process.patLayer0.remove(process.patLayer0BTagging)
        if layers.count(1) != 0: process.allLayer1Jets.addBTagInfo = False
    if doJTA or doBTagging:
        if not doBTagging:
            process.load(
                "RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi"
            )
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            process.jetTracksAssociatorAtVertex = ic5JetTracksAssociatorAtVertex.clone(
                jets=cms.InputTag(jetCollection))
            process.patLayer0.replace(
                process.patBeforeLevel0Reco,
                process.jetTracksAssociatorAtVertex +
                process.patBeforeLevel0Reco)
            process.patAODJetTracksAssociator.src = jetCollection
            process.patAODJetTracksAssociator.tracks = 'jetTracksAssociatorAtVertex'
            if runCleaner == None:
                process.globalReplace(
                    'layer0JetTracksAssociator',
                    process.patAODJetTracksAssociator.clone())
                process.layer0JetCharge.src = jetCollection
                process.patLayer0.remove(process.patAODJetTracksAssociator)
    else:  ## no JTA
        process.patHighLevelReco_withoutPFTau.remove(
            process.patLayer0JetTracksCharge)
        if layers.count(1) != 0:
            process.allLayer1Jets.addAssociatedTracks = False
            process.allLayer1Jets.addJetCharge = False
    if jetCorrLabel != None:
        if jetCorrLabel == False:
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to None, not False"
        if jetCorrLabel == "None":
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to None (without quotes), not 'None'"
        if type(jetCorrLabel) != type(('IC5', 'Calo')):
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be None, or a tuple ('Algo', 'Type')"
        if not hasattr(process, 'L2L3JetCorrector%s%s' % jetCorrLabel):
            setattr(
                process, 'L2L3JetCorrector%s%s' % jetCorrLabel,
                cms.ESSource("JetCorrectionServiceChain",
                             correctors=cms.vstring(
                                 'L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                 'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                             label=cms.string('L2L3JetCorrector%s%s' %
                                              jetCorrLabel)))
        switchJECParameters(process.jetCorrFactors,
                            jetCorrLabel[0],
                            jetCorrLabel[1],
                            oldalgo='IC5',
                            oldtype='Calo')
        process.jetCorrFactors.jetSource = jetCollection
        if doType1MET:
            process.corMetType1Icone5.inputUncorJetsLabel = jetCollection
            process.corMetType1Icone5.corrector = 'L2L3JetCorrector%s%s' % jetCorrLabel
        if runCleaner == None:
            process.globalReplace('layer0JetCorrFactors',
                                  process.jetCorrFactors.copy())
            process.patLayer0.remove(process.jetCorrFactors)
    else:
        process.patLayer0.remove(process.jetCorrFactors)
        process.patLayer0.remove(process.layer0JetCorrFactors)
        if layers.count(1) != 0:
            process.allLayer1Jets.addJetCorrFactors = False
示例#13
0
    def __call__(self, process,
                 jetCollection,
                 doJTA            = True,
                 doBTagging       = True,
                 jetCorrLabel     = None,
                 doType1MET       = True,
                 genJetCollection = cms.InputTag("iterativeCone5GenJets")):

        self.addParameter('process',process, 'description: process')
        self.addParameter('jetCollection',jetCollection, 'description: InputTag')
        self.addParameter('doJTA',doJTA, 'description: doJTA')
        self.addParameter('doBTagging',doBTagging, 'description: doBTagging')
        self.addParameter('jetCorrLabel',jetCorrLabel, 'description: jetCorrLabel')
        self.addParameter('doType1MET',doType1MET, 'description: doType1MET')
        self.addParameter('genJetCollection',genJetCollection, 'description: genJetCollection')


        process=self._parameters['process'].value
        oldLabel = process.allLayer1Jets.jetSource;
        jetCollection = self._parameters['jetCollection'].value
        doJTA = self._parameters['doJTA'].value
        doBTagging =self._parameters['doBTagging'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        doType1MET = self._parameters['doType1MET'].value
        genJetCollection = self._parameters['genJetCollection'].value
        process.jetPartonMatch.src        = jetCollection
        process.jetGenJetMatch.src        = jetCollection
        process.jetGenJetMatch.match      = genJetCollection
        process.jetPartonAssociation.jets = jetCollection
        process.allLayer1Jets.jetSource = jetCollection


        # quickly make VInputTag from strings
        def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
        if doBTagging :
            (btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD')
            process.patAODCoreReco += btagSeq # must add to Core, as it's needed by ExtraReco
            process.patJetCharge.src                     = btagLabels['jta']
            process.allLayer1Jets.trackAssociationSource = btagLabels['jta']
            process.allLayer1Jets.tagInfoSources       = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
            process.allLayer1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
        else:
            process.patAODReco.remove(process.patBTagging)
            process.allLayer1Jets.addBTagInfo = False
        if doJTA or doBTagging:
            if not doBTagging:
                process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
                from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
                process.jetTracksAssociatorAtVertex = ic5JetTracksAssociatorAtVertex.clone(jets = jetCollection)
                process.patAODReco.replace(process.patJetTracksCharge, process.jetTracksAssociatorAtVertex + process.patJetTracksCharge)
                process.patJetCharge.src                     = 'jetTracksAssociatorAtVertex'
                process.allLayer1Jets.trackAssociationSource = 'jetTracksAssociatorAtVertex'
        else: ## no JTA
            process.patAODReco.remove(process.patJetTracksCharge)
            process.allLayer1Jets.addAssociatedTracks = False
            process.allLayer1Jets.addJetCharge = False
        if jetCorrLabel != None:
            if jetCorrLabel == False : raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to None, not False"
            if jetCorrLabel == "None": raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to None (without quotes), not 'None'"
            if type(jetCorrLabel) != type(('IC5','Calo')):
                raise ValueError, "In switchJetCollection 'jetCorrLabel' must be None, or a tuple ('Algo', 'Type')"
            if not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel ):
                setattr( process,
                         'L2L3JetCorrector%s%s' % jetCorrLabel,
                         cms.ESSource("JetCorrectionServiceChain",
                                      correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                               'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                                      label      = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                                      )
                         )
            switchJECParameters(process.jetCorrFactors, jetCorrLabel[0], jetCorrLabel[1], oldalgo='IC5',oldtype='Calo')
            process.jetCorrFactors.jetSource = jetCollection
            if doType1MET:
                process.metJESCorIC5CaloJet.inputUncorJetsLabel = jetCollection.value() # FIXME it's metJESCorIC5CaloJet that's broken
                process.metJESCorIC5CaloJet.corrector           = 'L2L3JetCorrector%s%s' % jetCorrLabel
        else:
            process.patJetMETCorrections.remove(process.jetCorrFactors)
            process.allLayer1Jets.addJetCorrFactors = False
            ## Add this to the summary tables (not strictly needed, but useful)
        if oldLabel in process.aodSummary.candidates:
            process.aodSummary.candidates[process.aodSummary.candidates.index(oldLabel)] = jetCollection
        else:
            process.aodSummary.candidates += [jetCollection]
                                                                                
        action = Action("switchJetCollection",copy.copy(self._parameters),self)
        process.addAction(action)
示例#14
0
def switchJetCollection(process,jetCollection,layers=[0,1],runCleaner="CaloJet",doJTA=True,doBTagging=True,jetCorrLabel=None,doType1MET=True):
    """Switch the collection of jets in PAT from the default value.
          layers      : Determine which PAT layers will be affected ([0], [0,1])   
          runCleaner  : Run the layer 0 jet cleaner. Value is the C++ type of the jet CaloJet, PFJet, BasicJet), or None.
                        The cleaner module will be always called 'allLayer0Jets'.
                        None must be written without quotes!
          doBTagging  : True to run the BTagging sequence on top of this jets, and import it into PAT.
          doJTA       : Run Jet Tracks Association and Jet Charge (will be forced to True if doBTagging is true)
          jetCorrLabel: Name of the algorithm and jet type JEC to pick corrections from, or None for no JEC 
                        Examples are ('IC5','Calo'), ('SC7','Calo'), ('KT4','PF')
                        It tries to find a 'L2L3JetCorrector' + algo + type , or otherwise to create if as a 
                        JetCorrectionServiceChain of 'L2RelativeJetCorrector' and 'L3AbsoluteJetCorrector'
          doType1MET  : If jetCorrLabel is not 'None', set this to 'True' to remake Type1 MET from these jets
                        NOTE: at the moment it must be False for non-CaloJets otherwise the JetMET POG module crashes.

       Note: When turning off the cleaner, bTagging, JTA, jet corrections, MC and Trigger matching will be run directly on jetCollection
             The outputs will still be called 'layer0BTags', 'layer0JetTracksAssociatior' and so on.
       Note: Replacing only layer 1 is not a well defined task, so it's not allowed. 
             What you want is probably to replace 0+1 without any cleaning (runCleaner=None), or a simple replace of allLayer1Jets.jetSource"""
    if runCleaner == "CaloJet":
        process.allLayer0Jets.jetSource = jetCollection
    elif runCleaner == "PFJet":
        process.globalReplace('allLayer0Jets', process.allLayer0PFJets.clone(jetSource = cms.InputTag(jetCollection)))
    elif runCleaner == "BasicJet":
        from PhysicsTools.PatAlgos.cleaningLayer0.basicJetCleaner_cfi import allLayer0Jets as allLayer0BasicJets;
        process.globalReplace('allLayer0Jets', process.allLayer0BasicJets.clone(jetSource = cms.InputTag(jetCollection)))
    elif runCleaner == None:
        process.patLayer0.remove(process.allLayer0Jets)
        # MC match
        process.jetPartonMatch.src        = cms.InputTag(jetCollection)
        process.jetGenJetMatch.src        = cms.InputTag(jetCollection)
        process.jetPartonAssociation.jets = cms.InputTag(jetCollection)
        massSearchReplaceParam(process.patTrigMatch, 'src', cms.InputTag("allLayer0Jets"), cms.InputTag(jetCollection))
        if layers.count(1) != 0:
            process.allLayer1Jets.jetSource = cms.InputTag(jetCollection)
    elif runCleaner == "None":
        raise ValueError, "In switchJetCollection, the value None for runCleaner must be written without quotes"
    else:
        raise ValueError, ("Cleaner '%s' not known" % (runCleaner,))
    if doBTagging :
          (btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD')
          process.patLayer0.replace(process.patBeforeLevel0Reco, btagSeq + process.patBeforeLevel0Reco)
          process.patAODJetTracksAssociator.src       = jetCollection
          process.patAODJetTracksAssociator.tracks    = btagLabels['jta']
          process.patAODTagInfos.collection           = jetCollection
          process.patAODBTags.collection              = jetCollection
          process.patAODTagInfos.associations         = btagLabels['tagInfos']
          process.patAODBTags.associations            = btagLabels['jetTags']
          if runCleaner != None:
              process.layer0TagInfos.associations         = btagLabels['tagInfos']
              process.layer0BTags.associations            = btagLabels['jetTags']
          else:
              process.globalReplace('layer0JetTracksAssociator', process.patAODJetTracksAssociator.clone())
              process.globalReplace('layer0TagInfos',            process.patAODTagInfos.clone())
              process.globalReplace('layer0BTags',               process.patAODBTags.clone())
              process.patLayer0.remove(process.patAODJetTracksAssociator)
              process.patLayer0.remove(process.patAODBTags)
              process.patLayer0.remove(process.patAODTagInfos)
    else:
        process.patLayer0.remove(process.patAODBTagging)
        process.patLayer0.remove(process.patLayer0BTagging)
        if layers.count(1) != 0:  process.allLayer1Jets.addBTagInfo = False
    if doJTA or doBTagging:
        if not doBTagging:
            process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            process.jetTracksAssociatorAtVertex = ic5JetTracksAssociatorAtVertex.clone(jets = cms.InputTag(jetCollection))
            process.patLayer0.replace(process.patBeforeLevel0Reco, process.jetTracksAssociatorAtVertex + process.patBeforeLevel0Reco)
            process.patAODJetTracksAssociator.src       = jetCollection
            process.patAODJetTracksAssociator.tracks    = 'jetTracksAssociatorAtVertex'
            if runCleaner == None:
                process.globalReplace('layer0JetTracksAssociator', process.patAODJetTracksAssociator.clone())
                process.layer0JetCharge.src       = jetCollection
                process.patLayer0.remove(process.patAODJetTracksAssociator)
    else: ## no JTA
        process.patHighLevelReco_withoutPFTau.remove(process.patLayer0JetTracksCharge)
        if layers.count(1) != 0:  
            process.allLayer1Jets.addAssociatedTracks = False
            process.allLayer1Jets.addJetCharge = False
    if jetCorrLabel != None:
        if jetCorrLabel == False : raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to None, not False"
        if jetCorrLabel == "None": raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to None (without quotes), not 'None'"
        if type(jetCorrLabel) != type(('IC5','Calo')): 
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be None, or a tuple ('Algo', 'Type')"
        if not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel ):
            setattr( process, 
                        'L2L3JetCorrector%s%s' % jetCorrLabel, 
                        cms.ESSource("JetCorrectionServiceChain",
                            correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                     'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                            label      = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                        )
                    )
        switchJECParameters(process.jetCorrFactors, jetCorrLabel[0], jetCorrLabel[1], oldalgo='IC5',oldtype='Calo')
        process.jetCorrFactors.jetSource = jetCollection
        if doType1MET:
            process.corMetType1Icone5.inputUncorJetsLabel = jetCollection
            process.corMetType1Icone5.corrector           = 'L2L3JetCorrector%s%s' % jetCorrLabel
        if runCleaner == None:
            process.globalReplace('layer0JetCorrFactors', process.jetCorrFactors.copy())
            process.patLayer0.remove(process.jetCorrFactors)
    else:
        process.patLayer0.remove(process.jetCorrFactors)
        process.patLayer0.remove(process.layer0JetCorrFactors)
        if layers.count(1) != 0:
            process.allLayer1Jets.addJetCorrFactors = False
    rParam   = cms.double(0.4),
    jetPtMin = cms.double(20)
    )

AK6caPFJetsPrunedCHS = ak5PFJetsPruned.clone(
    src      = cms.InputTag('PFBRECO','pfNoElectron'),
    jetAlgorithm = cms.string("CambridgeAachen"),
    rParam = cms.double(0.4),
    doAreaFastjet = cms.bool(False),
    writeCompound = cms.bool(True),
    jetCollInstanceName=cms.string("SubJets"),
    jetPtMin = cms.double(20)
    )

from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
AK6jetTracksAssociatorAtVertexCHS          = ic5JetTracksAssociatorAtVertex.clone()
AK6jetTracksAssociatorAtVertexCHS  .jets   = cms.InputTag('AK6PFJetsCHS')
AK6jetTracksAssociatorAtVertexCHS  .tracks = "generalTracks"

AK6jetTracksAssociatorAtVertexSJCHS        = ic5JetTracksAssociatorAtVertex.clone()
AK6jetTracksAssociatorAtVertexSJCHS.jets   = cms.InputTag('AK6caPFJetsPrunedCHS','SubJets')
AK6jetTracksAssociatorAtVertexSJCHS.tracks = "generalTracks"

from RecoBTag.Configuration.RecoBTag_cff import *
AK6jetImpactParameterTagInfosCHS                      = impactParameterTagInfos.clone()
AK6jetImpactParameterTagInfosCHS.jetTracks            = "AK6jetTracksAssociatorAtVertexCHS"
AK6jetSecondaryVertexTagInfosCHS                      = secondaryVertexTagInfos.clone()
AK6jetSecondaryVertexTagInfosCHS.trackIPTagInfos      = "AK6jetImpactParameterTagInfosCHS"
AK6jetCombinedSecondaryVertexBJetTagsCHS           = combinedSecondaryVertexBJetTags.clone()
AK6jetCombinedSecondaryVertexBJetTagsCHS.tagInfos = cms.VInputTag( cms.InputTag("AK6jetImpactParameterTagInfosCHS"), cms.InputTag("AK6jetSecondaryVertexTagInfosCHS") )
示例#16
0
def addJetCollection(process,
                     jetCollection,
                     postfixLabel,
                     doJTA        = True,
                     doBTagging   = True,
                     jetCorrLabel = None,
                     doType1MET   = True,
                     doL1Cleaning = True,
                     doL1Counters = False,                     
                     genJetCollection=cms.InputTag("iterativeCone5GenJets"),
                     doTrigMatch  = False
                     ):
    """
    ------------------------------------------------------------------        
    add a new collection of jets in PAT

    process          : process
    jetCollection    : input jet collection    
    postfixLabel     : label to identify all modules that work with
                       this jet collection
    doBTagging       : run b tagging sequence for new jet collection
                       and add it to the new pat jet collection
    doJTA            : run JetTracksAssociation and JetCharge and add
                       it to the new pat jet collection (will autom.
                       be true if doBTagging is set to true)
    jetCorrLabel     : algorithm and type of JEC; use 'None' for no
                       JEC; examples are ('IC5','Calo'), ('SC7',
                       'Calo'), ('KT4','PF')
    doType1MET       : make also a new MET collection (not yet
                       implemented?)
    doL1Cleaning     : copy also the producer modules for cleanLayer1
                       will be set to 'True' automatically when
                       doL1Counters is 'True'
    doL1Counters     : copy also the filter modules that accept/reject
                       the event looking at the number of jets                       
    doTrigMatch      :
    genJetCollection : GenJet collection to match to

    this takes the configuration from the already-configured jets as
    starting point; replaces before calling addJetCollection will
    affect also the new jets
    ------------------------------------------------------------------                     
    """
    ## add module as process to the default sequence
    def addAlso(label, value):
        existing = getattr(process, label)
        setattr( process, label+postfixLabel, value)
        process.patDefaultSequence.replace( existing, existing*value )

    ## clone and add a module as process to the
    ## default sequence
    def addClone(label, **replaceStatements):
        new = getattr(process, label).clone(**replaceStatements)
        addAlso(label, new)
        
    ## add a clone of allLayer1Jets
    addClone('allLayer1Jets', jetSource = jetCollection, addTrigMatch = doTrigMatch)
    ## add a clone of selectedLayer1Jets    
    addClone('selectedLayer1Jets', src=cms.InputTag('allLayer1Jets'+postfixLabel))
    ## add a clone of cleanLayer1Jets    
    if (doL1Cleaning or doL1Counters):
        addClone('cleanLayer1Jets', src=cms.InputTag('selectedLayer1Jets'+postfixLabel))
    ## add a clone of countLayer1Jets    
    if (doL1Counters):
        addClone('countLayer1Jets', src=cms.InputTag('cleanLayer1Jets'+postfixLabel))

    ## attributes of allLayer1Jets
    l1Jets = getattr(process, 'allLayer1Jets'+postfixLabel)

    ## add a clone of gen jet matching
    addClone('jetPartonMatch', src = jetCollection)
    addClone('jetGenJetMatch', src = jetCollection, matched = genJetCollection)
    ## add a clone of parton and flavour associations
    addClone('jetPartonAssociation', jets = jetCollection)
    addClone('jetFlavourAssociation', srcByReference = cms.InputTag('jetPartonAssociation'+postfixLabel))

    ## fix label for input tag
    def fixInputTag(x): x.setModuleLabel(x.moduleLabel+postfixLabel)
    ## fix label for vector of input tags
    def fixVInputTag(x): x[0].setModuleLabel(x[0].moduleLabel+postfixLabel)

    ## provide allLayer1Jet inputs with individual labels
    fixInputTag(l1Jets.genJetMatch)
    fixInputTag(l1Jets.genPartonMatch)
    fixInputTag(l1Jets.JetPartonMapSource)

    ## find potential triggers for trigMatch 
    triggers = MassSearchParamVisitor('src', process.allLayer1Jets.jetSource)
    process.patTrigMatch.visit(triggers)
    for mod in triggers.modules():
        if (doTrigMatch):
            newmod = mod.clone(src = jetCollection)
            setattr( process, mod.label()+postfixLabel, newmod )
            process.patTrigMatch.replace( mod, mod * newmod )
    for it in l1Jets.trigPrimMatch.value(): fixInputTag(it)

    ## make VInputTag from strings 
    def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
    
    if (doBTagging):
        ## add b tagging sequence
        (btagSeq, btagLabels) = runBTagging(process, jetCollection, postfixLabel)
        ## add b tagging sequence to the patAODCoreReco
        ## sequence as it is also needed by ExtraReco
        process.patAODCoreReco += btagSeq
        ## add clone of jet charge associator tag
        addClone('patJetCharge', src=cms.InputTag(btagLabels['jta']))
        ## replace corresponding tags for pat jet production
        l1Jets.trackAssociationSource = cms.InputTag(btagLabels['jta'])
        l1Jets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
        l1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
        ## provide allLayer1Jet jetChargeSource with individual label
        fixInputTag(l1Jets.jetChargeSource)
    else:
        ## switch general b tagging info switch off
        l1Jets.addBTagInfo = False
        
    if (doJTA or doBTagging):
        ## add clone of jet track association        
        if not doBTagging:
            ## in case b tagging is switched off do the 
            ## jet track association production here            
            process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
            from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
            ## add jet track association module to processes
            jtaLabel = 'jetTracksAssociatorAtVertex'+postfixLabel
            setattr( process, jtaLabel, ic5JetTracksAssociatorAtVertex.clone(jets = jetCollection) )
            process.patAODReco.replace(process.patJetTracksCharge, getattr(process,jtaLabel)+process.patJetTracksCharge)
            l1Jets.trackAssociationSource = cms.InputTag(jtaLabel)
            addClone('patJetCharge', src=cms.InputTag(jtaLabel)),
            fixInputTag(l1Jets.jetChargeSource)
    else:
        ## switch embedding of track association and jet
        ## charge estimate to 'False'        
        l1Jets.addAssociatedTracks = False
        l1Jets.addJetCharge = False
    if (jetCorrLabel != None):
        ## add clone of jet energy corrections;
        ## catch a couple of exceptions first
        if (jetCorrLabel == False ):
            raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
        if (jetCorrLabel == "None"):
            raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
        ## check for the correct format
        if type(jetCorrLabel) != type(('IC5','Calo')): 
            raise ValueError, "In switchJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"

        ## add clone of jetCorrFactors
        addClone('jetCorrFactors', jetSource = jetCollection)
        switchJECParameters( getattr(process,'jetCorrFactors'+postfixLabel), jetCorrLabel[0], jetCorrLabel[1], oldAlgo='IC5',oldType='Calo' )
        fixVInputTag(l1Jets.jetCorrFactorsSource)

        ## add a clone of the type1MET correction for the new jet collection
        if (doType1MET):
            ## in case there is no jet correction service in the paths add it
            ## as L2L3 if possible, as combined from L2 and L3 otherwise
            if not hasattr( process, 'L2L3JetCorrector%s%s' % jetCorrLabel ):
                setattr( process, 
                         'L2L3JetCorrector%s%s' % jetCorrLabel, 
                         cms.ESSource("JetCorrectionServiceChain",
                                      correctors = cms.vstring('L2RelativeJetCorrector%s%s' % jetCorrLabel,
                                                               'L3AbsoluteJetCorrector%s%s' % jetCorrLabel),
                                      label= cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                                      )
                         )
            ## add a clone of the type1MET correction
            ## and the following muonMET correction  
            addClone('corMetType1Icone5', inputUncorJetsLabel = jetCollection.value(),
                     corrector = cms.string('L2L3JetCorrector%s%s' % jetCorrLabel)
                     )
            addClone('corMetType1Icone5Muons', uncorMETInputTag = cms.InputTag("corMetType1Icone5"+postfixLabel))
            addClone('layer1METs', metSource = cms.InputTag("corMetType1Icone5Muons"+postfixLabel),
                     addTrigMatch = doTrigMatch
                     )
            l1MET = getattr(process, 'layer1METs'+postfixLabel)

            ## find potential triggers for trigMatch             
            mettriggers = MassSearchParamVisitor('src', process.layer1METs.metSource)
            process.patTrigMatch.visit(mettriggers)
            for mod in mettriggers.modules():
                if doTrigMatch:
                    newmod = mod.clone(src = l1MET.metSource)
                    setattr( process, mod.label()+postfixLabel, newmod )
                    process.patTrigMatch.replace( mod, mod * newmod )
            for it in l1MET.trigPrimMatch.value(): fixInputTag(it)

            ## add new met collections output to the pat summary
            process.allLayer1Summary.candidates += [ cms.InputTag('layer1METs'+postfixLabel) ]
    else:
        ## switch jetCorrFactors off
        l1Jets.addJetCorrFactors = False

    if (jetCollection not in process.aodSummary.candidates):
        ## add the new jet collection to the summary tables
        process.aodSummary.candidates += [ jetCollection ]
    ## add new allLayer1Jets collection output to the pat summary
    process.allLayer1Summary.candidates += [ cms.InputTag('allLayer1Jets'+postfixLabel) ]
    ## add new selectedLayer1Jets collection output to the pat summary
    process.selectedLayer1Summary.candidates += [ cms.InputTag('selectedLayer1Jets'+postfixLabel) ]
AK12PFJets = ak5PFJets.clone(
    rParam = cms.double(1.2),
    jetPtMin = cms.double(20)
    )

AK12caPFJetsPruned = ak5PFJetsPruned.clone(
    jetAlgorithm = cms.string("CambridgeAachen"),
    rParam = cms.double(1.2),
    doAreaFastjet = cms.bool(False),
    writeCompound = cms.bool(True),
    jetCollInstanceName=cms.string("SubJets"),
    jetPtMin = cms.double(20)
    )

from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
AK12jetTracksAssociatorAtVertex          = ic5JetTracksAssociatorAtVertex.clone()
AK12jetTracksAssociatorAtVertex  .jets   = cms.InputTag('AK12PFJets')
AK12jetTracksAssociatorAtVertex  .tracks = "generalTracks"

AK12jetTracksAssociatorAtVertexSJ        = ic5JetTracksAssociatorAtVertex.clone()
AK12jetTracksAssociatorAtVertexSJ.jets   = cms.InputTag('AK12caPFJetsPruned','SubJets')
AK12jetTracksAssociatorAtVertexSJ.tracks = "generalTracks"

from RecoBTag.Configuration.RecoBTag_cff import *
AK12jetImpactParameterTagInfos                      = impactParameterTagInfos.clone()
AK12jetImpactParameterTagInfos.jetTracks            = "AK12jetTracksAssociatorAtVertex"
AK12jetSecondaryVertexTagInfos                      = secondaryVertexTagInfos.clone()
AK12jetSecondaryVertexTagInfos.trackIPTagInfos      = "AK12jetImpactParameterTagInfos"
AK12jetCombinedSecondaryVertexBJetTags           = combinedSecondaryVertexBJetTags.clone()
AK12jetCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag( cms.InputTag("AK12jetImpactParameterTagInfos"), cms.InputTag("AK12jetSecondaryVertexTagInfos") )
示例#18
0
def runBTagging(process,jetCollection,label) :
    """Define a sequence to run BTagging on AOD on top of jet collection 'jetCollection', appending 'label' to module labels.
       The sequence will be called "btaggingAOD" + 'label', and will already be added to the process (but not to any Path)
       The sequence will include a JetTracksAssociatorAtVertex with name "jetTracksAssociatorAtVertex" + 'label'
       The method will return a pair (sequence, labels) where 'sequence' is the cms.Sequence object, and 'labels' contains
         labels["jta"]      = the name of the JetTrackAssociator module
         labels["tagInfos"] = list of names of TagInfo modules
         labels["jetTags "] = list of names of JetTag modules
       these labels are meant to be used for PAT BTagging tools
       NOTE: 'label' MUST NOT BE EMPTY
     """
    if (label == ''):
        raise ValueError, "Label for re-running BTagging can't be empty, it will crash CRAB." 
    process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
    process.load("RecoBTag.Configuration.RecoBTag_cff")
    from RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi import ic5JetTracksAssociatorAtVertex
    import RecoBTag.Configuration.RecoBTag_cff as btag
    
    # quickly make VInputTag from strings
    def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
    
    # define labels
    jtaLabel =  'jetTracksAssociatorAtVertex' + label
    ipTILabel = 'impactParameterTagInfos'     + label
    svTILabel = 'secondaryVertexTagInfos'     + label
    seTILabel = 'softElectronTagInfos'        + label
    smTILabel = 'softMuonTagInfos'            + label
    
    # make JTA and TagInfos
    setattr( process, jtaLabel,  ic5JetTracksAssociatorAtVertex.clone(jets = cms.InputTag(jetCollection)))
    setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
    setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
    setattr( process, seTILabel, btag.softElectronTagInfos.clone(jets = cms.InputTag(jetCollection)) )
    setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = cms.InputTag(jetCollection)) )
    setattr( process, 'jetBProbabilityBJetTags'+label, btag.jetBProbabilityBJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'jetProbabilityBJetTags' +label,  btag.jetProbabilityBJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'trackCountingHighPurBJetTags'+label, btag.trackCountingHighPurBJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'trackCountingHighEffBJetTags'+label, btag.trackCountingHighEffBJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'impactParameterMVABJetTags'+label, btag.impactParameterMVABJetTags.clone(tagInfos = vit(ipTILabel)) )
    setattr( process, 'simpleSecondaryVertexBJetTags'+label, btag.simpleSecondaryVertexBJetTags.clone(tagInfos = vit(svTILabel)) )
    setattr( process, 'combinedSecondaryVertexBJetTags'+label, btag.combinedSecondaryVertexBJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
    setattr( process, 'combinedSecondaryVertexMVABJetTags'+label, btag.combinedSecondaryVertexMVABJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
    setattr( process, 'softElectronBJetTags'+label, btag.softElectronBJetTags.clone(tagInfos = vit(seTILabel)) )
    setattr( process, 'softMuonBJetTags'+label, btag.softMuonBJetTags.clone(tagInfos = vit(smTILabel)) )
    setattr( process, 'softMuonNoIPBJetTags'+label, btag.softMuonNoIPBJetTags.clone(tagInfos = vit(smTILabel)) )
    
    def mkseq(process, firstlabel, *otherlabels):
       seq = getattr(process, firstlabel)
       for x in otherlabels: seq += getattr(process, x)
       return cms.Sequence(seq)
    
    labels = { 'jta' : jtaLabel, 
               'tagInfos' : (ipTILabel,svTILabel,seTILabel,smTILabel), 
               'jetTags'  : [ (x + label) for x in ('jetBProbabilityBJetTags',
                                                'jetProbabilityBJetTags',
                                                'trackCountingHighPurBJetTags',
                                                'trackCountingHighEffBJetTags',
                                                'impactParameterMVABJetTags',
                                                'simpleSecondaryVertexBJetTags',
                                                'combinedSecondaryVertexBJetTags',
                                                'combinedSecondaryVertexMVABJetTags',
                                                'softElectronBJetTags',
                                                'softMuonBJetTags',
                                                'softMuonNoIPBJetTags') ]
    }
    
    setattr( process, 'btaggingTagInfos' + label, mkseq(process, *(labels['tagInfos']) ) )
    setattr( process, 'btaggingJetTags' + label,  mkseq(process, *(labels['jetTags'])  ) )
    seq = mkseq(process, jtaLabel, 'btaggingTagInfos' + label, 'btaggingJetTags' + label) 
    setattr( process, 'btagging' + label, seq )
    return (seq, labels)