CMS 3D CMS Logo

Classes | Functions

pf_01_customizeSimulation Namespace Reference

Classes

class  SeqVisitor

Functions

def customise

Function Documentation

def pf_01_customizeSimulation::customise (   process)

Definition at line 49 of file pf_01_customizeSimulation.py.

00050                       :
00051   
00052   
00053   process._Process__name="SELECTandSIM"
00054 
00055 
00056   process.TFileService = cms.Service("TFileService",  fileName = cms.string("histo_reconstruction.root")          )
00057 
00058   process.tmfTracks = cms.EDProducer("RecoTracksMixer",
00059       trackCol1 = cms.InputTag("removedInputMuons","tracks"),
00060       trackCol2 = cms.InputTag("generalTracks","","SELECTandSIM")
00061   )  
00062 
00063   process.offlinePrimaryVerticesWithBS.TrackLabel = cms.InputTag("tmfTracks")
00064   process.offlinePrimaryVertices.TrackLabel = cms.InputTag("tmfTracks")
00065   process.muons.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
00066   
00067   try:
00068         process.metreco.remove(process.BeamHaloId)
00069   except:
00070         pass
00071 
00072   try:
00073           outputModule = process.output
00074   except:
00075     pass
00076   try:
00077           outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
00078   except:
00079     pass
00080 
00081   print "Changing eventcontent to AODSIM + misc "
00082   outputModule.outputCommands = process.AODSIMEventContent.outputCommands
00083   keepMC = cms.untracked.vstring("keep *_*_zMusExtracted_*",
00084                                  "keep *_removedInputMuons_*_*",
00085                                  "keep *_generator_*_*",
00086                                  "keep *_tmfTracks_*_SELECTandSIM",
00087                                  "keep *_offlinePrimaryVertices_*_SELECTandSIM",
00088                                  "keep *_offlinePrimaryVerticesWithBS_*_SELECTandSIM",
00089                                  "keep *_PhotonIDProd_*_*",
00090                                  "keep *_photons_*_*",
00091                                  "keep *_photonCore_*_*",
00092                                  "keep *_genParticles_*_*",
00093                                  "keep *_particleFlow_*_*",
00094   )
00095   outputModule.outputCommands.extend(keepMC)
00096 
00097   if  hasattr(process,"iterativeTracking" ) :
00098     process.iterativeTracking.__iadd__(process.tmfTracks)
00099   elif hasattr(process,"trackCollectionMerging" ) :
00100     process.trackCollectionMerging.__iadd__(process.tmfTracks)
00101   else :
00102     raise "Cannot find tracking sequence"
00103 
00104   process.particleFlowORG = process.particleFlow.clone()
00105   if hasattr(process,"famosParticleFlowSequence"):
00106     process.famosParticleFlowSequence.remove(process.pfElectronTranslatorSequence)
00107     process.famosParticleFlowSequence.remove(process.particleFlow)
00108     process.famosParticleFlowSequence.__iadd__(process.particleFlowORG)
00109     process.famosParticleFlowSequence.__iadd__(process.particleFlow)
00110     process.famosParticleFlowSequence.__iadd__(process.pfElectronTranslatorSequence)
00111   elif hasattr(process,"particleFlowReco"):
00112     process.particleFlowReco.remove(process.pfElectronTranslatorSequence)
00113     process.particleFlowReco.remove(process.particleFlow)
00114     process.particleFlowReco.__iadd__(process.particleFlowORG)
00115     process.particleFlowReco.__iadd__(process.particleFlow)
00116     process.particleFlowReco.__iadd__(process.pfElectronTranslatorSequence)
00117   else :
00118     raise "Cannot find tracking sequence"
00119 
00120   process.particleFlow =  cms.EDProducer('PFCandidateMixer',
00121           col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
00122           col2 = cms.untracked.InputTag("particleFlowORG", "")
00123   )
00124 
00125  
00126 
00127   from FWCore.ParameterSet.Types import InputTag
00128   for p in process.paths:
00129      i =  getattr(process,p)
00130      target = process.particleFlow
00131      
00132      seqVis = SeqVisitor(target)
00133      seqVis.prepareSearch()
00134      seqVis.setLookFor(target)
00135      i.visit(seqVis) 
00136      while ( seqVis.catch != 1 and seqVis.found == 1 ): 
00137 
00138        target = seqVis.giveNext()
00139 
00140        targetAttributes =  dir(target)
00141        for targetAttribute in targetAttributes:
00142          attr=getattr(target,targetAttribute) # get actual attribute, not just  the name
00143          if isinstance(attr, InputTag) and attr.getModuleLabel()=="particleFlow":
00144            if ( attr.getProductInstanceLabel()!=""  ):
00145              print "Changing: ", target, " ", targetAttribute, " ", attr, " to particleFlowORG", 
00146              attr.setModuleLabel("particleFlowORG")
00147 
00148 
00149        #i.replace(target, source) 
00150        seqVis.prepareSearch()
00151        seqVis.setLookFor(target)
00152        i.visit(seqVis) 
00153             
00154      #if (seqVis.catch==1):
00155        #seqVis.catch=0
00156        #i.__iadd__(source)
00157 
00158   process.source.duplicateCheckMode = cms.untracked.string('noDuplicateCheck')
00159 
00160   import FWCore.ParameterSet.VarParsing as VarParsing
00161   options = VarParsing.VarParsing ('analysis')
00162 
00163   options.register ('overrideBeamSpot',
00164                     0, # default value, false
00165                     VarParsing.VarParsing.multiplicity.singleton,
00166                     VarParsing.VarParsing.varType.int,
00167                     "should I override beamspot in globaltag?")
00168 
00169   # Set this to REDIGI311X for Spring11 MC:
00170   options.register ('primaryProcess',
00171                     'RECO', # default value
00172                     VarParsing.VarParsing.multiplicity.singleton,
00173                     VarParsing.VarParsing.varType.string,
00174                     "original processName")
00175 
00176   # Workaround so that edmConfigHash does not fail with this config file.
00177   # cf. https://hypernews.cern.ch/HyperNews/CMS/get/crabFeedback/3852/1/1/1/1/1.html
00178   import sys
00179   if hasattr(sys, "argv") == True:
00180     options.parseArguments()
00181 
00182   # it should be the best solution to take the original beam spot for the
00183   # reconstruction of the new primary vertex
00184   process.offlinePrimaryVertices.beamSpotLabel = cms.InputTag("offlineBeamSpot","",options.primaryProcess)
00185   process.offlinePrimaryVerticesWithBS.beamSpotLabel = cms.InputTag("offlineBeamSpot","",options.primaryProcess)
00186 
00187   if options.overrideBeamSpot !=  0:
00188     bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v18_offline") # 41x data PR gt
00189     #bs = cms.string("BeamSpotObjects_2009_LumiBased_v16_offline") # 38x data gt
00190     #bs = cms.string("BeamSpotObjects_2009_v14_offline") # 36x data gt
00191     #  tag = cms.string("Early10TeVCollision_3p8cm_31X_v1_mc_START"), # 35 default
00192     #  tag = cms.string("Realistic900GeVCollisions_10cm_STARTUP_v1_mc"), # 36 default
00193     process.GlobalTag.toGet = cms.VPSet(
00194       cms.PSet(record = cms.string("BeamSpotObjectsRcd"),
00195            tag = bs,
00196            connect = cms.untracked.string("frontier://FrontierProd/CMS_COND_31X_BEAMSPOT")
00197       )
00198     )
00199     print "BeamSpot in globaltag set to ", bs
00200   else:
00201     print "BeamSpot in globaltag not changed"
00202 
00203   print "#############################################################"
00204   print " Warning! PFCandidates 'electron' collection is not mixed, "
00205   print "  and probably shouldnt be used. "
00206   print "#############################################################"
00207   return(process)