Skip to content

Commit

Permalink
Merge pull request cms-sw#25 from Sam-Harper/EgammaPostRecoTools_940
Browse files Browse the repository at this point in the history
Adding in CutBased Photon ID Fall17V2
  • Loading branch information
Sam-Harper authored Dec 20, 2018
2 parents bc57461 + e72a6db commit 4db50a7
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 7 deletions.
22 changes: 15 additions & 7 deletions RecoEgamma/EgammaTools/python/EgammaPostRecoTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
#the new Fall17V2 modules are loaded as default if they exist in the release
#we do it this way as we can use the same script for all releases and people who
#dont want V2 can still use this script
_fall17V2PhoIDModules = [
_fall17V2PhoMVAIDModules = [
'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff'
]
_fall17V2PhoCutIDModules = [
'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff'
]
_fall17V2EleIDModules = [
'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
Expand All @@ -35,12 +38,17 @@
if pkgutil.find_loader(_fall17V2EleIDModules[0]) != None:
_defaultEleIDModules.extend(_fall17V2EleIDModules)
else:
print "EgammaPostRecoTools: Fall17V2 electron modules not found, running ID without them. If you want Fall17V2 IDs, please merge the approprate PR"
print "EgammaPostRecoTools: Fall17V2 electron modules not found, running ID without them. If you want Fall17V2 IDs, please merge the approprate PR\n 94X: git cms-merge-topic cms-egamma/EgammaID_949"

if pkgutil.find_loader(_fall17V2PhoMVAIDModules[0]) != None:
_defaultPhoIDModules.extend(_fall17V2PhoMVAIDModules)
else:
print "EgammaPostRecoTools: Fall17V2 MVA photon modules not found, running ID without them. If you want Fall17V2 MVA Photon IDs, please merge the approprate PR\n 94X: git cms-merge-topic cms-egamma/EgammaID_949\n 102X: git cms-merge-topic cms-egamma/EgammaID_1023"

if pkgutil.find_loader(_fall17V2PhoIDModules[0]) != None:
_defaultPhoIDModules.extend(_fall17V2PhoIDModules)
if pkgutil.find_loader(_fall17V2PhoCutIDModules[0]) != None:
_defaultPhoIDModules.extend(_fall17V2PhoCutIDModules)
else:
print "EgammaPostRecoTools: Fall17V2 photons modules not found, running ID without them. If you want Fall17V2 IDs, please merge the approprate PR"
print "EgammaPostRecoTools: Fall17V2 cut based Photons ID modules not found, running ID without them. If you want Fall17V2 CutBased Photon IDs, please merge the approprate PR\n 94X: git cms-merge-topic cms-egamma/EgammaID_949\n 102X: git cms-merge-topic cms-egamma/EgammaID_1023"

def _getEnergyCorrectionFile(era):
if era=="2017-Nov17ReReco":
Expand Down Expand Up @@ -103,7 +111,7 @@ def _setupEgammaEnergyCorrections(process,eleSrc=cms.InputTag('gedGsfElectrons')
elif hasattr(process.calibratedPatElectrons,"useSmearCorrEcalEnergyErrInComb"):
process.calibratedPatElectrons.useSmearCorrEcalEnergyErrInComb=False
elif applyEPCombBug:
raise RuntimeError('Error in postRecoEgammaTools, the E/p combination bug can not be applied in >= 10_2_X, it is only possible to emulate in 9_4_X')
raise RuntimeError('Error in postRecoEgammaTools, the E/p combination bug can not be applied in >= 10_2_X (applyEPCombBug must be False), it is only possible to emulate in 9_4_X')

def _setupEgammaPostRECOSequence(process,applyEnergyCorrections=False,applyVIDOnCorrectedEgamma=False,era="2017-Nov17ReReco",runVID=True,runEnergyCorrections=True,applyEPCombBug=False):

Expand Down Expand Up @@ -173,7 +181,7 @@ def _setupEgammaEnergyCorrectionsMiniAOD(process,eleSrc,phoSrc,applyEnergyCorrec
elif hasattr(process.calibratedPatElectrons,'useSmearCorrEcalEnergyErrInComb'):
process.calibratedPatElectrons.useSmearCorrEcalEnergyErrInComb=False
elif applyEPCombBug:
raise RuntimeError('Error in postRecoEgammaTools, the E/p combination bug can not be applied in >= 10_2_X, it is only possible to emulate in 9_4_X')
raise RuntimeError('Error in postRecoEgammaTools, the E/p combination bug can not be applied in >= 10_2_X (applyEPCombBug must be False) , it is only possible to emulate in 9_4_X')

if applyEnergyCorrections or applyVIDOnCorrectedEgamma:
process.calibratedPatElectrons.produceCalibratedObjs = True
Expand Down
99 changes: 99 additions & 0 deletions RecoEgamma/EgammaTools/test/runEgammaPostRecoTools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

import FWCore.ParameterSet.Config as cms
import os
import sys
# set up process
process = cms.Process("EGAMMA")

import FWCore.ParameterSet.VarParsing as VarParsing
options = VarParsing.VarParsing ('analysis')
options.register('isMiniAOD',True,options.multiplicity.singleton,options.varType.bool," whether we are running on miniAOD or not")
options.register('runVID',True,options.multiplicity.singleton,options.varType.bool," ")
options.register('runEnergyCorrections',True,options.multiplicity.singleton,options.varType.bool," ")
options.register('applyEnergyCorrections',False,options.multiplicity.singleton,options.varType.bool," ")
options.register('applyVIDOnCorrectedEgamma',False,options.multiplicity.singleton,options.varType.bool," ")
options.register('applyEPCombBug',False,options.multiplicity.singleton,options.varType.bool," ")
options.register('era','2017-Nov17ReReco',options.multiplicity.singleton,options.varType.string," ")
options.register('isMC',False,options.multiplicity.singleton,options.varType.bool," ")
options.parseArguments()

# initialize MessageLogger and output report
process.load("FWCore.MessageLogger.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport = cms.untracked.PSet(
reportEvery = cms.untracked.int32(500),
limit = cms.untracked.int32(10000000)
)
# set the number of events
process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(options.maxEvents)
)

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(options.inputFiles),
)

def getGlobalTagName(isMC,era):
if era=='2018-Prompt':
if isMC: return '102X_upgrade2018_realistic_v15'
else: return '102X_dataRun2_Prompt_v11'
elif era=='2017-Nov17ReReco':
if isMC: return '94X_mc2017_realistic_v10'
else: return '94X_dataRun2_ReReco_EOY17_v2'
elif era=='2016-Legacy':
if isMC: return '94X_mcRun2_asymptotic_v3'
else: return '94X_dataRun2_v10'
else:
raise RuntimeError('Error in runPostRecoEgammaTools, era {} not currently implimented. Allowed eras are 2018-Prompt 2017-Nov17ReReco 2016-Legacy'.format(era))


process.load("Configuration.Geometry.GeometryRecoDB_cff")
process.load("Configuration.StandardSequences.MagneticField_cff")
process.load("Geometry.CaloEventSetup.CaloTowerConstituents_cfi")
process.load("Configuration.StandardSequences.Services_cff")
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff')
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, getGlobalTagName(isMC=options.isMC,era=options.era), '')


from RecoEgamma.EgammaTools.EgammaPostRecoTools import setupEgammaPostRecoSeq
setupEgammaPostRecoSeq(process,
applyEnergyCorrections=options.applyEnergyCorrections,
applyVIDOnCorrectedEgamma=options.applyVIDOnCorrectedEgamma,
isMiniAOD=options.isMiniAOD,
era=options.era,
runVID=options.runVID,
runEnergyCorrections=options.runEnergyCorrections,
applyEPCombBug=options.applyEPCombBug)


process.p = cms.Path( process.egammaPostRecoSeq )


process.egammaOutput = cms.OutputModule("PoolOutputModule",
compressionAlgorithm = cms.untracked.string('LZMA'),
compressionLevel = cms.untracked.int32(4),
dataset = cms.untracked.PSet(
dataTier = cms.untracked.string('AODSIM'),
filterName = cms.untracked.string('')
),
eventAutoFlushCompressedSize = cms.untracked.int32(15728640),
fileName = cms.untracked.string(options.outputFile.replace(".root","_EDM.root")),
outputCommands = cms.untracked.vstring('drop *',
"keep *_*_*_RECO",
"keep *_*_*_PAT",
'keep *_*_*_HLT',
'keep *_slimmedElectrons*_*_*',
'keep *_slimmedPhotons*_*_*')
)
process.outPath = cms.EndPath(process.egammaOutput)

residualCorrFileName = None
if hasattr(process,'calibratedPatElectrons'):
residualCorrFileName = process.calibratedPatElectrons.correctionFile.value()
if hasattr(process,'calibratedElectrons'):
residualCorrFileName = process.calibratedElectrons.correctionFile.value()
msgStr='''EgammaPostRecoTools:
running with GT: {}
running residual E corr: {}'''
print msgStr.format(process.GlobalTag.globaltag.value(),residualCorrFileName)

0 comments on commit 4db50a7

Please sign in to comment.