CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pf_01_customizeAll.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 import FWCore.ParameterSet.Config as cms
3 import os
4 
5 from FWCore.ParameterSet.Modules import _Module
6 # Searches for self.lookFor module in cms.Path. When found, next and prev module is stored
8  def __init__(self, lookFor):
9  self.lookFor=lookFor
10  self.nextInChain="NONE"
11  self.prevInChain="NONE"
12  self.prevInChainCandidate="NONE"
13  self.catch=0 # 1 - we have found self.lookFor, at next visit write visitee
14  self.found=0
15 
16  def prepareSearch(self): # this should be called on beggining of each iteration
17  self.found=0
18 
19  def setLookFor(self, lookFor):
20  self.lookFor = lookFor
21 
22  def giveNext(self):
23  return self.nextInChain
24  def givePrev(self):
25  return self.prevInChain
26 
27  def enter(self,visitee):
28  if isinstance(visitee, _Module):
29  if self.catch == 1:
30  self.catch=0
31  self.nextInChain=visitee
32  self.found=1
33  if visitee == self.lookFor:
34  self.catch=1
35  self.prevInChain=self.prevInChainCandidate
36 
37  self.prevInChainCandidate=visitee
38 
39  def leave(self,visitee):
40  pass
41 
42 
43 
44 
45 
46 def customise(process):
47 
48 
49 
50  process._Process__name="EmbeddedRECO"
51  process.TFileService = cms.Service("TFileService", fileName = cms.string("histo_embedded.root") )
52 
53  try:
54  outputModule = process.output
55  except:
56  pass
57  try:
58  outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
59  except:
60  pass
61 
62  print "Changing eventcontent to RAW+AODSIM + misc. "
63  outputModule.outputCommands = cms.untracked.vstring("drop *")
64  outputModule.outputCommands.extend(process.RAWEventContent.outputCommands )
65  outputModule.outputCommands.extend(process.AODSIMEventContent.outputCommands )
66 
67  keepMC = cms.untracked.vstring("keep *_*_zMusExtracted_*",
68  "keep *_*_zmmCands_*",
69  "keep *_removedInputMuons_*_*",
70  "keep *_generator_*_*",
71  "keep *_PhotonIDProd_*_*",
72  "keep *_photons_*_*",
73  "keep *_photonCore_*_*",
74  "keep *_genParticles_*_*",
75  "keep *_particleFlow_*_*",
76  "keep *_generator_*_*",
77  "keep *_tmfTracks_*_EmbeddedRECO",
78  "keep *_offlinePrimaryVertices_*_EmbeddedRECO",
79  "keep *_offlinePrimaryVerticesWithBS_*_EmbeddedRECO",
80  "keep *_PhotonIDProd_*_*",
81  "keep *_photons_*_*",
82  "keep *_photonCore_*_*",
83  "keep *_genParticles_*_*",
84  "keep *_particleFlow_*_*",
85  )
86  outputModule.outputCommands.extend(keepMC)
87 
88  # getRid of second "drop *"
89  index = 0
90  for item in outputModule.outputCommands[:]:
91  if item == "drop *" and index != 0:
92  #print index," ",outputModule.outputCommands[index]
93  del outputModule.outputCommands[index]
94  index -= 1
95  index += 1
96 
97 
98  hltProcessName = "HLT" #"REDIGI38X"
99  RECOproc = "RECO"
100  # the following block can be used for more efficient processing by replacing the HLT variable below automatically
101  try:
102  hltProcessName = __HLT__
103  except:
104  pass
105 
106  try:
107  process.dimuonsHLTFilter.TriggerResultsTag.processName = hltProcessName
108  process.goodZToMuMuAtLeast1HLT.TrigTag.processName = hltProcessName
109  process.goodZToMuMuAtLeast1HLT.triggerEvent.processName = hltProcessName
110  process.hltTrigReport,HLTriggerResults.processName = hltProcessName
111  except:
112  pass
113 
114  process.VtxSmeared = cms.EDProducer("FlatEvtVtxGenerator",
115  MaxZ = cms.double(0.0),
116  MaxX = cms.double(0.0),
117  MaxY = cms.double(0.0),
118  MinX = cms.double(0.0),
119  MinY = cms.double(0.0),
120  MinZ = cms.double(0.0),
121  TimeOffset = cms.double(0.0),
122  src = cms.InputTag("generator")
123  )
124 
125  import FWCore.ParameterSet.VarParsing as VarParsing
126  options = VarParsing.VarParsing ('analysis')
127  options.register ('mdtau',
128  0, # default value
129  VarParsing.VarParsing.multiplicity.singleton,
130  VarParsing.VarParsing.varType.int,
131  "mdtau value for tauola")
132 
133  options.register ('transformationMode',
134  1, #default value
135  VarParsing.VarParsing.multiplicity.singleton,
136  VarParsing.VarParsing.varType.int,
137  "transformation mode. 0=mumu->mumu, 1=mumu->tautau")
138 
139  options.register ('minVisibleTransverseMomentum',
140  "", #default value
141  VarParsing.VarParsing.multiplicity.singleton,
142  VarParsing.VarParsing.varType.string,
143  "generator level cut on visible transverse momentum (typeN:pT,[...];[...])")
144 
145  options.register ('useJson',
146  0, # default value, false
147  VarParsing.VarParsing.multiplicity.singleton,
148  VarParsing.VarParsing.varType.int,
149  "should I enable json usage?")
150 
151  options.register ('overrideBeamSpot',
152  0, # default value, false
153  VarParsing.VarParsing.multiplicity.singleton,
154  VarParsing.VarParsing.varType.int,
155  "should I override beamspot in globaltag?")
156 
157 # options.register ('primaryProcess',
158 # 'RECO', # default value
159 # VarParsing.VarParsing.multiplicity.singleton,
160 # VarParsing.VarParsing.varType.string,
161 # "original processName")
162 
163 
164  setFromCL = False
165  if not hasattr(process,"doNotParse"):
166  import sys
167  if hasattr(sys, "argv") == True:
168  if not sys.argv[0].endswith('cmsDriver.py'):
169  options.parseArguments()
170  setFromCL = True
171  else:
172  print "CL parsing disabled!"
173  if setFromCL:
174  print "Setting mdtau to ", options.mdtau
175  process.generator.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau
176  process.newSource.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau
177  process.generator.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau
178  process.newSource.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau
179 
180  print "Setting minVisibleTransverseMomentum to ", options.minVisibleTransverseMomentum
181  process.newSource.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
182  process.generator.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
183 
184  print "Setting transformationMode to ", options.transformationMode
185  process.generator.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
186  process.newSource.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
187 
188  print "options.overrideBeamSpot", options.overrideBeamSpot
189  if options.overrideBeamSpot != 0:
190  bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v26_offline") # 52x data PR gt
191  # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v21_offline") # 42x data PR gt
192  # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v18_offline") # 41x data PR gt
193  # bs = cms.string("BeamSpotObjects_2009_LumiBased_v17_offline") # 38x data gt
194  #bs = cms.string("BeamSpotObjects_2009_v14_offline") # 36x data gt
195  # tag = cms.string("Early10TeVCollision_3p8cm_31X_v1_mc_START"), # 35 default
196  # tag = cms.string("Realistic900GeVCollisions_10cm_STARTUP_v1_mc"), # 36 default
197  process.GlobalTag.toGet = cms.VPSet(
198  cms.PSet(record = cms.string("BeamSpotObjectsRcd"),
199  tag = bs,
200  connect = cms.untracked.string("frontier://FrontierProd/CMS_COND_31X_BEAMSPOT")
201  )
202  )
203  print "BeamSpot in globaltag set to ", bs
204  else:
205  print "BeamSpot in globaltag not changed"
206 
207  if options.useJson != 0:
208  print "Enabling json usage"
209  import PhysicsTools.PythonAnalysis.LumiList as LumiList
210  import FWCore.ParameterSet.Types as CfgTypes
211  myLumis = LumiList.LumiList(filename = 'my.json').getCMSSWString().split(',')
212  process.source.lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange())
213  process.source.lumisToProcess.extend(myLumis)
214 
215 # -*- coding: utf-8 -*-
216 
217 
218  process.tmfTracks = cms.EDProducer("RecoTracksMixer",
219  trackCol1 = cms.InputTag("removedInputMuons","tracks"),
220  trackCol2 = cms.InputTag("generalTracks","","EmbeddedRECO")
221  )
222 
223  process.offlinePrimaryVerticesWithBS.TrackLabel = cms.InputTag("tmfTracks")
224  process.offlinePrimaryVertices.TrackLabel = cms.InputTag("tmfTracks")
225 
226  if hasattr(process.muons, "TrackExtractorPSet"):
227  process.muons.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
228  elif hasattr(process, "muons1stStep") and hasattr(process.muons1stStep, "TrackExtractorPSet"):
229  process.muons1stStep.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
230  else:
231  raise "Problem with muons"
232  # it should be the best solution to take the original beam spot for the
233  # reconstruction of the new primary vertex
234  # use the one produced earlier, do not produce your own
235  for s in process.sequences:
236  seq = getattr(process,s)
237  seq.remove(process.offlineBeamSpot)
238 
239 
240  try:
241  process.metreco.remove(process.BeamHaloId)
242  except:
243  pass
244 
245  try:
246  outputModule = process.output
247  except:
248  pass
249  try:
250  outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
251  except:
252  pass
253 
254 
255  for p in process.paths:
256  pth = getattr(process,p)
257  if "generalTracks" in pth.moduleNames():
258  pth.replace(process.generalTracks, process.generalTracks*process.tmfTracks)
259 
260 
261  #'''
262  process.gsfElectronsORG = process.gsfElectrons.clone()
263  #print dir(process)
264  #for p in dir(process):
265 
266  for p in process.paths:
267  pth = getattr(process,p)
268  #if hasattr(pth,"gsfElectrons"):
269  if "gsfElectrons" in pth.moduleNames():
270  pth.replace(process.gsfElectrons, process.gsfElectronsORG*process.gsfElectrons)
271  #print p, dir(pth.moduleNames())
272 
273  # xxx
274  process.gsfElectrons = cms.EDProducer("GSFElectronsMixer",
275  col1 = cms.InputTag("gsfElectronsORG"),
276  col2 = cms.InputTag("gsfElectrons","", RECOproc )
277  )
278  #'''
279 
280 
281 
282  process.particleFlowORG = process.particleFlow.clone()
283 
284  # Since CMSSW 4_4 the particleFlow reco works a bit differently. The step is
285  # twofold, first particleFlowTmp is created and then the final particleFlow
286  # collection. What we do in this case is that we merge the final ParticleFlow
287  # collection. For the muon reconstruction, we also merge particleFlowTmp in
288  # order to get PF-based isolation right.
289  if hasattr(process, 'particleFlowTmp'):
290  process.particleFlowTmpMixed = cms.EDProducer('PFCandidateMixer',
291  col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
292  col2 = cms.untracked.InputTag("particleFlowTmp", ""),
293  trackCol = cms.untracked.InputTag("tmfTracks"),
294 
295  # Don't produce value maps:
296  muons = cms.untracked.InputTag(""),
297  gsfElectrons = cms.untracked.InputTag("")
298  )
299  process.muons.PFCandidates = cms.InputTag("particleFlowTmpMixed")
300 
301  for p in process.paths:
302  if "particleFlow" in pth.moduleNames():
303  pth.replace(process.particleFlow, process.particleFlowORG*process.particleFlow)
304  if "muons" in pth.moduleNames():
305  pth.replace(process.muons, process.particleFlowTmpMixed*process.muons)
306  else:
307  # CMSSW_4_2
308  if hasattr(process,"famosParticleFlowSequence"):
309  process.famosParticleFlowSequence.remove(process.pfPhotonTranslatorSequence)
310  process.famosParticleFlowSequence.remove(process.pfElectronTranslatorSequence)
311  process.famosParticleFlowSequence.remove(process.particleFlow)
312  process.famosParticleFlowSequence.__iadd__(process.particleFlowORG)
313  process.famosParticleFlowSequence.__iadd__(process.particleFlow)
314  process.famosParticleFlowSequence.__iadd__(process.pfElectronTranslatorSequence)
315  process.famosParticleFlowSequence.__iadd__(process.pfPhotonTranslatorSequence)
316  elif hasattr(process,"particleFlowReco"):
317  process.particleFlowReco.remove(process.pfPhotonTranslatorSequence)
318  process.particleFlowReco.remove(process.pfElectronTranslatorSequence)
319  process.particleFlowReco.remove(process.particleFlow)
320  process.particleFlowReco.__iadd__(process.particleFlowORG)
321  process.particleFlowReco.__iadd__(process.particleFlow)
322  process.particleFlowReco.__iadd__(process.pfElectronTranslatorSequence)
323  process.particleFlowReco.__iadd__(process.pfPhotonTranslatorSequence)
324  else :
325  raise "Cannot find particleFlow sequence"
326 
327  process.pfSelectedElectrons.src = cms.InputTag("particleFlowORG")
328  process.pfSelectedPhotons.src = cms.InputTag("particleFlowORG")
329 
330 
331  process.particleFlow = cms.EDProducer('PFCandidateMixer',
332  col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
333  col2 = cms.untracked.InputTag("particleFlowORG", ""),
334  trackCol = cms.untracked.InputTag("tmfTracks"),
335 
336  muons = cms.untracked.InputTag("muons"),
337  gsfElectrons = cms.untracked.InputTag("gsfElectrons")
338  # TODO: photons???
339  )
340 
341  process.filterEmptyEv.src = cms.untracked.InputTag("generator","","EmbeddedRECO")
342 
343  from FWCore.ParameterSet.Types import InputTag
344  for p in process.paths:
345  i = getattr(process,p)
346  target = process.particleFlow
347 
348  seqVis = SeqVisitor(target)
349  seqVis.prepareSearch()
350  seqVis.setLookFor(target)
351  i.visit(seqVis)
352  while ( seqVis.catch != 1 and seqVis.found == 1 ):
353 
354  target = seqVis.giveNext()
355 
356  targetAttributes = dir(target)
357  for targetAttribute in targetAttributes:
358  attr=getattr(target,targetAttribute) # get actual attribute, not just the name
359  if isinstance(attr, InputTag) and attr.getModuleLabel()=="particleFlow":
360  if ( attr.getProductInstanceLabel()!="" ):
361  print "Changing: ", target, " ", targetAttribute, " ", attr, " to particleFlowORG"
362  attr.setModuleLabel("particleFlowORG")
363 
364 
365  #i.replace(target, source)
366  seqVis.prepareSearch()
367  seqVis.setLookFor(target)
368  i.visit(seqVis)
369 
370  #if (seqVis.catch==1):
371  #seqVis.catch=0
372  #i.__iadd__(source)
373 
374 
375  if hasattr(process, "DQM_FEDIntegrity_v3"):
376  process.schedule.remove(process.DQM_FEDIntegrity_v3)
377 
378  skimEnabled = False
379  if hasattr(process,"doZmumuSkim"):
380  print "Enabling Zmumu skim"
381  skimEnabled = True
382 
383  cmssw_ver = os.environ["CMSSW_VERSION"]
384  if cmssw_ver.find("CMSSW_4_2") != -1:
385  print
386  print "Using legacy version of Zmumu skim. Note, that muon isolation is disabled"
387  print
388  process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelectionLegacy_cff")
389  process.RandomNumberGeneratorService.dummy = cms.PSet(
390  initialSeed = cms.untracked.uint32(123456789),
391  engineName = cms.untracked.string('HepJamesRandom')
392  )
393 
394  else:
395  process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelection_cff")
396 
397  #process.load("TauAnalysis/Skimming/goldenZmmSelectionVBTFrelPFIsolation_cfi")
398  process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi")
399 
400  # we are allready selecting events from generation step, so following way is ok
401  for path in process.paths:
402  getattr(process,path)._seq = process.goldenZmumuSelectionSequence * getattr(process,path)._seq
403 
404  #process.options = cms.untracked.PSet(
405  # wantSummary = cms.untracked.bool(True)
406  #)
407 
408 
409  if not skimEnabled:
410  print "Zmumu skim not enabled"
411 
412 
413  print "# ######################################################################################"
414  print " Following parameters can be added before customize function "
415  print " call in order to controll process customization: "
416  print " process.doNotParse = cms.PSet() # disables CL parsing for crab compat"
417  print " process.doZmumuSkim = cms.PSet() # adds Zmumu skimming before embedding is run"
418  print "# ######################################################################################"
419 
420  return(process)
list object
Definition: dbtoconf.py:77
dbl *** dir
Definition: mlp_gen.cc:35
double split
Definition: MVATrainer.cc:139
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run