CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Reconstruction_AftMix_cff.py
Go to the documentation of this file.
1 #############################
2 # This cfg configures the part of reconstruction
3 # in FastSim to be done after event mixing
4 # FastSim mixes tracker information on reconstruction level,
5 # so tracks are recontructed before mixing.
6 # At present, only the generalTrack collection, produced with iterative tracking is mixed.
7 #############################
8 
9 import FWCore.ParameterSet.Config as cms
10 from FWCore.ParameterSet.SequenceTypes import _SequenceCollection
11 
12 ###########################################
13 # remove modules from Reconstruction_cff that are run before mixing
14 ###########################################
15 
17 
18 # list of modules to be deleted
19 _mod2del = []
20 
21 # list the modules we want to get rid of
22 _mod2del = _reco.trackingGlobalReco.expandAndClone()._seq._collection
23 _mod2del.append(_reco.trackingGlobalReco)
24 _mod2del.extend(_reco.recopixelvertexing.expandAndClone()._seq._collection)
25 _mod2del.append(_reco.MeasurementTrackerEventPreSplitting)
26 
27 # actually we want to keep a few modules that we need to run (again) after mixing)
28 for _entry in [_reco.firstStepPrimaryVertices,_reco.ak4CaloJetsForTrk,_reco.caloTowerForTrk,_reco.trackExtrapolator]:
29  while _entry in _mod2del:
30  _mod2del.remove(_entry)
31 
32 # offlineBeamSpot is reconstructed before mixing
33 _mod2del.append(_reco.offlineBeamSpot)
34 
35 ###########################################
36 # no castor / zdc in FastSim
37 ###########################################
38 _reco.localreco.remove(_reco.castorreco)
39 _reco.globalreco.remove(_reco.CastorFullReco)
40 _reco.hcalLocalRecoSequence.remove(_reco.zdcreco)
41 
42 ##########################################
43 # Calo rechits
44 ##########################################
45 
46 # not commisoned and not relevant in FastSim (?):
47 _reco.reducedEcalRecHitsSequence.remove(_reco.seldigis)
48 _reco.ecalRecHitSequence.remove(_reco.ecalCompactTrigPrim)
49 _reco.ecalRecHitSequence.remove(_reco.ecalTPSkim)
50 
51 # no flags for bad channels in FastSim
52 _reco.ecalRecHit.killDeadChannels = False
53 _reco.ecalRecHit.recoverEBFE = False
54 _reco.ecalRecHit.recoverEEFE = False
55 _reco.ecalUncalibRecHitSequence.remove(_reco.ecalDetIdToBeRecovered)
56 ##########################################
57 # Changes to tracking sequences
58 ##########################################
59 
60 # remove tracking
61 _reco.localreco.remove(_reco.trackerlocalreco)
62 _reco.globalreco.remove(_reco.siPixelClusterShapeCachePreSplitting)
63 _reco.globalreco.remove(_reco.trackingGlobalReco)
64 
65 # we need a replacment for the firstStepPrimaryVertices
66 # that includes tracker information of signal and pile up
67 # after mixing there is no such thing as initialStepTracks,
68 # so we replace the input collection for firstStepPrimaryVertices with generalTracks
69 _reco.firstStepPrimaryVertices.TrackLabel = "generalTracks"
70 
71 # insert the few tracking modules to be run after mixing back in the globalreco sequence
72 #for _entry in reversed([trackExtrapolator,caloTowerForTrk,firstStepPrimaryVertices,ak4CaloJetsForTrk])
73 _reco.globalreco.insert(0,_reco.trackExtrapolator+_reco.caloTowerForTrk+_reco.firstStepPrimaryVertices+_reco.ak4CaloJetsForTrk)
74 
75 # FastSim doesn't use Runge Kute for propagation
76 # the following propagators are not used in FastSim, but just to be sure...
77 _reco.KFFitterForRefitOutsideIn.Propagator = 'SmartPropagatorAny'
78 _reco.KFSmootherForRefitOutsideIn.Propagator = 'SmartPropagator'
79 
80 
81 ##########################################
82 # FastSim changes to electron reconstruction
83 ##########################################
84 
85 # replace the standard ecal-driven seeds with the FastSim emulated ones
86 import FastSimulation.Tracking.globalCombinedSeeds_cfi
87 _reco.newCombinedSeeds = FastSimulation.Tracking.globalCombinedSeeds_cfi.newCombinedSeeds
88 _reco.globalreco.insert(0,_reco.newCombinedSeeds)
89 
90 # tracker driven electron seeds depend on the generalTracks trajectory collection
91 # However, in FastSim jobs, trajectories are only available for the 'before mixing' track collections
92 # Therefore we let the seeds depend on the 'before mixing' generalTracks collection
93 # TODO: investigate whether the dependence on trajectories can be avoided
94 import FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi
95 _trackerDrivenElectronSeeds = FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi.fixedTrackerDrivenElectronSeeds.clone()
96 _reco.electronSeeds.replace(_reco.trackerDrivenElectronSeeds,_reco.trackerDrivenElectronSeeds+_trackerDrivenElectronSeeds)
97 _reco.trackerDrivenElectronSeedsTmp = _reco.trackerDrivenElectronSeeds
98 _reco.trackerDrivenElectronSeedsTmp.TkColList = cms.VInputTag(cms.InputTag("generalTracksBeforeMixing"))
99 _reco.trackerDrivenElectronSeeds = _trackerDrivenElectronSeeds
100 _reco.trackerDrivenElectronSeeds.seedCollection.setModuleLabel("trackerDrivenElectronSeedsTmp")
101 _reco.trackerDrivenElectronSeeds.idCollection.setModuleLabel("trackerDrivenElectronSeedsTmp")
102 
103 # replace the ECAL driven electron track candidates with the FastSim emulated ones
105 _reco.electronGSGsfTrackCandidates = FastSimulation.EgammaElectronAlgos.electronGSGsfTrackCandidates_cff.electronGSGsfTrackCandidates
106 _reco.electronGsfTracking.replace(_reco.electronCkfTrackCandidates,_reco.electronGSGsfTrackCandidates)
107 _reco.electronGsfTracks.src = "electronGSGsfTrackCandidates"
108 
109 # FastSim has no template fit on tracker hits
110 _reco.electronGsfTracks.TTRHBuilder = "WithoutRefit"
111 
112 # the conversion producer depends on trajectories
113 # so we feed it with the 'before mixing' track colletion
114 _reco.generalConversionTrackProducer.TrackProducer = 'generalTracksBeforeMixing'
115 
116 # then we need to fix the track references, so that they point to the final track collection, after mixing
117 import FastSimulation.Tracking.ConversionTrackRefFix_cfi
118 _conversionTrackRefFix = FastSimulation.Tracking.ConversionTrackRefFix_cfi.fixedConversionTracks.clone(
119  src = cms.InputTag("generalConversionTrackProducerTmp"))
120 _reco.conversionTrackSequenceNoEcalSeeded.replace(_reco.generalConversionTrackProducer,_reco.generalConversionTrackProducer+_conversionTrackRefFix)
121 _reco.generalConversionTrackProducerTmp = _reco.generalConversionTrackProducer
122 _reco.generalConversionTrackProducer = _conversionTrackRefFix
123 
124 # this might be historical: not sure why we do this
125 _reco.egammaGlobalReco.replace(_reco.conversionTrackSequence,_reco.conversionTrackSequenceNoEcalSeeded)
126 _reco.allConversions.src = 'gsfGeneralConversionTrackMerger'
127 # TODO: revisit converions in FastSim
128 
129 # not commisoned and not relevant in FastSim (?):
130 _reco.egammaHighLevelRecoPrePF.remove(_reco.uncleanedOnlyElectronSequence)
131 
132 # not commisoned and not relevant in FastSim (?):
133 _reco.egammareco.remove(_reco.conversionSequence)
134 _reco.egammaHighLevelRecoPrePF.remove(_reco.conversionSequence)
135 
136 ##########################################
137 # FastSim changes to muon reconstruction
138 ##########################################
139 # not commisoned and not relevant in FastSim (?):
140 _reco.globalreco.remove(_reco.muoncosmicreco)
141 _reco.highlevelreco.remove(_reco.muoncosmichighlevelreco)
142 _reco.muons.FillCosmicsIdMap = False
143 
144 # not commisoned and not relevant in FastSim (?):
145 _reco.globalmuontracking.remove(_reco.displacedGlobalMuonTracking)
146 _reco.standalonemuontracking.remove(_reco.displacedMuonSeeds)
147 _reco.standalonemuontracking.remove(_reco.displacedStandAloneMuons)
148 
149 # not commisoned and not relevant in FastSim (?):
150 _reco.muonGlobalReco.remove(_reco.muonreco_with_SET)
151 
152 # not commisoned and not relevant in FastSim (?):
153 _reco.muonGlobalReco.remove(_reco.muonSelectionTypeSequence)
154 _reco.muons.FillSelectorMaps = False
155 
156 # FastSim has no template fit on tracker hits
157 _reco.globalMuons.GLBTrajBuilderParameters.GlbRefitterParameters.TrackerRecHitBuilder = 'WithoutRefit'
158 _reco.globalMuons.GLBTrajBuilderParameters.TrackerRecHitBuilder = 'WithoutRefit'
159 _reco.globalMuons.GLBTrajBuilderParameters.TrackTransformer.TrackerRecHitBuilder = 'WithoutRefit'
160 _reco.tevMuons.RefitterParameters.TrackerRecHitBuilder = 'WithoutRefit'
161 
162 # FastSim doesn't use Runge Kute for propagation
163 _reco.globalMuons.GLBTrajBuilderParameters.GlbRefitterParameters.Propagator = 'SmartPropagatorAny'
164 _reco.globalMuons.GLBTrajBuilderParameters.GlobalMuonTrackMatcher.Propagator = 'SmartPropagator'
165 _reco.globalMuons.GLBTrajBuilderParameters.TrackTransformer.Propagator = 'SmartPropagatorAny'
166 _reco.GlbMuKFFitter.Propagator = "SmartPropagatorAny"
167 _reco.GlobalMuonRefitter.Propagator = "SmartPropagatorAny"
168 _reco.KFSmootherForMuonTrackLoader.Propagator = "SmartPropagatorAny"
169 _reco.KFSmootherForRefitInsideOut.Propagator = "SmartPropagatorAny"
170 _reco.KFFitterForRefitInsideOut.Propagator = "SmartPropagatorAny"
171 _reco.tevMuons.RefitterParameters.Propagator = "SmartPropagatorAny"
172 
173 ##########################################
174 # FastSim changes to jet/met reconstruction
175 ##########################################
176 
177 # not commisoned and not relevant in FastSim (?):
178 _reco.jetHighLevelReco.remove(_reco.recoJetAssociationsExplicit)
179 
180 # not commisoned and not relevant in FastSim (?):
181 _reco.metreco.remove(_reco.BeamHaloId)
182 
183 # not commisoned and not relevant in FastSim (?):
184 _reco.metrecoPlusHCALNoise.remove(_reco.hcalnoise)
185 
186 ##########################################
187 # The PF Patch
188 ##########################################
189 
190 # throws random neutral hadrons in the detector to fix jet response
191 # we should get rid of this asap, but the source of the issue is not known
193 _FSparticleFlowTmp = FastSimulation.ParticleFlow.FSparticleFlow_cfi.FSparticleFlow
194 _reco.particleFlowReco.replace(_reco.particleFlowTmp,_reco.particleFlowTmp+_FSparticleFlowTmp)
195 _reco.particleFlowTmpTmp = _reco.particleFlowTmp
196 _reco.particleFlowTmp = _FSparticleFlowTmp
197 _reco.particleFlowTmp.pfCandidates = cms.InputTag("particleFlowTmpTmp")
198 
199 ############################################
200 # the final reconstruction sequence
201 ############################################
202 # this is the standard reconstruction sequence,
203 # except for the logErrorHarvester which is traditinally not run in FastSim
204 #_reco.reconstruction = cms.Sequence(_reco.localreco*_reco.globalreco*_reco.highlevelreco)
205 
206 
207 for _entry in _mod2del:
208  for _key,_value in _reco.__dict__.items():
209  _index = -1
210  if isinstance(_value,cms.Sequence):
211  try:
212  _index = _value.index(_entry)
213  except:
214  pass
215  if _index >= 0:
216  _value.remove(_entry)
217  # removing the last item does not work, and changes the properties of the sequence
218  # so, we detect this changed behaviour and add the sequence to the list of items to be deleted
219  # this is buggy
220  if not isinstance(_value._seq,_SequenceCollection):
221  _mod2del.append(_value)
222 
223 # and delete
224 for _entry in _mod2del:
225  for _key,_value in _reco.__dict__.items():
226  if _entry == _value:
227  delattr(_reco,_key)
228 
229 
231