CMS 3D CMS Logo

customizeMiniAOD_HcalFixLegacy2016.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 from PhysicsTools.PatAlgos.tools.helpers import MassSearchReplaceAnyInputTagVisitor, addKeepStatement
4 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask
5 import six
6 
7 def loadJetMETBTag(process):
8 
9  task = getPatAlgosToolsTask(process)
10 
12  process.particleFlowPtrs = RecoParticleFlow.PFProducer.pfLinker_cff.particleFlowPtrs.clone()
13  task.add(process.particleFlowPtrs)
14 
15  process.load("CommonTools.ParticleFlow.pfNoPileUpIso_cff")
16  task.add(process.pfNoPileUpIsoTask)
17  process.load("CommonTools.ParticleFlow.ParticleSelectors.pfSortByType_cff")
18  task.add(process.pfSortByTypeTask)
19 
21  process.ak4PFJetsCHS = RecoJets.Configuration.RecoPFJets_cff.ak4PFJetsCHS.clone()
22  task.add(process.ak4PFJetsCHS)
23  # need also the non-CHS ones as they are used to seed taus
24  process.ak4PFJets = RecoJets.Configuration.RecoPFJets_cff.ak4PFJets.clone()
25  task.add(process.ak4PFJets)
26  process.ak8PFJetsCHS = RecoJets.Configuration.RecoPFJets_cff.ak8PFJetsCHS.clone()
27  task.add(process.ak8PFJetsCHS)
28 
29  process.fixedGridRhoAll = RecoJets.Configuration.RecoPFJets_cff.fixedGridRhoAll.clone()
30  process.fixedGridRhoFastjetAll = RecoJets.Configuration.RecoPFJets_cff.fixedGridRhoFastjetAll.clone()
31  process.fixedGridRhoFastjetCentral = RecoJets.Configuration.RecoPFJets_cff.fixedGridRhoFastjetCentral.clone()
32  process.fixedGridRhoFastjetCentralChargedPileUp = RecoJets.Configuration.RecoPFJets_cff.fixedGridRhoFastjetCentralChargedPileUp.clone()
33  process.fixedGridRhoFastjetCentralNeutral = RecoJets.Configuration.RecoPFJets_cff.fixedGridRhoFastjetCentralNeutral.clone()
34  task.add( process.fixedGridRhoAll,
35  process.fixedGridRhoFastjetAll,
36  process.fixedGridRhoFastjetCentral,
37  process.fixedGridRhoFastjetCentralChargedPileUp,
38  process.fixedGridRhoFastjetCentralNeutral )
39 
40  process.load("RecoJets.JetAssociationProducers.ak4JTA_cff")
41  task.add(process.ak4JTATask)
42 
43  process.load('RecoBTag.Configuration.RecoBTag_cff')
44  task.add(process.btaggingTask)
45 
46  process.load("RecoMET.METProducers.PFMET_cfi")
47  task.add(process.pfMet)
48 
49 
50 def cleanPfCandidates(process, verbose=False):
51  task = getPatAlgosToolsTask(process)
52 
53  #add producer at the beginning of the schedule
54  process.load("CommonTools.ParticleFlow.pfCandidateRecalibrator_cfi")
55  task.add(process.pfCandidateRecalibrator)
56 
57  replacePFCandidates = MassSearchReplaceAnyInputTagVisitor("particleFlow", "pfCandidateRecalibrator", verbose=verbose)
58  replacePFTmpPtrs = MassSearchReplaceAnyInputTagVisitor("particleFlowTmpPtrs", "particleFlowPtrs", verbose=verbose)
59  for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]:
60  for name,obj in six.iteritems(everywhere):
61  if obj != process.pfCandidateRecalibrator:
62  replacePFCandidates.doIt(obj, name)
63  replacePFTmpPtrs.doIt(obj, name)
64 
65 
66  process.load("CommonTools.ParticleFlow.pfEGammaToCandidateRemapper_cfi")
67  task.add(process.pfEGammaToCandidateRemapper)
68  process.pfEGammaToCandidateRemapper.pf2pf = cms.InputTag("pfCandidateRecalibrator")
69  process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","electrons")
70  process.reducedEgamma.photonsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","photons")
71 
72 
73 def addDiscardedPFCandidates(process, inputCollection, verbose=False):
74 
75  task = getPatAlgosToolsTask(process)
76 
77  process.primaryVertexAssociationDiscardedCandidates = process.primaryVertexAssociation.clone(
78  particles = inputCollection,
79  )
80  task.add(process.primaryVertexAssociationDiscardedCandidates)
81 
82  process.packedPFCandidatesDiscarded = process.packedPFCandidates.clone(
83  inputCollection = inputCollection,
84  PuppiNoLepSrc = cms.InputTag(""),
85  PuppiSrc = cms.InputTag(""),
86  secondaryVerticesForWhiteList = cms.VInputTag(),
87  vertexAssociator = cms.InputTag("primaryVertexAssociationDiscardedCandidates","original")
88  )
89  task.add(process.packedPFCandidatesDiscarded)
90 
91  addKeepStatement(process, "keep patPackedCandidates_packedPFCandidates_*_*",
92  ["keep patPackedCandidates_packedPFCandidatesDiscarded_*_*"],
93  verbose=verbose)
94 
95 
96 def customizeAll(process, verbose=False):
97 
98  if verbose:
99  print "===>>> customizing the process for legacy rereco 2016"
100 
101  loadJetMETBTag(process)
102 
103  cleanPfCandidates(process, verbose)
104  addDiscardedPFCandidates(process, cms.InputTag("pfCandidateRecalibrator","discarded"), verbose=verbose)
105 
106  return process
def addKeepStatement(process, oldKeep, newKeeps, verbose=False)
Definition: helpers.py:353
def addDiscardedPFCandidates(process, inputCollection, verbose=False)
def getPatAlgosToolsTask(process)
Definition: helpers.py:13