Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:56

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.computeMuonIDMVA = True
0034     process.patMuons.computeSoftMuonMVA = True
0035 
0036     process.patMuons.addTriggerMatching = True
0037     from Configuration.Eras.Modifier_run2_muon_2016_cff import run2_muon_2016
0038     from Configuration.Eras.Modifier_run2_muon_2017_cff import run2_muon_2017
0039     from Configuration.Eras.Modifier_run2_muon_2018_cff import run2_muon_2018
0040     from Configuration.Eras.Modifier_run3_muon_cff import run3_muon
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     run3_muon.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
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 > 15")
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     from Configuration.Eras.Modifier_run3_upc_cff import run3_upc
0130     run3_upc.toModify(process.selectedPatMuons, cut = "")
0131     from Configuration.Eras.Modifier_ppRef_2024_cff import ppRef_2024
0132     ppRef_2024.toModify(process.selectedPatMuons, cut = "pt > 5 || isPFMuon || isTrackerMuon || (pt > 1.2 && (isGlobalMuon || isStandAloneMuon))")
0133 
0134     process.selectedPatElectrons.cut = cms.string("")
0135     process.selectedPatTaus.cut = cms.string("pt > 18. && tauID('decayModeFindingNewDMs')> 0.5")
0136     process.selectedPatPhotons.cut = cms.string("")
0137 
0138     _dummyPatJets = process.selectedPatJets.clone(cut = "pt < 0")
0139     task = getPatAlgosToolsTask(process)
0140 
0141     def _applySubstructure(process):
0142         from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
0143 
0144         from PhysicsTools.PatAlgos.slimming.applySubstructure_cff import applySubstructure
0145         applySubstructure( process )
0146     (~pp_on_AA).toModify(process, _applySubstructure)
0147 
0148     pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJets', p.selectedPatJets.clone(), p, task))
0149     pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJetsAK8', _dummyPatJets.clone(), p, task))
0150 
0151     #
0152     from PhysicsTools.PatAlgos.tools.trigTools import switchOnTriggerStandAlone
0153     switchOnTriggerStandAlone( process, outputModule = '' )
0154     process.patTrigger.packTriggerPathNames = cms.bool(True)
0155     #
0156     # apply type I + other PFMEt corrections to pat::MET object
0157     # and estimate systematic uncertainties on MET
0158 
0159     from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncForMiniAODProduction
0160     runMetCorAndUncForMiniAODProduction(process, metType="PF",
0161                                         jetCollUnskimmed="patJets")
0162     
0163     #caloMET computation
0164     from PhysicsTools.PatAlgos.tools.metTools import addMETCollection
0165     addMETCollection(process,
0166                      labelName = "patCaloMet",
0167                      metSource = "caloMetM"
0168                      )
0169 
0170     #noHF pfMET =========
0171 
0172     process.noHFCands = cms.EDFilter("GenericPFCandidateSelector",
0173                                      src=cms.InputTag("particleFlow"),
0174                                      cut=cms.string("abs(pdgId)!=1 && abs(pdgId)!=2 && abs(eta)<3.0")
0175                                      )
0176     task.add(process.noHFCands)
0177 
0178     runMetCorAndUncForMiniAODProduction(process,
0179                                         pfCandColl=cms.InputTag("noHFCands"),
0180                                         recoMetFromPFCs=True, #needed for HF removal
0181                                         jetSelection="pt>15 && abs(eta)<3.",
0182                                         postfix="NoHF"
0183                                         )
0184 
0185     process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
0186     task.add(process.slimmedMETs)
0187     (~pp_on_AA).toModify(process.slimmedMETs, addDeepMETs = True)
0188 
0189     # ================== NoHF pfMET
0190 
0191     #  ==================  CHSMET 
0192     process.load("CommonTools.ParticleFlow.pfCHS_cff")
0193     task.add(process.pfCHS)
0194 
0195     from RecoMET.METProducers.pfMet_cfi import pfMet
0196     process.pfMetCHS = pfMet.clone(src = 'pfCHS')
0197     task.add(process.pfMetCHS)
0198 
0199     addMETCollection(process,
0200                      labelName = "patCHSMet",
0201                      metSource = "pfMetCHS"
0202                      )
0203 
0204     process.patCHSMet.computeMETSignificance = cms.bool(False)
0205 
0206     #  ==================  CHSMET 
0207 
0208     #  ==================  TrkMET 
0209     process.TrkCands = chargedPackedCandsForTkMet.clone()
0210     task.add(process.TrkCands)
0211 
0212     process.pfMetTrk = pfMet.clone(src = 'TrkCands')
0213     task.add(process.pfMetTrk)
0214 
0215     addMETCollection(process,
0216                      labelName = "patTrkMet",
0217                      metSource = "pfMetTrk"
0218                      )
0219 
0220     process.patTrkMet.computeMETSignificance = cms.bool(False)
0221 
0222     #  ==================  TrkMET 
0223 
0224     #HF jet shower shape
0225     process.load('RecoJets.JetProducers.hfJetShowerShape_cfi')
0226     task.add(process.hfJetShowerShape)
0227 
0228     process.patJets.userData.userFloats.src += [ 'hfJetShowerShape:sigmaEtaEta', 'hfJetShowerShape:sigmaPhiPhi']
0229     process.patJets.userData.userInts.src += [ 'hfJetShowerShape:centralEtaStripSize', 'hfJetShowerShape:adjacentEtaStripsSize']
0230 
0231     ## DeepCSV meta discriminators (simple arithmethic on output probabilities)
0232     def _add_deepFlavour(process):
0233         process.load('RecoBTag.Combined.deepFlavour_cff')
0234         task.add(process.pfDeepCSVDiscriminatorsJetTags)
0235         process.patJets.discriminatorSources.extend([
0236             'pfDeepCSVDiscriminatorsJetTags:BvsAll',
0237             'pfDeepCSVDiscriminatorsJetTags:CvsB',
0238             'pfDeepCSVDiscriminatorsJetTags:CvsL',
0239         ])
0240 
0241     ## CaloJets
0242     process.caloJetMap = cms.EDProducer("RecoJetDeltaRValueMapProducer",
0243          src = process.patJets.jetSource,
0244          matched = cms.InputTag("ak4CaloJets"),
0245          distMax = cms.double(0.4),
0246          values = cms.vstring('pt','emEnergyFraction'),
0247      valueLabels = cms.vstring('pt','emEnergyFraction'),
0248      lazyParser = cms.bool(True) )
0249     task.add(process.caloJetMap)
0250     process.patJets.userData.userFloats.src += [ 'caloJetMap:pt', 'caloJetMap:emEnergyFraction' ]
0251 
0252     pp_on_AA.toModify(process.patJets.userData.userInts, src = [] )
0253     pp_on_AA.toModify(process.patJets.userData.userFloats, src = [] )
0254 
0255     #Muon object modifications 
0256     from PhysicsTools.PatAlgos.slimming.muonIsolationsPUPPI_cfi import makeInputForPUPPIIsolationMuon
0257     makeInputForPUPPIIsolationMuon(process)
0258 
0259     #EGM object modifications 
0260     from PhysicsTools.PatAlgos.slimming.egmIsolationsPUPPI_cfi import makeInputForPUPPIIsolationEgm
0261     makeInputForPUPPIIsolationEgm(process)
0262     from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma_modifications
0263     process.slimmedElectrons.modifierConfig.modifications = egamma_modifications
0264     process.slimmedPhotons.modifierConfig.modifications   = egamma_modifications
0265 
0266     #VID Electron IDs
0267     process.patElectrons.addElectronID = cms.bool(True)
0268     electron_ids = ['RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
0269                     'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV71_cff',
0270                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V1_cff',
0271                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
0272                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Winter22_122X_V1_cff',
0273                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff', 
0274                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
0275                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff', 
0276                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
0277                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
0278                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
0279                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
0280             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer16UL_ID_ISO_cff',
0281                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer17UL_ID_ISO_cff',
0282                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer18UL_ID_ISO_cff',
0283                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_noIso_V1_cff',
0284                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_iso_V1_cff',
0285                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Winter22_HZZ_V1_cff'
0286                     ]
0287     switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD, task)
0288     process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0289     process.electronMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedGsfElectrons')
0290 
0291     # To use older DataFormats, the electronMVAValueMapProducer MUST take a updated electron collection
0292     # such that the conversion variables are filled correctly.
0293     process.load("RecoEgamma.EgammaTools.gedGsfElectronsTo106X_cff")
0294     run2_miniAOD_80XLegacy.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom80XTo106XTask))
0295     run2_miniAOD_80XLegacy.toModify(process.electronMVAValueMapProducer,
0296                                      keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0297                                      src = cms.InputTag("gedGsfElectronsFrom80XTo106X"))
0298 
0299     run2_miniAOD_94XFall17.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
0300     run2_miniAOD_94XFall17.toModify(process.electronMVAValueMapProducer,
0301                                      keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0302                                      src = cms.InputTag("gedGsfElectronsFrom94XTo106X"))
0303 
0304     from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018
0305     pp_on_AA_2018.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
0306     pp_on_AA_2018.toModify(process.electronMVAValueMapProducer,
0307                            keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0308                            src = "gedGsfElectronsFrom94XTo106X")
0309 
0310     for idmod in electron_ids:
0311         setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection,None,False,task)
0312 
0313     #VID Photon IDs
0314     process.patPhotons.addPhotonID = cms.bool(True)
0315     photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
0316                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
0317                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', 
0318                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
0319                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
0320                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
0321                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Winter22_122X_V1_cff',
0322                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_RunIIIWinter22_122X_V1_cff']
0323 
0324     switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task) 
0325     process.egmPhotonIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedPhotons")
0326     process.photonMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedPhotons')
0327     for idmod in photon_ids:
0328         setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False,task)
0329  
0330     #add the cut base IDs bitmaps of which cuts passed
0331     from RecoEgamma.EgammaTools.egammaObjectModifications_tools import makeVIDBitsModifier
0332     egamma_modifications.append(makeVIDBitsModifier(process,"egmGsfElectronIDs","egmPhotonIDs"))
0333 
0334     #-- Adding boosted taus
0335     from RecoTauTag.Configuration.boostedHPSPFTaus_cfi import addBoostedTaus
0336     addBoostedTaus(process)
0337     process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
0338     process.load("RecoTauTag.Configuration.HPSPFTaus_cff")
0339     #-- Adding customization for 94X 2017 legacy reMniAOD
0340     _makePatTausTaskWithRetrainedMVATauID = process.makePatTausTask.copy()
0341     _makePatTausTaskWithRetrainedMVATauID.add(process.hpsPFTauBasicDiscriminatorsTask,
0342                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTTask,
0343                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLTTask,
0344                                               process.hpsPFTauBasicDiscriminatorsdR03Task,
0345                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLTTask,
0346                                               process.hpsPFTauDiscriminationByMVA6rawElectronRejection,
0347                                               process.hpsPFTauDiscriminationByMVA6ElectronRejection,
0348                                               process.hpsPFTauDiscriminationByMuonRejection3)
0349     from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
0350     (run2_miniAOD_94XFall17 | run2_miniAOD_UL).toReplaceWith(
0351         process.makePatTausTask, _makePatTausTaskWithRetrainedMVATauID
0352         )
0353     #-- Adding DeepTauID
0354     # deepTau v2p1 and v2p5
0355     _updatedTauName = 'slimmedTausDeepIDsv2p1'
0356     _noUpdatedTauName = 'slimmedTausNoDeepIDs'
0357     import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
0358     tauIdEmbedder = tauIdConfig.TauIDEmbedder(
0359         process, debug = False,
0360         originalTauName = _noUpdatedTauName,
0361         updatedTauName = _updatedTauName,
0362         postfix = 'ForMini',
0363         toKeep = ['deepTau2017v2p1','deepTau2018v2p5']
0364     )
0365     from Configuration.Eras.Modifier_phase2_common_cff import phase2_common #Phase2 Tau MVA
0366     _tauIds_phase2 = ['deepTau2026v2p5']
0367     phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.extend(_tauIds_phase2))
0368     tauIdEmbedder.runTauID()
0369     addToProcessAndTask(_noUpdatedTauName, process.slimmedTaus.clone(),process,task)
0370     delattr(process, 'slimmedTaus')
0371     process.slimmedTaus = getattr(process, _updatedTauName).clone()
0372     process.rerunMvaIsolationTaskForMini.add(process.slimmedTaus)
0373     task.add(process.rerunMvaIsolationTaskForMini)
0374 
0375     #-- Rerun tauID against dead ECal towers to taus for the various re-MiniAOD eras
0376     # to enable default behoviour with leading track extrapolation to ECAL
0377     _makePatTausTaskWithDeadECalVeto = process.makePatTausTask.copy()
0378     _makePatTausTaskWithDeadECalVeto.add(
0379         process.hpsPFTauDiscriminationByDeadECALElectronRejection
0380     )
0381     _run2_miniAOD_ANY = (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17 | run2_miniAOD_UL)
0382     _run2_miniAOD_ANY.toReplaceWith(
0383         process.makePatTausTask, _makePatTausTaskWithDeadECalVeto
0384     )
0385 
0386     #-- Adding customization for 80X 2016 legacy reMiniAOD and 2018 heavy ions
0387     _makePatTausTaskWithTauReReco = process.makePatTausTask.copy()
0388     _makePatTausTaskWithTauReReco.add(process.PFTauTask)
0389     (run2_miniAOD_80XLegacy | pp_on_AA).toReplaceWith(
0390         process.makePatTausTask, _makePatTausTaskWithTauReReco
0391         )
0392     
0393     # Adding puppi jets
0394     process.load('CommonTools.PileupAlgos.Puppi_cff')
0395     process.load('RecoJets.JetProducers.ak4PFJets_cfi')
0396     from Configuration.Eras.Modifier_pA_2016_cff import pA_2016
0397     from Configuration.Eras.Modifier_run3_miniAOD_12X_cff import run3_miniAOD_12X
0398     _rerun_puppijets_task = task.copy()
0399     _rerun_puppijets_task.add(process.puppi, process.ak4PFJetsPuppi)
0400     (_run2_miniAOD_ANY | pA_2016 | pp_on_AA | run3_miniAOD_12X).toReplaceWith(task, _rerun_puppijets_task)
0401 
0402     from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
0403     process.ak4PFJetsPuppiTracksAssociatorAtVertex = cms.EDProducer("JetTracksAssociatorAtVertex",
0404         j2tParametersVX,
0405         jets = cms.InputTag("ak4PFJetsPuppi")
0406     )
0407     task.add(process.ak4PFJetsPuppiTracksAssociatorAtVertex)
0408     process.patJetPuppiCharge = cms.EDProducer("JetChargeProducer",
0409         src = cms.InputTag("ak4PFJetsPuppiTracksAssociatorAtVertex"),
0410         var = cms.string('Pt'),
0411         exp = cms.double(1.0)
0412     )
0413     task.add(process.patJetPuppiCharge)
0414 
0415     def _add_jetsPuppi(process):
0416         from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
0417         noDeepFlavourDiscriminators = [x.value() if isinstance(x, cms.InputTag) else x for x in process.patJets.discriminatorSources 
0418                                        if (not "DeepFlavour" in str(x) and not "Transformer" in str(x))]
0419         addJetCollection(process, postfix   = "", labelName = 'Puppi', jetSource = cms.InputTag('ak4PFJetsPuppi'),
0420                          jetCorrections = ('AK4PFPuppi', ['L2Relative', 'L3Absolute'], ''),
0421                          pfCandidates = cms.InputTag("particleFlow"),
0422                          algo= 'AK', rParam = 0.4, btagDiscriminators = noDeepFlavourDiscriminators
0423                      )
0424 
0425         process.patJetGenJetMatchPuppi.matched = 'slimmedGenJets'
0426     
0427         process.patJetsPuppi.jetChargeSource = cms.InputTag("patJetPuppiCharge")
0428     
0429         process.selectedPatJetsPuppi.cut = cms.string("pt > 10")
0430     
0431         from PhysicsTools.PatAlgos.slimming.applyDeepBtagging_cff import applyDeepBtagging
0432         applyDeepBtagging( process )
0433 
0434         process.slimmedJetsNoDeepFlavour.dropTagInfos = '0'
0435         process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.addTagInfos = True
0436         process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.tagInfoSources = ["pixelClusterTagInfos"]
0437         _run2_miniAOD_ANY.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = False )
0438     (~pp_on_AA).toModify(process, _add_jetsPuppi)
0439 
0440     pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJetsPuppi', _dummyPatJets.clone(), p, task))
0441 
0442     # Embed pixelClusterTagInfos in slimmedJets
0443     process.patJets.addTagInfos = True
0444     process.patJets.tagInfoSources = ["pixelClusterTagInfos"]
0445 
0446     _run2_miniAOD_ANY.toModify(process.patJets, addTagInfos = False )
0447 
0448     from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018
0449     pp_on_AA_2018.toModify(process.patJets, tagInfoSources = cms.VInputTag(["impactParameterTagInfos","secondaryVertexTagInfos"]) )
0450 
0451     ## puppi met
0452     def _add_metPuppi(process):
0453         process.load('RecoMET.METProducers.pfMetPuppi_cfi')
0454         _rerun_puppimet_task = task.copy()
0455         _rerun_puppimet_task.add(process.puppiNoLep, process.pfMetPuppi)
0456         (_run2_miniAOD_ANY | pA_2016 | pp_on_AA | run3_miniAOD_12X).toReplaceWith(task, _rerun_puppimet_task)
0457     
0458         runMetCorAndUncForMiniAODProduction(process, metType="Puppi",
0459                                             jetCollUnskimmed="slimmedJetsPuppi",
0460                                             recoMetFromPFCs=True,
0461                                             jetFlavor="AK4PFPuppi",
0462                                             postfix="Puppi"
0463                                         )
0464     (~pp_on_AA).toModify(process, _add_metPuppi)
0465 
0466     process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
0467     task.add(process.slimmedMETs)
0468 
0469     def _add_slimmedMETsPuppi(process):
0470         addToProcessAndTask('slimmedMETsPuppi', process.slimmedMETs.clone(), process, task)
0471         process.slimmedMETsPuppi.src = cms.InputTag("patMETsPuppi")
0472         process.slimmedMETsPuppi.rawVariation =  cms.InputTag("patPFMetPuppi")
0473         process.slimmedMETsPuppi.t1Uncertainties = cms.InputTag("patPFMetT1%sPuppi")
0474         process.slimmedMETsPuppi.t01Variation = cms.InputTag("patPFMetT0pcT1Puppi")
0475         process.slimmedMETsPuppi.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sPuppi")
0476         process.slimmedMETsPuppi.tXYUncForRaw = cms.InputTag("patPFMetTxyPuppi")
0477         process.slimmedMETsPuppi.tXYUncForT1 = cms.InputTag("patPFMetT1TxyPuppi")
0478         process.slimmedMETsPuppi.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyPuppi")
0479         process.slimmedMETsPuppi.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyPuppi")
0480         process.slimmedMETsPuppi.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyPuppi")
0481         del process.slimmedMETsPuppi.caloMET
0482     (~pp_on_AA).toModify(process, _add_slimmedMETsPuppi)
0483 
0484     def _add_deepMET(process):
0485         from RecoMET.METPUSubtraction.deepMETProducer_cff import deepMETsResolutionTune, deepMETsResponseTune
0486 
0487         addToProcessAndTask('deepMETsResolutionTune', deepMETsResolutionTune, process, task)
0488         addToProcessAndTask('deepMETsResponseTune', deepMETsResponseTune, process, task)
0489     (~pp_on_AA).toModify(process, _add_deepMET)
0490 
0491     # add DetIdAssociatorRecords to EventSetup (for isolatedTracks)
0492     process.load("TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff")
0493 
0494     # EGamma objects from HGCal are not yet in GED
0495     # so add companion collections for Phase-II MiniAOD production
0496     from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal
0497     process.load("RecoEgamma.EgammaTools.slimmedEgammaHGC_cff")
0498     phase2_hgcal.toModify(task, func=lambda t: t.add(process.slimmedEgammaHGCTask))
0499 
0500     # L1 pre-firing weights for 2016, 2017, and 2018
0501     from Configuration.Eras.Modifier_run2_L1prefiring_cff import run2_L1prefiring
0502     from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
0503     from Configuration.Eras.Modifier_stage2L1Trigger_2017_cff import stage2L1Trigger_2017
0504     from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018
0505     from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016
0506     if not hasattr(process,'prefiringweight'):
0507         process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff")
0508     (stage2L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016preVFP", DataEraMuon = "2016preVFP" )
0509     (stage2L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016postVFP", DataEraMuon = "2016postVFP" )
0510     stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "UL2017BtoF", DataEraMuon = "20172018")
0511     stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018")
0512     run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight))
0513 
0514     from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeL1FastJetJECs
0515     pp_on_AA.toModify(process, removeL1FastJetJECs)
0516 
0517 def miniAOD_customizeMC(process):
0518     task = getPatAlgosToolsTask(process)
0519     #GenJetFlavourInfos
0520     process.load("PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi")
0521     task.add(process.selectedHadronsAndPartons)
0522     task.add(process.selectedHadronsAndPartonsForGenJetsFlavourInfos)
0523     
0524     process.load("PhysicsTools.JetMCAlgos.AK4GenJetFlavourInfos_cfi")
0525     task.add(process.ak4GenJetFlavourInfos)
0526 
0527     process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJetsFlavourInfos_cfi')
0528     task.add(process.slimmedGenJetsFlavourInfos)
0529 
0530     #slimmed pileup information
0531     process.load('PhysicsTools.PatAlgos.slimming.slimmedAddPileupInfo_cfi')
0532     task.add(process.slimmedAddPileupInfo)
0533 
0534     process.muonMatch.matched = "prunedGenParticles"
0535     process.electronMatch.matched = "prunedGenParticles"
0536     process.electronMatch.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0537     process.photonMatch.matched = "prunedGenParticles"
0538     process.photonMatch.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0539     process.ootPhotonMatch.matched = "prunedGenParticles"
0540     process.ootPhotonMatch.src = cms.InputTag("reducedEgamma","reducedOOTPhotons")
0541     process.tauMatch.matched = "prunedGenParticles"
0542     process.tauGenJets.GenParticles = "prunedGenParticles"
0543     #Boosted taus 
0544     process.tauMatchBoosted.matched = "prunedGenParticles"
0545     process.tauGenJetsBoosted.GenParticles = "prunedGenParticles"
0546     process.patJetPartons.particles = "genParticles"
0547     process.patJetPartonMatch.matched = "prunedGenParticles"
0548     pp_on_AA.toModify(process.patJetPartonMatch, matched =  "hiSignalGenParticles")
0549     from Configuration.ProcessModifiers.genJetSubEvent_cff import genJetSubEvent
0550     genJetSubEvent.toModify(process.patJetPartonMatch, matched =  "cleanedPartons")
0551     process.patJetPartonMatch.mcStatus = [ 3, 23 ]
0552     process.patJetGenJetMatch.matched = "slimmedGenJets"
0553     (~pp_on_AA).toModify(process, patJetGenJetMatchAK8Puppi = dict(matched =  "slimmedGenJetsAK8"))
0554     process.patMuons.embedGenMatch = False
0555     process.patElectrons.embedGenMatch = False
0556     process.patPhotons.embedGenMatch = False
0557     process.patOOTPhotons.embedGenMatch = False
0558     process.patTaus.embedGenMatch = False
0559     process.patTausBoosted.embedGenMatch = False
0560     process.patJets.embedGenPartonMatch = False
0561     #also jet flavour must be switched
0562     process.patJetFlavourAssociation.rParam = 0.4
0563     
0564     from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeJECsForMC
0565     pp_on_AA.toModify(process, removeJECsForMC)
0566     pp_on_AA.toReplaceWith(task,task.copyAndExclude([process.slimmedGenJetsFlavourInfos]))
0567 
0568 
0569 def miniAOD_customizeOutput(out):
0570     from PhysicsTools.PatAlgos.slimming.MicroEventContent_cff import MiniAODOverrideBranchesSplitLevel
0571     out.overrideBranchesSplitLevel = MiniAODOverrideBranchesSplitLevel
0572     out.splitLevel = cms.untracked.int32(0)
0573     out.dropMetaData = cms.untracked.string('ALL')
0574     out.fastCloning= cms.untracked.bool(False)
0575     out.overrideInputFileSplitLevels = cms.untracked.bool(True)
0576     out.compressionAlgorithm = cms.untracked.string('LZMA')
0577 
0578 def miniAOD_customizeData(process):
0579     from PhysicsTools.PatAlgos.tools.coreTools import runOnData
0580     runOnData( process, outputModules = [] )
0581     process.load("RecoPPS.Local.ctppsLocalTrackLiteProducer_cff")
0582     process.load("RecoPPS.ProtonReconstruction.ctppsProtons_cff")
0583     process.load("Geometry.VeryForwardGeometry.geometryRPFromDB_cfi")
0584     process.load('L1Trigger.L1TGlobal.simGtExtFakeProd_cfi')
0585     task = getPatAlgosToolsTask(process)
0586     task.add(process.simGtExtUnprefireable)
0587     from Configuration.Eras.Modifier_ctpps_cff import ctpps
0588     ctpps.toModify(task, func=lambda t: t.add(process.ctppsLocalTrackLiteProducer))
0589     ctpps.toModify(task, func=lambda t: t.add(process.ctppsProtons))
0590     from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
0591     run2_miniAOD_UL.toModify(task, func=lambda t: t.add(process.simGtExtUnprefireable))
0592 
0593 def miniAOD_customizeAllData(process):
0594     miniAOD_customizeCommon(process)
0595     miniAOD_customizeData(process)
0596     return process
0597 
0598 def miniAOD_customizeAllMC(process):
0599     miniAOD_customizeCommon(process)
0600     miniAOD_customizeMC(process)
0601     return process
0602 
0603 def miniAOD_customizeAllMCFastSim(process):
0604     miniAOD_customizeCommon(process)
0605     miniAOD_customizeMC(process)
0606     from PhysicsTools.PatAlgos.slimming.metFilterPaths_cff import miniAOD_customizeMETFiltersFastSim
0607     process = miniAOD_customizeMETFiltersFastSim(process)
0608     from PhysicsTools.PatAlgos.slimming.isolatedTracks_cfi import miniAOD_customizeIsolatedTracksFastSim
0609     process = miniAOD_customizeIsolatedTracksFastSim(process)
0610     process.patMuons.addTriggerMatching = False
0611     # Disable pixelClusterTagInfos in FastSim (no siPixelCluster available)
0612     from Configuration.Eras.Modifier_fastSim_cff import fastSim
0613     fastSim.toModify(process.patJets, addTagInfos = cms.bool(False) )
0614     fastSim.toModify(process.slimmedJetsNoDeepFlavour, dropTagInfos = cms.string('1') )
0615     fastSim.toModify(process.updatedPatJetsSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
0616     fastSim.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
0617 
0618     return process