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 def customise(process):
43 
44  process._Process__name="EmbeddedRECO"
45  process.TFileService = cms.Service("TFileService", fileName = cms.string("histo_embedded.root") )
46 
47  try:
48  outputModule = process.output
49  except:
50  pass
51  try:
52  outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
53  except:
54  pass
55 
56  print "Changing eventcontent to RAW+AODSIM + misc. "
57  outputModule.outputCommands = cms.untracked.vstring("drop *")
58  outputModule.outputCommands.extend(process.RAWEventContent.outputCommands )
59  outputModule.outputCommands.extend(process.AODSIMEventContent.outputCommands )
60 
61  keepMC = cms.untracked.vstring("keep *_*_zMusExtracted_*",
62  "keep *_*_zmmCands_*",
63  "keep *_removedInputMuons_*_*",
64  "keep *_generator_*_*",
65  "keep *_PhotonIDProd_*_*",
66  "keep *_photons_*_*",
67  "keep *_photonCore_*_*",
68  "keep *_genParticles_*_*",
69  "keep *_particleFlow_*_*",
70  "keep *_generator_*_*",
71  "keep *_tmfTracks_*_EmbeddedRECO",
72  "keep *_offlinePrimaryVertices_*_EmbeddedRECO",
73  "keep *_offlinePrimaryVerticesWithBS_*_EmbeddedRECO",
74  "keep *_PhotonIDProd_*_*",
75  "keep *_photons_*_*",
76  "keep *_photonCore_*_*",
77  "keep *_genParticles_*_*",
78  "keep *_particleFlow_*_*",
79  )
80  outputModule.outputCommands.extend(keepMC)
81 
82  # getRid of second "drop *"
83  index = 0
84  for item in outputModule.outputCommands[:]:
85  if item == "drop *" and index != 0:
86  #print index," ",outputModule.outputCommands[index]
87  del outputModule.outputCommands[index]
88  index -= 1
89  index += 1
90 
91 
92  hltProcessName = "HLT" #"REDIGI38X"
93  RECOproc = "RECO"
94  # the following block can be used for more efficient processing by replacing the HLT variable below automatically
95  try:
96  hltProcessName = __HLT__
97  except:
98  pass
99 
100  try:
101  process.dimuonsHLTFilter.TriggerResultsTag.processName = hltProcessName
102  process.goodZToMuMuAtLeast1HLT.TrigTag.processName = hltProcessName
103  process.goodZToMuMuAtLeast1HLT.triggerEvent.processName = hltProcessName
104  process.hltTrigReport,HLTriggerResults.processName = hltProcessName
105  except:
106  pass
107 
108  process.VtxSmeared = cms.EDProducer("FlatEvtVtxGenerator",
109  MaxZ = cms.double(0.0),
110  MaxX = cms.double(0.0),
111  MaxY = cms.double(0.0),
112  MinX = cms.double(0.0),
113  MinY = cms.double(0.0),
114  MinZ = cms.double(0.0),
115  TimeOffset = cms.double(0.0),
116  src = cms.InputTag("generator")
117  )
118 
119  import FWCore.ParameterSet.VarParsing as VarParsing
120  options = VarParsing.VarParsing ('analysis')
121  options.register ('mdtau',
122  0, # default value
123  VarParsing.VarParsing.multiplicity.singleton,
124  VarParsing.VarParsing.varType.int,
125  "mdtau value for tauola")
126 
127  options.register ('transformationMode',
128  1, #default value
129  VarParsing.VarParsing.multiplicity.singleton,
130  VarParsing.VarParsing.varType.int,
131  "transformation mode. 0=mumu->mumu, 1=mumu->tautau")
132 
133  options.register ('minVisibleTransverseMomentum',
134  "", #default value
135  VarParsing.VarParsing.multiplicity.singleton,
136  VarParsing.VarParsing.varType.string,
137  "generator level cut on visible transverse momentum (typeN:pT,[...];[...])")
138 
139  options.register ('useJson',
140  0, # default value, false
141  VarParsing.VarParsing.multiplicity.singleton,
142  VarParsing.VarParsing.varType.int,
143  "should I enable json usage?")
144 
145  options.register ('overrideBeamSpot',
146  0, # default value, false
147  VarParsing.VarParsing.multiplicity.singleton,
148  VarParsing.VarParsing.varType.int,
149  "should I override beamspot in globaltag?")
150 
151  options.register ('skimEnabled',
152  0, # default value, true
153  VarParsing.VarParsing.multiplicity.singleton,
154  VarParsing.VarParsing.varType.int,
155  "should I apply Zmumu event selection cuts?")
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  process.tmfTracks = cms.EDProducer("RecoTracksMixer",
218  trackCol1 = cms.InputTag("removedInputMuons","tracks"),
219  trackCol2 = cms.InputTag("generalTracks","","EmbeddedRECO")
220  )
221 
222  process.offlinePrimaryVerticesWithBS.TrackLabel = cms.InputTag("tmfTracks")
223  process.offlinePrimaryVertices.TrackLabel = cms.InputTag("tmfTracks")
224 
225  if hasattr(process.muons, "TrackExtractorPSet"):
226  process.muons.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
227  elif hasattr(process, "muons1stStep") and hasattr(process.muons1stStep, "TrackExtractorPSet"):
228  process.muons1stStep.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
229  else:
230  raise "Problem with muons"
231  # it should be the best solution to take the original beam spot for the
232  # reconstruction of the new primary vertex
233  # use the one produced earlier, do not produce your own
234  for s in process.sequences:
235  seq = getattr(process,s)
236  seq.remove(process.offlineBeamSpot)
237 
238  try:
239  process.metreco.remove(process.BeamHaloId)
240  except:
241  pass
242 
243  try:
244  outputModule = process.output
245  except:
246  pass
247  try:
248  outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
249  except:
250  pass
251 
252  for p in process.paths:
253  pth = getattr(process,p)
254  if "generalTracks" in pth.moduleNames():
255  pth.replace(process.generalTracks, process.generalTracks*process.tmfTracks)
256 
257  #'''
258  process.gsfElectronsORG = process.gsfElectrons.clone()
259  #print dir(process)
260  #for p in dir(process):
261 
262  for p in process.paths:
263  pth = getattr(process,p)
264  #if hasattr(pth,"gsfElectrons"):
265  if "gsfElectrons" in pth.moduleNames():
266  pth.replace(process.gsfElectrons, process.gsfElectronsORG*process.gsfElectrons)
267  #print p, dir(pth.moduleNames())
268 
269  # xxx
270  process.gsfElectrons = cms.EDProducer("GSFElectronsMixer",
271  col1 = cms.InputTag("gsfElectronsORG"),
272  col2 = cms.InputTag("gsfElectrons","", RECOproc )
273  )
274  #'''
275 
276  process.particleFlowORG = process.particleFlow.clone()
277 
278  # Since CMSSW 4_4 the particleFlow reco works a bit differently. The step is
279  # twofold, first particleFlowTmp is created and then the final particleFlow
280  # collection. What we do in this case is that we merge the final ParticleFlow
281  # collection. For the muon reconstruction, we also merge particleFlowTmp in
282  # order to get PF-based isolation right.
283  if hasattr(process, 'particleFlowTmp'):
284  process.particleFlowTmpMixed = cms.EDProducer('PFCandidateMixer',
285  col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
286  col2 = cms.untracked.InputTag("particleFlowTmp", ""),
287  trackCol = cms.untracked.InputTag("tmfTracks"),
288 
289  # Don't produce value maps:
290  muons = cms.untracked.InputTag(""),
291  gsfElectrons = cms.untracked.InputTag("")
292  )
293  process.muons.PFCandidates = cms.InputTag("particleFlowTmpMixed")
294 
295  for p in process.paths:
296  if "particleFlow" in pth.moduleNames():
297  pth.replace(process.particleFlow, process.particleFlowORG*process.particleFlow)
298  if "muons" in pth.moduleNames():
299  pth.replace(process.muons, process.particleFlowTmpMixed*process.muons)
300  else:
301  # CMSSW_4_2
302  if hasattr(process,"famosParticleFlowSequence"):
303  process.famosParticleFlowSequence.remove(process.pfPhotonTranslatorSequence)
304  process.famosParticleFlowSequence.remove(process.pfElectronTranslatorSequence)
305  process.famosParticleFlowSequence.remove(process.particleFlow)
306  process.famosParticleFlowSequence.__iadd__(process.particleFlowORG)
307  process.famosParticleFlowSequence.__iadd__(process.particleFlow)
308  process.famosParticleFlowSequence.__iadd__(process.pfElectronTranslatorSequence)
309  process.famosParticleFlowSequence.__iadd__(process.pfPhotonTranslatorSequence)
310  elif hasattr(process,"particleFlowReco"):
311  process.particleFlowReco.remove(process.pfPhotonTranslatorSequence)
312  process.particleFlowReco.remove(process.pfElectronTranslatorSequence)
313  process.particleFlowReco.remove(process.particleFlow)
314  process.particleFlowReco.__iadd__(process.particleFlowORG)
315  process.particleFlowReco.__iadd__(process.particleFlow)
316  process.particleFlowReco.__iadd__(process.pfElectronTranslatorSequence)
317  process.particleFlowReco.__iadd__(process.pfPhotonTranslatorSequence)
318  else :
319  raise "Cannot find particleFlow sequence"
320 
321  process.pfSelectedElectrons.src = cms.InputTag("particleFlowORG")
322  process.pfSelectedPhotons.src = cms.InputTag("particleFlowORG")
323 
324  process.particleFlow = cms.EDProducer('PFCandidateMixer',
325  col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
326  col2 = cms.untracked.InputTag("particleFlowORG", ""),
327  trackCol = cms.untracked.InputTag("tmfTracks"),
328 
329  muons = cms.untracked.InputTag("muons"),
330  gsfElectrons = cms.untracked.InputTag("gsfElectrons")
331  # TODO: photons???
332  )
333 
334  process.filterEmptyEv.src = cms.untracked.InputTag("generator","","EmbeddedRECO")
335 
336  from FWCore.ParameterSet.Types import InputTag
337  for p in process.paths:
338  i = getattr(process,p)
339  target = process.particleFlow
340 
341  seqVis = SeqVisitor(target)
342  seqVis.prepareSearch()
343  seqVis.setLookFor(target)
344  i.visit(seqVis)
345  while ( seqVis.catch != 1 and seqVis.found == 1 ):
346 
347  target = seqVis.giveNext()
348 
349  targetAttributes = dir(target)
350  for targetAttribute in targetAttributes:
351  attr=getattr(target,targetAttribute) # get actual attribute, not just the name
352  if isinstance(attr, InputTag) and attr.getModuleLabel()=="particleFlow":
353  if ( attr.getProductInstanceLabel()!="" ):
354  print "Changing: ", target, " ", targetAttribute, " ", attr, " to particleFlowORG"
355  attr.setModuleLabel("particleFlowORG")
356 
357  #i.replace(target, source)
358  seqVis.prepareSearch()
359  seqVis.setLookFor(target)
360  i.visit(seqVis)
361 
362  #if (seqVis.catch==1):
363  #seqVis.catch=0
364  #i.__iadd__(source)
365 
366  # CV: mix L1Extra collections
367  l1ExtraCollections = [
368  [ "L1EmParticle", "Isolated" ],
369  [ "L1EmParticle", "NonIsolated" ],
370  [ "L1EtMissParticle", "MET" ],
371  [ "L1EtMissParticle", "MHT" ],
372  [ "L1JetParticle", "Central" ],
373  [ "L1JetParticle", "Forward" ],
374  [ "L1JetParticle", "Tau" ],
375  [ "L1MuonParticle", "" ]
376  ]
377  l1extraParticleCollections = []
378  for l1ExtraCollection in l1ExtraCollections:
379  inputType = l1ExtraCollection[0]
380  pluginType = None
381  if inputType == "L1EmParticle":
382  pluginType = "L1ExtraEmParticleMixerPlugin"
383  elif inputType == "L1EtMissParticle":
384  pluginType = "L1ExtraMEtMixerPlugin"
385  elif inputType == "L1JetParticle":
386  pluginType = "L1ExtraJetParticleMixerPlugin"
387  elif inputType == "L1MuonParticle":
388  pluginType = "L1ExtraMuonParticleMixerPlugin"
389  else:
390  raise ValueError("Invalid L1Extra type = %s !!" % inputType)
391  instanceLabel = l1ExtraCollection[1]
392  l1extraParticleCollections.append(cms.PSet(
393  pluginType = cms.string(pluginType),
394  instanceLabel = cms.string(instanceLabel)))
395  process.l1extraParticlesORG = process.l1extraParticles.clone()
396  process.l1extraParticles = cms.EDProducer('L1ExtraMixer',
397  src1 = cms.InputTag('l1extraParticles::HLT'),
398  src2 = cms.InputTag('l1extraParticlesORG'),
399  collections = cms.VPSet(l1extraParticleCollections)
400  )
401  for p in process.paths:
402  pth = getattr(process,p)
403  if "l1extraParticles" in pth.moduleNames():
404  pth.replace(process.l1extraParticles, process.l1extraParticlesORG*process.l1extraParticles)
405 
406  #if hasattr(process, "DQM_FEDIntegrity_v3"):
407  # process.schedule.remove(process.DQM_FEDIntegrity_v3)
408  fedIntRemoved = False
409  for i in range(1,30):
410  attrName = "DQM_FEDIntegrity_v"+str(i)
411  if hasattr(process, attrName ):
412  process.schedule.remove(process.DQM_FEDIntegrity_v11)
413  del process.DTDataIntegrityTask
414  fedIntRemoved = True
415  break
416 
417  if fedIntRemoved:
418  print "Removed", attrName
419  else:
420  print "DQM_FEDIntegrity_vXX not found, expect problems"
421 
422  skimEnabled = False
423  if setFromCL:
424  if options.skimEnabled != 0:
425  skimEnabled = True
426  else:
427  if hasattr(process,"doZmumuSkim"):
428  skimEnabled = True
429  if skimEnabled:
430  print "Enabling Zmumu skim"
431  skimEnabled = True
432 
433  cmssw_ver = os.environ["CMSSW_VERSION"]
434  if cmssw_ver.find("CMSSW_4_2") != -1:
435  print
436  print "Using legacy version of Zmumu skim. Note, that muon isolation is disabled"
437  print
438  process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelectionLegacy_cff")
439  process.RandomNumberGeneratorService.dummy = cms.PSet(
440  initialSeed = cms.untracked.uint32(123456789),
441  engineName = cms.untracked.string('HepJamesRandom')
442  )
443 
444  else:
445  process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelection_cff")
446 
447  #process.load("TauAnalysis/Skimming/goldenZmmSelectionVBTFrelPFIsolation_cfi")
448  process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi")
449 
450  # we are allready selecting events from generation step, so following way is ok
451  for path in process.paths:
452  getattr(process,path)._seq = process.goldenZmumuSelectionSequence * getattr(process,path)._seq
453 
454  #process.options = cms.untracked.PSet(
455  # wantSummary = cms.untracked.bool(True)
456  #)
457  else:
458  print "Zmumu skim not enabled"
459  # CV: add path for keeping track of skimming efficiency
460  process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelection_cff")
461  process.skimEffFlag = cms.EDProducer("DummyBoolEventSelFlagProducer")
462  process.skimEffPath = cms.Path(process.goldenZmumuSelectionSequence * process.skimEffFlag)
463 
464  process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi")
465 
466  print "# ######################################################################################"
467  print " Following parameters can be added before customize function "
468  print " call in order to controll process customization: "
469  print " process.doNotParse = cms.PSet() # disables CL parsing for crab compat"
470  print " process.doZmumuSkim = cms.PSet() # adds Zmumu skimming before embedding is run"
471  print "# ######################################################################################"
472 
473  return(process)
list object
Definition: dbtoconf.py:77
return(e1-e2)*(e1-e2)+dp *dp
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