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  # the following block can be used for more efficient processing by replacing the HLT variable below automatically
100  try:
101  hltProcessName = __HLT__
102  except:
103  pass
104 
105  try:
106  process.dimuonsHLTFilter.TriggerResultsTag.processName = hltProcessName
107  process.goodZToMuMuAtLeast1HLT.TrigTag.processName = hltProcessName
108  process.goodZToMuMuAtLeast1HLT.triggerEvent.processName = hltProcessName
109  process.hltTrigReport,HLTriggerResults.processName = hltProcessName
110  except:
111  pass
112 
113  process.VtxSmeared = cms.EDProducer("FlatEvtVtxGenerator",
114  MaxZ = cms.double(0.0),
115  MaxX = cms.double(0.0),
116  MaxY = cms.double(0.0),
117  MinX = cms.double(0.0),
118  MinY = cms.double(0.0),
119  MinZ = cms.double(0.0),
120  TimeOffset = cms.double(0.0),
121  src = cms.InputTag("generator")
122  )
123 
124  import FWCore.ParameterSet.VarParsing as VarParsing
125  options = VarParsing.VarParsing ('analysis')
126  options.register ('mdtau',
127  0, # default value
128  VarParsing.VarParsing.multiplicity.singleton,
129  VarParsing.VarParsing.varType.int,
130  "mdtau value for tauola")
131 
132  options.register ('transformationMode',
133  1, #default value
134  VarParsing.VarParsing.multiplicity.singleton,
135  VarParsing.VarParsing.varType.int,
136  "transformation mode. 0=mumu->mumu, 1=mumu->tautau")
137 
138  options.register ('minVisibleTransverseMomentum',
139  "", #default value
140  VarParsing.VarParsing.multiplicity.singleton,
141  VarParsing.VarParsing.varType.string,
142  "generator level cut on visible transverse momentum (typeN:pT,[...];[...])")
143 
144  options.register ('useJson',
145  0, # default value, false
146  VarParsing.VarParsing.multiplicity.singleton,
147  VarParsing.VarParsing.varType.int,
148  "should I enable json usage?")
149 
150  options.register ('overrideBeamSpot',
151  0, # default value, false
152  VarParsing.VarParsing.multiplicity.singleton,
153  VarParsing.VarParsing.varType.int,
154  "should I override beamspot in globaltag?")
155 
156 # options.register ('primaryProcess',
157 # 'RECO', # default value
158 # VarParsing.VarParsing.multiplicity.singleton,
159 # VarParsing.VarParsing.varType.string,
160 # "original processName")
161 
162 
163  setFromCL = False
164  if not hasattr(process,"doNotParse"):
165  import sys
166  if hasattr(sys, "argv") == True:
167  if not sys.argv[0].endswith('cmsDriver.py'):
168  options.parseArguments()
169  setFromCL = True
170  else:
171  print "CL parsing disabled!"
172  if setFromCL:
173  print "Setting mdtau to ", options.mdtau
174  process.generator.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau
175  process.newSource.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau
176  process.generator.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau
177  process.newSource.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau
178 
179  print "Setting minVisibleTransverseMomentum to ", options.minVisibleTransverseMomentum
180  process.newSource.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
181  process.generator.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
182 
183  print "Setting transformationMode to ", options.transformationMode
184  process.generator.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
185  process.newSource.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
186 
187  print "options.overrideBeamSpot", options.overrideBeamSpot
188  if options.overrideBeamSpot != 0:
189  bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v26_offline") # 52x data PR gt
190  # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v21_offline") # 42x data PR gt
191  # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v18_offline") # 41x data PR gt
192  # bs = cms.string("BeamSpotObjects_2009_LumiBased_v17_offline") # 38x data gt
193  #bs = cms.string("BeamSpotObjects_2009_v14_offline") # 36x data gt
194  # tag = cms.string("Early10TeVCollision_3p8cm_31X_v1_mc_START"), # 35 default
195  # tag = cms.string("Realistic900GeVCollisions_10cm_STARTUP_v1_mc"), # 36 default
196  process.GlobalTag.toGet = cms.VPSet(
197  cms.PSet(record = cms.string("BeamSpotObjectsRcd"),
198  tag = bs,
199  connect = cms.untracked.string("frontier://FrontierProd/CMS_COND_31X_BEAMSPOT")
200  )
201  )
202  print "BeamSpot in globaltag set to ", bs
203  else:
204  print "BeamSpot in globaltag not changed"
205 
206  if options.useJson != 0:
207  print "Enabling json usage"
208  import PhysicsTools.PythonAnalysis.LumiList as LumiList
209  import FWCore.ParameterSet.Types as CfgTypes
210  myLumis = LumiList.LumiList(filename = 'my.json').getCMSSWString().split(',')
211  process.source.lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange())
212  process.source.lumisToProcess.extend(myLumis)
213 
214 # -*- coding: utf-8 -*-
215 
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  if hasattr(process.muons, "TrackExtractorPSet"):
225  process.muons.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
226  elif hasattr(process, "muons1stStep") and hasattr(process.muons1stStep, "TrackExtractorPSet"):
227  process.muons1stStep.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
228  else:
229  raise "Problem with muons"
230  # it should be the best solution to take the original beam spot for the
231  # reconstruction of the new primary vertex
232  # use the one produced earlier, do not produce your own
233  for s in process.sequences:
234  seq = getattr(process,s)
235  seq.remove(process.offlineBeamSpot)
236 
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 
253  for p in process.paths:
254  pth = getattr(process,p)
255  if "generalTracks" in pth.moduleNames():
256  pth.replace(process.generalTracks, process.generalTracks*process.tmfTracks)
257 
258 
259  process.particleFlowORG = process.particleFlow.clone()
260 
261  # Since CMSSW 4_4 the particleFlow reco works a bit differently. The step is
262  # twofold, first particleFlowTmp is created and then the final particleFlow
263  # collection. What we do in this case is that we merge the final ParticleFlow
264  # collection. For the muon reconstruction, we also merge particleFlowTmp in
265  # order to get PF-based isolation right.
266  if hasattr(process, 'particleFlowTmp'):
267  process.particleFlowTmpMixed = cms.EDProducer('PFCandidateMixer',
268  col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
269  col2 = cms.untracked.InputTag("particleFlowTmp", ""),
270  trackCol = cms.untracked.InputTag("tmfTracks")
271  )
272  process.muons.PFCandidates = cms.InputTag("particleFlowTmpMixed")
273 
274  for p in process.paths:
275  if "particleFlow" in pth.moduleNames():
276  pth.replace(process.particleFlow, process.particleFlowORG*process.particleFlow)
277  if "muons" in pth.moduleNames():
278  pth.replace(process.muons, process.particleFlowTmpMixed*process.muons)
279  else:
280  # CMSSW_4_2
281  if hasattr(process,"famosParticleFlowSequence"):
282  process.famosParticleFlowSequence.remove(process.pfPhotonTranslatorSequence)
283  process.famosParticleFlowSequence.remove(process.pfElectronTranslatorSequence)
284  process.famosParticleFlowSequence.remove(process.particleFlow)
285  process.famosParticleFlowSequence.__iadd__(process.particleFlowORG)
286  process.famosParticleFlowSequence.__iadd__(process.particleFlow)
287  process.famosParticleFlowSequence.__iadd__(process.pfElectronTranslatorSequence)
288  process.famosParticleFlowSequence.__iadd__(process.pfPhotonTranslatorSequence)
289  elif hasattr(process,"particleFlowReco"):
290  process.particleFlowReco.remove(process.pfPhotonTranslatorSequence)
291  process.particleFlowReco.remove(process.pfElectronTranslatorSequence)
292  process.particleFlowReco.remove(process.particleFlow)
293  process.particleFlowReco.__iadd__(process.particleFlowORG)
294  process.particleFlowReco.__iadd__(process.particleFlow)
295  process.particleFlowReco.__iadd__(process.pfElectronTranslatorSequence)
296  process.particleFlowReco.__iadd__(process.pfPhotonTranslatorSequence)
297  else :
298  raise "Cannot find particleFlow sequence"
299 
300  process.pfSelectedElectrons.src = cms.InputTag("particleFlowORG")
301  process.pfSelectedPhotons.src = cms.InputTag("particleFlowORG")
302 
303 
304  process.particleFlow = cms.EDProducer('PFCandidateMixer',
305  col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
306  col2 = cms.untracked.InputTag("particleFlowORG", ""),
307  trackCol = cms.untracked.InputTag("tmfTracks")
308  )
309 
310  process.filterEmptyEv.src = cms.untracked.InputTag("generator","","EmbeddedRECO")
311 
312  from FWCore.ParameterSet.Types import InputTag
313  for p in process.paths:
314  i = getattr(process,p)
315  target = process.particleFlow
316 
317  seqVis = SeqVisitor(target)
318  seqVis.prepareSearch()
319  seqVis.setLookFor(target)
320  i.visit(seqVis)
321  while ( seqVis.catch != 1 and seqVis.found == 1 ):
322 
323  target = seqVis.giveNext()
324 
325  targetAttributes = dir(target)
326  for targetAttribute in targetAttributes:
327  attr=getattr(target,targetAttribute) # get actual attribute, not just the name
328  if isinstance(attr, InputTag) and attr.getModuleLabel()=="particleFlow":
329  if ( attr.getProductInstanceLabel()!="" ):
330  print "Changing: ", target, " ", targetAttribute, " ", attr, " to particleFlowORG"
331  attr.setModuleLabel("particleFlowORG")
332 
333 
334  #i.replace(target, source)
335  seqVis.prepareSearch()
336  seqVis.setLookFor(target)
337  i.visit(seqVis)
338 
339  #if (seqVis.catch==1):
340  #seqVis.catch=0
341  #i.__iadd__(source)
342 
343 
344  #'''
345  process.gsfElectronsORG = process.gsfElectrons.clone()
346  #print dir(process)
347  #for p in dir(process):
348 
349  for p in process.paths:
350  pth = getattr(process,p)
351  #if hasattr(pth,"gsfElectrons"):
352  if "gsfElectrons" in pth.moduleNames():
353  pth.replace(process.gsfElectrons, process.gsfElectronsORG*process.gsfElectrons)
354  #print p, dir(pth.moduleNames())
355 
356  # xxx
357  process.gsfElectrons = cms.EDProducer("GSFElectronsMixer",
358  col1 = cms.InputTag("gsfElectronsORG"),
359  col2 = cms.InputTag("gsfElectrons","","RECO"),
360  )
361  #'''
362 
363  if hasattr(process, "DQM_FEDIntegrity_v3"):
364  process.schedule.remove(process.DQM_FEDIntegrity_v3)
365 
366  skimEnabled = False
367  if hasattr(process,"doZmumuSkim"):
368  print "Enabling Zmumu skim"
369  skimEnabled = True
370 
371  cmssw_ver = os.environ["CMSSW_VERSION"]
372  if cmssw_ver.find("CMSSW_4_2") != -1:
373  print
374  print "Using legacy version of Zmumu skim. Note, that muon isolation is disabled"
375  print
376  process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelectionLegacy_cff")
377  else:
378  process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelection_cff")
379 
380  #process.load("TauAnalysis/Skimming/goldenZmmSelectionVBTFrelPFIsolation_cfi")
381  process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi")
382 
383  # we are allready selecting events from generation step, so following way is ok
384  for path in process.paths:
385  getattr(process,path)._seq = process.goldenZmumuSelectionSequence * getattr(process,path)._seq
386 
387  #process.options = cms.untracked.PSet(
388  # wantSummary = cms.untracked.bool(True)
389  #)
390 
391 
392  if not skimEnabled:
393  print "Zmumu skim not enabled"
394 
395 
396  print "# ######################################################################################"
397  print " Following parameters can be added before customize function "
398  print " call in order to controll process customization: "
399  print " process.doNotParse = cms.PSet() # disables CL parsing for crab compat"
400  print " process.doZmumuSkim = cms.PSet() # adds Zmumu skimming before embedding is run"
401  print "# ######################################################################################"
402 
403 
404 
405 
406  print "#############################################################"
407  print " Warning! PFCandidates 'electron' collection is not mixed, "
408  print " and probably shouldnt be used. "
409  print "#############################################################"
410  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