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 prepareGenMixing(process):
78 
79  # prepare digitizers and mixObjects for Gen-mixing
80  process = prepareDigiRecoMixing(process)
81 
82  # for reasons of simplicity track mixing is not switched off,
83  # although it has no effect in case of Gen-mixing
84 
85  # OOT PU not supported for Gen-mixing: disable it
86  process.mix.maxBunch = cms.int32(0)
87  process.mix.minBunch = cms.int32(0)
88 
89  # set the bunch spacing
90  # bunch spacing matters for calorimeter calibration
91  # setting the bunch spacing here, will have actually no effect,
92  # but leads to consistency with the bunch spacing as hard coded in
93  # FastSimulation/PileUpProducer/plugins/PileUpProducer.cc
94  # where it is propagated to the pileUpInfo, from which calorimeter calibration reads the bunch spacing
95  process.mix.bunchspace = 450
96 
97  # define the PileUpProducer module
98  process.famosPileUp = cms.EDProducer(
99  "PileUpProducer",
100  PileUpSimulator = cms.PSet(),
101  VertexGenerator = cms.PSet()
102  )
103 
104  # get the pu vertex distribution
105  process.famosPileUp.VertexGenerator = get_VertexGeneratorPSet_PileUpProducer(process)
106 
107 
108  # get pu distribution from MixingModule
109  process.famosPileUp.PileUpSimulator = get_PileUpSimulatorPSet_PileUpProducer(process.mix.input)
110 
111  # MixingModule only used for digitization, no need for input
112  del process.mix.input
113 
114  # Insert the PileUpProducer in the simulation sequence
115  pos = process.simulationSequence.index(process.famosSimHits)
116  process.simulationSequence.insert(pos,process.famosPileUp)
117 
118  # No track mixing when Gen-mixing
119  del process.mix.digitizers.tracker
120  del process.mix.mixObjects.mixRecoTracks
121  del process.generalTracks
122  process.generalTracks = process.generalTracksBeforeMixing.clone()
123  process.iterTracking.replace(process.generalTracksBeforeMixing,process.generalTracks)
124  del process.generalTracksBeforeMixing
125 
126  # Use generalTracks where DIGI-RECO mixing requires preMixTracks
127  process.generalConversionTrackProducer.TrackProducer = cms.string('generalTracks')
128  # it's not nice but gen-mixing will be depricated anyhow
129  process.trackerDrivenElectronSeedsTmp.TkColList = cms.VInputTag(cms.InputTag("generalTracks"))
130  process.trackerDrivenElectronSeeds.oldTrackCollection = cms.InputTag('generalTracks')
131 
132  # PileUp info must be read from PileUpProducer, rather than from MixingModule
133  process.addPileupInfo.PileupMixingLabel = cms.InputTag("famosPileUp")
134 
135  return process
136 
138 
139  # switch to FastSim digitizers
140  if hasattr(process,"theDigitizersValid"):
141  del process.theDigitizersValid
142  from FastSimulation.Configuration.digitizers_cfi import theDigitizersValid
143  process.mix.digitizers = theDigitizersValid
144 
145  # switch to FastSim mixObjects
146  if hasattr(process,"theMixObjects"):
147  del process.theMixObjects
148  from FastSimulation.Configuration.mixObjects_cfi import theMixObjects
149  process.mix.mixObjects = theMixObjects
150 
151  # get rid of FullSim specific EDAliases for collections from MixingModule
152  del process.simCastorDigis
153  del process.simSiPixelDigis
154  del process.simSiStripDigis
155 
156  # import the FastSim specific EDAliases for collections from MixingModule
157  from FastSimulation.Configuration.digitizers_cfi import generalTracks
158  process.generalTracks = generalTracks
159 
160  # get rid of some FullSim specific psets that work confusing when dumping FastSim cfgs
161  # (this is optional)
162  del process.trackingParticles
163  del process.stripDigitizer
164  del process.SiStripSimBlock
165  del process.castorDigitizer
166  del process.pixelDigitizer
167  del process.ecalDigitizer
168 
169 
170  # get rid of FullSim specific services that work confusing when dumping FastSim cfgs
171  # (this is optional)
172  del process.siStripGainSimESProducer
173 
174  return process