CMS 3D CMS Logo

miniAOD_tools.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
4 
5 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
6 
7 from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
8 
10 
12  process.patMuons.isoDeposits = cms.PSet()
13  process.patElectrons.isoDeposits = cms.PSet()
14  process.patTaus.isoDeposits = cms.PSet()
15  process.patPhotons.isoDeposits = cms.PSet()
16  #
17  process.patMuons.embedTrack = True # used for IDs
18  process.patMuons.embedCombinedMuon = True # used for IDs
19  process.patMuons.embedMuonBestTrack = True # used for IDs
20  process.patMuons.embedStandAloneMuon = True # maybe?
21  process.patMuons.embedPickyMuon = False # no, use best track
22  process.patMuons.embedTpfmsMuon = False # no, use best track
23  process.patMuons.embedDytMuon = False # no, use best track
24  process.patMuons.addPuppiIsolation = cms.bool(True)
25  process.patMuons.puppiIsolationChargedHadrons = cms.InputTag("muonPUPPIIsolation","h+-DR040-ThresholdVeto000-ConeVeto000")
26  process.patMuons.puppiIsolationNeutralHadrons = cms.InputTag("muonPUPPIIsolation","h0-DR040-ThresholdVeto000-ConeVeto001")
27  process.patMuons.puppiIsolationPhotons = cms.InputTag("muonPUPPIIsolation","gamma-DR040-ThresholdVeto000-ConeVeto001")
28  process.patMuons.puppiNoLeptonsIsolationChargedHadrons = cms.InputTag("muonPUPPINoLeptonsIsolation","h+-DR040-ThresholdVeto000-ConeVeto000")
29  process.patMuons.puppiNoLeptonsIsolationNeutralHadrons = cms.InputTag("muonPUPPINoLeptonsIsolation","h0-DR040-ThresholdVeto000-ConeVeto001")
30  process.patMuons.puppiNoLeptonsIsolationPhotons = cms.InputTag("muonPUPPINoLeptonsIsolation","gamma-DR040-ThresholdVeto000-ConeVeto001")
31 
32  process.patMuons.computeMiniIso = True
33  process.patMuons.computeMuonMVA = True
34  process.patMuons.computeMuonIDMVA = True
35  process.patMuons.computeSoftMuonMVA = True
36 
37  process.patMuons.addTriggerMatching = True
38  from Configuration.Eras.Modifier_run2_muon_2016_cff import run2_muon_2016
39  from Configuration.Eras.Modifier_run2_muon_2017_cff import run2_muon_2017
40  from Configuration.Eras.Modifier_run2_muon_2018_cff import run2_muon_2018
41  run2_muon_2016.toModify( process.patMuons, effectiveAreaVec = [0.0735,0.0619,0.0465,0.0433,0.0577])
42  run2_muon_2017.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
43  run2_muon_2018.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
44  run2_muon_2016.toModify( process.patMuons, mvaTrainingFile = "RecoMuon/MuonIdentification/data/mu_2016_BDTG.weights.xml")
45 
46  process.patMuons.computePuppiCombinedIso = True
47  #
48  # disable embedding of electron and photon associated objects already stored by the ReducedEGProducer
49  process.patElectrons.embedGsfElectronCore = False
50  process.patElectrons.embedSuperCluster = False
51  process.patElectrons.embedPflowSuperCluster = False
52  process.patElectrons.embedSeedCluster = False
53  process.patElectrons.embedBasicClusters = False
54  process.patElectrons.embedPreshowerClusters = False
55  process.patElectrons.embedPflowBasicClusters = False
56  process.patElectrons.embedPflowPreshowerClusters = False
57  process.patElectrons.embedRecHits = False
58  process.patElectrons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
59  process.patElectrons.usePfCandidateMultiMap = True
60  process.patElectrons.pfCandidateMultiMap = cms.InputTag("reducedEgamma","reducedGsfElectronPfCandMap")
61  process.patElectrons.electronIDSources = cms.PSet()
62 
63  from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
64  from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17
65  (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17).toModify(process.patElectrons,
66  addPFClusterIso = True,
67  ecalPFClusterIsoMap = "reducedEgamma:eleEcalPFClusIso",
68  hcalPFClusterIsoMap = "reducedEgamma:eleHcalPFClusIso")
69 
70  #add puppi isolation in miniAOD
71  process.patElectrons.addPuppiIsolation = cms.bool(True)
72  process.patElectrons.puppiIsolationChargedHadrons = cms.InputTag("egmElectronPUPPIIsolation","h+-DR030-BarVeto000-EndVeto001")
73  process.patElectrons.puppiIsolationNeutralHadrons = cms.InputTag("egmElectronPUPPIIsolation","h0-DR030-BarVeto000-EndVeto000")
74  process.patElectrons.puppiIsolationPhotons = cms.InputTag("egmElectronPUPPIIsolation","gamma-DR030-BarVeto000-EndVeto008")
75  process.patElectrons.puppiNoLeptonsIsolationChargedHadrons = cms.InputTag("egmElectronPUPPINoLeptonsIsolation","h+-DR030-BarVeto000-EndVeto001")
76  process.patElectrons.puppiNoLeptonsIsolationNeutralHadrons = cms.InputTag("egmElectronPUPPINoLeptonsIsolation","h0-DR030-BarVeto000-EndVeto000")
77  process.patElectrons.puppiNoLeptonsIsolationPhotons = cms.InputTag("egmElectronPUPPINoLeptonsIsolation","gamma-DR030-BarVeto000-EndVeto008")
78 
79  process.patElectrons.computeMiniIso = cms.bool(True)
80 
81  process.elPFIsoDepositChargedPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
82  process.elPFIsoDepositChargedAllPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
83  process.elPFIsoDepositNeutralPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
84  process.elPFIsoDepositGammaPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
85  process.elPFIsoDepositPUPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
86  #
87  process.patPhotons.embedSuperCluster = False
88  process.patPhotons.embedSeedCluster = False
89  process.patPhotons.embedBasicClusters = False
90  process.patPhotons.embedPreshowerClusters = False
91  process.patPhotons.embedRecHits = False
92 
93  #add puppi isolation in miniAOD
94  process.patPhotons.addPuppiIsolation = cms.bool(True)
95  process.patPhotons.puppiIsolationChargedHadrons = cms.InputTag("egmPhotonPUPPIIsolation","h+-DR030-")
96  process.patPhotons.puppiIsolationNeutralHadrons = cms.InputTag("egmPhotonPUPPIIsolation","h0-DR030-")
97  process.patPhotons.puppiIsolationPhotons = cms.InputTag("egmPhotonPUPPIIsolation","gamma-DR030-")
98 
99  (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17).toModify(process.patPhotons,
100  addPFClusterIso = True,
101  ecalPFClusterIsoMap = "reducedEgamma:phoEcalPFClusIso",
102  hcalPFClusterIsoMap = "reducedEgamma:phoHcalPFClusIso")
103  #the 80X legacy customsations are done in ootPhotonProducer for OOT photons
104  run2_miniAOD_94XFall17.toModify(process.patOOTPhotons,
105  addPFClusterIso = True,
106  ecalPFClusterIsoMap = "reducedEgamma:ootPhoEcalPFClusIso",
107  hcalPFClusterIsoMap = "reducedEgamma:ootPhoHcalPFClusIso")
108 
109 
110  process.patPhotons.photonSource = cms.InputTag("reducedEgamma","reducedGedPhotons")
111  process.patPhotons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
112 
113  process.phPFIsoDepositChargedPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
114  process.phPFIsoDepositChargedAllPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
115  process.phPFIsoDepositNeutralPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
116  process.phPFIsoDepositGammaPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
117  process.phPFIsoDepositPUPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
118  #
119  process.patOOTPhotons.photonSource = cms.InputTag("reducedEgamma","reducedOOTPhotons")
120  process.patOOTPhotons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
121  #
122  process.selectedPatJets.cut = cms.string("pt > 10")
123  process.selectedPatMuons.cut = cms.string("pt > 5 || isPFMuon || (pt > 3 && (isGlobalMuon || isStandAloneMuon || numberOfMatches > 0 || muonID('RPCMuLoose')))")
124 
125  from Configuration.Eras.Modifier_phase2_muon_cff import phase2_muon
126  phase2_muon.toModify(process.selectedPatMuons, cut = "pt > 5 || isPFMuon || (pt > 3 && (isGlobalMuon || isStandAloneMuon || numberOfMatches > 0 || muonID('RPCMuLoose') || muonID('ME0MuonArbitrated') || muonID('GEMMuonArbitrated')) )")
127  from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
128  pp_on_AA.toModify(process.selectedPatMuons, cut = "pt > 5 || isPFMuon || (pt > 1.2 && (isGlobalMuon || isStandAloneMuon) )")
129 
130  process.selectedPatElectrons.cut = cms.string("")
131  process.selectedPatTaus.cut = cms.string("pt > 18. && tauID('decayModeFindingNewDMs')> 0.5")
132  process.selectedPatPhotons.cut = cms.string("")
133 
134  _dummyPatJets = process.selectedPatJets.clone(cut = "pt < 0")
135  task = getPatAlgosToolsTask(process)
136 
137  def _applySubstructure(process):
138  from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
139 
140  from PhysicsTools.PatAlgos.slimming.applySubstructure_cff import applySubstructure
141  applySubstructure( process )
142  (~pp_on_AA).toModify(process, _applySubstructure)
143 
144  pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJets', p.selectedPatJets.clone(), p, task))
145  pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJetsAK8', _dummyPatJets.clone(), p, task))
146 
147  #
148  from PhysicsTools.PatAlgos.tools.trigTools import switchOnTriggerStandAlone
149  switchOnTriggerStandAlone( process, outputModule = '' )
150  process.patTrigger.packTriggerPathNames = cms.bool(True)
151  #
152  # apply type I + other PFMEt corrections to pat::MET object
153  # and estimate systematic uncertainties on MET
154 
155  from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncForMiniAODProduction
156  runMetCorAndUncForMiniAODProduction(process, metType="PF",
157  jetCollUnskimmed="patJets")
158 
159  #caloMET computation
160  from PhysicsTools.PatAlgos.tools.metTools import addMETCollection
161  addMETCollection(process,
162  labelName = "patCaloMet",
163  metSource = "caloMetM"
164  )
165 
166  #noHF pfMET =========
167 
168  process.noHFCands = cms.EDFilter("GenericPFCandidateSelector",
169  src=cms.InputTag("particleFlow"),
170  cut=cms.string("abs(pdgId)!=1 && abs(pdgId)!=2 && abs(eta)<3.0")
171  )
172  task.add(process.noHFCands)
173 
175  pfCandColl=cms.InputTag("noHFCands"),
176  recoMetFromPFCs=True, #needed for HF removal
177  jetSelection="pt>15 && abs(eta)<3.",
178  postfix="NoHF"
179  )
180 
181  process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
182  task.add(process.slimmedMETs)
183  (~pp_on_AA).toModify(process.slimmedMETs, addDeepMETs = True)
184 
185  def _add_slimmedMETsNoHF(process):
186  addToProcessAndTask('slimmedMETsNoHF', process.slimmedMETs.clone(), process, task)
187  process.slimmedMETsNoHF.src = cms.InputTag("patMETsNoHF")
188  process.slimmedMETsNoHF.rawVariation = cms.InputTag("patPFMetNoHF")
189  process.slimmedMETsNoHF.t1Uncertainties = cms.InputTag("patPFMetT1%sNoHF")
190  process.slimmedMETsNoHF.t01Variation = cms.InputTag("patPFMetT0pcT1NoHF")
191  process.slimmedMETsNoHF.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sNoHF")
192  process.slimmedMETsNoHF.tXYUncForRaw = cms.InputTag("patPFMetTxyNoHF")
193  process.slimmedMETsNoHF.tXYUncForT1 = cms.InputTag("patPFMetT1TxyNoHF")
194  process.slimmedMETsNoHF.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyNoHF")
195  process.slimmedMETsNoHF.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyNoHF")
196  process.slimmedMETsNoHF.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyNoHF")
197  del process.slimmedMETsNoHF.caloMET
198  (~pp_on_AA).toModify(process, _add_slimmedMETsNoHF)
199  # ================== NoHF pfMET
200 
201  # ================== CHSMET
202  process.load("CommonTools.ParticleFlow.pfCHS_cff")
203  task.add(process.pfCHS)
204 
205  from RecoMET.METProducers.pfMet_cfi import pfMet
206  process.pfMetCHS = pfMet.clone(src = 'pfCHS')
207  task.add(process.pfMetCHS)
208 
209  addMETCollection(process,
210  labelName = "patCHSMet",
211  metSource = "pfMetCHS"
212  )
213 
214  process.patCHSMet.computeMETSignificance = cms.bool(False)
215 
216  # ================== CHSMET
217 
218  # ================== TrkMET
219  process.TrkCands = chargedPackedCandsForTkMet.clone()
220  task.add(process.TrkCands)
221 
222  process.pfMetTrk = pfMet.clone(src = 'TrkCands')
223  task.add(process.pfMetTrk)
224 
225  addMETCollection(process,
226  labelName = "patTrkMet",
227  metSource = "pfMetTrk"
228  )
229 
230  process.patTrkMet.computeMETSignificance = cms.bool(False)
231 
232  # ================== TrkMET
233 
234 
235 
236  process.load("RecoJets.JetProducers.PileupJetID_cfi")
237  task.add(process.pileUpJetIDTask)
238 
239  process.patJets.userData.userFloats.src = [ cms.InputTag("pileupJetId:fullDiscriminant"), ]
240  process.patJets.userData.userInts.src = [ cms.InputTag("pileupJetId:fullId"), ]
241 
242 
243  process.load('RecoJets.JetProducers.QGTagger_cfi')
244  task.add(process.QGTaggerTask)
245 
246  process.patJets.userData.userFloats.src += [ 'QGTagger:qgLikelihood', ]
247 
248  #HF jet shower shape
249  process.load('RecoJets.JetProducers.hfJetShowerShape_cfi')
250  task.add(process.hfJetShowerShape)
251 
252  process.patJets.userData.userFloats.src += [ 'hfJetShowerShape:sigmaEtaEta', 'hfJetShowerShape:sigmaPhiPhi']
253  process.patJets.userData.userInts.src += [ 'hfJetShowerShape:centralEtaStripSize', 'hfJetShowerShape:adjacentEtaStripsSize']
254 
255 
256  def _add_deepFlavour(process):
257  process.load('RecoBTag.Combined.deepFlavour_cff')
258  task.add(process.pfDeepCSVDiscriminatorsJetTags)
259  process.patJets.discriminatorSources.extend([
260  'pfDeepCSVDiscriminatorsJetTags:BvsAll',
261  'pfDeepCSVDiscriminatorsJetTags:CvsB',
262  'pfDeepCSVDiscriminatorsJetTags:CvsL',
263  ])
264  (~pp_on_AA).toModify(process, _add_deepFlavour)
265 
266 
267  process.caloJetMap = cms.EDProducer("RecoJetDeltaRValueMapProducer",
268  src = process.patJets.jetSource,
269  matched = cms.InputTag("ak4CaloJets"),
270  distMax = cms.double(0.4),
271  values = cms.vstring('pt','emEnergyFraction'),
272  valueLabels = cms.vstring('pt','emEnergyFraction'),
273  lazyParser = cms.bool(True) )
274  task.add(process.caloJetMap)
275  process.patJets.userData.userFloats.src += [ 'caloJetMap:pt', 'caloJetMap:emEnergyFraction' ]
276 
277  pp_on_AA.toModify(process.patJets.userData.userInts, src = [] )
278  pp_on_AA.toModify(process.patJets.userData.userFloats, src = [] )
279 
280  #Muon object modifications
281  from PhysicsTools.PatAlgos.slimming.muonIsolationsPUPPI_cfi import makeInputForPUPPIIsolationMuon
283 
284  #EGM object modifications
285  from PhysicsTools.PatAlgos.slimming.egmIsolationsPUPPI_cfi import makeInputForPUPPIIsolationEgm
287  from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma_modifications
288  process.slimmedElectrons.modifierConfig.modifications = egamma_modifications
289  process.slimmedPhotons.modifierConfig.modifications = egamma_modifications
290 
291  #VID Electron IDs
292  process.patElectrons.addElectronID = cms.bool(True)
293  electron_ids = ['RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
294  'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV71_cff',
295  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V1_cff',
296  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
297  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff',
298  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
299  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
300  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
301  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
302  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
303  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
304  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer16UL_ID_ISO_cff',
305  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer17UL_ID_ISO_cff',
306  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer18UL_ID_ISO_cff',
307  ]
308  switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD, task)
309  process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
310  process.electronMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedGsfElectrons')
311 
312  # To use older DataFormats, the electronMVAValueMapProducer MUST take a updated electron collection
313  # such that the conversion variables are filled correctly.
314  process.load("RecoEgamma.EgammaTools.gedGsfElectronsTo106X_cff")
315  run2_miniAOD_80XLegacy.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom80XTo106XTask))
316  run2_miniAOD_80XLegacy.toModify(process.electronMVAValueMapProducer,
317  keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
318  src = cms.InputTag("gedGsfElectronsFrom80XTo106X"))
319 
320  run2_miniAOD_94XFall17.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
321  run2_miniAOD_94XFall17.toModify(process.electronMVAValueMapProducer,
322  keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
323  src = cms.InputTag("gedGsfElectronsFrom94XTo106X"))
324 
325  from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
326  pp_on_AA.toModify(task, func=lambda t: t.add(process.gedGsfElectronsFrom94XTo106XTask))
327  pp_on_AA.toModify(process.electronMVAValueMapProducer,
328  keysForValueMaps = cms.InputTag('reducedEgamma','reducedGedGsfElectrons'),
329  src = "gedGsfElectronsFrom94XTo106X")
330 
331  for idmod in electron_ids:
332  setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection,None,False,task)
333 
334  #VID Photon IDs
335  process.patPhotons.addPhotonID = cms.bool(True)
336  photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
337  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
338  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff',
339  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
340  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
341  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff']
342  switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task)
343  process.egmPhotonIDs.physicsObjectSrc = cms.InputTag("reducedEgamma","reducedGedPhotons")
344  process.photonMVAValueMapProducer.src = cms.InputTag('reducedEgamma','reducedGedPhotons')
345  for idmod in photon_ids:
346  setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False,task)
347 
348  #add the cut base IDs bitmaps of which cuts passed
349  from RecoEgamma.EgammaTools.egammaObjectModifications_tools import makeVIDBitsModifier
350  egamma_modifications.append(makeVIDBitsModifier(process,"egmGsfElectronIDs","egmPhotonIDs"))
351 
352  #-- Adding boosted taus
353  from RecoTauTag.Configuration.boostedHPSPFTaus_cfi import addBoostedTaus
354  addBoostedTaus(process)
355  process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
356  process.load("RecoTauTag.Configuration.HPSPFTaus_cff")
357  #-- Adding customization for 94X 2017 legacy reMniAOD
358  _makePatTausTaskWithRetrainedMVATauID = process.makePatTausTask.copy()
359  _makePatTausTaskWithRetrainedMVATauID.add(process.hpsPFTauBasicDiscriminatorsTask,
360  process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTTask,
361  process.hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLTTask,
362  process.hpsPFTauBasicDiscriminatorsdR03Task,
363  process.hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLTTask,
364  process.hpsPFTauDiscriminationByMVA6rawElectronRejection,
365  process.hpsPFTauDiscriminationByMVA6ElectronRejection,
366  process.hpsPFTauDiscriminationByMuonRejection3)
367  from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
368  (run2_miniAOD_94XFall17 | run2_miniAOD_UL).toReplaceWith(
369  process.makePatTausTask, _makePatTausTaskWithRetrainedMVATauID
370  )
371  #-- Adding DeepTauID
372  # deepTau v2p1 and v2p5
373  _updatedTauName = 'slimmedTausDeepIDsv2p1'
374  _noUpdatedTauName = 'slimmedTausNoDeepIDs'
375  import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
376  tauIdEmbedder = tauIdConfig.TauIDEmbedder(
377  process, debug = False,
378  originalTauName = _noUpdatedTauName,
379  updatedTauName = _updatedTauName,
380  postfix = 'ForMini',
381  toKeep = ['deepTau2017v2p1','deepTau2018v2p5']
382  )
383  from Configuration.Eras.Modifier_phase2_common_cff import phase2_common #Phase2 Tau MVA
384  phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('newDMPhase2v1')) #Phase2 Tau isolation MVA
385  phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('againstElePhase2v1')) #Phase2 Tau anti-e MVA
386  tauIdEmbedder.runTauID()
387  addToProcessAndTask(_noUpdatedTauName, process.slimmedTaus.clone(),process,task)
388  delattr(process, 'slimmedTaus')
389  process.slimmedTaus = getattr(process, _updatedTauName).clone()
390  process.rerunMvaIsolationTaskForMini.add(process.slimmedTaus)
391  task.add(process.rerunMvaIsolationTaskForMini)
392 
393  #-- Rerun tauID against dead ECal towers to taus for the various re-MiniAOD eras
394  # to enable default behoviour with leading track extrapolation to ECAL
395  _makePatTausTaskWithDeadECalVeto = process.makePatTausTask.copy()
396  _makePatTausTaskWithDeadECalVeto.add(
397  process.hpsPFTauDiscriminationByDeadECALElectronRejection
398  )
399  _run2_miniAOD_ANY = (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17 | run2_miniAOD_UL)
400  _run2_miniAOD_ANY.toReplaceWith(
401  process.makePatTausTask, _makePatTausTaskWithDeadECalVeto
402  )
403 
404  #-- Adding customization for 80X 2016 legacy reMiniAOD and 2018 heavy ions
405  _makePatTausTaskWithTauReReco = process.makePatTausTask.copy()
406  _makePatTausTaskWithTauReReco.add(process.PFTauTask)
407  (run2_miniAOD_80XLegacy | pp_on_AA).toReplaceWith(
408  process.makePatTausTask, _makePatTausTaskWithTauReReco
409  )
410 
411  # Adding puppi jets
412  process.load('CommonTools.PileupAlgos.Puppi_cff')
413  process.load('RecoJets.JetProducers.ak4PFJets_cfi')
414  from Configuration.Eras.Modifier_pA_2016_cff import pA_2016
415  _rerun_puppijets_task = task.copy()
416  _rerun_puppijets_task.add(process.puppi, process.ak4PFJetsPuppi)
417  (_run2_miniAOD_ANY | pA_2016 | pp_on_AA).toReplaceWith(task, _rerun_puppijets_task)
418 
419  from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
420  process.ak4PFJetsPuppiTracksAssociatorAtVertex = cms.EDProducer("JetTracksAssociatorAtVertex",
421  j2tParametersVX,
422  jets = cms.InputTag("ak4PFJetsPuppi")
423  )
424  task.add(process.ak4PFJetsPuppiTracksAssociatorAtVertex)
425  process.patJetPuppiCharge = cms.EDProducer("JetChargeProducer",
426  src = cms.InputTag("ak4PFJetsPuppiTracksAssociatorAtVertex"),
427  var = cms.string('Pt'),
428  exp = cms.double(1.0)
429  )
430  task.add(process.patJetPuppiCharge)
431 
432  def _add_jetsPuppi(process):
433  from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
434  noDeepFlavourDiscriminators = [x.value() if isinstance(x, cms.InputTag) else x for x in process.patJets.discriminatorSources
435  if not "DeepFlavour" in str(x)]
436  addJetCollection(process, postfix = "", labelName = 'Puppi', jetSource = cms.InputTag('ak4PFJetsPuppi'),
437  jetCorrections = ('AK4PFPuppi', ['L2Relative', 'L3Absolute'], ''),
438  pfCandidates = cms.InputTag("particleFlow"),
439  algo= 'AK', rParam = 0.4, btagDiscriminators = noDeepFlavourDiscriminators
440  )
441 
442  process.patJetGenJetMatchPuppi.matched = 'slimmedGenJets'
443 
444  process.patJetsPuppi.jetChargeSource = cms.InputTag("patJetPuppiCharge")
445 
446  process.selectedPatJetsPuppi.cut = cms.string("pt > 10")
447 
448  from PhysicsTools.PatAlgos.slimming.applyDeepBtagging_cff import applyDeepBtagging
449  applyDeepBtagging( process )
450 
451  process.slimmedJetsNoDeepFlavour.dropTagInfos = '0'
452  process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.addTagInfos = True
453  process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour.tagInfoSources = ["pixelClusterTagInfos"]
454  _run2_miniAOD_ANY.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = False )
455  (~pp_on_AA).toModify(process, _add_jetsPuppi)
456 
457  pp_on_AA.toModify(process, func = lambda p: addToProcessAndTask('slimmedJetsPuppi', _dummyPatJets.clone(), p, task))
458 
459  # Embed pixelClusterTagInfos in slimmedJets
460  process.patJets.addTagInfos = True
461  process.patJets.tagInfoSources = ["pixelClusterTagInfos"]
462 
463  _run2_miniAOD_ANY.toModify(process.patJets, addTagInfos = False )
464 
465  pp_on_AA.toModify(process.patJets, tagInfoSources = cms.VInputTag(["impactParameterTagInfos","secondaryVertexTagInfos"]) )
466 
467 
468  def _add_metPuppi(process):
469  process.load('RecoMET.METProducers.pfMetPuppi_cfi')
470  _rerun_puppimet_task = task.copy()
471  _rerun_puppimet_task.add(process.puppiNoLep, process.pfMetPuppi)
472  (_run2_miniAOD_ANY | pA_2016 | pp_on_AA).toReplaceWith(task, _rerun_puppimet_task)
473 
474  runMetCorAndUncForMiniAODProduction(process, metType="Puppi",
475  jetCollUnskimmed="slimmedJetsPuppi",
476  recoMetFromPFCs=True,
477  jetFlavor="AK4PFPuppi",
478  postfix="Puppi"
479  )
480  (~pp_on_AA).toModify(process, _add_metPuppi)
481 
482  process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
483  task.add(process.slimmedMETs)
484 
485  def _add_slimmedMETsPuppi(process):
486  addToProcessAndTask('slimmedMETsPuppi', process.slimmedMETs.clone(), process, task)
487  process.slimmedMETsPuppi.src = cms.InputTag("patMETsPuppi")
488  process.slimmedMETsPuppi.rawVariation = cms.InputTag("patPFMetPuppi")
489  process.slimmedMETsPuppi.t1Uncertainties = cms.InputTag("patPFMetT1%sPuppi")
490  process.slimmedMETsPuppi.t01Variation = cms.InputTag("patPFMetT0pcT1Puppi")
491  process.slimmedMETsPuppi.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sPuppi")
492  process.slimmedMETsPuppi.tXYUncForRaw = cms.InputTag("patPFMetTxyPuppi")
493  process.slimmedMETsPuppi.tXYUncForT1 = cms.InputTag("patPFMetT1TxyPuppi")
494  process.slimmedMETsPuppi.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyPuppi")
495  process.slimmedMETsPuppi.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyPuppi")
496  process.slimmedMETsPuppi.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyPuppi")
497  del process.slimmedMETsPuppi.caloMET
498  (~pp_on_AA).toModify(process, _add_slimmedMETsPuppi)
499 
500  def _add_deepMET(process):
501  process.load('RecoMET.METPUSubtraction.deepMETProducer_cfi')
502 
503  addToProcessAndTask('deepMETsResolutionTune', process.deepMETProducer.clone(), process, task)
504  addToProcessAndTask('deepMETsResponseTune', process.deepMETProducer.clone(), process, task)
505  process.deepMETsResponseTune.graph_path = 'RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2018.pb'
506 
507  from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
508  phase2_common.toModify(
509  process.deepMETsResolutionTune,
510  max_n_pf=12500,
511  graph_path="RecoMET/METPUSubtraction/data/deepmet/deepmet_v1_phase2.pb"
512  )
513  phase2_common.toModify(
514  process.deepMETsResponseTune,
515  max_n_pf=12500,
516  graph_path="RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_phase2.pb"
517  )
518 
519  from Configuration.Eras.Modifier_run2_jme_2016_cff import run2_jme_2016
520  run2_jme_2016.toModify(
521  process.deepMETsResponseTune,
522  graph_path="RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2016.pb"
523  )
524  (~pp_on_AA).toModify(process, _add_deepMET)
525 
526  # add DetIdAssociatorRecords to EventSetup (for isolatedTracks)
527  process.load("TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff")
528 
529  # EGamma objects from HGCal are not yet in GED
530  # so add companion collections for Phase-II MiniAOD production
531  from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal
532  process.load("RecoEgamma.EgammaTools.slimmedEgammaHGC_cff")
533  phase2_hgcal.toModify(task, func=lambda t: t.add(process.slimmedEgammaHGCTask))
534 
535  # L1 pre-firing weights for 2016, 2017, and 2018
536  from Configuration.Eras.Modifier_run2_L1prefiring_cff import run2_L1prefiring
537  from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
538  from Configuration.Eras.Modifier_stage2L1Trigger_2017_cff import stage2L1Trigger_2017
539  from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018
540  from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016
541  process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff")
542  (stage2L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016preVFP", DataEraMuon = "2016preVFP" )
543  (stage2L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016postVFP", DataEraMuon = "2016postVFP" )
544  stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "UL2017BtoF", DataEraMuon = "20172018")
545  stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018")
546  run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight))
547 
548  from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeL1FastJetJECs
549  pp_on_AA.toModify(process, removeL1FastJetJECs)
550 
551 def miniAOD_customizeMC(process):
552  task = getPatAlgosToolsTask(process)
553  #GenJetFlavourInfos
554  process.load("PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi")
555  task.add(process.selectedHadronsAndPartons)
556  task.add(process.selectedHadronsAndPartonsForGenJetsFlavourInfos)
557 
558  process.load("PhysicsTools.JetMCAlgos.AK4GenJetFlavourInfos_cfi")
559  task.add(process.ak4GenJetFlavourInfos)
560 
561  process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJetsFlavourInfos_cfi')
562  task.add(process.slimmedGenJetsFlavourInfos)
563 
564  #slimmed pileup information
565  process.load('PhysicsTools.PatAlgos.slimming.slimmedAddPileupInfo_cfi')
566  task.add(process.slimmedAddPileupInfo)
567 
568  process.muonMatch.matched = "prunedGenParticles"
569  process.electronMatch.matched = "prunedGenParticles"
570  process.electronMatch.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
571  process.photonMatch.matched = "prunedGenParticles"
572  process.photonMatch.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
573  process.ootPhotonMatch.matched = "prunedGenParticles"
574  process.ootPhotonMatch.src = cms.InputTag("reducedEgamma","reducedOOTPhotons")
575  process.tauMatch.matched = "prunedGenParticles"
576  process.tauGenJets.GenParticles = "prunedGenParticles"
577  #Boosted taus
578  process.tauMatchBoosted.matched = "prunedGenParticles"
579  process.tauGenJetsBoosted.GenParticles = "prunedGenParticles"
580  process.patJetPartons.particles = "genParticles"
581  process.patJetPartonMatch.matched = "prunedGenParticles"
582  pp_on_AA.toModify(process.patJetPartonMatch, matched = "hiSignalGenParticles")
583  from Configuration.ProcessModifiers.genJetSubEvent_cff import genJetSubEvent
584  genJetSubEvent.toModify(process.patJetPartonMatch, matched = "cleanedPartons")
585  process.patJetPartonMatch.mcStatus = [ 3, 23 ]
586  process.patJetGenJetMatch.matched = "slimmedGenJets"
587  (~pp_on_AA).toModify(process, patJetGenJetMatchAK8Puppi = dict(matched = "slimmedGenJetsAK8"))
588  process.patMuons.embedGenMatch = False
589  process.patElectrons.embedGenMatch = False
590  process.patPhotons.embedGenMatch = False
591  process.patOOTPhotons.embedGenMatch = False
592  process.patTaus.embedGenMatch = False
593  process.patTausBoosted.embedGenMatch = False
594  process.patJets.embedGenPartonMatch = False
595  #also jet flavour must be switched
596  process.patJetFlavourAssociation.rParam = 0.4
597 
598  from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeJECsForMC
599  pp_on_AA.toModify(process, removeJECsForMC)
600  pp_on_AA.toReplaceWith(task,task.copyAndExclude([process.slimmedGenJetsFlavourInfos]))
601 
602 
604  from PhysicsTools.PatAlgos.slimming.MicroEventContent_cff import MiniAODOverrideBranchesSplitLevel
605  out.overrideBranchesSplitLevel = MiniAODOverrideBranchesSplitLevel
606  out.splitLevel = cms.untracked.int32(0)
607  out.dropMetaData = cms.untracked.string('ALL')
608  out.fastCloning= cms.untracked.bool(False)
609  out.overrideInputFileSplitLevels = cms.untracked.bool(True)
610  out.compressionAlgorithm = cms.untracked.string('LZMA')
611 
613  from PhysicsTools.PatAlgos.tools.coreTools import runOnData
614  runOnData( process, outputModules = [] )
615  process.load("RecoPPS.Local.ctppsLocalTrackLiteProducer_cff")
616  process.load("RecoPPS.ProtonReconstruction.ctppsProtons_cff")
617  process.load("Geometry.VeryForwardGeometry.geometryRPFromDB_cfi")
618  process.load('L1Trigger.L1TGlobal.simGtExtFakeProd_cfi')
619  task = getPatAlgosToolsTask(process)
620  task.add(process.simGtExtUnprefireable)
621  from Configuration.Eras.Modifier_ctpps_cff import ctpps
622  ctpps.toModify(task, func=lambda t: t.add(process.ctppsLocalTrackLiteProducer))
623  ctpps.toModify(task, func=lambda t: t.add(process.ctppsProtons))
624  from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
625  run2_miniAOD_UL.toModify(task, func=lambda t: t.add(process.simGtExtUnprefireable))
626 
628  miniAOD_customizeCommon(process)
629  miniAOD_customizeData(process)
630  return process
631 
633  miniAOD_customizeCommon(process)
634  miniAOD_customizeMC(process)
635  return process
636 
638  miniAOD_customizeCommon(process)
639  miniAOD_customizeMC(process)
640  from PhysicsTools.PatAlgos.slimming.metFilterPaths_cff import miniAOD_customizeMETFiltersFastSim
641  process = miniAOD_customizeMETFiltersFastSim(process)
642  from PhysicsTools.PatAlgos.slimming.isolatedTracks_cfi import miniAOD_customizeIsolatedTracksFastSim
643  process = miniAOD_customizeIsolatedTracksFastSim(process)
644  process.patMuons.addTriggerMatching = False
645  # Disable pixelClusterTagInfos in FastSim (no siPixelCluster available)
646  from Configuration.Eras.Modifier_fastSim_cff import fastSim
647  fastSim.toModify(process.patJets, addTagInfos = cms.bool(False) )
648  fastSim.toModify(process.slimmedJetsNoDeepFlavour, dropTagInfos = cms.string('1') )
649  fastSim.toModify(process.updatedPatJetsSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
650  fastSim.toModify(process.updatedPatJetsTransientCorrectedSlimmedDeepFlavour, addTagInfos = cms.bool(False) )
651 
652  return process
def makeInputForPUPPIIsolationMuon(process)
def miniAOD_customizeAllData(process)
def miniAOD_customizeData(process)
def miniAOD_customizeCommon(process)
def applySubstructure(process, postfix="")
def miniAOD_customizeMETFiltersFastSim(process)
def switchOnVIDElectronIdProducer(process, dataFormat, task=None)
Electrons.
Definition: vid_id_tools.py:66
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def makeInputForPUPPIIsolationEgm(process)
def setupAllVIDIdsInModule(process, id_module_name, setupFunction, patProducer=None, addUserData=True, task=None)
Definition: vid_id_tools.py:49
def runMetCorAndUncForMiniAODProduction(process, metType="PF", jetCollUnskimmed="patJets", photonColl="selectedPatPhotons", electronColl="selectedPatElectrons", muonColl="selectedPatMuons", tauColl="selectedPatTaus", pfCandColl="particleFlow", jetCleaning="LepClean", jetSelection="pt>15 && abs(eta)<9.9", jecUnFile="", jetFlavor="AK4PFchs", recoMetFromPFCs=False, postfix="")
def miniAOD_customizeAllMC(process)
def applyDeepBtagging(process, postfix="")
def miniAOD_customizeAllMCFastSim(process)
def miniAOD_customizeIsolatedTracksFastSim(process)
switchOnTriggerStandAlone
Definition: trigTools.py:283
def makeVIDBitsModifier(process, eleVIDModuleName, phoVIDModuleName)
def miniAOD_customizeOutput(out)
def miniAOD_customizeMC(process)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def getPatAlgosToolsTask(process)
Definition: helpers.py:13
def switchOnVIDPhotonIdProducer(process, dataFormat, task=None)
Photons.
#define str(s)