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