test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
miniAOD_tools.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
4 
6  process.patMuons.isoDeposits = cms.PSet()
7  process.patElectrons.isoDeposits = cms.PSet()
8  process.patTaus.isoDeposits = cms.PSet()
9  process.patPhotons.isoDeposits = cms.PSet()
10  #
11  process.patMuons.embedTrack = True # used for IDs
12  process.patMuons.embedCombinedMuon = True # used for IDs
13  process.patMuons.embedMuonBestTrack = True # used for IDs
14  process.patMuons.embedStandAloneMuon = True # maybe?
15  process.patMuons.embedPickyMuon = False # no, use best track
16  process.patMuons.embedTpfmsMuon = False # no, use best track
17  process.patMuons.embedDytMuon = False # no, use best track
18  #
19  # disable embedding of electron and photon associated objects already stored by the ReducedEGProducer
20  process.patElectrons.embedGsfElectronCore = False ## process.patElectrons.embed in AOD externally stored gsf electron core
21  process.patElectrons.embedSuperCluster = False ## process.patElectrons.embed in AOD externally stored supercluster
22  process.patElectrons.embedPflowSuperCluster = False ## process.patElectrons.embed in AOD externally stored supercluster
23  process.patElectrons.embedSeedCluster = False ## process.patElectrons.embed in AOD externally stored the electron's seedcluster
24  process.patElectrons.embedBasicClusters = False ## process.patElectrons.embed in AOD externally stored the electron's basic clusters
25  process.patElectrons.embedPreshowerClusters = False ## process.patElectrons.embed in AOD externally stored the electron's preshower clusters
26  process.patElectrons.embedPflowBasicClusters = False ## process.patElectrons.embed in AOD externally stored the electron's pflow basic clusters
27  process.patElectrons.embedPflowPreshowerClusters = False ## process.patElectrons.embed in AOD externally stored the electron's pflow preshower clusters
28  process.patElectrons.embedRecHits = False ## process.patElectrons.embed in AOD externally stored the RecHits - can be called from the PATElectronProducer
29  process.patElectrons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
30  process.patElectrons.electronIDSources = cms.PSet(
31  # configure many IDs as InputTag <someName> = <someTag> you
32  # can comment out those you don't want to save some disk space
33  eidRobustLoose = cms.InputTag("reducedEgamma","eidRobustLoose"),
34  eidRobustTight = cms.InputTag("reducedEgamma","eidRobustTight"),
35  eidLoose = cms.InputTag("reducedEgamma","eidLoose"),
36  eidTight = cms.InputTag("reducedEgamma","eidTight"),
37  eidRobustHighEnergy = cms.InputTag("reducedEgamma","eidRobustHighEnergy"),
38  )
39  process.patElectrons.addPFClusterIso = cms.bool(True)
40  process.patElectrons.ecalPFClusterIsoMap = cms.InputTag("reducedEgamma", "eleEcalPFClusIso")
41  process.patElectrons.hcalPFClusterIsoMap = cms.InputTag("reducedEgamma", "eleHcalPFClusIso")
42 
43  process.elPFIsoDepositChargedPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
44  process.elPFIsoDepositChargedAllPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
45  process.elPFIsoDepositNeutralPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
46  process.elPFIsoDepositGammaPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
47  process.elPFIsoDepositPUPAT.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
48  #
49  process.patPhotons.embedSuperCluster = False ## whether to process.patPhotons.embed in AOD externally stored supercluster
50  process.patPhotons.embedSeedCluster = False ## process.patPhotons.embed in AOD externally stored the photon's seedcluster
51  process.patPhotons.embedBasicClusters = False ## process.patPhotons.embed in AOD externally stored the photon's basic clusters
52  process.patPhotons.embedPreshowerClusters = False ## process.patPhotons.embed in AOD externally stored the photon's preshower clusters
53  process.patPhotons.embedRecHits = False ## process.patPhotons.embed in AOD externally stored the RecHits - can be called from the PATPhotonProducer
54  process.patPhotons.addPFClusterIso = cms.bool(True)
55  process.patPhotons.ecalPFClusterIsoMap = cms.InputTag("reducedEgamma", "phoEcalPFClusIso")
56  process.patPhotons.hcalPFClusterIsoMap = cms.InputTag("reducedEgamma", "phoHcalPFClusIso")
57  process.patPhotons.photonSource = cms.InputTag("reducedEgamma","reducedGedPhotons")
58  process.patPhotons.electronSource = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
59  process.patPhotons.photonIDSources = cms.PSet(
60  PhotonCutBasedIDLoose = cms.InputTag('reducedEgamma',
61  'PhotonCutBasedIDLoose'),
62  PhotonCutBasedIDTight = cms.InputTag('reducedEgamma',
63  'PhotonCutBasedIDTight')
64  )
65 
66  process.phPFIsoDepositChargedPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
67  process.phPFIsoDepositChargedAllPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
68  process.phPFIsoDepositNeutralPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
69  process.phPFIsoDepositGammaPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
70  process.phPFIsoDepositPUPAT.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
71  #
72  process.selectedPatJets.cut = cms.string("pt > 10")
73  process.selectedPatMuons.cut = cms.string("pt > 5 || isPFMuon || (pt > 3 && (isGlobalMuon || isStandAloneMuon || numberOfMatches > 0 || muonID('RPCMuLoose')))")
74  process.selectedPatElectrons.cut = cms.string("")
75  process.selectedPatTaus.cut = cms.string("pt > 18. && tauID('decayModeFindingNewDMs')> 0.5")
76  process.selectedPatPhotons.cut = cms.string("")
77 
78  from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
79 
80  from PhysicsTools.PatAlgos.slimming.applySubstructure_cff import applySubstructure
81  applySubstructure( process )
82 
83 
84  #
85  from PhysicsTools.PatAlgos.tools.trigTools import switchOnTriggerStandAlone
86  switchOnTriggerStandAlone( process, outputModule = '' )
87  process.patTrigger.packTriggerPathNames = cms.bool(True)
88  #
89  # apply type I + other PFMEt corrections to pat::MET object
90  # and estimate systematic uncertainties on MET
91 
92  process.selectedPatJetsForMETUnc = process.selectedPatJets.clone()
93  process.selectedPatJetsForMETUnc.cut = cms.string("pt > 15")
94 
95  from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncForMiniAODProduction
96  runMetCorAndUncForMiniAODProduction(process, metType="PF",
97  jetCollUnskimmed="patJets",
98  jetColl="selectedPatJetsForMETUnc")
99 
100  #caloMET computation
101  from PhysicsTools.PatAlgos.tools.metTools import addMETCollection
102  addMETCollection(process,
103  labelName = "patCaloMet",
104  metSource = "caloMetM"
105  )
106 
107  #noHF pfMET =========
108  process.noHFCands = cms.EDFilter("GenericPFCandidateSelector",
109  src=cms.InputTag("particleFlow"),
110  cut=cms.string("abs(pdgId)!=1 && abs(pdgId)!=2 && abs(eta)<3.0")
111  )
113  pfCandColl=cms.InputTag("noHFCands"),
114  recoMetFromPFCs=True, #needed for HF removal
115  postfix="NoHF"
116  )
117  process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
118  process.slimmedMETsNoHF = process.slimmedMETs.clone()
119  process.slimmedMETsNoHF.src = cms.InputTag("patMETsNoHF")
120  process.slimmedMETsNoHF.rawVariation = cms.InputTag("patPFMetNoHF")
121  process.slimmedMETsNoHF.t1Uncertainties = cms.InputTag("patPFMetT1%sNoHF")
122  process.slimmedMETsNoHF.t01Variation = cms.InputTag("patPFMetT0pcT1NoHF")
123  process.slimmedMETsNoHF.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sNoHF")
124  process.slimmedMETsNoHF.tXYUncForRaw = cms.InputTag("patPFMetTxyNoHF")
125  process.slimmedMETsNoHF.tXYUncForT1 = cms.InputTag("patPFMetT1TxyNoHF")
126  process.slimmedMETsNoHF.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyNoHF")
127  process.slimmedMETsNoHF.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyNoHF")
128  process.slimmedMETsNoHF.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyNoHF")
129  del process.slimmedMETsNoHF.caloMET
130  # ================== NoHF pfMET
131 
132  #keep this after all addJetCollections otherwise it will attempt computing them also for stuf with no taginfos
133  #Some useful BTAG vars
134  process.patJets.userData.userFunctions = cms.vstring(
135  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).p4.M):(0)',
136  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).numberOfSourceCandidatePtrs):(0)',
137  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").flightDistance(0).value):(0)',
138  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").flightDistance(0).significance):(0)',
139  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).p4.x):(0)',
140  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).p4.y):(0)',
141  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).p4.z):(0)',
142  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).vertex.x):(0)',
143  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).vertex.y):(0)',
144  '?(tagInfoCandSecondaryVertex("pfSecondaryVertex").nVertices()>0)?(tagInfoCandSecondaryVertex("pfSecondaryVertex").secondaryVertex(0).vertex.z):(0)',
145  )
146  process.patJets.userData.userFunctionLabels = cms.vstring('vtxMass','vtxNtracks','vtx3DVal','vtx3DSig','vtxPx','vtxPy','vtxPz','vtxPosX','vtxPosY','vtxPosZ')
147  process.patJets.tagInfoSources = cms.VInputTag(cms.InputTag("pfSecondaryVertexTagInfos"))
148  process.patJets.addTagInfos = cms.bool(True)
149  #
150  ## PU JetID
151  process.load("RecoJets.JetProducers.PileupJetID_cfi")
152  process.patJets.userData.userFloats.src = [ cms.InputTag("pileupJetId:fullDiscriminant"), ]
153 
154  ## CaloJets
155  process.caloJetMap = cms.EDProducer("RecoJetDeltaRValueMapProducer",
156  src = process.patJets.jetSource,
157  matched = cms.InputTag("ak4CaloJets"),
158  distMax = cms.double(0.4),
159  values = cms.vstring('pt','emEnergyFraction'),
160  valueLabels = cms.vstring('pt','emEnergyFraction'),
161  lazyParser = cms.bool(True) )
162  process.patJets.userData.userFloats.src += [ cms.InputTag("caloJetMap:pt"), cms.InputTag("caloJetMap:emEnergyFraction") ]
163 
164  #EGM object modifications
165  from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma_modifications
166  process.slimmedElectrons.modifierConfig.modifications = egamma_modifications
167  process.slimmedPhotons.modifierConfig.modifications = egamma_modifications
168 
169  #VID Electron IDs
170  electron_ids = ['RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_PHYS14_PU20bx25_V2_cff',
171  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_25ns_V1_cff',
172  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_50ns_V2_cff',
173  'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV60_cff',
174  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_nonTrig_V1_cff',
175  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_Trig_V1_cff',
176  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_50ns_Trig_V1_cff']
177  switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD)
178  process.egmGsfElectronIDs.physicsObjectSrc = \
179  cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
180  process.electronMVAValueMapProducer.src = \
181  cms.InputTag('reducedEgamma','reducedGedGsfElectrons')
182  process.electronRegressionValueMapProducer.src = \
183  cms.InputTag('reducedEgamma','reducedGedGsfElectrons')
184  for idmod in electron_ids:
185  setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection,None,False)
186 
187  #VID Photon IDs
188  photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_PHYS14_PU20bx25_V2p1_cff',
189  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring15_50ns_V1_cff',
190  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff',
191  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff']
192  switchOnVIDPhotonIdProducer(process,DataFormat.MiniAOD)
193  process.egmPhotonIDs.physicsObjectSrc = \
194  cms.InputTag("reducedEgamma","reducedGedPhotons")
195  process.photonIDValueMapProducer.src = \
196  cms.InputTag("reducedEgamma","reducedGedPhotons")
197  process.photonRegressionValueMapProducer.src = \
198  cms.InputTag("reducedEgamma","reducedGedPhotons")
199  process.photonIDValueMapProducer.particleBasedIsolation = \
200  cms.InputTag("reducedEgamma","reducedPhotonPfCandMap")
201  process.photonMVAValueMapProducer.src = \
202  cms.InputTag('reducedEgamma','reducedGedPhotons')
203  for idmod in photon_ids:
204  setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False)
205 
206  #----------------------------------------------------------------------------
207  # CV: add old and new tau ID discriminators for CMSSW 7_6_x reminiAOD v2
208  process.load("RecoTauTag.Configuration.RecoPFTauTag_reminiAOD_cff")
209  from PhysicsTools.PatAlgos.tools.tauTools import switchToPFTauHPS76xReMiniAOD
211  #----------------------------------------------------------------------------
212 
213  # Adding puppi jets
214  process.load('CommonTools.PileupAlgos.Puppi_cff')
215  process.load('RecoJets.JetProducers.ak4PFJetsPuppi_cfi')
216  process.ak4PFJetsPuppi.doAreaFastjet = True # even for standard ak4PFJets this is overwritten in RecoJets/Configuration/python/RecoPFJets_cff
217  #process.puppi.candName = cms.InputTag('packedPFCandidates')
218  #process.puppi.vertexName = cms.InputTag('offlineSlimmedPrimaryVertices')
219  # kind of ugly, is there a better way to do this?
220  process.pfNoLepPUPPI = cms.EDFilter("PdgIdCandViewSelector",
221  src = cms.InputTag("particleFlow"),
222  pdgId = cms.vint32( 1,2,22,111,130,310,2112,211,-211,321,-321,999211,2212,-2212 )
223  )
224  process.pfLeptonsPUPPET = cms.EDFilter("PdgIdCandViewSelector",
225  src = cms.InputTag("particleFlow"),
226  pdgId = cms.vint32(-11,11,-13,13),
227  )
228  process.puppiNoLep = process.puppi.clone()
229  process.puppiNoLep.candName = cms.InputTag('pfNoLepPUPPI')
230 
231  from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
232  process.ak4PFJetsPuppiTracksAssociatorAtVertex = cms.EDProducer("JetTracksAssociatorAtVertex",
233  j2tParametersVX,
234  jets = cms.InputTag("ak4PFJetsPuppi")
235  )
236  process.patJetPuppiCharge = cms.EDProducer("JetChargeProducer",
237  src = cms.InputTag("ak4PFJetsPuppiTracksAssociatorAtVertex"),
238  var = cms.string('Pt'),
239  exp = cms.double(1.0)
240  )
241 
242  addJetCollection(process, postfix = "", labelName = 'Puppi', jetSource = cms.InputTag('ak4PFJetsPuppi'),
243  jetCorrections = ('AK4PFchs', ['L2Relative', 'L3Absolute'], ''),
244  algo= 'AK', rParam = 0.4, btagDiscriminators = map(lambda x: x.value() ,process.patJets.discriminatorSources)
245  )
246 
247  process.patJetGenJetMatchPuppi.matched = 'slimmedGenJets'
248 
249  process.patJetsPuppi.userData.userFloats.src = cms.VInputTag(cms.InputTag(""))
250  process.patJetsPuppi.jetChargeSource = cms.InputTag("patJetPuppiCharge")
251 
252  process.selectedPatJetsPuppi.cut = cms.string("pt > 20")
253 
254  process.load('PhysicsTools.PatAlgos.slimming.slimmedJets_cfi')
255  process.slimmedJetsPuppi = process.slimmedJets.clone()
256  process.slimmedJetsPuppi.src = cms.InputTag("selectedPatJetsPuppi")
257  process.slimmedJetsPuppi.packedPFCandidates = cms.InputTag("packedPFCandidates")
258 
259  ## puppi met
260  process.load('RecoMET.METProducers.PFMET_cfi')
261  process.puppiForMET = cms.EDProducer("CandViewMerger",
262  src = cms.VInputTag( "pfLeptonsPUPPET", "puppiNoLep")
263  )
264  process.pfMetPuppi = process.pfMet.clone()
265  process.pfMetPuppi.src = cms.InputTag("puppiForMET")
266  process.pfMetPuppi.alias = cms.string('pfMetPuppi')
267  # type1 correction, from puppi jets
268  process.corrPfMetType1Puppi = process.corrPfMetType1.clone(
269  src = 'ak4PFJetsPuppi',
270  jetCorrLabel = 'ak4PFCHSL2L3Corrector',
271  )
272  del process.corrPfMetType1Puppi.offsetCorrLabel # no L1 for PUPPI jets
273  process.pfMetT1Puppi = process.pfMetT1.clone(
274  src = 'pfMetPuppi',
275  srcCorrections = [ cms.InputTag("corrPfMetType1Puppi","type1") ]
276  )
277 
278  from PhysicsTools.PatAlgos.tools.metTools import addMETCollection
279  addMETCollection(process, labelName='patMETPuppi', metSource='pfMetT1Puppi') # T1
280  addMETCollection(process, labelName='patPFMetPuppi', metSource='pfMetPuppi') # RAW
281 
282  process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
283  process.slimmedMETsPuppi = process.slimmedMETs.clone()
284  process.slimmedMETsPuppi.src = cms.InputTag("patMETPuppi")
285  process.slimmedMETsPuppi.rawVariation = cms.InputTag("patPFMetPuppi") # only central value
286  # only central values for puppi met
287  del process.slimmedMETsPuppi.t01Variation
288  del process.slimmedMETsPuppi.t1SmearedVarsAndUncs
289  del process.slimmedMETsPuppi.tXYUncForRaw
290  del process.slimmedMETsPuppi.tXYUncForT1
291  del process.slimmedMETsPuppi.tXYUncForT01
292  del process.slimmedMETsPuppi.tXYUncForT1Smear
293  del process.slimmedMETsPuppi.tXYUncForT01Smear
294  del process.slimmedMETsPuppi.caloMET
295 
296 
297 def miniAOD_customizeMC(process):
298  #slimmed pileup information
299  process.load('PhysicsTools.PatAlgos.slimming.slimmedAddPileupInfo_cfi')
300 
301  process.muonMatch.matched = "prunedGenParticles"
302  process.electronMatch.matched = "prunedGenParticles"
303  process.electronMatch.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
304  process.photonMatch.matched = "prunedGenParticles"
305  process.photonMatch.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
306  process.tauMatch.matched = "prunedGenParticles"
307  process.tauGenJets.GenParticles = "prunedGenParticles"
308  process.patJetPartons.particles = "prunedGenParticles"
309  process.patJetPartonMatch.matched = "prunedGenParticles"
310  process.patJetPartonMatch.mcStatus = [ 3, 23 ]
311  process.patJetGenJetMatch.matched = "slimmedGenJets"
312  process.patJetGenJetMatchAK8.matched = "slimmedGenJetsAK8"
313  process.patMuons.embedGenMatch = False
314  process.patElectrons.embedGenMatch = False
315  process.patPhotons.embedGenMatch = False
316  process.patTaus.embedGenMatch = False
317  process.patJets.embedGenPartonMatch = False
318  #also jet flavour must be switched
319  process.patJetFlavourAssociation.rParam = 0.4
320 
322  out.dropMetaData = cms.untracked.string('ALL')
323  out.fastCloning= cms.untracked.bool(False)
324  out.overrideInputFileSplitLevels = cms.untracked.bool(True)
325  out.compressionAlgorithm = cms.untracked.string('LZMA')
326 
328  from PhysicsTools.PatAlgos.tools.coreTools import runOnData
329  runOnData( process, outputModules = [] )
330 
332  miniAOD_customizeCommon(process)
333  miniAOD_customizeData(process)
334  return process
335 
337  miniAOD_customizeCommon(process)
338  miniAOD_customizeMC(process)
339  return process
def setupAllVIDIdsInModule
Definition: vid_id_tools.py:50
def switchOnVIDElectronIdProducer
Definition: vid_id_tools.py:69
def miniAOD_customizeAllMC
def miniAOD_customizeCommon
Definition: miniAOD_tools.py:5
def switchToPFTauHPS76xReMiniAOD
Definition: tauTools.py:330
def miniAOD_customizeAllData
def miniAOD_customizeOutput
tuple switchOnTriggerStandAlone
Definition: trigTools.py:276
def miniAOD_customizeData
def switchOnVIDPhotonIdProducer
Photons.