CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
embeddingCustomizeRH.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 
3 import FWCore.ParameterSet.Config as cms
4 import os
5 
6 import PhysicsTools.PatAlgos.tools.helpers as configtools
7 from TrackingTools.TrackAssociator.default_cfi import TrackAssociatorParameterBlock
8 from TauAnalysis.MCEmbeddingTools.rerunParticleFlow import updateInputTags
9 
10 def replaceModule_or_Sequence(process, moduleOld, modulesNew):
11  for sequenceName in process.sequences:
12  sequence = getattr(process, sequenceName)
13  #print("sequence = %s: modules = %s" % (sequenceName, sequence.moduleNames()))
14  moduleNameOld = moduleOld.label()
15  if moduleNameOld in sequence.moduleNames():
16  #print("replacing Module '%s' in Sequence '%s'." % (moduleNameOld, sequenceName))
17  sequence.replace(moduleOld, modulesNew)
18  for pathName in process.paths:
19  path = getattr(process, pathName)
20  #print("path = %s: modules = %s" % (pathName, path.moduleNames()))
21  if moduleNameOld in path.moduleNames():
22  #print("replacing Module '%s' in Path '%s'." % (moduleNameOld, pathName))
23  path.replace(moduleOld, modulesNew)
24 
25 def customise(process, inputProcess):
26 
27  # Determine detIds of calorimeter cells crossed by muon track
28  trackAssocParamsForMuonCleaning = TrackAssociatorParameterBlock.TrackAssociatorParameters
29  updateInputTags(process, trackAssocParamsForMuonCleaning, inputProcess)
30  process.muonCaloEnergyDepositsAllCrossed = cms.EDProducer('MuonCaloCleanerAllCrossed',
31  trackAssociator = trackAssocParamsForMuonCleaning,
32  selectedMuons = process.customization_options.ZmumuCollection,
33  esRecHits = cms.InputTag("ecalPreshowerRecHit", "EcalRecHitsES", inputProcess)
34  )
35  process.ProductionFilterSequence += process.muonCaloEnergyDepositsAllCrossed
36 
37  recHitCaloCleanerAllCrossedConfig = cms.PSet(
38  srcEnergyDepositMapMuPlus = cms.InputTag("muonCaloEnergyDepositsAllCrossed", "energyDepositsMuPlus"),
39  srcEnergyDepositMapMuMinus = cms.InputTag("muonCaloEnergyDepositsAllCrossed", "energyDepositsMuMinus"),
40  typeEnergyDepositMap = cms.string("absolute"), # CV: use 'absolute' for 'MuonCaloCleanerAllCrossed' module
41  )
42 
43  recHitCaloCleanerByDistanceConfig = None
44  if process.customization_options.cleaningMode == 'DEDX':
45  process.muonCaloEnergyDepositsByDistance = cms.EDProducer('MuonCaloCleanerByDistance',
46  muons = cms.InputTag("muonCaloDistances", "muons"),
47  distanceMapMuPlus = cms.InputTag("muonCaloDistances", "distancesMuPlus"),
48  distanceMapMuMinus = cms.InputTag("muonCaloDistances", "distancesMuMinus"),
49  energyDepositCorrection = cms.PSet(
50  H_Ecal_EcalBarrel = cms.double(process.customization_options.muonCaloCleaningSF.value()*0.9),
51  H_Ecal_EcalEndcap = cms.double(process.customization_options.muonCaloCleaningSF.value()*0.9), # AB: use barrel value for now
52  H_Hcal_HcalBarrel = cms.double(process.customization_options.muonCaloCleaningSF.value()*1.1),
53  H_Hcal_HcalOuter = cms.double(process.customization_options.muonCaloCleaningSF.value()*0.8),
54  H_Hcal_HcalEndcap = cms.double(process.customization_options.muonCaloCleaningSF.value()*0.9),
55  H_Hcal_HcalForward = cms.double(process.customization_options.muonCaloCleaningSF.value()*0.000), # CV: simulated tau decay products are not expected to deposit eny energy in HF calorimeter
56  H_Hcal_HcalOther = cms.double(process.customization_options.muonCaloCleaningSF.value()*0.000)
57  ),
58  verbosity = cms.int32(0)
59  )
60  process.ProductionFilterSequence += process.muonCaloEnergyDepositsByDistance
61 
62  recHitCaloCleanerByDistanceConfig = cms.PSet(
63  srcEnergyDepositMapMuPlus = cms.InputTag("muonCaloEnergyDepositsByDistance", "energyDepositsMuPlus"),
64  srcEnergyDepositMapMuMinus = cms.InputTag("muonCaloEnergyDepositsByDistance", "energyDepositsMuMinus"),
65  typeEnergyDepositMap = cms.string("absolute"), # CV: use 'absolute' ('relative') for 'MuonCaloCleanerByDistance' ('PFMuonCleaner') module
66  )
67  elif process.customization_options.cleaningMode == 'PF':
68  # Take energy deposits associated to muon by particle-flow algorithm
69  process.pfMuonCaloEnergyDeposits = cms.EDProducer('PFMuonCaloCleaner',
70  selectedMuons = process.customization_options.ZmumuCollection,
71  pfCandidates = cms.InputTag("particleFlowForPFMuonCleaning"),
72  dRmatch = cms.double(0.3),
73  verbosity = cms.int32(0)
74  )
75  process.ProductionFilterSequence += process.pfMuonCaloEnergyDeposits
76 
77  recHitCaloCleanerByDistanceConfig = cms.PSet(
78  srcEnergyDepositMapMuPlus = cms.InputTag("pfMuonCaloEnergyDeposits", "energyDepositsMuPlus"),
79  srcEnergyDepositMapMuMinus = cms.InputTag("pfMuonCaloEnergyDeposits", "energyDepositsMuMinus"),
80  typeEnergyDepositMap = cms.string("absolute"), # CV: use 'absolute' for 'PFMuonCaloCleaner'
81  )
82  else:
83  raise ValueError("Invalid Configuration parameter 'cleaningMode' = %s !!" % process.customization_options.cleaningMode)
84 
85  # mix recHits in CASTOR calorimeter
86  #
87  # NOTE: CASTOR is not expected to contain any energy from the simulated tau decay products;
88  # the mixing is necessary to get the energy deposits from the Z -> mu+ mu- event
89  # into the embedded event
90  #
91  if not process.customization_options.skipCaloRecHitMixing.value():
92  process.castorrecoORG = process.castorreco.clone()
93  process.castorreco = cms.EDProducer("CastorRecHitMixer",
94  recHitCaloCleanerAllCrossedConfig,
95  todo = cms.VPSet(
96  cms.PSet(
97  collection1 = cms.InputTag("castorrecoORG"),
98  collection2 = cms.InputTag("castorreco", "", inputProcess),
99  killNegEnergyBeforeMixing1 = cms.bool(False),
100  killNegEnergyBeforeMixing2 = cms.bool(True),
101  muonEnSutractionMode = cms.string("subtractFromCollection2BeforeMixing"),
102  killNegEnergyAfterMixing = cms.bool(False)
103  )
104  ),
105  verbosity = cms.int32(0)
106  )
107  replaceModule_or_Sequence(process, process.castorreco, process.castorrecoORG*process.castorreco)
108  else:
109  print("WARNING: disabling mixing of CASTOR recHit collection, this setting should be used for DEBUGGING only !!")
110 
111  # mix recHits in HF calorimeter
112  #
113  # NOTE: HF calorimeter is not expected to contain any energy from the simulated tau decay products;
114  # the mixing is necessary to get the energy deposits from the Z -> mu+ mu- event
115  # into the embedded event
116  #
117  if not process.customization_options.skipCaloRecHitMixing.value():
118  process.hfrecoORG = process.hfreco.clone()
119  process.hfreco = cms.EDProducer("HFRecHitMixer",
120  recHitCaloCleanerAllCrossedConfig,
121  todo = cms.VPSet(
122  cms.PSet(
123  collection1 = cms.InputTag("hfrecoORG"),
124  collection2 = cms.InputTag("hfreco", "", inputProcess),
125  killNegEnergyBeforeMixing1 = cms.bool(False),
126  killNegEnergyBeforeMixing2 = cms.bool(True),
127  muonEnSutractionMode = cms.string("subtractFromCollection2BeforeMixing"),
128  killNegEnergyAfterMixing = cms.bool(False)
129  )
130  ),
131  verbosity = cms.int32(0)
132  )
133  replaceModule_or_Sequence(process, process.hfreco, process.hfrecoORG*process.hfreco)
134  else:
135  print("WARNING: disabling mixing of HF recHit collection, this setting should be used for DEBUGGING only !!")
136 
137  # mix recHits in preshower
138  if not process.customization_options.skipCaloRecHitMixing.value():
139  process.ecalPreshowerRecHitORG = process.ecalPreshowerRecHit.clone()
140  process.ecalPreshowerRecHit = cms.EDProducer("EcalRecHitMixer",
141  recHitCaloCleanerAllCrossedConfig,
142  todo = cms.VPSet(
143  cms.PSet (
144  collection1 = cms.InputTag("ecalPreshowerRecHitORG", "EcalRecHitsES"),
145  collection2 = cms.InputTag("ecalPreshowerRecHit", "EcalRecHitsES", inputProcess),
146  killNegEnergyBeforeMixing1 = cms.bool(False),
147  killNegEnergyBeforeMixing2 = cms.bool(True),
148  muonEnSutractionMode = cms.string("subtractFromCollection2BeforeMixing"),
149  killNegEnergyAfterMixing = cms.bool(False)
150  )
151  ),
152  verbosity = cms.int32(0)
153  )
154  replaceModule_or_Sequence(process, process.ecalPreshowerRecHit, process.ecalPreshowerRecHitORG*process.ecalPreshowerRecHit)
155  else:
156  print("WARNING: disabling mixing of ES recHit collection, this setting should be used for DEBUGGING only !!")
157 
158  # mix recHits in ECAL
159  if not process.customization_options.skipCaloRecHitMixing.value():
160  print "Mixing ECAL recHit collections"
161  process.ecalRecHitORG = process.ecalRecHit.clone()
162  process.ecalRecHit = cms.EDProducer("EcalRecHitMixer",
163  recHitCaloCleanerByDistanceConfig,
164  todo = cms.VPSet(
165  cms.PSet(
166  collection1 = cms.InputTag("ecalRecHitORG", "EcalRecHitsEB"),
167  collection2 = cms.InputTag("ecalRecHit", "EcalRecHitsEB", inputProcess),
168  killNegEnergyBeforeMixing1 = cms.bool(False),
169  killNegEnergyBeforeMixing2 = cms.bool(True),
170  muonEnSutractionMode = cms.string("subtractFromCollection2BeforeMixing"),
171  killNegEnergyAfterMixing = cms.bool(False)
172  ),
173  cms.PSet (
174  collection1 = cms.InputTag("ecalRecHitORG", "EcalRecHitsEE"),
175  collection2 = cms.InputTag("ecalRecHit", "EcalRecHitsEE", inputProcess),
176  killNegEnergyBeforeMixing1 = cms.bool(False),
177  killNegEnergyBeforeMixing2 = cms.bool(True),
178  muonEnSutractionMode = cms.string("subtractFromCollection2BeforeMixing"),
179  killNegEnergyAfterMixing = cms.bool(False)
180  )
181  ),
182  verbosity = cms.int32(0)
183  )
184  replaceModule_or_Sequence(process, process.ecalRecHit, process.ecalRecHitORG*process.ecalRecHit)
185  else:
186  print("WARNING: disabling mixing of EB and EE recHit collections, this setting should be used for DEBUGGING only !!")
187 
188  # mix recHits in HCAL
189  if not process.customization_options.skipCaloRecHitMixing.value():
190  print "Mixing HCAL recHit collection"
191  process.hbherecoORG = process.hbhereco.clone()
192  process.hbhereco = cms.EDProducer("HBHERecHitMixer",
193  recHitCaloCleanerByDistanceConfig,
194  todo = cms.VPSet(
195  cms.PSet(
196  collection1 = cms.InputTag("hbherecoORG", ""),
197  collection2 = cms.InputTag("hbhereco", "", inputProcess),
198  killNegEnergyBeforeMixing1 = cms.bool(False),
199  killNegEnergyBeforeMixing2 = cms.bool(True),
200  muonEnSutractionMode = cms.string("subtractFromCollection2BeforeMixing"),
201  killNegEnergyAfterMixing = cms.bool(False)
202  )
203  ),
204  verbosity = cms.int32(0)
205  )
206  replaceModule_or_Sequence(process, process.hbhereco, process.hbherecoORG*process.hbhereco)
207 
208  process.horecoORG = process.horeco.clone()
209  process.horeco = cms.EDProducer("HORecHitMixer",
210  recHitCaloCleanerByDistanceConfig,
211  todo = cms.VPSet(
212  cms.PSet(
213  collection1 = cms.InputTag("horecoORG", ""),
214  collection2 = cms.InputTag("horeco", "", inputProcess),
215  killNegEnergyBeforeMixing1 = cms.bool(False),
216  killNegEnergyBeforeMixing2 = cms.bool(True),
217  muonEnSutractionMode = cms.string("subtractFromCollection2BeforeMixing"),
218  killNegEnergyAfterMixing = cms.bool(False)
219  )
220  ),
221  verbosity = cms.int32(0)
222  )
223  replaceModule_or_Sequence(process, process.horeco, process.horecoORG*process.horeco)
224  else:
225  print("WARNING: disabling mixing of HB, HE and HO recHit collections, this setting should be used for DEBUGGING only !!")
226 
227  # CV: Compute hits in muon detectors of the two muons produced in Z -> mu+ mu- decay
228  process.muonDetHits = cms.EDProducer('MuonDetCleaner',
229  trackAssociator = trackAssocParamsForMuonCleaning,
230  selectedMuons = process.customization_options.ZmumuCollection,
231  verbosity = cms.int32(0)
232  )
233  if process.customization_options.replaceGenOrRecMuonMomenta.value() == "gen":
234  process.muonDetHits.trackAssociator.muonMaxDistanceX = cms.double(1.e+3)
235  process.muonDetHits.trackAssociator.muonMaxDistanceX = cms.double(1.e+3)
236  process.muonDetHits.trackAssociator.dRMuonPreselection = cms.double(0.5)
237  process.ProductionFilterSequence += process.muonDetHits
238 
239  recHitMuonDetCleanerConfig = cms.PSet(
240  srcHitMapMuPlus = cms.InputTag("muonDetHits", "hitsMuPlus"),
241  srcHitMapMuMinus = cms.InputTag("muonDetHits", "hitsMuMinus"),
242  verbosity = cms.int32(0)
243  )
244 
245  if process.customization_options.muonMixingMode.value() == 2:
246  # CV: clone muon sequence for muon track segment reconstruction
247  configtools.cloneProcessingSnippet(process, process.muonlocalreco, "ORG")
248  process.reconstruction_step.replace(process.dt1DRecHits, process.muonlocalrecoORG*process.dt1DRecHits)
249 
250  if process.customization_options.muonMixingMode.value() == 1 or \
251  process.customization_options.muonMixingMode.value() == 2:
252  # mix recHits in CSC
253  print "Mixing CSC recHit collection"
254  process.csc2DRecHitsORG = process.csc2DRecHits.clone()
255  process.csc2DRecHits = cms.EDProducer("CSCRecHitMixer",
256  recHitMuonDetCleanerConfig,
257  todo = cms.VPSet(
258  cms.PSet(
259  collection1 = cms.InputTag("csc2DRecHitsORG", ""),
260  cleanCollection1 = cms.bool(False),
261  collection2 = cms.InputTag("csc2DRecHits", "", inputProcess),
262  cleanCollection2 = cms.bool(True)
263  )
264  )
265  )
266  replaceModule_or_Sequence(process, process.csc2DRecHits, process.csc2DRecHitsORG*process.csc2DRecHits)
267 
268  # mix recHits in DT
269  print "Mixing DT recHit collection"
270  process.dt1DRecHitsORG = process.dt1DRecHits.clone()
271  process.dt1DRecHits = cms.EDProducer("DTRecHitMixer",
272  recHitMuonDetCleanerConfig,
273  todo = cms.VPSet(
274  cms.PSet(
275  collection1 = cms.InputTag("dt1DRecHitsORG", ""),
276  cleanCollection1 = cms.bool(False),
277  collection2 = cms.InputTag("dt1DRecHits", "", inputProcess),
278  cleanCollection2 = cms.bool(True)
279  )
280  )
281  )
282  replaceModule_or_Sequence(process, process.dt1DRecHits, process.dt1DRecHitsORG*process.dt1DRecHits)
283 
284  # mix recHits in RPC
285  print "Mixing RPC recHit collection"
286  process.rpcRecHitsORG = process.rpcRecHits.clone()
287  process.rpcRecHits = cms.EDProducer("RPCRecHitMixer",
288  recHitMuonDetCleanerConfig,
289  todo = cms.VPSet(
290  cms.PSet(
291  collection1 = cms.InputTag("rpcRecHitsORG", ""),
292  cleanCollection1 = cms.bool(False),
293  collection2 = cms.InputTag("rpcRecHits", "", inputProcess),
294  cleanCollection2 = cms.bool(True)
295  )
296  )
297  )
298  replaceModule_or_Sequence(process, process.rpcRecHits, process.rpcRecHitsORG*process.rpcRecHits)
299 
300  if process.customization_options.muonMixingMode.value() == 2 or \
301  process.customization_options.muonMixingMode.value() == 3:
302 
303  # CV: need to switch to coarse positions to prevent exception
304  # when running 'glbTrackQual' module on mixed globalMuon collection
305  process.MuonTransientTrackingRecHitBuilderESProducerFromDisk = process.MuonTransientTrackingRecHitBuilderESProducer.clone(
306  ComponentName = cms.string('MuonRecHitBuilderFromDisk'),
307  ComputeCoarseLocalPositionFromDisk = cms.bool(True)
308  )
309  process.ttrhbwrFromDisk = process.ttrhbwr.clone(
310  ComponentName = cms.string('WithTrackAngleFromDisk'),
311  ComputeCoarseLocalPositionFromDisk = cms.bool(True)
312  )
313  process.glbTrackQual.RefitterParameters.MuonRecHitBuilder = cms.string('MuonRecHitBuilderFromDisk')
314  process.glbTrackQual.RefitterParameters.TrackerRecHitBuilder = cms.string('WithTrackAngleFromDisk')
315 
316  process.globalMuonsORG = process.globalMuons.clone()
317  process.cleanedGlobalMuons = cms.EDProducer("GlobalMuonTrackCleaner",
318  selectedMuons = process.customization_options.ZmumuCollection,
319  tracks = cms.VInputTag("globalMuons"),
320  dRmatch = cms.double(3.e-1),
321  removeDuplicates = cms.bool(True),
322  type = cms.string("links"),
323  srcMuons = cms.InputTag("muons"),
324  verbosity = cms.int32(0)
325  )
326  process.globalMuons = cms.EDProducer("GlobalMuonTrackMixer",
327  todo = cms.VPSet(
328  cms.PSet(
329  collection1 = cms.InputTag("globalMuonsORG", "", "EmbeddedRECO"),
330  collection2 = cms.InputTag("cleanedGlobalMuons"),
331  )
332  ),
333  verbosity = cms.int32(0)
334  )
335  replaceModule_or_Sequence(process, process.globalMuons, process.cleanedGlobalMuons*process.globalMuonsORG*process.globalMuons)
336 
337  process.standAloneMuonsORG = process.standAloneMuons.clone()
338  process.cleanedStandAloneMuons = process.cleanedGeneralTracks.clone(
339  tracks = cms.VInputTag(
340  cms.InputTag("standAloneMuons" ,""),
341  cms.InputTag("standAloneMuons", "UpdatedAtVtx"),
342  ),
343  type = cms.string("outer tracks"),
344  verbosity = cms.int32(0)
345  )
346  process.standAloneMuons = cms.EDProducer("TrackMixer",
347  todo = cms.VPSet(
348  cms.PSet(
349  collection1 = cms.InputTag("standAloneMuonsORG", "", "EmbeddedRECO"),
350  collection2 = cms.InputTag("cleanedStandAloneMuons", "")
351  ),
352  cms.PSet(
353  collection1 = cms.InputTag("standAloneMuonsORG", "UpdatedAtVtx", "EmbeddedRECO"),
354  collection2 = cms.InputTag("cleanedStandAloneMuons", "UpdatedAtVtx")
355  )
356  ),
357  verbosity = cms.int32(0)
358  )
359  replaceModule_or_Sequence(process, process.standAloneMuons, process.cleanedStandAloneMuons*process.standAloneMuonsORG*process.standAloneMuons)
360 
361  process.tevMuonsORG = process.tevMuons.clone()
362  if not process.customization_options.skipMuonDetRecHitMixing.value():
363  process.tevMuonsORG.RefitterParameters.CSCRecSegmentLabel = cms.InputTag("csc2DRecHitsORG")
364  process.tevMuonsORG.RefitterParameters.DTRecSegmentLabel = cms.InputTag("dt1DRecHitsORG")
365  process.tevMuonsORG.RefitterParameters.RPCRecSegmentLabel = cms.InputTag("rpcRecHitsORG")
366  process.tevMuonsORG.MuonCollectionLabel = cms.InputTag("globalMuonsORG")
367  process.cleanedTeVMuons = cms.EDProducer("TeVMuonTrackCleaner",
368  selectedMuons = process.customization_options.ZmumuCollection,
369  tracks = cms.VInputTag(
370  cms.InputTag("tevMuons", "default"),
371  cms.InputTag("tevMuons", "dyt"),
372  cms.InputTag("tevMuons", "firstHit"),
373  cms.InputTag("tevMuons", "picky")
374  ),
375  dRmatch = cms.double(3.e-1),
376  removeDuplicates = cms.bool(True),
377  type = cms.string("tev"),
378  srcGlobalMuons_cleaned = cms.InputTag("cleanedGlobalMuons"),
379  verbosity = cms.int32(0)
380  )
381  process.tevMuons = cms.EDProducer("TeVMuonTrackMixer",
382  todo = cms.VPSet(
383  cms.PSet(
384  collection1 = cms.InputTag("tevMuonsORG", "default", "EmbeddedRECO"),
385  collection2 = cms.InputTag("cleanedTeVMuons", "default")
386  ),
387  cms.PSet(
388  collection1 = cms.InputTag("tevMuonsORG", "dyt", "EmbeddedRECO"),
389  collection2 = cms.InputTag("cleanedTeVMuons", "dyt")
390  ),
391  cms.PSet(
392  collection1 = cms.InputTag("tevMuonsORG", "firstHit", "EmbeddedRECO"),
393  collection2 = cms.InputTag("cleanedTeVMuons", "firstHit")
394  ),
395  cms.PSet(
396  collection1 = cms.InputTag("tevMuonsORG", "picky", "EmbeddedRECO"),
397  collection2 = cms.InputTag("cleanedTeVMuons", "picky")
398  )
399  ),
400  srcGlobalMuons_cleaned = cms.InputTag("cleanedGlobalMuons"),
401  verbosity = cms.int32(0)
402  )
403  replaceModule_or_Sequence(process, process.tevMuons, process.cleanedTeVMuons*process.tevMuonsORG*process.tevMuons)
404 
405  return process
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8