CMS 3D CMS Logo

Classes | Functions

pf_01_customizeAll Namespace Reference

Classes

class  SeqVisitor

Functions

def customise

Function Documentation

def pf_01_customizeAll::customise (   process)

Definition at line 46 of file pf_01_customizeAll.py.

00047                       :
00048  
00049    
00050   
00051   process._Process__name="EmbeddedRECO"
00052   process.TFileService = cms.Service("TFileService",  fileName = cms.string("histo_embedded.root")          )
00053 
00054   try:
00055           outputModule = process.output
00056   except:
00057     pass
00058   try:
00059           outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
00060   except:
00061     pass
00062 
00063   print "Changing eventcontent to RAW+AODSIM + misc. "
00064   outputModule.outputCommands = cms.untracked.vstring("drop *")
00065   outputModule.outputCommands.extend(process.RAWEventContent.outputCommands )
00066   outputModule.outputCommands.extend(process.AODSIMEventContent.outputCommands )
00067 
00068   keepMC = cms.untracked.vstring("keep *_*_zMusExtracted_*",
00069                                  "keep *_*_zmmCands_*",
00070                                  "keep *_removedInputMuons_*_*",
00071                                  "keep *_generator_*_*",
00072                                  "keep *_PhotonIDProd_*_*",
00073                                  "keep *_photons_*_*",
00074                                  "keep *_photonCore_*_*",
00075                                  "keep *_genParticles_*_*",
00076                                  "keep *_particleFlow_*_*",
00077                                  "keep *_generator_*_*",
00078                                  "keep *_tmfTracks_*_EmbeddedRECO",
00079                                  "keep *_offlinePrimaryVertices_*_EmbeddedRECO",
00080                                  "keep *_offlinePrimaryVerticesWithBS_*_EmbeddedRECO",
00081                                  "keep *_PhotonIDProd_*_*",
00082                                  "keep *_photons_*_*",
00083                                  "keep *_photonCore_*_*",
00084                                  "keep *_genParticles_*_*",
00085                                  "keep *_particleFlow_*_*",
00086   )
00087   outputModule.outputCommands.extend(keepMC)
00088 
00089   # getRid of second "drop *"
00090   index = 0
00091   for item in outputModule.outputCommands[:]:
00092     if item == "drop *" and index != 0:
00093       #print index," ",outputModule.outputCommands[index]
00094       del outputModule.outputCommands[index]
00095       index -= 1
00096     index += 1  
00097 
00098 
00099   hltProcessName = "HLT"        #"REDIGI38X"
00100   RECOproc = "RECO"
00101   # the following block can be used for more efficient processing by replacing the HLT variable below automatically
00102   try:
00103     hltProcessName = __HLT__
00104   except:
00105     pass
00106         
00107   try:
00108     process.dimuonsHLTFilter.TriggerResultsTag.processName = hltProcessName
00109     process.goodZToMuMuAtLeast1HLT.TrigTag.processName = hltProcessName
00110     process.goodZToMuMuAtLeast1HLT.triggerEvent.processName = hltProcessName
00111     process.hltTrigReport,HLTriggerResults.processName = hltProcessName
00112   except:
00113     pass
00114 
00115   process.VtxSmeared = cms.EDProducer("FlatEvtVtxGenerator", 
00116     MaxZ = cms.double(0.0),
00117     MaxX = cms.double(0.0),
00118     MaxY = cms.double(0.0),
00119     MinX = cms.double(0.0),
00120     MinY = cms.double(0.0),
00121     MinZ = cms.double(0.0),
00122     TimeOffset = cms.double(0.0),
00123     src = cms.InputTag("generator")
00124   )
00125 
00126   import FWCore.ParameterSet.VarParsing as VarParsing
00127   options = VarParsing.VarParsing ('analysis')
00128   options.register ('mdtau',
00129                     0, # default value
00130                     VarParsing.VarParsing.multiplicity.singleton,
00131                     VarParsing.VarParsing.varType.int,         
00132                     "mdtau value for tauola")
00133 
00134   options.register ('transformationMode',
00135                     1, #default value
00136                     VarParsing.VarParsing.multiplicity.singleton,
00137                     VarParsing.VarParsing.varType.int,
00138                     "transformation mode. 0=mumu->mumu, 1=mumu->tautau")
00139 
00140   options.register ('minVisibleTransverseMomentum',
00141                     "", #default value
00142                     VarParsing.VarParsing.multiplicity.singleton,
00143                     VarParsing.VarParsing.varType.string,
00144                     "generator level cut on visible transverse momentum (typeN:pT,[...];[...])")
00145 
00146   options.register ('useJson',
00147                     0, # default value, false
00148                     VarParsing.VarParsing.multiplicity.singleton,
00149                     VarParsing.VarParsing.varType.int,         
00150                     "should I enable json usage?")
00151 
00152   options.register ('overrideBeamSpot',
00153                     0, # default value, false
00154                     VarParsing.VarParsing.multiplicity.singleton,
00155                     VarParsing.VarParsing.varType.int,         
00156                     "should I override beamspot in globaltag?")
00157 
00158 #  options.register ('primaryProcess',
00159 #                    'RECO', # default value
00160 #                     VarParsing.VarParsing.multiplicity.singleton,
00161 #                     VarParsing.VarParsing.varType.string,
00162 #                     "original processName")
00163 
00164 
00165   setFromCL = False
00166   if not hasattr(process,"doNotParse"):
00167     import sys
00168     if hasattr(sys, "argv") == True:
00169       if not sys.argv[0].endswith('cmsDriver.py'):
00170         options.parseArguments()
00171         setFromCL = True
00172   else:
00173     print "CL parsing disabled!"
00174   if setFromCL:
00175     print "Setting mdtau to ", options.mdtau
00176     process.generator.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau 
00177     process.newSource.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau
00178     process.generator.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau 
00179     process.newSource.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau 
00180 
00181     print "Setting minVisibleTransverseMomentum to ", options.minVisibleTransverseMomentum
00182     process.newSource.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
00183     process.generator.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
00184 
00185     print "Setting transformationMode to ", options.transformationMode
00186     process.generator.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
00187     process.newSource.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
00188 
00189     print "options.overrideBeamSpot", options.overrideBeamSpot
00190     if options.overrideBeamSpot != 0:
00191       bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v26_offline") # 52x data PR gt
00192       # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v21_offline") # 42x data PR gt
00193       # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v18_offline") # 41x data PR gt
00194       # bs = cms.string("BeamSpotObjects_2009_LumiBased_v17_offline") # 38x data gt
00195       #bs = cms.string("BeamSpotObjects_2009_v14_offline") # 36x data gt
00196       #  tag = cms.string("Early10TeVCollision_3p8cm_31X_v1_mc_START"), # 35 default
00197       #  tag = cms.string("Realistic900GeVCollisions_10cm_STARTUP_v1_mc"), # 36 default
00198       process.GlobalTag.toGet = cms.VPSet(
00199         cms.PSet(record = cms.string("BeamSpotObjectsRcd"),
00200            tag = bs,
00201            connect = cms.untracked.string("frontier://FrontierProd/CMS_COND_31X_BEAMSPOT")
00202         )
00203       )
00204       print "BeamSpot in globaltag set to ", bs 
00205     else:
00206       print "BeamSpot in globaltag not changed"
00207 
00208     if options.useJson !=  0:
00209       print "Enabling json usage"
00210       import PhysicsTools.PythonAnalysis.LumiList as LumiList
00211       import FWCore.ParameterSet.Types as CfgTypes
00212       myLumis = LumiList.LumiList(filename = 'my.json').getCMSSWString().split(',')
00213       process.source.lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange())
00214       process.source.lumisToProcess.extend(myLumis)
00215 
00216 # -*- coding: utf-8 -*-
00217 
00218 
00219   process.tmfTracks = cms.EDProducer("RecoTracksMixer",
00220       trackCol1 = cms.InputTag("removedInputMuons","tracks"),
00221       trackCol2 = cms.InputTag("generalTracks","","EmbeddedRECO")
00222   )  
00223 
00224   process.offlinePrimaryVerticesWithBS.TrackLabel = cms.InputTag("tmfTracks")
00225   process.offlinePrimaryVertices.TrackLabel = cms.InputTag("tmfTracks")
00226 
00227   if hasattr(process.muons, "TrackExtractorPSet"):
00228     process.muons.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
00229   elif hasattr(process, "muons1stStep") and hasattr(process.muons1stStep, "TrackExtractorPSet"):
00230     process.muons1stStep.TrackExtractorPSet.inputTrackCollection = cms.InputTag("tmfTracks")
00231   else:
00232     raise "Problem with muons"
00233   # it should be the best solution to take the original beam spot for the
00234   # reconstruction of the new primary vertex
00235   # use the  one produced earlier, do not produce your own
00236   for s in process.sequences:
00237      seq =  getattr(process,s)
00238      seq.remove(process.offlineBeamSpot) 
00239 
00240 
00241   try:
00242         process.metreco.remove(process.BeamHaloId)
00243   except:
00244         pass
00245 
00246   try:
00247           outputModule = process.output
00248   except:
00249     pass
00250   try:
00251           outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
00252   except:
00253     pass
00254 
00255 
00256   for p in process.paths:
00257     pth = getattr(process,p)
00258     if "generalTracks" in pth.moduleNames():
00259       pth.replace(process.generalTracks, process.generalTracks*process.tmfTracks)
00260 
00261 
00262   #'''
00263   process.gsfElectronsORG = process.gsfElectrons.clone()
00264   #print dir(process)
00265   #for p in dir(process):
00266 
00267   for p in process.paths:
00268     pth = getattr(process,p)
00269     #if hasattr(pth,"gsfElectrons"):
00270     if "gsfElectrons" in pth.moduleNames():
00271       pth.replace(process.gsfElectrons, process.gsfElectronsORG*process.gsfElectrons)
00272       #print p, dir(pth.moduleNames())
00273 
00274   # xxx
00275   process.gsfElectrons = cms.EDProducer("GSFElectronsMixer",
00276       col1 = cms.InputTag("gsfElectronsORG"),
00277       col2 = cms.InputTag("gsfElectrons","", RECOproc )
00278   )
00279   #'''
00280 
00281 
00282 
00283   process.particleFlowORG = process.particleFlow.clone()
00284 
00285   # Since CMSSW 4_4 the particleFlow reco works a bit differently. The step is
00286   # twofold, first particleFlowTmp is created and then the final particleFlow
00287   # collection. What we do in this case is that we merge the final ParticleFlow
00288   # collection. For the muon reconstruction, we also merge particleFlowTmp in
00289   # order to get PF-based isolation right.
00290   if hasattr(process, 'particleFlowTmp'):
00291     process.particleFlowTmpMixed = cms.EDProducer('PFCandidateMixer',
00292       col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
00293       col2 = cms.untracked.InputTag("particleFlowTmp", ""),
00294       trackCol = cms.untracked.InputTag("tmfTracks"),
00295 
00296       # Don't produce value maps:
00297       muons = cms.untracked.InputTag(""),
00298       gsfElectrons = cms.untracked.InputTag("")
00299     )
00300     process.muons.PFCandidates = cms.InputTag("particleFlowTmpMixed")
00301 
00302     for p in process.paths:
00303       if "particleFlow" in pth.moduleNames():
00304         pth.replace(process.particleFlow, process.particleFlowORG*process.particleFlow)
00305       if "muons" in pth.moduleNames():
00306         pth.replace(process.muons, process.particleFlowTmpMixed*process.muons)
00307   else:
00308     # CMSSW_4_2
00309     if hasattr(process,"famosParticleFlowSequence"):
00310       process.famosParticleFlowSequence.remove(process.pfPhotonTranslatorSequence)
00311       process.famosParticleFlowSequence.remove(process.pfElectronTranslatorSequence)
00312       process.famosParticleFlowSequence.remove(process.particleFlow)
00313       process.famosParticleFlowSequence.__iadd__(process.particleFlowORG)
00314       process.famosParticleFlowSequence.__iadd__(process.particleFlow)
00315       process.famosParticleFlowSequence.__iadd__(process.pfElectronTranslatorSequence)
00316       process.famosParticleFlowSequence.__iadd__(process.pfPhotonTranslatorSequence)
00317     elif hasattr(process,"particleFlowReco"):
00318       process.particleFlowReco.remove(process.pfPhotonTranslatorSequence)
00319       process.particleFlowReco.remove(process.pfElectronTranslatorSequence)
00320       process.particleFlowReco.remove(process.particleFlow)
00321       process.particleFlowReco.__iadd__(process.particleFlowORG)
00322       process.particleFlowReco.__iadd__(process.particleFlow)
00323       process.particleFlowReco.__iadd__(process.pfElectronTranslatorSequence)
00324       process.particleFlowReco.__iadd__(process.pfPhotonTranslatorSequence)
00325     else :
00326       raise "Cannot find particleFlow sequence"
00327 
00328     process.pfSelectedElectrons.src = cms.InputTag("particleFlowORG")
00329     process.pfSelectedPhotons.src   = cms.InputTag("particleFlowORG")
00330 
00331 
00332   process.particleFlow =  cms.EDProducer('PFCandidateMixer',
00333           col1 = cms.untracked.InputTag("removedInputMuons","pfCands"),
00334           col2 = cms.untracked.InputTag("particleFlowORG", ""),
00335           trackCol = cms.untracked.InputTag("tmfTracks"),
00336 
00337           muons = cms.untracked.InputTag("muons"),
00338           gsfElectrons = cms.untracked.InputTag("gsfElectrons")
00339           # TODO: photons???
00340   )
00341 
00342   process.filterEmptyEv.src = cms.untracked.InputTag("generator","","EmbeddedRECO")
00343 
00344   from FWCore.ParameterSet.Types import InputTag
00345   for p in process.paths:
00346      i =  getattr(process,p)
00347      target = process.particleFlow
00348      
00349      seqVis = SeqVisitor(target)
00350      seqVis.prepareSearch()
00351      seqVis.setLookFor(target)
00352      i.visit(seqVis) 
00353      while ( seqVis.catch != 1 and seqVis.found == 1 ): 
00354 
00355        target = seqVis.giveNext()
00356 
00357        targetAttributes =  dir(target)
00358        for targetAttribute in targetAttributes:
00359          attr=getattr(target,targetAttribute) # get actual attribute, not just  the name
00360          if isinstance(attr, InputTag) and attr.getModuleLabel()=="particleFlow":
00361            if ( attr.getProductInstanceLabel()!=""  ):
00362              print "Changing: ", target, " ", targetAttribute, " ", attr, " to particleFlowORG"
00363              attr.setModuleLabel("particleFlowORG")
00364 
00365 
00366        #i.replace(target, source) 
00367        seqVis.prepareSearch()
00368        seqVis.setLookFor(target)
00369        i.visit(seqVis) 
00370             
00371      #if (seqVis.catch==1):
00372        #seqVis.catch=0
00373        #i.__iadd__(source)
00374 
00375 
00376   if hasattr(process, "DQM_FEDIntegrity_v3"):
00377     process.schedule.remove(process.DQM_FEDIntegrity_v3)
00378 
00379   skimEnabled = False
00380   if hasattr(process,"doZmumuSkim"):
00381       print "Enabling Zmumu skim"
00382       skimEnabled = True
00383 
00384       cmssw_ver = os.environ["CMSSW_VERSION"]
00385       if cmssw_ver.find("CMSSW_4_2") != -1:
00386         print
00387         print "Using legacy version of Zmumu skim. Note, that muon isolation is disabled"
00388         print
00389         process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelectionLegacy_cff")
00390         process.RandomNumberGeneratorService.dummy = cms.PSet(
00391           initialSeed = cms.untracked.uint32(123456789),
00392           engineName = cms.untracked.string('HepJamesRandom')
00393         )
00394 
00395       else:
00396         process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelection_cff")
00397 
00398       #process.load("TauAnalysis/Skimming/goldenZmmSelectionVBTFrelPFIsolation_cfi")
00399       process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi")
00400 
00401       # we are allready selecting events from generation step, so following way is ok
00402       for path in process.paths:
00403           getattr(process,path)._seq = process.goldenZmumuSelectionSequence * getattr(process,path)._seq
00404 
00405       #process.options = cms.untracked.PSet(
00406       #  wantSummary = cms.untracked.bool(True)
00407       #)
00408 
00409 
00410   if not skimEnabled:
00411       print "Zmumu skim not enabled"
00412 
00413 
00414   print "# ######################################################################################"
00415   print "  Following parameters can be added before customize function "
00416   print "  call in order to controll process  customization: "
00417   print "     process.doNotParse =  cms.PSet() # disables CL parsing for crab compat"
00418   print "     process.doZmumuSkim = cms.PSet() # adds Zmumu skimming before embedding is run"
00419   print "# ######################################################################################"
00420 
00421   return(process)