Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-09 23:46:47

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
0004 
0005 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
0006 
0007 from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
0008 
0009 from PhysicsTools.PatUtils.tools.pfforTrkMET_cff import *
0010 
0011 def miniAOD_customizeCommon(process):
0012     process.patMuons.isoDeposits = cms.PSet()
0013     process.patElectrons.isoDeposits = cms.PSet()
0014     process.patTaus.isoDeposits = cms.PSet()
0015     process.patPhotons.isoDeposits = cms.PSet()
0016     #
0017     process.patMuons.embedTrack         = True  # used for IDs
0018     process.patMuons.embedCombinedMuon  = True  # used for IDs
0019     process.patMuons.embedMuonBestTrack = True  # used for IDs
0020     process.patMuons.embedStandAloneMuon = True # maybe?
0021     process.patMuons.embedPickyMuon = False   # no, use best track
0022     process.patMuons.embedTpfmsMuon = False   # no, use best track
0023     process.patMuons.embedDytMuon   = False   # no, use best track
0024     process.patMuons.addPuppiIsolation = cms.bool(True)
0025     process.patMuons.puppiIsolationChargedHadrons = cms.InputTag("muonPUPPIIsolation","h+-DR040-ThresholdVeto000-ConeVeto000")
0026     process.patMuons.puppiIsolationNeutralHadrons = cms.InputTag("muonPUPPIIsolation","h0-DR040-ThresholdVeto000-ConeVeto001")
0027     process.patMuons.puppiIsolationPhotons        = cms.InputTag("muonPUPPIIsolation","gamma-DR040-ThresholdVeto000-ConeVeto001")
0028     process.patMuons.puppiNoLeptonsIsolationChargedHadrons = cms.InputTag("muonPUPPINoLeptonsIsolation","h+-DR040-ThresholdVeto000-ConeVeto000")
0029     process.patMuons.puppiNoLeptonsIsolationNeutralHadrons = cms.InputTag("muonPUPPINoLeptonsIsolation","h0-DR040-ThresholdVeto000-ConeVeto001")
0030     process.patMuons.puppiNoLeptonsIsolationPhotons        = cms.InputTag("muonPUPPINoLeptonsIsolation","gamma-DR040-ThresholdVeto000-ConeVeto001")
0031 
0032     process.patMuons.computeMiniIso = True
0033     process.patMuons.computeMuonMVA = True
0034     process.patMuons.computeMuonIDMVA = True
0035     process.patMuons.computeSoftMuonMVA = True
0036 
0037     process.patMuons.addTriggerMatching = True
0038     from Configuration.Eras.Modifier_run2_muon_2016_cff import run2_muon_2016
0039     from Configuration.Eras.Modifier_run2_muon_2017_cff import run2_muon_2017
0040     from Configuration.Eras.Modifier_run2_muon_2018_cff import run2_muon_2018
0041     run2_muon_2016.toModify( process.patMuons, effectiveAreaVec = [0.0735,0.0619,0.0465,0.0433,0.0577])
0042     run2_muon_2017.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
0043     run2_muon_2018.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
0044     run2_muon_2016.toModify( process.patMuons, mvaTrainingFile = "RecoMuon/MuonIdentification/data/mu_2016_BDTG.weights.xml")
0045 
0046     process.patMuons.computePuppiCombinedIso = True
0047     #
0048     # disable embedding of electron and photon associated objects already stored by the ReducedEGProducer
0049     process.patElectrons.embedGsfElectronCore = False  ## process.patElectrons.embed in AOD externally stored gsf electron core
0050     process.patElectrons.embedSuperCluster    = False  ## process.patElectrons.embed in AOD externally stored supercluster
0051     process.patElectrons.embedPflowSuperCluster         = False  ## process.patElectrons.embed in AOD externally stored supercluster
0052     process.patElectrons.embedSeedCluster               = False  ## process.patElectrons.embed in AOD externally stored the electron's seedcluster
0053     process.patElectrons.embedBasicClusters             = False  ## process.patElectrons.embed in AOD externally stored the electron's basic clusters
0054     process.patElectrons.embedPreshowerClusters         = False  ## process.patElectrons.embed in AOD externally stored the electron's preshower clusters
0055     process.patElectrons.embedPflowBasicClusters        = False  ## process.patElectrons.embed in AOD externally stored the electron's pflow basic clusters
0056     process.patElectrons.embedPflowPreshowerClusters    = False  ## process.patElectrons.embed in AOD externally stored the electron's pflow preshower clusters
0057     process.patElectrons.embedRecHits         = False  ## process.patElectrons.embed in AOD externally stored the RecHits - can be called from the PATElectronProducer
0058     process.patElectrons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0059     process.patElectrons.usePfCandidateMultiMap = True
0060     process.patElectrons.pfCandidateMultiMap    = cms.InputTag("reducedEgamma","reducedGsfElectronPfCandMap")
0061     process.patElectrons.electronIDSources = cms.PSet()
0062 
0063     from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
0064     from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17
0065     (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17).toModify(process.patElectrons,
0066                                                                addPFClusterIso = True,
0067                                                                ecalPFClusterIsoMap = "reducedEgamma:eleEcalPFClusIso",
0068                                                                hcalPFClusterIsoMap = "reducedEgamma:eleHcalPFClusIso")
0069 
0070     #add puppi isolation in miniAOD
0071     process.patElectrons.addPuppiIsolation = cms.bool(True)
0072     process.patElectrons.puppiIsolationChargedHadrons = cms.InputTag("egmElectronPUPPIIsolation","h+-DR030-BarVeto000-EndVeto001")
0073     process.patElectrons.puppiIsolationNeutralHadrons = cms.InputTag("egmElectronPUPPIIsolation","h0-DR030-BarVeto000-EndVeto000")
0074     process.patElectrons.puppiIsolationPhotons        = cms.InputTag("egmElectronPUPPIIsolation","gamma-DR030-BarVeto000-EndVeto008")
0075     process.patElectrons.puppiNoLeptonsIsolationChargedHadrons = cms.InputTag("egmElectronPUPPINoLeptonsIsolation","h+-DR030-BarVeto000-EndVeto001")
0076     process.patElectrons.puppiNoLeptonsIsolationNeutralHadrons = cms.InputTag("egmElectronPUPPINoLeptonsIsolation","h0-DR030-BarVeto000-EndVeto000")
0077     process.patElectrons.puppiNoLeptonsIsolationPhotons        = cms.InputTag("egmElectronPUPPINoLeptonsIsolation","gamma-DR030-BarVeto000-EndVeto008")
0078 
0079     process.patElectrons.computeMiniIso = cms.bool(True)
0080 
0081     process.elPFIsoDepositChargedPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0082     process.elPFIsoDepositChargedAllPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0083     process.elPFIsoDepositNeutralPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0084     process.elPFIsoDepositGammaPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0085     process.elPFIsoDepositPUPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0086     #
0087     process.patPhotons.embedSuperCluster = False ## whether to process.patPhotons.embed in AOD externally stored supercluster
0088     process.patPhotons.embedSeedCluster               = False  ## process.patPhotons.embed in AOD externally stored the photon's seedcluster
0089     process.patPhotons.embedBasicClusters             = False  ## process.patPhotons.embed in AOD externally stored the photon's basic clusters
0090     process.patPhotons.embedPreshowerClusters         = False  ## process.patPhotons.embed in AOD externally stored the photon's preshower clusters
0091     process.patPhotons.embedRecHits         = False  ## process.patPhotons.embed in AOD externally stored the RecHits - can be called from the PATPhotonProducer
0092 
0093     #add puppi isolation in miniAOD
0094     process.patPhotons.addPuppiIsolation = cms.bool(True)
0095     process.patPhotons.puppiIsolationChargedHadrons = cms.InputTag("egmPhotonPUPPIIsolation","h+-DR030-")
0096     process.patPhotons.puppiIsolationNeutralHadrons = cms.InputTag("egmPhotonPUPPIIsolation","h0-DR030-")
0097     process.patPhotons.puppiIsolationPhotons        = cms.InputTag("egmPhotonPUPPIIsolation","gamma-DR030-")
0098 
0099     (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17).toModify(process.patPhotons,
0100                                                                addPFClusterIso = True,
0101                                                                ecalPFClusterIsoMap = "reducedEgamma:phoEcalPFClusIso",
0102                                                                hcalPFClusterIsoMap = "reducedEgamma:phoHcalPFClusIso")
0103     #the 80X legacy customsations are done in ootPhotonProducer for OOT photons
0104     run2_miniAOD_94XFall17.toModify(process.patOOTPhotons,
0105                                     addPFClusterIso = True,
0106                                     ecalPFClusterIsoMap = "reducedEgamma:ootPhoEcalPFClusIso",
0107                                     hcalPFClusterIsoMap = "reducedEgamma:ootPhoHcalPFClusIso")
0108 
0109 
0110     process.patPhotons.photonSource = cms.InputTag("reducedEgamma","reducedGedPhotons")
0111     process.patPhotons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0112     
0113     process.phPFIsoDepositChargedPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0114     process.phPFIsoDepositChargedAllPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0115     process.phPFIsoDepositNeutralPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0116     process.phPFIsoDepositGammaPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0117     process.phPFIsoDepositPUPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0118     #
0119     process.patOOTPhotons.photonSource = cms.InputTag("reducedEgamma","reducedOOTPhotons")
0120     process.patOOTPhotons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0121     #
0122     process.selectedPatJets.cut = cms.string("pt > 10")
0123     process.selectedPatMuons.cut = cms.string("pt > 5 || isPFMuon || (pt > 3 && (isGlobalMuon || isStandAloneMuon || numberOfMatches > 0 || muonID('RPCMuLoose')))")
0124     
0125     from Configuration.Eras.Modifier_phase2_muon_cff import phase2_muon
0126     phase2_muon.toModify(process.selectedPatMuons, cut = "pt > 5 || isPFMuon || (pt > 3 && (isGlobalMuon || isStandAloneMuon || numberOfMatches > 0 || muonID('RPCMuLoose') || muonID('ME0MuonArbitrated') || muonID('GEMMuonArbitrated')) )")
0127     from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
0128     pp_on_AA.toModify(process.selectedPatMuons, cut = "pt > 5 || isPFMuon || (pt > 1.2 && (isGlobalMuon || isStandAloneMuon) )")
0129 
0130     process.selectedPatElectrons.cut = cms.string("")
0131     process.selectedPatTaus.cut = cms.string("pt > 18. && tauID('decayModeFindingNewDMs')> 0.5")
0132     process.selectedPatPhotons.cut = cms.string("")
0133 
0134     _dummyPatJets = process.selectedPatJets.clone(cut = "pt < 0")
0135     task = getPatAlgosToolsTask(process)
0136 
0137     def _applySubstructure(process):
0138         from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
0139         
0140         from PhysicsTools.PatAlgos.slimming.applySubstructure_cff import applySubstructure
0141         applySubstructure( process )
0142     (~pp_on_AA).toModify(process, _applySubstructure)
0143 
0144     pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJets', p.selectedPatJets.clone(), p, task))
0145     pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJetsAK8', _dummyPatJets.clone(), p, task))
0146 
0147     #
0148     from PhysicsTools.PatAlgos.tools.trigTools import switchOnTriggerStandAlone
0149     switchOnTriggerStandAlone( process, outputModule = '' )
0150     process.patTrigger.packTriggerPathNames = cms.bool(True)
0151     #
0152     # apply type I + other PFMEt corrections to pat::MET object
0153     # and estimate systematic uncertainties on MET
0154 
0155     from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncForMiniAODProduction
0156     runMetCorAndUncForMiniAODProduction(process, metType="PF",
0157                                         jetCollUnskimmed="patJets")
0158     
0159     #caloMET computation
0160     from PhysicsTools.PatAlgos.tools.metTools import addMETCollection
0161     addMETCollection(process,
0162                      labelName = "patCaloMet",
0163                      metSource = "caloMetM"
0164                      )
0165 
0166     #noHF pfMET =========
0167 
0168     process.noHFCands = cms.EDFilter("GenericPFCandidateSelector",
0169                                      src=cms.InputTag("particleFlow"),
0170                                      cut=cms.string("abs(pdgId)!=1 && abs(pdgId)!=2 && abs(eta)<3.0")
0171                                      )
0172     task.add(process.noHFCands)
0173 
0174     runMetCorAndUncForMiniAODProduction(process,
0175                                         pfCandColl=cms.InputTag("noHFCands"),
0176                                         recoMetFromPFCs=True, #needed for HF removal
0177                                         jetSelection="pt>15 && abs(eta)<3.",
0178                                         postfix="NoHF"
0179                                         )
0180 
0181     process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
0182     task.add(process.slimmedMETs)
0183     (~pp_on_AA).toModify(process.slimmedMETs, addDeepMETs = True)
0184 
0185     def _add_slimmedMETsNoHF(process):
0186         addToProcessAndTask('slimmedMETsNoHF', process.slimmedMETs.clone(), process, task)
0187         process.slimmedMETsNoHF.src = cms.InputTag("patMETsNoHF")
0188         process.slimmedMETsNoHF.rawVariation =  cms.InputTag("patPFMetNoHF")
0189         process.slimmedMETsNoHF.t1Uncertainties = cms.InputTag("patPFMetT1%sNoHF") 
0190         process.slimmedMETsNoHF.t01Variation = cms.InputTag("patPFMetT0pcT1NoHF")
0191         process.slimmedMETsNoHF.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sNoHF")
0192         process.slimmedMETsNoHF.tXYUncForRaw = cms.InputTag("patPFMetTxyNoHF")
0193         process.slimmedMETsNoHF.tXYUncForT1 = cms.InputTag("patPFMetT1TxyNoHF")
0194         process.slimmedMETsNoHF.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyNoHF")
0195         process.slimmedMETsNoHF.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyNoHF")
0196         process.slimmedMETsNoHF.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyNoHF")
0197         del process.slimmedMETsNoHF.caloMET
0198     (~pp_on_AA).toModify(process, _add_slimmedMETsNoHF)
0199     # ================== NoHF pfMET
0200 
0201     #  ==================  CHSMET 
0202     process.load("CommonTools.ParticleFlow.pfCHS_cff")
0203     task.add(process.pfCHS)
0204 
0205     from RecoMET.METProducers.pfMet_cfi import pfMet
0206     process.pfMetCHS = pfMet.clone(src = 'pfCHS')
0207     task.add(process.pfMetCHS)
0208 
0209     addMETCollection(process,
0210                      labelName = "patCHSMet",
0211                      metSource = "pfMetCHS"
0212                      )
0213 
0214     process.patCHSMet.computeMETSignificance = cms.bool(False)
0215 
0216     #  ==================  CHSMET 
0217 
0218     #  ==================  TrkMET 
0219     process.TrkCands = chargedPackedCandsForTkMet.clone()
0220     task.add(process.TrkCands)
0221 
0222     process.pfMetTrk = pfMet.clone(src = 'TrkCands')
0223     task.add(process.pfMetTrk)
0224 
0225     addMETCollection(process,
0226                      labelName = "patTrkMet",
0227                      metSource = "pfMetTrk"
0228                      )
0229 
0230     process.patTrkMet.computeMETSignificance = cms.bool(False)
0231 
0232     #  ==================  TrkMET 
0233     
0234 
0235     ## PU JetID
0236     process.load("RecoJets.JetProducers.PileupJetID_cfi")
0237     task.add(process.pileUpJetIDTask)
0238 
0239     process.patJets.userData.userFloats.src = [ cms.InputTag("pileupJetId:fullDiscriminant"), ]
0240     process.patJets.userData.userInts.src = [ cms.InputTag("pileupJetId:fullId"), ]
0241 
0242     ## Quark Gluon Likelihood
0243     process.load('RecoJets.JetProducers.QGTagger_cfi')
0244     task.add(process.QGTaggerTask)
0245 
0246     process.patJets.userData.userFloats.src += [ 'QGTagger:qgLikelihood', ]
0247 
0248     #HF jet shower shape
0249     process.load('RecoJets.JetProducers.hfJetShowerShape_cfi')
0250     task.add(process.hfJetShowerShape)
0251 
0252     process.patJets.userData.userFloats.src += [ 'hfJetShowerShape:sigmaEtaEta', 'hfJetShowerShape:sigmaPhiPhi']
0253     process.patJets.userData.userInts.src += [ 'hfJetShowerShape:centralEtaStripSize', 'hfJetShowerShape:adjacentEtaStripsSize']
0254 
0255     ## DeepCSV meta discriminators (simple arithmethic on output probabilities)
0256     def _add_deepFlavour(process):
0257         process.load('RecoBTag.Combined.deepFlavour_cff')
0258         task.add(process.pfDeepCSVDiscriminatorsJetTags)
0259         process.patJets.discriminatorSources.extend([
0260             'pfDeepCSVDiscriminatorsJetTags:BvsAll',
0261             'pfDeepCSVDiscriminatorsJetTags:CvsB',
0262             'pfDeepCSVDiscriminatorsJetTags:CvsL',
0263         ])
0264     from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018
0265     (~pp_on_AA_2018).toModify(process, _add_deepFlavour)
0266 
0267     ## CaloJets
0268     process.caloJetMap = cms.EDProducer("RecoJetDeltaRValueMapProducer",
0269          src = process.patJets.jetSource,
0270          matched = cms.InputTag("ak4CaloJets"),
0271          distMax = cms.double(0.4),
0272          values = cms.vstring('pt','emEnergyFraction'),
0273      valueLabels = cms.vstring('pt','emEnergyFraction'),
0274      lazyParser = cms.bool(True) )
0275     task.add(process.caloJetMap)
0276     process.patJets.userData.userFloats.src += [ 'caloJetMap:pt', 'caloJetMap:emEnergyFraction' ]
0277 
0278     pp_on_AA.toModify(process.patJets.userData.userInts, src = [] )
0279     pp_on_AA.toModify(process.patJets.userData.userFloats, src = [] )
0280 
0281     #Muon object modifications 
0282     from PhysicsTools.PatAlgos.slimming.muonIsolationsPUPPI_cfi import makeInputForPUPPIIsolationMuon
0283     makeInputForPUPPIIsolationMuon(process)
0284 
0285     #EGM object modifications 
0286     from PhysicsTools.PatAlgos.slimming.egmIsolationsPUPPI_cfi import makeInputForPUPPIIsolationEgm
0287     makeInputForPUPPIIsolationEgm(process)
0288     from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma_modifications
0289     process.slimmedElectrons.modifierConfig.modifications = egamma_modifications
0290     process.slimmedPhotons.modifierConfig.modifications   = egamma_modifications
0291 
0292     #VID Electron IDs
0293     process.patElectrons.addElectronID = cms.bool(True)
0294     electron_ids = ['RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
0295                     'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV71_cff',
0296                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V1_cff',
0297                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
0298                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Winter22_122X_V1_cff',
0299                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff', 
0300                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
0301                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff', 
0302                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
0303                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
0304                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
0305                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
0306             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer16UL_ID_ISO_cff',
0307                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer17UL_ID_ISO_cff',
0308                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer18UL_ID_ISO_cff',
0309                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_noIso_V1_cff',
0310                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_iso_V1_cff'
0311                     ]
0312     switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD, task)
0313     process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0314     process.electronMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedGsfElectrons')
0315 
0316     # To use older DataFormats, the electronMVAValueMapProducer MUST take a updated electron collection
0317     # such that the conversion variables are filled correctly.
0318     process.load("RecoEgamma.EgammaTools.gedGsfElectronsTo106X_cff")
0319     run2_miniAOD_80XLegacy.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom80XTo106XTask))
0320     run2_miniAOD_80XLegacy.toModify(process.electronMVAValueMapProducer,
0321                                      keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0322                                      src = cms.InputTag("gedGsfElectronsFrom80XTo106X"))
0323 
0324     run2_miniAOD_94XFall17.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
0325     run2_miniAOD_94XFall17.toModify(process.electronMVAValueMapProducer,
0326                                      keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0327                                      src = cms.InputTag("gedGsfElectronsFrom94XTo106X"))
0328 
0329     from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018
0330     pp_on_AA_2018.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
0331     pp_on_AA_2018.toModify(process.electronMVAValueMapProducer,
0332                            keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0333                            src = "gedGsfElectronsFrom94XTo106X")
0334 
0335     for idmod in electron_ids:
0336         setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection,None,False,task)
0337 
0338     #VID Photon IDs
0339     process.patPhotons.addPhotonID = cms.bool(True)
0340     photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
0341                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
0342                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', 
0343                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
0344                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
0345                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
0346                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Winter22_122X_V1_cff',
0347                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_RunIIIWinter22_122X_V1_cff']
0348 
0349     switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task) 
0350     process.egmPhotonIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedPhotons")
0351     process.photonMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedPhotons')
0352     for idmod in photon_ids:
0353         setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False,task)
0354  
0355     #add the cut base IDs bitmaps of which cuts passed
0356     from RecoEgamma.EgammaTools.egammaObjectModifications_tools import makeVIDBitsModifier
0357     egamma_modifications.append(makeVIDBitsModifier(process,"egmGsfElectronIDs","egmPhotonIDs"))
0358 
0359     #-- Adding boosted taus
0360     from RecoTauTag.Configuration.boostedHPSPFTaus_cfi import addBoostedTaus
0361     addBoostedTaus(process)
0362     process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
0363     process.load("RecoTauTag.Configuration.HPSPFTaus_cff")
0364     #-- Adding customization for 94X 2017 legacy reMniAOD
0365     _makePatTausTaskWithRetrainedMVATauID = process.makePatTausTask.copy()
0366     _makePatTausTaskWithRetrainedMVATauID.add(process.hpsPFTauBasicDiscriminatorsTask,
0367                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTTask,
0368                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLTTask,
0369                                               process.hpsPFTauBasicDiscriminatorsdR03Task,
0370                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLTTask,
0371                                               process.hpsPFTauDiscriminationByMVA6rawElectronRejection,
0372                                               process.hpsPFTauDiscriminationByMVA6ElectronRejection,
0373                                               process.hpsPFTauDiscriminationByMuonRejection3)
0374     from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
0375     (run2_miniAOD_94XFall17 | run2_miniAOD_UL).toReplaceWith(
0376         process.makePatTausTask, _makePatTausTaskWithRetrainedMVATauID
0377         )
0378     #-- Adding DeepTauID
0379     # deepTau v2p1 and v2p5
0380     _updatedTauName = 'slimmedTausDeepIDsv2p1'
0381     _noUpdatedTauName = 'slimmedTausNoDeepIDs'
0382     import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
0383     tauIdEmbedder = tauIdConfig.TauIDEmbedder(
0384         process, debug = False,
0385         originalTauName = _noUpdatedTauName,
0386         updatedTauName = _updatedTauName,
0387         postfix = 'ForMini',
0388         toKeep = ['deepTau2017v2p1','deepTau2018v2p5']
0389     )
0390     from Configuration.Eras.Modifier_phase2_common_cff import phase2_common #Phase2 Tau MVA
0391     phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('newDMPhase2v1')) #Phase2 Tau isolation MVA
0392     phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('againstElePhase2v1')) #Phase2 Tau anti-e MVA
0393     tauIdEmbedder.runTauID()
0394     addToProcessAndTask(_noUpdatedTauName, process.slimmedTaus.clone(),process,task)
0395     delattr(process, 'slimmedTaus')
0396     process.slimmedTaus = getattr(process, _updatedTauName).clone()
0397     process.rerunMvaIsolationTaskForMini.add(process.slimmedTaus)
0398     task.add(process.rerunMvaIsolationTaskForMini)
0399 
0400     #-- Rerun tauID against dead ECal towers to taus for the various re-MiniAOD eras
0401     # to enable default behoviour with leading track extrapolation to ECAL
0402     _makePatTausTaskWithDeadECalVeto = process.makePatTausTask.copy()
0403     _makePatTausTaskWithDeadECalVeto.add(
0404         process.hpsPFTauDiscriminationByDeadECALElectronRejection
0405     )
0406     _run2_miniAOD_ANY = (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17 | run2_miniAOD_UL)
0407     _run2_miniAOD_ANY.toReplaceWith(
0408         process.makePatTausTask, _makePatTausTaskWithDeadECalVeto
0409     )
0410 
0411     #-- Adding customization for 80X 2016 legacy reMiniAOD and 2018 heavy ions
0412     _makePatTausTaskWithTauReReco = process.makePatTausTask.copy()
0413     _makePatTausTaskWithTauReReco.add(process.PFTauTask)
0414     (run2_miniAOD_80XLegacy | pp_on_AA).toReplaceWith(
0415         process.makePatTausTask, _makePatTausTaskWithTauReReco
0416         )
0417     
0418     # Adding puppi jets
0419     process.load('CommonTools.PileupAlgos.Puppi_cff')
0420     process.load('RecoJets.JetProducers.ak4PFJets_cfi')
0421     from Configuration.Eras.Modifier_pA_2016_cff import pA_2016
0422     _rerun_puppijets_task = task.copy()
0423     _rerun_puppijets_task.add(process.puppi, process.ak4PFJetsPuppi)
0424     (_run2_miniAOD_ANY | pA_2016 | pp_on_AA).toReplaceWith(task, _rerun_puppijets_task)
0425 
0426     from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
0427     process.ak4PFJetsPuppiTracksAssociatorAtVertex = cms.EDProducer("JetTracksAssociatorAtVertex",
0428         j2tParametersVX,
0429         jets = cms.InputTag("ak4PFJetsPuppi")
0430     )
0431     task.add(process.ak4PFJetsPuppiTracksAssociatorAtVertex)
0432     process.patJetPuppiCharge = cms.EDProducer("JetChargeProducer",
0433         src = cms.InputTag("ak4PFJetsPuppiTracksAssociatorAtVertex"),
0434         var = cms.string('Pt'),
0435         exp = cms.double(1.0)
0436     )
0437     task.add(process.patJetPuppiCharge)
0438 
0439     def _add_jetsPuppi(process):
0440         from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
0441         noDeepFlavourDiscriminators = [x.value() if isinstance(x, cms.InputTag) else x for x in process.patJets.discriminatorSources 
0442                                        if not "DeepFlavour" in str(x)]
0443         addJetCollection(process, postfix   = "", labelName = 'Puppi', jetSource = cms.InputTag('ak4PFJetsPuppi'),
0444                          jetCorrections = ('AK4PFPuppi', ['L2Relative', 'L3Absolute'], ''),
0445                          pfCandidates = cms.InputTag("particleFlow"),
0446                          algo= 'AK', rParam = 0.4, btagDiscriminators = noDeepFlavourDiscriminators
0447                      )
0448 
0449         process.patJetGenJetMatchPuppi.matched = 'slimmedGenJets'
0450     
0451         process.patJetsPuppi.jetChargeSource = cms.InputTag("patJetPuppiCharge")
0452     
0453         process.selectedPatJetsPuppi.cut = cms.string("pt > 10")
0454     
0455         from PhysicsTools.PatAlgos.slimming.applyDeepBtagging_cff import applyDeepBtagging
0456         applyDeepBtagging( process )
0457 
0458         process.slimmedJetsNoDeepFlavour.dropTagInfos = '0'
0459         process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.addTagInfos = True
0460         process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.tagInfoSources = ["pixelClusterTagInfos"]
0461         _run2_miniAOD_ANY.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = False )
0462     (~pp_on_AA).toModify(process, _add_jetsPuppi)
0463 
0464     pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJetsPuppi', _dummyPatJets.clone(), p, task))
0465 
0466     # Embed pixelClusterTagInfos in slimmedJets
0467     process.patJets.addTagInfos = True
0468     process.patJets.tagInfoSources = ["pixelClusterTagInfos"]
0469 
0470     _run2_miniAOD_ANY.toModify(process.patJets, addTagInfos = False )
0471 
0472     from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018
0473     pp_on_AA_2018.toModify(process.patJets, tagInfoSources = cms.VInputTag(["impactParameterTagInfos","secondaryVertexTagInfos"]) )
0474 
0475     ## puppi met
0476     def _add_metPuppi(process):
0477         process.load('RecoMET.METProducers.pfMetPuppi_cfi')
0478         _rerun_puppimet_task = task.copy()
0479         _rerun_puppimet_task.add(process.puppiNoLep, process.pfMetPuppi)
0480         (_run2_miniAOD_ANY | pA_2016 | pp_on_AA).toReplaceWith(task, _rerun_puppimet_task)
0481     
0482         runMetCorAndUncForMiniAODProduction(process, metType="Puppi",
0483                                             jetCollUnskimmed="slimmedJetsPuppi",
0484                                             recoMetFromPFCs=True,
0485                                             jetFlavor="AK4PFPuppi",
0486                                             postfix="Puppi"
0487                                         )
0488     (~pp_on_AA).toModify(process, _add_metPuppi)
0489 
0490     process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
0491     task.add(process.slimmedMETs)
0492 
0493     def _add_slimmedMETsPuppi(process):
0494         addToProcessAndTask('slimmedMETsPuppi', process.slimmedMETs.clone(), process, task)
0495         process.slimmedMETsPuppi.src = cms.InputTag("patMETsPuppi")
0496         process.slimmedMETsPuppi.rawVariation =  cms.InputTag("patPFMetPuppi")
0497         process.slimmedMETsPuppi.t1Uncertainties = cms.InputTag("patPFMetT1%sPuppi")
0498         process.slimmedMETsPuppi.t01Variation = cms.InputTag("patPFMetT0pcT1Puppi")
0499         process.slimmedMETsPuppi.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sPuppi")
0500         process.slimmedMETsPuppi.tXYUncForRaw = cms.InputTag("patPFMetTxyPuppi")
0501         process.slimmedMETsPuppi.tXYUncForT1 = cms.InputTag("patPFMetT1TxyPuppi")
0502         process.slimmedMETsPuppi.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyPuppi")
0503         process.slimmedMETsPuppi.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyPuppi")
0504         process.slimmedMETsPuppi.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyPuppi")
0505         del process.slimmedMETsPuppi.caloMET
0506     (~pp_on_AA).toModify(process, _add_slimmedMETsPuppi)
0507 
0508     def _add_deepMET(process):
0509         from RecoMET.METPUSubtraction.deepMETProducer_cff import deepMETsResolutionTune, deepMETsResponseTune
0510 
0511         addToProcessAndTask('deepMETsResolutionTune', deepMETsResolutionTune, process, task)
0512         addToProcessAndTask('deepMETsResponseTune', deepMETsResponseTune, process, task)
0513     (~pp_on_AA).toModify(process, _add_deepMET)
0514 
0515     # add DetIdAssociatorRecords to EventSetup (for isolatedTracks)
0516     process.load("TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff")
0517 
0518     # EGamma objects from HGCal are not yet in GED
0519     # so add companion collections for Phase-II MiniAOD production
0520     from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal
0521     process.load("RecoEgamma.EgammaTools.slimmedEgammaHGC_cff")
0522     phase2_hgcal.toModify(task, func=lambda t: t.add(process.slimmedEgammaHGCTask))
0523 
0524     # L1 pre-firing weights for 2016, 2017, and 2018
0525     from Configuration.Eras.Modifier_run2_L1prefiring_cff import run2_L1prefiring
0526     from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
0527     from Configuration.Eras.Modifier_stage2L1Trigger_2017_cff import stage2L1Trigger_2017
0528     from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018
0529     from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016
0530     if not hasattr(process,'prefiringweight'):
0531         process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff")
0532     (stage2L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016preVFP", DataEraMuon = "2016preVFP" )
0533     (stage2L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016postVFP", DataEraMuon = "2016postVFP" )
0534     stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "UL2017BtoF", DataEraMuon = "20172018")
0535     stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018")
0536     run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight))
0537 
0538     from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeL1FastJetJECs
0539     pp_on_AA.toModify(process, removeL1FastJetJECs)
0540 
0541 def miniAOD_customizeMC(process):
0542     task = getPatAlgosToolsTask(process)
0543     #GenJetFlavourInfos
0544     process.load("PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi")
0545     task.add(process.selectedHadronsAndPartons)
0546     task.add(process.selectedHadronsAndPartonsForGenJetsFlavourInfos)
0547     
0548     process.load("PhysicsTools.JetMCAlgos.AK4GenJetFlavourInfos_cfi")
0549     task.add(process.ak4GenJetFlavourInfos)
0550 
0551     process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJetsFlavourInfos_cfi')
0552     task.add(process.slimmedGenJetsFlavourInfos)
0553 
0554     #slimmed pileup information
0555     process.load('PhysicsTools.PatAlgos.slimming.slimmedAddPileupInfo_cfi')
0556     task.add(process.slimmedAddPileupInfo)
0557 
0558     process.muonMatch.matched = "prunedGenParticles"
0559     process.electronMatch.matched = "prunedGenParticles"
0560     process.electronMatch.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0561     process.photonMatch.matched = "prunedGenParticles"
0562     process.photonMatch.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0563     process.ootPhotonMatch.matched = "prunedGenParticles"
0564     process.ootPhotonMatch.src = cms.InputTag("reducedEgamma","reducedOOTPhotons")
0565     process.tauMatch.matched = "prunedGenParticles"
0566     process.tauGenJets.GenParticles = "prunedGenParticles"
0567     #Boosted taus 
0568     process.tauMatchBoosted.matched = "prunedGenParticles"
0569     process.tauGenJetsBoosted.GenParticles = "prunedGenParticles"
0570     process.patJetPartons.particles = "genParticles"
0571     process.patJetPartonMatch.matched = "prunedGenParticles"
0572     pp_on_AA.toModify(process.patJetPartonMatch, matched =  "hiSignalGenParticles")
0573     from Configuration.ProcessModifiers.genJetSubEvent_cff import genJetSubEvent
0574     genJetSubEvent.toModify(process.patJetPartonMatch, matched =  "cleanedPartons")
0575     process.patJetPartonMatch.mcStatus = [ 3, 23 ]
0576     process.patJetGenJetMatch.matched = "slimmedGenJets"
0577     (~pp_on_AA).toModify(process, patJetGenJetMatchAK8Puppi = dict(matched =  "slimmedGenJetsAK8"))
0578     process.patMuons.embedGenMatch = False
0579     process.patElectrons.embedGenMatch = False
0580     process.patPhotons.embedGenMatch = False
0581     process.patOOTPhotons.embedGenMatch = False
0582     process.patTaus.embedGenMatch = False
0583     process.patTausBoosted.embedGenMatch = False
0584     process.patJets.embedGenPartonMatch = False
0585     #also jet flavour must be switched
0586     process.patJetFlavourAssociation.rParam = 0.4
0587     
0588     from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeJECsForMC
0589     pp_on_AA.toModify(process, removeJECsForMC)
0590     pp_on_AA.toReplaceWith(task,task.copyAndExclude([process.slimmedGenJetsFlavourInfos]))
0591 
0592 
0593 def miniAOD_customizeOutput(out):
0594     from PhysicsTools.PatAlgos.slimming.MicroEventContent_cff import MiniAODOverrideBranchesSplitLevel
0595     out.overrideBranchesSplitLevel = MiniAODOverrideBranchesSplitLevel
0596     out.splitLevel = cms.untracked.int32(0)
0597     out.dropMetaData = cms.untracked.string('ALL')
0598     out.fastCloning= cms.untracked.bool(False)
0599     out.overrideInputFileSplitLevels = cms.untracked.bool(True)
0600     out.compressionAlgorithm = cms.untracked.string('LZMA')
0601 
0602 def miniAOD_customizeData(process):
0603     from PhysicsTools.PatAlgos.tools.coreTools import runOnData
0604     runOnData( process, outputModules = [] )
0605     process.load("RecoPPS.Local.ctppsLocalTrackLiteProducer_cff")
0606     process.load("RecoPPS.ProtonReconstruction.ctppsProtons_cff")
0607     process.load("Geometry.VeryForwardGeometry.geometryRPFromDB_cfi")
0608     process.load('L1Trigger.L1TGlobal.simGtExtFakeProd_cfi')
0609     task = getPatAlgosToolsTask(process)
0610     task.add(process.simGtExtUnprefireable)
0611     from Configuration.Eras.Modifier_ctpps_cff import ctpps
0612     ctpps.toModify(task, func=lambda t: t.add(process.ctppsLocalTrackLiteProducer))
0613     ctpps.toModify(task, func=lambda t: t.add(process.ctppsProtons))
0614     from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
0615     run2_miniAOD_UL.toModify(task, func=lambda t: t.add(process.simGtExtUnprefireable))
0616 
0617 def miniAOD_customizeAllData(process):
0618     miniAOD_customizeCommon(process)
0619     miniAOD_customizeData(process)
0620     return process
0621 
0622 def miniAOD_customizeAllMC(process):
0623     miniAOD_customizeCommon(process)
0624     miniAOD_customizeMC(process)
0625     return process
0626 
0627 def miniAOD_customizeAllMCFastSim(process):
0628     miniAOD_customizeCommon(process)
0629     miniAOD_customizeMC(process)
0630     from PhysicsTools.PatAlgos.slimming.metFilterPaths_cff import miniAOD_customizeMETFiltersFastSim
0631     process = miniAOD_customizeMETFiltersFastSim(process)
0632     from PhysicsTools.PatAlgos.slimming.isolatedTracks_cfi import miniAOD_customizeIsolatedTracksFastSim
0633     process = miniAOD_customizeIsolatedTracksFastSim(process)
0634     process.patMuons.addTriggerMatching = False
0635     # Disable pixelClusterTagInfos in FastSim (no siPixelCluster available)
0636     from Configuration.Eras.Modifier_fastSim_cff import fastSim
0637     fastSim.toModify(process.patJets, addTagInfos = cms.bool(False) )
0638     fastSim.toModify(process.slimmedJetsNoDeepFlavour, dropTagInfos = cms.string('1') )
0639     fastSim.toModify(process.updatedPatJetsSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
0640     fastSim.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
0641 
0642     return process