CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pf_01_customizeSimulation.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 
3 from FWCore.ParameterSet.Modules import _Module
4 
5 
6 
7 
8 
9 
10 
11 # Searches for self.lookFor module in cms.Path. When found, next and prev module is stored
13  def __init__(self, lookFor):
14  self.lookFor=lookFor
15  self.nextInChain="NONE"
16  self.prevInChain="NONE"
17  self.prevInChainCandidate="NONE"
18  self.catch=0 # 1 - we have found self.lookFor, at next visit write visitee
19  self.found=0
20 
21  def prepareSearch(self): # this should be called on beggining of each iteration
22  self.found=0
23 
24  def setLookFor(self, lookFor):
25  self.lookFor = lookFor
26 
27  def giveNext(self):
28  return self.nextInChain
29  def givePrev(self):
30  return self.prevInChain
31 
32  def enter(self,visitee):
33  if isinstance(visitee, _Module):
34  if self.catch == 1:
35  self.catch=0
36  self.nextInChain=visitee
37  self.found=1
38  if visitee == self.lookFor:
39  self.catch=1
40  self.prevInChain=self.prevInChainCandidate
41 
42  self.prevInChainCandidate=visitee
43 
44  def leave(self,visitee):
45  pass
46 
47 
48 
49 def customise(process):
50 
51 
52  process._Process__name="SELECTandSIM"
53 
54 
55  process.TFileService = cms.Service("TFileService", fileName = cms.string("histo_reconstruction.root") )
56 
57  process.tmfTracks = cms.EDProducer("RecoTracksMixer",
58  trackCol1 = cms.InputTag("removedInputMuons","tracks"),
59  trackCol2 = cms.InputTag("generalTracks","","SELECTandSIM")
60  )
61 
62  process.offlinePrimaryVerticesWithBS.TrackLabel = cms.InputTag("tmfTracks")
63  process.offlinePrimaryVertices.TrackLabel = cms.InputTag("tmfTracks")
64  process.muons.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
65 
66  try:
67  process.metreco.remove(process.BeamHaloId)
68  except:
69  pass
70 
71  try:
72  outputModule = process.output
73  except:
74  pass
75  try:
76  outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
77  except:
78  pass
79 
80  print "Changing eventcontent to AODSIM + misc "
81  outputModule.outputCommands = process.AODSIMEventContent.outputCommands
82  keepMC = cms.untracked.vstring("keep *_*_zMusExtracted_*",
83  "keep *_removedInputMuons_*_*",
84  "keep *_generator_*_*",
85  "keep *_tmfTracks_*_SELECTandSIM",
86  "keep *_offlinePrimaryVertices_*_SELECTandSIM",
87  "keep *_offlinePrimaryVerticesWithBS_*_SELECTandSIM",
88  "keep *_PhotonIDProd_*_*",
89  "keep *_photons_*_*",
90  "keep *_photonCore_*_*",
91  "keep *_genParticles_*_*",
92  "keep *_particleFlow_*_*",
93  )
94  outputModule.outputCommands.extend(keepMC)
95 
96  if hasattr(process,"iterativeTracking" ) :
97  process.iterativeTracking.__iadd__(process.tmfTracks)
98  elif hasattr(process,"trackCollectionMerging" ) :
99  process.trackCollectionMerging.__iadd__(process.tmfTracks)
100  else :
101  raise "Cannot find tracking sequence"
102 
103  process.particleFlowORG = process.particleFlow.clone()
104  if hasattr(process,"famosParticleFlowSequence"):
105  process.famosParticleFlowSequence.remove(process.pfElectronTranslatorSequence)
106  process.famosParticleFlowSequence.remove(process.particleFlow)
107  process.famosParticleFlowSequence.__iadd__(process.particleFlowORG)
108  process.famosParticleFlowSequence.__iadd__(process.particleFlow)
109  process.famosParticleFlowSequence.__iadd__(process.pfElectronTranslatorSequence)
110  elif hasattr(process,"particleFlowReco"):
111  process.particleFlowReco.remove(process.pfElectronTranslatorSequence)
112  process.particleFlowReco.remove(process.particleFlow)
113  process.particleFlowReco.__iadd__(process.particleFlowORG)
114  process.particleFlowReco.__iadd__(process.particleFlow)
115  process.particleFlowReco.__iadd__(process.pfElectronTranslatorSequence)
116  else :
117  raise "Cannot find tracking sequence"
118 
119  process.particleFlow = cms.EDProducer('PFCandidateMixer',
120  col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
121  col2 = cms.untracked.InputTag("particleFlowORG", "")
122  )
123 
124 
125 
126  from FWCore.ParameterSet.Types import InputTag
127  for p in process.paths:
128  i = getattr(process,p)
129  target = process.particleFlow
130 
131  seqVis = SeqVisitor(target)
132  seqVis.prepareSearch()
133  seqVis.setLookFor(target)
134  i.visit(seqVis)
135  while ( seqVis.catch != 1 and seqVis.found == 1 ):
136 
137  target = seqVis.giveNext()
138 
139  targetAttributes = dir(target)
140  for targetAttribute in targetAttributes:
141  attr=getattr(target,targetAttribute) # get actual attribute, not just the name
142  if isinstance(attr, InputTag) and attr.getModuleLabel()=="particleFlow":
143  if ( attr.getProductInstanceLabel()!="" ):
144  print "Changing: ", target, " ", targetAttribute, " ", attr, " to particleFlowORG",
145  attr.setModuleLabel("particleFlowORG")
146 
147 
148  #i.replace(target, source)
149  seqVis.prepareSearch()
150  seqVis.setLookFor(target)
151  i.visit(seqVis)
152 
153  #if (seqVis.catch==1):
154  #seqVis.catch=0
155  #i.__iadd__(source)
156 
157  process.source.duplicateCheckMode = cms.untracked.string('noDuplicateCheck')
158 
159  import FWCore.ParameterSet.VarParsing as VarParsing
160  options = VarParsing.VarParsing ('analysis')
161 
162  options.register ('overrideBeamSpot',
163  0, # default value, false
164  VarParsing.VarParsing.multiplicity.singleton,
165  VarParsing.VarParsing.varType.int,
166  "should I override beamspot in globaltag?")
167 
168  # Set this to REDIGI311X for Spring11 MC:
169  options.register ('primaryProcess',
170  'RECO', # default value
171  VarParsing.VarParsing.multiplicity.singleton,
172  VarParsing.VarParsing.varType.string,
173  "original processName")
174 
175  # Workaround so that edmConfigHash does not fail with this config file.
176  # cf. https://hypernews.cern.ch/HyperNews/CMS/get/crabFeedback/3852/1/1/1/1/1.html
177  import sys
178  if hasattr(sys, "argv") == True:
179  options.parseArguments()
180 
181  # it should be the best solution to take the original beam spot for the
182  # reconstruction of the new primary vertex
183  process.offlinePrimaryVertices.beamSpotLabel = cms.InputTag("offlineBeamSpot","",options.primaryProcess)
184  process.offlinePrimaryVerticesWithBS.beamSpotLabel = cms.InputTag("offlineBeamSpot","",options.primaryProcess)
185 
186  if options.overrideBeamSpot != 0:
187  bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v18_offline") # 41x data PR gt
188  #bs = cms.string("BeamSpotObjects_2009_LumiBased_v16_offline") # 38x data gt
189  #bs = cms.string("BeamSpotObjects_2009_v14_offline") # 36x data gt
190  # tag = cms.string("Early10TeVCollision_3p8cm_31X_v1_mc_START"), # 35 default
191  # tag = cms.string("Realistic900GeVCollisions_10cm_STARTUP_v1_mc"), # 36 default
192  process.GlobalTag.toGet = cms.VPSet(
193  cms.PSet(record = cms.string("BeamSpotObjectsRcd"),
194  tag = bs,
195  connect = cms.untracked.string("frontier://FrontierProd/CMS_COND_31X_BEAMSPOT")
196  )
197  )
198  print "BeamSpot in globaltag set to ", bs
199  else:
200  print "BeamSpot in globaltag not changed"
201 
202  print "#############################################################"
203  print " Warning! PFCandidates 'electron' collection is not mixed, "
204  print " and probably shouldnt be used. "
205  print "#############################################################"
206  return(process)
return((rh^lh)&mask)
list object
Definition: dbtoconf.py:77
dbl *** dir
Definition: mlp_gen.cc:35
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