Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-18 03:27:26

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     (~pp_on_AA).toModify(process, _add_deepFlavour)
0265 
0266     ## CaloJets
0267     process.caloJetMap = cms.EDProducer("RecoJetDeltaRValueMapProducer",
0268          src = process.patJets.jetSource,
0269          matched = cms.InputTag("ak4CaloJets"),
0270          distMax = cms.double(0.4),
0271          values = cms.vstring('pt','emEnergyFraction'),
0272      valueLabels = cms.vstring('pt','emEnergyFraction'),
0273      lazyParser = cms.bool(True) )
0274     task.add(process.caloJetMap)
0275     process.patJets.userData.userFloats.src += [ 'caloJetMap:pt', 'caloJetMap:emEnergyFraction' ]
0276 
0277     pp_on_AA.toModify(process.patJets.userData.userInts, src = [] )
0278     pp_on_AA.toModify(process.patJets.userData.userFloats, src = [] )
0279 
0280     #Muon object modifications 
0281     from PhysicsTools.PatAlgos.slimming.muonIsolationsPUPPI_cfi import makeInputForPUPPIIsolationMuon
0282     makeInputForPUPPIIsolationMuon(process)
0283 
0284     #EGM object modifications 
0285     from PhysicsTools.PatAlgos.slimming.egmIsolationsPUPPI_cfi import makeInputForPUPPIIsolationEgm
0286     makeInputForPUPPIIsolationEgm(process)
0287     from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma_modifications
0288     process.slimmedElectrons.modifierConfig.modifications = egamma_modifications
0289     process.slimmedPhotons.modifierConfig.modifications   = egamma_modifications
0290 
0291     #VID Electron IDs
0292     process.patElectrons.addElectronID = cms.bool(True)
0293     electron_ids = ['RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
0294                     'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV71_cff',
0295                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V1_cff',
0296                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
0297                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff', 
0298                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
0299                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff', 
0300                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
0301                     'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
0302                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
0303                     'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
0304                     ]
0305     switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD, task)
0306     process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0307     process.electronMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedGsfElectrons')
0308 
0309     # To use older DataFormats, the electronMVAValueMapProducer MUST take a updated electron collection
0310     # such that the conversion variables are filled correctly.
0311     process.load("RecoEgamma.EgammaTools.gedGsfElectronsTo106X_cff")
0312     run2_miniAOD_80XLegacy.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom80XTo106XTask))
0313     run2_miniAOD_80XLegacy.toModify(process.electronMVAValueMapProducer,
0314                                      keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0315                                      src = cms.InputTag("gedGsfElectronsFrom80XTo106X"))
0316 
0317     run2_miniAOD_94XFall17.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
0318     run2_miniAOD_94XFall17.toModify(process.electronMVAValueMapProducer,
0319                                      keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0320                                      src = cms.InputTag("gedGsfElectronsFrom94XTo106X"))
0321 
0322     from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
0323     pp_on_AA.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
0324     pp_on_AA.toModify(process.electronMVAValueMapProducer,
0325                                      keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
0326                                      src = "gedGsfElectronsFrom94XTo106X")
0327 
0328     for idmod in electron_ids:
0329         setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection,None,False,task)
0330 
0331     #VID Photon IDs
0332     process.patPhotons.addPhotonID = cms.bool(True)
0333     photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
0334                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
0335                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', 
0336                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
0337                   'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
0338                   'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff']
0339     switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task) 
0340     process.egmPhotonIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedPhotons")
0341     process.photonMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedPhotons')
0342     for idmod in photon_ids:
0343         setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False,task)
0344  
0345     #add the cut base IDs bitmaps of which cuts passed
0346     from RecoEgamma.EgammaTools.egammaObjectModifications_tools import makeVIDBitsModifier
0347     egamma_modifications.append(makeVIDBitsModifier(process,"egmGsfElectronIDs","egmPhotonIDs"))
0348 
0349     #-- Adding boosted taus
0350     from RecoTauTag.Configuration.boostedHPSPFTaus_cfi import addBoostedTaus
0351     addBoostedTaus(process)
0352     process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
0353     process.load("RecoTauTag.Configuration.HPSPFTaus_cff")
0354     #-- Adding customization for 94X 2017 legacy reMniAOD
0355     _makePatTausTaskWithRetrainedMVATauID = process.makePatTausTask.copy()
0356     _makePatTausTaskWithRetrainedMVATauID.add(process.hpsPFTauBasicDiscriminatorsTask,
0357                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTTask,
0358                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLTTask,
0359                                               process.hpsPFTauBasicDiscriminatorsdR03Task,
0360                                               process.hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLTTask,
0361                                               process.hpsPFTauDiscriminationByMVA6rawElectronRejection,
0362                                               process.hpsPFTauDiscriminationByMVA6ElectronRejection,
0363                                               process.hpsPFTauDiscriminationByMuonRejection3)
0364     from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
0365     (run2_miniAOD_94XFall17 | run2_miniAOD_UL).toReplaceWith(
0366         process.makePatTausTask, _makePatTausTaskWithRetrainedMVATauID
0367         )
0368     #-- Adding DeepTauID
0369     # deepTau v2p1 and v2p5
0370     _updatedTauName = 'slimmedTausDeepIDsv2p1'
0371     _noUpdatedTauName = 'slimmedTausNoDeepIDs'
0372     import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
0373     tauIdEmbedder = tauIdConfig.TauIDEmbedder(
0374         process, debug = False,
0375         originalTauName = _noUpdatedTauName,
0376         updatedTauName = _updatedTauName,
0377         toKeep = ['deepTau2017v2p1','deepTau2018v2p5']
0378     )
0379     from Configuration.Eras.Modifier_phase2_common_cff import phase2_common #Phase2 Tau MVA
0380     phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('newDMPhase2v1')) #Phase2 Tau isolation MVA
0381     phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('againstElePhase2v1')) #Phase2 Tau anti-e MVA
0382     tauIdEmbedder.runTauID()
0383     addToProcessAndTask(_noUpdatedTauName, process.slimmedTaus.clone(),process,task)
0384     delattr(process, 'slimmedTaus')
0385     process.slimmedTaus = getattr(process, _updatedTauName).clone()
0386     process.rerunMvaIsolationTask.add(process.slimmedTaus)
0387     task.add(process.rerunMvaIsolationTask)
0388 
0389     #-- Rerun tauID against dead ECal towers to taus for the various re-MiniAOD eras
0390     # to enable default behoviour with leading track extrapolation to ECAL
0391     _makePatTausTaskWithDeadECalVeto = process.makePatTausTask.copy()
0392     _makePatTausTaskWithDeadECalVeto.add(
0393         process.hpsPFTauDiscriminationByDeadECALElectronRejection
0394     )
0395     _run2_miniAOD_ANY = (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17 | run2_miniAOD_UL)
0396     _run2_miniAOD_ANY.toReplaceWith(
0397         process.makePatTausTask, _makePatTausTaskWithDeadECalVeto
0398     )
0399 
0400     #-- Adding customization for 80X 2016 legacy reMiniAOD and 2018 heavy ions
0401     _makePatTausTaskWithTauReReco = process.makePatTausTask.copy()
0402     _makePatTausTaskWithTauReReco.add(process.PFTauTask)
0403     (run2_miniAOD_80XLegacy | pp_on_AA).toReplaceWith(
0404         process.makePatTausTask, _makePatTausTaskWithTauReReco
0405         )
0406     
0407     # Adding puppi jets
0408     process.load('CommonTools.PileupAlgos.Puppi_cff')
0409     process.load('RecoJets.JetProducers.ak4PFJets_cfi')
0410     from Configuration.Eras.Modifier_pA_2016_cff import pA_2016
0411     _rerun_puppijets_task = task.copy()
0412     _rerun_puppijets_task.add(process.puppi, process.ak4PFJetsPuppi)
0413     (_run2_miniAOD_ANY | pA_2016 | pp_on_AA).toReplaceWith(task, _rerun_puppijets_task)
0414 
0415     from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
0416     process.ak4PFJetsPuppiTracksAssociatorAtVertex = cms.EDProducer("JetTracksAssociatorAtVertex",
0417         j2tParametersVX,
0418         jets = cms.InputTag("ak4PFJetsPuppi")
0419     )
0420     task.add(process.ak4PFJetsPuppiTracksAssociatorAtVertex)
0421     process.patJetPuppiCharge = cms.EDProducer("JetChargeProducer",
0422         src = cms.InputTag("ak4PFJetsPuppiTracksAssociatorAtVertex"),
0423         var = cms.string('Pt'),
0424         exp = cms.double(1.0)
0425     )
0426     task.add(process.patJetPuppiCharge)
0427 
0428     def _add_jetsPuppi(process):
0429         from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
0430         noDeepFlavourDiscriminators = [x.value() if isinstance(x, cms.InputTag) else x for x in process.patJets.discriminatorSources 
0431                                        if not "DeepFlavour" in str(x)]
0432         addJetCollection(process, postfix   = "", labelName = 'Puppi', jetSource = cms.InputTag('ak4PFJetsPuppi'),
0433                          jetCorrections = ('AK4PFPuppi', ['L2Relative', 'L3Absolute'], ''),
0434                          pfCandidates = cms.InputTag("particleFlow"),
0435                          algo= 'AK', rParam = 0.4, btagDiscriminators = noDeepFlavourDiscriminators
0436                      )
0437 
0438         process.patJetGenJetMatchPuppi.matched = 'slimmedGenJets'
0439     
0440         process.patJetsPuppi.jetChargeSource = cms.InputTag("patJetPuppiCharge")
0441     
0442         process.selectedPatJetsPuppi.cut = cms.string("pt > 10")
0443     
0444         from PhysicsTools.PatAlgos.slimming.applyDeepBtagging_cff import applyDeepBtagging
0445         applyDeepBtagging( process )
0446 
0447         process.slimmedJetsNoDeepFlavour.dropTagInfos = '0'
0448         process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.addTagInfos = True
0449         process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.tagInfoSources = ["pixelClusterTagInfos"]
0450         _run2_miniAOD_ANY.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = False )
0451     (~pp_on_AA).toModify(process, _add_jetsPuppi)
0452 
0453     pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJetsPuppi', _dummyPatJets.clone(), p, task))
0454 
0455     # Embed pixelClusterTagInfos in slimmedJets
0456     process.patJets.addTagInfos = True
0457     process.patJets.tagInfoSources = ["pixelClusterTagInfos"]
0458 
0459     _run2_miniAOD_ANY.toModify(process.patJets, addTagInfos = False )
0460     
0461     pp_on_AA.toModify(process.patJets, tagInfoSources = cms.VInputTag(["impactParameterTagInfos","secondaryVertexTagInfos"]) )
0462 
0463     ## puppi met
0464     def _add_metPuppi(process):
0465         process.load('RecoMET.METProducers.pfMetPuppi_cfi')
0466         _rerun_puppimet_task = task.copy()
0467         _rerun_puppimet_task.add(process.puppiNoLep, process.pfMetPuppi)
0468         (_run2_miniAOD_ANY | pA_2016 | pp_on_AA).toReplaceWith(task, _rerun_puppimet_task)
0469     
0470         runMetCorAndUncForMiniAODProduction(process, metType="Puppi",
0471                                             jetCollUnskimmed="slimmedJetsPuppi",
0472                                             recoMetFromPFCs=True,
0473                                             jetFlavor="AK4PFPuppi",
0474                                             postfix="Puppi"
0475                                         )
0476     (~pp_on_AA).toModify(process, _add_metPuppi)
0477 
0478     process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
0479     task.add(process.slimmedMETs)
0480 
0481     def _add_slimmedMETsPuppi(process):
0482         addToProcessAndTask('slimmedMETsPuppi', process.slimmedMETs.clone(), process, task)
0483         process.slimmedMETsPuppi.src = cms.InputTag("patMETsPuppi")
0484         process.slimmedMETsPuppi.rawVariation =  cms.InputTag("patPFMetPuppi")
0485         process.slimmedMETsPuppi.t1Uncertainties = cms.InputTag("patPFMetT1%sPuppi")
0486         process.slimmedMETsPuppi.t01Variation = cms.InputTag("patPFMetT0pcT1Puppi")
0487         process.slimmedMETsPuppi.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sPuppi")
0488         process.slimmedMETsPuppi.tXYUncForRaw = cms.InputTag("patPFMetTxyPuppi")
0489         process.slimmedMETsPuppi.tXYUncForT1 = cms.InputTag("patPFMetT1TxyPuppi")
0490         process.slimmedMETsPuppi.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyPuppi")
0491         process.slimmedMETsPuppi.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyPuppi")
0492         process.slimmedMETsPuppi.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyPuppi")
0493         del process.slimmedMETsPuppi.caloMET
0494     (~pp_on_AA).toModify(process, _add_slimmedMETsPuppi)
0495 
0496     def _add_deepMET(process):
0497         process.load('RecoMET.METPUSubtraction.deepMETProducer_cfi')
0498 
0499         addToProcessAndTask('deepMETsResolutionTune', process.deepMETProducer.clone(), process, task)
0500         addToProcessAndTask('deepMETsResponseTune', process.deepMETProducer.clone(), process, task)
0501         process.deepMETsResponseTune.graph_path = 'RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2018.pb'
0502 
0503         from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
0504         phase2_common.toModify(
0505             process.deepMETsResolutionTune,
0506             max_n_pf=12500,
0507             graph_path="RecoMET/METPUSubtraction/data/deepmet/deepmet_v1_phase2.pb"
0508         )
0509         phase2_common.toModify(
0510             process.deepMETsResponseTune,
0511             max_n_pf=12500,
0512             graph_path="RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_phase2.pb"
0513         )
0514         
0515         from Configuration.Eras.Modifier_run2_jme_2016_cff import run2_jme_2016
0516         run2_jme_2016.toModify(
0517             process.deepMETsResponseTune,
0518             graph_path="RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2016.pb"
0519         )
0520     (~pp_on_AA).toModify(process, _add_deepMET)
0521 
0522     # add DetIdAssociatorRecords to EventSetup (for isolatedTracks)
0523     process.load("TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff")
0524 
0525     # EGamma objects from HGCal are not yet in GED
0526     # so add companion collections for Phase-II MiniAOD production
0527     from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal
0528     process.load("RecoEgamma.EgammaTools.slimmedEgammaHGC_cff")
0529     phase2_hgcal.toModify(task, func=lambda t: t.add(process.slimmedEgammaHGCTask))
0530 
0531     # L1 pre-firing weights for 2016, 2017, and 2018
0532     from Configuration.Eras.Modifier_run2_L1prefiring_cff import run2_L1prefiring
0533     from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
0534     from Configuration.Eras.Modifier_stage2L1Trigger_2017_cff import stage2L1Trigger_2017
0535     from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018
0536     from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016
0537     process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff")
0538     (stage2L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016preVFP", DataEraMuon = "2016preVFP" )
0539     (stage2L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016postVFP", DataEraMuon = "2016postVFP" )
0540     stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "UL2017BtoF", DataEraMuon = "20172018")
0541     stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018")
0542     run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight))
0543 
0544     from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeL1FastJetJECs
0545     pp_on_AA.toModify(process, removeL1FastJetJECs)
0546 
0547 def miniAOD_customizeMC(process):
0548     task = getPatAlgosToolsTask(process)
0549     #GenJetFlavourInfos
0550     process.load("PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi")
0551     task.add(process.selectedHadronsAndPartons)
0552     task.add(process.selectedHadronsAndPartonsForGenJetsFlavourInfos)
0553     
0554     process.load("PhysicsTools.JetMCAlgos.AK4GenJetFlavourInfos_cfi")
0555     task.add(process.ak4GenJetFlavourInfos)
0556 
0557     process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJetsFlavourInfos_cfi')
0558     task.add(process.slimmedGenJetsFlavourInfos)
0559 
0560     #slimmed pileup information
0561     process.load('PhysicsTools.PatAlgos.slimming.slimmedAddPileupInfo_cfi')
0562     task.add(process.slimmedAddPileupInfo)
0563 
0564     process.muonMatch.matched = "prunedGenParticles"
0565     process.electronMatch.matched = "prunedGenParticles"
0566     process.electronMatch.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0567     process.photonMatch.matched = "prunedGenParticles"
0568     process.photonMatch.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0569     process.ootPhotonMatch.matched = "prunedGenParticles"
0570     process.ootPhotonMatch.src = cms.InputTag("reducedEgamma","reducedOOTPhotons")
0571     process.tauMatch.matched = "prunedGenParticles"
0572     process.tauGenJets.GenParticles = "prunedGenParticles"
0573     #Boosted taus 
0574     process.tauMatchBoosted.matched = "prunedGenParticles"
0575     process.tauGenJetsBoosted.GenParticles = "prunedGenParticles"
0576     process.patJetPartons.particles = "genParticles"
0577     process.patJetPartonMatch.matched = "prunedGenParticles"
0578     pp_on_AA.toModify(process.patJetPartonMatch, matched =  "hiSignalGenParticles")
0579     from Configuration.ProcessModifiers.genJetSubEvent_cff import genJetSubEvent
0580     genJetSubEvent.toModify(process.patJetPartonMatch, matched =  "cleanedPartons")
0581     process.patJetPartonMatch.mcStatus = [ 3, 23 ]
0582     process.patJetGenJetMatch.matched = "slimmedGenJets"
0583     (~pp_on_AA).toModify(process, patJetGenJetMatchAK8Puppi = dict(matched =  "slimmedGenJetsAK8"))
0584     process.patMuons.embedGenMatch = False
0585     process.patElectrons.embedGenMatch = False
0586     process.patPhotons.embedGenMatch = False
0587     process.patOOTPhotons.embedGenMatch = False
0588     process.patTaus.embedGenMatch = False
0589     process.patTausBoosted.embedGenMatch = False
0590     process.patJets.embedGenPartonMatch = False
0591     #also jet flavour must be switched
0592     process.patJetFlavourAssociation.rParam = 0.4
0593     
0594     from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeJECsForMC
0595     pp_on_AA.toModify(process, removeJECsForMC)
0596     pp_on_AA.toReplaceWith(task,task.copyAndExclude([process.slimmedGenJetsFlavourInfos]))
0597 
0598 
0599 def miniAOD_customizeOutput(out):
0600     from PhysicsTools.PatAlgos.slimming.MicroEventContent_cff import MiniAODOverrideBranchesSplitLevel
0601     out.overrideBranchesSplitLevel = MiniAODOverrideBranchesSplitLevel
0602     out.splitLevel = cms.untracked.int32(0)
0603     out.dropMetaData = cms.untracked.string('ALL')
0604     out.fastCloning= cms.untracked.bool(False)
0605     out.overrideInputFileSplitLevels = cms.untracked.bool(True)
0606     out.compressionAlgorithm = cms.untracked.string('LZMA')
0607 
0608 def miniAOD_customizeData(process):
0609     from PhysicsTools.PatAlgos.tools.coreTools import runOnData
0610     runOnData( process, outputModules = [] )
0611     process.load("RecoPPS.Local.ctppsLocalTrackLiteProducer_cff")
0612     process.load("RecoPPS.ProtonReconstruction.ctppsProtons_cff")
0613     process.load("Geometry.VeryForwardGeometry.geometryRPFromDB_cfi")
0614     process.load('L1Trigger.L1TGlobal.simGtExtFakeProd_cfi')
0615     task = getPatAlgosToolsTask(process)
0616     from Configuration.Eras.Modifier_ctpps_cff import ctpps
0617     ctpps.toModify(task, func=lambda t: t.add(process.ctppsLocalTrackLiteProducer))
0618     ctpps.toModify(task, func=lambda t: t.add(process.ctppsProtons))
0619     from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
0620     run2_miniAOD_UL.toModify(task, func=lambda t: t.add(process.simGtExtUnprefireable))
0621 
0622 def miniAOD_customizeAllData(process):
0623     miniAOD_customizeCommon(process)
0624     miniAOD_customizeData(process)
0625     return process
0626 
0627 def miniAOD_customizeAllMC(process):
0628     miniAOD_customizeCommon(process)
0629     miniAOD_customizeMC(process)
0630     return process
0631 
0632 def miniAOD_customizeAllMCFastSim(process):
0633     miniAOD_customizeCommon(process)
0634     miniAOD_customizeMC(process)
0635     from PhysicsTools.PatAlgos.slimming.metFilterPaths_cff import miniAOD_customizeMETFiltersFastSim
0636     process = miniAOD_customizeMETFiltersFastSim(process)
0637     from PhysicsTools.PatAlgos.slimming.isolatedTracks_cfi import miniAOD_customizeIsolatedTracksFastSim
0638     process = miniAOD_customizeIsolatedTracksFastSim(process)
0639     process.patMuons.addTriggerMatching = False
0640     # Disable pixelClusterTagInfos in FastSim (no siPixelCluster available)
0641     from Configuration.Eras.Modifier_fastSim_cff import fastSim
0642     fastSim.toModify(process.patJets, addTagInfos = cms.bool(False) )
0643     fastSim.toModify(process.slimmedJetsNoDeepFlavour, dropTagInfos = cms.string('1') )
0644     fastSim.toModify(process.updatedPatJetsSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
0645     fastSim.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
0646 
0647     return process