CMS 3D CMS Logo

Functions

rh_customizeAll Namespace Reference

Functions

def customise

Function Documentation

def rh_customizeAll::customise (   process)

Definition at line 5 of file rh_customizeAll.py.

00006                       :
00007    
00008   inputProcess="HLT"  # some automagic check possible?
00009 
00010   process._Process__name="EmbeddedRECO"
00011   process.TFileService = cms.Service("TFileService",  fileName = cms.string("histo_embedded.root")          )
00012 
00013   try:
00014           outputModule = process.output
00015   except:
00016     pass
00017   try:
00018           outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
00019   except:
00020     pass
00021 
00022   print "Changing eventcontent to RAW+AODSIM + misc. "
00023   outputModule.outputCommands = cms.untracked.vstring("drop *")
00024   outputModule.outputCommands.extend(process.RAWEventContent.outputCommands )
00025   outputModule.outputCommands.extend(process.AODSIMEventContent.outputCommands )
00026 
00027   keepMC = cms.untracked.vstring("keep *_*_zMusExtracted_*",
00028                                  "keep *_*_zmmCands_*",
00029                                  "keep *_removedInputMuons_*_*",
00030                                  "keep *_generator_*_*",
00031                                  "keep *_PhotonIDProd_*_*",
00032                                  "keep *_photons_*_*",
00033                                  "keep *_photonCore_*_*",
00034                                  "keep *_genParticles_*_*",
00035                                  "keep *_particleFlow_*_*",
00036                                  "keep *_generator_*_*",
00037                                  "keep *_tmfTracks_*_EmbeddedRECO",
00038                                  "keep *_offlinePrimaryVertices_*_EmbeddedRECO",
00039                                  "keep *_offlinePrimaryVerticesWithBS_*_EmbeddedRECO",
00040                                  "keep *_PhotonIDProd_*_*",
00041                                  "keep *_photons_*_*",
00042                                  "keep *_photonCore_*_*",
00043                                  "keep *_genParticles_*_*",
00044                                  "keep *_particleFlow_*_*",
00045   )
00046   outputModule.outputCommands.extend(keepMC)
00047 
00048   # getRid of second "drop *"
00049   index = 0
00050   for item in outputModule.outputCommands[:]:
00051     if item == "drop *" and index != 0:
00052       #print index," ",outputModule.outputCommands[index]
00053       del outputModule.outputCommands[index]
00054       index -= 1
00055     index += 1  
00056 
00057 
00058   hltProcessName = "HLT"        #"REDIGI38X"
00059   # the following block can be used for more efficient processing by replacing the HLT variable below automatically
00060   try:
00061     hltProcessName = __HLT__
00062   except:
00063     pass
00064         
00065   try:
00066     process.dimuonsHLTFilter.TriggerResultsTag.processName = hltProcessName
00067     process.goodZToMuMuAtLeast1HLT.TrigTag.processName = hltProcessName
00068     process.goodZToMuMuAtLeast1HLT.triggerEvent.processName = hltProcessName
00069     process.hltTrigReport,HLTriggerResults.processName = hltProcessName
00070   except:
00071     pass
00072 
00073   process.VtxSmeared = cms.EDProducer("FlatEvtVtxGenerator", 
00074     MaxZ = cms.double(0.0),
00075     MaxX = cms.double(0.0),
00076     MaxY = cms.double(0.0),
00077     MinX = cms.double(0.0),
00078     MinY = cms.double(0.0),
00079     MinZ = cms.double(0.0),
00080     TimeOffset = cms.double(0.0),
00081     src = cms.InputTag("generator")
00082   )
00083 
00084   import FWCore.ParameterSet.VarParsing as VarParsing
00085   options = VarParsing.VarParsing ('analysis')
00086   options.register ('mdtau',
00087                     0, # default value
00088                     VarParsing.VarParsing.multiplicity.singleton,
00089                     VarParsing.VarParsing.varType.int,         
00090                     "mdtau value for tauola")
00091 
00092   options.register ('transformationMode',
00093                     1, #default value
00094                     VarParsing.VarParsing.multiplicity.singleton,
00095                     VarParsing.VarParsing.varType.int,
00096                     "transformation mode. 0=mumu->mumu, 1=mumu->tautau")
00097 
00098   options.register ('minVisibleTransverseMomentum',
00099                     "", #default value
00100                     VarParsing.VarParsing.multiplicity.singleton,
00101                     VarParsing.VarParsing.varType.string,
00102                     "generator level cut on visible transverse momentum (typeN:pT,[...];[...])")
00103 
00104   options.register ('useJson',
00105                     0, # default value, false
00106                     VarParsing.VarParsing.multiplicity.singleton,
00107                     VarParsing.VarParsing.varType.int,         
00108                     "should I enable json usage?")
00109 
00110   options.register ('overrideBeamSpot',
00111                     0, # default value, false
00112                     VarParsing.VarParsing.multiplicity.singleton,
00113                     VarParsing.VarParsing.varType.int,         
00114                     "should I override beamspot in globaltag?")
00115 
00116 #  options.register ('primaryProcess',
00117 #                    'RECO', # default value
00118 #                     VarParsing.VarParsing.multiplicity.singleton,
00119 #                     VarParsing.VarParsing.varType.string,
00120 #                     "original processName")
00121 
00122 
00123 
00124   setFromCL = False
00125   if not hasattr(process,"doNotParse"):
00126     import sys
00127     if hasattr(sys, "argv") == True:
00128       if not sys.argv[0].endswith('cmsDriver.py'):
00129         options.parseArguments()
00130         setFromCL = True
00131   else :
00132     print "CL parsing disabled!"
00133 
00134   
00135   if setFromCL:
00136     print "Setting mdtau to ", options.mdtau
00137     process.generator.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau 
00138     process.newSource.ZTauTau.TauolaOptions.InputCards.mdtau = options.mdtau
00139     process.generator.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau 
00140     process.newSource.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = options.mdtau 
00141 
00142     print "Setting minVisibleTransverseMomentum to ", options.minVisibleTransverseMomentum
00143     process.newSource.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
00144     process.generator.ZTauTau.minVisibleTransverseMomentum = cms.untracked.string(options.minVisibleTransverseMomentum)
00145 
00146     print "Setting transformationMode to ", options.transformationMode
00147     process.generator.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
00148     process.newSource.ZTauTau.transformationMode = cms.untracked.int32(options.transformationMode)
00149 
00150   if setFromCL and options.overrideBeamSpot != 0  :
00151     print "options.overrideBeamSpot", options.overrideBeamSpot
00152     # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v26_offline") # 52x data PR gt
00153     bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v21_offline") # 42x data PR gt
00154     # bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v18_offline") # 41x data PR gt
00155     # bs = cms.string("BeamSpotObjects_2009_LumiBased_v17_offline") # 38x data gt
00156     #bs = cms.string("BeamSpotObjects_2009_v14_offline") # 36x data gt
00157     #  tag = cms.string("Early10TeVCollision_3p8cm_31X_v1_mc_START"), # 35 default
00158     #  tag = cms.string("Realistic900GeVCollisions_10cm_STARTUP_v1_mc"), # 36 default
00159     process.GlobalTag.toGet = cms.VPSet(
00160       cms.PSet(record = cms.string("BeamSpotObjectsRcd"),
00161            tag = bs,
00162            connect = cms.untracked.string("frontier://FrontierProd/CMS_COND_31X_BEAMSPOT")
00163       )
00164     )
00165     print "BeamSpot in globaltag set to ", bs 
00166   else:
00167     print "BeamSpot in globaltag not changed"
00168 
00169   if setFromCL and options.useJson !=  0:
00170     print "Enabling json usage"
00171     import PhysicsTools.PythonAnalysis.LumiList as LumiList
00172     import FWCore.ParameterSet.Types as CfgTypes
00173     myLumis = LumiList.LumiList(filename = 'my.json').getCMSSWString().split(',')
00174     process.source.lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange())
00175     process.source.lumisToProcess.extend(myLumis)
00176 
00177 
00178 
00179   
00180   process.generalTracksORG = process.generalTracks.clone()
00181 
00182   process.generalTracks = cms.EDProducer("RecoTracksMixer",
00183       trackCol1 = cms.InputTag("generalTracksORG","","EmbeddedRECO"),
00184       trackCol2 = cms.InputTag("removedInputMuons","tracks")
00185   )  
00186 
00187   for p in process.paths:
00188     pth = getattr(process,p)
00189     if "generalTracks" in pth.moduleNames():
00190       pth.replace(process.generalTracks, process.generalTracksORG*process.generalTracks)
00191 
00192   # We can try mixing seeds or keep std::vector<Trajectory> from Zmumu event and
00193   # try mixing it. 
00194   # note - later approach may have no sense. Different geometries...
00195   process.trackerDrivenElectronSeedsORG = process.trackerDrivenElectronSeeds.clone()
00196   process.trackerDrivenElectronSeedsORG.TkColList = cms.VInputTag(cms.InputTag("generalTracksORG"))
00197 
00198   process.trackerDrivenElectronSeeds = cms.EDProducer("ElectronSeedTrackRefUpdater",
00199     PreIdLabel = process.trackerDrivenElectronSeedsORG.PreIdLabel,
00200     PreGsfLabel = process.trackerDrivenElectronSeedsORG.PreGsfLabel,
00201     targetTracks = cms.InputTag("generalTracks"),
00202     inSeeds = cms.InputTag("trackerDrivenElectronSeedsORG", process.trackerDrivenElectronSeedsORG.PreGsfLabel.value()),
00203     inPreId = cms.InputTag("trackerDrivenElectronSeedsORG", process.trackerDrivenElectronSeedsORG.PreIdLabel.value()),
00204   )
00205 
00206   for p in process.paths:
00207     pth = getattr(process,p)
00208     if "trackerDrivenElectronSeeds" in pth.moduleNames():
00209         pth.replace(process.trackerDrivenElectronSeeds, process.trackerDrivenElectronSeedsORG*process.trackerDrivenElectronSeeds)
00210 
00211 
00212   # hack photonCore:
00213   process.trackerDrivenElectronSeedsMerged = cms.EDProducer("ElectronSeedTrackRefUpdaterAndMerger",
00214    PreIdLabel = process.trackerDrivenElectronSeedsORG.PreIdLabel,
00215    PreGsfLabel = process.trackerDrivenElectronSeedsORG.PreGsfLabel,
00216    targetTracks = cms.InputTag("generalTracks"),
00217    inSeeds1 = cms.InputTag("trackerDrivenElectronSeedsORG", process.trackerDrivenElectronSeeds.PreGsfLabel.value()),
00218    inPreId1 = cms.InputTag("trackerDrivenElectronSeedsORG", process.trackerDrivenElectronSeeds.PreIdLabel.value()),
00219    inSeeds2 = cms.InputTag("trackerDrivenElectronSeeds", process.trackerDrivenElectronSeeds.PreGsfLabel.value()),
00220    inPreId2 = cms.InputTag("trackerDrivenElectronSeeds", process.trackerDrivenElectronSeeds.PreIdLabel.value())
00221   )
00222 
00223   process.electronMergedSeedsPhotonCoreHack = cms.EDProducer("ElectronSeedMerger",
00224     EcalBasedSeeds = cms.InputTag("ecalDrivenElectronSeeds"),
00225     TkBasedSeeds = cms.InputTag("trackerDrivenElectronSeedsMerged","SeedsForGsf")
00226   )
00227 
00228   process.photonCore.pixelSeedProducer = cms.string('electronMergedSeedsPhotonCoreHack')
00229 
00230 
00231   for p in process.paths:
00232     pth = getattr(process,p)
00233     if "photonCore" in pth.moduleNames():
00234         pth.replace(process.photonCore, 
00235                     process.trackerDrivenElectronSeedsMerged * process.electronMergedSeedsPhotonCoreHack *process.photonCore)
00236 
00237 
00238 
00239 
00240   # mix gsfTracks
00241   process.electronGsfTracksORG = process.electronGsfTracks.clone()
00242   process.electronGsfTracks = cms.EDProducer("GsfTrackMixer", 
00243       col1 = cms.InputTag("electronGsfTracksORG","","EmbeddedRECO"),
00244       col2= cms.InputTag("electronGsfTracks","", inputProcess),
00245   )
00246 
00247   # TODO: in 42x conversions seem not be used anywhere during reco. What about ana?
00248   # what about 52X?
00249   process.gsfConversionTrackProducer.TrackProducer = cms.string('electronGsfTracksORG')
00250 
00251   for p in process.paths:
00252     pth = getattr(process,p)
00253     if "electronGsfTracks" in pth.moduleNames():
00254         pth.replace(process.electronGsfTracks, process.electronGsfTracksORG*process.electronGsfTracks)
00255 
00256 
00257 
00258 
00259 
00260   '''
00261   process.electronMergedSeedsORG = process.electronMergedSeeds.clone()
00262   process.electronMergedSeeds = cms.EDProducer("ElectronSeedsMixer",
00263       col1 = cms.InputTag("electronMergedSeeds","", inputProcess),
00264       col2 = cms.InputTag("electronMergedSeedsORG","","EmbeddedRECO")
00265   )
00266   for p in process.paths:
00267     pth = getattr(process,p)
00268     if "electronMergedSeeds" in pth.moduleNames():
00269       pth.replace(process.electronMergedSeeds, process.electronMergedSeedsORG*process.electronMergedSeeds)
00270   '''
00271 
00272   process.generalConversionTrackProducer.TrackProducer = cms.string('generalTracksORG')
00273 
00274 
00275   process.gsfElectronsORG = process.gsfElectrons.clone()
00276   process.gsfElectrons = cms.EDProducer("GSFElectronsMixer",
00277       col1 = cms.InputTag("gsfElectronsORG"),
00278       col2 = cms.InputTag("gsfElectrons","",inputProcess),
00279   )
00280   for p in process.paths:
00281     pth = getattr(process,p)
00282     if "gsfElectrons" in pth.moduleNames():
00283       pth.replace(process.gsfElectrons, process.gsfElectronsORG*process.gsfElectrons)
00284 
00285 
00286 
00287 
00288   for p in process.paths:
00289     pth = getattr(process,p)
00290     #print dir(pth)
00291     #sys.exit(0)
00292     for mod in pth.moduleNames():
00293       if mod.find("dedx") != -1:
00294         print "Removing", mod
00295         module=getattr(process,mod)
00296         pth.remove(module)
00297 
00298 
00299  
00300   clConfig = cms.PSet (
00301              depsPlus = cms.InputTag("anaDeposits", "plus" ),
00302              depsMinus = cms.InputTag("anaDeposits", "minus" )
00303   ) 
00304 
00305 
00306 
00307   process.castorrecoORG = process.castorreco.clone()
00308   process.castorreco = cms.EDProducer("CastorRHMixer",
00309        cleaningAlgo = cms.string("CaloCleanerAllCrossed"),
00310        cleaningConfig = clConfig,
00311        todo = cms.VPSet(cms.PSet ( colZmumu = cms.InputTag("castorreco","", inputProcess  ), colTauTau = cms.InputTag("castorrecoORG" )  ))
00312   )
00313 
00314   for p in process.paths:
00315     pth = getattr(process,p)
00316     if "castorreco" in pth.moduleNames():
00317       pth.replace(process.castorreco, process.castorrecoORG*process.castorreco)
00318 
00319   process.ecalRecHitORG = process.ecalRecHit.clone()
00320   process.ecalRecHit = cms.EDProducer("EcalRHMixer",
00321          cleaningAlgo = cms.string("CaloCleanerAllCrossed"), # CaloCleanerMVA
00322          #cleaningAlgo = cms.string("CaloCleanerMVA"), 
00323          cleaningConfig = clConfig,
00324          todo = cms.VPSet(
00325               cms.PSet ( colZmumu = cms.InputTag("ecalRecHit","EcalRecHitsEB", inputProcess ), 
00326                          colTauTau = cms.InputTag("ecalRecHitORG","EcalRecHitsEB" )  ),
00327 
00328               cms.PSet ( colZmumu = cms.InputTag("ecalRecHit","EcalRecHitsEE", inputProcess  ), 
00329                          colTauTau = cms.InputTag("ecalRecHitORG","EcalRecHitsEE" )  )
00330          )
00331   )
00332   for p in process.paths:
00333     pth = getattr(process,p)
00334     if "ecalRecHit" in pth.moduleNames():
00335       pth.replace(process.ecalRecHit, process.ecalRecHitORG*process.ecalRecHit)
00336 
00337 
00338 
00339   process.hbherecoORG = process.hbhereco.clone()
00340   process.hbhereco = cms.EDProducer("HBHERHMixer",
00341          cleaningAlgo = cms.string("CaloCleanerAllCrossed"),
00342          cleaningConfig = clConfig,
00343          todo = 
00344            cms.VPSet(cms.PSet ( colZmumu = cms.InputTag( "hbhereco","", inputProcess  ), colTauTau = cms.InputTag("hbherecoORG","" )))
00345   )
00346   for p in process.paths:
00347     pth = getattr(process,p)
00348     if "hbhereco" in pth.moduleNames():
00349       pth.replace(process.hbhereco, process.hbherecoORG*process.hbhereco)
00350 
00351   # typedef CaloRecHitMixer< HFRecHit >   HFRHMixer;
00352   process.hfrecoORG = process.hfreco.clone()
00353   process.hfreco = cms.EDProducer("HFRHMixer",
00354          cleaningAlgo = cms.string("CaloCleanerAllCrossed"),
00355          cleaningConfig = clConfig,
00356          todo =
00357            cms.VPSet(cms.PSet ( colZmumu = cms.InputTag( "hfreco","", inputProcess  ), colTauTau = cms.InputTag("hfrecoORG","" )))
00358   )
00359   for p in process.paths:
00360     pth = getattr(process,p)
00361     if "hfreco" in pth.moduleNames():
00362       pth.replace(process.hfreco, process.hfrecoORG*process.hfreco)
00363 
00364 
00365   # typedef CaloRecHitMixer< HORecHit > HORHMixer;
00366   process.horecoORG = process.horeco.clone()
00367   process.horeco = cms.EDProducer("HORHMixer",
00368          cleaningAlgo = cms.string("CaloCleanerAllCrossed"),
00369          cleaningConfig = clConfig,
00370          todo =
00371            cms.VPSet(cms.PSet ( colZmumu = cms.InputTag( "horeco","", inputProcess  ), colTauTau = cms.InputTag("horecoORG","" )))
00372   )
00373   for p in process.paths:
00374     pth = getattr(process,p)
00375     if "horeco" in pth.moduleNames():
00376       pth.replace(process.horeco, process.horecoORG*process.horeco)
00377 
00378 
00379 
00380    
00381 
00382 
00383   # it should be the best solution to take the original beam spot for the
00384   # reconstruction of the new primary vertex
00385   # use the  one produced earlier, do not produce your own
00386   for s in process.sequences:
00387      seq =  getattr(process,s)
00388      seq.remove(process.offlineBeamSpot) 
00389 
00390 
00391   try:
00392         process.metreco.remove(process.BeamHaloId)
00393   except:
00394         pass
00395 
00396   try:
00397           outputModule = process.output
00398   except:
00399     pass
00400   try:
00401           outputModule = getattr(process,str(getattr(process,list(process.endpaths)[-1])))
00402   except:
00403     pass
00404 
00405   process.filterEmptyEv.src = cms.untracked.InputTag("generator","","EmbeddedRECO")
00406 
00407 
00408   try:
00409     process.schedule.remove(process.DQM_FEDIntegrity_v3)
00410   except:
00411     pass
00412 
00413 
00414   process.RECOSIMoutput.outputCommands.extend(['keep *_*_*_skimGoldenZmumu2'])
00415 
00416   # keep orginal collections, needed for PF2PAT - generalTracksORG, not sure for others 
00417   process.RECOSIMoutput.outputCommands.extend(['keep *_*ORG_*_*'])
00418 
00419   #xxx process.globalMuons.TrackerCollectionLabel = cms.InputTag("generalTracksORG")
00420   #xxx process.globalSETMuons.TrackerCollectionLabel = cms.InputTag("generalTracksORG")
00421   #print "TODO: add xcheck, that this is not changed"
00422   #process.muons.inputCollectionLabels = cms.VInputTag(cms.InputTag("generalTracksORG"), 
00423   #                             cms.InputTag("globalMuons"), 
00424   #                             cms.InputTag("standAloneMuons","UpdatedAtVtx"))
00425 
00426 
00427   skimEnabled = False
00428   if hasattr(process,"doZmumuSkim"):
00429       print "Enabling Zmumu skim"
00430       skimEnabled = True
00431       #process.load("TauAnalysis/Skimming/goldenZmmSelectionVBTFrelPFIsolation_cfi")
00432 
00433       
00434       cmssw_ver = os.environ["CMSSW_VERSION"]
00435       if cmssw_ver.find("CMSSW_4_2") != -1:
00436         print
00437         print "Using legacy version of Zmumu skim. Note, that muon isolation is disabled"
00438         print
00439         process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelectionLegacy_cff")
00440       else:
00441         process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandalonSelection_cff")
00442       process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi")
00443 
00444       # we are allready selecting events from generation step, so following way is ok
00445       for path in process.paths:
00446           getattr(process,path)._seq = process.goldenZmumuSelectionSequence * getattr(process,path)._seq
00447 
00448       #process.options = cms.untracked.PSet(
00449       #  wantSummary = cms.untracked.bool(True)
00450       #)
00451 
00452 
00453 
00454 
00455   if not skimEnabled:
00456       print "Zmumu skim not enabled"
00457 
00458 
00459   print "# ######################################################################################"
00460   print "  Following parameters can be added before customize function "
00461   print "  call in order to controll process  customization: " 
00462   print "     process.doNotParse =  cms.PSet() # disables CL parsing for crab compat"
00463   print "     process.doZmumuSkim = cms.PSet() # adds Zmumu skimming before embedding is run"
00464   print "# ######################################################################################"
00465 
00466 
00467   return(process)