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