def add_tau_variables(process, sequence, pfjet_tag, patjet_tag, algo, taus):
	tag = "taus" + patjet_tag.replace("patJets", "")
	tau_calculator = Njettiness.clone(
		src=cms.InputTag(pfjet_tag),
		Njets=cms.vuint32(taus),
		# variables for measure definition: 
		measureDefinition = cms.uint32(0),    # CMS default is normalized measure
		beta=cms.double(1.0),                 # CMS default is 1
		R0=cms.double(algo.r),                # CMS default is jet cone size
		Rcutoff=cms.double(999.0),            # not used by default
		# variables for axes definition:
		axesDefinition=cms.uint32(6),         # CMS default is 1-pass KT axes
		nPass=cms.int32(999),                 # not used by default
		akAxesR0=cms.double(-999.0),          # not used by default
	)
	setattr(process, tag, tau_calculator)
	
	for tau in taus:
		getattr(process, patjet_tag).userData.userFloats.src += ['{}:tau{}'.format(tag, tau)]
	
	sequence += getattr(process, tag)
	return tag
Beispiel #2
0
        addTagInfos = True,
        addDiscriminators = True,
        addAssociatedTracks = True,
        addJetCharge = False,
        addJetID = False,
        getJetMCFlavour = False,
        addGenPartonMatch = False,
        addGenJetMatch = False,
        embedGenJetMatch = False,
        embedGenPartonMatch = False,
        # embedCaloTowers = False,
        # embedPFCandidates = True
        )

akPuFilter3PFNjettiness = Njettiness.clone(
		    src = cms.InputTag("akPuFilter3PFJets"),
           	    R0  = cms.double( 0.3)
)
akPuFilter3PFpatJetsWithBtagging.userData.userFloats.src += ['akPuFilter3PFNjettiness:tau1','akPuFilter3PFNjettiness:tau2','akPuFilter3PFNjettiness:tau3']

akPuFilter3PFJetAnalyzer = inclusiveJetAnalyzer.clone(jetTag = cms.InputTag("akPuFilter3PFpatJetsWithBtagging"),
                                                             genjetTag = 'ak3GenJets',
                                                             rParam = 0.3,
                                                             matchJets = cms.untracked.bool(False),
                                                             matchTag = 'patJetsWithBtagging',
                                                             pfCandidateLabel = cms.untracked.InputTag('particleFlow'),
                                                             trackTag = cms.InputTag("generalTracks"),
                                                             fillGenJets = False,
                                                             isMC = False,
							     doSubEvent = False,
                                                             useHepMC = cms.untracked.bool(False),
							     genParticles = cms.untracked.InputTag("genParticles"),
Beispiel #3
0
        addTagInfos = True,
        addDiscriminators = True,
        addAssociatedTracks = True,
        addJetCharge = False,
        addJetID = False,
        getJetMCFlavour = True,
        addGenPartonMatch = True,
        addGenJetMatch = True,
        embedGenJetMatch = True,
        embedGenPartonMatch = True,
        # embedCaloTowers = False,
        # embedPFCandidates = True
        )

akPuFilter5CaloNjettiness = Njettiness.clone(
		    src = cms.InputTag("akPuFilter5CaloJets"),
           	    R0  = cms.double( 0.5)
)
akPuFilter5CalopatJetsWithBtagging.userData.userFloats.src += ['akPuFilter5CaloNjettiness:tau1','akPuFilter5CaloNjettiness:tau2','akPuFilter5CaloNjettiness:tau3']

akPuFilter5CaloJetAnalyzer = inclusiveJetAnalyzer.clone(jetTag = cms.InputTag("akPuFilter5CalopatJetsWithBtagging"),
                                                             genjetTag = 'ak5HiGenJets',
                                                             rParam = 0.5,
                                                             matchJets = cms.untracked.bool(False),
                                                             matchTag = 'patJetsWithBtagging',
                                                             pfCandidateLabel = cms.untracked.InputTag('particleFlowTmp'),
                                                             trackTag = cms.InputTag("hiGeneralTracks"),
                                                             fillGenJets = True,
                                                             isMC = True,
							     doSubEvent = True,
                                                             useHepMC = cms.untracked.bool(False),
							     genParticles = cms.untracked.InputTag("genParticles"),
        addTagInfos = True,
        addDiscriminators = True,
        addAssociatedTracks = True,
        addJetCharge = False,
        addJetID = False,
        getJetMCFlavour = True,
        addGenPartonMatch = True,
        addGenJetMatch = True,
        embedGenJetMatch = True,
        embedGenPartonMatch = True,
        # embedCaloTowers = False,
        # embedPFCandidates = True
        )

akCsSoftDrop2PFNjettiness = Njettiness.clone(
		    src = cms.InputTag("akCsSoftDrop2PFJets"),
           	    R0  = cms.double( 0.2)
)
akCsSoftDrop2PFpatJetsWithBtagging.userData.userFloats.src += ['akCsSoftDrop2PFNjettiness:tau1','akCsSoftDrop2PFNjettiness:tau2','akCsSoftDrop2PFNjettiness:tau3']

akCsSoftDrop2PFJetAnalyzer = inclusiveJetAnalyzer.clone(jetTag = cms.InputTag("akCsSoftDrop2PFpatJetsWithBtagging"),
                                                             genjetTag = 'ak2HiGenJets',
                                                             rParam = 0.2,
                                                             matchJets = cms.untracked.bool(False),
                                                             matchTag = 'patJetsWithBtagging',
                                                             pfCandidateLabel = cms.untracked.InputTag('particleFlowTmp'),
                                                             trackTag = cms.InputTag("hiGeneralTracks"),
                                                             fillGenJets = True,
                                                             isMC = True,
							     doSubEvent = True,
                                                             useHepMC = cms.untracked.bool(False),
							     genParticles = cms.untracked.InputTag("genParticles"),
from RecoJets.JetProducers.QGTagger_cfi import *
AK8QGTaggerCHS           = QGTagger.clone()
AK8QGTaggerCHS.srcJets   = cms.InputTag('AK8PFJetsCHS')
AK8QGTaggerCHS.jetsLabel = cms.string('QGL_AK4PFchs')
AK8QGTaggerCHS.jec       = cms.InputTag("ak8PFCHSL1FastL2L3Corrector") # NOTE: use "ak8PFCHSL1FastL2L3Corrector" for MC / "ak8PFCHSL1FastL2L3ResidualCorrector" for Data

AK8QGTaggerSubJetsCHS           = AK8QGTaggerCHS.clone()
AK8QGTaggerSubJetsCHS.srcJets   = cms.InputTag('AK8caPFJetsSoftDropCHS','SubJets')
AK8QGTaggerSubJetsCHS.jetsLabel = cms.string('QGL_AK4PFchs')
AK8QGTaggerSubJetsCHS.jec       = cms.InputTag("ak8PFCHSL1FastL2L3Corrector") # NOTE: use "ak8PFCHSL1FastL2L3Corrector" for MC / "ak8PFCHSL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
AK8NjettinessCHS = Njettiness.clone(
    src   = cms.InputTag('AK8PFJetsCHS'),
    cone  = cms.double(0.8),
    Njets = cms.vuint32(1,2,3,4)
  )

#
# Define sequences
#
AK8genjetsequenceCHS = cms.Sequence(
  AK8GenJetsCHS*
  AK8FlavorCHS
)

AK8jetsequenceCHS = cms.Sequence(
    AK8PFJetsCHS*
    AK8caPFJetsPrunedCHS*
    AK8caPFJetsTrimmedCHS*
Beispiel #6
0
add_fatjets_subjets(process, 'ca15PuppiJets', 'hepTopTagPuppi')
#add_fatjets_subjets(process, 'ca8PuppiJets', 'ca8PuppiJetsSoftDrop')

# configure PAT for miniAOD:
#process.patJetPartons.particles = 'prunedGenParticles'

from PhysicsTools.PatAlgos.tools.pfTools import *
## Adapt primary vertex collection
adaptPVs(process, pvCollection = cms.InputTag('offlineSlimmedPrimaryVertices'))


# Add subjet variables (on ungroomed jets only!)
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder

process.NjettinessAk8CHS = Njettiness.clone(src = cms.InputTag("ak8CHSJets"), cone = cms.double(0.8))
process.NjettinessCa15CHS = Njettiness.clone(src = cms.InputTag("ca15CHSJets"), cone = cms.double(1.5),R0 = cms.double(1.5))
process.NjettinessCa15SoftDropCHS = Njettiness.clone(
                                                 src = cms.InputTag("ca15CHSJetsSoftDropforsub"),
                                                 Njets=cms.vuint32(1,2,3),          # compute 1-, 2-, 3- subjettiness
                                                 # variables for measure definition : 
                                                 measureDefinition = cms.uint32( 0 ), # CMS default is normalized measure
                                                 beta = cms.double(1.0),              # CMS default is 1
                                                 R0 = cms.double(1.5),                  # CMS default is jet cone size
                                                 Rcutoff = cms.double( -999.0),       # not used by default
                                                 # variables for axes definition :
                                                 axesDefinition = cms.uint32( 6 ),    # CMS default is 1-pass KT axes
                                                 nPass = cms.int32(-999),             # not used by default
                                                 akAxesR0 = cms.double(-999.0)        # not used by default
                                                 )
process.NjettinessCa15SoftDropPuppi = process.NjettinessCa15SoftDropCHS.clone(src = cms.InputTag("ca15PuppiJetsSoftDropforsub"))
CA8QGTaggerCHS.jetsLabel = cms.string("QGL_AK4PFchs")
CA8QGTaggerCHS.jec = cms.InputTag(
    "ca8PFCHSL1FastL2L3Corrector"
)  # NOTE: use "ca8PFCHSL1FastL2L3Corrector" for MC / "ca8PFCHSL1FastL2L3ResidualCorrector" for Data

CA8QGTaggerSubJetsCHS = CA8QGTaggerCHS.clone()
CA8QGTaggerSubJetsCHS.srcJets = cms.InputTag("CA8caPFJetsSoftDropCHS", "SubJets")
CA8QGTaggerSubJetsCHS.jetsLabel = cms.string("QGL_AK4PFchs")
CA8QGTaggerSubJetsCHS.jec = cms.InputTag(
    "ca8PFCHSL1FastL2L3Corrector"
)  # NOTE: use "ca8PFCHSL1FastL2L3Corrector" for MC / "ca8PFCHSL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

CA8NjettinessCHS = Njettiness.clone(src=cms.InputTag("CA8PFJetsCHS"), R0=cms.double(0.8), Njets=cms.vuint32(1, 2, 3, 4))

#
# Define sequences
#
CA8genjetsequenceCHS = cms.Sequence(
    CA8GenJetsCHS
    # CA8FlavorCHS
)

CA8jetsequenceCHS = cms.Sequence(
    CA8PFJetsCHS
    * CA8caPFJetsPrunedCHS
    * CA8caPFJetsTrimmedCHS
    * CA8caPFJetsSoftDropCHS
    * ca8PFCHSL1FastL2L3CorrectorChain
def applySubstructure( process, postfix="" ) :

    from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection


    from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import _patJets as patJetsDefault

    #add AK8
    addJetCollection(process, postfix=postfix, labelName = 'AK8',
                     jetSource = cms.InputTag('ak8PFJetsCHS'+postfix),
                     algo= 'AK', rParam = 0.8,
                     jetCorrections = ('AK8PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None'),
                     btagDiscriminators = ([x.getModuleLabel() for x in patJetsDefault.discriminatorSources] + ['pfBoostedDoubleSecondaryVertexAK8BJetTags']),
                     genJetCollection = cms.InputTag('slimmedGenJetsAK8')
                     )
    getattr(process, "patJetsAK8"+postfix).userData.userFloats.src = [] # start with empty list of user floats
    getattr(process,"selectedPatJetsAK8"+postfix).cut = cms.string("pt > 170")

    from RecoJets.JetProducers.ak8PFJetsPuppi_cfi import ak8PFJetsPuppi
    #process.load('RecoJets.JetProducers.ak8PFJetsPuppi_cfi')
    setattr(process, "ak8PFJetsPuppi"+postfix, ak8PFJetsPuppi.clone(
            doAreaFastjet=True)  # even for standard ak8PFJets this is overwritten in RecoJets/Configuration/python/RecoPFJets_cff
            )

    from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
    setattr(process,"ak8PFJetsPuppiTracksAssociatorAtVertex"+postfix, 
            cms.EDProducer("JetTracksAssociatorAtVertex",
                           j2tParametersVX,
                           jets = cms.InputTag("ak8PFJetsPuppi"+postfix)
                           ) 
            )
    setattr(process, "patJetPuppiCharge"+postfix, 
            cms.EDProducer("JetChargeProducer",
                           src = cms.InputTag("ak8PFJetsPuppiTracksAssociatorAtVertex"+postfix),
                           var = cms.string('Pt'),
                           exp = cms.double(1.0)
                           ) 
            )

    ## AK8 groomed masses
    from RecoJets.Configuration.RecoPFJets_cff import ak8PFJetsCHSPruned, ak8PFJetsCHSSoftDrop, ak8PFJetsPuppiSoftDrop 
    setattr(process, "ak8PFJetsCHSPruned"+postfix, ak8PFJetsCHSPruned.clone(
            src = cms.InputTag("pfNoPileUpJME"+postfix),
            ) )
    setattr(process, "ak8PFJetsCHSSoftDrop"+postfix, ak8PFJetsCHSSoftDrop.clone(
            src = cms.InputTag("pfNoPileUpJME"+postfix),
            ) )
    from RecoJets.JetProducers.ak8PFJetsCHS_groomingValueMaps_cfi import ak8PFJetsCHSPrunedMass, ak8PFJetsCHSSoftDropMass
    setattr(process, "ak8PFJetsCHSPrunedMass"+postfix, ak8PFJetsCHSPrunedMass.clone(
            src = cms.InputTag("ak8PFJetsCHS"+postfix),
            matched = cms.InputTag("ak8PFJetsCHSPruned"+postfix),
            ) )
    setattr(process, "ak8PFJetsCHSSoftDropMass"+postfix, ak8PFJetsCHSSoftDropMass.clone(
            src = cms.InputTag("ak8PFJetsCHS"+postfix),
            matched = cms.InputTag("ak8PFJetsCHSSoftDrop"+postfix), 
            ) )

    getattr(process, "patJetsAK8"+postfix).userData.userFloats.src += ['ak8PFJetsCHSPrunedMass'+postfix,'ak8PFJetsCHSSoftDropMass'+postfix] 
    getattr(process, "patJetsAK8"+postfix).addTagInfos = cms.bool(False)


    # add Njetiness
    from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
    #process.load('RecoJets.JetProducers.nJettinessAdder_cfi')
    setattr(process,"NjettinessAK8"+postfix, Njettiness.clone(
            src = cms.InputTag("ak8PFJetsCHS"+postfix),
            cone = cms.double(0.8) )
            )
    getattr(process, "patJetsAK8"+postfix).userData.userFloats.src += ['NjettinessAK8'+postfix+':tau1','NjettinessAK8'+postfix+':tau2','NjettinessAK8'+postfix+':tau3']




    #add AK8 from PUPPI
    #MM no need for that, already done on L23
    #process.load('RecoJets.JetProducers.ak8PFJetsPuppi_cfi')
    #from RecoJets.JetProducers.ak8PFJetsPuppi_cfi import ak8PFJetsPuppi
    #getattr(process, "ak8PFJetsPuppi".doAreaFastjet = True # even for standard ak8PFJets this is overwritten in RecoJets/Configuration/python/RecoPFJets_cff

        
    addJetCollection(process, postfix=postfix,labelName = 'AK8Puppi',
                     jetSource = cms.InputTag('ak8PFJetsPuppi'+postfix),
                     algo= 'AK', rParam = 0.8,
                     jetCorrections = ('AK8PFPuppi', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None'),
                     genJetCollection = cms.InputTag('slimmedGenJetsAK8')
                     )
    getattr(process,"patJetsAK8Puppi"+postfix).userData.userFloats.src = [] # start with empty list of user floats
    getattr(process,"selectedPatJetsAK8Puppi"+postfix).cut = cms.string("pt > 170")


    from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
    setattr(process,"ak8PFJetsPuppiTracksAssociatorAtVertex"+postfix,
            cms.EDProducer("JetTracksAssociatorAtVertex",
                           j2tParametersVX,
                           jets = cms.InputTag("ak8PFJetsPuppi"+postfix) )
            )
    setattr(process,"patJetAK8PuppiCharge"+postfix,
            cms.EDProducer("JetChargeProducer",
                           src = cms.InputTag("ak8PFJetsPuppiTracksAssociatorAtVertex"+postfix),
                           var = cms.string('Pt'),
                           exp = cms.double(1.0) )
            )

    ## AK8 groomed masses
    from RecoJets.Configuration.RecoPFJets_cff import ak8PFJetsPuppiSoftDrop
    setattr(process,"ak8PFJetsPuppiSoftDrop"+postfix, ak8PFJetsPuppiSoftDrop.clone(
            src = cms.InputTag("puppi"+postfix),
            ) )
    from RecoJets.JetProducers.ak8PFJetsPuppi_groomingValueMaps_cfi import ak8PFJetsPuppiSoftDropMass
    setattr(process, "ak8PFJetsPuppiSoftDropMass"+postfix, ak8PFJetsPuppiSoftDropMass.clone(
            src = cms.InputTag("ak8PFJetsPuppi"+postfix),
            matched = cms.InputTag("ak8PFJetsPuppiSoftDrop"+postfix), 
            ) )
    getattr(process,"patJetsAK8Puppi"+postfix).userData.userFloats.src += ['ak8PFJetsPuppiSoftDropMass'+postfix]
    getattr(process,"patJetsAK8Puppi"+postfix).addTagInfos = cms.bool(False)



    # add Njetiness
    setattr(process,"NjettinessAK8Puppi"+postfix, Njettiness.clone(
            src = cms.InputTag("ak8PFJetsPuppi"+postfix),
            cone = cms.double(0.8) )
            )
    getattr(process,"patJetsAK8Puppi"+postfix).userData.userFloats.src += ['NjettinessAK8Puppi'+postfix+':tau1',
                                                                           'NjettinessAK8Puppi'+postfix+':tau2',
                                                                           'NjettinessAK8Puppi'+postfix+':tau3']

    setattr(process,"ak8PFJetsPuppiValueMap"+postfix, 
            cms.EDProducer("RecoJetToPatJetDeltaRValueMapProducer",
                           src = cms.InputTag("ak8PFJetsCHS"+postfix),
                           matched = cms.InputTag("patJetsAK8Puppi"+postfix),                                         
                           distMax = cms.double(0.8),
                           values = cms.vstring([
                    'userFloat("NjettinessAK8Puppi'+postfix+':tau1")',
                    'userFloat("NjettinessAK8Puppi'+postfix+':tau2")',
                    'userFloat("NjettinessAK8Puppi'+postfix+':tau3")',
                    'pt','eta','phi','mass'
                    ]),
                           valueLabels = cms.vstring( [
                    'NjettinessAK8PuppiTau1',
                    'NjettinessAK8PuppiTau2',
                    'NjettinessAK8PuppiTau3',
                    'pt','eta','phi','mass'
                    ])
                           )
            )
    #process.patJetsAK8.userData.userFloats.src += ['NjettinessAK8:tau1','NjettinessAK8:tau2','NjettinessAK8:tau3']

    getattr(process,"patJetsAK8"+postfix).userData.userFloats.src += [cms.InputTag('ak8PFJetsPuppiValueMap'+postfix,'NjettinessAK8PuppiTau1'),
                                                                      cms.InputTag('ak8PFJetsPuppiValueMap'+postfix,'NjettinessAK8PuppiTau2'),
                                                                      cms.InputTag('ak8PFJetsPuppiValueMap'+postfix,'NjettinessAK8PuppiTau3'),
                                                                      cms.InputTag('ak8PFJetsPuppiValueMap'+postfix,'pt'),
                                                                      cms.InputTag('ak8PFJetsPuppiValueMap'+postfix,'eta'),
                                                                      cms.InputTag('ak8PFJetsPuppiValueMap'+postfix,'phi'),
                                                                      cms.InputTag('ak8PFJetsPuppiValueMap'+postfix,'mass'),
                                                                      ]
    
    
    ## PATify pruned fat jets
    addJetCollection(
        process, postfix=postfix,
        labelName = 'AK8PFCHSSoftDrop',
        jetSource = cms.InputTag('ak8PFJetsCHSSoftDrop'+postfix),
        btagDiscriminators = ['None'],
        jetCorrections = ('AK8PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute'], 'None'),
        getJetMCFlavour = False # jet flavor disabled
    )
    
    ## PATify soft drop subjets
    addJetCollection(
        process, postfix=postfix,
        labelName = 'AK8PFCHSSoftDropSubjets',
        jetSource = cms.InputTag('ak8PFJetsCHSSoftDrop'+postfix,'SubJets'),
        algo = 'ak',  # needed for subjet flavor clustering
        rParam = 0.8, # needed for subjet flavor clustering
        btagDiscriminators = ['pfCombinedSecondaryVertexV2BJetTags', 'pfCombinedInclusiveSecondaryVertexV2BJetTags'],
        jetCorrections = ('AK4PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute'], 'None'),
        explicitJTA = True,  # needed for subjet b tagging
        svClustering = True, # needed for subjet b tagging
        genJetCollection = cms.InputTag('slimmedGenJets'), 
        fatJets=cms.InputTag('ak8PFJetsCHS'+postfix),             # needed for subjet flavor clustering
        groomedFatJets=cms.InputTag('ak8PFJetsCHSSoftDrop'+postfix) # needed for subjet flavor clustering
    )
    getattr(process,"selectedPatJetsAK8PFCHSSoftDrop"+postfix).cut = cms.string("pt > 170")
    
    setattr(process,"slimmedJetsAK8PFCHSSoftDropSubjets"+postfix,
            cms.EDProducer("PATJetSlimmer",
                           src = cms.InputTag("selectedPatJetsAK8PFCHSSoftDropSubjets"+postfix),
                           packedPFCandidates = cms.InputTag("packedPFCandidates"+postfix),
                           dropJetVars = cms.string("1"),
                           dropDaughters = cms.string("0"),
                           rekeyDaughters = cms.string("1"),
                           dropTrackRefs = cms.string("1"),
                           dropSpecific = cms.string("1"),
                           dropTagInfos = cms.string("1"),
                           modifyJets = cms.bool(True),
                           mixedDaughters = cms.bool(False),
                           modifierConfig = cms.PSet( modifications = cms.VPSet() )
                           )
            )

    
    ## Establish references between PATified fat jets and subjets using the BoostedJetMerger
    setattr(process,"slimmedJetsAK8PFCHSSoftDropPacked"+postfix, 
            cms.EDProducer("BoostedJetMerger",
                           jetSrc=cms.InputTag("selectedPatJetsAK8PFCHSSoftDrop"+postfix),
                           subjetSrc=cms.InputTag("slimmedJetsAK8PFCHSSoftDropSubjets"+postfix) 
                           )
            )
    
    

    ## PATify pruned fat jets
    addJetCollection(
        process, postfix=postfix,
        labelName = 'AK8PFPuppiSoftDrop',
        jetSource = cms.InputTag('ak8PFJetsPuppiSoftDrop'+postfix),
        btagDiscriminators = ['None'],
        jetCorrections = ('AK8PFPuppi', ['L1FastJet', 'L2Relative', 'L3Absolute'], 'None'),
        getJetMCFlavour = False # jet flavor disabled
    )
    
    ## PATify soft drop subjets
    addJetCollection(
        process, postfix=postfix,
        labelName = 'AK8PFPuppiSoftDropSubjets',
        jetSource = cms.InputTag('ak8PFJetsPuppiSoftDrop'+postfix,'SubJets'),
        algo = 'ak',  # needed for subjet flavor clustering
        rParam = 0.8, # needed for subjet flavor clustering
        btagDiscriminators = ['pfCombinedSecondaryVertexV2BJetTags', 'pfCombinedInclusiveSecondaryVertexV2BJetTags'],
        jetCorrections = ('AK4PFPuppi', ['L1FastJet', 'L2Relative', 'L3Absolute'], 'None'),
        explicitJTA = True,  # needed for subjet b tagging
        svClustering = True, # needed for subjet b tagging
        genJetCollection = cms.InputTag('slimmedGenJets'), 
        fatJets=cms.InputTag('ak8PFJetsPuppi'+postfix),             # needed for subjet flavor clustering
        groomedFatJets=cms.InputTag('ak8PFJetsPuppiSoftDrop'+postfix) # needed for subjet flavor clustering
    )
    getattr(process,"selectedPatJetsAK8PFPuppiSoftDrop"+postfix).cut = cms.string("pt > 170")
    
    setattr(process,"slimmedJetsAK8PFPuppiSoftDropSubjets"+postfix,
            cms.EDProducer("PATJetSlimmer",
        src = cms.InputTag("selectedPatJetsAK8PFPuppiSoftDropSubjets"+postfix),
        packedPFCandidates = cms.InputTag("packedPFCandidates"+postfix),
        dropJetVars = cms.string("1"),
        dropDaughters = cms.string("0"),
        rekeyDaughters = cms.string("1"),
        dropTrackRefs = cms.string("1"),
        dropSpecific = cms.string("1"),
        dropTagInfos = cms.string("1"),
        modifyJets = cms.bool(True),
        mixedDaughters = cms.bool(False),
        modifierConfig = cms.PSet( modifications = cms.VPSet() )
    ) )

    
    ## Establish references between PATified fat jets and subjets using the BoostedJetMerger
    setattr(process,"slimmedJetsAK8PFPuppiSoftDropPacked"+postfix,
            cms.EDProducer("BoostedJetMerger",
        jetSrc=cms.InputTag("selectedPatJetsAK8PFPuppiSoftDrop"+postfix),
        subjetSrc=cms.InputTag("slimmedJetsAK8PFPuppiSoftDropSubjets"+postfix)
    ) )

    
    setattr(process,"packedPatJetsAK8"+postfix,
            cms.EDProducer("JetSubstructurePacker",
            jetSrc = cms.InputTag("selectedPatJetsAK8"+postfix),
            distMax = cms.double(0.8),
            algoTags = cms.VInputTag(
                # NOTE: For an optimal storage of the AK8 jet daughters, the first subjet collection listed here should be
                #       derived from AK8 jets, i.e., subjets should contain either all or a subset of AK8 constituents.
                #       The PUPPI collection has its own pointers to its own PUPPI constituents. 
                cms.InputTag("slimmedJetsAK8PFCHSSoftDropPacked"+postfix),
                cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked"+postfix)
            ),
            algoLabels = cms.vstring(
                'SoftDrop',
                'SoftDropPuppi'
                ),
            fixDaughters = cms.bool(True),
            packedPFCandidates = cms.InputTag("packedPFCandidates"+postfix), #oldPFCandToPackedOrDiscarded #"packedPFCandidates"+postfix
    ) )


    #if the slimmedJet collection is not here, produce it
    if not hasattr(process, "slimmedJetsAK8"+postfix):
        from PhysicsTools.PatAlgos.slimming.slimmedJets_cfi import slimmedJetsAK8
        setattr(process, "slimmedJetsAK8"+postfix, slimmedJetsAK8.clone(
                src = cms.InputTag("packedPatJetsAK8"+postfix),
                packedPFCandidates = cms.InputTag("packedPFCandidates"), #MM FIXME
                ) )

    # switch off daughter re-keying since it's done in the JetSubstructurePacker (and can't be done afterwards)
    getattr(process,"slimmedJetsAK8"+postfix).rekeyDaughters = "0"
Beispiel #9
0
        addTagInfos = True,
        addDiscriminators = True,
        addAssociatedTracks = True,
        addJetCharge = False,
        addJetID = False,
        getJetMCFlavour = False,
        addGenPartonMatch = False,
        addGenJetMatch = False,
        embedGenJetMatch = False,
        embedGenPartonMatch = False,
        # embedCaloTowers = False,
        # embedPFCandidates = True
        )

akVsFilter2PFNjettiness = Njettiness.clone(
		    src = cms.InputTag("akVsFilter2PFJets"),
           	    R0  = cms.double( 0.2)
)
akVsFilter2PFpatJetsWithBtagging.userData.userFloats.src += ['akVsFilter2PFNjettiness:tau1','akVsFilter2PFNjettiness:tau2','akVsFilter2PFNjettiness:tau3']

akVsFilter2PFJetAnalyzer = inclusiveJetAnalyzer.clone(jetTag = cms.InputTag("akVsFilter2PFpatJetsWithBtagging"),
                                                             genjetTag = 'ak2GenJets',
                                                             rParam = 0.2,
                                                             matchJets = cms.untracked.bool(False),
                                                             matchTag = 'patJetsWithBtagging',
                                                             pfCandidateLabel = cms.untracked.InputTag('particleFlow'),
                                                             trackTag = cms.InputTag("generalTracks"),
                                                             fillGenJets = False,
                                                             isMC = False,
							     doSubEvent = False,
                                                             useHepMC = cms.untracked.bool(False),
							     genParticles = cms.untracked.InputTag("genParticles"),
Beispiel #10
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akVs2CaloNjettiness = Njettiness.clone(src=cms.InputTag("akVs2CaloJets"),
                                       R0=cms.double(0.2))
akVs2CalopatJetsWithBtagging.userData.userFloats.src += [
    'akVs2CaloNjettiness:tau1', 'akVs2CaloNjettiness:tau2',
    'akVs2CaloNjettiness:tau3'
]

akVs2CaloJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akVs2CalopatJetsWithBtagging"),
    genjetTag='ak2GenJets',
    rParam=0.2,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlow'),
    trackTag=cms.InputTag("generalTracks"),
    fillGenJets=True,
    isMC=True,
AK4QGTaggerCHS.jec = cms.InputTag(
    "ak4PFCHSL1FastL2L3Corrector"
)  # NOTE: use "ak4PFCHSL1FastL2L3Corrector" for MC / "ak4PFCHSL1FastL2L3ResidualCorrector" for Data

AK4QGTaggerSubJetsCHS = AK4QGTaggerCHS.clone()
AK4QGTaggerSubJetsCHS.srcJets = cms.InputTag('AK4caPFJetsSoftDropCHS',
                                             'SubJets')
AK4QGTaggerSubJetsCHS.jetsLabel = cms.string('QGL_AK4PFchs')
AK4QGTaggerSubJetsCHS.jec = cms.InputTag(
    "ak4PFCHSL1FastL2L3Corrector"
)  # NOTE: use "ak4PFCHSL1FastL2L3Corrector" for MC / "ak4PFCHSL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
AK4NjettinessCHS = Njettiness.clone(src=cms.InputTag('ak4PFJetsCHS'),
                                    cone=cms.double(0.4),
                                    Njets=cms.vuint32(1, 2, 3, 4))

from RecoJets.JetProducers.PileupJetID_cfi import *
AK4PUJetIdCHS = pileupJetId.clone(
    jets=cms.InputTag('ak4PFJetsCHS'),
    inputIsCorrected=False,
    applyJec=True,
    vertexes=cms.InputTag("offlinePrimaryVertices"))
#
# Define sequences
#
AK4genjetsequenceCHS = cms.Sequence(AK4GenJetsCHS
                                    #AK4FlavorCHS
                                    )
def makeFatJets(process, isData, pfCandidates, algoLabel, jetRadius):

    isMC = not isData
    postfix = 'PFlow'
    if pfCandidates == 'particleFlow':
        # mini aod needs a different config
        pfCandidates = 'pfCHS'

    if pfCandidates == 'pfCHS':
        puMethod = 'CHS'
    else:
        puMethod = 'Puppi'

    rLabel = algoLabel + str(int(jetRadius * 10))
    neroLabel = rLabel + puMethod

    if algoLabel == 'CA':
        jetAlgo = 'CambridgeAachen'
    else:
        jetAlgo = 'AntiKt'

    if jetRadius < 1:
        sdZcut = 0.1
        sdBeta = 0.0
    else:
        sdZcut = 0.2
        sdBeta = 1.0

    setattr(process, neroLabel + 'Sequence', cms.Sequence())
    newSeq = getattr(process, neroLabel + 'Sequence')

    ## Various collection names
    genParticles = 'prunedGenParticles'
    pvSource = 'offlineSlimmedPrimaryVertices'
    svSource = 'slimmedSecondaryVertices'
    muSource = 'slimmedMuons'
    elSource = 'slimmedElectrons'
    bTagInfos = [
        'pfImpactParameterTagInfos', 'pfSecondaryVertexTagInfos',
        'pfInclusiveSecondaryVertexFinderTagInfos', 'softPFMuonsTagInfos',
        'softPFElectronsTagInfos'
    ]
    ## b-tag discriminators
    bTagDiscriminators = [
        'pfCombinedSecondaryVertexV2BJetTags',
        'pfCombinedInclusiveSecondaryVertexV2BJetTags'
    ]

    bTagInfosSubjets = [
        'pfImpactParameterTagInfos', 'pfSecondaryVertexTagInfos',
        'pfInclusiveSecondaryVertexFinderTagInfos', 'softPFMuonsTagInfos',
        'softPFElectronsTagInfos'
    ]
    ## b-tag discriminators
    bTagDiscriminatorsSubjets = [
        'pfCombinedSecondaryVertexV2BJetTags',
        'pfCombinedInclusiveSecondaryVertexV2BJetTags'
    ]

    bTagInfosSubjets = ['None']
    bTagDiscriminatorsSubjets = ['None']

    ### jet clustering ###
    ########################################
    ##           REMAKE JETS              ##
    ########################################

    addingGenJets = False

    if not (hasattr(process, "genJetsNoNu" + rLabel)) and isMC:
        addingGenJets = True
        setattr(
            process, "genJetsNoNu" + rLabel,
            ak4GenJets.clone(
                jetAlgorithm=cms.string(jetAlgo),
                rParam=cms.double(jetRadius),
                src=cms.InputTag("packedGenParticlesForJetsNoNu")))
    setattr(
        process, "PFJets" + neroLabel,
        ak4PFJets.clone(jetAlgorithm=cms.string(jetAlgo),
                        rParam=cms.double(jetRadius),
                        src=cms.InputTag(pfCandidates),
                        srcPVs=cms.InputTag(pvSource),
                        doAreaFastjet=cms.bool(True),
                        jetPtMin=cms.double(150)))
    if not (hasattr(process, "genJetsNoNuSoftDrop" + rLabel)) and isMC:
        addingGenJets = True
        setattr(
            process, "genJetsNoNuSoftDrop" + rLabel,
            getattr(process, 'genJetsNoNu' + rLabel).clone(
                R0=cms.double(jetRadius),
                useSoftDrop=cms.bool(True),
                zcut=cms.double(sdZcut),
                beta=cms.double(sdBeta),
                writeCompound=cms.bool(True),
                jetCollInstanceName=cms.string("SubJets")))
    setattr(
        process, "PFJets" + "SoftDrop" + neroLabel,
        getattr(process, 'PFJets' + neroLabel).clone(
            useSoftDrop=cms.bool(True),
            R0=cms.double(jetRadius),
            zcut=cms.double(sdZcut),
            beta=cms.double(sdBeta),
            writeCompound=cms.bool(True),
            useExplicitGhosts=cms.bool(True),
            jetCollInstanceName=cms.string("SubJets"),
            jetPtMin=cms.double(150)))
    process.dump = cms.EDAnalyzer("EventContentAnalyzer")
    if addingGenJets and not (isData):
        print 'addingGenJets', 'genJetsNoNu' + rLabel
        newSeq += getattr(process, 'genJetsNoNu' + rLabel)
        newSeq += getattr(process, 'genJetsNoNuSoftDrop' + rLabel)
    newSeq += getattr(process, 'PFJets' + neroLabel)
    newSeq += getattr(process, 'PFJets' + "SoftDrop" + neroLabel)

    ########################################
    ##           SUBSTRUCTURE             ##
    #######################################

    setattr(
        process, neroLabel + 'Njettiness',
        Njettiness.clone(src=cms.InputTag('PFJets' + neroLabel),
                         R0=cms.double(jetRadius),
                         Njets=cms.vuint32(1, 2, 3, 4)))

    setattr(
        process, neroLabel + 'SDKinematics',
        cms.EDProducer(
            'RecoJetDeltaRValueMapProducer',
            src=cms.InputTag('PFJets' + neroLabel),
            matched=cms.InputTag('PFJets' + "SoftDrop" + neroLabel),
            distMax=cms.double(1.5),
            values=cms.vstring('mass'),
            valueLabels=cms.vstring('Mass'),
        ))

    newSeq += getattr(process, neroLabel + 'SDKinematics')
    newSeq += getattr(process, neroLabel + 'Njettiness')

    ### subjet b-tagging ###

    setattr(
        process, neroLabel + 'PFImpactParameterTagInfos',
        pfImpactParameterTagInfos.clone(
            jets=cms.InputTag('PFJets' + "SoftDrop" + neroLabel, 'SubJets'),
            maxDeltaR=cms.double(jetRadius),
            primaryVertex=cms.InputTag('offlineSlimmedPrimaryVertices'),
            candidates=cms.InputTag('packedPFCandidates')))

    setattr(
        process, neroLabel + 'PFInclusiveSecondaryVertexFinderTagInfos',
        pfInclusiveSecondaryVertexFinderTagInfos.clone(
            trackIPTagInfos=cms.InputTag(neroLabel +
                                         'PFImpactParameterTagInfos'),
            extSVCollection=cms.InputTag('slimmedSecondaryVertices')))
    setattr(
        process, neroLabel + 'PFCombinedInclusiveSecondaryVertexV2BJetTags',
        pfCombinedInclusiveSecondaryVertexV2BJetTags.clone(
            tagInfos=cms.VInputTag(
                cms.InputTag(neroLabel + "PFImpactParameterTagInfos"),
                cms.InputTag(neroLabel +
                             "PFInclusiveSecondaryVertexFinderTagInfos"))))
    newSeq += getattr(process, neroLabel + 'PFImpactParameterTagInfos')
    newSeq += getattr(process,
                      neroLabel + 'PFInclusiveSecondaryVertexFinderTagInfos')
    newSeq += getattr(
        process, neroLabel + 'PFCombinedInclusiveSecondaryVertexV2BJetTags')

    bTagInfos = ['None']
    bTagDiscriminators = ['None']

    ########################################
    ##          MAKE PAT JETS             ##
    ########################################

    addJetCollection(
        process,
        labelName='PF' + neroLabel,
        jetSource=cms.InputTag('PFJets' + neroLabel),
        algo=algoLabel,  # needed for jet flavor clustering
        rParam=jetRadius,  # needed for jet flavor clustering
        pfCandidates=cms.InputTag('packedPFCandidates'),
        pvSource=cms.InputTag(pvSource),
        svSource=cms.InputTag(svSource),
        muSource=cms.InputTag(muSource),
        elSource=cms.InputTag(elSource),
        btagInfos=bTagInfos,
        btagDiscriminators=bTagDiscriminators,
        genJetCollection=cms.InputTag('genJetsNoNu' + rLabel),
        genParticles=cms.InputTag(genParticles),
        getJetMCFlavour=False,  # jet flavor disabled
    )
    getattr(process, 'selectedPatJetsPF' +
            neroLabel).cut = cms.string("abs(eta) < " + str(2.5))
    ## SOFT DROP ##
    addJetCollection(
        process,
        labelName='SoftDropPF' + neroLabel,
        jetSource=cms.InputTag('PFJets' + "SoftDrop" + neroLabel),
        pfCandidates=cms.InputTag('packedPFCandidates'),
        algo=algoLabel,
        rParam=jetRadius,
        btagInfos=['None'],
        btagDiscriminators=['None'],
        genJetCollection=cms.InputTag('genJetsNoNu' + rLabel),
        genParticles=cms.InputTag(genParticles),
        getJetMCFlavour=False,  # jet flavor disabled
    )
    addJetCollection(
        process,
        labelName='SoftDropSubjetsPF' + neroLabel,
        jetSource=cms.InputTag('PFJets' + "SoftDrop" + neroLabel, 'SubJets'),
        algo=algoLabel,
        rParam=jetRadius,
        pfCandidates=cms.InputTag('packedPFCandidates'),
        pvSource=cms.InputTag(pvSource),
        svSource=cms.InputTag(svSource),
        muSource=cms.InputTag(muSource),
        elSource=cms.InputTag(elSource),
        btagInfos=bTagInfosSubjets,
        btagDiscriminators=bTagDiscriminatorsSubjets,
        genJetCollection=cms.InputTag('genJetsNoNuSoftDrop' + rLabel,
                                      'SubJets'),
        genParticles=cms.InputTag(genParticles),
        explicitJTA=True,  # needed for subjet b tagging
        svClustering=True,  # needed for subjet b tagging
        fatJets=cms.InputTag('PFJets' +
                             neroLabel),  # needed for subjet flavor clustering
        groomedFatJets=cms.InputTag(
            'PFJets' + "SoftDrop" +
            neroLabel),  # needed for subjet flavor clustering
        runIVF=False,
        getJetMCFlavour=False,  # jet flavor disabled
    )

    isMC = not (isData)
    if isMC:
        newSeq += getattr(process, 'patJetPartonMatchPF' + neroLabel)
        newSeq += getattr(process, 'patJetGenJetMatchPF' + neroLabel)
    newSeq += getattr(process, 'patJetsPF' + neroLabel)
    newSeq += getattr(process, 'selectedPatJetsPF' + neroLabel)

    if isMC:
        newSeq += getattr(process, 'patJetPartonMatchSoftDropPF' + neroLabel)
        newSeq += getattr(process, 'patJetGenJetMatchSoftDropPF' + neroLabel)
    newSeq += getattr(process, 'patJetsSoftDropPF' + neroLabel)
    newSeq += getattr(process, 'selectedPatJetsSoftDropPF' + neroLabel)

    if isMC:
        newSeq += getattr(process,
                          'patJetPartonMatchSoftDropSubjetsPF' + neroLabel)
        newSeq += getattr(process,
                          'patJetGenJetMatchSoftDropSubjetsPF' + neroLabel)
    newSeq += getattr(process, 'patJetsSoftDropSubjetsPF' + neroLabel)
    newSeq += getattr(process, 'selectedPatJetsSoftDropSubjetsPF' + neroLabel)

    setattr(
        process, "selectedPatJetsSoftDropPF" + "Packed" + neroLabel,
        cms.EDProducer(
            "BoostedJetMerger",
            jetSrc=cms.InputTag("selectedPatJetsSoftDropPF" + neroLabel),
            subjetSrc=cms.InputTag("selectedPatJetsSoftDropSubjetsPF" +
                                   neroLabel)))
    ## PACK ##
    setattr(
        process, "packedPatJetsPF" + neroLabel,
        cms.EDProducer("JetSubstructurePacker",
                       jetSrc=cms.InputTag('selectedPatJetsPF' + neroLabel),
                       distMax=cms.double(jetRadius),
                       algoTags=cms.VInputTag(),
                       algoLabels=cms.vstring(),
                       fixDaughters=cms.bool(False)))
    getattr(process, "packedPatJetsPF" + neroLabel).algoTags.append(
        cms.InputTag('selectedPatJetsSoftDropPF' + "Packed" + neroLabel))
    getattr(process,
            "packedPatJetsPF" + neroLabel).algoLabels.append('SoftDrop')
    getattr(process, 'patJetsPF' + neroLabel).userData.userFloats.src += [
        neroLabel + 'Njettiness:tau1'
    ]
    getattr(process, 'patJetsPF' + neroLabel).userData.userFloats.src += [
        neroLabel + 'Njettiness:tau2'
    ]
    getattr(process, 'patJetsPF' + neroLabel).userData.userFloats.src += [
        neroLabel + 'Njettiness:tau3'
    ]
    getattr(process, 'patJetsPF' + neroLabel).userData.userFloats.src += [
        neroLabel + 'Njettiness:tau4'
    ]
    getattr(process, 'patJetsPF' + neroLabel).userData.userFloats.src += [
        neroLabel + 'SDKinematics:Mass'
    ]

    for m in ['patJetsPF' + neroLabel, 'patJetsSoftDropSubjetsPF' + neroLabel]:
        if hasattr(process, m) and getattr(getattr(process, m), 'addBTagInfo'):
            setattr(getattr(process, m), 'addTagInfos', cms.bool(True))
        #if hasattr(process,m):
        #  setattr( getattr(process,m), 'addJetFlavourInfo', cms.bool(True))

    newSeq += cms.Sequence(
        getattr(process, 'selectedPatJetsSoftDropPF' + "Packed" + neroLabel) +
        getattr(process, 'packedPatJetsPF' + neroLabel))

    if isData:
        removeMCMatching(process, ['All'], outputModules=[])
    return newSeq
Beispiel #13
0
process.patJetCorrFactorsSlimmedJetsAK8BTagged.primaryVertices = "unpackedTracksAndVertices"

#adjust JTA cone size
process.jetTracksAssociatorAtVertexSlimmedJetsAK8BTagged.coneSize = 0.8

process.load('PhysicsTools.PatAlgos.slimming.unpackedTracksAndVertices_cfi')
#process.combinedSecondaryVertex.trackMultiplicityMin = 1 #silly sv, uses un filtered tracks.. i.e. any pt

process.chs = cms.EDFilter("CandPtrSelector",
                           src=cms.InputTag("packedPFCandidates"),
                           cut=cms.string("fromPV()>0"))

### Add Nsubjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

process.Njettiness = Njettiness.clone(src=cms.InputTag("ak8PFJetsCHS"),
                                      cone=cms.double(0.8))

process.patJetsAK8PFCHS.userData.userFloats.src += [
    'Njettiness:tau1', 'Njettiness:tau2', 'Njettiness:tau3'
]

from RecoJets.Configuration.RecoPFJets_cff import ak8PFJetsCHSPruned, ak8PFJetsCHSFiltered, ak8PFJetsCHSTrimmed

process.ak8PFJetsCHSPruned = ak8PFJetsCHSPruned.clone(src=cms.InputTag("chs"))
process.ak8PFJetsCHSTrimmed = ak8PFJetsCHSTrimmed.clone(
    src=cms.InputTag("chs"))
process.ak8PFJetsCHSFiltered = ak8PFJetsCHSFiltered.clone(
    src=cms.InputTag("chs"))

from RecoJets.JetProducers.ak8PFJetsCHS_groomingValueMaps_cfi import *
def makeFatJets(process,isData,pfCandidates,algoLabel,jetRadius):
  
  isMC = not isData
  postfix='PFlow'
  if pfCandidates=='particleFlow':
    # mini aod needs a different config
    pfCandidates = 'pfCHS'
  
  if pfCandidates=='pfCHS':
    puMethod='CHS'
  else:
    puMethod='Puppi'

  rLabel = algoLabel+str(int(jetRadius*10))
  neroLabel = rLabel+puMethod

  if algoLabel=='CA':
    jetAlgo = 'CambridgeAachen'
  else:
    jetAlgo = 'AntiKt'

  if jetRadius<1:
    sdZcut = 0.1
    sdBeta = 0.0
  else:
    sdZcut = 0.2
    sdBeta = 1.0

  setattr(process,neroLabel+'Sequence',cms.Sequence())
  newSeq = getattr(process,neroLabel+'Sequence')
  
  ## Various collection names
  genParticles = 'prunedGenParticles'
  pvSource = 'offlineSlimmedPrimaryVertices'
  svSource = 'slimmedSecondaryVertices'
  muSource = 'slimmedMuons'
  elSource = 'slimmedElectrons'
  bTagInfos = [
      'pfImpactParameterTagInfos'
     ,'pfSecondaryVertexTagInfos'
     ,'pfInclusiveSecondaryVertexFinderTagInfos'
     ,'softPFMuonsTagInfos'
     ,'softPFElectronsTagInfos'
  ]
  ## b-tag discriminators
  bTagDiscriminators = [
      'pfCombinedSecondaryVertexV2BJetTags'
      ,'pfCombinedInclusiveSecondaryVertexV2BJetTags'
  ]


  bTagInfosSubjets = [
      'pfImpactParameterTagInfos'
     ,'pfSecondaryVertexTagInfos'
     ,'pfInclusiveSecondaryVertexFinderTagInfos'
     ,'softPFMuonsTagInfos'
     ,'softPFElectronsTagInfos'
  ]
  ## b-tag discriminators
  bTagDiscriminatorsSubjets = [
      'pfCombinedSecondaryVertexV2BJetTags'
      ,'pfCombinedInclusiveSecondaryVertexV2BJetTags'
  ]

  bTagInfosSubjets=['None']
  bTagDiscriminatorsSubjets=['None']

  ### jet clustering ### 
  ########################################
  ##           REMAKE JETS              ##
  ########################################

  addingGenJets = False

  if not(hasattr(process,"genJetsNoNu"+rLabel)) and isMC:
    addingGenJets = True
    setattr(process,"genJetsNoNu"+rLabel, ak4GenJets.clone(
                                           jetAlgorithm = cms.string(jetAlgo),
                                           rParam = cms.double(jetRadius),
                                           src = cms.InputTag("packedGenParticlesForJetsNoNu")
                                         )
    )
  setattr(process,"PFJets"+neroLabel, ak4PFJets.clone(
                                                jetAlgorithm = cms.string(jetAlgo),
                                                rParam = cms.double(jetRadius),
                                                src = cms.InputTag(pfCandidates),
                                                srcPVs = cms.InputTag(pvSource),
                                                doAreaFastjet = cms.bool(True),
                                                jetPtMin = cms.double(150)
                                            )
  )
  if not(hasattr(process,"genJetsNoNuSoftDrop"+rLabel)) and isMC:
    addingGenJets = True
    setattr(process,"genJetsNoNuSoftDrop"+rLabel, getattr(process,'genJetsNoNu'+rLabel).clone(
                                                      R0 = cms.double(jetRadius),
                                                      useSoftDrop = cms.bool(True),
                                                      zcut = cms.double(sdZcut),
                                                      beta = cms.double(sdBeta),
                                                      writeCompound = cms.bool(True),
                                                      jetCollInstanceName=cms.string("SubJets")
                                                  )
    )
  setattr(process,"PFJets"+"SoftDrop"+neroLabel, getattr(process,'PFJets'+neroLabel).clone(
                                                          useSoftDrop = cms.bool(True),
                                                          R0 = cms.double(jetRadius),
                                                          zcut = cms.double(sdZcut),
                                                          beta = cms.double(sdBeta),
                                                          writeCompound = cms.bool(True),
                                                          useExplicitGhosts = cms.bool(True),
                                                          jetCollInstanceName=cms.string("SubJets"),
                                                          jetPtMin = cms.double(150)
                                                      )
  )
  if addingGenJets and not(isData):
    newSeq += getattr(process,'genJetsNoNu'+rLabel)
    newSeq += getattr(process,'genJetsNoNuSoftDrop'+rLabel)
  newSeq += getattr(process,'PFJets'+neroLabel)
  newSeq += getattr(process,'PFJets'+"SoftDrop"+neroLabel)
  
  ########################################
  ##           SUBSTRUCTURE             ##
  #######################################

  setattr(process,neroLabel+'Njettiness',                          
          Njettiness.clone(                                      
            src = cms.InputTag('PFJets'+neroLabel),       
            R0 = cms.double(jetRadius),
            Njets = cms.vuint32(1,2,3,4)
          )
  )

  setattr(process,neroLabel+'SDKinematics',
      cms.EDProducer('RecoJetDeltaRValueMapProducer',
            src = cms.InputTag('PFJets'+neroLabel),
            matched = cms.InputTag('PFJets'+"SoftDrop"+neroLabel),
            distMax = cms.double(1.5),
            values = cms.vstring('mass'),
            valueLabels = cms.vstring('Mass'),
      )
  )

  newSeq += getattr(process,neroLabel+'SDKinematics')
  newSeq += getattr(process,neroLabel+'Njettiness')

  ### subjet b-tagging ###

  setattr(process,neroLabel+'PFImpactParameterTagInfos',
      pfImpactParameterTagInfos.clone(
          jets      = cms.InputTag('PFJets'+"SoftDrop"+neroLabel,'SubJets'),
          maxDeltaR = cms.double(jetRadius),
          primaryVertex = cms.InputTag('offlineSlimmedPrimaryVertices'),
          candidates = cms.InputTag('packedPFCandidates')
      )
  )

  setattr(process,neroLabel+'PFInclusiveSecondaryVertexFinderTagInfos',
    pfInclusiveSecondaryVertexFinderTagInfos.clone(
      trackIPTagInfos = cms.InputTag(neroLabel+'PFImpactParameterTagInfos'),
      extSVCollection = cms.InputTag('slimmedSecondaryVertices')
    )
  )
  setattr(process,neroLabel+'PFCombinedInclusiveSecondaryVertexV2BJetTags',
    pfCombinedInclusiveSecondaryVertexV2BJetTags.clone(
      tagInfos = cms.VInputTag( 
        cms.InputTag(neroLabel+"PFImpactParameterTagInfos"), 
        cms.InputTag(neroLabel+"PFInclusiveSecondaryVertexFinderTagInfos") 
      )
    )
  )
  newSeq += getattr(process,neroLabel+'PFImpactParameterTagInfos')
  newSeq += getattr(process,neroLabel+'PFInclusiveSecondaryVertexFinderTagInfos')
  newSeq += getattr(process,neroLabel+'PFCombinedInclusiveSecondaryVertexV2BJetTags')
  
  bTagInfos = ['None']
  bTagDiscriminators = ['None']

  ########################################
  ##          MAKE PAT JETS             ##
  ########################################

  addJetCollection(
      process,
      labelName='PF'+neroLabel,
      jetSource=cms.InputTag('PFJets'+neroLabel),
      algo=algoLabel,           # needed for jet flavor clustering
      rParam=jetRadius, # needed for jet flavor clustering
      pfCandidates = cms.InputTag('packedPFCandidates'),
      pvSource = cms.InputTag(pvSource),
      svSource = cms.InputTag(svSource),
      muSource = cms.InputTag(muSource),
      elSource = cms.InputTag(elSource),
      btagInfos = bTagInfos,
      btagDiscriminators = bTagDiscriminators,
      genJetCollection = cms.InputTag('genJetsNoNu'+rLabel),
      genParticles = cms.InputTag(genParticles),
      getJetMCFlavour = False, # jet flavor disabled
  )
  getattr(process,'selectedPatJetsPF'+neroLabel).cut = cms.string("abs(eta) < " + str(2.5))
  ## SOFT DROP ##
  addJetCollection(
      process,
      labelName='SoftDropPF'+neroLabel,
      jetSource=cms.InputTag('PFJets'+"SoftDrop"+neroLabel),
      pfCandidates = cms.InputTag('packedPFCandidates'),
      algo=algoLabel,
      rParam=jetRadius,
      btagInfos = ['None'],
      btagDiscriminators = ['None'],
      genJetCollection = cms.InputTag('genJetsNoNu'+rLabel),
      genParticles = cms.InputTag(genParticles),
      getJetMCFlavour = False, # jet flavor disabled
  )
  addJetCollection(
      process,
      labelName='SoftDropSubjetsPF'+neroLabel,
      jetSource=cms.InputTag('PFJets'+"SoftDrop"+neroLabel,'SubJets'),
      algo=algoLabel,  
      rParam=jetRadius, 
      pfCandidates = cms.InputTag('packedPFCandidates'),
      pvSource = cms.InputTag(pvSource),
      svSource = cms.InputTag(svSource),
      muSource = cms.InputTag(muSource),
      elSource = cms.InputTag(elSource),
      btagInfos = bTagInfosSubjets,
      btagDiscriminators = bTagDiscriminatorsSubjets,
      genJetCollection = cms.InputTag('genJetsNoNuSoftDrop'+rLabel,'SubJets'),
      genParticles = cms.InputTag(genParticles),
      explicitJTA = True,  # needed for subjet b tagging
      svClustering = True, # needed for subjet b tagging
      fatJets = cms.InputTag('PFJets'+neroLabel),              # needed for subjet flavor clustering
      groomedFatJets = cms.InputTag('PFJets'+"SoftDrop"+neroLabel), # needed for subjet flavor clustering
      runIVF = False,
      getJetMCFlavour = False, # jet flavor disabled
  )
  
  isMC = not(isData)
  if isMC:
    newSeq += getattr(process,'patJetPartonMatchPF'+neroLabel)
    newSeq += getattr(process,'patJetGenJetMatchPF'+neroLabel)
  newSeq += getattr(process,'patJetsPF'+neroLabel)
  newSeq += getattr(process,'selectedPatJetsPF'+neroLabel)
  
  if isMC:
    newSeq += getattr(process,'patJetPartonMatchSoftDropPF'+neroLabel)
    newSeq += getattr(process,'patJetGenJetMatchSoftDropPF'+neroLabel)
  newSeq += getattr(process,'patJetsSoftDropPF'+neroLabel)
  newSeq += getattr(process,'selectedPatJetsSoftDropPF'+neroLabel)
  
  if isMC:
    newSeq += getattr(process,'patJetPartonMatchSoftDropSubjetsPF'+neroLabel)
    newSeq += getattr(process,'patJetGenJetMatchSoftDropSubjetsPF'+neroLabel)
  newSeq += getattr(process,'patJetsSoftDropSubjetsPF'+neroLabel)
  newSeq += getattr(process,'selectedPatJetsSoftDropSubjetsPF'+neroLabel)
  
  setattr(process,"selectedPatJetsSoftDropPF"+"Packed"+neroLabel, 
          cms.EDProducer("BoostedJetMerger",    
                          jetSrc=cms.InputTag("selectedPatJetsSoftDropPF"+neroLabel),
                          subjetSrc=cms.InputTag("selectedPatJetsSoftDropSubjetsPF"+neroLabel)  
          )
  )
  ## PACK ##
  setattr(process,"packedPatJetsPF"+neroLabel, 
          cms.EDProducer("JetSubstructurePacker",
                          jetSrc = cms.InputTag('selectedPatJetsPF'+neroLabel),
                          distMax = cms.double(jetRadius),
                          algoTags = cms.VInputTag(),
                          algoLabels = cms.vstring(),
                          fixDaughters = cms.bool(False)
                        )
  )
  getattr(process,"packedPatJetsPF"+neroLabel).algoTags.append(
      cms.InputTag('selectedPatJetsSoftDropPF'+"Packed"+neroLabel)
  )
  getattr(process,"packedPatJetsPF"+neroLabel).algoLabels.append(
      'SoftDrop'
  )
  getattr(process,'patJetsPF'+neroLabel).userData.userFloats.src += [neroLabel+'Njettiness:tau1']
  getattr(process,'patJetsPF'+neroLabel).userData.userFloats.src += [neroLabel+'Njettiness:tau2']
  getattr(process,'patJetsPF'+neroLabel).userData.userFloats.src += [neroLabel+'Njettiness:tau3']
  getattr(process,'patJetsPF'+neroLabel).userData.userFloats.src += [neroLabel+'Njettiness:tau4']
  getattr(process,'patJetsPF'+neroLabel).userData.userFloats.src += [neroLabel+'SDKinematics:Mass']

  for m in ['patJetsPF'+neroLabel,'patJetsSoftDropSubjetsPF'+neroLabel]:
    if hasattr(process,m) and getattr( getattr(process,m),'addBTagInfo'):
      setattr( getattr(process,m), 'addTagInfos', cms.bool(True))
    #if hasattr(process,m):
    #  setattr( getattr(process,m), 'addJetFlavourInfo', cms.bool(True))

  newSeq += cms.Sequence(
      getattr(process,'selectedPatJetsSoftDropPF'+"Packed"+neroLabel)+
      getattr(process,'packedPatJetsPF'+neroLabel)
  )

  if isData:
      removeMCMatching(process, ['All'], outputModules = [])
  return newSeq
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=False,
    addGenPartonMatch=False,
    addGenJetMatch=False,
    embedGenJetMatch=False,
    embedGenPartonMatch=False,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akCsFilter4PFNjettiness = Njettiness.clone(
    src=cms.InputTag("akCsFilter4PFJets"), R0=cms.double(0.4))
akCsFilter4PFpatJetsWithBtagging.userData.userFloats.src += [
    'akCsFilter4PFNjettiness:tau1', 'akCsFilter4PFNjettiness:tau2',
    'akCsFilter4PFNjettiness:tau3'
]

akCsFilter4PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akCsFilter4PFpatJetsWithBtagging"),
    genjetTag='ak4HiGenJets',
    rParam=0.4,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
    fillGenJets=False,
    isMC=False,
Beispiel #16
0
def jetToolbox( proc, jetType, jetSequence, outputFile, 
		newPFCollection=False, nameNewPFCollection = '',	
		PUMethod='CHS',                    #### Options: Puppi, CS, SK, Plain
		miniAOD=True,
		runOnMC=True,
		JETCorrPayload='', JETCorrLevels = [ 'None' ], GetJetMCFlavour=True,
		Cut = '', 
		bTagDiscriminators = None, 
		subJETCorrPayload='', subJETCorrLevels = [ 'None' ], GetSubjetMCFlavour=False,
		CutSubjet = '', 
		addPruning=False, zCut=0.1, rCut=0.5, addPrunedSubjets=False,
		addSoftDrop=False, betaCut=0.0,  zCutSD=0.1, addSoftDropSubjets=False,
		addTrimming=False, rFiltTrim=0.2, ptFrac=0.03,
		addFiltering=False, rfilt=0.3, nfilt=3,
		addCMSTopTagger=False,
		addMassDrop=False,
		addHEPTopTagger=False,
		addNsub=False, maxTau=4,
		addPUJetID=False,
		addQJets=False,
		addQGTagger=False, QGjetsLabel='chs',
		addEnergyCorrFunc=False, ecfBeta = 1.0, maxECF=3,
		):

	runOnData = not runOnMC
	if runOnData:
		GetJetMCFlavour = False
		GetSubjetMCFlavour = False
	
	###############################################################################
	#######  Verifying some inputs and defining variables
	###############################################################################
	print '|---- jetToolbox: Initialyzing collection...'
	if newPFCollection: print '|---- jetToolBox: Using '+ nameNewPFCollection +' as PFCandidates collection'
	supportedJetAlgos = { 'ak': 'AntiKt', 'ca' : 'CambridgeAachen', 'kt' : 'Kt' }
	recommendedJetAlgos = [ 'ak4', 'ak8', 'ca4', 'ca8', 'ca10' ]
	payloadList = [ 'None',
			'AK1PFchs', 'AK2PFchs', 'AK3PFchs', 'AK4PFchs', 'AK5PFchs', 'AK6PFchs', 'AK7PFchs', 'AK8PFchs', 'AK9PFchs', 'AK10PFchs',
			'AK1PFPUPPI', 'AK2PFPUPPI', 'AK3PFPUPPI', 'AK4PFPUPPI', 'AK5PFPUPPI', 'AK6PFPUPPI', 'AK7PFPUPPI', 'AK8PFPUPPI', 'AK9PFPUPPI', 'AK10PFPUPPI',  
			'AK1PFSK', 'AK2PFSK', 'AK3PFSK', 'AK4PFSK', 'AK5PFSK', 'AK6PFSK', 'AK7PFSK', 'AK8PFSK', 'AK9PFSK', 'AK10PFSK',  
			'AK1PF', 'AK2PF', 'AK3PF', 'AK4PF', 'AK5PF', 'AK6PF', 'AK7PF', 'AK8PF', 'AK9PF', 'AK10PF' ]
	JECLevels = [ 'L1Offset', 'L1FastJet', 'L1JPTOffset', 'L2Relative', 'L3Absolute', 'L5Falvour', 'L7Parton' ]
	if runOnData:
		JECLevels += ['L2L3Residual']
	jetAlgo = ''
	algorithm = ''
	size = ''
	for type, tmpAlgo in supportedJetAlgos.iteritems(): 
		if type in jetType.lower():
			jetAlgo = type
			algorithm = tmpAlgo
			size = jetType.replace( type, '' )

	jetSize = 0.
	if int(size) in range(0, 20): jetSize = int(size)/10.
	else: print '|---- jetToolBox: jetSize has not a valid value. Insert a number between 1 and 20 after algorithm, like: AK8'
	### Trick for uppercase/lowercase algo name
	jetALGO = jetAlgo.upper()+size
	jetalgo = jetAlgo.lower()+size
	if jetalgo not in recommendedJetAlgos: print '|---- jetToolBox: CMS recommends the following jet algoritms: '+' '.join(recommendedJetAlgos)+'. You are using', jetalgo,'.'


	#################################################################################
	####### Toolbox start 
	#################################################################################

	elemToKeep = []
	jetSeq = cms.Sequence()
	genParticlesLabel = ''
	pvLabel = ''
	tvLabel = ''
	toolsUsed = []

	#### For MiniAOD
	if miniAOD:

		print '|---- jetToolBox: JETTOOLBOX RUNNING ON MiniAOD FOR '+jetALGO+' JETS USING '+PUMethod

		genParticlesLabel = 'prunedGenParticles'
		pvLabel = 'offlineSlimmedPrimaryVertices'
		svLabel = 'slimmedSecondaryVertices'
		tvLabel = 'unpackedTracksAndVertices'
		pfCand = nameNewPFCollection if newPFCollection else 'packedPFCandidates'

		if runOnMC:
			## Filter out neutrinos from packed GenParticles
			setattr( proc, 'packedGenParticlesForJetsNoNu', 
					cms.EDFilter("CandPtrSelector", 
						src = cms.InputTag("packedGenParticles"), 
						cut = cms.string("abs(pdgId) != 12 && abs(pdgId) != 14 && abs(pdgId) != 16")
						))
			jetSeq += getattr(proc, 'packedGenParticlesForJetsNoNu' )

			setattr( proc, jetalgo+'GenJetsNoNu', 
					ak4GenJets.clone( src = 'packedGenParticlesForJetsNoNu', 
						rParam = jetSize, 
						jetAlgorithm = algorithm ) ) 
			jetSeq += getattr(proc, jetalgo+'GenJetsNoNu' )

		#for Inclusive Vertex Finder
		proc.load('PhysicsTools.PatAlgos.slimming.unpackedTracksAndVertices_cfi')

	#### For AOD
	else:
		print '|---- jetToolBox: JETTOOLBOX RUNNING ON AOD FOR '+jetALGO+' JETS USING '+PUMethod

		genParticlesLabel = 'genParticles'
		pvLabel = 'offlinePrimaryVertices'
		tvLabel = 'generalTracks'
		pfCand =  nameNewPFCollection if newPFCollection else 'particleFlow'
		svLabel = 'inclusiveCandidateSecondaryVertices'

		if runOnMC:
			proc.load('RecoJets.Configuration.GenJetParticles_cff')
			setattr( proc, jetalgo+'GenJetsNoNu', ak4GenJets.clone( src = 'genParticlesForJetsNoNu', rParam = jetSize, jetAlgorithm = algorithm ) ) 
			jetSeq += getattr(proc, jetalgo+'GenJetsNoNu' )
		
		

	## b-tag discriminators
	if bTagDiscriminators is None:
		bTagDiscriminators = [
				'pfTrackCountingHighEffBJetTags',
				'pfTrackCountingHighPurBJetTags',
				'pfJetProbabilityBJetTags',
				'pfJetBProbabilityBJetTags',
				'pfSimpleSecondaryVertexHighEffBJetTags',
				'pfSimpleSecondaryVertexHighPurBJetTags',
				'pfCombinedSecondaryVertexV2BJetTags',
				'pfCombinedInclusiveSecondaryVertexV2BJetTags'
	    	]

	### Jet Corrections
	if not set(JETCorrLevels).issubset(set(JECLevels)): 
		if ( 'CHS' in PUMethod ) or  ( 'Plain' in PUMethod ): JETCorrLevels = ['L1FastJet','L2Relative', 'L3Absolute']
		else: JETCorrLevels = [ 'L2Relative', 'L3Absolute']
		if runOnData: JETCorrLevels.append('L2L3Residual')
	if not set(subJETCorrLevels).issubset(set(JECLevels)): 
		if ( 'CHS' in PUMethod ) or  ( 'Plain' in PUMethod ): subJETCorrLevels = ['L1FastJet','L2Relative', 'L3Absolute']
		else: subJETCorrLevels = [ 'L2Relative', 'L3Absolute']
		if runOnData: subJETCorrLevels.append('L2L3Residual')

	####  Creating PATjets
	tmpPfCandName = pfCand.lower()
	if 'Puppi' in PUMethod:
		if ('puppi' in tmpPfCandName): 
			srcForPFJets = pfCand
			print '|---- jetToolBox: Not running puppi algorithm because keyword puppi was specified in nameNewPFCollection, but applying puppi corrections.' 
		else: 
			proc.load('CommonTools.PileupAlgos.Puppi_cff')
			puppi.candName = cms.InputTag( pfCand ) 
			if miniAOD: puppi.vertexName = cms.InputTag('offlineSlimmedPrimaryVertices')
			jetSeq += getattr(proc, 'puppi' )
			srcForPFJets = 'puppi'
		from RecoJets.JetProducers.ak4PFJetsPuppi_cfi import ak4PFJetsPuppi
		setattr( proc, jetalgo+'PFJetsPuppi', 
				ak4PFJetsPuppi.clone( src = cms.InputTag( srcForPFJets ),
					doAreaFastjet = True, 
					rParam = jetSize, 
					jetAlgorithm = algorithm ) )  
		jetSeq += getattr(proc, jetalgo+'PFJetsPuppi' )
		if JETCorrPayload not in payloadList: JETCorrPayload = 'AK'+size+'PFPuppi'
		if subJETCorrPayload not in payloadList: subJETCorrPayload = 'AK4PFPuppi'

	elif 'CS' in PUMethod:

		from RecoJets.JetProducers.ak4PFJetsCS_cfi import ak4PFJetsCS
		setattr( proc, jetalgo+'PFJetsCS', 
				ak4PFJetsCS.clone( doAreaFastjet = True, 
					csRParam = cms.double(jetSize),
					jetAlgorithm = algorithm ) ) 
		if miniAOD: getattr( proc, jetalgo+'PFJetsCS').src = pfCand
		#setattr( proc, jetalgo+'PFJetsCSConstituents', ak8PFJetsCSConstituents.clone( src = cms.InputTag(jetalgo+'PFJetsCS') ) )
		jetSeq += getattr(proc, jetalgo+'PFJetsCS' )

		#setattr( proc, jetalgo+'PFJetsCSConstituents', ak8PFJetsCSConstituents.clone( src = cms.InputTag(jetalgo+'PFJetsCS') ) )
		jetSeq += getattr(proc, jetalgo+'PFJetsCS' )
		if JETCorrPayload not in payloadList: JETCorrPayload = 'AK'+size+'PFCS'
		if subJETCorrPayload not in payloadList: subJETCorrPayload = 'AK4PFCS'

	elif 'SK' in PUMethod:

		if ('sk' in tmpPfCandName): 
			srcForPFJets = pfCand
			print '|---- jetToolBox: Not running softkiller algorithm because keyword SK was specified in nameNewPFCollection, but applying SK corrections.' 
		else:
			proc.load('CommonTools.PileupAlgos.softKiller_cfi')
			getattr( proc, 'softKiller' ).PFCandidates = cms.InputTag( pfCand ) 
			jetSeq += getattr(proc, 'softKiller' )
			srcForPFJets = 'softKiller'
		from RecoJets.JetProducers.ak4PFJetsSK_cfi import ak4PFJetsSK
		setattr( proc, jetalgo+'PFJetsSK', 
				ak4PFJetsSK.clone(  src = cms.InputTag( srcForPFJets ),
					rParam = jetSize, 
					jetAlgorithm = algorithm ) ) 
		jetSeq += getattr(proc, jetalgo+'PFJetsSK' )
		if JETCorrPayload not in payloadList: JETCorrPayload = 'AK'+size+'PFSK'
		if subJETCorrPayload not in payloadList: subJETCorrPayload = 'AK4PFSK'
	
	elif 'CHS' in PUMethod: 
		
		if miniAOD:
			if ('chs' in tmpPfCandName): 
				srcForPFJets = pfCand
				print '|---- jetToolBox: Not running CHS algorithm because keyword CHS was specified in nameNewPFCollection, but applying CHS corrections.' 
			else: 
				setattr( proc, 'chs', cms.EDFilter('CandPtrSelector', src = cms.InputTag( pfCand ), cut = cms.string('fromPV')) )
				jetSeq += getattr(proc, 'chs')
				srcForPFJets = 'chs'
		else:
			if ( pfCand == 'particleFlow' ):
				from RecoParticleFlow.PFProducer.particleFlowTmpPtrs_cfi import particleFlowTmpPtrs
				setattr( proc, 'newParticleFlowTmpPtrs', particleFlowTmpPtrs.clone( src = pfCand ) )
				jetSeq += getattr(proc, 'newParticleFlowTmpPtrs')
				from CommonTools.ParticleFlow.pfNoPileUpJME_cff import pfPileUpJME, pfNoPileUpJME
				proc.load('CommonTools.ParticleFlow.goodOfflinePrimaryVertices_cfi')
				setattr( proc, 'newPfPileUpJME', pfPileUpJME.clone( PFCandidates= 'newParticleFlowTmpPtrs' ) )
				jetSeq += getattr(proc, 'newPfPileUpJME')
				setattr( proc, 'newPfNoPileUpJME', pfNoPileUpJME.clone( topCollection='newPfPileUpJME', bottomCollection= 'newParticleFlowTmpPtrs' ) )
				jetSeq += getattr(proc, 'newPfNoPileUpJME')
				srcForPFJets = 'newPfNoPileUpJME'
			else: 
				proc.load('CommonTools.ParticleFlow.pfNoPileUpJME_cff')
				srcForPFJets = 'pfNoPileUpJME'
			

		setattr( proc, jetalgo+'PFJetsCHS', 
				ak4PFJetsCHS.clone( src = cms.InputTag( srcForPFJets ), 
					doAreaFastjet = True, 
					rParam = jetSize, 
					jetAlgorithm = algorithm ) ) 
		jetSeq += getattr(proc, jetalgo+'PFJetsCHS' )
		if JETCorrPayload not in payloadList: JETCorrPayload = 'AK'+size+'PFchs'
		if subJETCorrPayload not in payloadList: subJETCorrPayload = 'AK4PFchs'

	else: 
		PUMethod = ''
		setattr( proc, jetalgo+'PFJets', 
				ak4PFJets.clone( 
					doAreaFastjet = True, 
					rParam = jetSize, 
					jetAlgorithm = algorithm ) ) 
		if miniAOD: getattr( proc, jetalgo+'PFJets').src = pfCand
		jetSeq += getattr(proc, jetalgo+'PFJets' )
		if JETCorrPayload not in payloadList: JETCorrPayload = 'AK'+size+'PF'
		if subJETCorrPayload not in payloadList: subJETCorrPayload = 'AK4PF'

	if 'None' in JETCorrPayload: JEC = None
	else: JEC = ( JETCorrPayload.replace('CS','chs').replace('SK','chs') , JETCorrLevels, 'None' )   ### temporary
	#else: JEC = ( JETCorrPayload., JETCorrLevels, 'None' ) 
	print '|---- jetToolBox: Applying this corrections: '+str(JEC)

	if addPrunedSubjets or addSoftDropSubjets or addCMSTopTagger:
		if 'None' in subJETCorrPayload: subJEC = None
		else: subJEC = ( subJETCorrPayload.replace('CS','chs').replace('SK','chs') , subJETCorrLevels, 'None' )   ### temporary


	if ( 'CHS' in PUMethod ) and miniAOD: setattr( proc, jetalgo+'PFJets'+PUMethod+'Constituents', cms.EDFilter("MiniAODJetConstituentSelector", src = cms.InputTag( jetalgo+'PFJets'+PUMethod ), cut = cms.string( Cut ) ))
	else: setattr( proc, jetalgo+'PFJets'+PUMethod+'Constituents', cms.EDFilter("PFJetConstituentSelector", src = cms.InputTag( jetalgo+'PFJets'+PUMethod ), cut = cms.string( Cut ) ))
	jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Constituents' )

	addJetCollection(
			proc,
			labelName = jetALGO+'PF'+PUMethod,
			jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod),
			algo = jetalgo,
			rParam = jetSize,
			jetCorrections = JEC if JEC is not None else None, 
			pfCandidates = cms.InputTag( pfCand ),  
			svSource = cms.InputTag( svLabel ),  
			genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
			pvSource = cms.InputTag( pvLabel ), 
			btagDiscriminators = bTagDiscriminators,
			getJetMCFlavour = GetJetMCFlavour,
			genParticles = cms.InputTag(genParticlesLabel),
			outputModules = ['outputFile']
			) 


	if 'CS' in PUMethod: getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod ).getJetMCFlavour = False  # CS jets cannot be re-clustered from their constituents
	
	#### Groomers
	if addSoftDrop or addSoftDropSubjets: 

		setattr( proc, jetalgo+'PFJets'+PUMethod+'SoftDrop', 
			ak8PFJetsCHSSoftDrop.clone( 
				src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents' ),
				rParam = jetSize, 
				jetAlgorithm = algorithm, 
				useExplicitGhosts=True,
				R0= cms.double(jetSize),
				#zcut=zCutSD, 
				beta=betaCut,
				writeCompound = cms.bool(True),
				jetCollInstanceName=cms.string('SubJets') ) )
		setattr( proc, jetalgo+'PFJets'+PUMethod+'SoftDropMass', 
			ak8PFJetsCHSSoftDropMass.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'SoftDrop'), 
				distMax = cms.double( jetSize ) ) )

		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'SoftDropMass_*_*'] 
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'SoftDrop' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'SoftDropMass' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'SoftDropMass']
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'SoftDropMass' )

		if addSoftDropSubjets:

			if runOnMC:
				setattr( proc, jetalgo+'GenJetsNoNuSoftDrop',
						ak4GenJets.clone(
							SubJetParameters,
							useSoftDrop = cms.bool(True),
							rParam = jetSize, 
							jetAlgorithm = algorithm, 
							useExplicitGhosts=cms.bool(True),
							#zcut=cms.double(zCutSD), 
							R0= cms.double(jetSize),
							beta=cms.double(betaCut),
							writeCompound = cms.bool(True),
							jetCollInstanceName=cms.string('SubJets')
							))
				if miniAOD: getattr( proc, jetalgo+'GenJetsNoNuSoftDrop' ).src = 'packedGenParticlesForJetsNoNu'
				jetSeq += getattr(proc, jetalgo+'GenJetsNoNuSoftDrop' )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'SoftDrop',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'SoftDrop'),
					algo = jetalgo,
					rParam = jetSize,
					jetCorrections = JEC if JEC is not None else None, 
					pvSource = cms.InputTag( pvLabel ),
					btagDiscriminators = ['None'],
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
					getJetMCFlavour = False, # jet flavor should always be disabled for groomed jets
					genParticles = cms.InputTag(genParticlesLabel),
					outputModules = ['outputFile']
					) 

			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDrop', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'SoftDrop', cut = Cut ) )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'SoftDropSubjets',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'SoftDrop', 'SubJets'),
					algo = jetalgo,  # needed for subjet b tagging
					rParam = jetSize,  # needed for subjet b tagging
					jetCorrections = subJEC if subJEC is not None else None, 
					pfCandidates = cms.InputTag( pfCand ), 
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ),  
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNuSoftDrop','SubJets'),
					getJetMCFlavour = GetSubjetMCFlavour,
					genParticles = cms.InputTag(genParticlesLabel),
					explicitJTA = True,  # needed for subjet b tagging
					svClustering = True, # needed for subjet b tagging
					fatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod),             # needed for subjet flavor clustering
					groomedFatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod+'SoftDrop'), # needed for subjet flavor clustering
					outputModules = ['outputFile']
					) 

			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets', cut = Cut ))

			## Establish references between PATified fat jets and subjets using the BoostedJetMerger
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked', 
					cms.EDProducer("BoostedJetMerger",
						jetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDrop'),
						subjetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets')
						))
			jetSeq += getattr(proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked' )
			elemToKeep += [ 'keep *_selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked_*_*' ]
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked' )
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets' )

	if addPruning or addPrunedSubjets: 

		setattr( proc, jetalgo+'PFJets'+PUMethod+'Pruned', 
			ak8PFJetsCHSPruned.clone( 
				src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents' ),
				rParam = jetSize, 
				jetAlgorithm = algorithm, 
				zcut=zCut, 
				rcut_factor=rCut,
				writeCompound = cms.bool(True),
				doAreaFastjet = cms.bool(True),
				jetCollInstanceName=cms.string('SubJets') ) )
		setattr( proc, jetalgo+'PFJets'+PUMethod+'PrunedMass', 
			ak8PFJetsCHSPrunedMass.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Pruned'), 
				distMax = cms.double( jetSize ) ) )

		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Pruned' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'PrunedMass' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'PrunedMass']
		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'PrunedMass_*_*'] 
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'PrunedMass' )

		if addPrunedSubjets:
			if runOnMC:
				setattr( proc, jetalgo+'GenJetsNoNuPruned',
						ak4GenJets.clone(
							SubJetParameters,
							rParam = jetSize,
							usePruning = cms.bool(True),
							writeCompound = cms.bool(True),
							jetCollInstanceName=cms.string('SubJets')
							))
				if miniAOD: getattr( proc, jetalgo+'GenJetsNoNuPruned' ).src = 'packedGenParticlesForJetsNoNu'
				jetSeq += getattr(proc, jetalgo+'GenJetsNoNuPruned' )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'Pruned',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Pruned'),
					algo = jetalgo,
					rParam = jetSize,
					jetCorrections = JEC if JEC is not None else None, 
					pvSource = cms.InputTag( pvLabel ),
					btagDiscriminators = ['None'],
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
					getJetMCFlavour = False, # jet flavor should always be disabled for groomed jets
					genParticles = cms.InputTag(genParticlesLabel),
					outputModules = ['outputFile']
					) 

			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'Pruned', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'Pruned', cut = Cut ) )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'PrunedSubjets',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Pruned', 'SubJets'),
					algo = jetalgo,  # needed for subjet b tagging
					rParam = jetSize,  # needed for subjet b tagging
					jetCorrections = subJEC if subJEC is not None else None, 
					pfCandidates = cms.InputTag( pfCand ),  
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ), 
					getJetMCFlavour = GetSubjetMCFlavour,
					genParticles = cms.InputTag(genParticlesLabel),
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNuPruned','SubJets'),
					explicitJTA = True,  # needed for subjet b tagging
					svClustering = True, # needed for subjet b tagging
					fatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod),             # needed for subjet flavor clustering
					groomedFatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod+'Pruned'), # needed for subjet flavor clustering
					outputModules = ['outputFile']
					) 

			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets', cut = Cut ) )

			## Establish references between PATified fat jets and subjets using the BoostedJetMerger
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked', 
					cms.EDProducer("BoostedJetMerger",
						jetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'Pruned'),
						subjetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets')
						))
			jetSeq += getattr(proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked' )
			elemToKeep += [ 'keep *_selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked_*_*' ]
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked' )
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets' )


	if addTrimming:

		setattr( proc, jetalgo+'PFJets'+PUMethod+'Trimmed', 
				ak8PFJetsCHSTrimmed.clone( 
					rParam = jetSize, 
					src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents'),
					jetAlgorithm = algorithm,
					rFilt= rFiltTrim,
					trimPtFracMin= ptFrac) ) 
		setattr( proc, jetalgo+'PFJets'+PUMethod+'TrimmedMass', 
				ak8PFJetsCHSTrimmedMass.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
					matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Trimmed'), 
					distMax = cms.double( jetSize ) ) )

		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'TrimmedMass_*_*'] 
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Trimmed' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'TrimmedMass' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'TrimmedMass']
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'TrimmedMass' )

	if addFiltering:

		setattr( proc, jetalgo+'PFJets'+PUMethod+'Filtered', 
				ak8PFJetsCHSFiltered.clone( 
					src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents' ),
					rParam = jetSize, 
					jetAlgorithm = algorithm,
					rFilt= rfilt,
					nFilt= nfilt ) ) 
		setattr( proc, jetalgo+'PFJets'+PUMethod+'FilteredMass', 
				ak8PFJetsCHSFilteredMass.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
					matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Filtered'), 
					distMax = cms.double( jetSize ) ) )
		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'FilteredMass_*_*'] 
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Filtered' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'FilteredMass' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'FilteredMass']
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'FilteredMass' )

	if addCMSTopTagger :

		if 'CA' in jetALGO : 

			setattr( proc, 'cmsTopTagPFJets'+PUMethod,  
					cms.EDProducer("CATopJetProducer",
						PFJetParameters.clone( 
							src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents' ),
							doAreaFastjet = cms.bool(True),
							doRhoFastjet = cms.bool(False),
							jetPtMin = cms.double(100.0)
							),
						AnomalousCellParameters,
						CATopJetParameters.clone( jetCollInstanceName = cms.string("SubJets"),
							verbose = cms.bool(False),
							algorithm = cms.int32(1), # 0 = KT, 1 = CA, 2 = anti-KT
							tagAlgo = cms.int32(0), #0=legacy top
							useAdjacency = cms.int32(2), # modified adjacency
							centralEtaCut = cms.double(2.5), # eta for defining "central" jets
							sumEtBins = cms.vdouble(0,1600,2600), # sumEt bins over which cuts vary. vector={bin 0 lower bound, bin 1 lower bound, ...}
							rBins = cms.vdouble(0.8,0.8,0.8), # Jet distance paramter R. R values depend on sumEt bins.
							ptFracBins = cms.vdouble(0.05,0.05,0.05), # minimum fraction of central jet pt for subjets (deltap)
							deltarBins = cms.vdouble(0.19,0.19,0.19), # Applicable only if useAdjacency=1. deltar adjacency values for each sumEtBin
							nCellBins = cms.vdouble(1.9,1.9,1.9),
							),
						jetAlgorithm = cms.string("CambridgeAachen"),
						rParam = cms.double(jetSize),
						writeCompound = cms.bool(True)
						)
					)
			
			setattr( proc, "CATopTagInfos", 
					cms.EDProducer("CATopJetTagger",
						src = cms.InputTag('cmsTopTagPFJets'+PUMethod),
						TopMass = cms.double(171),
						TopMassMin = cms.double(0.),
						TopMassMax = cms.double(250.),
						WMass = cms.double(80.4),
						WMassMin = cms.double(0.0),
						WMassMax = cms.double(200.0),
						MinMassMin = cms.double(0.0),
						MinMassMax = cms.double(200.0),
						verbose = cms.bool(False)
						)
					)
			addJetCollection(
					proc,
					labelName = 'CMSTopTag'+PUMethod,
					jetSource = cms.InputTag('cmsTopTagPFJets'+PUMethod),
					jetCorrections = JEC if JEC is not None else None, 
					pfCandidates = cms.InputTag( pfCand ),  
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ), 
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag(jetalgo+'GenJetsNoNu'),
					getJetMCFlavour = False, # jet flavor should always be disabled for groomed jets
					genParticles = cms.InputTag(genParticlesLabel)
					)
			getattr(proc,'patJetsCMSTopTag'+PUMethod).addTagInfos = True
			getattr(proc,'patJetsCMSTopTag'+PUMethod).tagInfoSources = cms.VInputTag( cms.InputTag('CATopTagInfos'))
			setattr( proc, 'selectedPatJetsCMSTopTag'+PUMethod, selectedPatJets.clone( src = 'patJetsCMSTopTag'+PUMethod, cut = Cut ) )

			addJetCollection(
					proc,
					labelName = 'CMSTopTag'+PUMethod+'Subjets',
					jetSource = cms.InputTag('cmsTopTagPFJets'+PUMethod, 'SubJets'),
					algo = jetalgo,  # needed for subjet b tagging
					rParam = jetSize,  # needed for subjet b tagging
					jetCorrections = subJEC if subJEC is not None else None, 
					pfCandidates = cms.InputTag( pfCand ),  
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ), 
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
					getJetMCFlavour = GetSubjetMCFlavour,
					explicitJTA = True,  # needed for subjet b tagging
					svClustering = True, # needed for subjet b tagging
					fatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod),             # needed for subjet flavor clustering
					groomedFatJets=cms.InputTag('patJetsCMSTopTag'+PUMethod), # needed for subjet flavor clustering
					genParticles = cms.InputTag(genParticlesLabel)
					)

			setattr( proc, 'selectedPatJetsCMSTopTag'+PUMethod+'Subjets', selectedPatJets.clone( src = 'patJetsCMSTopTag'+PUMethod+'Subjets', cut = Cut ) )

			setattr( proc, 'patJetsCMSTopTag'+PUMethod+'Packed', 
					cms.EDProducer("BoostedJetMerger",
						jetSrc=cms.InputTag('patJetsCMSTopTag'+PUMethod ),
						subjetSrc=cms.InputTag('patJetsCMSTopTag'+PUMethod+'Subjets')
						))
			jetSeq += getattr(proc, 'patJetsCMSTopTag'+PUMethod+'Packed' )
			elemToKeep += [ 'keep *_patJetsCMSTopTag'+PUMethod+'Packed_*_*' ]
			toolsUsed.append( 'patJetsCMSTopTag'+PUMethod+'Packed' )

		else: print '|---- jetToolBox: CMS recommends CambridgeAachen for CMS Top Tagger, you are using '+algorithm+'. JetToolbox will not run CMS Top Tagger.'

	if addMassDrop :

		if 'CA' in jetALGO : 
			setattr( proc, jetalgo+'PFJets'+PUMethod+'MassDropFiltered', 
					ca15PFJetsCHSMassDropFiltered.clone( 
						rParam = jetSize,
						src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents' ),
						) )
			setattr( proc, jetalgo+'PFJets'+PUMethod+'MassDropFilteredMass', ak8PFJetsCHSPrunedMass.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag(jetalgo+'PFJets'+PUMethod+'MassDropFiltered'), distMax = cms.double( jetSize ) ) )
			elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'MassDropFilteredMass_*_*' ]
			getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'MassDropFilteredMass' ]
			jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'MassDropFiltered' )
			jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'MassDropFilteredMass' )
		else: print '|---- jetToolBox: CMS recommends CambridgeAachen for Mass Drop, you are using '+algorithm+'. JetToolbox will not run Mass Drop.'
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'MassDropFilteredMass' )

	if addHEPTopTagger: 
		if ( jetSize >= 1. ) and ( 'CA' in jetALGO ): 

			setattr( proc, 'hepTopTagPFJets'+PUMethod, hepTopTagPFJetsCHS.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents' ) ) )
			setattr( proc, 'hepTopTagPFJets'+PUMethod+'Mass'+jetALGO, ak8PFJetsCHSPrunedMass.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag("hepTopTagPFJets"+PUMethod), distMax = cms.double( jetSize ) ) )
			elemToKeep += [ 'keep *_hepTopTagPFJets'+PUMethod+'Mass'+jetALGO+'_*_*' ]
			getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ 'hepTopTagPFJets'+PUMethod+'Mass'+jetALGO ]
			jetSeq += getattr(proc, 'hepTopTagPFJets'+PUMethod )
			jetSeq += getattr(proc, 'hepTopTagPFJets'+PUMethod+'Mass'+jetALGO )
			toolsUsed.append( 'hepTopTagPFJets'+PUMethod+'Mass'+jetALGO )
		else: print '|---- jetToolBox: CMS recommends CambridgeAachen for HEPTopTagger, you are using '+algorithm+', and a jet cone size bigger than 1. JetToolbox will not run HEP TopTagger.'

	####### Nsubjettiness
	if addNsub:
		from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

		rangeTau = range(1,maxTau+1)
		setattr( proc, 'Njettiness'+jetALGO+PUMethod, 
				Njettiness.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
					Njets=cms.vuint32(rangeTau),         # compute 1-, 2-, 3-, 4- subjettiness
					# variables for measure definition : 
					measureDefinition = cms.uint32( 0 ), # CMS default is normalized measure
					beta = cms.double(1.0),              # CMS default is 1
					R0 = cms.double( jetSize ),              # CMS default is jet cone size
					Rcutoff = cms.double( -999.0),       # not used by default
					# variables for axes definition :
					axesDefinition = cms.uint32( 6 ),    # CMS default is 1-pass KT axes
					nPass = cms.int32(-999),             # not used by default
					akAxesR0 = cms.double(-999.0) ) )        # not used by default

		elemToKeep += [ 'keep *_Njettiness'+jetALGO+PUMethod+'_*_*' ]
		for tau in rangeTau: getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += ['Njettiness'+jetALGO+PUMethod+':tau'+str(tau) ] 
		jetSeq += getattr(proc, 'Njettiness'+jetALGO+PUMethod )
		toolsUsed.append( 'Njettiness'+jetALGO+PUMethod )

	###### QJetsAdder
	'''
	if addQJets:
		### there must be a better way to do this random number introduction
		setattr( proc, 'RandomNumberGeneratorService', cms.Service("RandomNumberGeneratorService", 
							QJetsAdderCA8 = cms.PSet(initialSeed = cms.untracked.uint32(7)),
							QJetsAdderAK8 = cms.PSet(initialSeed = cms.untracked.uint32(31)),
							QJetsAdderCA15 = cms.PSet(initialSeed = cms.untracked.uint32(76)), ) )

		from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder
		setattr( proc, 'QJetsAdder'+jetALGO, 
				QJetsAdder.clone( src = cms.InputTag(jetalgo+'PFJets'+PUMethod), 
					jetRad = cms.double( jetSize ), 
					jetAlgo = cms.string( jetALGO[0:2] )))
		elemToKeep += [ 'keep *_QJetsAdder'+jetALGO+'_*_*' ]
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += ['QJetsAdder'+jetALGO+':QjetsVolatility']  
		jetSeq += getattr(proc, 'QJetsAdder'+jetALGO )
		toolsUsed.append( 'QJetsAdder'+jetALGO )
	'''

	###### QGTagger
	if addQGTagger:
		if ( 'ak4' in jetalgo ) and ( PUMethod not in ['Puppi','CS','SK'] ) :
			from RecoJets.JetProducers.QGTagger_cfi import QGTagger
			proc.load('RecoJets.JetProducers.QGTagger_cfi') 	## In 74X you need to run some stuff before.
			setattr( proc, 'QGTagger'+jetALGO+'PF'+PUMethod, 
					QGTagger.clone(
						srcJets = cms.InputTag(jetalgo+'PFJets'+PUMethod),    # Could be reco::PFJetCollection or pat::JetCollection (both AOD and miniAOD)
						jetsLabel = cms.string('QGL_AK4PF'+QGjetsLabel)        # Other options (might need to add an ESSource for it): see https://twiki.cern.ch/twiki/bin/viewauth/CMS/QGDataBaseVersion
						)
					)
			elemToKeep += [ 'keep *_QGTagger'+jetALGO+'PF'+PUMethod+'_*_*' ]
			getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += ['QGTagger'+jetALGO+'PF'+PUMethod+':qgLikelihood']  
			jetSeq += getattr(proc, 'QGTagger'+jetALGO+'PF'+PUMethod )

                        toolsUsed.append( 'QGTagger'+jetALGO+'PF'+PUMethod )
		else:
			print '|---- jetToolBox: QGTagger is optimized for ak4 jets with CHS. NOT running QGTagger'

			
	####### Pileup JetID
        if addPUJetID:
                if ( 'ak4' in jetalgo ) and ( 'CHS' in PUMethod ):
                        from RecoJets.JetProducers.pileupjetidproducer_cfi import pileupJetIdCalculator,pileupJetIdEvaluator

			setattr( proc, jetALGO+'PF'+PUMethod+'pileupJetIdCalculator',
					pileupJetIdCalculator.clone(
						jets = cms.InputTag(jetalgo+'PFJets'+PUMethod),
						rho = cms.InputTag("fixedGridRhoFastjetAll"),
						vertexes = cms.InputTag(pvLabel),
						applyJec = cms.bool(True),
						inputIsCorrected = cms.bool(False)
						))

			setattr( proc, jetALGO+'PF'+PUMethod+'pileupJetIdEvaluator',
					pileupJetIdEvaluator.clone(
						jetids = cms.InputTag(jetALGO+'PF'+PUMethod+'pileupJetIdCalculator'),
						jets = cms.InputTag(jetalgo+'PFJets'+PUMethod),
						rho = cms.InputTag("fixedGridRhoFastjetAll"),
						vertexes = cms.InputTag(pvLabel)
						)
					)

                        getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [jetALGO+'PF'+PUMethod+'pileupJetIdEvaluator:fullDiscriminant']
                        getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userInts.src += [jetALGO+'PF'+PUMethod+'pileupJetIdEvaluator:cutbasedId',jetALGO+'PF'+PUMethod+'pileupJetIdEvaluator:fullId']
                        elemToKeep += ['keep *_'+jetALGO+'PF'+PUMethod+'pileupJetIdEvaluator_*_*']
                        toolsUsed.append( jetALGO+'PF'+PUMethod+'pileupJetIdEvaluator' )
		else:
                        print '|---- jetToolBox: PUJetID is optimized for ak4 PFjets with CHS. NOT running PUJetID.'

	###### Energy Correlation Functions
	if addEnergyCorrFunc:
		from RecoJets.JetProducers.ECF_cfi import ECF 
		rangeECF = range(1,maxECF+1)
		setattr( proc, jetalgo+'PFJets'+PUMethod+'ECF', ECF.clone(
				src = cms.InputTag(jetalgo+'PFJets'+PUMethod),
				Njets = cms.vuint32( rangeECF ),
				beta = cms.double( ecfBeta ) 
				))

		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'ECF_*_*'] 
		for ecf in rangeECF: getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'ECF:ecf'+str(ecf) ]
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'ECF' )
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'ECF' )
	
	if hasattr(proc, 'patJetPartons'): proc.patJetPartons.particles = genParticlesLabel


	setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod, selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod, cut = Cut ) )
	elemToKeep += [ 'keep *_selectedPatJets'+jetALGO+'PF'+PUMethod+'_*_*' ]
	elemToKeep += [ 'drop *_selectedPatJets'+jetALGO+'PF'+PUMethod+'_calo*_*' ]
	elemToKeep += [ 'drop *_selectedPatJets'+jetALGO+'PF'+PUMethod+'_tagInfos_*' ]


	if len(toolsUsed) > 0 : print '|---- jetToolBox: Running '+', '.join(toolsUsed)+'.'
	print '|---- jetToolBox: Creating selectedPatJets'+jetALGO+'PF'+PUMethod+' collection.'

	### "return"
	setattr(proc, jetSequence, jetSeq)
	if hasattr(proc, outputFile): getattr(proc, outputFile).outputCommands += elemToKeep
	else: setattr( proc, outputFile, 
			cms.OutputModule('PoolOutputModule', 
				fileName = cms.untracked.string('jettoolbox.root'), 
				outputCommands = cms.untracked.vstring( elemToKeep ) ) )

	if runOnData:
		from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
		removeMCMatching(proc, names=['Jets'], outputModules=[outputFile])
Beispiel #17
0
def makeFatJets(process,
                src,
                algoLabel,
                jetRadius,
                colLabel,
                jetPtMin=150.,
                btagLabel=''):

    rLabel = algoLabel + '%d' % (int(jetRadius * 10))  # 'ak8'

    if algoLabel.lower() == 'ca':
        jetAlgo = 'CambridgeAachen'
    elif algoLabel.lower() == 'ak':
        jetAlgo = 'AntiKt'
    else:
        raise RuntimeError('Unknown jet algo ' + algoLabel)

    if jetRadius < 1.:
        sdZcut = 0.1
        sdBeta = 0.0
    else:
        sdZcut = 0.15
        sdBeta = 1.0

    ## Used for btagging & jet clustering (pvSource)
    ## CMS uses the particleFlow collection to compute the btag info regardless of the jet source collection.
    pfSource = 'particleFlow'
    pvSource = 'offlinePrimaryVertices'

    ########################################
    ##           CLUSTER JETS             ##
    ########################################

    jets = ak4PFJets.clone(jetAlgorithm=cms.string(jetAlgo),
                           rParam=cms.double(jetRadius),
                           src=cms.InputTag(src),
                           srcPVs=cms.InputTag(pvSource),
                           doAreaFastjet=cms.bool(True),
                           jetPtMin=cms.double(jetPtMin))

    jetsName = rLabel + colLabel  # 'ak8PFJetsCHS'
    setattr(process, jetsName, jets)

    softDropJets = jets.clone(useSoftDrop=cms.bool(True),
                              R0=cms.double(jetRadius),
                              zcut=cms.double(sdZcut),
                              beta=cms.double(sdBeta),
                              writeCompound=cms.bool(True),
                              useExplicitGhosts=cms.bool(True),
                              jetCollInstanceName=cms.string("SubJets"))

    softDropJetsName = jetsName + 'SoftDrop'
    setattr(process, softDropJetsName, softDropJets)

    softDropSubjetsName = softDropJetsName + 'Subjets'

    clustering = cms.Sequence(jets + softDropJets)

    ########################################
    ##           SUBSTRUCTURE             ##
    ########################################

    njettiness = Njettiness.clone(src=cms.InputTag(jetsName),
                                  R0=cms.double(jetRadius),
                                  Njets=cms.vuint32(1, 2, 3, 4))

    njettinessName = 'njettiness' + jetsName
    setattr(process, njettinessName, njettiness)

    sdKinematics = cms.EDProducer(
        'RecoJetDeltaRValueMapProducer',
        src=cms.InputTag(jetsName),
        matched=cms.InputTag(softDropJetsName),
        distMax=cms.double(1.5),
        values=cms.vstring('mass'),
        valueLabels=cms.vstring('Mass'),
    )

    sdKinematicsName = 'sdKinematics' + jetsName
    setattr(process, sdKinematicsName, sdKinematics)

    substructure = cms.Sequence(njettiness + sdKinematics)

    if btagLabel != '':
        #######################################
        ##         FATJET BTAGGING           ##
        #######################################

        initBTag(process, btagLabel, pfSource, pvSource)

        btags = [
            'pfJetProbabilityBJetTags', 'pfJetBProbabilityBJetTags',
            'pfCombinedSecondaryVertexV2BJetTags',
            'pfCombinedInclusiveSecondaryVertexV2BJetTags',
            'pfCombinedMVAV2BJetTags'
        ]

        btagInfos = []
        btagging = setupBTag(process,
                             jetsName,
                             jetsName,
                             btagLabel,
                             tags=btags,
                             addedTagInfos=btagInfos)

        doubleBtags = ['pfBoostedDoubleSecondaryVertexBJetTags']

        doubleBtagging = setupDoubleBTag(process,
                                         jetsName,
                                         jetsName,
                                         btagLabel,
                                         rLabel.lower(),
                                         addedTagInfos=btagInfos)

        #######################################
        ##         SUBJET BTAGGING           ##
        #######################################

        # Product: std::vector<reco::CandIPTagInfo>
        # IPTagInfo object contains a reference to jet
        subjetIpTagInfos = btag.pfImpactParameterTagInfos.clone(
            jets=cms.InputTag(softDropJetsName, 'SubJets'),
            primaryVertex=cms.InputTag(pvSource),
            candidates=cms.InputTag(pfSource),
            #      explicitJTA = cms.bool(True)
        )

        subjetIpTagInfosName = 'pfImpactParameterTagInfos' + softDropSubjetsName
        setattr(process, subjetIpTagInfosName, subjetIpTagInfos)

        # Product: std::vector<TemplatedSecondaryVertexTagInfo<reco::CandIPTagInfo, reco::VertexCompositePtrCandidate>>
        subjetInclSVFinderTagInfos = btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(
            trackIPTagInfos=cms.InputTag(subjetIpTagInfosName),
            extSVCollection=cms.InputTag(
                'inclusiveCandidateSecondaryVertices' + btagLabel),
            #      useSVClustering = cms.bool(True),
            #      jetAlgorithm = cms.string(jetAlgo),
            #      rParam = cms.double(jetRadius),
            #      fatJets = cms.InputTag(jetsName),
            #      groomedFatJets = cms.InputTag(softDropJetsName)
        )

        subjetInclSVFinderTagInfosName = 'pfInclusiveSecondaryVertexFinderTagInfos' + softDropSubjetsName
        setattr(process, subjetInclSVFinderTagInfosName,
                subjetInclSVFinderTagInfos)

        # Product: JetTagCollection (aka reco::JetFloatAssociation::Container aka edm::AssociationVector<reco::JetRefBaseProd, std::vector<float>>)
        # Uses the internal reference to the jet in the TagInfos object to create an AssociationVector
        subjetBjetTags = btag.pfCombinedInclusiveSecondaryVertexV2BJetTags.clone(
            tagInfos=cms.VInputTag(
                cms.InputTag(subjetIpTagInfosName),
                cms.InputTag(subjetInclSVFinderTagInfosName)))

        subjetBjetTagsName = 'pfCombinedInclusiveSecondaryVertexV2BJetTags' + softDropSubjetsName
        setattr(process, subjetBjetTagsName, subjetBjetTags)

        subjetBTagging = cms.Sequence(subjetIpTagInfos +
                                      subjetInclSVFinderTagInfos +
                                      subjetBjetTags)

    else:
        btagging = cms.Sequence()
        doubleBtagging = cms.Sequence()
        subjetBTagging = cms.Sequence()

    ########################################
    ##          MAKE PAT JETS             ##
    ########################################

    patJets = _patJets.clone(jetSource=cms.InputTag(jetsName),
                             getJetMCFlavour=cms.bool(False),
                             addGenJetMatch=cms.bool(False),
                             addGenPartonMatch=cms.bool(False),
                             addJetFlavourInfo=cms.bool(False),
                             addAssociatedTracks=cms.bool(False),
                             addJetCharge=cms.bool(False),
                             addJetCorrFactors=cms.bool(False),
                             addBTagInfo=cms.bool(True),
                             addTagInfos=cms.bool(True),
                             addDiscriminators=cms.bool(True),
                             tagInfoSources=cms.VInputTag(
                                 [cms.InputTag(name) for name in btagInfos]),
                             discriminatorSources=cms.VInputTag([
                                 cms.InputTag(name + jetsName)
                                 for name in btags + doubleBtags
                             ]))
    patJets.userData.userFloats.src = [
        cms.InputTag(njettinessName + ':tau1'),
        cms.InputTag(njettinessName + ':tau2'),
        cms.InputTag(njettinessName + ':tau3'),
        cms.InputTag(njettinessName + ':tau4'),
        cms.InputTag(sdKinematicsName + ':Mass')
    ]

    patJetsName = 'pat' + jetsName
    setattr(process, patJetsName, patJets)

    selectedJets = selectedPatJets.clone(src=cms.InputTag(patJetsName))

    selectedJetsName = 'selectedPat' + jetsName
    setattr(process, selectedJetsName, selectedJets)

    patSoftDropJets = _patJets.clone(jetSource=cms.InputTag(softDropJetsName),
                                     getJetMCFlavour=cms.bool(False),
                                     addGenJetMatch=cms.bool(False),
                                     addGenPartonMatch=cms.bool(False),
                                     addJetFlavourInfo=cms.bool(False),
                                     addTagInfos=cms.bool(False),
                                     addBTagInfo=cms.bool(False),
                                     addDiscriminators=cms.bool(False),
                                     addAssociatedTracks=cms.bool(False),
                                     addJetCharge=cms.bool(False),
                                     addJetCorrFactors=cms.bool(False))

    patSoftDropJetsName = 'pat' + softDropJetsName
    setattr(process, patSoftDropJetsName, patSoftDropJets)

    selectedSoftDropJets = selectedPatJets.clone(
        src=cms.InputTag(patSoftDropJetsName))

    selectedSoftDropJetsName = 'selectedPat' + softDropJetsName
    setattr(process, selectedSoftDropJetsName, selectedSoftDropJets)

    patSoftDropSubjets = _patJets.clone(
        jetSource=cms.InputTag(softDropJetsName, 'SubJets'),
        getJetMCFlavour=cms.bool(False),
        addGenJetMatch=cms.bool(False),
        addGenPartonMatch=cms.bool(False),
        addJetFlavourInfo=cms.bool(False),
        addAssociatedTracks=cms.bool(False),
        addJetCharge=cms.bool(False),
        addJetCorrFactors=cms.bool(False),
        addBTagInfo=cms.bool(True),
        addDiscriminators=cms.bool(True),
        addTagInfos=cms.bool(False),
        discriminatorSources=cms.VInputTag(cms.InputTag(subjetBjetTagsName)))

    patSoftDropSubjetsName = 'pat' + softDropJetsName + 'Subjets'
    setattr(process, patSoftDropSubjetsName, patSoftDropSubjets)

    selectedSoftDropSubjets = selectedPatJets.clone(
        src=cms.InputTag(patSoftDropSubjetsName))

    selectedSoftDropSubjetsName = 'selectedPat' + softDropSubjetsName
    setattr(process, selectedSoftDropSubjetsName, selectedSoftDropSubjets)

    pat = cms.Sequence(patJets + selectedJets + patSoftDropJets +
                       selectedSoftDropJets + patSoftDropSubjets +
                       selectedSoftDropSubjets)

    ###############################################
    ##     Pack subjets back into fat jets       ##
    ###############################################

    packedSoftDropJets = cms.EDProducer(
        'BoostedJetMerger',
        jetSrc=cms.InputTag(selectedSoftDropJetsName),
        subjetSrc=cms.InputTag(selectedSoftDropSubjetsName))

    packedSoftDropJetsName = 'packed' + softDropJetsName
    setattr(process, packedSoftDropJetsName, packedSoftDropJets)

    packedPatJets = cms.EDProducer('JetSubstructurePacker',
                                   jetSrc=cms.InputTag(selectedJetsName),
                                   distMax=cms.double(jetRadius),
                                   algoTags=cms.VInputTag(
                                       cms.InputTag(packedSoftDropJetsName)),
                                   algoLabels=cms.vstring('SoftDrop'),
                                   fixDaughters=cms.bool(False))

    packedPatJetsName = 'packed' + jetsName
    setattr(process, packedPatJetsName, packedPatJets)

    packing = cms.Sequence(packedSoftDropJets + packedPatJets)

    ##############################
    ##     Return a sequence    ##
    ##############################

    sequence = cms.Sequence(clustering + substructure + btagging +
                            doubleBtagging + subjetBTagging + pat + packing)

    return sequence
from RecoJets.JetProducers.QGTagger_cfi import *
AK4QGTaggerCHS           = QGTagger.clone()
AK4QGTaggerCHS.srcJets   = cms.InputTag('ak4PFJetsCHS')
AK4QGTaggerCHS.jetsLabel = cms.string('QGL_AK4PFchs')
AK4QGTaggerCHS.jec       = cms.InputTag("ak4PFCHSL1FastL2L3Corrector") # NOTE: use "ak4PFCHSL1FastL2L3Corrector" for MC / "ak4PFCHSL1FastL2L3ResidualCorrector" for Data

AK4QGTaggerSubJetsCHS           = AK4QGTaggerCHS.clone()
AK4QGTaggerSubJetsCHS.srcJets   = cms.InputTag('AK4caPFJetsSoftDropCHS','SubJets')
AK4QGTaggerSubJetsCHS.jetsLabel = cms.string('QGL_AK4PFchs')
AK4QGTaggerSubJetsCHS.jec       = cms.InputTag("ak4PFCHSL1FastL2L3Corrector") # NOTE: use "ak4PFCHSL1FastL2L3Corrector" for MC / "ak4PFCHSL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
AK4NjettinessCHS = Njettiness.clone(
    src   = cms.InputTag('ak4PFJetsCHS'),
    cone  = cms.double(0.4),
    Njets = cms.vuint32(1,2,3,4)
  )

#
# Define sequences
#
AK4genjetsequenceCHS = cms.Sequence(
  AK4GenJetsCHS 
  #AK4FlavorCHS
)

AK4jetsequenceCHS = cms.Sequence(
    AK4PFJetsCHS*   ### no need to run, already in AOD
    AK4caPFJetsPrunedCHS*
    AK4caPFJetsTrimmedCHS*
Beispiel #19
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akSoftDrop1CaloNjettiness = Njettiness.clone(
    src=cms.InputTag("akSoftDrop1CaloJets"), R0=cms.double(0.1))
akSoftDrop1CalopatJetsWithBtagging.userData.userFloats.src += [
    'akSoftDrop1CaloNjettiness:tau1', 'akSoftDrop1CaloNjettiness:tau2',
    'akSoftDrop1CaloNjettiness:tau3'
]

akSoftDrop1CaloJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akSoftDrop1CalopatJetsWithBtagging"),
    genjetTag='ak1HiGenJets',
    rParam=0.1,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
    fillGenJets=True,
    isMC=True,
import FWCore.ParameterSet.Config as cms
from BristolAnalysis.NTupleTools.BristolNTuple_PFCandidates_cfi import nTuplePFCands, puppi
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

njettiness = Njettiness.clone(
    src = cms.InputTag('nTuplePFCands', 'OneJet'),
	measureDefinition = cms.uint32(4),
	beta = cms.double(2.0),
	R0 = cms.double( 0.4 ),
	Rcutoff = cms.double( 0.4 ),
	Njets=cms.vuint32(1,2,3,4,5,6),
)

addNJettiness = cms.Sequence( puppi * nTuplePFCands * njettiness )

# addNJettiness = cms.Sequence( njettiness  )
CA8QGTaggerPuppi.jec = cms.InputTag(
    "ak8PuppiL1FastL2L3Corrector"
)  # NOTE: use "ca8PFPuppiL1FastL2L3Corrector" for MC / "ca8PFPuppiL1FastL2L3ResidualCorrector" for Data

CA8QGTaggerSubJetsPuppi = CA8QGTaggerPuppi.clone()
CA8QGTaggerSubJetsPuppi.srcJets = cms.InputTag('CA8caPFJetsSoftDropPuppi',
                                               'SubJets')
CA8QGTaggerSubJetsPuppi.jetsLabel = cms.string('QGL_AK4PFchs')
CA8QGTaggerSubJetsPuppi.jec = cms.InputTag(
    "ak8PuppiL1FastL2L3Corrector"
)  # NOTE: use "ca8PFPuppiL1FastL2L3Corrector" for MC / "ca8PFPuppiL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
CA8NjettinessPuppi = Njettiness.clone(src=cms.InputTag('CA8PFJetsPuppi'),
                                      R0=cms.double(0.8),
                                      Njets=cms.vuint32(1, 2, 3, 4))

CA8genjetsequencePuppi = cms.Sequence(CA8GenJetsPuppi * CA8FlavorPuppi)

#
# Define sequences
#
CA8jetsequencePuppi = cms.Sequence(
    CA8PFJetsPuppi * CA8caPFJetsPrunedPuppi * CA8caPFJetsTrimmedPuppi *
    CA8caPFJetsSoftDropPuppi * ak8PuppiL1FastL2L3Chain * CA8QGTaggerPuppi *
    CA8QGTaggerSubJetsPuppi * CA8NjettinessPuppi * CA8FlavorPuppi)

CA8jetsequencePuppiData = cms.Sequence(
    CA8PFJetsPuppi * CA8caPFJetsPrunedPuppi * CA8caPFJetsTrimmedPuppi *
    CA8caPFJetsSoftDropPuppi * ak8PuppiL1FastL2L3ResidualChain *
Beispiel #22
0
def makeFatJets(process, src, algoLabel, jetRadius, colLabel, jetPtMin = 150., btagLabel = ''):

  rLabel = algoLabel + '%d' % (int(jetRadius * 10)) # 'ak8'

  if algoLabel.lower() == 'ca':
    jetAlgo = 'CambridgeAachen'
  elif algoLabel.lower() == 'ak':
    jetAlgo = 'AntiKt'
  else:
    raise RuntimeError('Unknown jet algo ' + algoLabel)

  if jetRadius < 1.:
    sdZcut = 0.1
    sdBeta = 0.0
  else:
    sdZcut = 0.15
    sdBeta = 1.0

  ## Used for btagging & jet clustering (pvSource)
  ## CMS uses the particleFlow collection to compute the btag info regardless of the jet source collection.
  pfSource = 'particleFlow'
  pvSource = 'offlinePrimaryVertices'

  ########################################
  ##           CLUSTER JETS             ##
  ########################################

  jets = ak4PFJets.clone(
    jetAlgorithm = cms.string(jetAlgo),
    rParam = cms.double(jetRadius),
    src = cms.InputTag(src),
    srcPVs = cms.InputTag(pvSource),
    doAreaFastjet = cms.bool(True),
    jetPtMin = cms.double(jetPtMin)
  )

  jetsName = rLabel + colLabel # 'ak8PFJetsCHS'
  setattr(process, jetsName, jets)

  softDropJets = jets.clone(
    useSoftDrop = cms.bool(True),
    R0 = cms.double(jetRadius),
    zcut = cms.double(sdZcut),
    beta = cms.double(sdBeta),
    writeCompound = cms.bool(True),
    useExplicitGhosts = cms.bool(True),
    jetCollInstanceName = cms.string("SubJets")
  )

  softDropJetsName = jetsName + 'SoftDrop'
  setattr(process, softDropJetsName, softDropJets)

  softDropSubjetsName = softDropJetsName + 'Subjets'

  clustering = cms.Sequence(
    jets +
    softDropJets
  )
  
  ########################################
  ##           SUBSTRUCTURE             ##
  ########################################

  njettiness = Njettiness.clone(
    src = cms.InputTag(jetsName),
    R0 = cms.double(jetRadius),
    Njets = cms.vuint32(1,2,3,4)
  )

  njettinessName = 'njettiness' + jetsName
  setattr(process, njettinessName, njettiness)

  sdKinematics = cms.EDProducer('RecoJetDeltaRValueMapProducer',
    src = cms.InputTag(jetsName),
    matched = cms.InputTag(softDropJetsName),
    distMax = cms.double(1.5),
    values = cms.vstring('mass'),
    valueLabels = cms.vstring('Mass'),
  )

  sdKinematicsName = 'sdKinematics' + jetsName
  setattr(process, sdKinematicsName, sdKinematics)

  substructure = cms.Sequence(
    njettiness +
    sdKinematics
  )

  if btagLabel != '':
    #######################################
    ##         FATJET BTAGGING           ##
    #######################################

    initBTag(process, btagLabel, pfSource, pvSource)
  
    btags = [
      'pfJetProbabilityBJetTags',
      'pfJetBProbabilityBJetTags',
      'pfCombinedSecondaryVertexV2BJetTags',
      'pfCombinedInclusiveSecondaryVertexV2BJetTags',
      'pfCombinedMVAV2BJetTags'
    ]
  
    btagInfos = []
    btagging = setupBTag(process, jetsName, jetsName, btagLabel, tags = btags, addedTagInfos = btagInfos)

    doubleBtags = [
      'pfBoostedDoubleSecondaryVertexBJetTags'
    ]
    
    doubleBtagging = setupDoubleBTag(process, jetsName, jetsName, btagLabel, rLabel.lower(), addedTagInfos = btagInfos)

    #######################################
    ##         SUBJET BTAGGING           ##
    #######################################
  
    # Product: std::vector<reco::CandIPTagInfo>
    # IPTagInfo object contains a reference to jet
    subjetIpTagInfos = btag.pfImpactParameterTagInfos.clone(
      jets = cms.InputTag(softDropJetsName, 'SubJets'),
      primaryVertex = cms.InputTag(pvSource),
      candidates = cms.InputTag(pfSource),
#      explicitJTA = cms.bool(True)
    )
  
    subjetIpTagInfosName = 'pfImpactParameterTagInfos' + softDropSubjetsName
    setattr(process, subjetIpTagInfosName, subjetIpTagInfos)
  
    # Product: std::vector<TemplatedSecondaryVertexTagInfo<reco::CandIPTagInfo, reco::VertexCompositePtrCandidate>>
    subjetInclSVFinderTagInfos = btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(
      trackIPTagInfos = cms.InputTag(subjetIpTagInfosName),
      extSVCollection = cms.InputTag('inclusiveCandidateSecondaryVertices' + btagLabel),
#      useSVClustering = cms.bool(True),
#      jetAlgorithm = cms.string(jetAlgo),
#      rParam = cms.double(jetRadius),
#      fatJets = cms.InputTag(jetsName),
#      groomedFatJets = cms.InputTag(softDropJetsName)
    )
  
    subjetInclSVFinderTagInfosName = 'pfInclusiveSecondaryVertexFinderTagInfos' + softDropSubjetsName
    setattr(process, subjetInclSVFinderTagInfosName, subjetInclSVFinderTagInfos)
  
    # Product: JetTagCollection (aka reco::JetFloatAssociation::Container aka edm::AssociationVector<reco::JetRefBaseProd, std::vector<float>>)
    # Uses the internal reference to the jet in the TagInfos object to create an AssociationVector
    subjetBjetTags = btag.pfCombinedInclusiveSecondaryVertexV2BJetTags.clone(
      tagInfos = cms.VInputTag( 
        cms.InputTag(subjetIpTagInfosName), 
        cms.InputTag(subjetInclSVFinderTagInfosName)
      )
    )
  
    subjetBjetTagsName = 'pfCombinedInclusiveSecondaryVertexV2BJetTags' + softDropSubjetsName
    setattr(process, subjetBjetTagsName, subjetBjetTags)
  
    subjetBTagging = cms.Sequence(
      subjetIpTagInfos +
      subjetInclSVFinderTagInfos +
      subjetBjetTags
    )

  else:
    btagging = cms.Sequence()
    doubleBtagging = cms.Sequence()
    subjetBTagging = cms.Sequence()

  ########################################
  ##          MAKE PAT JETS             ##
  ########################################

  patJets = _patJets.clone(
    jetSource = cms.InputTag(jetsName),
    getJetMCFlavour = cms.bool(False),
    addGenJetMatch = cms.bool(False),
    addGenPartonMatch = cms.bool(False),
    addJetFlavourInfo = cms.bool(False),
    addAssociatedTracks = cms.bool(False),
    addJetCharge = cms.bool(False),
    addJetCorrFactors = cms.bool(False),
    addBTagInfo = cms.bool(True),
    addTagInfos = cms.bool(True),
    addDiscriminators = cms.bool(True),
    tagInfoSources = cms.VInputTag([cms.InputTag(name) for name in btagInfos]),
    discriminatorSources = cms.VInputTag([cms.InputTag(name + jetsName) for name in btags + doubleBtags])
  )
  patJets.userData.userFloats.src = [
    cms.InputTag(njettinessName + ':tau1'),
    cms.InputTag(njettinessName + ':tau2'),
    cms.InputTag(njettinessName + ':tau3'),
    cms.InputTag(njettinessName + ':tau4'),
    cms.InputTag(sdKinematicsName + ':Mass')
  ]

  patJetsName = 'pat' + jetsName
  setattr(process, patJetsName, patJets)

  selectedJets = selectedPatJets.clone(
    src = cms.InputTag(patJetsName)
  )

  selectedJetsName = 'selectedPat' + jetsName
  setattr(process, selectedJetsName, selectedJets)

  patSoftDropJets = _patJets.clone(
    jetSource = cms.InputTag(softDropJetsName),
    getJetMCFlavour = cms.bool(False),
    addGenJetMatch = cms.bool(False),
    addGenPartonMatch = cms.bool(False),
    addJetFlavourInfo = cms.bool(False),
    addTagInfos = cms.bool(False),
    addBTagInfo = cms.bool(False),
    addDiscriminators = cms.bool(False),
    addAssociatedTracks = cms.bool(False),
    addJetCharge = cms.bool(False),
    addJetCorrFactors = cms.bool(False)
  )

  patSoftDropJetsName = 'pat' + softDropJetsName
  setattr(process, patSoftDropJetsName, patSoftDropJets)

  selectedSoftDropJets = selectedPatJets.clone(
    src = cms.InputTag(patSoftDropJetsName)
  )

  selectedSoftDropJetsName = 'selectedPat' + softDropJetsName
  setattr(process, selectedSoftDropJetsName, selectedSoftDropJets)

  patSoftDropSubjets = _patJets.clone(
    jetSource = cms.InputTag(softDropJetsName, 'SubJets'),
    getJetMCFlavour = cms.bool(False),
    addGenJetMatch = cms.bool(False),
    addGenPartonMatch = cms.bool(False),
    addJetFlavourInfo = cms.bool(False),
    addAssociatedTracks = cms.bool(False),
    addJetCharge = cms.bool(False),
    addJetCorrFactors = cms.bool(False),
    addBTagInfo = cms.bool(True),
    addDiscriminators = cms.bool(True),
    addTagInfos = cms.bool(False),
    discriminatorSources = cms.VInputTag(
      cms.InputTag(subjetBjetTagsName)
    )
  )

  patSoftDropSubjetsName = 'pat' + softDropJetsName + 'Subjets'
  setattr(process, patSoftDropSubjetsName, patSoftDropSubjets)

  selectedSoftDropSubjets = selectedPatJets.clone(
    src = cms.InputTag(patSoftDropSubjetsName)
  )

  selectedSoftDropSubjetsName = 'selectedPat' + softDropSubjetsName
  setattr(process, selectedSoftDropSubjetsName, selectedSoftDropSubjets)

  pat = cms.Sequence(
    patJets +
    selectedJets +
    patSoftDropJets +
    selectedSoftDropJets +
    patSoftDropSubjets +
    selectedSoftDropSubjets
  )

  ###############################################
  ##     Pack subjets back into fat jets       ##
  ###############################################

  packedSoftDropJets = cms.EDProducer('BoostedJetMerger',
    jetSrc = cms.InputTag(selectedSoftDropJetsName),
    subjetSrc = cms.InputTag(selectedSoftDropSubjetsName)
  )

  packedSoftDropJetsName = 'packed' + softDropJetsName
  setattr(process, packedSoftDropJetsName, packedSoftDropJets)

  packedPatJets = cms.EDProducer('JetSubstructurePacker',
    jetSrc = cms.InputTag(selectedJetsName),
    distMax = cms.double(jetRadius),
    algoTags = cms.VInputTag(cms.InputTag(packedSoftDropJetsName)),
    algoLabels = cms.vstring('SoftDrop'),
    fixDaughters = cms.bool(False)
  )

  packedPatJetsName = 'packed' + jetsName
  setattr(process, packedPatJetsName, packedPatJets)

  packing = cms.Sequence(
    packedSoftDropJets +
    packedPatJets
  )

  ##############################
  ##     Return a sequence    ##
  ##############################

  sequence = cms.Sequence(
    clustering + 
    substructure +
    btagging +
    doubleBtagging +
    subjetBTagging +
    pat +
    packing
  )

  return sequence
Beispiel #23
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akCsSoftDropZ05B155PFNjettiness = Njettiness.clone(
    src=cms.InputTag("akCsSoftDropZ05B155PFJets"), R0=cms.double(0.5))

akCsSoftDropZ05B155PFpatJetsWithBtagging.userData.userFloats.src += [
    'akCsSoftDropZ05B155PFNjettiness:tau1',
    'akCsSoftDropZ05B155PFNjettiness:tau2',
    'akCsSoftDropZ05B155PFNjettiness:tau3'
]

akCsSoftDropZ05B155PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akCsSoftDropZ05B155PFpatJetsWithBtagging"),
    genjetTag='ak5HiGenJets',
    rParam=0.5,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlow'),
    trackTag=cms.InputTag("generalTracks"),
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akPu4CaloNjettiness = Njettiness.clone(src=cms.InputTag("akPu4CaloJets"),
                                       R0=cms.double(0.4))
akPu4CalopatJetsWithBtagging.userData.userFloats.src += [
    'akPu4CaloNjettiness:tau1', 'akPu4CaloNjettiness:tau2',
    'akPu4CaloNjettiness:tau3'
]

akPu4CaloJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akPu4CalopatJetsWithBtagging"),
    genjetTag='ak4HiGenJets',
    rParam=0.4,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
    fillGenJets=True,
    isMC=True,
Beispiel #25
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akFilter1CaloNjettiness = Njettiness.clone(
    src=cms.InputTag("akFilter1CaloJets"), R0=cms.double(0.1))
akFilter1CalopatJetsWithBtagging.userData.userFloats.src += [
    'akFilter1CaloNjettiness:tau1', 'akFilter1CaloNjettiness:tau2',
    'akFilter1CaloNjettiness:tau3'
]

akFilter1CaloJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akFilter1CalopatJetsWithBtagging"),
    genjetTag='ak1HiGenJets',
    rParam=0.1,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
    fillGenJets=True,
    isMC=True,
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=False,
    addGenPartonMatch=False,
    addGenJetMatch=False,
    embedGenJetMatch=False,
    embedGenPartonMatch=False,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akVsFilter6CaloNjettiness = Njettiness.clone(
    src=cms.InputTag("akVsFilter6CaloJets"), R0=cms.double(0.6))
akVsFilter6CalopatJetsWithBtagging.userData.userFloats.src += [
    'akVsFilter6CaloNjettiness:tau1', 'akVsFilter6CaloNjettiness:tau2',
    'akVsFilter6CaloNjettiness:tau3'
]

akVsFilter6CaloJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akVsFilter6CalopatJetsWithBtagging"),
    genjetTag='ak6GenJets',
    rParam=0.6,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlow'),
    trackTag=cms.InputTag("generalTracks"),
    fillGenJets=False,
    isMC=False,
Beispiel #27
0
#add_fatjets_subjets(process, 'ca8PuppiJets', 'cmsTopTagPuppi', genjets_name = lambda s: s.replace('Puppi', 'Gen'))
add_fatjets_subjets(process, 'ca15PuppiJets', 'hepTopTagPuppi')
#add_fatjets_subjets(process, 'ca8PuppiJets', 'ca8PuppiJetsSoftDrop')

# configure PAT for miniAOD:
#process.patJetPartons.particles = 'prunedGenParticles'

from PhysicsTools.PatAlgos.tools.pfTools import *
## Adapt primary vertex collection
adaptPVs(process, pvCollection=cms.InputTag('offlineSlimmedPrimaryVertices'))

# Add subjet variables (on ungroomed jets only!)
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder

process.NjettinessAk8CHS = Njettiness.clone(src=cms.InputTag("ak8CHSJets"),
                                            cone=cms.double(0.8))
process.NjettinessCa15CHS = Njettiness.clone(src=cms.InputTag("ca15CHSJets"),
                                             cone=cms.double(1.5),
                                             R0=cms.double(1.5))
process.NjettinessCa15SoftDropCHS = Njettiness.clone(
    src=cms.InputTag("ca15CHSJetsSoftDropforsub"),
    Njets=cms.vuint32(1, 2, 3),  # compute 1-, 2-, 3- subjettiness
    # variables for measure definition :
    measureDefinition=cms.uint32(0),  # CMS default is normalized measure
    beta=cms.double(1.0),  # CMS default is 1
    R0=cms.double(1.5),  # CMS default is jet cone size
    Rcutoff=cms.double(999.0),  # not used by default
    # variables for axes definition :
    axesDefinition=cms.uint32(6),  # CMS default is 1-pass KT axes
    nPass=cms.int32(999),  # not used by default
    akAxesR0=cms.double(999.0)  # not used by default
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akVsSoftDrop6PFNjettiness = Njettiness.clone(
    src=cms.InputTag("akVsSoftDrop6PFJets"), R0=cms.double(0.6))
akVsSoftDrop6PFpatJetsWithBtagging.userData.userFloats.src += [
    'akVsSoftDrop6PFNjettiness:tau1', 'akVsSoftDrop6PFNjettiness:tau2',
    'akVsSoftDrop6PFNjettiness:tau3'
]

akVsSoftDrop6PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akVsSoftDrop6PFpatJetsWithBtagging"),
    genjetTag='ak6GenJets',
    rParam=0.6,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlow'),
    trackTag=cms.InputTag("generalTracks"),
    fillGenJets=True,
    isMC=True,
Beispiel #29
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akPuSoftDropZ05B154PFNjettiness = Njettiness.clone(
    src=cms.InputTag("akPuSoftDropZ05B154PFJets"), R0=cms.double(0.4))

akPuSoftDropZ05B154PFpatJetsWithBtagging.userData.userFloats.src += [
    'akPuSoftDropZ05B154PFNjettiness:tau1',
    'akPuSoftDropZ05B154PFNjettiness:tau2',
    'akPuSoftDropZ05B154PFNjettiness:tau3'
]

akPuSoftDropZ05B154PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akPuSoftDropZ05B154PFpatJetsWithBtagging"),
    genjetTag='ak4HiSignalGenJets',
    rParam=0.4,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
from RecoJets.JetProducers.QGTagger_cfi import *
CA15QGTaggerPuppi           = QGTagger.clone()
CA15QGTaggerPuppi.srcJets   = cms.InputTag('CA15PFJetsPuppi')
CA15QGTaggerPuppi.jetsLabel = cms.string('QGL_AK4PFchs')
CA15QGTaggerPuppi.jec       = cms.InputTag("ca15PuppiL1FastL2L3Corrector") # NOTE: use "ca15PFPuppiL1FastL2L3Corrector" for MC / "ca15PFPuppiL1FastL2L3ResidualCorrector" for Data

CA15QGTaggerSubJetsPuppi           = CA15QGTaggerPuppi.clone()
CA15QGTaggerSubJetsPuppi.srcJets   = cms.InputTag('CA15caPFJetsSoftDropPuppi','SubJets')
CA15QGTaggerSubJetsPuppi.jetsLabel = cms.string('QGL_AK4PFchs')
CA15QGTaggerSubJetsPuppi.jec       = cms.InputTag("ca15PuppiL1FastL2L3Corrector") # NOTE: use "ca15PFPuppiL1FastL2L3Corrector" for MC / "ca15PFPuppiL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
CA15NjettinessPuppi = Njettiness.clone(
    src   = cms.InputTag('CA15PFJetsPuppi'),
    cone  = cms.double(1.5),
    Njets = cms.vuint32(1,2,3,4)
  )

CA15genjetsequencePuppi = cms.Sequence(
  CA15GenJetsPuppi* 
  CA15FlavorPuppi
)

#
# Define sequences
#
CA15jetsequencePuppi = cms.Sequence(
    CA15PFJetsPuppi*
    CA15caPFJetsPrunedPuppi*
    CA15caPFJetsTrimmedPuppi*
Beispiel #31
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=False,
    addGenPartonMatch=False,
    addGenJetMatch=False,
    embedGenJetMatch=False,
    embedGenPartonMatch=False,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akFlowPuCs4PFNjettiness = Njettiness.clone(
    src=cms.InputTag("akFlowPuCs4PFJets"), R0=cms.double(0.4))

akFlowPuCs4PFpatJetsWithBtagging.userData.userFloats.src += [
    'akFlowPuCs4PFNjettiness:tau1', 'akFlowPuCs4PFNjettiness:tau2',
    'akFlowPuCs4PFNjettiness:tau3'
]

akFlowPuCs4PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akFlowPuCs4PFpatJetsWithBtagging"),
    genjetTag='ak4HiSignalGenJets',
    rParam=0.4,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlow'),
    trackTag=cms.InputTag("generalTracks"),
    fillGenJets=False,
#pileupJetIdEvaluator.rho = cms.InputTag("fixedGridRhoFastjetAll")  
"""
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#QGTagger
#"""
from RecoJets.JetProducers.QGTagger_cfi import QGTagger

QGTagger.srcJets = cms.InputTag("ak4PFJetsCHS")
QGTagger.jetsLabel = cms.string('QGL_AK5PFchs')
#"""
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#Njettiness

from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

NjettinessCA8 = Njettiness.clone()
NjettinessCA8.src = cms.InputTag("ca8PFJetsCHS")
NjettinessCA8.cone = cms.double(0.8)

NjettinessAK8 = NjettinessCA8.clone()
NjettinessAK8.src = cms.InputTag("ak8PFJetsCHS")


#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#QJetsAdder

RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
                                                   QJetsAdderCA8 = cms.PSet(initialSeed = cms.untracked.uint32(7)),
                                                   QJetsAdderAK8 = cms.PSet(initialSeed = cms.untracked.uint32(31)))

from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder
Beispiel #33
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akFlowPuCsSoftDrop5PFNjettiness = Njettiness.clone(
    src=cms.InputTag("akFlowPuCsSoftDrop5PFJets"), R0=cms.double(0.5))

akFlowPuCsSoftDrop5PFpatJetsWithBtagging.userData.userFloats.src += [
    'akFlowPuCsSoftDrop5PFNjettiness:tau1',
    'akFlowPuCsSoftDrop5PFNjettiness:tau2',
    'akFlowPuCsSoftDrop5PFNjettiness:tau3'
]

akFlowPuCsSoftDrop5PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akFlowPuCsSoftDrop5PFpatJetsWithBtagging"),
    genjetTag='ak5GenJets',
    rParam=0.5,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlow'),
    trackTag=cms.InputTag("generalTracks"),
Beispiel #34
0
def jetToolbox( proc, jetType, jetSequence, outputFile, 
		PUMethod='CHS',                    #### Options: Puppi, CS, SK, Plain
		JETCorrPayload='None', JETCorrLevels = [ 'None' ],
		subJETCorrPayload='None', subJETCorrLevels = [ 'None' ],
		miniAOD=True,
		Cut = '', 
		addPruning=False, zCut=0.1, rCut=0.5, addPrunedSubjets=False,
		addSoftDrop=False, betaCut=0.0,  zCutSD=0.1, addSoftDropSubjets=False,
		addTrimming=False, rFiltTrim=0.2, ptFrac=0.03,
		addFiltering=False, rfilt=0.3, nfilt=3,
		addCMSTopTagger=False,
		addMassDrop=False,
		addHEPTopTagger=False,
		addNsub=False, maxTau=4, 
		addQJets=False 
		):
	
	###############################################################################
	#######  Verifying some inputs and defining variables
	###############################################################################
	print '|---- jetToolbox: Initialyzing...'
	supportedJetAlgos = { 'ak': 'AntiKt', 'ca' : 'CambridgeAachen', 'kt' : 'Kt' }
	recommendedJetAlgos = [ 'ak4', 'ak8', 'ca4', 'ca8', 'ca10' ]
	payloadList = [ 'AK1PFchs', 'AK2PFchs', 'AK3PFchs', 'AK4PFchs', 'AK5PFchs', 'AK6PFchs', 'AK7PFchs', 'AK8PFchs', 'AK9PFchs', 'AK10PFchs' ]
	JECLevels = [ 'L1Offset', 'L1FastJet', 'L1JPTOffset', 'L2Relative', 'L3Absolute', 'L5Falvour', 'L7Parton' ]
	jetAlgo = ''
	algorithm = ''
	size = ''
	for type, tmpAlgo in supportedJetAlgos.iteritems(): 
		if type in jetType.lower():
			jetAlgo = type
			algorithm = tmpAlgo
			size = jetType.replace( type, '' )

	jetSize = 0.
	if int(size) in range(0, 20): jetSize = int(size)/10.
	else: print '|---- jetToolBox: jetSize has not a valid value. Insert a number between 1 and 20 after algorithm, like: AK8'
	### Trick for uppercase/lowercase algo name
	jetALGO = jetAlgo.upper()+size
	jetalgo = jetAlgo.lower()+size
	if jetalgo not in recommendedJetAlgos: print '|---- jetToolBox: CMS recommends the following jet algoritms: '+' '.join(recommendedJetAlgos)+'. You are using', jetalgo,'.'

	if JETCorrPayload not in payloadList:
		if( int(size) > 10 ): 
			size = '10' 
			print '|---- jetToolbox: For jets bigger than 1.0, the jet corrections are AK10PFchs.'
		if not 'None' in JETCorrPayload: print '|---- jetToolBox: Payload given for Jet corrections ('+JETCorrPayload+') is not correct. Using a default AK'+size+'PFchs instead.'
		JETCorrPayload = 'AK'+size+'PFchs'
	else: print '|---- jetToolBox: Using '+JETCorrPayload+' payload for jet corrections.'

	if not set(JETCorrLevels).issubset(set(JECLevels)) :
		if not 'None' in JETCorrLevels: print '|---- jetToolbox: JEC levels given ( '+' '.join(JETCorrLevels)+' ) are incorrect. Using the default levels: L1FastJet, L2Relative, L3Absolute.'
		JETCorrLevels = ['L1FastJet', 'L2Relative', 'L3Absolute']
	
	print '|---- jetToolBox: Applying these jet corrections: ( '+JETCorrPayload+', '+' '.join(JETCorrLevels)+' )'
	JEC = ( JETCorrPayload, JETCorrLevels , 'None')

	if addPrunedSubjets or addSoftDropSubjets or addCMSTopTagger:
		if subJETCorrPayload not in payloadList: 
			if not 'None' in subJETCorrPayload: print '|---- jetToolBox: Payload given for subjet corrections ('+JETCorrPayload+') is not correct. Using default AK4PFchs instead.'
			subJETCorrPayload = 'AK4PFchs'
		if not set(subJETCorrLevels).issubset(set(JECLevels)) or not subJETCorrLevels:
			if not 'None' in subJETCorrLevels: print '|---- jetToolbox: Subjet JEC levels given ( '+' '.join(subJETCorrLevels)+' ) are incorrect. Using the default levels: L1FastJet, L2Relative, L3Absolute.'
			subJETCorrLevels = ['L1FastJet', 'L2Relative', 'L3Absolute']
		print '|---- jetToolBox: Applying these subjet corrections: ( '+subJETCorrPayload+', '+' '.join(subJETCorrLevels)+' )'
		subJEC = ( subJETCorrPayload, subJETCorrLevels , 'None')


	#################################################################################
	####### Toolbox start 
	#################################################################################

	elemToKeep = []
	jetSeq = cms.Sequence()
	genParticlesLabel = ''
	pvLabel = ''
	tvLabel = ''
	toolsUsed = []

	#### For MiniAOD
	if miniAOD:

		print '|---- jetToolBox: JETTOOLBOX RUNNING ON MiniAOD FOR '+jetALGO+' JETS USING '+PUMethod

		genParticlesLabel = 'prunedGenParticles'
		pvLabel = 'offlineSlimmedPrimaryVertices'
		svLabel = 'slimmedSecondaryVertices'
		tvLabel = 'unpackedTracksAndVertices'
		pfCand = 'packedPFCandidates'

		setattr( proc, 'chs', cms.EDFilter('CandPtrSelector', src = cms.InputTag('packedPFCandidates'), cut = cms.string('fromPV')) )
		jetSeq += getattr(proc, 'chs')


		## Filter out neutrinos from packed GenParticles
		setattr( proc, 'packedGenParticlesForJetsNoNu', 
				cms.EDFilter("CandPtrSelector", 
					src = cms.InputTag("packedGenParticles"), 
					cut = cms.string("abs(pdgId) != 12 && abs(pdgId) != 14 && abs(pdgId) != 16")
					))
		jetSeq += getattr(proc, 'packedGenParticlesForJetsNoNu' )
		    
		setattr( proc, jetalgo+'GenJetsNoNu', 
				ak4GenJets.clone( src = 'packedGenParticlesForJetsNoNu', 
					rParam = jetSize, 
					jetAlgorithm = algorithm ) ) 
		jetSeq += getattr(proc, jetalgo+'GenJetsNoNu' )
		#fixedGridRhoFastjetAll.pfCandidatesTag = 'packedPFCandidates'

		#for Inclusive Vertex Finder
		proc.load('PhysicsTools.PatAlgos.slimming.unpackedTracksAndVertices_cfi')

	#### For AOD
	else:
		print '|---- jetToolBox: JETTOOLBOX RUNNING ON AOD FOR '+jetALGO+' JETS USING '+PUMethod

		genParticlesLabel = 'genParticles'
		pvLabel = 'offlinePrimaryVertices'
		tvLabel = 'generalTracks'
		pfCand = 'particleFlow'
		svLabel = 'inclusiveSecondaryVertices'

		proc.load('RecoJets.Configuration.GenJetParticles_cff')
		proc.load('CommonTools.ParticleFlow.pfNoPileUpJME_cff')
		setattr( proc, jetalgo+'GenJetsNoNu', ak4GenJets.clone( src = 'genParticlesForJetsNoNu', rParam = jetSize, jetAlgorithm = algorithm ) ) 
		jetSeq += getattr(proc, jetalgo+'GenJetsNoNu' )
		
		

	## b-tag discriminators
	bTagDiscriminators = [
			'pfTrackCountingHighEffBJetTags',
			'pfTrackCountingHighPurBJetTags',
			'pfJetProbabilityBJetTags',
			'pfJetBProbabilityBJetTags',
			'pfSimpleSecondaryVertexHighEffBJetTags',
			'pfSimpleSecondaryVertexHighPurBJetTags',
			'pfCombinedSecondaryVertexBJetTags',
			'pfCombinedInclusiveSecondaryVertexV2BJetTags'
	    ]

	####  Creating PATjets
	if 'Puppi' in PUMethod:

		proc.load('CommonTools.PileupAlgos.Puppi_cff')
		from RecoJets.JetProducers.ak4PFJetsPuppi_cfi import ak4PFJetsPuppi
		setattr( proc, jetalgo+'PFJetsPuppi', 
				ak4PFJetsPuppi.clone( doAreaFastjet = True, 
					rParam = jetSize, 
					jetAlgorithm = algorithm ) )  
		if miniAOD:
			puppi.candName = cms.InputTag('packedPFCandidates')
			puppi.vertexName = cms.InputTag('offlineSlimmedPrimaryVertices')
		jetSeq += getattr(proc, 'puppi' )
		jetSeq += getattr(proc, jetalgo+'PFJetsPuppi' )

	elif 'CS' in PUMethod:

		from RecoJets.JetProducers.ak4PFJetsCS_cfi import ak4PFJetsCS
		setattr( proc, jetalgo+'PFJetsCS', 
				ak4PFJetsCS.clone( doAreaFastjet = True, 
					csRParam = cms.double(jetSize),
					jetAlgorithm = algorithm ) ) 
		if miniAOD: getattr( proc, jetalgo+'PFJetsCS').src = 'chs'
		jetSeq += getattr(proc, jetalgo+'PFJetsCS' )

		#setattr( proc, jetalgo+'PFJetsCSConstituents', ak8PFJetsCSConstituents.clone( src = cms.InputTag(jetalgo+'PFJetsCS') ) )
		jetSeq += getattr(proc, jetalgo+'PFJetsCS' )

	elif 'SK' in PUMethod:

		proc.load('CommonTools.PileupAlgos.softKiller_cfi')
		from RecoJets.JetProducers.ak4PFJetsSK_cfi import ak4PFJetsSK
		setattr( proc, jetalgo+'PFJetsSK', 
				ak4PFJetsSK.clone( rParam = jetSize, 
					jetAlgorithm = algorithm ) ) 
		if miniAOD: getattr( proc, 'softKiller' ).PFCandidates = cms.InputTag('packedPFCandidates')
		jetSeq += getattr(proc, 'softKiller' )
		jetSeq += getattr(proc, jetalgo+'PFJetsSK' )
	
	elif 'CHS' in PUMethod: 
		setattr( proc, jetalgo+'PFJetsCHS', 
				ak4PFJetsCHS.clone( 
					doAreaFastjet = True, 
					rParam = jetSize, 
					jetAlgorithm = algorithm ) ) 
		if miniAOD: getattr( proc, jetalgo+'PFJetsCHS').src = 'chs'
		jetSeq += getattr(proc, jetalgo+'PFJetsCHS' )
	else: 
		PUMethod = ''
		setattr( proc, jetalgo+'PFJets', 
				ak4PFJets.clone( 
					doAreaFastjet = True, 
					rParam = jetSize, 
					jetAlgorithm = algorithm ) ) 
		if miniAOD: getattr( proc, jetalgo+'PFJets').src = 'packedPFCandidates'
		jetSeq += getattr(proc, jetalgo+'PFJets' )

	#if miniAOD: setattr( proc, jetalgo+'PFJets'+PUMethod+'Constituents', cms.EDFilter("MiniAODJetConstituentSelector", src = cms.InputTag( jetalgo+'PFJets'+PUMethod ), cut = cms.string( 'pt > 100.0 ' ) ))
	#else: setattr( proc, jetalgo+'PFJets'+PUMethod+'Constituents', cms.EDFilter("PFJetConstituentSelector", src = cms.InputTag( jetalgo+'PFJets'+PUMethod ), cut = cms.string( Cut ) ))
	#jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Constituents' )

	addJetCollection(
			proc,
			labelName = jetALGO+'PF'+PUMethod,
			jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod),
			algo = jetalgo,
			rParam = jetSize,
			jetCorrections = JEC, #( 'AK'+size+'PFchs', cms.vstring( ['L1FastJet', 'L2Relative', 'L3Absolute']), 'None'),
			pfCandidates = cms.InputTag( pfCand ),  #'packedPFCandidates'),
			svSource = cms.InputTag( svLabel ),   #'slimmedSecondaryVertices'),
			genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
			pvSource = cms.InputTag( pvLabel ), #'offlineSlimmedPrimaryVertices'),
			btagDiscriminators = bTagDiscriminators,
			outputModules = ['outputFile']
			) 

	getattr( proc, 'patJetCorrFactors'+jetALGO+'PF'+PUMethod ).primaryVertices = pvLabel  #'offlineSlimmedPrimaryVertices' 
	getattr( proc, 'jetTracksAssociatorAtVertex'+jetALGO+'PF'+PUMethod ).tracks = tvLabel  # 'unpackedTracksAndVertices'

	if 'CS' in PUMethod: getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod ).getJetMCFlavour = False  
	else: getattr(proc,'patJetPartons').particles = cms.InputTag( genParticlesLabel ) #'prunedGenParticles')
	getattr(proc,'patJetPartonMatch'+jetALGO+'PF'+PUMethod).matched = cms.InputTag( genParticlesLabel ) #'prunedGenParticles')
	if miniAOD:
		if hasattr(proc,'pfInclusiveSecondaryVertexFinderTagInfos'+jetALGO+'PF'+PUMethod):
			    getattr(proc,'pfInclusiveSecondaryVertexFinderTagInfos'+jetALGO+'PF'+PUMethod).extSVCollection = cms.InputTag( svLabel ) #'slimmedSecondaryVertices')
		getattr(proc,'patJets'+jetALGO+'PF'+PUMethod).addAssociatedTracks = cms.bool(False) # needs to be disabled since there is no track collection present in MiniAOD
		getattr(proc,'patJets'+jetALGO+'PF'+PUMethod).addJetCharge = cms.bool(False)        # needs to be disabled since there is no track collection present in MiniAOD
	

	if addSoftDrop or addSoftDropSubjets: 

		setattr( proc, jetalgo+'PFJets'+PUMethod+'SoftDrop', 
			ak8PFJetsCHSSoftDrop.clone( 
				rParam = jetSize, 
				jetAlgorithm = algorithm, 
				useExplicitGhosts=True,
				zcut=zCutSD, 
				beta=betaCut,
				writeCompound = cms.bool(True),
				jetCollInstanceName=cms.string('SubJets') ) )
		if miniAOD: getattr( proc, jetalgo+'PFJets'+PUMethod+'SoftDrop').src = 'chs'
		setattr( proc, jetalgo+'PFJets'+PUMethod+'SoftDropLinks', 
			ak8PFJetsCHSSoftDropLinks.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'SoftDrop'), 
				distMax = cms.double( jetSize ) ) )

		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'SoftDropLinks_*_*'] 
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'SoftDrop' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'SoftDropLinks' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'SoftDropLinks']
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'SoftDropLinks' )

		if addSoftDropSubjets:

			setattr( proc, jetalgo+'GenJetsNoNuSoftDrop',
					ak4GenJets.clone(
						SubJetParameters,
						useSoftDrop = cms.bool(True),
						rParam = jetSize, 
						jetAlgorithm = algorithm, 
						useExplicitGhosts=cms.bool(True),
						#zcut=cms.double(zCutSD), 
						beta=cms.double(betaCut),
						writeCompound = cms.bool(True),
						jetCollInstanceName=cms.string('SubJets')
						))
			if miniAOD: getattr( proc, jetalgo+'GenJetsNoNuSoftDrop' ).src = 'packedGenParticlesForJetsNoNu'
			jetSeq += getattr(proc, jetalgo+'GenJetsNoNuSoftDrop' )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'SoftDrop',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'SoftDrop'),
					algo = jetalgo,
					rParam = jetSize,
					jetCorrections = JEC,
					btagDiscriminators = ['None'],
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
					getJetMCFlavour = False,
					outputModules = ['outputFile']
					) 
			getattr( proc, 'patJetCorrFactors'+jetALGO+'PF'+PUMethod+'SoftDrop' ).primaryVertices = pvLabel  #'offlineSlimmedPrimaryVertices' 
			getattr(proc,'patJetPartonMatch'+jetALGO+'PF'+PUMethod+'SoftDrop').matched = cms.InputTag( genParticlesLabel ) #'prunedGenParticles')
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDrop', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'SoftDrop', cut = Cut ) )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'SoftDropSubjets',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'SoftDrop', 'SubJets'),
					algo = jetalgo,  # needed for subjet b tagging
					rParam = jetSize,  # needed for subjet b tagging
					jetCorrections = subJEC, 
					pfCandidates = cms.InputTag( pfCand ), 
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ),  
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNuSoftDrop','SubJets'),
					getJetMCFlavour = False,
					explicitJTA = True,  # needed for subjet b tagging
					svClustering = True, # needed for subjet b tagging
					fatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod),             # needed for subjet flavor clustering
					groomedFatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod+'SoftDrop'), # needed for subjet flavor clustering
					outputModules = ['outputFile']
					) 

			if miniAOD:
				getattr( proc,'patJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets').addAssociatedTracks = cms.bool(False) 
				getattr( proc,'patJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets').addJetCharge = cms.bool(False) 
				if hasattr(proc,'pfInclusiveSecondaryVertexFinderTagInfos'+jetALGO+'PF'+PUMethod+'SoftDropSubjets'):
					    getattr(proc,'pfInclusiveSecondaryVertexFinderTagInfos'+jetALGO+'PF'+PUMethod+'SoftDropSubjets').extSVCollection = cms.InputTag( svLabel ) 
			getattr(proc,'patJetCorrFactors'+jetALGO+'PF'+PUMethod+'SoftDropSubjets' ).primaryVertices = pvLabel 
			getattr(proc,'patJetPartonMatch'+jetALGO+'PF'+PUMethod+'SoftDropSubjets').matched = cms.InputTag( genParticlesLabel ) 
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets', cut = Cut ))

			## Establish references between PATified fat jets and subjets using the BoostedJetMerger
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked', 
					cms.EDProducer("BoostedJetMerger",
						jetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDrop'),
						subjetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets')
						))
			jetSeq += getattr(proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked' )
			elemToKeep += [ 'keep *_selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked_*_*' ]
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropPacked' )
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'SoftDropSubjets' )

	if addPruning or addPrunedSubjets: 

		setattr( proc, jetalgo+'PFJets'+PUMethod+'Pruned', 
			ak8PFJetsCHSPruned.clone( 
				rParam = jetSize, 
				jetAlgorithm = algorithm, 
				zcut=zCut, 
				rcut_factor=rCut,
				writeCompound = cms.bool(True),
				doAreaFastjet = cms.bool(True),
				jetCollInstanceName=cms.string('SubJets') ) )
		if miniAOD: getattr( proc, jetalgo+'PFJets'+PUMethod+'Pruned').src = 'chs'
		setattr( proc, jetalgo+'PFJets'+PUMethod+'PrunedLinks', 
			ak8PFJetsCHSPrunedLinks.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Pruned'), 
				distMax = cms.double( jetSize ) ) )

		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Pruned' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'PrunedLinks' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'PrunedLinks']
		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'PrunedLinks_*_*'] 
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'PrunedLinks' )

		if addPrunedSubjets:
			setattr( proc, jetalgo+'GenJetsNoNuPruned',
					ak4GenJets.clone(
						SubJetParameters,
						rParam = jetSize,
						usePruning = cms.bool(True),
						writeCompound = cms.bool(True),
						jetCollInstanceName=cms.string('SubJets')
						))
			if miniAOD: getattr( proc, jetalgo+'GenJetsNoNuPruned' ).src = 'packedGenParticlesForJetsNoNu'
			jetSeq += getattr(proc, jetalgo+'GenJetsNoNuPruned' )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'Pruned',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Pruned'),
					algo = jetalgo,
					rParam = jetSize,
					jetCorrections = JEC,
					btagDiscriminators = ['None'],
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
					getJetMCFlavour = False,
					outputModules = ['outputFile']
					) 
			getattr( proc, 'patJetCorrFactors'+jetALGO+'PF'+PUMethod+'Pruned' ).primaryVertices = pvLabel  
			getattr(proc,'patJetPartonMatch'+jetALGO+'PF'+PUMethod+'Pruned').matched = cms.InputTag( genParticlesLabel ) 
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'Pruned', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'Pruned', cut = Cut ) )

			addJetCollection(
					proc,
					labelName = jetALGO+'PF'+PUMethod+'PrunedSubjets',
					jetSource = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Pruned', 'SubJets'),
					algo = jetalgo,  # needed for subjet b tagging
					rParam = jetSize,  # needed for subjet b tagging
					jetCorrections = subJEC,
					pfCandidates = cms.InputTag( pfCand ),  
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ), 
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNuPruned','SubJets'),
					getJetMCFlavour = False,
					explicitJTA = True,  # needed for subjet b tagging
					svClustering = True, # needed for subjet b tagging
					fatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod),             # needed for subjet flavor clustering
					groomedFatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod+'Pruned'), # needed for subjet flavor clustering
					outputModules = ['outputFile']
					) 

			getattr(proc,'patJetPartonMatch'+jetALGO+'PF'+PUMethod+'PrunedSubjets').matched = cms.InputTag( genParticlesLabel ) 
			getattr(proc,'patJetCorrFactors'+jetALGO+'PF'+PUMethod+'PrunedSubjets' ).primaryVertices = pvLabel  
			if miniAOD:
				if hasattr(proc,'pfInclusiveSecondaryVertexFinderTagInfos'+jetALGO+'PF'+PUMethod+'PrunedSubjets'):
					getattr(proc,'pfInclusiveSecondaryVertexFinderTagInfos'+jetALGO+'PF'+PUMethod+'PrunedSubjets').extSVCollection = cms.InputTag( svLabel ) 
				getattr( proc,'patJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets').addAssociatedTracks = cms.bool(False)
				getattr( proc,'patJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets').addJetCharge = cms.bool(False) 
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets', selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets', cut = Cut ) )

			## Establish references between PATified fat jets and subjets using the BoostedJetMerger
			setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked', 
					cms.EDProducer("BoostedJetMerger",
						jetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'Pruned'),
						subjetSrc=cms.InputTag('selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets')
						))
			jetSeq += getattr(proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked' )
			elemToKeep += [ 'keep *_selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked_*_*' ]
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedPacked' )
			toolsUsed.append( 'selectedPatJets'+jetALGO+'PF'+PUMethod+'PrunedSubjets' )


	if addTrimming:

		setattr( proc, jetalgo+'PFJets'+PUMethod+'Trimmed', 
				ak8PFJetsCHSTrimmed.clone( #src = 'chs',
					rParam = jetSize, 
					jetAlgorithm = algorithm,
					rFilt= rFiltTrim,
					trimPtFracMin= ptFrac) ) 
		if miniAOD: getattr( proc, jetalgo+'PFJets'+PUMethod+'Trimmed').src = 'chs'
		setattr( proc, jetalgo+'PFJets'+PUMethod+'TrimmedLinks', 
				ak8PFJetsCHSTrimmedLinks.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
					matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Trimmed'), 
					distMax = cms.double( jetSize ) ) )

		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'TrimmedLinks_*_*'] 
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Trimmed' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'TrimmedLinks' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'TrimmedLinks']
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'TrimmedLinks' )

	if addFiltering:

		setattr( proc, jetalgo+'PFJets'+PUMethod+'Filtered', 
				ak8PFJetsCHSFiltered.clone( #src = 'chs', 
					rParam = jetSize, 
					jetAlgorithm = algorithm,
					rFilt= rfilt,
					nFilt= nfilt ) ) 
		if miniAOD: getattr( proc, jetalgo+'PFJets'+PUMethod+'Filtered').src = 'chs'
		setattr( proc, jetalgo+'PFJets'+PUMethod+'FilteredLinks', 
				ak8PFJetsCHSFilteredLinks.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
					matched = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Filtered'), 
					distMax = cms.double( jetSize ) ) )
		elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'FilteredLinks_*_*'] 
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'Filtered' )
		jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'FilteredLinks' )
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'FilteredLinks']
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'FilteredLinks' )

	if addCMSTopTagger :

		if 'CA' in jetALGO : 

			setattr( proc, 'cmsTopTagPFJets'+PUMethod,  
					cms.EDProducer("CATopJetProducer",
						PFJetParameters.clone( #src = cms.InputTag("chs"), #ak8PFJetsCHSConstituents", "constituents"),
							doAreaFastjet = cms.bool(True),
							doRhoFastjet = cms.bool(False),
							jetPtMin = cms.double(100.0)
							),
						AnomalousCellParameters,
						CATopJetParameters.clone( jetCollInstanceName = cms.string("SubJets"),
							verbose = cms.bool(False),
							algorithm = cms.int32(1), # 0 = KT, 1 = CA, 2 = anti-KT
							tagAlgo = cms.int32(0), #0=legacy top
							useAdjacency = cms.int32(2), # modified adjacency
							centralEtaCut = cms.double(2.5), # eta for defining "central" jets
							sumEtBins = cms.vdouble(0,1600,2600), # sumEt bins over which cuts vary. vector={bin 0 lower bound, bin 1 lower bound, ...}
							rBins = cms.vdouble(0.8,0.8,0.8), # Jet distance paramter R. R values depend on sumEt bins.
							ptFracBins = cms.vdouble(0.05,0.05,0.05), # minimum fraction of central jet pt for subjets (deltap)
							deltarBins = cms.vdouble(0.19,0.19,0.19), # Applicable only if useAdjacency=1. deltar adjacency values for each sumEtBin
							nCellBins = cms.vdouble(1.9,1.9,1.9),
							),
						jetAlgorithm = cms.string("CambridgeAachen"),
						rParam = cms.double(jetSize),
						writeCompound = cms.bool(True)
						)
					)
			if miniAOD: getattr( proc, 'cmsTopTagPFJets'+PUMethod ).src = 'chs'
			
			setattr( proc, "CATopTagInfos", 
					cms.EDProducer("CATopJetTagger",
						src = cms.InputTag('cmsTopTagPFJets'+PUMethod),
						TopMass = cms.double(171),
						TopMassMin = cms.double(0.),
						TopMassMax = cms.double(250.),
						WMass = cms.double(80.4),
						WMassMin = cms.double(0.0),
						WMassMax = cms.double(200.0),
						MinMassMin = cms.double(0.0),
						MinMassMax = cms.double(200.0),
						verbose = cms.bool(False)
						)
					)
			addJetCollection(
					proc,
					labelName = 'CMSTopTag'+PUMethod,
					jetSource = cms.InputTag('cmsTopTagPFJets'+PUMethod),
					jetCorrections = JEC,
					pfCandidates = cms.InputTag( pfCand ),  
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ), 
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag(jetalgo+'GenJetsNoNu'),
					getJetMCFlavour = False
					)
			getattr(proc,'patJetPartonMatchCMSTopTag'+PUMethod).matched = cms.InputTag( genParticlesLabel ) 
			if hasattr(proc,'pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag'+PUMethod):
				getattr(proc,'pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag'+PUMethod).extSVCollection = cms.InputTag( svLabel ) 
			getattr(proc,'patJetsCMSTopTag'+PUMethod).addTagInfos = True
			getattr(proc,'patJetsCMSTopTag'+PUMethod).tagInfoSources = cms.VInputTag( cms.InputTag('CATopTagInfos'))
			getattr(proc,'patJetCorrFactorsCMSTopTag'+PUMethod ).primaryVertices = pvLabel  
			getattr(proc,'patJetsCMSTopTag'+PUMethod).addAssociatedTracks = cms.bool(False)
			getattr(proc,'patJetsCMSTopTag'+PUMethod).addJetCharge = cms.bool(False)      
			setattr( proc, 'selectedPatJetsCMSTopTag'+PUMethod, selectedPatJets.clone( src = 'patJetsCMSTopTag'+PUMethod, cut = Cut ) )

			addJetCollection(
					proc,
					labelName = 'CMSTopTag'+PUMethod+'Subjets',
					jetSource = cms.InputTag('cmsTopTagPFJets'+PUMethod, 'SubJets'),
					algo = jetalgo,  # needed for subjet b tagging
					rParam = jetSize,  # needed for subjet b tagging
					jetCorrections = subJEC,
					pfCandidates = cms.InputTag( pfCand ),  
					pvSource = cms.InputTag( pvLabel), 
					svSource = cms.InputTag( svLabel ), 
					btagDiscriminators = bTagDiscriminators,
					genJetCollection = cms.InputTag( jetalgo+'GenJetsNoNu'),
					#getJetMCFlavour = False,
					explicitJTA = True,  # needed for subjet b tagging
					svClustering = True, # needed for subjet b tagging
					fatJets=cms.InputTag(jetalgo+'PFJets'+PUMethod),             # needed for subjet flavor clustering
					groomedFatJets=cms.InputTag('patJetsCMSTopTag'+PUMethod), # needed for subjet flavor clustering
					)

			getattr(proc,'patJetPartonMatchCMSTopTag'+PUMethod+'Subjets').matched = cms.InputTag( genParticlesLabel ) #'prunedGenParticles')
			if hasattr(proc,'pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag'+PUMethod+'Subjets'):
				getattr(proc,'pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag'+PUMethod+'Subjets').extSVCollection = cms.InputTag(svLabel) 
			getattr(proc,'patJetCorrFactorsCMSTopTag'+PUMethod+'Subjets' ).primaryVertices = pvLabel  
			getattr(proc,'patJetsCMSTopTag'+PUMethod+'Subjets').addAssociatedTracks = cms.bool(False)
			getattr(proc,'patJetsCMSTopTag'+PUMethod+'Subjets').addJetCharge = cms.bool(False)      
			setattr( proc, 'selectedPatJetsCMSTopTag'+PUMethod+'Subjets', selectedPatJets.clone( src = 'patJetsCMSTopTag'+PUMethod+'Subjets', cut = Cut ) )

			setattr( proc, 'patJetsCMSTopTag'+PUMethod+'Packed', 
					cms.EDProducer("BoostedJetMerger",
						jetSrc=cms.InputTag('patJetsCMSTopTag'+PUMethod ),
						subjetSrc=cms.InputTag('patJetsCMSTopTag'+PUMethod+'Subjets')
						))
			jetSeq += getattr(proc, 'patJetsCMSTopTag'+PUMethod+'Packed' )
			elemToKeep += [ 'keep *_patJetsCMSTopTag'+PUMethod+'Packed_*_*' ]
			toolsUsed.append( 'patJetsCMSTopTag'+PUMethod+'Packed' )

		else: print '|----- CMS recommends CambridgeAachen for CMS Top Tagger, you are using '+algorithm+'. JetToolbox will not run CMS Top Tagger.'

	if addMassDrop :

		if 'CA' in jetALGO : 
			setattr( proc, jetalgo+'PFJets'+PUMethod+'MassDropFiltered', ca15PFJetsCHSMassDropFiltered.clone( rParam = jetSize ) )
			if miniAOD: getattr( proc, jetalgo+'PFJets'+PUMethod+'MassDropFiltered').src = 'chs'
			setattr( proc, jetalgo+'PFJets'+PUMethod+'MassDropFilteredLinks', ak8PFJetsCHSPrunedLinks.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag(jetalgo+'PFJets'+PUMethod+'MassDropFiltered'), distMax = cms.double( jetSize ) ) )
			elemToKeep += [ 'keep *_'+jetalgo+'PFJets'+PUMethod+'MassDropFilteredLinks_*_*' ]
			getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ jetalgo+'PFJets'+PUMethod+'MassDropFilteredLinks' ]
			jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'MassDropFiltered' )
			jetSeq += getattr(proc, jetalgo+'PFJets'+PUMethod+'MassDropFilteredLinks' )
		else: print '|----- CMS recommends CambridgeAachen for Mass Drop, you are using '+algorithm+'. JetToolbox will not run Mass Drop.'
		toolsUsed.append( jetalgo+'PFJets'+PUMethod+'MassDropFilteredLinks' )

	if addHEPTopTagger: 
		if ( jetSize >= 1. ) and ( 'CA' in jetALGO ): 

			if miniAOD: setattr( proc, 'hepTopTagPFJets'+PUMethod, hepTopTagPFJetsCHS.clone( src = 'chs' ) )
			else: 
				setattr( proc, jetalgo+'PFJets'+PUMethod+'Constituents', ak8PFJetsCHSConstituents.clone( src = jetalgo+'PFJets'+PUMethod ) )
				setattr( proc, 'hepTopTagPFJets'+PUMethod, hepTopTagPFJetsCHS.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod+'Constituents', 'constituents' ) ) )
			setattr( proc, 'hepTopTagPFJets'+PUMethod+'Links'+jetALGO, ak8PFJetsCHSPrunedLinks.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
				matched = cms.InputTag("hepTopTagPFJets"+PUMethod), distMax = cms.double( jetSize ) ) )
			elemToKeep += [ 'keep *_hepTopTagPFJets'+PUMethod+'Links'+jetALGO+'_*_*' ]
			getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += [ 'hepTopTagPFJets'+PUMethod+'Links'+jetALGO ]
			jetSeq += getattr(proc, 'hepTopTagPFJets'+PUMethod )
			jetSeq += getattr(proc, 'hepTopTagPFJets'+PUMethod+'Links'+jetALGO )
			toolsUsed.append( 'hepTopTagPFJets'+PUMethod+'Links'+jetALGO )
		else: print '|----- CMS recommends CambridgeAachen for HEPTopTagger, you are using '+algorithm+', and a jet cone size bigger than 1. JetToolbox will not run HEP TopTagger.'

	####### Nsubjettiness
	if addNsub:
		from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

		rangeTau = range(1,maxTau+1)
		setattr( proc, 'Njettiness'+jetALGO+PUMethod, 
				Njettiness.clone( src = cms.InputTag( jetalgo+'PFJets'+PUMethod), 
					Njets=cms.vuint32(rangeTau),         # compute 1-, 2-, 3-, 4- subjettiness
					# variables for measure definition : 
					measureDefinition = cms.uint32( 0 ), # CMS default is normalized measure
					beta = cms.double(1.0),              # CMS default is 1
					R0 = cms.double( jetSize ),              # CMS default is jet cone size
					Rcutoff = cms.double( -999.0),       # not used by default
					# variables for axes definition :
					axesDefinition = cms.uint32( 6 ),    # CMS default is 1-pass KT axes
					nPass = cms.int32(-999),             # not used by default
					akAxesR0 = cms.double(-999.0) ) )        # not used by default

		elemToKeep += [ 'keep *_Njettiness'+jetALGO+PUMethod+'_*_*' ]
		for tau in rangeTau: getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += ['Njettiness'+jetALGO+PUMethod+':tau'+str(tau) ] 
		jetSeq += getattr(proc, 'Njettiness'+jetALGO+PUMethod )
		toolsUsed.append( 'Njettiness'+jetALGO+PUMethod )

	###### QJetsAdder
	if addQJets:
		#This is the old way before 731
		### there must be a better way to do this random number introduction
		setattr( proc, 'RandomNumberGeneratorService', cms.Service("RandomNumberGeneratorService", 
							QJetsAdderCA8 = cms.PSet(initialSeed = cms.untracked.uint32(7)),
							QJetsAdderAK8 = cms.PSet(initialSeed = cms.untracked.uint32(31)),
							QJetsAdderCA15 = cms.PSet(initialSeed = cms.untracked.uint32(76)), ) )

		from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder
		setattr( proc, 'QJetsAdder'+jetALGO, 
				QJetsAdder.clone( src = cms.InputTag(jetalgo+'PFJets'+PUMethod), 
					jetRad = cms.double( jetSize ), 
					jetAlgo = cms.string( jetALGO[0:2] )))
		elemToKeep += [ 'keep *_QJetsAdder'+jetALGO+'_*_*' ]
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += ['QJetsAdder'+jetALGO+':QjetsVolatility']  
		jetSeq += getattr(proc, 'QJetsAdder'+jetALGO )
		toolsUsed.append( 'QJetsAdder'+jetALGO )
		'''
		### This is for 731 or higher
		if 'ak4' in jetalgo:
			proc.load('RecoJets.JetProducers.QGTagger_cfi')
			proc.QGTagger.srcJets = cms.InputTag(jetalgo+'PFJets'+PUMethod)    # Could be reco::PFJetCollection or pat::JetCollection (both AOD and miniAOD)
			proc.QGTagger.jetsLabel = cms.string('QGL_AK4PFchs')        # Other options (might need to add an ESSource for it): see https://twiki.cern.ch/twiki/bin/viewauth/CMS/QGDataBaseVersion
			elemToKeep += [ 'keep *_QGTagger_*_*' ]
			getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += ['QJetsAdder'+jetALGO+':qgLikelihood']  
			jetSeq += getattr(proc, 'QGTagger' )
		else:
			'QGTagger is optimized for ak4 jets.'
		'''

	setattr( proc, 'selectedPatJets'+jetALGO+'PF'+PUMethod, selectedPatJets.clone( src = 'patJets'+jetALGO+'PF'+PUMethod, cut = Cut ) )
	elemToKeep += [ 'keep *_selectedPatJets'+jetALGO+'PF'+PUMethod+'_*_*' ]
	elemToKeep += [ 'drop *_selectedPatJets'+jetALGO+'PF'+PUMethod+'_calo*_*' ]
	elemToKeep += [ 'drop *_selectedPatJets'+jetALGO+'PF'+PUMethod+'_tagInfos_*' ]

	print '|---- jetToolBox: Running '+', '.join(toolsUsed)+'.'

	### "return"
	setattr(proc, jetSequence, jetSeq)
	if hasattr(proc, outputFile): getattr(proc, outputFile).outputCommands += elemToKeep
	else: setattr( proc, outputFile, 
			cms.OutputModule('PoolOutputModule', 
				fileName = cms.untracked.string('jettoolbox.root'), 
				outputCommands = cms.untracked.vstring( elemToKeep ) ) )
        addTagInfos = True,
        addDiscriminators = True,
        addAssociatedTracks = True,
        addJetCharge = False,
        addJetID = False,
        getJetMCFlavour = True,
        addGenPartonMatch = True,
        addGenJetMatch = True,
        embedGenJetMatch = True,
        embedGenPartonMatch = True,
        # embedCaloTowers = False,
        # embedPFCandidates = True
        )

akSoftDrop3PFNjettiness = Njettiness.clone(
		    src = cms.InputTag("akSoftDrop3PFJets"),
           	    R0  = cms.double( 0.3)
)
akSoftDrop3PFpatJetsWithBtagging.userData.userFloats.src += ['akSoftDrop3PFNjettiness:tau1','akSoftDrop3PFNjettiness:tau2','akSoftDrop3PFNjettiness:tau3']

akSoftDrop3PFJetAnalyzer = inclusiveJetAnalyzer.clone(jetTag = cms.InputTag("akSoftDrop3PFpatJetsWithBtagging"),
                                                             genjetTag = 'ak3HiGenJets',
                                                             rParam = 0.3,
                                                             matchJets = cms.untracked.bool(False),
                                                             matchTag = 'patJetsWithBtagging',
                                                             pfCandidateLabel = cms.untracked.InputTag('particleFlowTmp'),
                                                             trackTag = cms.InputTag("hiGeneralTracks"),
                                                             fillGenJets = True,
                                                             isMC = True,
							     doSubEvent = True,
                                                             useHepMC = cms.untracked.bool(False),
							     genParticles = cms.untracked.InputTag("genParticles"),
from RecoJets.JetProducers.QGTagger_cfi import *
AK4QGTaggerPuppi           = QGTagger.clone()
AK4QGTaggerPuppi.srcJets   = cms.InputTag('AK4PFJetsPuppi')
AK4QGTaggerPuppi.jetsLabel = cms.string('QGL_AK4PFchs')
AK4QGTaggerPuppi.jec       = cms.InputTag("ak4PuppiL1FastL2L3Corrector") # NOTE: use "ak4PFPuppiL1FastL2L3Corrector" for MC / "ak4PFPuppiL1FastL2L3ResidualCorrector" for Data

AK4QGTaggerSubJetsPuppi           = AK4QGTaggerPuppi.clone()
AK4QGTaggerSubJetsPuppi.srcJets   = cms.InputTag('AK4caPFJetsSoftDropPuppi','SubJets')
AK4QGTaggerSubJetsPuppi.jetsLabel = cms.string('QGL_AK4PFchs')
AK4QGTaggerSubJetsPuppi.jec       = cms.InputTag("ak4PuppiL1FastL2L3Corrector") # NOTE: use "ak4PFPuppiL1FastL2L3Corrector" for MC / "ak4PFPuppiL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
AK4NjettinessPuppi = Njettiness.clone(
    src   = cms.InputTag('AK4PFJetsPuppi'),
    cone  = cms.double(0.4),
    Njets = cms.vuint32(1,2,3,4)
  )

#
# Define sequences
#
AK4genjetsequencePuppi = cms.Sequence(
  AK4GenJetsPuppi* 
  AK4FlavorPuppi
)

AK4jetsequencePuppi = cms.Sequence(
    AK4PFJetsPuppi*   
    AK4caPFJetsPrunedPuppi*
    AK4caPFJetsTrimmedPuppi*
Beispiel #37
0
def jetToolbox(
    proc,
    jetType,
    jetSequence,
    outputFile,
    PUMethod="CHS",  #### Options: Puppi, CS, SK, Plain
    miniAOD=True,
    JETCorrPayload="None",
    JETCorrLevels=["None"],
    GetJetMCFlavour=True,
    Cut="",
    subJETCorrPayload="None",
    subJETCorrLevels=["None"],
    GetSubjetMCFlavour=False,
    CutSubjet="",
    addPruning=False,
    zCut=0.1,
    rCut=0.5,
    addPrunedSubjets=False,
    addSoftDrop=False,
    betaCut=0.0,
    zCutSD=0.1,
    addSoftDropSubjets=False,
    addTrimming=False,
    rFiltTrim=0.2,
    ptFrac=0.03,
    addFiltering=False,
    rfilt=0.3,
    nfilt=3,
    addCMSTopTagger=False,
    addMassDrop=False,
    addHEPTopTagger=False,
    addNsub=False,
    maxTau=4,
    addPUJetID=False,
    addQJets=False,
):

    ###############################################################################
    #######  Verifying some inputs and defining variables
    ###############################################################################
    print "|---- jetToolbox: Initialyzing collection..."
    supportedJetAlgos = {"ak": "AntiKt", "ca": "CambridgeAachen", "kt": "Kt"}
    recommendedJetAlgos = ["ak4", "ak8", "ca4", "ca8", "ca10"]
    payloadList = [
        "AK1PFchs",
        "AK2PFchs",
        "AK3PFchs",
        "AK4PFchs",
        "AK5PFchs",
        "AK6PFchs",
        "AK7PFchs",
        "AK8PFchs",
        "AK9PFchs",
        "AK10PFchs",
        "AK1PFPUPPI",
        "AK2PFPUPPI",
        "AK3PFPUPPI",
        "AK4PFPUPPI",
        "AK5PFPUPPI",
        "AK6PFPUPPI",
        "AK7PFPUPPI",
        "AK8PFPUPPI",
        "AK9PFPUPPI",
        "AK10PFPUPPI",
        "AK1PFSK",
        "AK2PFSK",
        "AK3PFSK",
        "AK4PFSK",
        "AK5PFSK",
        "AK6PFSK",
        "AK7PFSK",
        "AK8PFSK",
        "AK9PFSK",
        "AK10PFSK",
        "AK1PF",
        "AK2PF",
        "AK3PF",
        "AK4PF",
        "AK5PF",
        "AK6PF",
        "AK7PF",
        "AK8PF",
        "AK9PF",
        "AK10PF",
    ]
    JECLevels = ["L1Offset", "L1FastJet", "L1JPTOffset", "L2Relative", "L3Absolute", "L5Falvour", "L7Parton"]
    jetAlgo = ""
    algorithm = ""
    size = ""
    for type, tmpAlgo in supportedJetAlgos.iteritems():
        if type in jetType.lower():
            jetAlgo = type
            algorithm = tmpAlgo
            size = jetType.replace(type, "")

    jetSize = 0.0
    if int(size) in range(0, 20):
        jetSize = int(size) / 10.0
    else:
        print "|---- jetToolBox: jetSize has not a valid value. Insert a number between 1 and 20 after algorithm, like: AK8"
    ### Trick for uppercase/lowercase algo name
    jetALGO = jetAlgo.upper() + size
    jetalgo = jetAlgo.lower() + size
    if jetalgo not in recommendedJetAlgos:
        print "|---- jetToolBox: CMS recommends the following jet algoritms: " + " ".join(
            recommendedJetAlgos
        ) + ". You are using", jetalgo, "."

    #################################################################################
    ####### Toolbox start
    #################################################################################

    elemToKeep = []
    jetSeq = cms.Sequence()
    genParticlesLabel = ""
    pvLabel = ""
    tvLabel = ""
    toolsUsed = []

    #### For MiniAOD
    if miniAOD:

        print "|---- jetToolBox: JETTOOLBOX RUNNING ON MiniAOD FOR " + jetALGO + " JETS USING " + PUMethod

        genParticlesLabel = "prunedGenParticles"
        pvLabel = "offlineSlimmedPrimaryVertices"
        svLabel = "slimmedSecondaryVertices"
        tvLabel = "unpackedTracksAndVertices"
        pfCand = "packedPFCandidates"

        setattr(
            proc,
            "chs",
            cms.EDFilter("CandPtrSelector", src=cms.InputTag("packedPFCandidates"), cut=cms.string("fromPV")),
        )
        jetSeq += getattr(proc, "chs")

        ## Filter out neutrinos from packed GenParticles
        setattr(
            proc,
            "packedGenParticlesForJetsNoNu",
            cms.EDFilter(
                "CandPtrSelector",
                src=cms.InputTag("packedGenParticles"),
                cut=cms.string("abs(pdgId) != 12 && abs(pdgId) != 14 && abs(pdgId) != 16"),
            ),
        )
        jetSeq += getattr(proc, "packedGenParticlesForJetsNoNu")

        setattr(
            proc,
            jetalgo + "GenJetsNoNu",
            ak4GenJets.clone(src="packedGenParticlesForJetsNoNu", rParam=jetSize, jetAlgorithm=algorithm),
        )
        jetSeq += getattr(proc, jetalgo + "GenJetsNoNu")

        # for Inclusive Vertex Finder
        proc.load("PhysicsTools.PatAlgos.slimming.unpackedTracksAndVertices_cfi")

        #### For AOD
    else:
        print "|---- jetToolBox: JETTOOLBOX RUNNING ON AOD FOR " + jetALGO + " JETS USING " + PUMethod

        genParticlesLabel = "genParticles"
        pvLabel = "offlinePrimaryVertices"
        tvLabel = "generalTracks"
        pfCand = "particleFlow"
        svLabel = "inclusiveSecondaryVertices"

        proc.load("RecoJets.Configuration.GenJetParticles_cff")
        proc.load("CommonTools.ParticleFlow.pfNoPileUpJME_cff")
        setattr(
            proc,
            jetalgo + "GenJetsNoNu",
            ak4GenJets.clone(src="genParticlesForJetsNoNu", rParam=jetSize, jetAlgorithm=algorithm),
        )
        jetSeq += getattr(proc, jetalgo + "GenJetsNoNu")

        ## b-tag discriminators
    bTagDiscriminators = [
        "pfTrackCountingHighEffBJetTags",
        "pfTrackCountingHighPurBJetTags",
        "pfJetProbabilityBJetTags",
        "pfJetBProbabilityBJetTags",
        "pfSimpleSecondaryVertexHighEffBJetTags",
        "pfSimpleSecondaryVertexHighPurBJetTags",
        "pfCombinedSecondaryVertexV2BJetTags",
        "pfCombinedSecondaryVertexBJetTags",
        #'pfcombinedInclusiveSecondaryVertexV2BJetTags',
        #'pfCombinedSecondaryVertexSoftLeptonBJetTags',
        #'pfCombinedMVABJetTags'
    ]

    ####  Creating PATjets
    if "Puppi" in PUMethod:

        proc.load("CommonTools.PileupAlgos.Puppi_cff")
        from RecoJets.JetProducers.ak4PFJetsPuppi_cfi import ak4PFJetsPuppi

        setattr(
            proc,
            jetalgo + "PFJetsPuppi",
            ak4PFJetsPuppi.clone(doAreaFastjet=True, rParam=jetSize, jetAlgorithm=algorithm),
        )
        if miniAOD:
            puppi.candName = cms.InputTag("packedPFCandidates")
            puppi.vertexName = cms.InputTag("offlineSlimmedPrimaryVertices")
        jetSeq += getattr(proc, "puppi")
        jetSeq += getattr(proc, jetalgo + "PFJetsPuppi")

    elif "CS" in PUMethod:

        from RecoJets.JetProducers.ak4PFJetsCS_cfi import ak4PFJetsCS

        setattr(
            proc,
            jetalgo + "PFJetsCS",
            ak4PFJetsCS.clone(doAreaFastjet=True, csRParam=cms.double(jetSize), jetAlgorithm=algorithm),
        )
        # if miniAOD: getattr( proc, jetalgo+'PFJetsCS').src = 'chs'
        if miniAOD:
            getattr(proc, jetalgo + "PFJetsCS").src = "packedPFCandidates"
        # setattr( proc, jetalgo+'PFJetsCSConstituents', ak8PFJetsCSConstituents.clone( src = cms.InputTag(jetalgo+'PFJetsCS') ) )
        jetSeq += getattr(proc, jetalgo + "PFJetsCS")

        # setattr( proc, jetalgo+'PFJetsCSConstituents', ak8PFJetsCSConstituents.clone( src = cms.InputTag(jetalgo+'PFJetsCS') ) )
        jetSeq += getattr(proc, jetalgo + "PFJetsCS")

    elif "SK" in PUMethod:

        proc.load("CommonTools.PileupAlgos.softKiller_cfi")
        from RecoJets.JetProducers.ak4PFJetsSK_cfi import ak4PFJetsSK

        setattr(proc, jetalgo + "PFJetsSK", ak4PFJetsSK.clone(rParam=jetSize, jetAlgorithm=algorithm))
        if miniAOD:
            getattr(proc, "softKiller").PFCandidates = cms.InputTag("packedPFCandidates")
        jetSeq += getattr(proc, "softKiller")
        jetSeq += getattr(proc, jetalgo + "PFJetsSK")

    elif "CHS" in PUMethod:
        setattr(
            proc, jetalgo + "PFJetsCHS", ak4PFJetsCHS.clone(doAreaFastjet=True, rParam=jetSize, jetAlgorithm=algorithm)
        )
        if miniAOD:
            getattr(proc, jetalgo + "PFJetsCHS").src = "chs"
        jetSeq += getattr(proc, jetalgo + "PFJetsCHS")

    else:
        PUMethod = ""
        setattr(proc, jetalgo + "PFJets", ak4PFJets.clone(doAreaFastjet=True, rParam=jetSize, jetAlgorithm=algorithm))
        if miniAOD:
            getattr(proc, jetalgo + "PFJets").src = "packedPFCandidates"
        jetSeq += getattr(proc, jetalgo + "PFJets")

    if miniAOD:
        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "Constituents",
            cms.EDFilter(
                "MiniAODJetConstituentSelector", src=cms.InputTag(jetalgo + "PFJets" + PUMethod), cut=cms.string(Cut)
            ),
        )
    else:
        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "Constituents",
            cms.EDFilter(
                "PFJetConstituentSelector", src=cms.InputTag(jetalgo + "PFJets" + PUMethod), cut=cms.string(Cut)
            ),
        )
    jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "Constituents")

    ### Jet Corrections
    if JETCorrPayload not in payloadList:
        if not set(JETCorrLevels).issubset(set(JECLevels)):
            if "CHS" in PUMethod:
                JEC = ("AK" + size + "PFchs", ["L1FastJet", "L2Relative", "L3Absolute"], "None")
            elif "Plain" in PUMethod:
                JEC = ("AK" + size + "PF", ["L1FastJet", "L2Relative", "L3Absolute"], "None")
            else:
                JEC = None
            if "None" in JETCorrPayload:
                print "|---- jetToolBox: No JEC provided, jetToolbox is using the recommended corrections for this PU method: " + str(
                    JEC
                )
            else:
                print '|---- jetToolBox: JEC payload provided ("' + JETCorrPayload + '") is wrong, jetToolbox is using the recommended corrections for this PU method: ' + str(
                    JEC
                )
        else:
            if "CHS" in PUMethod:
                JEC = ("AK" + size + "PFchs", JETCorrLevels, "None")
            elif "Plain" in PUMethod:
                JEC = ("AK" + size + "PF", JETCorrLevels, "None")
            else:
                JEC = None
            if "None" in JETCorrPayload:
                print "|---- jetToolBox: No JEC payload provided, jetToolbox is using the recommended payload. Using JEC: " + str(
                    JEC
                )
            else:
                print '|---- jetToolBox: JEC payload provided ("' + JETCorrPayload + '") is wrong, jetToolbox is using the recommended corrections for this PU method: ' + str(
                    JEC
                )
    else:
        if not set(JETCorrLevels).issubset(set(JECLevels)):
            if ("CHS" in PUMethod) or ("Plain" in PUMethod):
                JEC = (JETCorrPayload, ["L1FastJet", "L2Relative", "L3Absolute"], "None")
            else:
                JEC = None
            print "|---- jetToolBox: JEC levels are not provided or wrong, jetToolbox is using the recommended levels for this PU method: " + str(
                JEC
            )
        else:
            JEC = (JETCorrPayload, JETCorrLevels, "None")
            print "|---- jetToolBox: JEC payload and levels provided by user. Using JEC: " + str(JEC)

    if addPrunedSubjets or addSoftDropSubjets or addCMSTopTagger:
        if subJETCorrPayload not in payloadList:
            if not set(subJETCorrLevels).issubset(set(JECLevels)):
                if "CHS" in PUMethod:
                    subJEC = ("AK4PFchs", ["L1FastJet", "L2Relative", "L3Absolute"], "None")
                elif "Plain" in PUMethod:
                    subJEC = ("AK4PF", ["L1FastJet", "L2Relative", "L3Absolute"], "None")
                else:
                    subJEC = None
                if "None" in subJETCorrPayload:
                    print "|---- jetToolBox: No subJEC provided, jetToolbox is using the recommended corrections for this PU method: " + str(
                        subJEC
                    )
                else:
                    print '|---- jetToolBox: subJEC payload provided ("' + subJETCorrPayload + '") is wrong, jetToolbox is using the recommended corrections for this PU method: ' + str(
                        subJEC
                    )
            else:
                if "CHS" in PUMethod:
                    subJEC = ("AK4PFchs", subJETCorrLevels, "None")
                elif "Plain" in PUMethod:
                    subJEC = ("AK4PF", subJETCorrLevels, "None")
                else:
                    subJEC = None
                if "None" in subJETCorrPayload:
                    print "|---- jetToolBox: No subJEC payload provided, jetToolbox is using the recommended payload. Using subJEC: " + str(
                        subJEC
                    )
                else:
                    print '|---- jetToolBox: subJEC payload provided ("' + subJETCorrPayload + '") is wrong, jetToolbox is using the recommended corrections for this PU method: ' + str(
                        subJEC
                    )
        else:
            if not set(subJETCorrLevels).issubset(set(JECLevels)):
                if ("CHS" in PUMethod) or ("Plain" in PUMethod):
                    subJEC = (subJETCorrPayload, ["L1FastJet", "L2Relative", "L3Absolute"], "None")
                else:
                    subJEC = None
                print "|---- jetToolBox: subJEC levels are not provided or wrong, jetToolbox is using the recommended levels for this PU method: " + str(
                    subJEC
                )
            else:
                subJEC = (subJETCorrPayload, subJETCorrLevels, "None")
                print "|---- jetToolBox: subJEC payload and levels provided by user. Using subJEC: " + str(subJEC)

    addJetCollection(
        proc,
        labelName=jetALGO + "PF" + PUMethod,
        jetSource=cms.InputTag(jetalgo + "PFJets" + PUMethod),
        algo=jetalgo,
        rParam=jetSize,
        jetCorrections=JEC if JEC is not None else None,
        pfCandidates=cms.InputTag(pfCand),  #'packedPFCandidates'),
        svSource=cms.InputTag(svLabel),  #'slimmedSecondaryVertices'),
        genJetCollection=cms.InputTag(jetalgo + "GenJetsNoNu"),
        pvSource=cms.InputTag(pvLabel),  #'offlineSlimmedPrimaryVertices'),
        btagDiscriminators=bTagDiscriminators,
        getJetMCFlavour=GetJetMCFlavour,
        outputModules=["outputFile"],
    )

    if JEC is not None:
        getattr(
            proc, "patJetCorrFactors" + jetALGO + "PF" + PUMethod
        ).primaryVertices = pvLabel  #'offlineSlimmedPrimaryVertices'

    if "CS" in PUMethod:
        getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).getJetMCFlavour = False
    else:
        getattr(proc, "patJetPartons").particles = cms.InputTag(genParticlesLabel)  #'prunedGenParticles')
    getattr(proc, "patJetPartonMatch" + jetALGO + "PF" + PUMethod).matched = cms.InputTag(
        genParticlesLabel
    )  #'prunedGenParticles')
    if miniAOD:
        if hasattr(proc, "pfInclusiveSecondaryVertexFinderTagInfos" + jetALGO + "PF" + PUMethod):
            getattr(
                proc, "pfInclusiveSecondaryVertexFinderTagInfos" + jetALGO + "PF" + PUMethod
            ).extSVCollection = cms.InputTag(
                svLabel
            )  #'slimmedSecondaryVertices')
        getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).addAssociatedTracks = cms.bool(
            False
        )  # needs to be disabled since there is no track collection present in MiniAOD
        getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).addJetCharge = cms.bool(
            False
        )  # needs to be disabled since there is no track collection present in MiniAOD

        #### Grommers
    if addSoftDrop or addSoftDropSubjets:

        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "SoftDrop",
            ak8PFJetsCHSSoftDrop.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Constituents"),
                rParam=jetSize,
                jetAlgorithm=algorithm,
                useExplicitGhosts=True,
                R0=cms.double(jetSize),
                # zcut=zCutSD,
                beta=betaCut,
                writeCompound=cms.bool(True),
                jetCollInstanceName=cms.string("SubJets"),
            ),
        )
        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "SoftDropMass",
            ak8PFJetsCHSSoftDropMass.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                matched=cms.InputTag(jetalgo + "PFJets" + PUMethod + "SoftDrop"),
                distMax=cms.double(jetSize),
            ),
        )

        elemToKeep += ["keep *_" + jetalgo + "PFJets" + PUMethod + "SoftDropMass_*_*"]
        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "SoftDrop")
        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "SoftDropMass")
        getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
            jetalgo + "PFJets" + PUMethod + "SoftDropMass"
        ]
        toolsUsed.append(jetalgo + "PFJets" + PUMethod + "SoftDropMass")

        if addSoftDropSubjets:

            setattr(
                proc,
                jetalgo + "GenJetsNoNuSoftDrop",
                ak4GenJets.clone(
                    SubJetParameters,
                    useSoftDrop=cms.bool(True),
                    rParam=jetSize,
                    jetAlgorithm=algorithm,
                    useExplicitGhosts=cms.bool(True),
                    # zcut=cms.double(zCutSD),
                    R0=cms.double(jetSize),
                    beta=cms.double(betaCut),
                    writeCompound=cms.bool(True),
                    jetCollInstanceName=cms.string("SubJets"),
                ),
            )
            if miniAOD:
                getattr(proc, jetalgo + "GenJetsNoNuSoftDrop").src = "packedGenParticlesForJetsNoNu"
            jetSeq += getattr(proc, jetalgo + "GenJetsNoNuSoftDrop")

            addJetCollection(
                proc,
                labelName=jetALGO + "PF" + PUMethod + "SoftDrop",
                jetSource=cms.InputTag(jetalgo + "PFJets" + PUMethod + "SoftDrop"),
                algo=jetalgo,
                rParam=jetSize,
                jetCorrections=JEC if JEC is not None else None,
                btagDiscriminators=["None"],
                genJetCollection=cms.InputTag(jetalgo + "GenJetsNoNu"),
                getJetMCFlavour=GetJetMCFlavour,
                outputModules=["outputFile"],
            )

            if JEC is not None:
                getattr(proc, "patJetCorrFactors" + jetALGO + "PF" + PUMethod + "SoftDrop").primaryVertices = pvLabel
            getattr(proc, "patJetPartonMatch" + jetALGO + "PF" + PUMethod + "SoftDrop").matched = cms.InputTag(
                genParticlesLabel
            )  #'prunedGenParticles')
            setattr(
                proc,
                "selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDrop",
                selectedPatJets.clone(src="patJets" + jetALGO + "PF" + PUMethod + "SoftDrop", cut=Cut),
            )

            addJetCollection(
                proc,
                labelName=jetALGO + "PF" + PUMethod + "SoftDropSubjets",
                jetSource=cms.InputTag(jetalgo + "PFJets" + PUMethod + "SoftDrop", "SubJets"),
                algo=jetalgo,  # needed for subjet b tagging
                rParam=jetSize,  # needed for subjet b tagging
                jetCorrections=subJEC if subJEC is not None else None,
                pfCandidates=cms.InputTag(pfCand),
                pvSource=cms.InputTag(pvLabel),
                svSource=cms.InputTag(svLabel),
                btagDiscriminators=bTagDiscriminators,
                genJetCollection=cms.InputTag(jetalgo + "GenJetsNoNuSoftDrop", "SubJets"),
                getJetMCFlavour=GetSubjetMCFlavour,
                explicitJTA=True,  # needed for subjet b tagging
                svClustering=True,  # needed for subjet b tagging
                fatJets=cms.InputTag(jetalgo + "PFJets" + PUMethod),  # needed for subjet flavor clustering
                groomedFatJets=cms.InputTag(
                    jetalgo + "PFJets" + PUMethod + "SoftDrop"
                ),  # needed for subjet flavor clustering
                outputModules=["outputFile"],
            )

            if miniAOD:
                getattr(proc, "patJets" + jetALGO + "PF" + PUMethod + "SoftDropSubjets").addAssociatedTracks = cms.bool(
                    False
                )
                getattr(proc, "patJets" + jetALGO + "PF" + PUMethod + "SoftDropSubjets").addJetCharge = cms.bool(False)
                if hasattr(
                    proc, "pfInclusiveSecondaryVertexFinderTagInfos" + jetALGO + "PF" + PUMethod + "SoftDropSubjets"
                ):
                    getattr(
                        proc, "pfInclusiveSecondaryVertexFinderTagInfos" + jetALGO + "PF" + PUMethod + "SoftDropSubjets"
                    ).extSVCollection = cms.InputTag(svLabel)
            if subJEC is not None:
                getattr(
                    proc, "patJetCorrFactors" + jetALGO + "PF" + PUMethod + "SoftDropSubjets"
                ).primaryVertices = pvLabel
            getattr(proc, "patJetPartonMatch" + jetALGO + "PF" + PUMethod + "SoftDropSubjets").matched = cms.InputTag(
                genParticlesLabel
            )
            setattr(
                proc,
                "selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDropSubjets",
                selectedPatJets.clone(src="patJets" + jetALGO + "PF" + PUMethod + "SoftDropSubjets", cut=Cut),
            )

            ## Establish references between PATified fat jets and subjets using the BoostedJetMerger
            setattr(
                proc,
                "selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDropPacked",
                cms.EDProducer(
                    "BoostedJetMerger",
                    jetSrc=cms.InputTag("selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDrop"),
                    subjetSrc=cms.InputTag("selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDropSubjets"),
                ),
            )
            jetSeq += getattr(proc, "selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDropPacked")
            elemToKeep += ["keep *_selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDropPacked_*_*"]
            toolsUsed.append("selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDropPacked")
            toolsUsed.append("selectedPatJets" + jetALGO + "PF" + PUMethod + "SoftDropSubjets")

    if addPruning or addPrunedSubjets:

        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "Pruned",
            ak8PFJetsCHSPruned.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Constituents"),
                rParam=jetSize,
                jetAlgorithm=algorithm,
                zcut=zCut,
                rcut_factor=rCut,
                writeCompound=cms.bool(True),
                doAreaFastjet=cms.bool(True),
                jetCollInstanceName=cms.string("SubJets"),
            ),
        )
        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "PrunedMass",
            ak8PFJetsCHSPrunedMass.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                matched=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Pruned"),
                distMax=cms.double(jetSize),
            ),
        )

        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "Pruned")
        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "PrunedMass")
        getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
            jetalgo + "PFJets" + PUMethod + "PrunedMass"
        ]
        elemToKeep += ["keep *_" + jetalgo + "PFJets" + PUMethod + "PrunedMass_*_*"]
        toolsUsed.append(jetalgo + "PFJets" + PUMethod + "PrunedMass")

        if addPrunedSubjets:
            setattr(
                proc,
                jetalgo + "GenJetsNoNuPruned",
                ak4GenJets.clone(
                    SubJetParameters,
                    rParam=jetSize,
                    usePruning=cms.bool(True),
                    writeCompound=cms.bool(True),
                    jetCollInstanceName=cms.string("SubJets"),
                ),
            )
            if miniAOD:
                getattr(proc, jetalgo + "GenJetsNoNuPruned").src = "packedGenParticlesForJetsNoNu"
            jetSeq += getattr(proc, jetalgo + "GenJetsNoNuPruned")

            addJetCollection(
                proc,
                labelName=jetALGO + "PF" + PUMethod + "Pruned",
                jetSource=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Pruned"),
                algo=jetalgo,
                rParam=jetSize,
                jetCorrections=JEC if JEC is not None else None,
                btagDiscriminators=["None"],
                genJetCollection=cms.InputTag(jetalgo + "GenJetsNoNu"),
                getJetMCFlavour=GetJetMCFlavour,
                outputModules=["outputFile"],
            )
            if JEC is not None:
                getattr(proc, "patJetCorrFactors" + jetALGO + "PF" + PUMethod + "Pruned").primaryVertices = pvLabel
            getattr(proc, "patJetPartonMatch" + jetALGO + "PF" + PUMethod + "Pruned").matched = cms.InputTag(
                genParticlesLabel
            )
            setattr(
                proc,
                "selectedPatJets" + jetALGO + "PF" + PUMethod + "Pruned",
                selectedPatJets.clone(src="patJets" + jetALGO + "PF" + PUMethod + "Pruned", cut=Cut),
            )

            addJetCollection(
                proc,
                labelName=jetALGO + "PF" + PUMethod + "PrunedSubjets",
                jetSource=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Pruned", "SubJets"),
                algo=jetalgo,  # needed for subjet b tagging
                rParam=jetSize,  # needed for subjet b tagging
                jetCorrections=subJEC if subJEC is not None else None,
                pfCandidates=cms.InputTag(pfCand),
                pvSource=cms.InputTag(pvLabel),
                svSource=cms.InputTag(svLabel),
                getJetMCFlavour=GetSubjetMCFlavour,
                btagDiscriminators=bTagDiscriminators,
                genJetCollection=cms.InputTag(jetalgo + "GenJetsNoNuPruned", "SubJets"),
                explicitJTA=True,  # needed for subjet b tagging
                svClustering=True,  # needed for subjet b tagging
                fatJets=cms.InputTag(jetalgo + "PFJets" + PUMethod),  # needed for subjet flavor clustering
                groomedFatJets=cms.InputTag(
                    jetalgo + "PFJets" + PUMethod + "Pruned"
                ),  # needed for subjet flavor clustering
                outputModules=["outputFile"],
            )

            getattr(proc, "patJetPartonMatch" + jetALGO + "PF" + PUMethod + "PrunedSubjets").matched = cms.InputTag(
                genParticlesLabel
            )
            if subJEC is not None:
                getattr(
                    proc, "patJetCorrFactors" + jetALGO + "PF" + PUMethod + "PrunedSubjets"
                ).primaryVertices = pvLabel
            if miniAOD:
                if hasattr(
                    proc, "pfInclusiveSecondaryVertexFinderTagInfos" + jetALGO + "PF" + PUMethod + "PrunedSubjets"
                ):
                    getattr(
                        proc, "pfInclusiveSecondaryVertexFinderTagInfos" + jetALGO + "PF" + PUMethod + "PrunedSubjets"
                    ).extSVCollection = cms.InputTag(svLabel)
                getattr(proc, "patJets" + jetALGO + "PF" + PUMethod + "PrunedSubjets").addAssociatedTracks = cms.bool(
                    False
                )
                getattr(proc, "patJets" + jetALGO + "PF" + PUMethod + "PrunedSubjets").addJetCharge = cms.bool(False)
            setattr(
                proc,
                "selectedPatJets" + jetALGO + "PF" + PUMethod + "PrunedSubjets",
                selectedPatJets.clone(src="patJets" + jetALGO + "PF" + PUMethod + "PrunedSubjets", cut=Cut),
            )

            ## Establish references between PATified fat jets and subjets using the BoostedJetMerger
            setattr(
                proc,
                "selectedPatJets" + jetALGO + "PF" + PUMethod + "PrunedPacked",
                cms.EDProducer(
                    "BoostedJetMerger",
                    jetSrc=cms.InputTag("selectedPatJets" + jetALGO + "PF" + PUMethod + "Pruned"),
                    subjetSrc=cms.InputTag("selectedPatJets" + jetALGO + "PF" + PUMethod + "PrunedSubjets"),
                ),
            )
            jetSeq += getattr(proc, "selectedPatJets" + jetALGO + "PF" + PUMethod + "PrunedPacked")
            elemToKeep += ["keep *_selectedPatJets" + jetALGO + "PF" + PUMethod + "PrunedPacked_*_*"]
            toolsUsed.append("selectedPatJets" + jetALGO + "PF" + PUMethod + "PrunedPacked")
            toolsUsed.append("selectedPatJets" + jetALGO + "PF" + PUMethod + "PrunedSubjets")

    if addTrimming:

        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "Trimmed",
            ak8PFJetsCHSTrimmed.clone(
                rParam=jetSize,
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Constituents"),
                jetAlgorithm=algorithm,
                rFilt=rFiltTrim,
                trimPtFracMin=ptFrac,
            ),
        )
        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "TrimmedMass",
            ak8PFJetsCHSTrimmedMass.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                matched=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Trimmed"),
                distMax=cms.double(jetSize),
            ),
        )

        elemToKeep += ["keep *_" + jetalgo + "PFJets" + PUMethod + "TrimmedMass_*_*"]
        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "Trimmed")
        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "TrimmedMass")
        getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
            jetalgo + "PFJets" + PUMethod + "TrimmedMass"
        ]
        toolsUsed.append(jetalgo + "PFJets" + PUMethod + "TrimmedMass")

    if addFiltering:

        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "Filtered",
            ak8PFJetsCHSFiltered.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Constituents"),
                rParam=jetSize,
                jetAlgorithm=algorithm,
                rFilt=rfilt,
                nFilt=nfilt,
            ),
        )
        setattr(
            proc,
            jetalgo + "PFJets" + PUMethod + "FilteredMass",
            ak8PFJetsCHSFilteredMass.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                matched=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Filtered"),
                distMax=cms.double(jetSize),
            ),
        )
        elemToKeep += ["keep *_" + jetalgo + "PFJets" + PUMethod + "FilteredMass_*_*"]
        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "Filtered")
        jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "FilteredMass")
        getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
            jetalgo + "PFJets" + PUMethod + "FilteredMass"
        ]
        toolsUsed.append(jetalgo + "PFJets" + PUMethod + "FilteredMass")

    if addCMSTopTagger:

        if "CA" in jetALGO:

            setattr(
                proc,
                "cmsTopTagPFJets" + PUMethod,
                cms.EDProducer(
                    "CATopJetProducer",
                    PFJetParameters.clone(
                        src=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Constituents"),
                        doAreaFastjet=cms.bool(True),
                        doRhoFastjet=cms.bool(False),
                        jetPtMin=cms.double(100.0),
                    ),
                    AnomalousCellParameters,
                    CATopJetParameters.clone(
                        jetCollInstanceName=cms.string("SubJets"),
                        verbose=cms.bool(False),
                        algorithm=cms.int32(1),  # 0 = KT, 1 = CA, 2 = anti-KT
                        tagAlgo=cms.int32(0),  # 0=legacy top
                        useAdjacency=cms.int32(2),  # modified adjacency
                        centralEtaCut=cms.double(2.5),  # eta for defining "central" jets
                        sumEtBins=cms.vdouble(
                            0, 1600, 2600
                        ),  # sumEt bins over which cuts vary. vector={bin 0 lower bound, bin 1 lower bound, ...}
                        rBins=cms.vdouble(0.8, 0.8, 0.8),  # Jet distance paramter R. R values depend on sumEt bins.
                        ptFracBins=cms.vdouble(
                            0.05, 0.05, 0.05
                        ),  # minimum fraction of central jet pt for subjets (deltap)
                        deltarBins=cms.vdouble(
                            0.19, 0.19, 0.19
                        ),  # Applicable only if useAdjacency=1. deltar adjacency values for each sumEtBin
                        nCellBins=cms.vdouble(1.9, 1.9, 1.9),
                    ),
                    jetAlgorithm=cms.string("CambridgeAachen"),
                    rParam=cms.double(jetSize),
                    writeCompound=cms.bool(True),
                ),
            )

            setattr(
                proc,
                "CATopTagInfos",
                cms.EDProducer(
                    "CATopJetTagger",
                    src=cms.InputTag("cmsTopTagPFJets" + PUMethod),
                    TopMass=cms.double(171),
                    TopMassMin=cms.double(0.0),
                    TopMassMax=cms.double(250.0),
                    WMass=cms.double(80.4),
                    WMassMin=cms.double(0.0),
                    WMassMax=cms.double(200.0),
                    MinMassMin=cms.double(0.0),
                    MinMassMax=cms.double(200.0),
                    verbose=cms.bool(False),
                ),
            )
            addJetCollection(
                proc,
                labelName="CMSTopTag" + PUMethod,
                jetSource=cms.InputTag("cmsTopTagPFJets" + PUMethod),
                jetCorrections=JEC if JEC is not None else None,
                pfCandidates=cms.InputTag(pfCand),
                pvSource=cms.InputTag(pvLabel),
                svSource=cms.InputTag(svLabel),
                btagDiscriminators=bTagDiscriminators,
                genJetCollection=cms.InputTag(jetalgo + "GenJetsNoNu"),
                getJetMCFlavour=GetJetMCFlavour,
            )
            getattr(proc, "patJetPartonMatchCMSTopTag" + PUMethod).matched = cms.InputTag(genParticlesLabel)
            if hasattr(proc, "pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag" + PUMethod):
                getattr(
                    proc, "pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag" + PUMethod
                ).extSVCollection = cms.InputTag(svLabel)
            getattr(proc, "patJetsCMSTopTag" + PUMethod).addTagInfos = True
            getattr(proc, "patJetsCMSTopTag" + PUMethod).tagInfoSources = cms.VInputTag(cms.InputTag("CATopTagInfos"))
            if JEC is not None:
                getattr(proc, "patJetCorrFactorsCMSTopTag" + PUMethod).primaryVertices = pvLabel
            getattr(proc, "patJetsCMSTopTag" + PUMethod).addAssociatedTracks = cms.bool(False)
            getattr(proc, "patJetsCMSTopTag" + PUMethod).addJetCharge = cms.bool(False)
            setattr(
                proc,
                "selectedPatJetsCMSTopTag" + PUMethod,
                selectedPatJets.clone(src="patJetsCMSTopTag" + PUMethod, cut=Cut),
            )

            addJetCollection(
                proc,
                labelName="CMSTopTag" + PUMethod + "Subjets",
                jetSource=cms.InputTag("cmsTopTagPFJets" + PUMethod, "SubJets"),
                algo=jetalgo,  # needed for subjet b tagging
                rParam=jetSize,  # needed for subjet b tagging
                jetCorrections=subJEC if subJEC is not None else None,
                pfCandidates=cms.InputTag(pfCand),
                pvSource=cms.InputTag(pvLabel),
                svSource=cms.InputTag(svLabel),
                btagDiscriminators=bTagDiscriminators,
                genJetCollection=cms.InputTag(jetalgo + "GenJetsNoNu"),
                getJetMCFlavour=GetSubjetMCFlavour,
                explicitJTA=True,  # needed for subjet b tagging
                svClustering=True,  # needed for subjet b tagging
                fatJets=cms.InputTag(jetalgo + "PFJets" + PUMethod),  # needed for subjet flavor clustering
                groomedFatJets=cms.InputTag("patJetsCMSTopTag" + PUMethod),  # needed for subjet flavor clustering
            )

            getattr(proc, "patJetPartonMatchCMSTopTag" + PUMethod + "Subjets").matched = cms.InputTag(
                genParticlesLabel
            )  #'prunedGenParticles')
            if hasattr(proc, "pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag" + PUMethod + "Subjets"):
                getattr(
                    proc, "pfInclusiveSecondaryVertexFinderTagInfosCMSTopTag" + PUMethod + "Subjets"
                ).extSVCollection = cms.InputTag(svLabel)
            if subJEC is not None:
                getattr(proc, "patJetCorrFactorsCMSTopTag" + PUMethod + "Subjets").primaryVertices = pvLabel
            getattr(proc, "patJetsCMSTopTag" + PUMethod + "Subjets").addAssociatedTracks = cms.bool(False)
            getattr(proc, "patJetsCMSTopTag" + PUMethod + "Subjets").addJetCharge = cms.bool(False)
            setattr(
                proc,
                "selectedPatJetsCMSTopTag" + PUMethod + "Subjets",
                selectedPatJets.clone(src="patJetsCMSTopTag" + PUMethod + "Subjets", cut=Cut),
            )

            setattr(
                proc,
                "patJetsCMSTopTag" + PUMethod + "Packed",
                cms.EDProducer(
                    "BoostedJetMerger",
                    jetSrc=cms.InputTag("patJetsCMSTopTag" + PUMethod),
                    subjetSrc=cms.InputTag("patJetsCMSTopTag" + PUMethod + "Subjets"),
                ),
            )
            jetSeq += getattr(proc, "patJetsCMSTopTag" + PUMethod + "Packed")
            elemToKeep += ["keep *_patJetsCMSTopTag" + PUMethod + "Packed_*_*"]
            toolsUsed.append("patJetsCMSTopTag" + PUMethod + "Packed")

        else:
            print "|---- jetToolBox: CMS recommends CambridgeAachen for CMS Top Tagger, you are using " + algorithm + ". JetToolbox will not run CMS Top Tagger."

    if addMassDrop:

        if "CA" in jetALGO:
            setattr(
                proc,
                jetalgo + "PFJets" + PUMethod + "MassDropFiltered",
                ca15PFJetsCHSMassDropFiltered.clone(
                    rParam=jetSize, src=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Constituents")
                ),
            )
            setattr(
                proc,
                jetalgo + "PFJets" + PUMethod + "MassDropFilteredMass",
                ak8PFJetsCHSPrunedMass.clone(
                    src=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                    matched=cms.InputTag(jetalgo + "PFJets" + PUMethod + "MassDropFiltered"),
                    distMax=cms.double(jetSize),
                ),
            )
            elemToKeep += ["keep *_" + jetalgo + "PFJets" + PUMethod + "MassDropFilteredMass_*_*"]
            getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
                jetalgo + "PFJets" + PUMethod + "MassDropFilteredMass"
            ]
            jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "MassDropFiltered")
            jetSeq += getattr(proc, jetalgo + "PFJets" + PUMethod + "MassDropFilteredMass")
        else:
            print "|---- jetToolBox: CMS recommends CambridgeAachen for Mass Drop, you are using " + algorithm + ". JetToolbox will not run Mass Drop."
        toolsUsed.append(jetalgo + "PFJets" + PUMethod + "MassDropFilteredMass")

    if addHEPTopTagger:
        if (jetSize >= 1.0) and ("CA" in jetALGO):

            setattr(
                proc,
                "hepTopTagPFJets" + PUMethod,
                hepTopTagPFJetsCHS.clone(src=cms.InputTag(jetalgo + "PFJets" + PUMethod + "Constituents")),
            )
            setattr(
                proc,
                "hepTopTagPFJets" + PUMethod + "Mass" + jetALGO,
                ak8PFJetsCHSPrunedMass.clone(
                    src=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                    matched=cms.InputTag("hepTopTagPFJets" + PUMethod),
                    distMax=cms.double(jetSize),
                ),
            )
            elemToKeep += ["keep *_hepTopTagPFJets" + PUMethod + "Mass" + jetALGO + "_*_*"]
            getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
                "hepTopTagPFJets" + PUMethod + "Mass" + jetALGO
            ]
            jetSeq += getattr(proc, "hepTopTagPFJets" + PUMethod)
            jetSeq += getattr(proc, "hepTopTagPFJets" + PUMethod + "Mass" + jetALGO)
            toolsUsed.append("hepTopTagPFJets" + PUMethod + "Mass" + jetALGO)
        else:
            print "|---- jetToolBox: CMS recommends CambridgeAachen for HEPTopTagger, you are using " + algorithm + ", and a jet cone size bigger than 1. JetToolbox will not run HEP TopTagger."

        ####### Nsubjettiness
    if addNsub:
        from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

        rangeTau = range(1, maxTau + 1)
        setattr(
            proc,
            "Njettiness" + jetALGO + PUMethod,
            Njettiness.clone(
                src=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                Njets=cms.vuint32(rangeTau),  # compute 1-, 2-, 3-, 4- subjettiness
                # variables for measure definition :
                measureDefinition=cms.uint32(0),  # CMS default is normalized measure
                beta=cms.double(1.0),  # CMS default is 1
                R0=cms.double(jetSize),  # CMS default is jet cone size
                Rcutoff=cms.double(-999.0),  # not used by default
                # variables for axes definition :
                axesDefinition=cms.uint32(6),  # CMS default is 1-pass KT axes
                nPass=cms.int32(-999),  # not used by default
                akAxesR0=cms.double(-999.0),
            ),
        )  # not used by default

        elemToKeep += ["keep *_Njettiness" + jetALGO + PUMethod + "_*_*"]
        for tau in rangeTau:
            getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
                "Njettiness" + jetALGO + PUMethod + ":tau" + str(tau)
            ]
        jetSeq += getattr(proc, "Njettiness" + jetALGO + PUMethod)
        toolsUsed.append("Njettiness" + jetALGO + PUMethod)

        ###### QJetsAdder
    if addQJets:
        """
		#This is the old way before 731
		### there must be a better way to do this random number introduction
		setattr( proc, 'RandomNumberGeneratorService', cms.Service("RandomNumberGeneratorService", 
							QJetsAdderCA8 = cms.PSet(initialSeed = cms.untracked.uint32(7)),
							QJetsAdderAK8 = cms.PSet(initialSeed = cms.untracked.uint32(31)),
							QJetsAdderCA15 = cms.PSet(initialSeed = cms.untracked.uint32(76)), ) )

		from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder
		setattr( proc, 'QJetsAdder'+jetALGO, 
				QJetsAdder.clone( src = cms.InputTag(jetalgo+'PFJets'+PUMethod), 
					jetRad = cms.double( jetSize ), 
					jetAlgo = cms.string( jetALGO[0:2] )))
		elemToKeep += [ 'keep *_QJetsAdder'+jetALGO+'_*_*' ]
		getattr( proc, 'patJets'+jetALGO+'PF'+PUMethod).userData.userFloats.src += ['QJetsAdder'+jetALGO+':QjetsVolatility']  
		jetSeq += getattr(proc, 'QJetsAdder'+jetALGO )
		toolsUsed.append( 'QJetsAdder'+jetALGO )
		"""
        ### This is for 731 or higher
        if "ak4" in jetalgo:
            proc.load("RecoJets.JetProducers.QGTagger_cfi")
            proc.QGTagger.srcJets = cms.InputTag(
                jetalgo + "PFJets" + PUMethod
            )  # Could be reco::PFJetCollection or pat::JetCollection (both AOD and miniAOD)
            proc.QGTagger.jetsLabel = cms.string(
                "QGL_AK4PFchs"
            )  # Other options (might need to add an ESSource for it): see https://twiki.cern.ch/twiki/bin/viewauth/CMS/QGDataBaseVersion
            elemToKeep += ["keep *_QGTagger_*_*"]
            getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += ["QGTagger:qgLikelihood"]
            jetSeq += getattr(proc, "QGTagger")
        else:
            print "|---- jetToolBox: QGTagger is optimized for ak4 jets."

            ####### Pileup JetID
    if addPUJetID:
        if ("ak4" in jetalgo) and ("CHS" in PUMethod):
            from RecoJets.JetProducers.pileupjetidproducer_cfi import pileupJetIdCalculator, pileupJetIdEvaluator

            setattr(
                proc,
                jetALGO + "PF" + PUMethod + "pileupJetIdCalculator",
                pileupJetIdCalculator.clone(
                    jets=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                    rho=cms.InputTag("fixedGridRhoFastjetAll"),
                    vertexes=cms.InputTag(pvLabel),
                ),
            )

            setattr(
                proc,
                jetALGO + "PF" + PUMethod + "pileupJetIdEvaluator",
                pileupJetIdEvaluator.clone(
                    jetids=cms.InputTag(jetALGO + "PF" + PUMethod + "pileupJetIdCalculator"),
                    jets=cms.InputTag(jetalgo + "PFJets" + PUMethod),
                    rho=cms.InputTag("fixedGridRhoFastjetAll"),
                    vertexes=cms.InputTag(pvLabel),
                ),
            )

            getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userFloats.src += [
                jetALGO + "PF" + PUMethod + "pileupJetIdEvaluator:fullDiscriminant"
            ]
            getattr(proc, "patJets" + jetALGO + "PF" + PUMethod).userData.userInts.src += [
                jetALGO + "PF" + PUMethod + "pileupJetIdEvaluator:cutbasedId",
                jetALGO + "PF" + PUMethod + "pileupJetIdEvaluator:fullId",
            ]
            elemToKeep += ["keep *_" + jetALGO + "PF" + PUMethod + "pileupJetIdEvaluator_*_*"]
            toolsUsed.append(jetALGO + "PF" + PUMethod + "pileupJetIdEvaluator")
        else:
            print "|---- jetToolBox: PUJetID is optimized for ak4 PFjets with CHS."

    if hasattr(proc, "patJetPartons"):
        proc.patJetPartons.particles = genParticlesLabel

    setattr(
        proc,
        "selectedPatJets" + jetALGO + "PF" + PUMethod,
        selectedPatJets.clone(src="patJets" + jetALGO + "PF" + PUMethod, cut=Cut),
    )
    elemToKeep += ["keep *_selectedPatJets" + jetALGO + "PF" + PUMethod + "_*_*"]
    elemToKeep += ["drop *_selectedPatJets" + jetALGO + "PF" + PUMethod + "_calo*_*"]
    elemToKeep += ["drop *_selectedPatJets" + jetALGO + "PF" + PUMethod + "_tagInfos_*"]

    print "|---- jetToolBox: Running " + ", ".join(toolsUsed) + "."
    print "|---- jetToolBox: Creating selectedPatJets" + jetALGO + "PF" + PUMethod + " collection."

    ### "return"
    setattr(proc, jetSequence, jetSeq)
    if hasattr(proc, outputFile):
        getattr(proc, outputFile).outputCommands += elemToKeep
    else:
        setattr(
            proc,
            outputFile,
            cms.OutputModule(
                "PoolOutputModule",
                fileName=cms.untracked.string("jettoolbox.root"),
                outputCommands=cms.untracked.vstring(elemToKeep),
            ),
        )
Beispiel #38
0
        groomedFatJets = cms.InputTag('PFJetsCHSPruned'), # needed for subjet flavor clustering
        postfix = postfix
    )

    ## Establish references between PATified fat jets and subjets using the BoostedJetMerger
    process.selectedPatJetsPrunedPFCHSPacked = cms.EDProducer("BoostedJetMerger",
        jetSrc=cms.InputTag("selectedPatJetsPrunedPFCHS"+postfix),
        subjetSrc=cms.InputTag("selectedPatJetsPrunedSubjetsPFCHS"+postfix)
    )

    #-------------------------------------
    ## N-subjettiness
    from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

    process.Njettiness = Njettiness.clone(
        src = cms.InputTag("PFJetsCHS"),
        cone = cms.double(options.jetRadius)
    )

    getattr(process,'patJetsPFCHS'+postfix).userData.userFloats.src += ['Njettiness:tau1','Njettiness:tau2','Njettiness:tau3']

    #-------------------------------------
    ## Grooming ValueMaps
    process.Pruned = cms.EDProducer("RecoJetDeltaRValueMapProducer",
        src = cms.InputTag("PFJetsCHS"),
        matched = cms.InputTag("PFJetsCHSPruned"),
        distMax = cms.double(options.jetRadius),
        values = cms.vstring('mass','pt'),
        valueLabels = cms.vstring('Mass','Pt'),
        lazyParser = cms.bool(True)
    )
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akVsSoftDrop3CaloNjettiness = Njettiness.clone(
    src=cms.InputTag("akVsSoftDrop3CaloJets"), R0=cms.double(0.3))
akVsSoftDrop3CalopatJetsWithBtagging.userData.userFloats.src += [
    'akVsSoftDrop3CaloNjettiness:tau1', 'akVsSoftDrop3CaloNjettiness:tau2',
    'akVsSoftDrop3CaloNjettiness:tau3'
]

akVsSoftDrop3CaloJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akVsSoftDrop3CalopatJetsWithBtagging"),
    genjetTag='ak3HiGenJets',
    rParam=0.3,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
    fillGenJets=True,
    isMC=True,
Beispiel #40
0
#add_fatjets_subjets(process, 'ca15PuppiJets', 'hepTopTagPuppi', genjets_name = lambda s: s.replace('Puppi', 'Gen'))
#add_fatjets_subjets(process, 'ca8PuppiJets', 'ca8PuppiJetsSoftDrop')

# configure PAT for miniAOD:
#process.patJetPartons.particles = 'prunedGenParticles'

from PhysicsTools.PatAlgos.tools.pfTools import *
## Adapt primary vertex collection
adaptPVs(process, pvCollection = cms.InputTag('offlineSlimmedPrimaryVertices'))


# Add subjet variables (on ungroomed jets only!)
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder

process.NjettinessAk8CHS = Njettiness.clone(src = cms.InputTag("patJetsAk8CHSJets"), cone = cms.double(0.8))
process.NjettinessCa15CHS = Njettiness.clone(src = cms.InputTag("patJetsCa15CHSJets"), cone = cms.double(1.5),R0 = cms.double(1.5))
process.NjettinessCa15SoftDropCHS = Njettiness.clone(src = cms.InputTag("patJetsCa15CHSJetsSoftDrop"), cone = cms.double(1.5),R0 = cms.double(1.5))
#process.NjettinessCa8Puppi = Njettiness.clone(src = cms.InputTag("patJetsCa8PuppiJets"), cone = cms.double(0.8))
#process.NjettinessCa15Puppi = Njettiness.clone(src = cms.InputTag("patJetsCa15PuppiJets"), cone = cms.double(1.5))

"""
process.QJetsCa8CHS = QJetsAdder.clone(src = cms.InputTag("patJetsCa8CHSJets"), jetRad = cms.double(0.8))
process.QJetsCa15CHS = QJetsAdder.clone(src = cms.InputTag("patJetsCa15CHSJets"), jetRad = cms.double(1.5))

process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
   QJetsCa8CHS = cms.PSet(
      initialSeed = cms.untracked.uint32(123)
   ),
   QJetsCa15CHS = cms.PSet(
      initialSeed = cms.untracked.uint32(123)
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=True,
    addGenPartonMatch=True,
    addGenJetMatch=True,
    embedGenJetMatch=True,
    embedGenPartonMatch=True,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akFilter5PFNjettiness = Njettiness.clone(src=cms.InputTag("akFilter5PFJets"),
                                         R0=cms.double(0.5))
akFilter5PFpatJetsWithBtagging.userData.userFloats.src += [
    'akFilter5PFNjettiness:tau1', 'akFilter5PFNjettiness:tau2',
    'akFilter5PFNjettiness:tau3'
]

akFilter5PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akFilter5PFpatJetsWithBtagging"),
    genjetTag='ak5HiGenJets',
    rParam=0.5,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
    fillGenJets=True,
    isMC=True,
Beispiel #42
0
for jetcoll in (process.patJetsCA8CHS,
                process.patJetsCA15CHS,
                process.patJetsCA8CHSpruned,
                process.patJetsCA15CHSFiltered,
                process.patJetsCMSTopTagCHS,
                process.patJetsHEPTopTagCHS,
                ) :
        jetcoll.getJetMCFlavour = False
        

# Add subjet variables:
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
#from RecoJets.JetProducers.qjetsadder_cfi import QJetsAdder

process.NjettinessCA8CHS = Njettiness.clone(src = cms.InputTag("patJetsCA8CHS"), cone = cms.double(0.8))
process.NjettinessCA15CHS = Njettiness.clone(src = cms.InputTag("patJetsCA15CHS"), cone = cms.double(1.5))
#process.QJetsCA8CHS = QJetsAdder.clone(src = cms.InputTag("patJetsCA8CHS"), jetRad = cms.double(0.8), jetAlgo = cms.string('CA'))


#NtupleWriter
process.MyNtuple = cms.EDFilter('NtupleWriter',
                                  #AnalysisModule = cms.PSet(
                                  #    name = cms.string("NoopAnalysisModule"),
                                  #    library = cms.string("libUHH2examples.so"),
                                  #    # Note: all other settings of type string are passed to the module, e.g.:
                                  #    TestKey = cms.string("TestValue")
                                  #),
                                  fileName = cms.string("Ntuple.root"), 
                                  runOnMiniAOD = cms.bool(useMiniAOD),
                                  doElectrons = cms.bool(True),
Beispiel #43
0
    addBTagInfo=True,
    addTagInfos=True,
    addDiscriminators=True,
    addAssociatedTracks=True,
    addJetCharge=False,
    addJetID=False,
    getJetMCFlavour=False,
    addGenPartonMatch=False,
    addGenJetMatch=False,
    embedGenJetMatch=False,
    embedGenPartonMatch=False,
    # embedCaloTowers = False,
    # embedPFCandidates = True
)

akPuSoftDrop1PFNjettiness = Njettiness.clone(
    src=cms.InputTag("akPuSoftDrop1PFJets"), R0=cms.double(0.1))
akPuSoftDrop1PFpatJetsWithBtagging.userData.userFloats.src += [
    'akPuSoftDrop1PFNjettiness:tau1', 'akPuSoftDrop1PFNjettiness:tau2',
    'akPuSoftDrop1PFNjettiness:tau3'
]

akPuSoftDrop1PFJetAnalyzer = inclusiveJetAnalyzer.clone(
    jetTag=cms.InputTag("akPuSoftDrop1PFpatJetsWithBtagging"),
    genjetTag='ak1HiGenJets',
    rParam=0.1,
    matchJets=cms.untracked.bool(False),
    matchTag='patJetsWithBtagging',
    pfCandidateLabel=cms.untracked.InputTag('particleFlowTmp'),
    trackTag=cms.InputTag("hiGeneralTracks"),
    fillGenJets=False,
    isMC=False,
    getattr(process,'pfInclusiveSecondaryVertexFinderTagInfosAK8PFCHS').extSVCollection = cms.InputTag('slimmedSecondaryVertices')
getattr(process,'patJetsAK8PFCHS').addAssociatedTracks = cms.bool(False) # needs to be disabled since there is no track collection present in MiniAOD
getattr(process,'patJetsAK8PFCHS').addJetCharge = cms.bool(False)        # needs to be disabled since there is no track collection present in MiniAOD

from RecoJets.JetProducers.ak8PFJetsCHS_groomingValueMaps_cfi import *
process.ak8PFJetsCHSPrunedMass = cms.EDProducer("RecoJetDeltaRValueMapProducer",
    src = cms.InputTag("ak8PFJetsCHS"),
    matched = cms.InputTag("ak8PFJetsCHSPruned"),
    distMax = cms.double(0.8),
    value = cms.string('mass')
    )

### Add Nsubjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
process.Njettiness = Njettiness.clone(
    src = cms.InputTag("ak8PFJetsCHS"),
    cone = cms.double(0.8)
    )

process.patJetsAK8PFCHS.userData.userFloats.src += ['ak8PFJetsCHSPrunedMass','Njettiness:tau1','Njettiness:tau2','Njettiness:tau3']


## PATify pruned fat jets
addJetCollection(
    process,
    labelName = 'AK8PFCHSPruned',
    jetSource = cms.InputTag('ak8PFJetsCHSPruned'),
    btagDiscriminators = ['None'],
    jetCorrections = ('AK8PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute'], 'None'),
    genJetCollection = cms.InputTag('ak8GenJetsNoNu'),
    getJetMCFlavour = False # jet flavor disabled
)
Beispiel #45
0
        addTagInfos = True,
        addDiscriminators = True,
        addAssociatedTracks = True,
        addJetCharge = False,
        addJetID = False,
        getJetMCFlavour = False,
        addGenPartonMatch = False,
        addGenJetMatch = False,
        embedGenJetMatch = False,
        embedGenPartonMatch = False,
        # embedCaloTowers = False,
        # embedPFCandidates = True
        )

akPuSoftDrop5CaloNjettiness = Njettiness.clone(
		    src = cms.InputTag("akPuSoftDrop5CaloJets"),
           	    R0  = cms.double( 0.5)
)
akPuSoftDrop5CalopatJetsWithBtagging.userData.userFloats.src += ['akPuSoftDrop5CaloNjettiness:tau1','akPuSoftDrop5CaloNjettiness:tau2','akPuSoftDrop5CaloNjettiness:tau3']

akPuSoftDrop5CaloJetAnalyzer = inclusiveJetAnalyzer.clone(jetTag = cms.InputTag("akPuSoftDrop5CalopatJetsWithBtagging"),
                                                             genjetTag = 'ak5HiGenJets',
                                                             rParam = 0.5,
                                                             matchJets = cms.untracked.bool(False),
                                                             matchTag = 'patJetsWithBtagging',
                                                             pfCandidateLabel = cms.untracked.InputTag('particleFlowTmp'),
                                                             trackTag = cms.InputTag("hiGeneralTracks"),
                                                             fillGenJets = False,
                                                             isMC = False,
							     doSubEvent = False,
                                                             useHepMC = cms.untracked.bool(False),
							     genParticles = cms.untracked.InputTag("genParticles"),
from RecoJets.JetProducers.QGTagger_cfi import *
CA8QGTaggerPuppi           = QGTagger.clone()
CA8QGTaggerPuppi.srcJets   = cms.InputTag('CA8PFJetsPuppi')
CA8QGTaggerPuppi.jetsLabel = cms.string('QGL_AK4PFchs')
CA8QGTaggerPuppi.jec       = cms.InputTag("ak8PuppiL1FastL2L3Corrector") # NOTE: use "ca8PFPuppiL1FastL2L3Corrector" for MC / "ca8PFPuppiL1FastL2L3ResidualCorrector" for Data

CA8QGTaggerSubJetsPuppi           = CA8QGTaggerPuppi.clone()
CA8QGTaggerSubJetsPuppi.srcJets   = cms.InputTag('CA8caPFJetsSoftDropPuppi','SubJets')
CA8QGTaggerSubJetsPuppi.jetsLabel = cms.string('QGL_AK4PFchs')
CA8QGTaggerSubJetsPuppi.jec       = cms.InputTag("ak8PuppiL1FastL2L3Corrector") # NOTE: use "ca8PFPuppiL1FastL2L3Corrector" for MC / "ca8PFPuppiL1FastL2L3ResidualCorrector" for Data

# N-subjettiness
from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
CA8NjettinessPuppi = Njettiness.clone(
    src   = cms.InputTag('CA8PFJetsPuppi'),
    R0    = cms.double(0.8),
    Njets = cms.vuint32(1,2,3,4)
  )

CA8genjetsequencePuppi = cms.Sequence(
  CA8GenJetsPuppi* 
  CA8FlavorPuppi
)

#
# Define sequences
#
CA8jetsequencePuppi = cms.Sequence(
    CA8PFJetsPuppi*
    CA8caPFJetsPrunedPuppi*
    CA8caPFJetsTrimmedPuppi*
            algoLabels = cms.vstring(),
            fixDaughters = cms.bool(False)
    )
    if options.useSoftDrop:
        process.packedPatJetsPFCHS.algoTags.append( cms.InputTag('selectedPatJetsSoftDropPFCHSPacked') )
        process.packedPatJetsPFCHS.algoLabels.append( 'SoftDrop' )
    if options.usePruned:
        process.packedPatJetsPFCHS.algoTags.append( cms.InputTag('selectedPatJetsPrunedPFCHSPacked') )
        process.packedPatJetsPFCHS.algoLabels.append( 'Pruned' )

    #-------------------------------------
    ## N-subjettiness
    from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness

    process.Njettiness = Njettiness.clone(
        src = cms.InputTag("PFJetsCHS"),
        R0  = cms.double(options.fatJetRadius)
    )

    getattr(process,'patJetsPFCHS'+postfix).userData.userFloats.src += ['Njettiness:tau1','Njettiness:tau2','Njettiness:tau3']


    #-------------------------------------
    ## Grooming ValueMaps
    process.SoftDrop = cms.EDProducer("RecoJetDeltaRValueMapProducer",
        src = cms.InputTag("PFJetsCHS"),
        matched = cms.InputTag("selectedPatJetsSoftDropPFCHSPacked"),
        distMax = cms.double(options.fatJetRadius),
        values = cms.vstring('mass','pt','eta','phi','jecFactor(0)'),
        valueLabels = cms.vstring('Mass','Pt','Eta','Phi','jecFactor0'),
        lazyParser = cms.bool(True)
    )