Example #1
0
    def applyElectronRegression(self):
        """
        Apply electron regression from
            https://twiki.cern.ch/twiki/bin/view/CMS/EGMRegression
        """

        if self.verbose:
            print("")
            print("Applying electron regression...")

        # Read corrections for database
        from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
        regressionWeights(self.process)

        self.process.load(
            'EgammaAnalysis.ElectronTools.regressionApplication_cff')

        # Rename the collection
        self.process.slimmedElectronsWithRegression = self.process.slimmedElectrons.clone(
        )

        # Look for producers using the default electron input
        for producer in self.producers:
            p = getattr(self.process.framework.producers, producer)
            change_input_tags_and_strings(p,
                                          self.__miniaod_electron_collection,
                                          'slimmedElectronsWithRegression',
                                          'producers.' + producer, '    ')

        self.__miniaod_electron_collection = 'slimmedElectronsWithRegression'

        if self.verbose:
            print("New electrons collection: %r" %
                  (self.__miniaod_electron_collection))
Example #2
0
def customizeEGM(process,runOnData):

    process = regressionWeights(process)
    process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')
    process.load('EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi')
    process.calibratedPatElectrons.isMC = cms.bool(False) if runOnData else cms.bool(True)
    print 'Using smeared electrons with corrections from',process.calibratedPatElectrons.correctionFile

    # Set up electron ID (VID framework)
    dataFormat = DataFormat.MiniAOD
    switchOnVIDElectronIdProducer(process, dataFormat)
    my_id_modules = ['RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronHLTPreselecition_Summer16_V1_cff']
    for idmod in my_id_modules:
        setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)
    process.selectedElectrons = cms.EDFilter("PATElectronSelector",
                                             src = cms.InputTag("calibratedPatElectrons"),
                                             cut = cms.string("pt>5")
                                             )
    process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag('selectedElectrons')
    process.electronRegressionValueMapProducer.srcMiniAOD = cms.InputTag('selectedElectrons')
    process.electronMVAValueMapProducer.srcMiniAOD = cms.InputTag('selectedElectrons')

    process.EGMRegression = cms.Path(process.regressionApplication)
    process.EGMSmearerElectrons = cms.Path(process.calibratedPatElectrons)
Example #3
0
    def makeAnalysisStep(self, stepName, **inputs):
        step = super(ElectronCalibration,
                     self).makeAnalysisStep(stepName, **inputs)

        if stepName == 'preliminary':
            from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
            self.process = regressionWeights(self.process)

            from EgammaAnalysis.ElectronTools.regressionApplication_cff import slimmedElectrons as eReg

            eReg.src = step.getObjTag('e')
            step.addModule('electronRegression', eReg, 'e')

            cutOnSCEta = cms.EDFilter(
                "PATElectronSelector",
                src=step.getObjTag('e'),
                cut=cms.string('pt >= 5. && abs(superCluster.eta) < 2.5'),
            )
            step.addModule('selectElectronsBeforeID', cutOnSCEta, 'e')

            if not hasattr(self.process, 'RandomNumberGeneratorService'):
                self.process.RandomNumberGeneratorService = cms.Service(
                    'RandomNumberGeneratorService', )
            self.process.RandomNumberGeneratorService.calibratedPatElectrons = cms.PSet(
                initialSeed=cms.untracked.uint32(987), )

            from EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi import calibratedPatElectrons
            calibratedPatElectrons.isMC = cms.bool(self.isMC)
            calibratedPatElectrons.electrons = step.getObjTag('e')
            calibratedPatElectrons.isSynchronization = cms.bool(self.isSync)
            #self.process.calibratedPatElectrons.correctionFile = cms.string(correctionFile),

            step.addModule('calibratedPatElectrons', calibratedPatElectrons,
                           'e')

            if self.electronScaleShift or self.electronRhoResShift or self.electronPhiResShift:
                self.process.RandomNumberGeneratorService.electronSystematicShift = cms.PSet(
                    initialSeed=cms.untracked.uint32(345), )

                shiftMod = cms.EDProducer(
                    "PATElectronSystematicShifter",
                    src=step.getObjTag('e'),
                    correctionFile=cms.string(correctionFile),
                    scaleShift=cms.double(self.electronScaleShift),
                    rhoResShift=cms.double(self.electronRhoResShift),
                    phiResShift=cms.double(self.electronPhiResShift),
                )

                step.addModule('electronSystematicShift', shiftMod, 'e')

        if stepName == 'selection':
            # need to re-sort now that we're calibrated
            eSort = cms.EDProducer(
                "PATElectronCollectionSorter",
                src=step.getObjTag('e'),
                function=cms.string('pt'),
            )
            step.addModule('electronSorting', eSort, 'e')

        return step
def electronPrep(process, isMC, useCalibration):
    from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
    process = regressionWeights(process)
    process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

    if not hasattr(process, "RandomNumberGeneratorService"):
        process.load('Configuration.StandardSequences.Services_cff')
        process.RandomNumberGeneratorService = cms.Service(
            "RandomNumberGeneratorService")

    process.RandomNumberGeneratorService.calibratedPatElectrons = cms.PSet(
        initialSeed=cms.untracked.uint32(81),
        engineName=cms.untracked.string('TRandom3'),
    )
    process.load('EgammaAnalysis.ElectronTools.calibratedElectronsRun2_cfi')
    process.calibratedPatElectrons.isMC = cms.bool(isMC)

    electronInput = cms.InputTag("slimmedElectrons::ANA")
    if useCalibration:
        electronInput = cms.InputTag("calibratedPatElectrons")

    import PhysicsTools.SelectorUtils.tools.vid_id_tools as vid_tools
    vid_tools.switchOnVIDElectronIdProducer(process,
                                            vid_tools.DataFormat.MiniAOD)

    my_id_modules = [
        'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
        'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff'
    ]

    for idmod in my_id_modules:
        vid_tools.setupAllVIDIdsInModule(process, idmod,
                                         vid_tools.setupVIDElectronSelection)

    process.egmGsfElectronIDs.physicsObjectSrc = electronInput
    process.electronMVAValueMapProducer.srcMiniAOD = electronInput
    process.electronRegressionValueMapProducer.srcMiniAOD = electronInput
    process.heepIDVarValueMaps.elesMiniAOD = electronInput

    process.preppedElectrons = cms.EDProducer(
        "ElectronPrep",
        electronSrc=electronInput,
        uncalibratedSrc=cms.InputTag("slimmedElectrons::ANA"),
        vetoId=cms.InputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto"),
        looseId=cms.InputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose"),
        mediumId=cms.InputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium"),
        tightId=cms.InputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight"),
        heepId=cms.InputTag("egmGsfElectronIDs:heepElectronID-HEEPV70"),
        vertexSrc=cms.InputTag("offlineSlimmedPrimaryVertices"),
        kinematicCutAnyVariation=cms.string('pt > 10 && abs(eta) < 2.5'),
        finalCut=cms.string('userInt("VetoId")'),
    )
def setup_electrons(process, cms, options):
	print '=' * 60
	print "Setting up Electrons and ID"
	print '=' * 60
	isMC = not options.isData
	##########################################################
	### Applying the Electron Regression #####################
	##########################################################

	from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
	process = regressionWeights(process)
	process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

	##########################################################
	### Applying the Electron Smearer ########################
	##########################################################
	process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
		calibratedPatElectrons  = cms.PSet(
			initialSeed = cms.untracked.uint32(81),
			engineName = cms.untracked.string('TRandom3'),
		),
	)
	process.load('EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi')
	process.calibratedPatElectrons.isMC = cms.bool(isMC)

	##########################################################
	### Applying the ID ######################################
	##########################################################
	process.load("RecoEgamma.ElectronIdentification.ElectronIDValueMapProducer_cfi")

	from PhysicsTools.SelectorUtils.tools.vid_id_tools import *

	dataFormat = DataFormat.MiniAOD
	switchOnVIDElectronIdProducer(process, dataFormat)

	# define which IDs we want to produce
	my_id_modules = [
		'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
		'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronHLTPreselecition_Summer16_V1_cff',
	]

	#add them to the VID producer
	for idmod in my_id_modules:
		setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)
	
	process.selectedElectrons = cms.EDFilter("PATElectronSelector", 
	    src = cms.InputTag("calibratedPatElectrons"), 
	    cut = cms.string("pt > 5 && abs(eta)<2.5") 
	)

	process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag("selectedElectrons")
	process.electronIDValueMapProducer.srcMiniAOD = cms.InputTag('selectedElectrons')
	process.electronRegressionValueMapProducer.srcMiniAOD = cms.InputTag('selectedElectrons')

	process.processedElectrons = cms.Sequence( process.regressionApplication + process.calibratedPatElectrons + process.selectedElectrons + process.egmGsfElectronIDSequence + process.electronIDValueMapProducer)
Example #6
0
 def customizeDec2016Regression(self,process):
     if not (process.GlobalTag.globaltag == "80X_mcRun2_asymptotic_2016_TrancheIV_v7" or process.GlobalTag.globaltag == "80X_dataRun2_2016SeptRepro_v6"):
         raise Exception,"Regression application turned on but globalTag has unexpected value %s - see MicroAODCustomize.py" % process.GlobalTag.globaltag
     
     from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
     process = regressionWeights(process)
     process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')
     process.p.insert(0,process.regressionApplication)
     process.electronMVAValueMapProducer.srcMiniAOD = cms.InputTag("slimmedElectrons")
     process.photonMVAValueMapProducer.srcMiniAOD = cms.InputTag("slimmedPhotons")
     process.photonIDValueMapProducer.srcMiniAOD = cms.InputTag("slimmedPhotons")
Example #7
0
 def customizeDec2016Regression(self,process):
     if not (process.GlobalTag.globaltag == "80X_mcRun2_asymptotic_2016_TrancheIV_v7" or process.GlobalTag.globaltag == "80X_dataRun2_2016SeptRepro_v6"):
         raise Exception,"Regression application turned on but globalTag has unexpected value %s - see MicroAODCustomize.py" % process.GlobalTag.globaltag
     
     from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
     process = regressionWeights(process)
     process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')
     process.p.insert(0,process.regressionApplication)
     process.electronMVAValueMapProducer.srcMiniAOD = cms.InputTag("slimmedElectrons")
     process.photonMVAValueMapProducer.srcMiniAOD = cms.InputTag("slimmedPhotons")
     process.photonIDValueMapProducer.srcMiniAOD = cms.InputTag("slimmedPhotons")
def enableElectronRegression(process):
    from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
    process = regressionWeights(process)

    from EgammaAnalysis.ElectronTools.regressionWeights_local_cfi import GBRDWrapperRcd
    GBRDWrapperRcd.connect = "sqlite_fip:EgammaAnalysis/ElectronTools/data/ged_regression_20170114.db"

    process.regressions           = GBRDWrapperRcd
    process.es_prefer_regressions = cms.ESPrefer('PoolDBESSource','regressions')

    process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

    process.catElectrons.unsmaredElectrons = "slimmedElectrons::"+process.process

    return process
Example #9
0
def calibrateEGM(process, options):

    ### apply 80X regression
    from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
    process = regressionWeights(process)

    process.RandomNumberGeneratorService = cms.Service(
        "RandomNumberGeneratorService",
        calibratedPatElectrons=cms.PSet(
            initialSeed=cms.untracked.uint32(81),
            engineName=cms.untracked.string('TRandom3'),
        ),
        calibratedPatPhotons=cms.PSet(
            initialSeed=cms.untracked.uint32(81),
            engineName=cms.untracked.string('TRandom3'),
        ),
    )

    process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')
    process.load('EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi')
    process.load('EgammaAnalysis.ElectronTools.calibratedPatPhotonsRun2_cfi')

    process.calibratedPatElectrons.electrons = cms.InputTag(
        options['ELECTRON_COLL'])
    process.calibratedPatPhotons.photons = cms.InputTag(options['PHOTON_COLL'])
    if options['isMC']:
        process.calibratedPatElectrons.isMC = cms.bool(True)
        process.calibratedPatPhotons.isMC = cms.bool(True)
    else:
        process.calibratedPatElectrons.isMC = cms.bool(False)
        process.calibratedPatPhotons.isMC = cms.bool(False)

    process.selectElectronsBase = cms.EDFilter(
        "PATElectronSelector",
        src=cms.InputTag('calibratedPatElectrons'),
        cut=cms.string(options['ELECTRON_CUTS']),
    )

    process.selectPhotonsBase = cms.EDFilter(
        "PATPhotonSelector",
        src=cms.InputTag('calibratedPatPhotons'),
        cut=cms.string(options['PHOTON_CUTS']),
    )

    ### change the input collection to be the calibrated energy one for all other modules from now on
    options['ELECTRON_COLL'] = 'selectElectronsBase'
    options['PHOTON_COLL'] = 'selectPhotonsBase'
Example #10
0
        #        '/store/data/Run2016E/DoubleMuon/MINIAOD/03Feb2017-v1/100000/062FB971-1AED-E611-965F-0CC47A4C8F12.root',
        #        '/store/data/Run2016E/DoubleMuon/MINIAOD/23Sep2016-v1/100000/0049B6D2-278C-E611-AEB4-0025902D944E.root',
        #'/store/data/Run2016H/DoubleMuon/MINIAOD/PromptReco-v3/000/284/036/00000/04DC0281-C89F-E611-81C6-02163E0141E6.root'
        #        '/store/data/Run2016B/SingleElectron/MINIAOD/23Sep2016-v2/80000/5A4402F5-638C-E611-A471-0025905A60AA.root'
    ))

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

process.load("PhysicsTools.PatAlgos.producersLayer1.patCandidates_cff")
process.load("PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cff")
process.load("PhysicsTools.PatAlgos.selectionLayer1.selectedPatCandidates_cff")

### EGM 80X regression
from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights

process = regressionWeights(process)
process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

### EGM scale and smearing correction
process.load('EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi')
process.load('EgammaAnalysis.ElectronTools.calibratedPatPhotonsRun2_cfi')

#from PhysicsTools.PatAlgos.tools.cmsswVersionTools import *
from PhysicsTools.PatAlgos.tools.coreTools import *

runOnData(process,
          names=['Photons', 'Electrons', 'Muons', 'Taus', 'Jets'],
          outputModules=[])
#runOnData( process, outputModules = [] )
#removeMCMatching(process, names=['All'], outputModules=[])
Example #11
0
#GLOBALTAG
process.load('Configuration.StandardSequences.Services_cff')#Lisa
process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff')
from Configuration.AlCa.GlobalTag import GlobalTag
GT = ''
if isData:          GT = '80X_dataRun2_2016SeptRepro_v7'
elif not(isData):   GT = '80X_mcRun2_asymptotic_2016_TrancheIV_v8'
process.GlobalTag = GlobalTag(process.GlobalTag, GT)
print 'GlobalTag', GT

#electron/photon regression modules
from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
process = regressionWeights(process)
process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

#electrons upstream modules
from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
switchOnVIDElectronIdProducer(process, DataFormat.MiniAOD)
ele_id_modules = ['RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
                  'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
                  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff']

for ele_idmod in ele_id_modules:
    setupAllVIDIdsInModule(process,ele_idmod,setupVIDElectronSelection)

#muons upstream modules
process.cleanedMuons = cms.EDProducer('PATMuonCleanerBySegments',
    src = cms.InputTag('slimmedMuons'),#('calibratedMuons'),
Example #12
0
    def makeAnalysisStep(self, stepName, **inputs):
        step = super(ElectronCalibration, self).makeAnalysisStep(stepName, **inputs)

        if stepName == 'preliminary':
            from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
            self.process = regressionWeights(self.process)

            from EgammaAnalysis.ElectronTools.regressionApplication_cff import slimmedElectrons as eReg

            eReg.src = step.getObjTag('e')
            step.addModule('electronRegression', eReg, 'e')

            cutOnSCEta = cms.EDFilter(
                "PATElectronSelector",
                src = step.getObjTag('e'),
                cut = cms.string('pt >= 5. && abs(superCluster.eta) < 2.5'),
                )
            step.addModule('selectElectronsBeforeID', cutOnSCEta, 'e')

            if not hasattr(self.process, 'RandomNumberGeneratorService'):
                self.process.RandomNumberGeneratorService = cms.Service(
                    'RandomNumberGeneratorService',
                    )
            self.process.RandomNumberGeneratorService.calibratedPatElectrons = cms.PSet(
                initialSeed = cms.untracked.uint32(987),
                )
            
            from EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi import calibratedPatElectrons
            calibratedPatElectrons.isMC = cms.bool(self.isMC)
            calibratedPatElectrons.electrons = step.getObjTag('e') 
            calibratedPatElectrons.isSynchronization = cms.bool(self.isSync)
            #self.process.calibratedPatElectrons.correctionFile = cms.string(correctionFile),

            step.addModule('calibratedPatElectrons', calibratedPatElectrons, 'e')

            if self.electronScaleShift or self.electronRhoResShift or self.electronPhiResShift:
                self.process.RandomNumberGeneratorService.electronSystematicShift = cms.PSet(
                    initialSeed = cms.untracked.uint32(345),
                    )

                shiftMod = cms.EDProducer(
                    "PATElectronSystematicShifter",
                    src = step.getObjTag('e'),
                    correctionFile = cms.string(correctionFile),
                    scaleShift = cms.double(self.electronScaleShift),
                    rhoResShift = cms.double(self.electronRhoResShift),
                    phiResShift = cms.double(self.electronPhiResShift),
                    )

                step.addModule('electronSystematicShift', shiftMod, 'e')

        if stepName == 'selection':
            # need to re-sort now that we're calibrated
            eSort = cms.EDProducer(
                "PATElectronCollectionSorter",
                src = step.getObjTag('e'),
                function = cms.string('pt'),
                )
            step.addModule('electronSorting', eSort, 'e')

        return step
def setup_electrons(process, cms, options):
	print '=' * 60
	print "Setting up Electrons and ID"
	print '=' * 60
	isMC = not options.isData
	##########################################################
	### Applying the Electron Regression #####################
	##########################################################
	# TODO PROPERLY
	# Apply the regression from local sqlite file
	# from EgammaAnalysis.ElectronTools.regressionWeights_local_cfi import GBRDWrapperRcd
	# process.regressions           = GBRDWrapperRcd
	# process.es_prefer_regressions = cms.ESPrefer('PoolDBESSource','regressions')
	# process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

	# Apply the regression from a remote database
	from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
	process = regressionWeights(process)
	process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

	# Apply from GT
	# process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')

	process.electronRegression = cms.Sequence(process.regressionApplication)

	##########################################################
	### Applying the Electron Smearer ########################
	##########################################################
	if isMC:
	    process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
	        calibratedPatElectrons  = cms.PSet(
	            initialSeed = cms.untracked.uint32(81),
	            engineName = cms.untracked.string('TRandom3'),
	        ),
	    )
	process.load('EgammaAnalysis.ElectronTools.calibratedElectronsRun2_cfi')
	process.selectedSlimmedElectrons = cms.EDFilter("PATElectronSelector", 
	    src = cms.InputTag("slimmedElectrons"), 
	    cut = cms.string("pt > 5 && abs(eta)<2.5") 
	)

	process.calibratedPatElectrons = cms.EDProducer("CalibratedPatElectronProducerRun2",
	    electrons = cms.InputTag("selectedSlimmedElectrons"),
	    gbrForestName = cms.string('gedelectron_p4combination_25ns'),
	    isMC = cms.bool(isMC),
	    isSynchronization = cms.bool(False),
	    correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Winter_2016_reReco_v1_ele"),
	)
	# process.smearedElectrons = cms.Sequence( process.selectedSlimmedElectrons + process.calibratedPatElectrons)
	process.smearedElectrons = cms.Sequence( process.electronRegression + process.selectedSlimmedElectrons + process.calibratedPatElectrons)

	##########################################################
	### Applying the ID ######################################
	##########################################################
	from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
	# Switch ValueMap Producer to use calibrated Electrons
	process.load("RecoEgamma.ElectronIdentification.ElectronIDValueMapProducer_cfi")
	process.electronIDValueMapProducer.srcMiniAOD = cms.InputTag('calibratedPatElectrons')

	# turn on VID producer, indicate data format  to be
	# DataFormat.AOD or DataFormat.MiniAOD, as appropriate 
	dataFormat = DataFormat.MiniAOD
	switchOnVIDElectronIdProducer(process, dataFormat)

	# Switch egmGsfElectronIDs from switchOnVIDElectronIdProducer to use calibrated Electrons
	process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag("calibratedPatElectrons")

	# define which IDs we want to produce
	my_id_modules = [
		# 'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_25ns_V1_cff',
		# 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_Trig_V1_cff',
		'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
		# 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_Trig_V1_cff',
	]

	#add them to the VID producer
	for idmod in my_id_modules:
		setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)
def makeTreeFromMiniAOD(
process,
outfile,
reportfreq=10,
dataset="",
globaltag="",
numevents=1000,
geninfo=False,
tagname="RECO",
jsonfile="",
jecfile="",
residual=False,
jerfile="",
pufile="",
doPDFs=False,
fastsim=False,
signal=False,
scenario=""
):

    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------
    ## Preamble
    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------
    
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff")
    process.GlobalTag.globaltag = globaltag

    # log output
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr.FwkReport.reportEvery = reportfreq
    process.options = cms.untracked.PSet(
        allowUnscheduled = cms.untracked.bool(True),
#        wantSummary = cms.untracked.bool(True) # off by default
    )

    # files to process
    import FWCore.PythonUtilities.LumiList as LumiList
    process.maxEvents = cms.untracked.PSet(
        input = cms.untracked.int32(numevents)
    )
    process.source = cms.Source("PoolSource",
        fileNames = cms.untracked.vstring(dataset)
    )
    if len(jsonfile)>0: process.source.lumisToProcess = LumiList.LumiList(filename = jsonfile).getVLuminosityBlockRange()

    # output file
    process.TFileService = cms.Service("TFileService",
        fileName = cms.string(outfile+".root")
    )
    # branches for treemaker
    VectorRecoCand       = cms.vstring() 
    VarsDouble           = cms.vstring()
    VarsInt              = cms.vstring()
    VarsBool             = cms.vstring()
    VectorTLorentzVector = cms.vstring()
    VectorDouble         = cms.vstring()
    VectorString         = cms.vstring()
    VectorInt            = cms.vstring()
    VectorBool           = cms.vstring()

    # configure treemaker
    from LeptoQuarkTreeMaker.LeptoQuarkTreeMaker.treeMaker import TreeMaker
    process.LQTreeMaker2 = TreeMaker.clone(
        TreeName             = cms.string("SimpleTree"),
        VectorRecoCand       = VectorRecoCand, 
        VarsDouble           = VarsDouble,
        VarsInt              = VarsInt,
        VarsBool             = VarsBool,
        VectorTLorentzVector = VectorTLorentzVector,
        VectorDouble         = VectorDouble,
        VectorInt            = VectorInt,
        VectorString         = VectorString,
        VectorBool           = VectorBool,
    )

    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------
    ## Standard producers
    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------

    ## ----------------------------------------------------------------------------------------------
    ## SUSY scan info

    
    ## ----------------------------------------------------------------------------------------------
    ## WeightProducer
    ## ----------------------------------------------------------------------------------------------
    if geninfo:
        from LeptoQuarkTreeMaker.WeightProducer.getWeightProducer_cff import getWeightProducer
        process.WeightProducer = getWeightProducer(process.source.fileNames[0],fastsim and signal)
        process.WeightProducer.Lumi                       = cms.double(1) #default: 1 pb-1 (unit value)
        process.WeightProducer.FileNamePUDataDistribution = cms.string(pufile)
        VarsDouble.extend(['WeightProducer:weight(Weight)','WeightProducer:xsec(CrossSection)','WeightProducer:nevents(NumEvents)',
                           'WeightProducer:TrueNumInteractions','WeightProducer:PUweight(puWeight)','WeightProducer:PUSysUp(puSysUp)','WeightProducer:PUSysDown(puSysDown)'])
        VarsInt.extend(['WeightProducer:NumInteractions'])

    ## ----------------------------------------------------------------------------------------------
    ## PDF weights for PDF systematics
    ## ----------------------------------------------------------------------------------------------
    if geninfo and doPDFs:
        process.PDFWeights = cms.EDProducer('PDFWeightProducer')
        VectorDouble.extend(['PDFWeights:PDFweights','PDFWeights:ScaleWeights','PDFWeights:genWeight'])
        VectorInt.extend(['PDFWeights:PDFids'])

    ## ----------------------------------------------------------------------------------------------
    ## GenHT for stitching together MC samples
    ## ----------------------------------------------------------------------------------------------
    if geninfo:
        process.MadHT = cms.EDProducer('GenHTProducer')
        # called madHT, i.e. MadGraph, to distinguish from GenHT from GenJets
        VarsDouble.extend(['MadHT:genHT(madHT)'])
    
    ## ----------------------------------------------------------------------------------------------
    ## PrimaryVertices
    ## ----------------------------------------------------------------------------------------------
    process.goodVertices = cms.EDFilter("VertexSelector",
        src = cms.InputTag("offlineSlimmedPrimaryVertices"),
        cut = cms.string("!isFake && ndof > 4 && abs(z) < 24 && position.Rho < 2"),
        filter = cms.bool(False)
    )
    from LeptoQuarkTreeMaker.Utils.primaryvertices_cfi import primaryvertices
    process.NVtx = primaryvertices.clone(
        VertexCollection  = cms.InputTag('goodVertices'),
    )
    VarsInt.extend(['NVtx'])
    # also store total number of vertices without quality checks
    process.nAllVertices = primaryvertices.clone(
        VertexCollection  = cms.InputTag('offlineSlimmedPrimaryVertices'),
    )
    VarsInt.extend(['nAllVertices'])

    ## ----------------------------------------------------------------------------------------------
    ## GenParticles
    ## ----------------------------------------------------------------------------------------------
    ## JECs
    ## ----------------------------------------------------------------------------------------------

    process.load("CondCore.DBCommon.CondDBCommon_cfi")
    from CondCore.DBCommon.CondDBSetup_cfi import CondDBSetup
    
    # default miniAOD tags
    JetTag = cms.InputTag('slimmedJets')
    JetAK8Tag = cms.InputTag('slimmedJetsAK8')
    METTag = cms.InputTag('slimmedMETs')
    if scenario=="2016ReMiniAOD03Feb": METTag = cms.InputTag('slimmedMETsMuEGClean') 
    # get the JECs (disabled by default)
    # this requires the user to download the .db file from this twiki
    # https://twiki.cern.ch/twiki/bin/viewauth/CMS/JECDataMC
    if len(jecfile)>0:
        #get name of JECs without any directories
        JECera = jecfile.split('/')[-1]
        JECPatch = cms.string('sqlite_file:'+jecfile+'.db')
        if os.getenv('GC_CONF'): 
            JECPatch = cms.string('sqlite_file:../src/'+jecfile+'.db')

        process.jec = cms.ESSource("PoolDBESSource",CondDBSetup,
            connect = JECPatch,
            toGet   = cms.VPSet(
                cms.PSet(
                    record = cms.string("JetCorrectionsRecord"),
                    tag    = cms.string("JetCorrectorParametersCollection_"+JECera+"_AK4PFchs"),
                    label  = cms.untracked.string("AK4PFchs")
                ),
                cms.PSet(
                    record = cms.string("JetCorrectionsRecord"),
                    tag    = cms.string("JetCorrectorParametersCollection_"+JECera+"_AK4PF"),
                    label  = cms.untracked.string("AK4PF")
                ),
                cms.PSet(
                    record = cms.string("JetCorrectionsRecord"),
                    tag    = cms.string("JetCorrectorParametersCollection_"+JECera+"_AK8PFchs"),
                    label  = cms.untracked.string("AK8PFchs")
                ),
            )
        )
        process.es_prefer_jec = cms.ESPrefer("PoolDBESSource","jec")
        
        levels  = ['L1FastJet','L2Relative','L3Absolute']
        if residual: levels.append('L2L3Residual')
        
        from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
        
        updateJetCollection(
            process,
            jetSource = cms.InputTag('slimmedJets'),
            postfix = 'UpdatedJEC',
            jetCorrections = ('AK4PFchs', levels, 'None')
        )
        
        JetTag = cms.InputTag('updatedPatJetsUpdatedJEC')
        
        # also update the corrections for AK8 jets
        updateJetCollection(
            process,
            jetSource = cms.InputTag('slimmedJetsAK8'),
            labelName = 'AK8',
            postfix = 'UpdatedJEC',
            jetCorrections = ('AK8PFchs', levels, 'None')
        )
        
        JetAK8Tag = cms.InputTag('updatedPatJetsAK8UpdatedJEC')
        
        # update the MET to account for the new JECs
        from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
        runMetCorAndUncFromMiniAOD(
            process,
            isData=not geninfo, # controls gen met
        )
        process.load('RecoMET.METFilters.badGlobalMuonTaggersMiniAOD_cff')
        process.badGlobalMuonTaggerMAOD.taggingMode = cms.bool(True)
        process.cloneGlobalMuonTaggerMAOD.taggingMode = cms.bool(True)
        from PhysicsTools.PatUtils.tools.muonRecoMitigation import muonRecoMitigation
        muonRecoMitigation(
                          process = process,
                          pfCandCollection = "packedPFCandidates", #input PF Candidate Collection
                          runOnMiniAOD = True, #To determine if you are running on AOD or MiniAOD
                          selection="", #You can use a custom selection for your bad muons. Leave empty if you would like to use the bad muon recipe definition.
                          muonCollection="", #The muon collection name where your custom selection will be applied to. Leave empty if you would like to use the bad muon recipe definition.
                          cleanCollName="cleanMuonsPFCandidates", #output pf candidate collection ame
                          cleaningScheme="computeAllApplyClone", #Options are: "all", "computeAllApplyBad","computeAllApplyClone". Decides which (or both) bad muon collections to be used for MET cleaning coming from the bad muon recipe.
                          postfix="" #Use if you would like to add a post fix to your muon / pf collections
                       )
        runMetCorAndUncFromMiniAOD(process,
                                 isData=not geninfo,
                                 pfCandColl="cleanMuonsPFCandidates",
                                 recoMetFromPFCs=True,
                                 postfix="MuClean"
                           )
        process.mucorMET = cms.Sequence(                     
           process.badGlobalMuonTaggerMAOD *
           process.cloneGlobalMuonTaggerMAOD *
           #process.badMuons * # If you are using cleaning mode "all", uncomment this line
           process.cleanMuonsPFCandidates *
           process.fullPatMetSequenceMuClean
           )

        from PhysicsTools.PatUtils.tools.corMETFromMuonAndEG import corMETFromMuonAndEG
        corMETFromMuonAndEG(process,
                    pfCandCollection="", #not needed                                                                                                                                                                                                                                                                                                                      
                    electronCollection="slimmedElectronsBeforeGSFix",
                    photonCollection="slimmedPhotonsBeforeGSFix",
                    corElectronCollection="slimmedElectrons",
                    corPhotonCollection="slimmedPhotons",
                    allMETEGCorrected=True,
                    muCorrection=False,
                    eGCorrection=True,
                    runOnMiniAOD=True,
                    postfix="MuEGClean"
                    )

        process.slimmedMETsMuEGClean = process.slimmedMETs.clone()
        process.slimmedMETsMuEGClean.src = cms.InputTag("patPFMetT1MuEGClean")
        process.slimmedMETsMuEGClean.rawVariation =  cms.InputTag("patPFMetRawMuEGClean")
        process.slimmedMETsMuEGClean.t1Uncertainties = cms.InputTag("patPFMetT1%sMuEGClean")
        del process.slimmedMETsMuEGClean.caloMET

        METTag = cms.InputTag('slimmedMETs','',process.name_())
    else:
        # pointless run of MET tool because it is barely functional
        from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
        runMetCorAndUncFromMiniAOD(
            process,
            isData=not geninfo, # controls gen met
        )

    # keep jets before any further modifications for hadtau
    JetTagBeforeSmearing = JetTag
    # JEC uncertainty - after JECs are updated
    from LeptoQuarkTreeMaker.Utils.jetuncertainty_cfi import JetUncertaintyProducer
    process.jecUnc = JetUncertaintyProducer.clone(
        JetTag = JetTag,
        jecUncDir = cms.int32(0)
    )
    _infosToAdd = ['jecUnc']
    if geninfo:
        # JER factors - central, up, down
        from LeptoQuarkTreeMaker.Utils.smearedpatjet_cfi import SmearedPATJetProducer
        process.jerFactor = SmearedPATJetProducer.clone(
            src = JetTag,
            variation = cms.int32(0),
            store_factor = cms.bool(True)
        )
        process.jerFactorUp = SmearedPATJetProducer.clone(
            src = JetTag,
            variation = cms.int32(1),
            store_factor = cms.bool(True)
        )
        process.jerFactorDown = SmearedPATJetProducer.clone(
            src = JetTag,
            variation = cms.int32(-1),
            store_factor = cms.bool(True)
        )
        _infosToAdd.extend(['jerFactor','jerFactorUp','jerFactorDown'])
    # add userfloat & update tag
    from LeptoQuarkTreeMaker.LeptoQuarkTreeMaker.addJetInfo import addJetInfo
    process, JetTag = addJetInfo(process, JetTag, _infosToAdd, [])

    ## ----------------------------------------------------------------------------------------------
    ## IsoTracks

    ## ----------------------------------------------------------------------------------------------
    ## MET Filters
    ## ----------------------------------------------------------------------------------------------
    
    # When the miniAOD file is created, the results of several different
    # MET filters are save in a TriggerResults object for the PAT process
    # Look at /PhysicsTools/PatAlgos/python/slimming/metFilterPaths_cff.py
    # for the available filter flags

    # The decision was made to include the filter decision flags
    # as individual branches in the tree
    
    if not fastsim: # MET filters are not run for fastsim samples

        from LeptoQuarkTreeMaker.Utils.filterdecisionproducer_cfi import filterDecisionProducer
        
        process.CSCTightHaloFilter = filterDecisionProducer.clone(
            trigTagArg1 = cms.string('TriggerResults'),
            trigTagArg2 = cms.string(''),
            trigTagArg3 = cms.string(tagname),
            filterName  = cms.string("Flag_CSCTightHalo2015Filter"),
        )
        VarsInt.extend(['CSCTightHaloFilter'])
        
        process.globalTightHalo2016Filter = filterDecisionProducer.clone(
            trigTagArg1 = cms.string('TriggerResults'),
            trigTagArg2 = cms.string(''),
            trigTagArg3 = cms.string(tagname),
            filterName  = cms.string("Flag_globalTightHalo2016Filter"),
        )
        VarsInt.extend(['globalTightHalo2016Filter'])
        
        process.HBHENoiseFilter = filterDecisionProducer.clone(
            trigTagArg1 = cms.string('TriggerResults'),
            trigTagArg2 = cms.string(''),
            trigTagArg3 = cms.string(tagname),
            filterName  = cms.string("Flag_HBHENoiseFilter"),
        )
        VarsInt.extend(['HBHENoiseFilter'])
        
        process.HBHEIsoNoiseFilter = filterDecisionProducer.clone(
            trigTagArg1 = cms.string('TriggerResults'),
            trigTagArg2 = cms.string(''),
            trigTagArg3 = cms.string(tagname),
            filterName  = cms.string("Flag_HBHENoiseIsoFilter"),
        )
        VarsInt.extend(['HBHEIsoNoiseFilter'])
        
        process.EcalDeadCellTriggerPrimitiveFilter = filterDecisionProducer.clone(
            trigTagArg1 = cms.string('TriggerResults'),
            trigTagArg2 = cms.string(''),
            trigTagArg3 = cms.string(tagname),
            filterName  = cms.string("Flag_EcalDeadCellTriggerPrimitiveFilter"),
        )
        VarsInt.extend(['EcalDeadCellTriggerPrimitiveFilter'])
        
        process.eeBadScFilter = filterDecisionProducer.clone(
            trigTagArg1  = cms.string('TriggerResults'),
            trigTagArg2  = cms.string(''),
            trigTagArg3  = cms.string(tagname),
            filterName  =   cms.string("Flag_eeBadScFilter"),
        )
        VarsInt.extend(['eeBadScFilter'])
        
        # some filters need to be rerun
        process.load('RecoMET.METFilters.BadChargedCandidateFilter_cfi')
        process.BadChargedCandidateFilter.muons = cms.InputTag("slimmedMuons")
        process.BadChargedCandidateFilter.PFCandidates = cms.InputTag("packedPFCandidates")
        process.BadChargedCandidateFilter.taggingMode = True
        VarsBool.extend(['BadChargedCandidateFilter'])
        
        process.load('RecoMET.METFilters.BadPFMuonFilter_cfi')
        process.BadPFMuonFilter.muons = cms.InputTag("slimmedMuons")
        process.BadPFMuonFilter.PFCandidates = cms.InputTag("packedPFCandidates")
        process.BadPFMuonFilter.taggingMode = True
        VarsBool.extend(['BadPFMuonFilter'])



    from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
    process = regressionWeights(process) 
    '''
    process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
                  calibratedPatElectrons  = cms.PSet( initialSeed = cms.untracked.uint32(8675389),
                                                      engineName = cms.untracked.string('TRandom3'),
                                                      ),
                  calibratedPatPhotons    = cms.PSet( initialSeed = cms.untracked.uint32(8675389),
                                                      engineName = cms.untracked.string('TRandom3'),
                                                      ),
                                                   )
    '''
    process.load('Configuration.StandardSequences.Services_cff')
    process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
                                                   calibratedPatElectrons  = cms.PSet( 
                                                     initialSeed = cms.untracked.uint32(81),
                                                     engineName = cms.untracked.string('TRandom3'),
                                                     ),
                                                   calibratedPatPhotons  = cms.PSet( 
                                                     initialSeed = cms.untracked.uint32(81),
                                                     engineName = cms.untracked.string('TRandom3'),
                                                     ),
                                                   )

    process.load('EgammaAnalysis.ElectronTools.regressionApplication_cff')
    process.load('EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi')
    process.calibratedPatElectrons.isMC =  cms.bool(False)
    process.selectedElectrons = cms.EDFilter(
                                "PATElectronSelector",
        src = cms.InputTag("slimmedElectrons"),
        cut = cms.string("pt > 5 && abs(eta)<2.5")
    )
    process.calibratedPatElectrons.electrons = cms.InputTag('selectedElectrons')
    process.calibratedPatElectrons.isMC =  cms.bool(False)

    #process.EGMRegression =cms.Path(process.regressionApplication)
   # process.EGMSmearerElectrons = cms.Path(process.calibratedPatElectrons)
   # process.EGMSmearerElectrons.isMC = cms.bool(False)

    #process.schedule = cms.Schedule(process.EGMRegression,process.EGMSmearerElectrons,process.analysis)
    '''
    process.load('Configuration.StandardSequences.Services_cff')
    process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
                                                   calibratedPatElectrons  = cms.PSet( 
                                                     initialSeed = cms.untracked.uint32(81),
                                                     engineName = cms.untracked.string('TRandom3'),
                                                     ),
                                                   calibratedPatPhotons  = cms.PSet( 
                                                     initialSeed = cms.untracked.uint32(81),
                                                     engineName = cms.untracked.string('TRandom3'),
                                                     ),
                                                   )
    process.load('EgammaAnalysis.ElectronTools.calibratedElectronsRun2_cfi')
    correctionType = "Moriond2017_JEC "
    
    calibratedPatElectrons = cms.EDProducer("CalibratedPatElectronProducerRun2",
                                        
                                        # input collections
                                        electrons = cms.InputTag('slimmedElectrons'),
                                        gbrForestName = cms.string("gedelectron_p4combination_25ns"),
                                        
                                        # data or MC corrections
                                        # if isMC is false, data corrections are applied
                                        isMC = cms.bool(True),
                                        
                                        # set to True to get special "fake" smearing for synchronization. Use JUST in case of synchronization
                                        isSynchronization = cms.bool(True),

                                        correctionFile = cms.string("Moriond2017_JEC ")
                                        )   
    '''
    #process.Baseline += process.calibratedPatElectrons
    from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
    switchOnVIDElectronIdProducer(process, DataFormat.MiniAOD)
    my_id_modules = []
    my_id_modules.append('RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_25ns_V1_cff')
    my_id_modules.append('RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV60_cff') 
    my_id_modules.append('RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff')
    my_id_modules.append('RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_nonTrig_V1_cff')
    for idmod in my_id_modules:
        setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)

    process.egmGsfElectronIDs.physicsObjectSrc     = cms.InputTag('calibratedPatElectrons')
    process.electronMVAValueMapProducer.srcMiniAOD = cms.InputTag('calibratedPatElectrons')
    process.heepIDVarValueMaps.elesMiniAOD  = cms.InputTag('calibratedPatElectrons')
    process.electronRegressionValueMapProducer.srcMiniAOD = cms.InputTag('calibratedPatElectrons')

    
    
    from LeptoQuarkTreeMaker.Utils.HEEPProducer_cfi import HEEPProducer
    process.HEEPProducer = HEEPProducer.clone(
        eletag = cms.InputTag('calibratedPatElectrons')
    )
    #process.Baseline += process.HEEPProducer
    VectorDouble.extend(['HEEPProducer:trackiso(Electron_trackiso)'])
    #VectorDouble.extend(['HEEPProducer:Eta(Electron_Eta)'])
    VectorDouble.extend(['HEEPProducer:Et(Electron_Et)'])
    VectorDouble.extend(['HEEPProducer:DeltaEtain(Electron_DeltaEtain)'])
    VectorDouble.extend(['HEEPProducer:DeltaPhiin(Electron_DeltaPhiin)'])
    VectorDouble.extend(['HEEPProducer:HbE(Electron_HOverE)'])
    #VectorDouble.extend(['HEEPProducer:SiEtaiEta(Electron_SiEtaiEta)'])
    VectorDouble.extend(['HEEPProducer:Ecaliso(Electron_Ecaliso)'])
    VectorDouble.extend(['HEEPProducer:HD1iso(Electron_HD1iso)'])
    #VectorDouble.extend(['HEEPProducer:HD2iso(Electron_HD2iso)'])
    VectorBool.extend(['HEEPProducer:ecalDriven(Electron_ecalDriven)'])
    #VectorDouble.extend(['HEEPProducer:e25max(Electron_e25max)'])
    #VectorDouble.extend(['HEEPProducer:e55(Electron_e55)'])
    VectorDouble.extend(['HEEPProducer:e25bye55(Electron_e25bye55)'])
    VectorDouble.extend(['HEEPProducer:Fullsce25bye55(Electron_Fullsce25bye55)'])
    VectorDouble.extend(['HEEPProducer:Fulle15bye55(Electron_Fulle15bye55)'])
    VectorDouble.extend(['HEEPProducer:scEnergy(Electron_scEnergy)'])
    VectorDouble.extend(['HEEPProducer:DeltaEtaSeed(Electron_DeltaEtaSeed)'])
    VectorDouble.extend(['HEEPProducer:rho(rho)'])
    VectorInt.extend(['HEEPProducer:Charge(Electron_Charge)'])
    #VectorDouble.extend(['HEEPProducer:ePt(Electron_Pt)'])
    #VectorDouble.extend(['HEEPProducer:e15(Electron_e15)'])
    VectorDouble.extend(['HEEPProducer:ecalEnergy(Electron_ecalEnergy)'])
    VectorDouble.extend(['HEEPProducer:full55SiEtaiEta(Electron_full55SiEtaiEta)'])
    #VectorDouble.extend(['HEEPProducer:sce25max(Electron_sce25max)'])
    #VectorDouble.extend(['HEEPProducer:sce55(Electron_sce55)'])
    VectorDouble.extend(['HEEPProducer:sce25bye55(Electron_sce25bye55)'])
    VectorDouble.extend(['HEEPProducer:e15bye55(Electron_e15bye55)'])
    #VectorDouble.extend(['HEEPProducer:DeltaEtaSeedscandTrack(Electron_DeltaEtaSeedscandTrack)'])
    VectorDouble.extend(['HEEPProducer:Phi(Electron_Phi)'])
    VectorDouble.extend(['HEEPProducer:eEnergy(Electron_Energy)'])
    VectorDouble.extend(['HEEPProducer:dxy(dxy)'])
    VectorInt.extend(['HEEPProducer:losthits(Electron_losthits)'])
    VectorDouble.extend(['HEEPProducer:ePz(Electron_Pz)'])
    #VectorDouble.extend(['HEEPProducer:eTheta(Electron_Theta)'])
    VectorDouble.extend(['HEEPProducer:ePx(Electron_Px)'])
    VectorDouble.extend(['HEEPProducer:ePy(Electron_Py)'])
    #VectorDouble.extend(['HEEPProducer:normalizedChi2(Electron_normalizedChi2)'])
    VectorInt.extend(['HEEPProducer:PDGID(PDGID)'])
    VectorInt.extend(['HEEPProducer:gencharge(gencharge)'])
    VectorDouble.extend(['HEEPProducer:genPt(genPt)'])
    VectorDouble.extend(['HEEPProducer:genEta(genEta)'])
    VectorDouble.extend(['HEEPProducer:genPhi(genPhi)'])
    VectorDouble.extend(['HEEPProducer:genEnergy(genEnergy)'])
    VectorInt.extend(['HEEPProducer:motherPDGID(motherPDGID)'])
    VectorInt.extend(['HEEPProducer:elstatus(elstatus)'])
    VectorDouble.extend(['HEEPProducer:PtHEEP(Electron_PtHEEP)'])
    #VectorDouble.extend(['HEEPProducer:scEtaa(Electron_scEtaa)'])
    VectorDouble.extend(['HEEPProducer:scEta(Electron_scEta)'])
    VectorDouble.extend(['HEEPProducer:heep70TrkIso(Electron_heep70TrkIso)'])
    VectorBool.extend(['HEEPProducer:passEMHD1iso(Electron_passEMHD1iso)'])
    
    
    VectorBool.extend(['HEEPProducer:passShowerShape(Electron_passShowerShape)'])
    VectorBool.extend(['HEEPProducer:passDeltaEta(Electron_passDeltaEta)'])
    VectorBool.extend(['HEEPProducer:passDeltaPhi(Electron_passDeltaPhi)'])
    VectorBool.extend(['HEEPProducer:passEMHD1iso(Electron_passEMHD1iso)'])
    VectorBool.extend(['HEEPProducer:passHoverE(Electron_passHoverE)'])
    VectorBool.extend(['HEEPProducer:passDXY(Electron_passDXY)'])
    VectorBool.extend(['HEEPProducer:passMissingHits(Electron_passMissingHits)'])
    
    VectorBool.extend(['HEEPProducer:passEcaldriven(Electron_passEcaldriven)'])
    VectorBool.extend(['HEEPProducer:passN1TrkIso(Electron_passN1TrkIso)'])
    VectorDouble.extend(['HEEPProducer:worzsystempt(worzsystempt)']) 










    ## Muons
    ## ----------------------------------------------------------------------------------------------

    from LeptoQuarkTreeMaker.Utils.MuonProducer_cfi import MuonProducer
    process.MuonProducer = MuonProducer.clone(
        muontag = cms.InputTag('slimmedMuons')
    )
    #process.Baseline += process.MuonProducer

    #VectorBool.extend(['MuonProducer:MuonisTightMuon(MuonisTightMuon)'])
    #VectorBool.extend(['MuonProducer:MuonisHighPtMuon(MuonisHighPtMuon)'])
    VectorDouble.extend(['MuonProducer:MuonEta(MuonEta)'])
    VectorDouble.extend(['MuonProducer:MuonPhi(MuonPhi)'])
    VectorDouble.extend(['MuonProducer:MuonPt(MuonPt)'])
    VectorDouble.extend(['MuonProducer:MuonEnergy(MuonEnergy)'])
    #VectorDouble.extend(['MuonProducer:MuonPtError(MuonPtError)'])
    #VectorDouble.extend(['MuonProducer:MuonGlobalChi2(MuonGlobalChi2)'])
    #VectorDouble.extend(['MuonProducer:MuonTrkPtError(MuonTrkPtError)'])
    #VectorInt.extend(['MuonProducer:MuonIsPF(MuonIsPF)'])
    VectorInt.extend(['MuonProducer:MuonCharge(MuonCharge)'])
    #VectorInt.extend(['MuonProducer:MuonGlobalTrkValidHits(MuonGlobalTrkValidHits)'])
    #VectorInt.extend(['MuonProducer:MuonTrkPixelHits(MuonTrkPixelHits)'])
    #VectorInt.extend(['MuonProducer:MuonStationMatches(MuonStationMatches)'])
    #VectorDouble.extend(['MuonProducer:MuonPFIsoR04Photon(MuonPFIsoR04Photon)'])
    #VectorDouble.extend(['MuonProducer:MuonPFIsoR04NeutralHadron(MuonPFIsoR04NeutralHadron)'])
    #VectorDouble.extend(['MuonProducer:MuonPFIsoR04PU(MuonPFIsoR04PU)'])
    #VectorDouble.extend(['MuonProducer:MuonTrackerIsoSumPT(MuonTrackerIsoSumPT)'])
    #VectorDouble.extend(['MuonProducer:MuonPFIsoR04ChargedHadron(MuonPFIsoR04ChargedHadron)'])
    VectorInt.extend(['MuonProducer:MuonPassID(MuonPassID)'])
    VectorInt.extend(['MuonProducer:MuonIsGlobal(MuonIsGlobal)'])
    #VectorInt.extend(['MuonProducer:MuonTrackLayersWithMeasurement(MuonTrackLayersWithMeasurement)'])
    #VectorDouble.extend(['MuonProducer:CocktailEta(CocktailPtError)'])
    #VectorDouble.extend(['MuonProducer:CocktailPt(CocktailPt)'])
    #VectorDouble.extend(['MuonProducer:MuonBestTrackVtxDistXY(MuonBestTrackVtxDistXY)'])
    #VectorDouble.extend(['MuonProducer:MuonBestTrackVtxDistZ(MuonBestTrackVtxDistZ)'])

    ## ----------------------------------------------------------------------------------------------
    ## Taus
    ## ----------------------------------------------------------------------------------------------


    from LeptoQuarkTreeMaker.Utils.TauProducer_cfi import TauProducer
    process.TauProducer = TauProducer.clone(
        tautag = cms.InputTag('slimmedTaus')
    )
    #process.Baseline += process.TauProducer
    VectorDouble.extend(['TauProducer:tEta(TauEta)'])
    VectorDouble.extend(['TauProducer:tPhi(TauPhi)'])
    VectorDouble.extend(['TauProducer:tPt(TauPt)'])
    



        
    ## ----------------------------------------------------------------------------------------------
    ## Triggers
    ## ----------------------------------------------------------------------------------------------

    # The trigger results are saved to the tree as a vector
    # Three vectors are saved:
    # 1) names of the triggers
    # 2) trigger results
    # 3) trigger prescales
    # the indexing of these vectors must match
    # If the version number of the input trigger name is omitted,
    # any matching trigger will be included (default behavior)

    from LeptoQuarkTreeMaker.Utils.triggerproducer_cfi import triggerProducer
    from LeptoQuarkTreeMaker.LeptoQuarkTreeMaker.triggerNameList import triggerNameList as _triggerNameList
    process.TriggerProducer = triggerProducer.clone(
        trigTagArg1     = cms.string('TriggerResults'),
        trigTagArg2     = cms.string(''),
        trigTagArg3     = cms.string('HLT'),
        prescaleTagArg1  = cms.string('patTrigger'),
        prescaleTagArg2  = cms.string(''),
        prescaleTagArg3  = cms.string(''),
        triggerNameList = _triggerNameList
    )
    VectorInt.extend(['TriggerProducer:TriggerPass','TriggerProducer:TriggerPrescales'])
    VectorString.extend(['TriggerProducer:TriggerNames'])
    VectorDouble.extend(['TriggerProducer:objectPt'])
    VectorDouble.extend(['TriggerProducer:objecteta'])
    VectorDouble.extend(['TriggerProducer:objectphi'])
    VectorDouble.extend(['TriggerProducer:objectE'])
    VectorDouble.extend(['TriggerProducer:ColumnNum'])


    
    ## ----------------------------------------------------------------------------------------------
    ## JER smearing, various uncertainties
    ## ----------------------------------------------------------------------------------------------
    
    # list of clean tags - ignore jet ID for jets matching these objects
    SkipTag = cms.VInputTag(
    )
    
    # get the JERs (disabled by default)
    # this requires the user to download the .db file from this github
    # https://github.com/cms-jet/JRDatabase
    if len(jerfile)>0:
        #get name of JERs without any directories
        JERera = jerfile.split('/')[-1]
        JERPatch = cms.string('sqlite_file:'+jerfile+'.db')
        if os.getenv('GC_CONF'): 
            JERPatch = cms.string('sqlite_file:../src/'+jerfile+'.db')
    
        process.jer = cms.ESSource("PoolDBESSource",CondDBSetup,
            connect = JERPatch,
            toGet = cms.VPSet(
                cms.PSet(
                    record = cms.string('JetResolutionRcd'),
                    tag    = cms.string('JR_'+JERera+'_PtResolution_AK4PFchs'),
                    label  = cms.untracked.string('AK4PFchs_pt')
                ),
                cms.PSet(
                    record = cms.string('JetResolutionScaleFactorRcd'),
                    tag    = cms.string('JR_'+JERera+'_SF_AK4PFchs'),
                    label  = cms.untracked.string('AK4PFchs')
                ),
            ),
        )

        process.es_prefer_jer = cms.ESPrefer('PoolDBESSource', 'jer')

    # skip all jet smearing and uncertainties for data
    from LeptoQuarkTreeMaker.LeptoQuarkTreeMaker.JetDepot import JetDepot          #........Uncomment it once you start running on MC datasets
    from LeptoQuarkTreeMaker.LeptoQuarkTreeMaker.makeJetVars import makeJetVars

    process = makeJetVars(process,
                          JetTag=JetTag,
                          suff='',
                          skipGoodJets=False,
                          storeProperties=2,
                          geninfo=geninfo,
                          fastsim=fastsim,
                          SkipTag=SkipTag
    )

    
    if geninfo:
        # JEC unc up
        process, JetTagJECup = JetDepot(process,
            JetTag=JetTag,
            jecUncDir=1,
            doSmear=True,
            jerUncDir=0
        )
        process = makeJetVars(process,
                              JetTag=JetTagJECup,
                              suff='JECup',
                              skipGoodJets=False,
                              storeProperties=1,
                              geninfo=geninfo,
                              fastsim=fastsim,
                              SkipTag=SkipTag
        )
        
        # JEC unc down
        process, JetTagJECdown = JetDepot(process,
            JetTag=JetTag,
            jecUncDir=-1,
            doSmear=True,
            jerUncDir=0
        )
        process = makeJetVars(process,
                              JetTag=JetTagJECdown,
                              suff='JECdown',
                              skipGoodJets=False,
                              storeProperties=1,
                              geninfo=geninfo,
                              fastsim=fastsim,
                              SkipTag=SkipTag
        )

        # JER unc up
        process, JetTagJERup = JetDepot(process,
            JetTag=JetTag,
            jecUncDir=0,
            doSmear=True,
            jerUncDir=1
        )
        process = makeJetVars(process,
                              JetTag=JetTagJERup,
                              suff='JERup',
                              skipGoodJets=False,
                              storeProperties=1,
                              geninfo=geninfo,
                              fastsim=fastsim,
                              SkipTag=SkipTag
        )
        
        # JER unc down
        process, JetTagJERdown = JetDepot(process,
            JetTag=JetTag,
            jecUncDir=0,
            doSmear=True,
            jerUncDir=-1
        )
        process = makeJetVars(process,
                              JetTag=JetTagJERdown,
                              suff='JERdown',
                              skipGoodJets=False,
                              storeProperties=1,
                              geninfo=geninfo,
                              fastsim=fastsim,
                              SkipTag=SkipTag
        )

        # finally, do central smearing and replace jet tag
        process, JetTag = JetDepot(process,
            JetTag=JetTag,
            jecUncDir=0,
            doSmear=True,
            jerUncDir=0
        )
        
    ## ----------------------------------------------------------------------------------------------
    ## Jet variables
    ## ----------------------------------------------------------------------------------------------
    '''
    # get updated QG training
    QGPatch = cms.string('sqlite_file:data/QGL_80X.db')
    if os.getenv('GC_CONF'): 
        QGPatch = cms.string('sqlite_file:../src/data/QGL_80X.db')

    process.qgdb = cms.ESSource("PoolDBESSource",CondDBSetup,
        connect = QGPatch,
        toGet   = cms.VPSet(
            cms.PSet(
                record = cms.string('QGLikelihoodRcd'),
                tag    = cms.string('QGLikelihoodObject_80X_AK4PFchs'),
                label  = cms.untracked.string('QGL_AK4PFchs')
            ),
            cms.PSet(
                record = cms.string('QGLikelihoodRcd'),
                tag    = cms.string('QGLikelihoodObject_80X_AK4PFchs_antib'),
                label  = cms.untracked.string('QGL_AK4PFchs_antib')
            ),
        )
    )
    process.es_prefer_qg = cms.ESPrefer("PoolDBESSource","qgdb")
    
    # get QG tagging discriminant
    process.QGTagger = cms.EDProducer('QGTagger',
        srcJets	            = JetTag,
        jetsLabel           = cms.string('QGL_AK4PFchs'),
        srcRho              = cms.InputTag('fixedGridRhoFastjetAll'),		
        srcVertexCollection	= cms.InputTag('offlinePrimaryVerticesWithBS'),
        useQualityCuts	    = cms.bool(False)
    )
    
    # add userfloats & update tag
    process, JetTag = addJetInfo(process, JetTag, ['QGTagger:qgLikelihood','QGTagger:ptD', 'QGTagger:axis2'], ['QGTagger:mult'])
    
    process = makeJetVars(process,
                          JetTag=JetTag,
                          suff='',
                          skipGoodJets=False,
                          storeProperties=2,
                          geninfo=geninfo,
                          fastsim=fastsim,
                          SkipTag=SkipTag
    )
    
    # get double b-tagger (w/ miniAOD customizations)
    process.load("RecoBTag.ImpactParameter.pfImpactParameterAK8TagInfos_cfi")
    process.pfImpactParameterAK8TagInfos.primaryVertex = cms.InputTag("offlineSlimmedPrimaryVertices")
    process.pfImpactParameterAK8TagInfos.candidates = cms.InputTag("packedPFCandidates")
    process.pfImpactParameterAK8TagInfos.jets = JetAK8Tag
    process.load("RecoBTag.SecondaryVertex.pfInclusiveSecondaryVertexFinderAK8TagInfos_cfi")
    process.pfInclusiveSecondaryVertexFinderAK8TagInfos.extSVCollection = cms.InputTag("slimmedSecondaryVertices")
    process.pfInclusiveSecondaryVertexFinderAK8TagInfos.trackIPTagInfos = cms.InputTag("pfImpactParameterAK8TagInfos")
    process.load("RecoBTag.SecondaryVertex.pfBoostedDoubleSVAK8TagInfos_cfi")
    process.load("RecoBTag.SecondaryVertex.candidateBoostedDoubleSecondaryVertexAK8Computer_cfi")
    process.load("RecoBTag.SecondaryVertex.pfBoostedDoubleSecondaryVertexAK8BJetTags_cfi")
    
    # add discriminator and update tag
    process, JetAK8Tag = addJetInfo(process, JetAK8Tag, [], [], cms.VInputTag(cms.InputTag("pfBoostedDoubleSecondaryVertexAK8BJetTags")))
    
    # apply jet ID
    process = makeJetVars(process,
                          JetTag=JetAK8Tag,
                          suff='AK8',
                          skipGoodJets=False,
                          storeProperties=1,
                          geninfo=geninfo,
                          fastsim=fastsim,
                          onlyGoodJets=True
    )
    
    # AK8 jet variables - separate instance of jet properties producer
    from LeptoQuarkTreeMaker.Utils.jetproperties_cfi import jetproperties
    process.JetsPropertiesAK8 = jetproperties.clone(
        JetTag       = JetAK8Tag,
        properties = cms.vstring(
            "prunedMass"           ,
            "NsubjettinessTau1"    ,
            "NsubjettinessTau2"    ,
            "NsubjettinessTau3"    ,
            "bDiscriminatorSubjet1",
            "bDiscriminatorSubjet2",
            "bDiscriminatorCSV"    ,
            "NumBhadrons"          ,
            "NumChadrons"          ,
        )
    )
    #specify userfloats
    process.JetsPropertiesAK8.prunedMass = cms.vstring('ak8PFJetsCHSPrunedMass')
    process.JetsPropertiesAK8.NsubjettinessTau1 = cms.vstring('NjettinessAK8:tau1')
    process.JetsPropertiesAK8.NsubjettinessTau2 = cms.vstring('NjettinessAK8:tau2')
    process.JetsPropertiesAK8.NsubjettinessTau3 = cms.vstring('NjettinessAK8:tau3')
    process.JetsPropertiesAK8.bDiscriminatorSubjet1 = cms.vstring('SoftDrop','pfCombinedInclusiveSecondaryVertexV2BJetTags')
    process.JetsPropertiesAK8.bDiscriminatorSubjet2 = cms.vstring('SoftDrop','pfCombinedInclusiveSecondaryVertexV2BJetTags')
    process.JetsPropertiesAK8.bDiscriminatorCSV = cms.vstring('pfBoostedDoubleSecondaryVertexAK8BJetTags')
    #VectorRecoCand.extend([JetAK8Tag.value()+'(JetsAK8)'])
    VectorDouble.extend(['JetsPropertiesAK8:prunedMass(JetsAK8_prunedMass)',
                         'JetsPropertiesAK8:bDiscriminatorSubjet1(JetsAK8_bDiscriminatorSubjet1CSV)',
                         'JetsPropertiesAK8:bDiscriminatorSubjet2(JetsAK8_bDiscriminatorSubjet2CSV)',
                         'JetsPropertiesAK8:bDiscriminatorCSV(JetsAK8_doubleBDiscriminator)',
                         'JetsPropertiesAK8:NsubjettinessTau1(JetsAK8_NsubjettinessTau1)',
                         'JetsPropertiesAK8:NsubjettinessTau2(JetsAK8_NsubjettinessTau2)',
                         'JetsPropertiesAK8:NsubjettinessTau3(JetsAK8_NsubjettinessTau3)'])
    VectorInt.extend(['JetsPropertiesAK8:NumBhadrons(JetsAK8_NumBhadrons)',
                      'JetsPropertiesAK8:NumChadrons(JetsAK8_NumChadrons)'])

    '''
    ## ----------------------------------------------------------------------------------------------
    ## GenJet variables
    ## ----------------------------------------------------------------------------------------------
    if geninfo:
        # store all genjets
        VectorRecoCand.extend ( [ 'slimmedGenJets(GenJets)' ] )
    
        from LeptoQuarkTreeMaker.Utils.subJetSelection_cfi import SubGenJetSelection
        
        process.GenHTJets = SubGenJetSelection.clone(
            JetTag = cms.InputTag('slimmedGenJets'),
            MinPt  = cms.double(30),
            MaxEta = cms.double(2.4),
        )
        VectorBool.extend(['GenHTJets:SubJetMask(GenJets_HTMask)'])
        
        # make gen HT
        from LeptoQuarkTreeMaker.Utils.htdouble_cfi import htdouble
        process.GenHT = htdouble.clone(
            JetTag = cms.InputTag("GenHTJets"),
        )
        VarsDouble.extend(['GenHT'])
        
        process.GenMHTJets = SubGenJetSelection.clone(
            JetTag = cms.InputTag('slimmedGenJets'),
            MinPt  = cms.double(30),
            MaxEta = cms.double(5.0),
        )
        VectorBool.extend(['GenMHTJets:SubJetMask(GenJets_MHTMask)'])
        
        # make gen MHT
    
    ## ----------------------------------------------------------------------------------------------
    ## Baseline filters
    ## ----------------------------------------------------------------------------------------------
    # sequence for baseline filters
    process.Baseline = cms.Sequence()
        #process.Baseline += process.MHTFilter
    
    ## ----------------------------------------------------------------------------------------------
    ## MET
    ## ----------------------------------------------------------------------------------------------
    from LeptoQuarkTreeMaker.Utils.metdouble_cfi import metdouble
    process.MET = metdouble.clone(
        METTag = METTag,
        GenMETTag = cms.InputTag("slimmedMETs","",tagname), #original collection used deliberately here
        JetTag = cms.InputTag('HTJets'),
        geninfo = cms.untracked.bool(geninfo),
    )
    VarsDouble.extend(['MET:Pt(MET)','MET:Phi(METPhi)','MET:CaloPt(CaloMET)','MET:CaloPhi(CaloMETPhi)','MET:PFCaloPtRatio(PFCaloMETRatio)'])
    if geninfo:
        VarsDouble.extend(['MET:GenPt(GenMET)','MET:GenPhi(GenMETPhi)'])
        VectorDouble.extend(['MET:PtUp(METUp)', 'MET:PtDown(METDown)', 'MET:PhiUp(METPhiUp)', 'MET:PhiDown(METPhiDown)'])

    
    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------
    ## Optional producers (background estimations, control regions)
    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------

    ## ----------------------------------------------------------------------------------------------
    ## Hadronic Tau Background
    ## ----------------------------------------------------------------------------------------------

    ## ----------------------------------------------------------------------------------------------
    ## Lost Lepton Background
    ## ----------------------------------------------------------------------------------------------
    ## Zinv Background
    ## ----------------------------------------------------------------------------------------------

    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------
    ## Final steps
    ## ----------------------------------------------------------------------------------------------
    ## ----------------------------------------------------------------------------------------------

    # create the process path
    process.dump = cms.EDAnalyzer("EventContentAnalyzer")
    process.WriteTree = cms.Path(
        process.Baseline *
        process.LQTreeMaker2
    )
    
    return process
Example #15
0
    def makeAnalysisStep(self, stepName, **inputs):
        step = super(ElectronCalibration, self).makeAnalysisStep(stepName, **inputs)

        if stepName == 'preliminary':
            from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
            self.process = regressionWeights(self.process)

            from EgammaAnalysis.ElectronTools.regressionApplication_cff import slimmedElectrons as eReg

            eReg.src = step.getObjTag('e')
            step.addModule('electronRegression', eReg, 'e')

            cutOnSCEta = cms.EDFilter(
                "PATElectronSelector",
                src = step.getObjTag('e'),
                cut = cms.string('pt >= 5. && abs(superCluster.eta) < 2.5'),
                )
            step.addModule('selectElectronsBeforeID', cutOnSCEta, 'e')

            if not hasattr(self.process, 'RandomNumberGeneratorService'):
                self.process.RandomNumberGeneratorService = cms.Service(
                    'RandomNumberGeneratorService',
                    )
            self.process.RandomNumberGeneratorService.calibratedPatElectrons = cms.PSet(
                initialSeed = cms.untracked.uint32(987),
                )
            
            from EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi import calibratedPatElectrons
            from EgammaAnalysis.ElectronTools.calibrationTablesRun2 import files
            # from EgammaAnalysis.ElectronTools.calibrationTablesRun2 import correctionType
            # This would give you the default value of Legacy2016_v1 which should be used for
            # the ReReco, not the ReMiniAOD
            correctionType = "Moriond17_23Jan"

            calibratedPatElectrons.isMC = cms.bool(self.isMC)
            calibratedPatElectrons.electrons = step.getObjTag('e') 
            calibratedPatElectrons.isSynchronization = cms.bool(self.isSync)
            calibratedPatElectrons.correctionFile = cms.string(files[correctionType])

            step.addModule('calibratedPatElectrons', calibratedPatElectrons, 'e')

            if self.isMC:
                makeNewCollection=False
                if self.electronScaleShift or self.electronRhoResShift or self.electronPhiResShift:
                    makeNewCollection=True

                self.process.RandomNumberGeneratorService.electronSystematicShift = cms.PSet(
                    initialSeed = cms.untracked.uint32(345),
                    )

                shiftMod = cms.EDProducer(
                    "PATElectronSystematicShifter",
                    src = step.getObjTag('e'),
                    recHitCollectionEB = cms.InputTag('reducedEgamma:reducedEBRecHits'),
                    recHitCollectionEE = cms.InputTag('reducedEgamma:reducedEERecHits'),
                    correctionFile = cms.string(files[correctionType]),
                    scaleShift = cms.double(self.electronScaleShift),
                    rhoResShift = cms.double(self.electronRhoResShift),
                    phiResShift = cms.double(self.electronPhiResShift),
                    shiftCollection = cms.bool(makeNewCollection),
                    )

                step.addModule('electronSystematicShift', shiftMod, 'e')

        if stepName == 'selection':
            # need to re-sort now that we're calibrated
            eSort = cms.EDProducer(
                "PATElectronCollectionSorter",
                src = step.getObjTag('e'),
                function = cms.string('pt'),
                )
            step.addModule('electronSorting', eSort, 'e')

        return step
Example #16
0
    def makeAnalysisStep(self, stepName, **inputs):
        step = super(ElectronCalibration,
                     self).makeAnalysisStep(stepName, **inputs)

        if stepName == 'preliminary':
            from EgammaAnalysis.ElectronTools.regressionWeights_cfi import regressionWeights
            self.process = regressionWeights(self.process)

            from EgammaAnalysis.ElectronTools.regressionApplication_cff import slimmedElectrons as eReg

            eReg.src = step.getObjTag('e')
            step.addModule('electronRegression', eReg, 'e')

            cutOnSCEta = cms.EDFilter(
                "PATElectronSelector",
                src=step.getObjTag('e'),
                cut=cms.string('pt >= 5. && abs(superCluster.eta) < 2.5'),
            )
            step.addModule('selectElectronsBeforeID', cutOnSCEta, 'e')

            if not hasattr(self.process, 'RandomNumberGeneratorService'):
                self.process.RandomNumberGeneratorService = cms.Service(
                    'RandomNumberGeneratorService', )
            self.process.RandomNumberGeneratorService.calibratedPatElectrons = cms.PSet(
                initialSeed=cms.untracked.uint32(987), )

            from EgammaAnalysis.ElectronTools.calibratedPatElectronsRun2_cfi import calibratedPatElectrons
            from EgammaAnalysis.ElectronTools.calibrationTablesRun2 import files
            # from EgammaAnalysis.ElectronTools.calibrationTablesRun2 import correctionType
            # This would give you the default value of Legacy2016_v1 which should be used for
            # the ReReco, not the ReMiniAOD
            correctionType = "Moriond17_23Jan"

            calibratedPatElectrons.isMC = cms.bool(self.isMC)
            calibratedPatElectrons.electrons = step.getObjTag('e')
            calibratedPatElectrons.isSynchronization = cms.bool(self.isSync)
            calibratedPatElectrons.correctionFile = cms.string(
                files[correctionType])

            step.addModule('calibratedPatElectrons', calibratedPatElectrons,
                           'e')

            if self.isMC:
                makeNewCollection = False
                if self.electronScaleShift or self.electronRhoResShift or self.electronPhiResShift:
                    makeNewCollection = True

                self.process.RandomNumberGeneratorService.electronSystematicShift = cms.PSet(
                    initialSeed=cms.untracked.uint32(345), )

                shiftMod = cms.EDProducer(
                    "PATElectronSystematicShifter",
                    src=step.getObjTag('e'),
                    recHitCollectionEB=cms.InputTag(
                        'reducedEgamma:reducedEBRecHits'),
                    recHitCollectionEE=cms.InputTag(
                        'reducedEgamma:reducedEERecHits'),
                    correctionFile=cms.string(files[correctionType]),
                    scaleShift=cms.double(self.electronScaleShift),
                    rhoResShift=cms.double(self.electronRhoResShift),
                    phiResShift=cms.double(self.electronPhiResShift),
                    shiftCollection=cms.bool(makeNewCollection),
                )

                step.addModule('electronSystematicShift', shiftMod, 'e')

        if stepName == 'selection':
            # need to re-sort now that we're calibrated
            eSort = cms.EDProducer(
                "PATElectronCollectionSorter",
                src=step.getObjTag('e'),
                function=cms.string('pt'),
            )
            step.addModule('electronSorting', eSort, 'e')

        return step