CMS 3D CMS Logo

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