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