Exemple #1
0
## customizations for the pp_on_AA eras
from Configuration.Eras.Modifier_pp_on_XeXe_2017_cff import pp_on_XeXe_2017
from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
(pp_on_XeXe_2017 | pp_on_AA).toModify(bTagAnalysis,
                                      doJEC=False
)


########## MC ############
#Matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(
    jets = cms.InputTag("ak4PFJetsCHS"),
    partons = cms.InputTag("selectedHadronsAndPartons","algorithmicPartons"),
    hadronFlavourHasPriority = cms.bool(True)
    )

#Get gen jet collection for real jets
ak4GenJetsForPUid = cms.EDFilter("GenJetSelector",
                                 src = cms.InputTag("ak4GenJets"),
                                 cut = cms.string('pt > 8.'),
                                 filter = cms.bool(False)
                                 )
#do reco gen - reco matching
from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
newpatJetGenJetMatch = patJetGenJetMatch.clone(
    src = cms.InputTag("ak4PFJetsCHS"),
    matched = cms.InputTag("ak4GenJetsForPUid"),
    maxDeltaR = cms.double(0.25),
## Ghost particle collection used for Hadron-Jet association 
# MUST use proper input particle collection
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles = genParticleCollection
)
process.task.add(process.selectedHadronsAndPartons)

## Input particle collection for matching to gen jets (partons + leptons) 
# MUST use use proper input jet collection: the jets to which hadrons should be associated
# rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
# More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets = genJetCollection,
)
process.task.add(process.genJetFlavourInfos)

## Plugin for analysing B hadrons
# MUST use the same particle collection as in selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
process.matchGenBHadron = matchGenBHadron.clone(
    genParticles = genParticleCollection,
    jetFlavourInfos = "genJetFlavourInfos"
)
process.task.add(process.matchGenBHadron)

## Plugin for analysing C hadrons
# MUST use the same particle collection as in selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
Exemple #3
0
def genHFTool(process, useMiniAOD=True):
    # Setting input particle collections to be used by the tools
    genParticleCollection = ''
    genJetCollection = 'ak4GenJetsCustom'
    if useMiniAOD:
        genParticleCollection = 'prunedGenParticles'
        genJetCollection = 'slimmedGenJets'
    else:
        genParticleCollection = 'genParticles'
        ## producing a subset of genParticles to be used for jet reclustering
        from RecoJets.Configuration.GenJetParticles_cff import genParticlesForJetsNoNu
        process.genParticlesForJetsCustom = genParticlesForJetsNoNu.clone(
            src=genParticleCollection)
        # Producing own jets for testing purposes
        from RecoJets.JetProducers.ak4GenJets_cfi import ak4GenJets
        process.ak4GenJetsCustom = ak4GenJets.clone(
            src='genParticlesForJetsCustom',
            rParam=cms.double(0.4),
            jetAlgorithm=cms.string("AntiKt"))

    # Supplies PDG ID to real name resolution of MC particles
    process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")

    # Ghost particle collection used for Hadron-Jet association
    # MUST use proper input particle collection
    process.load("PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi")
    process.selectedHadronsAndPartons.particles = genParticleCollection

    ## Input particle collection for matching to gen jets (partons + leptons)
    # MUST use use proper input jet collection: the jets to which hadrons should be associated
    # rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
    # More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
    from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
    process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
        jets=genJetCollection)

    #for cmssw_7_6_X, not ready for 74x
    #process.load("PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff")
    #added the 3-lines instead of GenHFHadronMatcher_cff
    from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cfi import matchGenHFHadron
    process.matchGenBHadron = matchGenHFHadron.clone(flavour=5)
    process.matchGenCHadron = matchGenHFHadron.clone(flavour=4)
    ## Plugin for analysing B hadrons
    # MUST use the same particle collection as in selectedHadronsAndPartons
    process.matchGenBHadron.genParticles = genParticleCollection
    process.matchGenBHadron.jetFlavourInfos = "genJetFlavourInfos"
    ## Plugin for analysing C hadrons
    # MUST use the same particle collection as in selectedHadronsAndPartons
    process.matchGenCHadron.genParticles = genParticleCollection
    process.matchGenCHadron.jetFlavourInfos = "genJetFlavourInfos"

    process.load("TopQuarkAnalysis.TopTools.GenTtbarCategorizer_cfi")
    process.GenTtbarCategories = process.categorizeGenTtbar.clone(
        genJets=cms.InputTag(genJetCollection), genJetPtMin=cms.double(20.))
    process.GenTtbarCategories30 = process.categorizeGenTtbar.clone(
        genJets=cms.InputTag(genJetCollection), genJetPtMin=cms.double(30.))
    process.GenTtbarCategories40 = process.categorizeGenTtbar.clone(
        genJets=cms.InputTag(genJetCollection), genJetPtMin=cms.double(40.))

    process.catGenTops.genJetLabel = genJetCollection
    process.catGenTops.mcParticleLabel = genParticleCollection
Exemple #4
0
genParticleCollection = "prunedGenParticles"
genJetCollection = "slimmedGenJets"
jetFlavourInfos = "genJetFlavourInfos"
jetAlgo = "AntiKt"
rParam = 0.4
genJetPtMin = 20.
genJetAbsEtaMax = 2.4
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron

process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles=genParticleCollection)
process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets=genJetCollection,
    rParam=cms.double(rParam),
    jetAlgorithm=cms.string(jetAlgo))
process.matchGenBHadron = matchGenBHadron.clone(
    genParticles=genParticleCollection, jetFlavourInfos=jetFlavourInfos)
process.matchGenCHadron = matchGenCHadron.clone(
    genParticles=genParticleCollection, jetFlavourInfos=jetFlavourInfos)

#####Tau#####

updatedTauName = "slimmedTausNewID"  #name of pat::Tau collection with new tau-Ids
import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig

tauIdEmbedder = tauIdConfig.TauIDEmbedder(
    process,
    cms,
    debug=False,
    )
)

#for Inclusive Vertex Finder
process.load('RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff')
process.load('RecoBTag.SecondaryVertex.inclusiveSecondaryVertexFinderTagInfos_cfi')
process.load('RecoBTag.SecondaryVertex.candidateCombinedSecondaryVertexSoftLeptonComputer_cfi')
process.inclusiveVertexFinder.primaryVertices = 'offlinePrimaryVertices' #cms.InputTag("goodOfflinePrimaryVertices")
process.trackVertexArbitrator.primaryVertices = 'offlinePrimaryVertices' #cms.InputTag("goodOfflinePrimaryVertices")

#for the flavour matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone()

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.jetFlavourInfosAK4PFJets = ak4JetFlavourInfos.clone()
process.jetFlavourInfosAK4PFJets.jets = cms.InputTag("pfJetsPFBRECO", '', 'CSVTrainer')
process.jetFlavourInfosAK4PFJets.hadronFlavourHasPriority = True

process.source = cms.Source(
   "PoolSource",
   fileNames = cms.untracked.vstring(
#      'file:/uscms_data/d3/verzetti/RelValTTbar_13_sample.root',
      '/store/relval/CMSSW_7_6_0/RelValTTbar_13_HS/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v11_TSGstudy-v1/00000/0489299E-7B89-E511-9947-0025905B858E.root'
			#'root://cms-xrd-global.cern.ch//store/mc/RunIISpring15DR74/QCD_Pt_30to50_TuneCUETP8M1_13TeV_pythia8/AODSIM/Asympt25ns_MCRUN2_74_V9-v2/00000/022C94E2-5F0F-E511-B8BA-7845C4FC3C98.root'
      ),
   ## eventsToProcess = cms.untracked.VEventRange([
   ##       '1:33:3209',
   ##       '1:33:3294',
   ##       '1:36:3512'
   ##       ])
################################################
### PROCESS PATH
################################################

# Configure a path and endpath to run the producer and output modules

# ----------------------- GenHFHadronMatcher -----------------
if (isTTbar):
    process.load("PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff")

    from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
    process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
        particles=cms.InputTag("prunedGenParticles"))
    from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
    process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
        jets=cms.InputTag("slimmedGenJets"))
    from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
    process.matchGenBHadron = matchGenBHadron.clone(
        genParticles=cms.InputTag("prunedGenParticles"),
        jetFlavourInfos="genJetFlavourInfos")
    from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
    process.matchGenCHadron = matchGenCHadron.clone(
        genParticles=cms.InputTag("prunedGenParticles"),
        jetFlavourInfos="genJetFlavourInfos")
    process.load("TopQuarkAnalysis.TopTools.GenTtbarCategorizer_cfi")
    process.categorizeGenTtbar.genJets = cms.InputTag("slimmedGenJets")

    process.ttbarcat = cms.Sequence(
        process.selectedHadronsAndPartons * process.genJetFlavourInfos *
        process.matchGenBHadron *
        process.matchGenCHadron *  ## gen HF flavour matching
from RecoJets.JetProducers.ak4GenJets_cfi import ak4GenJets
process.ak4GenJetsNoNuNoLepton = ak4GenJets.clone(src = "genParticlesForJetsNoNuNoLepton")

# Ghost particle collection for matching to gen jets (b/c hadrons + leptons)
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(particles = genParticleCollection)

# Flavour info: jet collection with all associated ghosts
# For the moment leptons need to be specified explicitely here, until lepton access can be made more generic in miniAOD
# This is only needed as long as the jetConstituents are not accessible directly in miniAOD, then it should be fixed
# by using the leptons from the constituents, instead of feeding them as ghosts into the jets 

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.ak4GenJetFlavourPlusLeptonInfos = ak4JetFlavourInfos.clone(
    jets = genJetCollection,
    leptons = cms.InputTag("selectedHadronsAndPartons", "leptons")
)


####################################################################
## Generator-level selection 

if genFilter == "ttbar":
    process.load('TtZAnalysis.TreeWriter.topDecayFilter_cff')
    process.topDecayFilter.src=genParticleCollection
    process.topDecayFilter.invert=genFilterInvert
    process.topDecayFilter.partonShower=partonShower
    process.fsFilterSequence = cms.Sequence(process.topDecayFilter)
else :
    process.fsFilterSequence = cms.Sequence()
    
Exemple #8
0
process.load('RecoJets.JetProducers.QGTagger_cfi')
process.QGTagger.srcJets             = process.nero.jets   # Could be reco::PFJetCollection or pat::JetCollection (both AOD and miniAOD)               
process.QGTagger.srcVertexCollection = process.nero.vertices
process.QGTagger.useQualityCuts = cms.bool(False)

# ----------------------- GenHFHadronMatcher -----------------

process.load("PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff")

from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
            particles = process.nero.prunedgen
            )
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
            jets = process.nero.genjets
            )

from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
process.matchGenBHadron = matchGenBHadron.clone(
            genParticles = process.nero.prunedgen,
            jetFlavourInfos = "genJetFlavourInfos"
            )
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
process.matchGenCHadron = matchGenCHadron.clone(
            genParticles = process.nero.prunedgen,
            jetFlavourInfos = "genJetFlavourInfos"
            )
process.load("TopQuarkAnalysis.TopTools.GenTtbarCategorizer_cfi")
process.categorizeGenTtbar.genJets = process.nero.genjets
Exemple #9
0
jetname = 'slimmedJetsAK8'
gjetname = 'slimmedGenJetsAK8'

# Other options: see https://twiki.cern.ch/twiki/bin/viewauth/CMS/QGDataBaseVersion
#process.load('RecoJets.JetProducers.QGTagger_cfi')
#process.QGTagger.srcJets = cms.InputTag(jetname)
#process.QGTagger.jetsLabel  = cms.string('QGL_AK4PFchs')

process.load('PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi')
process.selectedHadronsAndPartons.particles = genParticleCollection
process.physDefHadronsAndPartons = process.selectedHadronsAndPartons.clone(
    fullChainPhysPartons=cms.bool(False))

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.jetFlavs = ak4JetFlavourInfos.clone(jets=gjetname,
                                            partons=cms.InputTag(
                                                "selectedHadronsAndPartons",
                                                "algorithmicPartons"))
process.jetFlavsPD = process.jetFlavs.clone(
    partons=cms.InputTag("physDefHadronsAndPartons", "physicsPartons"))

process.load("PhysicsTools.PatAlgos.patSequences_cff")

process.ak8 = cms.EDAnalyzer(
    'ProcessedTreeProducerBTag',
    ## jet collections ###########################
    pfjetschs=cms.InputTag(jetname),
    pfchsjetpuid=cms.string('pileupJetId:fullDiscriminant'),
    runYear=cms.untracked.string("2016"),
    ## MET collection ####
    pfmetT1=cms.InputTag('slimmedMETs'),
    genjets=cms.untracked.InputTag(gjetname),
Exemple #10
0
process.es_prefer_qg = cms.ESPrefer('PoolDBESSource', 'QGPoolDBESSource')

process.load('RecoJets.JetProducers.QGTagger_cfi')
process.QGTagger.srcJets = process.nero.jets  # Could be reco::PFJetCollection or pat::JetCollection (both AOD and miniAOD)
process.QGTagger.srcVertexCollection = process.nero.vertices
process.QGTagger.useQualityCuts = cms.bool(False)

# ----------------------- GenHFHadronMatcher -----------------

process.load("PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff")

from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles=process.nero.prunedgen)
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets=process.nero.genjets)

from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
process.matchGenBHadron = matchGenBHadron.clone(
    genParticles=process.nero.prunedgen, jetFlavourInfos="genJetFlavourInfos")
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
process.matchGenCHadron = matchGenCHadron.clone(
    genParticles=process.nero.prunedgen, jetFlavourInfos="genJetFlavourInfos")
process.load("TopQuarkAnalysis.TopTools.GenTtbarCategorizer_cfi")
process.categorizeGenTtbar.genJets = process.nero.genjets

process.ttbarcat = cms.Sequence()
if not isData:
    process.ttbarcat = cms.Sequence(
        process.selectedHadronsAndPartons * process.genJetFlavourInfos *
        process.matchGenBHadron *
import FWCore.ParameterSet.Config as cms
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

ak4GenJetFlavourInfos = ak4JetFlavourInfos.clone(jets = "ak4GenJetsNoNu")

Exemple #12
0
bTagAnalysis.doJetID = True
bTagAnalysis.doJEC = True
#Residual correction will be added inside the c++ code only for data (checking the presence of genParticles collection), not explicit here as this sequence also ran on MC FullSim
bTagPlotsDATA = cms.Sequence(bTagAnalysis)

## customizations for the pp_on_AA eras
from Configuration.Eras.Modifier_pp_on_XeXe_2017_cff import pp_on_XeXe_2017
from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
(pp_on_XeXe_2017 | pp_on_AA).toModify(bTagAnalysis, doJEC=False)

########## MC ############
#Matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(
    jets="ak4PFJetsCHS",
    partons="selectedHadronsAndPartons:algorithmicPartons",
    hadronFlavourHasPriority=True)

#Get gen jet collection for real jets
ak4GenJetsForPUid = cms.EDFilter("GenJetSelector",
                                 src=cms.InputTag("ak4GenJets"),
                                 cut=cms.string('pt > 8.'),
                                 filter=cms.bool(False))
#do reco gen - reco matching
from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
newpatJetGenJetMatch = patJetGenJetMatch.clone(src="ak4PFJetsCHS",
                                               matched="ak4GenJetsForPUid",
                                               maxDeltaR=0.25,
                                               resolveAmbiguities=True)

from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
        rParam = cms.double(0.4)
)
seq += process.ak4GenJetsCustom

    
# Ghost particle collection used for Hadron-Jet association 
# MUST use proper input particle collection
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
        particles = cms.InputTag(genParticleCollection)
)
seq += process.selectedHadronsAndPartons

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
	jets = cms.InputTag(genJetCollection)
)
seq += process.genJetFlavourInfos
    
# Input particle collection for matching to gen jets (partons + leptons) 
# MUST use use proper input jet collection: the jets to which hadrons should be associated
# rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
# More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition


    
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
# Plugin for analysing B hadrons
# MUST use the same particle collection as in selectedHadronsAndPartons
process.matchGenBHadron = matchGenBHadron.clone(
        genParticles = cms.InputTag(genParticleCollection),
Exemple #14
0
process.prunedGenParticles = prunedGenParticlesWithStatusOne.clone()

genParticleSequence = cms.Sequence(process.generatorSmeared +
                                   process.genParticles +
                                   process.prunedGenParticles)

#################
## JET FLAVORS ##
#################

process.load('PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi')
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

process.selectedHadronsAndPartons.particles = 'prunedGenParticles'

process.ak4GenJetFlavourInfos = ak4JetFlavourInfos.clone(jets='ak4GenJets')
process.ak8GenJetFlavourInfos = ak4JetFlavourInfos.clone(jets='ak8GenJets',
                                                         rParam=0.8)

genJetFlavorSequence = cms.Sequence(process.selectedHadronsAndPartons +
                                    process.ak4GenJetFlavourInfos +
                                    process.ak8GenJetFlavourInfos)

### RECO PATH

process.reco = cms.Path(genParticleSequence + genJetFlavorSequence)

#############
## NTUPLES ##
#############
  payload     = cms.untracked.string('AK8PFchs'),
  shiftJES    = cms.untracked.double(1.0),
  doShift     = cms.untracked.bool(True)
)

process.shiftedJetsAK8Down = process.shiftedJetsAK8Up.clone(shiftJES = -1.0)

genParticleCollection = 'prunedGenParticles'
genJetCollection = 'slimmedGenJetsAK8'

from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(particles = genParticleCollection)

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.ak8genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets = genJetCollection,
    rParam = cms.double(0.8),
)

#only needed if information of the associated b hadrons are required
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
process.matchGenBHadron = matchGenBHadron.clone(
    genParticles = genParticleCollection,
    jetFlavourInfos = cms.InputTag("ak8genJetFlavourInfos"),
    flavour = cms.int32(5),
    onlyJetClusteredHadrons = cms.bool(True),
    noBBbarResonances = cms.bool(False),
)


##-------------------- User analyzers  --------------------------------
process.boosted = cms.EDAnalyzer('BoostedTTbarFlatTreeProducer',
Exemple #16
0
def initialize(**kwargs):
    isMC = kwargs.get("isMC", True)
    lumisToProcess = kwargs.get("lumisToProcess", None)

    process = cms.Process("EX")
    if lumisToProcess == None:
        process.source = cms.Source("PoolSource",
            fileNames = cms.untracked.vstring("file:///scratch/gregor/TTJets_MSDecaysCKM_central_Tune4C_13TeV_MiniAOD.root")
        )
    else:
        process.source = cms.Source("PoolSource",
            fileNames = cms.untracked.vstring("file:///scratch/gregor/TTJets_MSDecaysCKM_central_Tune4C_13TeV_MiniAOD.root"),
            lumisToProcess = lumisToProcess
        )
    process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(100) )

    process.OUT = cms.OutputModule("PoolOutputModule",
        fileName = cms.untracked.string('test.root'),
        outputCommands = cms.untracked.vstring(['drop *'])
    )
    process.endpath= cms.EndPath(process.OUT)

    # Let CMSSW take care of scheduling 
    process.options = cms.untracked.PSet(     
        wantSummary = cms.untracked.bool(True),
        allowUnscheduled = cms.untracked.bool(True)
    )

    skip_ca15 = False

    # 76X PU ID
#    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
#    process.GlobalTag = GlobalTag(process.GlobalTag, '76X_mcRun2_asymptotic_RunIIFall15DR76_v1')
    process.load("RecoJets.JetProducers.PileupJetID_cfi")
    process.pileupJetIdUpdated = process.pileupJetId.clone(
    jets=cms.InputTag("slimmedJets"),
      inputIsCorrected=True,
      applyJec=False,
      vertexes=cms.InputTag("offlineSlimmedPrimaryVertices")
    )
    process.OUT.outputCommands.append("keep *_pileupJetIdUpdated_fullId_EX")

    ########################################
    # Boosted Substructure
    ########################################


    # Select candidates that would pass CHS requirements
    process.chs = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string("fromPV"))

    if isMC:
        process.OUT.outputCommands.append("keep *_slimmedJetsAK8_*_PAT")
    else:
        process.OUT.outputCommands.append("keep *_slimmedJetsAK8_*_RECO")

    if not skip_ca15:
        # CA, R=1.5, pT > 200 GeV
        process.ca15PFJetsCHS = cms.EDProducer(
                "FastjetJetProducer",
                PFJetParameters,
                AnomalousCellParameters,
                jetAlgorithm = cms.string("CambridgeAachen"),
                rParam       = cms.double(1.5))
        process.ca15PFJetsCHS.src = cms.InputTag("chs")
        process.ca15PFJetsCHS.jetPtMin = cms.double(200.)

        # Calculate tau1, tau2 and tau3 for ungroomed CA R=1.5 jets
        process.ca15PFJetsCHSNSubjettiness  = cms.EDProducer("NjettinessAdder",
                                                             src=cms.InputTag("ca15PFJetsCHS"),
                                                             cone=cms.double(1.5),
                                                             Njets = cms.vuint32(1,2,3),
                                                             # 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
        )

        # Apply pruning to CA R=1.5 jets
        process.ca15PFPrunedJetsCHS = process.ca15PFJetsCHS.clone(
            usePruning = cms.bool(True),
            nFilt = cms.int32(2),
            zcut = cms.double(0.1),
            rcut_factor = cms.double(0.5),
            useExplicitGhosts = cms.bool(True),
            writeCompound = cms.bool(True), # Also write subjets for pruned fj
            jetCollInstanceName=cms.string("SubJets"),
        )

        # Apply softdrop to CA R=1.5 jets
        process.ca15PFSoftdropJetsCHS = process.ca15PFJetsCHS.clone(
            useSoftDrop = cms.bool(True),
            zcut = cms.double(0.1),
            beta = cms.double(0.0),
            R0 = cms.double(1.5),
            useExplicitGhosts = cms.bool(True))

        # Apply softdrop z=0.2, beta=1 to CA R=1.5 jets
        process.ca15PFSoftdropZ2B1JetsCHS = process.ca15PFJetsCHS.clone(
            useSoftDrop = cms.bool(True),
            zcut = cms.double(0.2),
            beta = cms.double(1.),
            R0 = cms.double(1.5),
            useExplicitGhosts = cms.bool(True))

        # Apply trimming to CA R=1.5 jets
        process.ca15PFTrimmedJetsCHS = process.ca15PFJetsCHS.clone(
            useTrimming = cms.bool(True),
            rFilt = cms.double(0.2),
            trimPtFracMin = cms.double(0.06),
            useExplicitGhosts = cms.bool(True))

        # Calculate tau1, tau2 and tau3 for softdrop (z=0.2, beta=1) CA R=1.5 jets
        process.ca15PFSoftdropZ2B1JetsCHSNSubjettiness  = cms.EDProducer("NjettinessAdder",
                                                                         src=cms.InputTag("ca15PFSoftdropZ2B1JetsCHS"),
                                                                         cone=cms.double(1.5),
                                                                         Njets = cms.vuint32(1,2,3),
                                                                         # 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
        )


        # HEPTopTagger (MultiR)
        process.looseOptRHTT = cms.EDProducer(
            "HTTTopJetProducer",
            PFJetParameters,
            AnomalousCellParameters,
            jetCollInstanceName=cms.string("SubJets"),
            useExplicitGhosts = cms.bool(True),
            writeCompound  = cms.bool(True), 
            optimalR       = cms.bool(True),
            algorithm      = cms.int32(1),
            jetAlgorithm   = cms.string("CambridgeAachen"),
            rParam         = cms.double(1.5),
            mode           = cms.int32(4),
            minFatjetPt    = cms.double(200.),
            minCandPt      = cms.double(200.),
            minSubjetPt    = cms.double(30.),
            minCandMass    = cms.double(0.),
            maxCandMass    = cms.double(1000),
            massRatioWidth = cms.double(100.),
            minM23Cut      = cms.double(0.),
            minM13Cut      = cms.double(0.),
            maxM13Cut      = cms.double(2.))
        process.looseOptRHTT.src = cms.InputTag("chs")
        process.looseOptRHTT.jetPtMin = cms.double(200.)

        process.OUT.outputCommands.append("keep *_ca15PFJetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFPrunedJetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFSoftdropJetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFSoftdropZ2B1JetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFTrimmedJetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFJetsCHSNSubjettiness_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFSoftdropZ2B1JetsCHSNSubjettiness_*_EX")
        process.OUT.outputCommands.append("keep *_looseOptRHTT_*_EX")




    ########################################
    # Hbb Tagging
    ########################################

    process.load("Configuration.StandardSequences.MagneticField_cff")
    process.load('Configuration.Geometry.GeometryRecoDB_cff')
    process.load("RecoBTag.Configuration.RecoBTag_cff") # this loads all available b-taggers

    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    from Configuration.AlCa.GlobalTag import GlobalTag
    process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc')

    for fatjet_name in ["slimmedJetsAK8", "ca15PFJetsCHS"]:

        if skip_ca15 and (fatjet_name in ["ca15PFJetsCHS"]):
            continue


        if fatjet_name == "slimmedJetsAK8":        
            delta_r = 0.8
            maxSVDeltaRToJet = 0.7
            weightFile = 'RecoBTag/SecondaryVertex/data/BoostedDoubleSV_AK8_BDT_v2.weights.xml.gz'
            jetAlgo = "AntiKt"
        elif fatjet_name == "ca15PFJetsCHS":        
            delta_r = 1.5
            maxSVDeltaRToJet = 1.3
            weightFile = 'RecoBTag/SecondaryVertex/data/BoostedDoubleSV_CA15_BDT_v2.weights.xml.gz'
            jetAlgo = "CambridgeAachen"
        else:
            print "Invalid fatjet for b-tagging: ", fatjet_name
            sys.exit()

        # Define the module names
        impact_info_name          = fatjet_name + "ImpactParameterTagInfos"
        isv_info_name             = fatjet_name + "pfInclusiveSecondaryVertexFinderTagInfos"        
        sm_info_name              = fatjet_name + "softPFMuonsTagInfos"
        se_info_name              = fatjet_name + "softPFElectronsTagInfos"
        bb_comp_name              = fatjet_name + "candidateBoostedDoubleSecondaryVertexComputer"
        tag_name                  = fatjet_name + "pfBoostedDoubleSecondaryVertexBJetTags"

        # Setup the modules
        # IMPACT PARAMETER
        setattr(process, 
                impact_info_name, 
                process.pfImpactParameterTagInfos.clone(
                    primaryVertex = cms.InputTag("offlineSlimmedPrimaryVertices"),
                    candidates = cms.InputTag("packedPFCandidates"),
                    computeProbabilities = cms.bool(False),
                    computeGhostTrack = cms.bool(False),
                    maxDeltaR = cms.double(delta_r),
                    jets = cms.InputTag(fatjet_name),
                ))
        getattr(process, impact_info_name).explicitJTA = cms.bool(False)

        # ISV
        setattr(process,
                isv_info_name,                
                process.pfInclusiveSecondaryVertexFinderTagInfos.clone(
                   extSVCollection               = cms.InputTag('slimmedSecondaryVertices'),
                   trackIPTagInfos               = cms.InputTag(impact_info_name),                
                ))
        getattr(process, isv_info_name).useSVClustering = cms.bool(False)
        getattr(process, isv_info_name).rParam = cms.double(delta_r)
        getattr(process, isv_info_name).extSVDeltaRToJet = cms.double(delta_r)
        getattr(process, isv_info_name).trackSelection.jetDeltaRMax = cms.double(delta_r)
        getattr(process, isv_info_name).vertexCuts.maxDeltaRToJetAxis = cms.double(delta_r)
        getattr(process, isv_info_name).jetAlgorithm = cms.string(jetAlgo)

        # DOUBLE B COMPUTER
        setattr(process,
                bb_comp_name,                
                cms.ESProducer("CandidateBoostedDoubleSecondaryVertexESProducer",
                               trackSelectionBlock,
                               beta = cms.double(1.0),
                               R0 = cms.double(delta_r),
                               maxSVDeltaRToJet = cms.double(maxSVDeltaRToJet),
                               useCondDB = cms.bool(False),
                               weightFile = cms.FileInPath(weightFile),
                               useGBRForest = cms.bool(True),
                               useAdaBoost = cms.bool(False),
                               trackPairV0Filter = cms.PSet(k0sMassWindow = cms.double(0.03))
                           ))
        getattr(process, bb_comp_name).trackSelection.jetDeltaRMax = cms.double(delta_r)

        # TAGS
        setattr(process,
                tag_name, 
                cms.EDProducer("JetTagProducer",
                               jetTagComputer = cms.string(bb_comp_name),
                               tagInfos = cms.VInputTag(cms.InputTag(impact_info_name),
                                                        cms.InputTag(isv_info_name)
                                                    )))


        # SOFT MUON
        setattr(process,
                sm_info_name,
                softPFMuonsTagInfos.clone(
                    jets = cms.InputTag(fatjet_name),
                    muons = cms.InputTag("slimmedMuons"),
                    primaryVertex = cms.InputTag("offlineSlimmedPrimaryVertices")             
                ))

        # SOFT ELECTRON
        setattr(process,
                se_info_name,
                softPFElectronsTagInfos.clone(
                    jets = cms.InputTag(fatjet_name),
                    electrons = cms.InputTag("slimmedElectrons"),
                    primaryVertex = cms.InputTag("offlineSlimmedPrimaryVertices"),                
                    DeltaRElectronJet=cms.double(delta_r),
                ))



        # Produce the output
        for object_name in [impact_info_name, isv_info_name,
                            sm_info_name, se_info_name,          
                            bb_comp_name, tag_name]:

            process.OUT.outputCommands.append("keep *_{0}_*_EX".format(object_name))


    ########################################
    # Subjet b-tagging
    ########################################


    for fatjet_name in ["ca15PFPrunedJetsCHS", "looseOptRHTT"]:

        if skip_ca15 and (fatjet_name in ["ca15PFPrunedJetsCHS", "looseOptRHTT"]):
            continue

        if fatjet_name == "ca15PFPrunedJetsCHS":        
            delta_r = 1.5
            jetAlgo = "CambridgeAachen"
        elif fatjet_name == "looseOptRHTT":
            delta_r = 1.5
            jetAlgo = "CambridgeAachen"
        else:
            print "Invalid fatjet for subjet b-tagging: ", fatjet_name
            sys.exit()

        # Define the module names
        impact_info_name          = fatjet_name + "ImpactParameterTagInfos"
        isv_info_name             = fatjet_name + "pfInclusiveSecondaryVertexFinderTagInfos"        
        csvv2_computer_name       = fatjet_name + "combinedSecondaryVertexV2Computer"
        csvv2ivf_name             = fatjet_name + "pfCombinedInclusiveSecondaryVertexV2BJetTags"        

        # Setup the modules
        # IMPACT PARAMETER
        setattr(process, 
                impact_info_name, 
                process.pfImpactParameterTagInfos.clone(
                    primaryVertex = cms.InputTag("offlineSlimmedPrimaryVertices"),
                    candidates = cms.InputTag("packedPFCandidates"),
                    computeProbabilities = cms.bool(False),
                    computeGhostTrack = cms.bool(False),
                    maxDeltaR = cms.double(delta_r),
                    jets = cms.InputTag(fatjet_name, "SubJets"),
                ))
        getattr(process, impact_info_name).explicitJTA = cms.bool(True)

        # ISV
        setattr(process,
                isv_info_name,                
                process.pfInclusiveSecondaryVertexFinderTagInfos.clone(
                   extSVCollection               = cms.InputTag('slimmedSecondaryVertices'),
                   trackIPTagInfos               = cms.InputTag(impact_info_name),                
                ))
        getattr(process, isv_info_name).useSVClustering = cms.bool(True)
        getattr(process, isv_info_name).rParam = cms.double(delta_r)
        getattr(process, isv_info_name).extSVDeltaRToJet = cms.double(delta_r)
        getattr(process, isv_info_name).trackSelection.jetDeltaRMax = cms.double(delta_r)
        getattr(process, isv_info_name).vertexCuts.maxDeltaRToJetAxis = cms.double(delta_r)
        getattr(process, isv_info_name).jetAlgorithm = cms.string(jetAlgo)
        getattr(process, isv_info_name).fatJets  =  cms.InputTag(fatjet_name.replace("looseOptRHTT","ca15PFJetsCHS"))
        getattr(process, isv_info_name).groomedFatJets  =  cms.InputTag(fatjet_name)

        # CSV V2 COMPUTER
        setattr(process,
                csvv2_computer_name,
                process.candidateCombinedSecondaryVertexV2Computer.clone())

        # CSV IVF V2
        setattr(process,
                csvv2ivf_name,
                process.pfCombinedInclusiveSecondaryVertexV2BJetTags.clone(
                    tagInfos = cms.VInputTag(cms.InputTag(impact_info_name),
                                             cms.InputTag(isv_info_name)),
                    jetTagComputer = cms.string(csvv2_computer_name,)
                ))


        # Produce the output
        process.OUT.outputCommands.append("keep *_{0}_*_EX".format(csvv2ivf_name))




    ###
    ### GenHFHadronMatcher
    ###
    if isMC:
        process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")

        genParticleCollection = 'prunedGenParticles'

        genJetCollection = "slimmedGenJets"

        from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
        process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
           jets = genJetCollection,
        )


        # Ghost particle collection used for Hadron-Jet association
        # MUST use proper input particle collection
        from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
        process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
            particles = genParticleCollection
        )

        # Input particle collection for matching to gen jets (partons + leptons)
        # MUST use use proper input jet collection: the jets to which hadrons should be associated
        # rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
        # More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
#        from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import genJetFlavourPlusLeptonInfos
 #       process.genJetFlavourPlusLeptonInfos = genJetFlavourPlusLeptonInfos.clone(
 #           jets = genJetCollection,
 #           rParam = cms.double(0.4),
 #           jetAlgorithm = cms.string("AntiKt")
 #       )


        # Plugin for analysing B hadrons
        # MUST use the same particle collection as in selectedHadronsAndPartons
        from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
        process.matchGenBHadron = matchGenBHadron.clone(
            genParticles = genParticleCollection
        )

        # Plugin for analysing C hadrons
        # MUST use the same particle collection as in selectedHadronsAndPartons
        from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
        process.matchGenCHadron = matchGenCHadron.clone(
            genParticles = genParticleCollection
        )

        process.categorizeGenTtbar = cms.EDProducer("GenTtbarCategorizer",
            # Phase space of additional jets
            genJetPtMin = cms.double(20.),
            genJetAbsEtaMax = cms.double(2.4),
            # Input tags holding information about b/c hadron matching
            genJets = cms.InputTag(genJetCollection),
            genBHadJetIndex = cms.InputTag("matchGenBHadron", "genBHadJetIndex"),
            genBHadFlavour = cms.InputTag("matchGenBHadron", "genBHadFlavour"),
            genBHadFromTopWeakDecay = cms.InputTag("matchGenBHadron", "genBHadFromTopWeakDecay"),
            genBHadPlusMothers = cms.InputTag("matchGenBHadron", "genBHadPlusMothers"),
            genBHadPlusMothersIndices = cms.InputTag("matchGenBHadron", "genBHadPlusMothersIndices"),
            genBHadIndex = cms.InputTag("matchGenBHadron", "genBHadIndex"),
            genBHadLeptonHadronIndex = cms.InputTag("matchGenBHadron", "genBHadLeptonHadronIndex"),
            genBHadLeptonViaTau = cms.InputTag("matchGenBHadron", "genBHadLeptonViaTau"),
            genCHadJetIndex = cms.InputTag("matchGenCHadron", "genCHadJetIndex"),
            genCHadFlavour = cms.InputTag("matchGenCHadron", "genCHadFlavour"),
            genCHadFromTopWeakDecay = cms.InputTag("matchGenCHadron", "genCHadFromTopWeakDecay"),
            genCHadBHadronId = cms.InputTag("matchGenCHadron", "genCHadBHadronId"),
        )

        process.OUT.outputCommands.append("keep *_matchGenBHadron__EX")
        process.OUT.outputCommands.append("keep *_matchGenCHadron__EX")
        process.OUT.outputCommands.append("keep *_matchGenBHadron_*_EX")
        process.OUT.outputCommands.append("keep *_matchGenCHadron_*_EX")
        process.OUT.outputCommands.append("keep *_categorizeGenTtbar_*_EX")
        process.OUT.outputCommands.append("keep *_categorizeGenTtbar__EX")

    #Schedule to run soft muon and electron taggers on miniAOD
    process.softPFElectronsTagInfos.jets = cms.InputTag("slimmedJets")
    process.softPFElectronsTagInfos.electrons = cms.InputTag("slimmedElectrons")
    process.softPFElectronsTagInfos.primaryVertex = cms.InputTag("offlineSlimmedPrimaryVertices")
            
    process.softPFMuonsTagInfos.jets = cms.InputTag("slimmedJets")
    process.softPFMuonsTagInfos.muons = cms.InputTag("slimmedMuons")
    process.softPFMuonsTagInfos.primaryVertex = cms.InputTag("offlineSlimmedPrimaryVertices")
        
    process.OUT.outputCommands.append("keep *_softPFElectronsTagInfos_*_*")
    process.OUT.outputCommands.append("keep *_softPFMuonsTagInfos_*_*")
    process.OUT.outputCommands.append("keep *_softPFElectronBJetTags_*_EX")
    process.OUT.outputCommands.append("keep *_softPFMuonBJetTags_*_EX")



    ########################################
    # Generator level hadronic tau decays
    ########################################
    if isMC:
        process.load("PhysicsTools.JetMCAlgos.TauGenJets_cfi")
        process.tauGenJets.GenParticles = cms.InputTag('prunedGenParticles')
        process.load("PhysicsTools.JetMCAlgos.TauGenJetsDecayModeSelectorAllHadrons_cfi")
        process.OUT.outputCommands.append("keep *_tauGenJetsSelectorAllHadrons_*_EX")



    ########################################
    # Electron MVA ID: https://twiki.cern.ch/twiki/bin/viewauth/CMS/MultivariateElectronIdentificationRun2#Recipes_and_implementation
    ########################################
   
    from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
    switchOnVIDElectronIdProducer(process, DataFormat.MiniAOD)
    for eleid in ["RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_Trig_V1_cff"]:
        setupAllVIDIdsInModule(process, eleid, setupVIDElectronSelection)
    for eleid in ["RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_nonTrig_V1_cff"]:
        setupAllVIDIdsInModule(process, eleid, setupVIDElectronSelection)
    process.OUT.outputCommands.append("keep *_electronMVAValueMapProducer_*_EX")
    process.OUT.outputCommands.append("keep *_egmGsfElectronIDs_*_EX")
    
    return process
######### DATA ############
from DQMOffline.RecoB.bTagAnalysisData_cfi import *
bTagAnalysis.ptRanges = cms.vdouble(0.0)
bTagAnalysis.doJetID = True
bTagAnalysis.doJEC = True
#Residual correction will be added inside the c++ code only for data (checking the presence of genParticles collection), not explicit here as this sequence also ran on MC FullSim
bTagPlotsDATA = cms.Sequence(pfDeepCSVDiscriminatorsJetTags * bTagAnalysis)

########## MC ############
#Matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(
    jets = cms.InputTag("ak4PFJetsCHS"),
    partons = cms.InputTag("selectedHadronsAndPartons","algorithmicPartons"),
    hadronFlavourHasPriority = cms.bool(True)
    )

#Get gen jet collection for real jets
ak4GenJetsForPUid = cms.EDFilter("GenJetSelector",
                                 src = cms.InputTag("ak4GenJets"),
                                 cut = cms.string('pt > 8.'),
                                 filter = cms.bool(False)
                                 )
#do reco gen - reco matching
from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
newpatJetGenJetMatch = patJetGenJetMatch.clone(
    src = cms.InputTag("ak4PFJetsCHS"),
    matched = cms.InputTag("ak4GenJetsForPUid"),
    maxDeltaR = cms.double(0.25),
Exemple #18
0
import FWCore.ParameterSet.Config as cms

######### DATA ############
from DQMOffline.RecoB.bTagAnalysisData_cfi import *
bTagAnalysis.ptRanges = cms.vdouble(0.0)
bTagAnalysis.doJetID = True
bTagAnalysis.doJEC = True
#Residual correction will be added inside the c++ code only for data (checking the presence of genParticles collection), not explicit here as this sequence also ran on MC FullSim
bTagPlotsDATA = cms.Sequence(bTagAnalysis)

########## MC ############
#Matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(
    jets=cms.InputTag("ak4PFJetsCHS"), hadronFlavourHasPriority=cms.bool(True))

#Get gen jet collection for real jets
ak4GenJetsForPUid = cms.EDFilter("GenJetSelector",
                                 src=cms.InputTag("ak4GenJets"),
                                 cut=cms.string('pt > 8.'),
                                 filter=cms.bool(False))
#do reco gen - reco matching
from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
newpatJetGenJetMatch = patJetGenJetMatch.clone(
    src=cms.InputTag("ak4PFJetsCHS"),
    matched=cms.InputTag("ak4GenJetsForPUid"),
    maxDeltaR=cms.double(0.25),
    resolveAmbiguities=cms.bool(True))

# Module execution for MC
Exemple #19
0
def initialize(isMC=True):

    process = cms.Process("EX")
    process.source = cms.Source(
        "PoolSource",
        fileNames=cms.untracked.vstring(
            "file:///scratch/gregor/TTJets_MSDecaysCKM_central_Tune4C_13TeV_MiniAOD.root"
        ))
    process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(100))

    process.OUT = cms.OutputModule("PoolOutputModule",
                                   fileName=cms.untracked.string('test.root'),
                                   outputCommands=cms.untracked.vstring(
                                       ['drop *']))
    process.endpath = cms.EndPath(process.OUT)

    # Let CMSSW take care of scheduling
    process.options = cms.untracked.PSet(
        wantSummary=cms.untracked.bool(True),
        allowUnscheduled=cms.untracked.bool(True))

    skip_ca15 = False

    ########################################
    # Boosted Substructure
    ########################################

    # Select candidates that would pass CHS requirements
    process.chs = cms.EDFilter("CandPtrSelector",
                               src=cms.InputTag("packedPFCandidates"),
                               cut=cms.string("fromPV"))

    # Apply pruning to AK R=0.8 jets
    process.ak08PFPrunedJetsCHS = cms.EDProducer(
        "FastjetJetProducer",
        PFJetParameters,
        AnomalousCellParameters,
        jetAlgorithm=cms.string("AntiKt"),
        rParam=cms.double(0.8),
        usePruning=cms.bool(True),
        nFilt=cms.int32(2),
        zcut=cms.double(0.1),
        rcut_factor=cms.double(0.5),
        useExplicitGhosts=cms.bool(True),
        writeCompound=cms.bool(True),  # Also write subjets for pruned fj
        jetCollInstanceName=cms.string("SubJets"))
    process.ak08PFPrunedJetsCHS.src = cms.InputTag("chs")
    process.ak08PFPrunedJetsCHS.jetPtMin = cms.double(200.)

    if isMC:
        process.OUT.outputCommands.append("keep *_slimmedJetsAK8_*_PAT")
    else:
        process.OUT.outputCommands.append("keep *_slimmedJetsAK8_*_RECO")

    process.OUT.outputCommands.append("keep *_ak08PFPrunedJetsCHS_*_EX")

    if not skip_ca15:
        # CA, R=1.5, pT > 200 GeV
        process.ca15PFJetsCHS = cms.EDProducer(
            "FastjetJetProducer",
            PFJetParameters,
            AnomalousCellParameters,
            jetAlgorithm=cms.string("CambridgeAachen"),
            rParam=cms.double(1.5))
        process.ca15PFJetsCHS.src = cms.InputTag("chs")
        process.ca15PFJetsCHS.jetPtMin = cms.double(200.)

        # Calculate tau1, tau2 and tau3 for ungroomed CA R=1.5 jets
        process.ca15PFJetsCHSNSubjettiness = cms.EDProducer(
            "NjettinessAdder",
            src=cms.InputTag("ca15PFJetsCHS"),
            cone=cms.double(1.5),
            Njets=cms.vuint32(1, 2, 3),
            # 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
        )

        # Apply pruning to CA R=1.5 jets
        process.ca15PFPrunedJetsCHS = process.ca15PFJetsCHS.clone(
            usePruning=cms.bool(True),
            nFilt=cms.int32(2),
            zcut=cms.double(0.1),
            rcut_factor=cms.double(0.5),
            useExplicitGhosts=cms.bool(True),
            writeCompound=cms.bool(True),  # Also write subjets for pruned fj
            jetCollInstanceName=cms.string("SubJets"),
        )

        # Apply softdrop to CA R=1.5 jets
        process.ca15PFSoftdropJetsCHS = process.ca15PFJetsCHS.clone(
            useSoftDrop=cms.bool(True),
            zcut=cms.double(0.1),
            beta=cms.double(0.0),
            R0=cms.double(1.5),
            useExplicitGhosts=cms.bool(True))

        # Apply softdrop z=0.2, beta=1 to CA R=1.5 jets
        process.ca15PFSoftdropZ2B1JetsCHS = process.ca15PFJetsCHS.clone(
            useSoftDrop=cms.bool(True),
            zcut=cms.double(0.2),
            beta=cms.double(1.),
            R0=cms.double(1.5),
            useExplicitGhosts=cms.bool(True))

        # Apply trimming to CA R=1.5 jets
        process.ca15PFTrimmedJetsCHS = process.ca15PFJetsCHS.clone(
            useTrimming=cms.bool(True),
            rFilt=cms.double(0.2),
            trimPtFracMin=cms.double(0.06),
            useExplicitGhosts=cms.bool(True))

        # Calculate tau1, tau2 and tau3 for softdrop (z=0.2, beta=1) CA R=1.5 jets
        process.ca15PFSoftdropZ2B1JetsCHSNSubjettiness = cms.EDProducer(
            "NjettinessAdder",
            src=cms.InputTag("ca15PFSoftdropZ2B1JetsCHS"),
            cone=cms.double(1.5),
            Njets=cms.vuint32(1, 2, 3),
            # 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
        )

        # HEPTopTagger (MultiR)
        process.looseOptRHTT = cms.EDProducer(
            "HTTTopJetProducer",
            PFJetParameters,
            AnomalousCellParameters,
            jetCollInstanceName=cms.string("SubJets"),
            useExplicitGhosts=cms.bool(True),
            writeCompound=cms.bool(True),
            optimalR=cms.bool(True),
            algorithm=cms.int32(1),
            jetAlgorithm=cms.string("CambridgeAachen"),
            rParam=cms.double(1.5),
            mode=cms.int32(4),
            minFatjetPt=cms.double(200.),
            minCandPt=cms.double(200.),
            minSubjetPt=cms.double(30.),
            minCandMass=cms.double(0.),
            maxCandMass=cms.double(1000),
            massRatioWidth=cms.double(100.),
            minM23Cut=cms.double(0.),
            minM13Cut=cms.double(0.),
            maxM13Cut=cms.double(2.))
        process.looseOptRHTT.src = cms.InputTag("chs")
        process.looseOptRHTT.jetPtMin = cms.double(200.)

        process.OUT.outputCommands.append("keep *_ca15PFJetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFPrunedJetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFSoftdropJetsCHS_*_EX")
        process.OUT.outputCommands.append(
            "keep *_ca15PFSoftdropZ2B1JetsCHS_*_EX")
        process.OUT.outputCommands.append("keep *_ca15PFTrimmedJetsCHS_*_EX")
        process.OUT.outputCommands.append(
            "keep *_ca15PFJetsCHSNSubjettiness_*_EX")
        process.OUT.outputCommands.append(
            "keep *_ca15PFSoftdropZ2B1JetsCHSNSubjettiness_*_EX")
        process.OUT.outputCommands.append("keep *_looseOptRHTT_*_EX")

    ########################################
    # Hbb Tagging
    ########################################

    process.load("Configuration.StandardSequences.MagneticField_cff")
    process.load('Configuration.Geometry.GeometryRecoDB_cff')
    process.load("RecoBTag.Configuration.RecoBTag_cff"
                 )  # this loads all available b-taggers

    process.load(
        "Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    from Configuration.AlCa.GlobalTag import GlobalTag
    process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc')

    for fatjet_name in ["slimmedJetsAK8", "ca15PFJetsCHS"]:

        if skip_ca15 and (fatjet_name in ["ca15PFJetsCHS"]):
            continue

        if fatjet_name == "slimmedJetsAK8":
            delta_r = 0.8
            maxSVDeltaRToJet = 0.7
            weightFile = 'RecoBTag/SecondaryVertex/data/BoostedDoubleSV_AK8_BDT_v2.weights.xml.gz'
            jetAlgo = "AntiKt"
        elif fatjet_name == "ca15PFJetsCHS":
            delta_r = 1.5
            maxSVDeltaRToJet = 1.3
            weightFile = 'RecoBTag/SecondaryVertex/data/BoostedDoubleSV_CA15_BDT_v2.weights.xml.gz'
            jetAlgo = "CambridgeAachen"
        else:
            print "Invalid fatjet for b-tagging: ", fatjet_name
            sys.exit()

        # Define the module names
        impact_info_name = fatjet_name + "ImpactParameterTagInfos"
        isv_info_name = fatjet_name + "pfInclusiveSecondaryVertexFinderTagInfos"
        sm_info_name = fatjet_name + "softPFMuonsTagInfos"
        se_info_name = fatjet_name + "softPFElectronsTagInfos"
        bb_comp_name = fatjet_name + "candidateBoostedDoubleSecondaryVertexComputer"
        tag_name = fatjet_name + "pfBoostedDoubleSecondaryVertexBJetTags"

        # Setup the modules
        # IMPACT PARAMETER
        setattr(
            process, impact_info_name,
            process.pfImpactParameterTagInfos.clone(
                primaryVertex=cms.InputTag("offlineSlimmedPrimaryVertices"),
                candidates=cms.InputTag("packedPFCandidates"),
                computeProbabilities=cms.bool(False),
                computeGhostTrack=cms.bool(False),
                maxDeltaR=cms.double(delta_r),
                jets=cms.InputTag(fatjet_name),
            ))
        getattr(process, impact_info_name).explicitJTA = cms.bool(False)

        # ISV
        setattr(
            process, isv_info_name,
            process.pfInclusiveSecondaryVertexFinderTagInfos.clone(
                extSVCollection=cms.InputTag('slimmedSecondaryVertices'),
                trackIPTagInfos=cms.InputTag(impact_info_name),
            ))
        getattr(process, isv_info_name).useSVClustering = cms.bool(False)
        getattr(process, isv_info_name).rParam = cms.double(delta_r)
        getattr(process, isv_info_name).extSVDeltaRToJet = cms.double(delta_r)
        getattr(
            process,
            isv_info_name).trackSelection.jetDeltaRMax = cms.double(delta_r)
        getattr(
            process,
            isv_info_name).vertexCuts.maxDeltaRToJetAxis = cms.double(delta_r)
        getattr(process, isv_info_name).jetAlgorithm = cms.string(jetAlgo)

        # DOUBLE B COMPUTER
        setattr(
            process, bb_comp_name,
            cms.ESProducer(
                "CandidateBoostedDoubleSecondaryVertexESProducer",
                trackSelectionBlock,
                beta=cms.double(1.0),
                R0=cms.double(delta_r),
                maxSVDeltaRToJet=cms.double(maxSVDeltaRToJet),
                useCondDB=cms.bool(False),
                weightFile=cms.FileInPath(weightFile),
                useGBRForest=cms.bool(True),
                useAdaBoost=cms.bool(False),
                trackPairV0Filter=cms.PSet(k0sMassWindow=cms.double(0.03))))
        getattr(process,
                bb_comp_name).trackSelection.jetDeltaRMax = cms.double(delta_r)

        # TAGS
        setattr(
            process, tag_name,
            cms.EDProducer("JetTagProducer",
                           jetTagComputer=cms.string(bb_comp_name),
                           tagInfos=cms.VInputTag(
                               cms.InputTag(impact_info_name),
                               cms.InputTag(isv_info_name))))

        # SOFT MUON
        setattr(
            process, sm_info_name,
            softPFMuonsTagInfos.clone(
                jets=cms.InputTag(fatjet_name),
                muons=cms.InputTag("slimmedMuons"),
                primaryVertex=cms.InputTag("offlineSlimmedPrimaryVertices")))

        # SOFT ELECTRON
        setattr(
            process, se_info_name,
            softPFElectronsTagInfos.clone(
                jets=cms.InputTag(fatjet_name),
                electrons=cms.InputTag("slimmedElectrons"),
                primaryVertex=cms.InputTag("offlineSlimmedPrimaryVertices"),
                DeltaRElectronJet=cms.double(delta_r),
            ))

        # Produce the output
        for object_name in [
                impact_info_name, isv_info_name, sm_info_name, se_info_name,
                bb_comp_name, tag_name
        ]:

            process.OUT.outputCommands.append(
                "keep *_{0}_*_EX".format(object_name))

    ########################################
    # Subjet b-tagging
    ########################################

    for fatjet_name in [
            "ak08PFPrunedJetsCHS", "ca15PFPrunedJetsCHS", "looseOptRHTT"
    ]:

        if skip_ca15 and (fatjet_name
                          in ["ca15PFPrunedJetsCHS", "looseOptRHTT"]):
            continue

        if fatjet_name == "ak08PFPrunedJetsCHS":
            delta_r = 0.8
            jetAlgo = "AntiKt"
        elif fatjet_name == "ca15PFPrunedJetsCHS":
            delta_r = 1.5
            jetAlgo = "CambridgeAachen"
        elif fatjet_name == "looseOptRHTT":
            delta_r = 1.5
            jetAlgo = "CambridgeAachen"
        else:
            print "Invalid fatjet for subjet b-tagging: ", fatjet_name
            sys.exit()

        # Define the module names
        impact_info_name = fatjet_name + "ImpactParameterTagInfos"
        isv_info_name = fatjet_name + "pfInclusiveSecondaryVertexFinderTagInfos"
        csvv2_computer_name = fatjet_name + "combinedSecondaryVertexV2Computer"
        csvv2ivf_name = fatjet_name + "pfCombinedInclusiveSecondaryVertexV2BJetTags"

        # Setup the modules
        # IMPACT PARAMETER
        setattr(
            process, impact_info_name,
            process.pfImpactParameterTagInfos.clone(
                primaryVertex=cms.InputTag("offlineSlimmedPrimaryVertices"),
                candidates=cms.InputTag("packedPFCandidates"),
                computeProbabilities=cms.bool(False),
                computeGhostTrack=cms.bool(False),
                maxDeltaR=cms.double(delta_r),
                jets=cms.InputTag(fatjet_name, "SubJets"),
            ))
        getattr(process, impact_info_name).explicitJTA = cms.bool(True)

        # ISV
        setattr(
            process, isv_info_name,
            process.pfInclusiveSecondaryVertexFinderTagInfos.clone(
                extSVCollection=cms.InputTag('slimmedSecondaryVertices'),
                trackIPTagInfos=cms.InputTag(impact_info_name),
            ))
        getattr(process, isv_info_name).useSVClustering = cms.bool(True)
        getattr(process, isv_info_name).rParam = cms.double(delta_r)
        getattr(process, isv_info_name).extSVDeltaRToJet = cms.double(delta_r)
        getattr(
            process,
            isv_info_name).trackSelection.jetDeltaRMax = cms.double(delta_r)
        getattr(
            process,
            isv_info_name).vertexCuts.maxDeltaRToJetAxis = cms.double(delta_r)
        getattr(process, isv_info_name).jetAlgorithm = cms.string(jetAlgo)
        getattr(process, isv_info_name).fatJets = cms.InputTag(
            fatjet_name.replace("ak08PFPrunedJetsCHS",
                                "slimmedJetsAK8").replace(
                                    "looseOptRHTT", "ca15PFJetsCHS"))
        getattr(process,
                isv_info_name).groomedFatJets = cms.InputTag(fatjet_name)

        # CSV V2 COMPUTER
        setattr(process, csvv2_computer_name,
                process.candidateCombinedSecondaryVertexV2Computer.clone())

        # CSV IVF V2
        setattr(
            process, csvv2ivf_name,
            process.pfCombinedInclusiveSecondaryVertexV2BJetTags.clone(
                tagInfos=cms.VInputTag(cms.InputTag(impact_info_name),
                                       cms.InputTag(isv_info_name)),
                jetTagComputer=cms.string(csvv2_computer_name, )))

        # Produce the output
        process.OUT.outputCommands.append(
            "keep *_{0}_*_EX".format(csvv2ivf_name))

    ###
    ### GenHFHadronMatcher
    ###
    if isMC:
        process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")

        genParticleCollection = 'prunedGenParticles'

        genJetCollection = "slimmedGenJets"

        from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
        process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
            jets=genJetCollection, )

        # Ghost particle collection used for Hadron-Jet association
        # MUST use proper input particle collection
        from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
        process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
            particles=genParticleCollection)

        # Input particle collection for matching to gen jets (partons + leptons)
        # MUST use use proper input jet collection: the jets to which hadrons should be associated
        # rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
        # More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
        #        from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import genJetFlavourPlusLeptonInfos
        #       process.genJetFlavourPlusLeptonInfos = genJetFlavourPlusLeptonInfos.clone(
        #           jets = genJetCollection,
        #           rParam = cms.double(0.4),
        #           jetAlgorithm = cms.string("AntiKt")
        #       )

        # Plugin for analysing B hadrons
        # MUST use the same particle collection as in selectedHadronsAndPartons
        from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
        process.matchGenBHadron = matchGenBHadron.clone(
            genParticles=genParticleCollection)

        # Plugin for analysing C hadrons
        # MUST use the same particle collection as in selectedHadronsAndPartons
        from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
        process.matchGenCHadron = matchGenCHadron.clone(
            genParticles=genParticleCollection)

        process.categorizeGenTtbar = cms.EDProducer(
            "GenTtbarCategorizer",
            # Phase space of additional jets
            genJetPtMin=cms.double(20.),
            genJetAbsEtaMax=cms.double(2.4),
            # Input tags holding information about b/c hadron matching
            genJets=cms.InputTag(genJetCollection),
            genBHadJetIndex=cms.InputTag("matchGenBHadron", "genBHadJetIndex"),
            genBHadFlavour=cms.InputTag("matchGenBHadron", "genBHadFlavour"),
            genBHadFromTopWeakDecay=cms.InputTag("matchGenBHadron",
                                                 "genBHadFromTopWeakDecay"),
            genBHadPlusMothers=cms.InputTag("matchGenBHadron",
                                            "genBHadPlusMothers"),
            genBHadPlusMothersIndices=cms.InputTag(
                "matchGenBHadron", "genBHadPlusMothersIndices"),
            genBHadIndex=cms.InputTag("matchGenBHadron", "genBHadIndex"),
            genBHadLeptonHadronIndex=cms.InputTag("matchGenBHadron",
                                                  "genBHadLeptonHadronIndex"),
            genBHadLeptonViaTau=cms.InputTag("matchGenBHadron",
                                             "genBHadLeptonViaTau"),
            genCHadJetIndex=cms.InputTag("matchGenCHadron", "genCHadJetIndex"),
            genCHadFlavour=cms.InputTag("matchGenCHadron", "genCHadFlavour"),
            genCHadFromTopWeakDecay=cms.InputTag("matchGenCHadron",
                                                 "genCHadFromTopWeakDecay"),
            genCHadBHadronId=cms.InputTag("matchGenCHadron",
                                          "genCHadBHadronId"),
        )

        process.OUT.outputCommands.append("keep *_matchGenBHadron__EX")
        process.OUT.outputCommands.append("keep *_matchGenCHadron__EX")
        process.OUT.outputCommands.append("keep *_matchGenBHadron_*_EX")
        process.OUT.outputCommands.append("keep *_matchGenCHadron_*_EX")
        process.OUT.outputCommands.append("keep *_categorizeGenTtbar_*_EX")
        process.OUT.outputCommands.append("keep *_categorizeGenTtbar__EX")

    #Schedule to run soft muon and electron taggers on miniAOD
    process.softPFElectronsTagInfos.jets = cms.InputTag("slimmedJets")
    process.softPFElectronsTagInfos.electrons = cms.InputTag(
        "slimmedElectrons")
    process.softPFElectronsTagInfos.primaryVertex = cms.InputTag(
        "offlineSlimmedPrimaryVertices")

    process.softPFMuonsTagInfos.jets = cms.InputTag("slimmedJets")
    process.softPFMuonsTagInfos.muons = cms.InputTag("slimmedMuons")
    process.softPFMuonsTagInfos.primaryVertex = cms.InputTag(
        "offlineSlimmedPrimaryVertices")

    process.OUT.outputCommands.append("keep *_softPFElectronsTagInfos_*_*")
    process.OUT.outputCommands.append("keep *_softPFMuonsTagInfos_*_*")
    process.OUT.outputCommands.append("keep *_softPFElectronBJetTags_*_EX")
    process.OUT.outputCommands.append("keep *_softPFMuonBJetTags_*_EX")

    ########################################
    # Generator level hadronic tau decays
    ########################################
    if isMC:
        process.load("PhysicsTools.JetMCAlgos.TauGenJets_cfi")
        process.tauGenJets.GenParticles = cms.InputTag('prunedGenParticles')
        process.load(
            "PhysicsTools.JetMCAlgos.TauGenJetsDecayModeSelectorAllHadrons_cfi"
        )
        process.OUT.outputCommands.append(
            "keep *_tauGenJetsSelectorAllHadrons_*_EX")

    ########################################
    # Electron MVA ID: https://twiki.cern.ch/twiki/bin/viewauth/CMS/MultivariateElectronIdentificationRun2#Recipes_and_implementation
    ########################################

    from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
    switchOnVIDElectronIdProducer(process, DataFormat.MiniAOD)
    for eleid in [
            "RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_Trig_V1_cff"
    ]:
        setupAllVIDIdsInModule(process, eleid, setupVIDElectronSelection)
    for eleid in [
            "RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_nonTrig_V1_cff"
    ]:
        setupAllVIDIdsInModule(process, eleid, setupVIDElectronSelection)
    process.OUT.outputCommands.append(
        "keep *_electronMVAValueMapProducer_*_EX")
    process.OUT.outputCommands.append("keep *_egmGsfElectronIDs_*_EX")

    return process
import FWCore.ParameterSet.Config as cms
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

ak4GenJetFlavourInfos = ak4JetFlavourInfos.clone(jets="ak4GenJetsNoNu")
    #    src = genJetInputParticleCollection,
    jetAlgorithm=cms.string("AntiKt"),
    rParam=cms.double(0.4))
seq += process.ak4GenJetsCustom

# Ghost particle collection used for Hadron-Jet association
# MUST use proper input particle collection
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons

process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles=cms.InputTag(genParticleCollection))
seq += process.selectedHadronsAndPartons

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets=cms.InputTag(genJetCollection))
seq += process.genJetFlavourInfos

# Input particle collection for matching to gen jets (partons + leptons)
# MUST use use proper input jet collection: the jets to which hadrons should be associated
# rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
# More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition

from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
# Plugin for analysing B hadrons
# MUST use the same particle collection as in selectedHadronsAndPartons
process.matchGenBHadron = matchGenBHadron.clone(
    genParticles=cms.InputTag(genParticleCollection),
    jetFlavourInfos=cms.InputTag("genJetFlavourInfos"),
    onlyJetClusteredHadrons=cms.bool(False))
seq += process.matchGenBHadron
#addMETCollection(process,'patMETPF','pfMetT1')
#patMETs.addGenMet = cms.bool(False)
#patMETs.genMETSource = cms.InputTag("")
process.patJets.addTagInfos = True
process.patJets.getJetMCFlavour = True

genJetCollection = 'ak4GenJetsNoNu'
genParticleCollection = 'genParticles'

from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles=genParticleCollection)

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

process.genJetFlavourInfos = ak4JetFlavourInfos.clone(jets=genJetCollection, )

#You need to create another collection to give the physics definition

process.genJetFlavourInfosPhysicsDef = ak4JetFlavourInfos.clone(
    jets=genJetCollection,
    partons=cms.InputTag("selectedHadronsAndPartons", "physicsPartons"),
)

#fillPhysicsDefinition
# partons = cms.InputTag("selectedHadronsAndPartons","algorithmicPartons"),

process.ak4 = cms.EDAnalyzer(
    'ProcessedTreeProducerBTag',
    ## jet collections ###########################
    #pfjets          = cms.InputTag('selectedPatJetsAK4PF'),
#for Inclusive Vertex Finder
process.load('RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff')
process.load(
    'RecoBTag.SecondaryVertex.inclusiveSecondaryVertexFinderTagInfos_cfi')
process.load(
    'RecoBTag.SecondaryVertex.candidateCombinedSecondaryVertexSoftLeptonComputer_cfi'
)
process.inclusiveVertexFinder.primaryVertices = 'offlinePrimaryVertices'  #cms.InputTag("goodOfflinePrimaryVertices")
process.trackVertexArbitrator.primaryVertices = 'offlinePrimaryVertices'  #cms.InputTag("goodOfflinePrimaryVertices")

#for the flavour matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone()

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.jetFlavourInfosAK4PFJets = ak4JetFlavourInfos.clone()
process.jetFlavourInfosAK4PFJets.jets = cms.InputTag("pfJetsPFBRECO", '',
                                                     'CSVTrainer')
process.jetFlavourInfosAK4PFJets.hadronFlavourHasPriority = True

process.source = cms.Source(
    "PoolSource",
    fileNames=cms.untracked.vstring(
        #      'file:/uscms_data/d3/verzetti/RelValTTbar_13_sample.root',
        '/store/relval/CMSSW_7_6_0/RelValTTbar_13_HS/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v11_TSGstudy-v1/00000/0489299E-7B89-E511-9947-0025905B858E.root'
        #'root://cms-xrd-global.cern.ch//store/mc/RunIISpring15DR74/QCD_Pt_30to50_TuneCUETP8M1_13TeV_pythia8/AODSIM/Asympt25ns_MCRUN2_74_V9-v2/00000/022C94E2-5F0F-E511-B8BA-7845C4FC3C98.root'
    ),
    ## eventsToProcess = cms.untracked.VEventRange([
    ##       '1:33:3209',
    ##       '1:33:3294',
    ##       '1:36:3512'
Exemple #24
0
patAlgosToolsTask.add(process.ak4GenJetsCustom)

## Ghost particle collection used for Hadron-Jet association
# MUST use proper input particle collection
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles = genParticleCollection,
)
patAlgosToolsTask.add(process.selectedHadronsAndPartons)
#Input particle collection for matching to gen jets (partons + leptons)
# MUST use use proper input jet collection: the jets to which hadrons should be associated
# rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
# More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets = genJetCollection,
)
patAlgosToolsTask.add(process.genJetFlavourInfos)

# Plugin for analysing B hadrons
# MUST use the same particle collection as in selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
process.matchGenBHadron = matchGenBHadron.clone(
    genParticles = genParticleCollection,
    jetFlavourInfos = "genJetFlavourInfos",
    onlyJetClusteredHadrons = cms.bool(False)
)

# Plugin for analysing C hadrons
# MUST use the same particle collection as in selectedHadronsAndPartons
#from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
from JetMETCorrections.Configuration.JetCorrectionServices_cff import ak4PFCHSL1Fastjet, ak4PFCHSL2Relative, ak4PFCHSL3Absolute, ak4PFCHSResidual, ak4PFCHSL1FastL2L3, ak4PFCHSL1FastL2L3Residual

######### DATA ############
from DQMOffline.RecoB.bTagAnalysisData_cfi import *
bTagAnalysis.ptRanges = cms.vdouble(0.0)
bTagAnalysis.doJetID = True
bTagAnalysis.doJEC = True
#Residual correction will be added inside the c++ code only for data (checking the presence of genParticles collection), not explicit here as this sequence also ran on MC FullSim
bTagAnalysis.JECsource = cms.string("ak4PFCHSL1FastL2L3") 
bTagPlotsDATA = cms.Sequence(bTagAnalysis)

########## MC ############
#Matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(jets = cms.InputTag("ak4PFJetsCHS"))

#Get gen jet collection for real jets
ak4GenJetsForPUid = cms.EDFilter("GenJetSelector",
                                 src = cms.InputTag("ak4GenJets"),
                                 cut = cms.string('pt > 8.'),
                                 filter = cms.bool(False)
                                 )
#do reco gen - reco matching
from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
newpatJetGenJetMatch = patJetGenJetMatch.clone(
    src = cms.InputTag("ak4PFJetsCHS"),
    matched = cms.InputTag("ak4GenJetsForPUid"),
    maxDeltaR = cms.double(0.25),
    resolveAmbiguities = cms.bool(True)
)
jetsNameAK4 = "selectedUpdatedPatJetsUpdatedJEC"
#jetsNameAK4="slimmedJets"

########################
#  Additional modules  #
########################

if not options.isData:
    process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")

    from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
    process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
        particles="prunedGenParticles")

    from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
    process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
        jets="slimmedGenJets")

    from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
    process.matchGenBHadron = matchGenBHadron.clone(
        genParticles="prunedGenParticles",
        jetFlavourInfos="genJetFlavourInfos")

    from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
    process.matchGenCHadron = matchGenCHadron.clone(
        genParticles="prunedGenParticles",
        jetFlavourInfos="genJetFlavourInfos")

# egamma
from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
switchOnVIDElectronIdProducer(process, DataFormat.MiniAOD)
Exemple #27
0
process.flavourByRefGenJet = cms.EDProducer("JetPartonMatcher",
                                            jets = cms.InputTag("ak4GenJets"),
                                            coneSizeToAssociate = cms.double(0.3),
                                            partons = cms.InputTag("myPartons")
                                            )
process.flavourByValGenJet = cms.EDProducer("JetFlavourIdentifier",
                                            srcByReference = cms.InputTag("flavourByRefGenJet"),
                                            physicsDefinition = cms.bool(False)
                                            )


from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone()

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.myak4PFJetFlavourInfos = ak4JetFlavourInfos.clone(jets = cms.InputTag("ak4PFJets"))

#ak5 jets
from PhysicsTools.JetMCAlgos.AK5PFJetsMCFlavourInfos_cfi import ak5JetFlavourInfos
process.myak5PFJetFlavourInfos = ak5JetFlavourInfos.clone(jets = cms.InputTag("ak5PFJets"))


from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.myak4PFJetCHSFlavourInfos = ak4JetFlavourInfos.clone(jets = cms.InputTag("ak4PFJetsCHS"))

#from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
#process.myak4CaloJetFlavourInfos = ak4JetFlavourInfos.clone(jets = cms.InputTag("ak4CaloJets"))

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.myak4GenJetFlavourInfos = ak4JetFlavourInfos.clone(jets = cms.InputTag("ak4GenJets"))
Exemple #28
0
process.ak4GenJetsNoNuNoLepton = ak4GenJets.clone(
    src="genParticlesForJetsNoNuNoLepton")

# Ghost particle collection for matching to gen jets (b/c hadrons + leptons)
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles=genParticleCollection)

# Flavour info: jet collection with all associated ghosts
# For the moment leptons need to be specified explicitely here, until lepton access can be made more generic in miniAOD
# This is only needed as long as the jetConstituents are not accessible directly in miniAOD, then it should be fixed
# by using the leptons from the constituents, instead of feeding them as ghosts into the jets

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.ak4GenJetFlavourPlusLeptonInfos = ak4JetFlavourInfos.clone(
    jets=genJetCollection,
    leptons=cms.InputTag("selectedHadronsAndPartons", "leptons"))

####################################################################
## Generator-level selection

if genFilter == "ttbar":
    process.load('TtZAnalysis.TreeWriter.topDecayFilter_cff')
    process.topDecayFilter.src = genParticleCollection
    process.topDecayFilter.invert = genFilterInvert
    process.topDecayFilter.partonShower = partonShower
    process.fsFilterSequence = cms.Sequence(process.topDecayFilter)
else:
    process.fsFilterSequence = cms.Sequence()

####################################################################
process.MINIAODSIMoutput_step = cms.EndPath(process.MINIAODSIMoutput)

import UserCode.ICHiggsTauTau.default_producers_cfi as producers

process.icGenParticleProducer = producers.icGenParticleProducer.clone(
    input=cms.InputTag('prunedGenParticles', '', 'PAT'),
    includeMothers=cms.bool(True),
    includeDaughters=cms.bool(True),
    includeStatusFlags=cms.bool(True))

from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles=cms.InputTag('prunedGenParticles', '', 'PAT'))

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets=cms.InputTag("ak4GenJetsNoNu"))

process.MessageLogger.categories += cms.vstring('JetPtMismatch',
                                                'MissingJetConstituent',
                                                'JetPtMismatchAtLowPt')
process.MessageLogger.cerr.JetPtMismatch = cms.untracked.PSet(
    limit=cms.untracked.int32(0))
process.MessageLogger.cerr.MissingJetConstituent = cms.untracked.PSet(
    limit=cms.untracked.int32(0))
process.MessageLogger.cerr.JetPtMismatchAtLowPt = cms.untracked.PSet(
    limit=cms.untracked.int32(0))

process.selectedGenJets = cms.EDFilter("GenJetRefSelector",
                                       src=cms.InputTag("ak4GenJetsNoNu"),
                                       cut=cms.string("pt > 10.0"))
Exemple #30
0
fatJetSequence = cms.Sequence(fatJetInitSequence + ak8CHSSequence +
                              ak8PuppiSequence + ca15CHSSequence +
                              ca15PuppiSequence + ak8CHSDoubleBTagSequence +
                              ak8PuppiDoubleBTagSequence +
                              ca15CHSDoubleBTagSequence +
                              ca15PuppiDoubleBTagSequence)

### GEN JET FLAVORS
if not options.isData:
    process.load('PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi')
    from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

    process.selectedHadronsAndPartons.particles = 'prunedGenParticles'

    process.ak4GenJetFlavourInfos = ak4JetFlavourInfos.clone(
        jets='slimmedGenJets')
    process.ak8GenJetFlavourInfos = ak4JetFlavourInfos.clone(
        jets='genJetsNoNuAK8', rParam=0.8)
    process.ca15GenJetFlavourInfos = ak4JetFlavourInfos.clone(
        jets='genJetsNoNuCA15', jetAlgorithm='CambridgeAachen', rParam=1.5)

    genJetFlavorSequence = cms.Sequence(process.selectedHadronsAndPartons +
                                        process.ak4GenJetFlavourInfos +
                                        process.ak8GenJetFlavourInfos +
                                        process.ca15GenJetFlavourInfos)
else:
    genJetFlavorSequence = cms.Sequence()

### MONOX FILTER

process.load('PandaProd.Filters.MonoXFilter_cfi')
import FWCore.ParameterSet.Config as cms
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

ak4GenJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets="ak4GenJetsNoNu",
    bHadrons=cms.InputTag("selectedHadronsAndPartonsForGenJetsFlavourInfos",
                          "bHadrons"),
    cHadrons=cms.InputTag("selectedHadronsAndPartonsForGenJetsFlavourInfos",
                          "cHadrons"),
    partons=cms.InputTag("selectedHadronsAndPartonsForGenJetsFlavourInfos",
                         "physicsPartons"),
    leptons=cms.InputTag("selectedHadronsAndPartonsForGenJetsFlavourInfos",
                         "leptons"),
)
Exemple #32
0
    src = genParticleCollection,
    rParam = cms.double(0.8),
    jetAlgorithm = cms.string("AntiKt")
)

genParticleCollection = 'prunedGenParticles'
genJetCollection = 'slimmedGenJetsAK8'

from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
    particles = genParticleCollection
)

from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
process.ak8genJetFlavourInfos = ak4JetFlavourInfos.clone(
    jets = genJetCollection,
    rParam = cms.double(0.8),
)

#only needed if information of the associated b hadrons are required
from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
process.matchGenBHadron = matchGenBHadron.clone(
    genParticles = genParticleCollection,
    jetFlavourInfos = cms.InputTag("ak8genJetFlavourInfos"),
    flavour = cms.int32(5),
    onlyJetClusteredHadrons = cms.bool(True),
    noBBbarResonances = cms.bool(False),
)

##-------------------- User analyzer  --------------------------------
process.boosted = cms.EDAnalyzer('BoostedTTbarFlatTreeProducer',
  jets             = cms.InputTag('slimmedJetsAK8'),
Exemple #33
0
import FWCore.ParameterSet.Config as cms

######### DATA ############
from DQMOffline.RecoB.bTagAnalysisData_cfi import *
bTagAnalysis.ptRanges = cms.vdouble(0.0)
bTagAnalysis.doJetID = True
bTagAnalysis.doJEC = True
#Residual correction will be added inside the c++ code only for data (checking the presence of genParticles collection), not explicit here as this sequence also ran on MC FullSim
bTagPlotsDATA = cms.Sequence(bTagAnalysis)

########## MC ############
#Matching
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(
    jets = cms.InputTag("ak4PFJetsCHS"),
    hadronFlavourHasPriority = cms.bool(True)
    )

#Get gen jet collection for real jets
ak4GenJetsForPUid = cms.EDFilter("GenJetSelector",
                                 src = cms.InputTag("ak4GenJets"),
                                 cut = cms.string('pt > 8.'),
                                 filter = cms.bool(False)
                                 )
#do reco gen - reco matching
from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
newpatJetGenJetMatch = patJetGenJetMatch.clone(
    src = cms.InputTag("ak4PFJetsCHS"),
    matched = cms.InputTag("ak4GenJetsForPUid"),
    maxDeltaR = cms.double(0.25),
    resolveAmbiguities = cms.bool(True)