CMS 3D CMS Logo

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 # import standard reconstruction
13 # apply modifications before doing the actual import at the end
15 
16 # list of modules to be deleted
17 _mod2del = []
18 
19 ##########################################
20 # offlineBeamSpot is reconstructed before mixing
21 ##########################################
22 _mod2del.append(_reco.offlineBeamSpot)
23 _reco.globalreco.remove(_reco.offlineBeamSpot) # temporary removing this by hand, cause the usual removal (see end of this file) doesn't seem work
24 
25 ###########################################
26 # no castor, zdc, Totem/CTPPS RP in FastSim
27 ###########################################
28 _reco.localreco.remove(_reco.castorreco)
29 _reco.globalreco.remove(_reco.CastorFullReco)
30 _reco.hcalLocalRecoSequence.remove(_reco.zdcreco)
31 _reco.localreco.remove(_reco.totemRPLocalReconstruction)
32 _reco.localreco.remove(_reco.ctppsDiamondLocalReconstruction)
33 _reco.localreco.remove(_reco.ctppsLocalTrackLiteProducer)
34 _reco.localreco.remove(_reco.ctppsPixelLocalReconstruction)
35 
36 ##########################################
37 # Calo rechits
38 ##########################################
39 # not commisoned and not relevant in FastSim (?):
40 _reco.reducedEcalRecHitsSequence.remove(_reco.seldigis)
41 _reco.ecalRecHitSequence.remove(_reco.ecalCompactTrigPrim)
42 _reco.ecalRecHitSequence.remove(_reco.ecalTPSkim)
43 
44 # no flags for bad channels in FastSim
45 _reco.ecalRecHit.killDeadChannels = False
46 _reco.ecalRecHit.recoverEBFE = False
47 _reco.ecalRecHit.recoverEEFE = False
48 _reco.ecalUncalibRecHitSequence.remove(_reco.ecalDetIdToBeRecovered)
49 
50 ##########################################
51 # Changes to tracking sequences
52 ##########################################
53 # modules to be removed
54 _mod2del = _reco.trackingGlobalReco.expandAndClone()._seq._collection
55 _mod2del.append(_reco.trackingGlobalReco)
56 _mod2del.extend(_reco.recopixelvertexing.expandAndClone()._seq._collection)
57 _mod2del.append(_reco.MeasurementTrackerEventPreSplitting)
58 # actually we want to keep a few modules that we need to run (again) after mixing)
59 for _entry in [_reco.firstStepPrimaryVerticesUnsorted,_reco.firstStepPrimaryVertices,_reco.ak4CaloJetsForTrk,_reco.caloTowerForTrk,_reco.initialStepTrackRefsForJets,_reco.trackExtrapolator]:
60  while _entry in _mod2del:
61  _mod2del.remove(_entry)
62 
63 # remove tracking sequences from main reco sequences
64 _reco.localreco.remove(_reco.trackerlocalreco)
65 _reco.globalreco.remove(_reco.siPixelClusterShapeCachePreSplitting)
66 _reco.globalreco.remove(_reco.trackingGlobalReco)
67 
68 # we need a replacment for the firstStepPrimaryVerticesUnsorted
69 # that includes tracker information of signal and pile up
70 # after mixing there is no such thing as initialStepTracks,
71 # so we replace the input collection for firstStepPrimaryVerticesUnsorted with generalTracks
72 _reco.firstStepPrimaryVerticesUnsorted.TrackLabel = "generalTracks"
73 _reco.initialStepTrackRefsForJets.src = "generalTracks"
74 
75 # insert the few tracking modules to be run after mixing back in the globalreco sequence
76 #for _entry in reversed([trackExtrapolator,caloTowerForTrk,firstStepPrimaryVertices,ak4CaloJetsForTrk])
77 _reco.globalreco.insert(0,_reco.trackExtrapolator+_reco.caloTowerForTrk+_reco.firstStepPrimaryVerticesUnsorted+_reco.ak4CaloJetsForTrk+_reco.initialStepTrackRefsForJets+_reco.firstStepPrimaryVertices)
78 
79 # FastSim doesn't use Runge Kute for propagation
80 # the following propagators are not used in FastSim, but just to be sure...
81 _reco.KFFitterForRefitOutsideIn.Propagator = 'SmartPropagatorAny'
82 _reco.KFSmootherForRefitOutsideIn.Propagator = 'SmartPropagator'
83 
84 # replace the standard ecal-driven seeds with the FastSim emulated ones
85 import FastSimulation.Tracking.ElectronSeeds_cff
86 _reco.newCombinedSeeds = FastSimulation.Tracking.ElectronSeeds_cff.newCombinedSeeds
87 _reco.globalreco.insert(0,_reco.newCombinedSeeds)
88 
89 ##########################################
90 # FastSim changes to electron reconstruction
91 ##########################################
92 # tracker driven electron seeds depend on the generalTracks trajectory collection
93 # However, in FastSim jobs, trajectories are only available for the 'before mixing' track collections
94 # Therefore we let the seeds depend on the 'before mixing' generalTracks collection
95 # TODO: investigate whether the dependence on trajectories can be avoided
96 import FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi
97 _trackerDrivenElectronSeeds = FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi.fixedTrackerDrivenElectronSeeds.clone()
98 _reco.electronSeeds.replace(_reco.trackerDrivenElectronSeeds,_reco.trackerDrivenElectronSeeds+_trackerDrivenElectronSeeds)
99 _reco.trackerDrivenElectronSeedsTmp = _reco.trackerDrivenElectronSeeds
100 _reco.trackerDrivenElectronSeedsTmp.TkColList = cms.VInputTag(cms.InputTag("generalTracksBeforeMixing"))
101 _reco.trackerDrivenElectronSeeds = _trackerDrivenElectronSeeds
102 _reco.trackerDrivenElectronSeeds.seedCollection.setModuleLabel("trackerDrivenElectronSeedsTmp")
103 _reco.trackerDrivenElectronSeeds.idCollection.setModuleLabel("trackerDrivenElectronSeedsTmp")
104 
105 # replace the ECAL driven electron track candidates with the FastSim emulated ones
107 _reco.fastElectronCkfTrackCandidates = FastSimulation.Tracking.electronCkfTrackCandidates_cff.electronCkfTrackCandidates.clone()
108 _reco.electronGsfTracking.replace(_reco.electronCkfTrackCandidates,_reco.fastElectronCkfTrackCandidates)
109 _reco.electronGsfTracks.src = "fastElectronCkfTrackCandidates"
110 
111 # FastSim has no template fit on tracker hits
112 _reco.electronGsfTracks.TTRHBuilder = "WithoutRefit"
113 
114 # the conversion producer depends on trajectories
115 # so we feed it with the 'before mixing' track colletion
116 _reco.generalConversionTrackProducer.TrackProducer = 'generalTracksBeforeMixing'
117 
118 # then we need to fix the track references, so that they point to the final track collection, after mixing
119 import FastSimulation.Tracking.ConversionTrackRefFix_cfi
120 _conversionTrackRefFix = FastSimulation.Tracking.ConversionTrackRefFix_cfi.fixedConversionTracks.clone(
121  src = cms.InputTag("generalConversionTrackProducerTmp"))
122 _reco.conversionTrackSequenceNoEcalSeeded.replace(_reco.generalConversionTrackProducer,_reco.generalConversionTrackProducer+_conversionTrackRefFix)
123 _reco.generalConversionTrackProducerTmp = _reco.generalConversionTrackProducer
124 _reco.generalConversionTrackProducer = _conversionTrackRefFix
125 
126 # this might be historical: not sure why we do this
127 _reco.egammaGlobalReco.replace(_reco.conversionTrackSequence,_reco.conversionTrackSequenceNoEcalSeeded)
128 _reco.allConversions.src = 'gsfGeneralConversionTrackMerger'
129 # TODO: revisit converions in FastSim
130 
131 # not commisoned and not relevant in FastSim (?):
132 _reco.egammaHighLevelRecoPrePF.remove(_reco.uncleanedOnlyElectronSequence)
133 
134 # not commisoned and not relevant in FastSim (?):
135 _reco.egammareco.remove(_reco.conversionSequence)
136 _reco.egammaHighLevelRecoPrePF.remove(_reco.conversionSequence)
137 
138 ##########################################
139 # FastSim changes to muon reconstruction
140 ##########################################
141 # not commisoned and not relevant in FastSim (?):
142 _reco.globalreco.remove(_reco.muoncosmicreco)
143 _reco.highlevelreco.remove(_reco.cosmicDCTracksSeq)
144 _reco.highlevelreco.remove(_reco.muoncosmichighlevelreco)
145 _reco.muons.FillCosmicsIdMap = False
146 
147 # not commisoned and not relevant in FastSim (?):
148 _reco.globalmuontracking.remove(_reco.displacedGlobalMuonTracking)
149 _reco.standalonemuontracking.remove(_reco.displacedMuonSeeds)
150 _reco.standalonemuontracking.remove(_reco.displacedStandAloneMuons)
151 
152 # not commisoned and not relevant in FastSim (?):
153 _reco.muonGlobalReco.remove(_reco.muonreco_with_SET)
154 
155 # not commisoned and not relevant in FastSim (?):
156 _reco.muonGlobalReco.remove(_reco.muonSelectionTypeSequence)
157 _reco.muons.FillSelectorMaps = False
158 
159 # FastSim has no template fit on tracker hits
160 _reco.globalMuons.GLBTrajBuilderParameters.GlbRefitterParameters.TrackerRecHitBuilder = 'WithoutRefit'
161 _reco.globalMuons.GLBTrajBuilderParameters.TrackerRecHitBuilder = 'WithoutRefit'
162 _reco.globalMuons.GLBTrajBuilderParameters.TrackTransformer.TrackerRecHitBuilder = 'WithoutRefit'
163 _reco.tevMuons.RefitterParameters.TrackerRecHitBuilder = 'WithoutRefit'
164 
165 # FastSim doesn't use Runge Kute for propagation
166 _reco.globalMuons.GLBTrajBuilderParameters.GlbRefitterParameters.Propagator = 'SmartPropagatorAny'
167 _reco.globalMuons.GLBTrajBuilderParameters.GlobalMuonTrackMatcher.Propagator = 'SmartPropagator'
168 _reco.globalMuons.GLBTrajBuilderParameters.TrackTransformer.Propagator = 'SmartPropagatorAny'
169 _reco.GlbMuKFFitter.Propagator = "SmartPropagatorAny"
170 _reco.GlobalMuonRefitter.Propagator = "SmartPropagatorAny"
171 _reco.KFSmootherForMuonTrackLoader.Propagator = "SmartPropagatorAny"
172 _reco.KFSmootherForRefitInsideOut.Propagator = "SmartPropagatorAny"
173 _reco.KFFitterForRefitInsideOut.Propagator = "SmartPropagatorAny"
174 _reco.tevMuons.RefitterParameters.Propagator = "SmartPropagatorAny"
175 
176 ##########################################
177 # FastSim changes to jet/met reconstruction
178 ##########################################
179 # CSCHaloData depends on cosmic muons, not available in fastsim
180 _reco.BeamHaloId.remove(_reco.CSCHaloData)
181 # GlobalHaloData and BeamHaloSummary depend on CSCHaloData
182 _reco.BeamHaloId.remove(_reco.GlobalHaloData)
183 _reco.BeamHaloId.remove(_reco.BeamHaloSummary)
184 
185 ############################################
186 # deleting modules to avoid clashes with part of reconstruction run before mixing
187 ############################################
188 for _entry in _mod2del:
189  for _key,_value in _reco.__dict__.items():
190  _index = -1
191  if isinstance(_value,cms.Sequence):
192  try:
193  _index = _value.index(_entry)
194  except:
195  pass
196  if _index >= 0:
197  _value.remove(_entry)
198  # removing the last item does not work, and changes the properties of the sequence
199  # so, we detect this changed behaviour and add the sequence to the list of items to be deleted
200  # this is buggy
201  if not isinstance(_value._seq,_SequenceCollection):
202  _mod2del.append(_value)
203 
204 # and delete
205 for _entry in _mod2del:
206  for _key,_value in _reco.__dict__.items():
207  if _entry == _value:
208  delattr(_reco,_key)
209 
210 ############################################
211 # the actual import
212 ############################################
214