Ejemplo n.º 1
0
def customizeJetTools(process, jecLevels, jecFile, jecTag):

    process.load('CondCore.CondDB.CondDB_cfi')
    from CondCore.CondDB.CondDB_cfi import CondDB
    process.jec = cms.ESSource(
        "PoolDBESSource",
        DBParameters=cms.PSet(messageLevel=cms.untracked.int32(0)),
        timetype=cms.string('runnumber'),
        toGet=cms.VPSet(
            cms.PSet(record=cms.string('JetCorrectionsRecord'),
                     tag=cms.string('JetCorrectorParametersCollection_%s' %
                                    jecTag),
                     label=cms.untracked.string('AK4PFchs')),

            ## here you add as many jet types as you need
            ## note that the tag name is specific for the particular sqlite file
        ),
        connect=cms.string('sqlite_file:%s' % jecFile))
    ## add an es_prefer statement to resolve a possible conflict from simultaneous connection to a global tag
    process.es_prefer_jec = cms.ESPrefer('PoolDBESSource', 'jec')

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
    process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
        src=cms.InputTag("slimmedJets"), levels=jecLevels, payload='AK4PFchs'
    )  # Make sure to choose the appropriate levels and payload here!

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
    process.slimmedJetsReapplyJEC = updatedPatJets.clone(
        jetSource=cms.InputTag("slimmedJets"),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag("patJetCorrFactorsReapplyJEC")))

    #sequence to include
    process.customizeJetToolsSequence = cms.Sequence(
        process.patJetCorrFactorsReapplyJEC + process.slimmedJetsReapplyJEC)
Ejemplo n.º 2
0
def customizeJetTools(process,jecLevels,jecFile,jecTag):

	process.load('CondCore.CondDB.CondDB_cfi')
	from CondCore.CondDB.CondDB_cfi import CondDB
	process.jec = cms.ESSource("PoolDBESSource",
				   DBParameters = cms.PSet(
			messageLevel = cms.untracked.int32(0)
			),
				   timetype = cms.string('runnumber'),
				   toGet = cms.VPSet(
			cms.PSet(
				record = cms.string('JetCorrectionsRecord'),
				tag    = cms.string('JetCorrectorParametersCollection_%s'%jecTag),
				label  = cms.untracked.string('AK4PFchs')
				),


      	## here you add as many jet types as you need
      	## note that the tag name is specific for the particular sqlite file 
     	 ), 
      	connect = cms.string('sqlite_file:%s'%jecFile)
	)
	## add an es_prefer statement to resolve a possible conflict from simultaneous connection to a global tag
	process.es_prefer_jec = cms.ESPrefer('PoolDBESSource','jec')

	from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
	process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
		src = cms.InputTag("slimmedJets"),
		levels = jecLevels,
		payload = 'AK4PFchs' ) # Make sure to choose the appropriate levels and payload here!
	
	from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
	process.slimmedJetsReapplyJEC = updatedPatJets.clone(
		jetSource = cms.InputTag("slimmedJets"),
		jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsReapplyJEC"))
  	)

	#sequence to include
	process.customizeJetToolsSequence = cms.Sequence(process.patJetCorrFactorsReapplyJEC 
							 + process. slimmedJetsReapplyJEC)
Ejemplo n.º 3
0
def recorrectJets(process, isData=False, src="slimmedJets"):
    print 'recorrecting the jets'
    JECTag = 'Summer16_23Sep2016V4_MC'
    if (isData):
        JECTag = 'Summer16_23Sep2016AllV4_DATA'
    cmssw_base = os.environ['CMSSW_BASE']
    ## getting the JEC from the DB
    process.load("CondCore.CondDB.CondDB_cfi")
    process.jec = cms.ESSource(
        "PoolDBESSource",
        DBParameters=cms.PSet(messageLevel=cms.untracked.int32(0)),
        timetype=cms.string('runnumber'),
        toGet=cms.VPSet(
            cms.PSet(record=cms.string('JetCorrectionsRecord'),
                     tag=cms.string('JetCorrectorParametersCollection_' +
                                    JECTag + '_AK4PFchs'),
                     label=cms.untracked.string('AK4PFchs'))),
        connect=cms.string('sqlite:////' + cmssw_base +
                           '/src/PUAnalysis/Configuration/data/' + JECTag +
                           '.db'))

    ## add an es_prefer statement to resolve a possible conflict from simultaneous connection to a global tag
    process.es_prefer_jec = cms.ESPrefer('PoolDBESSource', 'jec')
    ## https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CorrPatJets
    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
    process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
        src=cms.InputTag(src),
        levels=['L1FastJet', 'L2Relative', 'L3Absolute'],
        payload='AK4PFchs'
    )  # Make sure to choose the appropriate levels and payload here!
    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
    process.patJetsReapplyJEC = updatedPatJets.clone(
        jetSource=cms.InputTag(src),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag("patJetCorrFactorsReapplyJEC")))
    if (isData):
        process.patJetCorrFactorsReapplyJEC.levels = [
            'L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual'
        ]
    process.analysisSequence *= process.patJetCorrFactorsReapplyJEC
Ejemplo n.º 4
0
def JetCorrector(process,jetCollection,payloadName,isMC,applyL2L3Residuals):
    
    ## apply corrections on jets                                                                                                                                             
    if not hasattr(process,"patJetCorrFactorsReapplyJEC"+payloadName):
        setattr(process,"patJetCorrFactorsReapplyJEC"+payloadName, updatedPatJetCorrFactors.clone(
                src     = cms.InputTag(jetCollection),
                levels  = process.JECLevels.labels,
                payload = payloadName
                ));

    if "Puppi" in jetCollection or "PUPPI" in jetCollection: ## fix corrections for puppi jets removing L1                                                           
        puppiJEC = copy.deepcopy(process.JECLevels.labels)
        getattr(process,"patJetCorrFactorsReapplyJEC"+payloadName).levels = puppiJEC
        getattr(process,"patJetCorrFactorsReapplyJEC"+payloadName).useRho = True

    if not hasattr(process,"slimmedJetsRecorrected"+payloadName):
        setattr(process,"slimmedJetsRecorrected"+payloadName,
                updatedPatJets.clone(jetSource = cms.InputTag(jetCollection),
                                     jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsReapplyJEC"+payloadName))))


    return "slimmedJetsRecorrected"+payloadName;
Ejemplo n.º 5
0
    setupAllVIDIdsInModule(process, idmod, setupVIDElectronSelection)
process.electronMVAValueMapProducer.srcMiniAOD = cms.InputTag(
    "calibratedPatElectrons")

###Jet part####
## Sequence : 1. JEC 2. QGtagger 3. Producer with QG+JER from JEC applied jets
##############
#############################################################################
#ReApply JEC on Data
#############################################################################
#Remember to change the jet collection name as 'patJetsReapplyJEC'
from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors

process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
    src=cms.InputTag("slimmedJets"),
    ##levels = ['L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual'], ##for DATA
    levels=['L1FastJet', 'L2Relative', 'L3Absolute'],  ##forMC
    payload='AK4PFchs'
)  # Make sure to choose the appropriate levels and payload here!
from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets

process.patJetsReapplyJEC = updatedPatJets.clone(
    jetSource=cms.InputTag("slimmedJets"),
    jetCorrFactorsSource=cms.VInputTag(
        cms.InputTag("patJetCorrFactorsReapplyJEC")))

##############################################################################
##QG tagger
##############################################################################
process.load("CondCore.CondDB.CondDB_cfi")
qgDatabaseVersion = 'cmssw8020_v2'
import os
Ejemplo n.º 6
0
    pfCleaningSequence = cms.Sequence(process.badMuons +
                                      process.cleanMuonsPFCandidates)

    process.reco.insert(0, pfCleaningSequence)

if jetMETReco:
    ### JET RE-CORRECTION

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors, updatedPatJets

    jecLevels = ['L1FastJet', 'L2Relative', 'L3Absolute']
    if options.isData:
        jecLevels.append('L2L3Residual')

    process.updatedPatJetCorrFactors = updatedPatJetCorrFactors.clone(
        src=cms.InputTag('slimmedJets', '', cms.InputTag.skipCurrentProcess()),
        levels=cms.vstring(*jecLevels),
    )

    process.slimmedJets = updatedPatJets.clone(
        jetSource=cms.InputTag('slimmedJets', '',
                               cms.InputTag.skipCurrentProcess()),
        addJetCorrFactors=cms.bool(True),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag('updatedPatJetCorrFactors')),
        addBTagInfo=cms.bool(False),
        addDiscriminators=cms.bool(False))

    jetRecorrectionSequence = cms.Sequence(process.updatedPatJetCorrFactors +
                                           process.slimmedJets)

    process.reco.insert(process.reco.index(process.QGTagger),
Ejemplo n.º 7
0
                        jetCorrections=('AK8PFchs',
                                        cms.vstring([
                                            'L1FastJet', 'L2Relative',
                                            'L3Absolute', 'L2L3Residual'
                                        ]), 'None'),
                        btagDiscriminators=bTagDiscriminators)
    ## Update to latest PU jet ID training
    process.load("RecoJets.JetProducers.PileupJetID_cfi")
    process.pileupJetIdUpdated = process.pileupJetId.clone(
        jets=cms.InputTag("slimmedJets"),
        inputIsCorrected=True,
        applyJec=True,
        vertexes=cms.InputTag("offlineSlimmedPrimaryVertices"))
    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors, updatedPatJets
    process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
        src=cms.InputTag("slimmedJets"),
        levels=['L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual'])
    process.updatedJets = updatedPatJets.clone(
        jetSource=cms.InputTag("slimmedJets"),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag("patJetCorrFactorsReapplyJEC")))
    process.updatedJets.userData.userFloats.src += [
        'pileupJetIdUpdated:fullDiscriminant'
    ]
    process.updatedJets.userData.userInts.src += ['pileupJetIdUpdated:fullId']


def cap(s):
    return s[0].upper() + s[1:]

Ejemplo n.º 8
0
if len(options.lumiFile) > 0:
    import FWCore.PythonUtilities.LumiList as LumiList
    process.source.lumisToProcess = LumiList.LumiList(
        filename=options.lumiFile).getVLuminosityBlockRange()

if options.eventList != '':
    process.source.eventsToProcess = cms.untracked.VEventRange(
        re.split(',', options.eventList))

### re-run JEC and and use corrected jets for MET significance, if requested
if options.ReRunJEC:
    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
    process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
        src=cms.InputTag('slimmedJets'),
        levels=['L1FastJet', 'L2Relative', 'L3Absolute'],
        payload=
        'AK4PFchs'  # Make sure to choose the appropriate levels and payload here!
    )
    if isData:
        process.patJetCorrFactorsReapplyJEC.levels.append('L2L3Residual')

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
    process.patJetsReapplyJEC = updatedPatJets.clone(
        jetSource=cms.InputTag('slimmedJets'),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag('patJetCorrFactorsReapplyJEC')))

    process.JECsequence = cms.Sequence(process.patJetCorrFactorsReapplyJEC *
                                       process.patJetsReapplyJEC)

    JetsInputTag = cms.InputTag('patJetsReapplyJEC', '', processName)
                tag = cms.string("JetCorrectorParametersCollection_"+era+"_AK4PFchs"),
                label= cms.untracked.string("AK4PFchs")
                ),
            )
                               )
    process.es_prefer_jec = cms.ESPrefer("PoolDBESSource",'jec')

### =====================================================================================================


### ReRun JEC ===========================================================================================

from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
  src = cms.InputTag("slimmedJets"),
  levels = ['L1FastJet', 
        'L2Relative', 
        'L3Absolute'],
  payload = 'AK4PFchs' ) # Make sure to choose the appropriate levels and payload here!

if runOnData:
  process.patJetCorrFactorsReapplyJEC.levels.append("L2L3Residual")

from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
process.patJetsReapplyJEC = updatedPatJets.clone(
  jetSource = cms.InputTag("slimmedJets"),
  jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsReapplyJEC"))
  )

### END ReRun JEC ======================================================================================

# Electron ID ==========================================================================================
    'byLooseIsolationMVArun2017v2DBoldDMwLT2017'),
byMediumIsolationMVArun2017v2DBoldDMwLT2017 = cms.string(
    'byMediumIsolationMVArun2017v2DBoldDMwLT2017'),
byTightIsolationMVArun2017v2DBoldDMwLT2017 = cms.string(
    'byTightIsolationMVArun2017v2DBoldDMwLT2017'),
byVTightIsolationMVArun2017v2DBoldDMwLT2017 = cms.string(
    'byVTightIsolationMVArun2017v2DBoldDMwLT2017'),
byVVTightIsolationMVArun2017v2DBoldDMwLT2017 = cms.string(
    'byVVTightIsolationMVArun2017v2DBoldDMwLT2017')

## For normal AK4 jets jet energy correction on top of miniAOD
from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors

process.patJetCorrFactorsReapplyJECAK4 = updatedPatJetCorrFactors.clone(
    src=cms.InputTag("appliedRegJets"),
    levels=jetCorrectionLevelsFullCHS,
    payload='AK4PFchs'
)  # Make sure to choose the appropriate levels and payload here!

from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets

process.patJetsReapplyJECAK4 = updatedPatJets.clone(
    jetSource=cms.InputTag("appliedRegJets"),
    jetCorrFactorsSource=cms.VInputTag(
        cms.InputTag("patJetCorrFactorsReapplyJECAK4")))

process.jetCorrSequenceAK4 = cms.Sequence(
    process.patJetCorrFactorsReapplyJECAK4 + process.patJetsReapplyJECAK4)

### For normal AK8 jet energy correction on top of miniAOD
process.patJetCorrFactorsReapplyJECAK8 = updatedPatJetCorrFactors.clone(
Ejemplo n.º 11
0
def createProcess(
        runOnMC=True,
        # Christians's default. If not touched, it would default to this anyways
        scaleTau=0.,
        recorrectJets=True,
        maxevents=-1,
        verbose=False):
    '''Set up CMSSW process to run MVA MET and SVFit.

    Args:
        runOnMC (bool): run on MC (access to gen-level products) or data
    '''

    sep_line = '-' * 70

    process = cms.Process("H2TAUTAU")
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(maxevents))
    process.load("FWCore.MessageLogger.MessageLogger_cfi")
    process.MessageLogger.cerr.FwkReport.reportEvery = 100
    process.options = cms.untracked.PSet(
        allowUnscheduled=cms.untracked.bool(True),
        wantSummary=cms.untracked.bool(True))

    addNewTauID(process)
    addMETFilters(process)

    if recorrectJets:
        # Adding jet collection
        process.load(
            'Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff'
        )

        # Global tags from https://twiki.cern.ch/twiki/bin/view/CMS/JECDataMC 07 Feb 2017
        process.GlobalTag.globaltag = '80X_mcRun2_asymptotic_2016_TrancheIV_v8'
        if not runOnMC:
            process.GlobalTag.globaltag = '80X_dataRun2_2016SeptRepro_v7'

        process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
        process.load('Configuration.StandardSequences.MagneticField_38T_cff')

        from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
        process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
            src=cms.InputTag("slimmedJets"),
            levels=['L1FastJet', 'L2Relative', 'L3Absolute'],
            payload='AK4PFchs'
        )  # Make sure to choose the appropriate levels and payload here!

        if not runOnMC:
            process.patJetCorrFactorsReapplyJEC.levels += ['L2L3Residual']

        from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
        process.patJetsReapplyJEC = updatedPatJets.clone(
            jetSource=cms.InputTag("slimmedJets"),
            jetCorrFactorsSource=cms.VInputTag(
                cms.InputTag("patJetCorrFactorsReapplyJEC")))

    # We always need this
    runMetCorAndUncFromMiniAOD(process, isData=not runOnMC)

    process.selectedVerticesForPFMEtCorrType0.src = cms.InputTag(
        "offlineSlimmedPrimaryVertices")

    # loadLocalSqlite(process, 'Spring16_25nsV3_DATA.db') #os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/jec/'

    # increase to 1000 before running on the batch, to reduce size of log files
    # on your account
    reportInterval = 100

    print sep_line

    # Input & JSON             -------------------------------------------------

    if runOnMC:
        from CMGTools.H2TauTau.proto.samples.summer16.higgs_susy import HiggsSUSYGG160 as ggh160
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(ggh160.files))
    else:
        # from CMGTools.RootTools.samples.samples_13TeV_DATA2015 import SingleMuon_Run2015D_Promptv4
        from CMGTools.H2TauTau.proto.samples.summer16.htt_common import data_single_muon
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(
                data_single_muon[1].files)  # mu-tau
        )

    if runOnMC:
        process.genEvtWeightsCounter = cms.EDProducer(
            'GenEvtWeightCounter', verbose=cms.untracked.bool(False))

    print 'Run on MC?', runOnMC  #, process.source.fileNames[0]

    # Message logger setup.
    #process.load("FWCore.MessageLogger.MessageLogger_cfi")
    #process.MessageLogger.cerr.FwkReport.reportEvery = reportInterval
    #process.MessageLogger.suppressWarning = cms.untracked.vstring('cmgDiTau')
    #process.options = cms.untracked.PSet(wantSummary=cms.untracked.bool(True))

    #process.options = cms.untracked.PSet(
    #    allowUnscheduled=cms.untracked.bool(True)
    #)

    # OUTPUT definition ----------------------------------------------------------
    process.out = cms.OutputModule(
        "PoolOutputModule",
        fileName=cms.untracked.string('miniaodmod.root'),
        # save only events passing the full path
        # SelectEvents=cms.untracked.PSet(
        #     SelectEvents=cms.vstring()
        # ),
        # save PAT Layer 1 output; you need a '*' to
        # unpack the list of commands 'patEventContent'
        outputCommands=cms.untracked.vstring(
            'keep *_externalLHEProducer_*_*',
            'keep *_TriggerResults_*_*',
            'keep *_selectedPatTrigger_*_*',
            'keep *_patTrigger_*_*',
            'keep *_generator_*_*',
            'keep *_slimmedGenJets_*_*',
            'keep *_prunedGenJets_*_*',
            'keep *_prunedGenParticles_*_*',
            'keep *_packedGenParticles_*_*',
            'keep *_packedPFCandidates_*_*',
            'keep *_slimmedJets_*_*',
            'keep *_slimmedTaus_*_*',
            'keep *_slimmedElectrons_*_*',
            'keep *_slimmedMuons_*_*',
            'keep *_slimmedMETs_*_*',
            'keep *_slimmedMETsPuppi_*_*',  # actually not used?
            'keep *_reducedEgamma_*_*',
            'keep *_offline*PrimaryVertices_*_*',
            'keep *_offlineBeamSpot_*_*',
            'keep *_slimmedAddPileupInfo_*_*',
            'keep *_fixedGrid*_*_*',
            'keep bool_*_*_*',
        ))
    process.outpath = cms.EndPath(process.out)

    if runOnMC:
        #        pass
        process.genEvtWeightsCounterPath = cms.Path(
            process.genEvtWeightsCounter)


#        process.schedule.insert(0, process.genEvtWeightsCounterPath)

    if verbose:
        print sep_line
        print 'INPUT:'
        print sep_line
        print process.source.fileNames
        print
        # if not runOnMC:
        #     print 'json:', json
        print
        print sep_line
        print 'PROCESSING'
        print sep_line
        print 'runOnMC:', runOnMC
        print

    return process
    setupAllVIDIdsInModule(process, idmod, setupVIDElectronSelection)

my_phoid_modules = [
    'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
    'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff'
]

#add them to the VID producer
for idmod in my_phoid_modules:
    setupAllVIDIdsInModule(process, idmod, setupVIDPhotonSelection)

## For normal AK4 jets jet energy correction on top of miniAOD
from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
process.patJetCorrFactorsReapplyJECAK4 = updatedPatJetCorrFactors.clone(
    src=cms.InputTag("slimmedJets"),
    levels=jetCorrectionLevelsFullCHS,
    payload='AK4PFchs'
)  # Make sure to choose the appropriate levels and payload here!

from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
process.patJetsReapplyJECAK4 = updatedPatJets.clone(
    jetSource=cms.InputTag("slimmedJets"),
    jetCorrFactorsSource=cms.VInputTag(
        cms.InputTag("patJetCorrFactorsReapplyJECAK4")))

process.jetCorrSequenceAK4 = cms.Sequence(
    process.patJetCorrFactorsReapplyJECAK4 + process.patJetsReapplyJECAK4)

###########

updateJetCollection(
Ejemplo n.º 13
0
def createProcess(
        runOnMC=True,
        channel='tau-mu',
        runSVFit=False,
        # Christians's default. If not touched, it would default to this anyways
        p4TransferFunctionFile='CMGTools/SVfitStandalone/data/svFitVisMassAndPtResolutionPDF.root',
        integrateOverP4=False,
        scaleTau=0.):
    '''Set up CMSSW process to run MVA MET and SVFit.

    Args:
        runOnMC (bool): run on MC (access to gen-level products) or data
        channel (string): choose from 'tau-mu' 'di-tau' 'tau-ele' 'mu-ele' 
                          'all-separate' 'all'
        runSVFit (bool): enables the svfit mass reconstruction used for the 
                         H->tau tau analysis.
    '''

    sep_line = '-' * 70

    process = cms.Process("H2TAUTAU")

    # Adding jet collection
    process.load(
        'Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff'
    )
    process.GlobalTag.globaltag = '80X_mcRun2_asymptotic_2016_miniAODv2_v1'
    if not runOnMC:
        process.GlobalTag.globaltag = '80X_dataRun2_Prompt_ICHEP16JEC_v0'

    process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
    process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
        src=cms.InputTag("slimmedJets"),
        levels=['L1FastJet', 'L2Relative', 'L3Absolute'],
        payload='AK4PFchs'
    )  # Make sure to choose the appropriate levels and payload here!

    if not runOnMC:
        process.patJetCorrFactorsReapplyJEC.levels += ['L2L3Residual']

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
    process.patJetsReapplyJEC = updatedPatJets.clone(
        jetSource=cms.InputTag("slimmedJets"),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag("patJetCorrFactorsReapplyJEC")))

    # if runOnMC:
    #     runMVAMET(process)
    #
    # else:
    runMVAMET(process, jetCollectionPF="patJetsReapplyJEC")
    runMetCorAndUncFromMiniAOD(process, isData=not runOnMC)

    process.selectedVerticesForPFMEtCorrType0.src = cms.InputTag(
        "offlineSlimmedPrimaryVertices")

    # loadLocalSqlite(process, 'Spring16_25nsV3_DATA.db') #os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/jec/'

    process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(-1))

    numberOfFilesToProcess = -1
    numberOfFilesToProcess = 1
    debugEventContent = False

    # increase to 1000 before running on the batch, to reduce size of log files
    # on your account
    reportInterval = 100

    print sep_line
    print 'channel', channel
    print 'runSVFit', runSVFit

    # Input & JSON             -------------------------------------------------

    # dataset_user = '******'
    # dataset_name = '/VBF_HToTauTau_M-125_13TeV-powheg-pythia6/Spring14dr-PU20bx25_POSTLS170_V5-v1/AODSIM/SS14/'
    # dataset_files = 'miniAOD-prod_PAT_.*root'

    if runOnMC:
        from CMGTools.H2TauTau.proto.samples.spring16.higgs_susy import HiggsSUSYGG160 as ggh160
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(ggh160.files))
    else:
        # from CMGTools.RootTools.samples.samples_13TeV_DATA2015 import SingleMuon_Run2015D_Promptv4
        from CMGTools.H2TauTau.proto.samples.spring16.htt_common import data_single_muon
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(
                data_single_muon[1].files)  # mu-tau
        )

    if runOnMC:
        process.genEvtWeightsCounter = cms.EDProducer(
            'GenEvtWeightCounter', verbose=cms.untracked.bool(False))

    if numberOfFilesToProcess > 0:
        process.source.fileNames = process.source.fileNames[:
                                                            numberOfFilesToProcess]

    print 'Run on MC?', runOnMC  #, process.source.fileNames[0]

    # if not runOnMC:
    #     from CMGTools.H2TauTau.proto.samples.spring16.htt_common import json
    #     # print 'Running on data, setting up JSON file'
    #     # json = setupJSON(process)

    # Message logger setup.
    process.load("FWCore.MessageLogger.MessageLogger_cfi")
    process.MessageLogger.cerr.FwkReport.reportEvery = reportInterval
    process.options = cms.untracked.PSet(wantSummary=cms.untracked.bool(True))

    process.options = cms.untracked.PSet(
        allowUnscheduled=cms.untracked.bool(True))

    pickEvents = False

    if pickEvents:
        process.pickEvents = cms.EDFilter(
            "PickEvents",
            # the original format to input run/event -based selection is described in :
            # DPGAnalysis/Skims/data/listrunev
            # and kept as default, for historical reasons
            RunEventList=cms.untracked.string(
                "CMGTools/H2TauTau/data/eventList.txt"),

            # run/lumiSection @json -based input of selection can be toggled (but not used in THIS example)
            IsRunLsBased=cms.bool(False),

            # json is not used in this example -> list of LS left empty
            LuminositySectionsBlockRange=cms.untracked.VLuminosityBlockRange(
                ()))

    # process.load('JetMETCorrections.Configuration.DefaultJEC_cff')
    # process.load('JetMETCorrections.Configuration.JetCorrectors_cff')

    # # if '25ns' in process.source.fileNames[0] or 'mcRun2_asymptotic_v2' in process.source.fileNames[0]:
    # print 'Using 25 ns MVA MET training'
    # for mvaMETCfg in [process.mvaMETTauMu, process.mvaMETTauEle, process.mvaMETDiMu, process.mvaMETDiTau, process.mvaMETMuEle]:
    #     mvaMETCfg.inputFileNames = cms.PSet(
    #     U     = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru_7_4_X_miniAOD_25NS_July2015.root'),
    #     DPhi  = cms.FileInPath('RecoMET/METPUSubtraction/data/gbrphi_7_4_X_miniAOD_25NS_July2015.root'),
    #     CovU1 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru1cov_7_4_X_miniAOD_25NS_July2015.root'),
    #     CovU2 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru2cov_7_4_X_miniAOD_25NS_July2015.root')
    # )

    # load the channel paths -------------------------------------------

    process.MVAMET.requireOS = cms.bool(False)
    process.MVAMET.srcMETs = cms.VInputTag(
        cms.InputTag("slimmedMETs", "", "PAT" if runOnMC else "RECO"),
        cms.InputTag("patpfMET"), cms.InputTag("patpfMETT1"),
        cms.InputTag("patpfTrackMET"), cms.InputTag("patpfNoPUMET"),
        cms.InputTag("patpfPUCorrectedMET"), cms.InputTag("patpfPUMET"),
        cms.InputTag("slimmedMETsPuppi", "", "PAT" if runOnMC else "RECO"))

    if channel == 'tau-mu':
        process.load('CMGTools.H2TauTau.objects.tauMuObjectsMVAMET_cff')
        if pickEvents:
            process.tauMuPath.insert(0, process.pickEvents)
        process.mvaMETTauMu = process.MVAMET.clone()
        process.mvaMETTauMu.srcLeptons = cms.VInputTag(
            "tauPreSelectionTauMu", "muonPreSelectionTauMu")
        process.mvaMETTauMu.MVAMETLabel = cms.string('mvaMETTauMu')
        process.cmgTauMu.metCollection = cms.InputTag('mvaMETTauMu',
                                                      'mvaMETTauMu')
        if not runSVFit:
            process.cmgTauMuCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgTauMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgTauMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
        if scaleTau:
            process.cmgTauMuCor.nSigma = scaleTau

    elif channel == 'tau-ele':
        process.load('CMGTools.H2TauTau.objects.tauEleObjectsMVAMET_cff')
        process.mvaMETTauEle = process.MVAMET.clone()
        process.mvaMETTauEle.srcLeptons = cms.VInputTag(
            "tauPreSelectionTauEle", "electronPreSelectionTauEle")
        process.mvaMETTauEle.MVAMETLabel = cms.string('mvaMETTauEle')
        process.cmgTauEle.metCollection = cms.InputTag('mvaMETTauEle',
                                                       'mvaMETTauEle')
        if not runSVFit:
            process.cmgTauEleCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgTauEleCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgTauEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    elif channel == 'mu-ele':
        process.load('CMGTools.H2TauTau.objects.muEleObjectsMVAMET_cff')
        process.mvaMETMuEle = process.MVAMET.clone()
        process.mvaMETMuEle.srcLeptons = cms.VInputTag(
            "muonPreSelectionMuEle", "electronPreSelectionMuEle")
        process.mvaMETMuEle.MVAMETLabel = cms.string('mvaMETMuEle')
        process.cmgMuEle.metCollection = cms.InputTag('mvaMETMuEle',
                                                      'mvaMETMuEle')
        if not runSVFit:
            process.cmgMuEleCorSVFitPreSel.SVFitVersion = 0
        else:
            process.cmgMuEleCorSVFitPreSel.SVFitVersion = 2

    # elif channel == 'mu-ele':
    #     process.MVAMET.srcLeptons = cms.VInputTag("electronPreSelectionMuEle", "muonPreSelectionMuEle")
    #     # process.muEleSequence.insert(4, process.MVAMET)
    elif channel == 'di-tau':
        process.load('CMGTools.H2TauTau.objects.diTauObjectsMVAMET_cff')
        process.mvaMETDiTau = process.MVAMET.clone()
        process.mvaMETDiTau.srcLeptons = cms.VInputTag("tauPreSelectionDiTau",
                                                       "tauPreSelectionDiTau")
        process.mvaMETDiTau.MVAMETLabel = cms.string('mvaMETDiTau')
        process.cmgDiTau.metCollection = cms.InputTag('mvaMETDiTau',
                                                      'mvaMETDiTau')
        if not runSVFit:
            process.cmgDiTauCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgDiTauCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgDiTauCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    elif channel == 'di-mu':
        process.load('CMGTools.H2TauTau.objects.diMuObjectsMVAMET_cff')
        process.mvaMETDiMu = process.MVAMET.clone()
        process.mvaMETDiMu.srcLeptons = cms.VInputTag("muonPreSelectionDiMu",
                                                      "muonPreSelectionDiMu")
        process.mvaMETDiMu.MVAMETLabel = cms.string('mvaMETDiMu')
        process.cmgDiMu.metCollection = cms.InputTag('mvaMETDiMu',
                                                     'mvaMETDiMu')
        if not runSVFit:
            process.cmgDiMuCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgDiMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgDiMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    # OUTPUT definition ----------------------------------------------------------
    process.outpath = cms.EndPath()

    if runOnMC:
        #        pass
        process.genEvtWeightsCounterPath = cms.Path(
            process.genEvtWeightsCounter)


#        process.schedule.insert(0, process.genEvtWeightsCounterPath)

# Enable printouts like this:
# process.cmgTauMuCorSVFitPreSel.verbose = True

    oneFile = (channel == 'all')

    if channel == 'tau-mu' or 'all' in channel:
        addTauMuOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)
    if channel == 'tau-ele' or 'all' in channel:
        addTauEleOutput(process,
                        debugEventContent,
                        addPreSel=False,
                        oneFile=oneFile)
    if channel == 'mu-ele' or 'all' in channel:
        addMuEleOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)
    if channel == 'di-mu' or 'all' in channel:
        addDiMuOutput(process,
                      debugEventContent,
                      addPreSel=False,
                      oneFile=oneFile)
    if channel == 'di-tau' or 'all' in channel:
        addDiTauOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)

    if not runOnMC:
        if channel == 'tau-mu' or 'all' in channel:
            process.tauMuSequence.remove(process.cmgTauMuCor)
            process.cmgTauMuTauPtSel.src = 'cmgTauMu'
        if channel == 'tau-ele' or 'all' in channel:
            process.tauEleSequence.remove(process.cmgTauEleCor)
            process.cmgTauEleTauPtSel.src = 'cmgTauEle'
        if channel == 'di-tau' or 'all' in channel:
            process.diTauSequence.remove(process.cmgDiTauCor)
            process.cmgDiTauTauPtSel.src = 'cmgDiTau'

    # if runSVFit:
    #     process.cmgTauMuCorSVFitPreSel.SVFitVersion = 2
    # process.cmgTauEleCorSVFitPreSel.SVFitVersion = 2
    # process.cmgDiTauCorSVFitPreSel.SVFitVersion = 2
    # process.cmgMuEleCorSVFitPreSel.SVFitVersion = 2
    # process.cmgDiMuCorSVFitPreSel.SVFitVersion = 2

    # else:
    #     process.cmgTauMuCorSVFitPreSel.SVFitVersion = 0
    # process.cmgTauEleCorSVFitPreSel.SVFitVersion = 0
    # process.cmgDiTauCorSVFitPreSel.SVFitVersion = 0
    # process.cmgMuEleCorSVFitPreSel.SVFitVersion = 0
    # process.cmgDiMuCorSVFitPreSel.SVFitVersion = 0

    # if integrateOverP4:
    #     process.cmgTauMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgTauEleCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgDiTauCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgMuEleCorSVFitPreSel.integrateOverP4 = integrateOverP4

    # if p4TransferFunctionFile:
    #     process.cmgTauMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgTauEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgDiTauCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgMuEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    print sep_line
    print 'INPUT:'
    print sep_line
    print process.source.fileNames
    print
    # if not runOnMC:
    #     print 'json:', json
    print
    print sep_line
    print 'PROCESSING'
    print sep_line
    print 'runOnMC:', runOnMC
    print

    # from FWCore.ParameterSet.Utilities import convertToUnscheduled
    # convertToUnscheduled(process)
    return process
Ejemplo n.º 14
0
def addJets(process, coll, **kwargs):
    # note: jet cleaning is defined in RootTree.py
    runP = kwargs.pop('runP', 'NA')
    isMC = kwargs.pop('isMC', False)
    jSrc = coll['ak4pfchsjets']
    pvSrc = coll['vertices']
    genSrc = coll['prunedgen']
    packedSrc = coll['packed']
    # customization path
    process.jetCustomization = cms.Path()

    ####################
    #### recorrect jets
    ####################
    levels = ['L1FastJet', 'L2Relative', 'L3Absolute']
    if not isMC: levels.append('L2L3Residual')

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
    process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
        src=cms.InputTag(jSrc), levels=levels, payload='AK4PFchs')
    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
    process.patJetsReapplyJEC = updatedPatJets.clone(
        jetSource=cms.InputTag(jSrc),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag('patJetCorrFactorsReapplyJEC')))
    process.jetCustomization *= process.patJetCorrFactorsReapplyJEC
    process.jetCustomization *= process.patJetsReapplyJEC
    jSrc = 'patJetsReapplyJEC'

    # embed ids
    process.jID = cms.EDProducer(
        'JetIDEmbedder',
        src=cms.InputTag(jSrc),
    )
    process.jetCustomization *= process.jID
    jSrc = 'jID'

    ## embed pt shifts
    #jecUncDataFile_ = 'RootMaker/RootMaker/data/'
    #if isMC:
    #    jecUncDataFile_ += 'Summer16_23Sep2016V4_MC_Uncertainty_AK4PFchs.txt'
    #elif runP in ['B','C','D']:
    #    jecUncDataFile_ += 'Summer16_23Sep2016BCDV4_DATA_Uncertainty_AK4PFchs.txt'
    #elif runP in ['E','F']:
    #    jecUncDataFile_ += 'Summer16_23Sep2016EFV4_DATA_Uncertainty_AK4PFchs.txt'
    #elif runP in ['G']:
    #    jecUncDataFile_ += 'Summer16_23Sep2016GV4_DATA_Uncertainty_AK4PFchs.txt'
    #else:
    #    jecUncDataFile_ += 'Summer16_23Sep2016HV4_DATA_Uncertainty_AK4PFchs.txt'

    #process.jShift = cms.EDProducer(
    #    'JetShiftEmbedder',
    #    src = cms.InputTag(jSrc),
    #    jecUncDataFile = cms.FileInPath(jecUncDataFile_),
    #)
    #jSrc = 'jShift'
    #process.jetCustomization *= process.jShift

    #process.load('RecoJets.JetProducers.PileupJetID_cfi')
    #process.jpuID = process.pileupJetId.clone(
    #    jets=cms.InputTag(jSrc),
    #    inputIsCorrected=True,
    #    applyJec=True,
    #    vertexes=cms.InputTag(pvSrc)
    #)

    #process.jetCustomization *= process.jpuID
    #jSrc = 'jpuID'

    ## embed gen jets
    #if isMC:
    #    process.jGenJet = cms.EDProducer(
    #        'JetMatchedGenJetEmbedder',
    #        src = cms.InputTag(jSrc),
    #        genJets = cms.InputTag('slimmedGenJets'),
    #        srcIsTaus = cms.bool(False),
    #        deltaR = cms.double(0.5),
    #    )
    #    jSrc = 'jGenJet'
    #    process.jetCustomization *= process.jGenJet

    # add to schedule
    process.schedule.append(process.jetCustomization)
    coll['ak4pfchsjets'] = jSrc
    return coll
Ejemplo n.º 15
0
        '/store/data/Run2016H/JetHT/AOD/PromptReco-v3/000/284/043/00000/4EDD51A4-CE9F-E611-9E9D-02163E014310.root',
        '/store/data/Run2016H/JetHT/AOD/PromptReco-v3/000/284/043/00000/566A0223-C49F-E611-BF3B-02163E01230B.root',
        '/store/data/Run2016H/JetHT/AOD/PromptReco-v3/000/284/043/00000/88BE1171-C79F-E611-95CF-02163E01352A.root',
    ]),
)

### global-tag
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag.globaltag = options.globalTag

from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors, updatedPatJets
from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors
process.JECLevels = cms.PSet(labels=cms.vstring('L1FastJet', 'L2Relative',
                                                'L3Absolute', 'L2L3Residual'))
process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
    src=cms.InputTag("slimmedJets"),
    levels=process.JECLevels.labels,
    payload="AK4PFchs")
process.slimmedJetsRecorrected = updatedPatJets.clone(
    jetSource=cms.InputTag("slimmedJets"),
    jetCorrFactorsSource=cms.VInputTag(
        cms.InputTag("patJetCorrFactorsReapplyJEC")))

### propagate to the MET
from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
runMetCorAndUncFromMiniAOD(process, isData=True)

from PhysicsTools.PatUtils.tools.corMETFromMuonAndEG import corMETFromMuonAndEG
corMETFromMuonAndEG(process,
                    pfCandCollection="",
                    electronCollection="slimmedElectronsBeforeGSFix",
                    photonCollection="slimmedPhotonsBeforeGSFix",