CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MixingModule_Full2Fast.py
Go to the documentation of this file.
1 #####################################
2 # customisation functions that allow to convert a FullSim PU cfg into a FastSim one
3 # main functions: prepareGenMixing and prepareDigiRecoMixing
4 # author: Lukas Vanelderen
5 # date: Jan 21 2015
6 #####################################
7 
8 import FWCore.ParameterSet.Config as cms
9 
11 
12  # container for vertex parameters
13  vertexParameters = cms.PSet()
14 
15  # find the standard vertex generator
16  if not hasattr(process,"VtxSmeared"):
17  "WARNING: no vtx smearing applied (ok for steps other than SIM)"
18  return vertexParameters
19  vertexGenerator = process.VtxSmeared
20 
21  # check the type of the standard vertex generator
22  vertexGeneratorType = vertexGenerator.type_().replace("EvtVtxGenerator","")
23  vtxGenMap = {"Betafunc":"BetaFunc","Flat":"Flat","Gauss":"Gaussian"}
24  if not vertexGeneratorType in vtxGenMap.keys():
25  raise Error("WARNING: given vertex generator type for vertex smearing is not supported")
26  vertexParameters.type = cms.string(vtxGenMap[vertexGeneratorType])
27 
28  # set vertex generator parameters in PileUpProducer
29  vertexGeneratorParameterNames = vertexGenerator.parameterNames_()
30  for name in vertexGeneratorParameterNames:
31  exec("vertexParameters.{0} = {1}".format(name,getattr(vertexGenerator,name).dumpPython()))
32 
33  return vertexParameters
34 
36 
37  # container for PileUpSimulator parameters
38  PileUpSimulator = cms.PSet()
39 
40  # Extract the type of pu distribution
41  _type = "none"
42  if hasattr(_input,"type"):
43  _type = _input.type
44 
45  if _type == "poisson":
46  if not hasattr(_input.nbPileupEvents,"averageNumber"):
47  print " ERROR while reading PU distribution for FastSim PileUpProducer:"
48  print " when process.mix.input.type is set to 'poisson', process.mix.input.nbPileupEvents.averageNumber must be specified."
49  raise
50  PileUpSimulator.averageNumber = _input.nbPileupEvents.averageNumber
51  PileUpSimulator.usePoisson = cms.bool(True)
52 
53  elif _type == "probFunction":
54  if not hasattr(_input.nbPileupEvents,"probFunctionVariable") or not hasattr(_input.nbPileupEvents,"probValue"):
55  print " ERROR while reading PU distribution for FastSim PileUpProducer:"
56  print " when process.mix.input.type is set to 'probFunction', process.mix.nbPileupEvents.probFunctionVariable and process.mix.nbPileupEvents.probValue must be specified"
57  raise
58  PileUpSimulator.usePoisson = cms.bool(False)
59  PileUpSimulator.probFunctionVariable = _input.nbPileupEvents.probFunctionVariable
60  PileUpSimulator.probValue = _input.nbPileupEvents.probValue
61 
62  elif _type != "none":
63  print " ERROR while reading PU distribution for FastSim PileUpProducer:"
64  print " value {0} for process.mix.input.type not supported by FastSim GEN-level PU mixing".format(_type)
65  raise
66 
67  # minbias files
68  from FastSimulation.PileUpProducer.PileUpFiles_cff import puFileNames
69  PileUpSimulator.fileNames = puFileNames.fileNames
70 
71  # a purely technical, but required, setting
72  PileUpSimulator.inputFile = cms.untracked.string('PileUpInputFile.txt')
73 
74  return PileUpSimulator
75 
76 
77 def digitizersFull2Fast(digitizers):
78 
79  # fastsim does not simulate castor
80  if hasattr(digitizers,"castor"):
81  delattr(digitizers,"castor")
82  else:
83  print "WARNING: digitizers has no attribute 'castor'"
84 
85  # fastsim does not digitize pixel and strip hits, it mixes tracks
86  if hasattr(digitizers,"pixel") and hasattr(digitizers,"strip"):
87  delattr(digitizers,"pixel")
88  delattr(digitizers,"strip")
89  import FastSimulation.Tracking.recoTrackAccumulator_cfi
90  digitizers.tracker = cms.PSet(FastSimulation.Tracking.recoTrackAccumulator_cfi.recoTrackAccumulator)
91  else:
92  print "WARNING: digitizers has no attribute 'pixel' and/or 'strip'"
93  print " : => not mixing tracks"
94 
95  # fastsim has its own names for simhit collections
96  for element in ["ecal","hcal"]:
97  if hasattr(digitizers,element):
98  getattr(digitizers,element).hitsProducer = "famosSimHits"
99  else:
100  print "WARNING: digitizers has no attribute '{0}'".format(element)
101 
102  # fastsim has different input for merged truth
103  if hasattr(digitizers,"mergedtruth"):
104  digitizers.mergedtruth.allowDifferentSimHitProcesses = True
105  digitizers.mergedtruth.simHitCollections = cms.PSet(
106  muon = cms.VInputTag( cms.InputTag('MuonSimHits','MuonDTHits'),
107  cms.InputTag('MuonSimHits','MuonCSCHits'),
108  cms.InputTag('MuonSimHits','MuonRPCHits') ),
109  trackerAndPixel = cms.VInputTag( cms.InputTag('famosSimHits','TrackerHits') )
110  )
111  digitizers.mergedtruth.simTrackCollection = cms.InputTag('famosSimHits')
112  digitizers.mergedtruth.simVertexCollection = cms.InputTag('famosSimHits')
113 
114  return digitizers
115 
116 
117 def prepareGenMixing(process):
118 
119  # prepare digitizers and mixObjects for Gen-mixing
120  process = prepareDigiRecoMixing(process)
121 
122  # OOT PU not supported for Gen-mixing: disable it
123  process.mix.maxBunch = cms.int32(0)
124  process.mix.minBunch = cms.int32(0)
125 
126  # set the bunch spacing
127  # bunch spacing matters for calorimeter calibration
128  # setting the bunch spacing here, will have actually no effect,
129  # but leads to consistency with the bunch spacing as hard coded in
130  # FastSimulation/PileUpProducer/plugins/PileUpProducer.cc
131  # where it is propagated to the pileUpInfo, from which calorimeter calibration reads the bunch spacing
132  process.mix.bunchspace = 450
133 
134  # define the PileUpProducer module
135  process.famosPileUp = cms.EDProducer(
136  "PileUpProducer",
137  PileUpSimulator = cms.PSet(),
138  VertexGenerator = cms.PSet()
139  )
140 
141  # get the pu vertex distribution
142  process.famosPileUp.VertexGenerator = get_VertexGeneratorPSet_PileUpProducer(process)
143 
144 
145  # get pu distribution from MixingModule
146  process.famosPileUp.PileUpSimulator = get_PileUpSimulatorPSet_PileUpProducer(process.mix.input)
147 
148  # MixingModule only used for digitization, no need for input
149  del process.mix.input
150 
151  # Insert the PileUpProducer in the simulation sequence
152  pos = process.psim.index(process.famosSimHits)
153  process.psim.insert(pos,process.famosPileUp)
154 
155  # No track mixing when Gen-mixing
156  del process.mix.digitizers.tracker
157  del process.mix.mixObjects.mixRecoTracks
158  del process.generalTracks
159  process.generalTracks = process.generalTracksBeforeMixing.clone()
160  process.iterTracking.replace(process.generalTracksBeforeMixing,process.generalTracks)
161  del process.generalTracksBeforeMixing
162 
163  # Use generalTracks where DIGI-RECO mixing requires preMixTracks
164  process.generalConversionTrackProducer.TrackProducer = cms.string('generalTracks')
165  process.generalConversionTrackProducerTmp.TrackProducer = cms.string('generalTracks')
166  process.trackerDrivenElectronSeedsTmp.TkColList = cms.VInputTag(cms.InputTag("generalTracks"))
167  process.trackerDrivenElectronSeeds.oldTrackCollection = "generalTracks"
168 
169  # take care of the track aliases for HLT
170 
171  _parameters = {
172  "generalTracks":cms.VPSet( cms.PSet(type=cms.string('recoTracks')),
173  cms.PSet(type=cms.string('recoTrackExtras')),
174  cms.PSet(type=cms.string('TrackingRecHitsOwned')),
175  cms.PSet(type=cms.string('floatedmValueMap')))
176  }
177  process.hltIter4HighPtMerged = cms.EDAlias(**_parameters)
178  process.hltIter2HighPtMerged = cms.EDAlias(**_parameters)
179  process.hltIter4Merged = cms.EDAlias(**_parameters)
180  process.hltIter2Merged = cms.EDAlias(**_parameters)
181  process.hltIter4Tau3MuMerged = cms.EDAlias(**_parameters)
182  process.hltIter4MergedReg = cms.EDAlias(**_parameters)
183  process.hltIter2MergedForElectrons = cms.EDAlias(**_parameters)
184  process.hltIter2MergedForPhotons = cms.EDAlias(**_parameters)
185  process.hltIter2L3MuonMerged = cms.EDAlias(**_parameters)
186  process.hltIter2L3MuonMergedReg = cms.EDAlias(**_parameters)
187  process.hltIter2MergedForBTag = cms.EDAlias(**_parameters)
188  process.hltIter2MergedForTau = cms.EDAlias(**_parameters)
189  process.hltIter4MergedForTau = cms.EDAlias(**_parameters)
190  process.hltIter2GlbTrkMuonMerged = cms.EDAlias(**_parameters)
191  process.hltIter2HighPtTkMuMerged = cms.EDAlias(**_parameters)
192  process.hltIter2HighPtTkMuIsoMerged = cms.EDAlias(**_parameters)
193  process.hltIter2DisplacedJpsiMerged = cms.EDAlias(**_parameters)
194  process.hltIter2DisplacedPsiPrimeMerged = cms.EDAlias(**_parameters)
195  process.hltIter2DisplacedNRMuMuMerged = cms.EDAlias(**_parameters)
196  process.hltIter0PFlowTrackSelectionHighPurityForBTag = cms.EDAlias(**_parameters)
197  process.hltIter4MergedWithIter012DisplacedJets = cms.EDAlias(**_parameters)
198 
199  # PileUp info must be read from PileUpProducer, rather than from MixingModule
200  process.addPileupInfo.PileupMixingLabel = cms.InputTag("famosPileUp")
201 
202  return process
203 
205 
206  # switch to FastSim digitizers
207  process.mix.digitizers = digitizersFull2Fast(process.mix.digitizers)
208 
209  # switch to FastSim mixObjects
210  import FastSimulation.Configuration.mixObjects_cfi
211  process.mix.mixObjects = FastSimulation.Configuration.mixObjects_cfi.theMixObjects
212 
213  # fastsim does not simulate castor
214  # fastsim does not digitize pixel and strip hits
215  for element in ["simCastorDigis","simSiPixelDigis","simSiStripDigis"]:
216  if hasattr(process,element):
217  delattr(process,element)
218 
219  # get rid of some FullSim specific psets that work confusing when dumping FastSim cfgs
220  # (this is optional)
221  del process.theDigitizers
222  del process.theDigitizersValid
223  del process.trackingParticles
224  del process.stripDigitizer
225  del process.SiStripSimBlock
226  del process.castorDigitizer
227  del process.pixelDigitizer
228  del process.ecalDigitizer
229 
230  # get rid of FullSim specific services that work confusing when dumping FastSim cfgs
231  # (this is optional)
232  del process.siStripGainSimESProducer
233 
234  return process