Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-26 23:20:39

0001 #!/usr/bin/env python
0002 
0003 
0004 ### Various set of customise functions needed for embedding
0005 from __future__ import print_function
0006 import FWCore.ParameterSet.Config as cms
0007 
0008 ################################ Customizer for skimming ###########################
0009 ### There are four different parts.
0010 ##First step is the SELECT (former SKIM) part, where we identfy the events which are good for Embedding. Need to store RAWRECO [RAW is needed for the MERG and RECO for the CLEAN step]
0011 ##Second step is the CLEAN input are PAT muons with RECO information. After this step only RAW plus some special collections needed for the MERG step must be saved
0012 ##Third step is the SIM. The input is the externalLHEProducer, which must be produced before (At the moment we do it parallel to the CLEAN step). Again only save RAW of the SELECT and only save what is need for the MERG step
0013 ##Last step is the MERG step. Which is the usally reconstruction, where the input produces are replaced by merg producer, which mix the SIM and CLEAN inputs.
0014 
0015 ## Some comments on this approach. All steps runs the RECO sequence until the end in the moment. It would be possible to stop after the all inputs which are needed for the MERG step are generated (which happens at a very early state of the reconstruction. But with this approach we are able to get the RECO (and PAT aka miniAOD) of all four step SELECT (orginal event), SIM, CLEAN and MERGED. Therefor one only needs to SAVE the corresponding output (in cmsDriver change output to RAW -> RAW,RECO,PAT)
0016 
0017 #######################  Some basic functions ####################
0018 ## Helper Class, which summerizes in which step which Producer (Cleaner Merger), should be loaded. It is also usefull to define which collection should be stored for the next step
0019 ## E.g What is needed for MERGE must be produce in the CLEAN and SIM step
0020 
0021 
0022 class module_manipulate():
0023     def __init__(self, module_name, manipulator_name, steps = ["SELECT","CLEAN","SIM","MERGE"], instance=[""], merge_prefix = ""):
0024         self.module_name = module_name
0025         self.manipulator_name = manipulator_name
0026         self.steps = steps
0027         self.instance = instance
0028         self.merger_name = manipulator_name+"ColMerger"
0029         self.cleaner_name = manipulator_name+"ColCleaner"
0030         self.merge_prefix = merge_prefix
0031 
0032 
0033 
0034 
0035 to_bemanipulate = []
0036 
0037 
0038 to_bemanipulate.append(module_manipulate(module_name = 'siPixelClusters', manipulator_name = "Pixel", steps = ["SELECT","CLEAN"] ))
0039 to_bemanipulate.append(module_manipulate(module_name = 'siStripClusters', manipulator_name = "Strip", steps = ["SELECT","CLEAN"] ))
0040 
0041 to_bemanipulate.append(module_manipulate(module_name = 'generalTracks', manipulator_name = "Track", steps = ["SIM", "MERGE"]))
0042 to_bemanipulate.append(module_manipulate(module_name = 'muons1stStep', manipulator_name = "Muon", steps = ["SIM", "MERGE"]))
0043 to_bemanipulate.append(module_manipulate(module_name = 'gedGsfElectronsTmp', manipulator_name = "GsfElectron", steps = ["SIM", "MERGE"]))
0044 to_bemanipulate.append(module_manipulate(module_name = 'gedPhotonsTmp', manipulator_name = "Photon", steps = ["SIM", "MERGE"]))
0045 to_bemanipulate.append(module_manipulate(module_name = 'particleFlowTmp', manipulator_name = "PF", steps = ["SIM", "MERGE"], instance=["","CleanedHF","CleanedCosmicsMuons","CleanedTrackerAndGlobalMuons","CleanedFakeMuons","CleanedPunchThroughMuons","CleanedPunchThroughNeutralHadrons","AddedMuonsAndHadrons"]))
0046 
0047 
0048 to_bemanipulate.append(module_manipulate(module_name = 'ecalRecHit', manipulator_name = "EcalRecHit", instance= ["EcalRecHitsEB","EcalRecHitsEE"]))
0049 to_bemanipulate.append(module_manipulate(module_name = 'ecalPreshowerRecHit', manipulator_name = "EcalRecHit", instance= ["EcalRecHitsES"]))
0050 
0051 to_bemanipulate.append(module_manipulate(module_name = 'hbheprereco', manipulator_name = "HBHERecHit"))
0052 to_bemanipulate.append(module_manipulate(module_name = 'hbhereco', manipulator_name = "HBHERecHit"))
0053 to_bemanipulate.append(module_manipulate(module_name = 'zdcreco', manipulator_name = "ZDCRecHit"))
0054 
0055 to_bemanipulate.append(module_manipulate(module_name = 'horeco', manipulator_name = "HORecHit"))
0056 to_bemanipulate.append(module_manipulate(module_name = 'hfreco', manipulator_name = "HFRecHit"))
0057 to_bemanipulate.append(module_manipulate(module_name = 'castorreco', manipulator_name = "CastorRecHit"))
0058 
0059 
0060 to_bemanipulate.append(module_manipulate(module_name = 'dt1DRecHits', manipulator_name = "DTRecHit",  steps = ["SELECT","CLEAN"] ))
0061 to_bemanipulate.append(module_manipulate(module_name = 'dt1DCosmicRecHits', manipulator_name = "DTRecHit", steps = ["SELECT","CLEAN"]  ))
0062 
0063 to_bemanipulate.append(module_manipulate(module_name = 'csc2DRecHits', manipulator_name = "CSCRecHit", steps = ["SELECT","CLEAN"]  ))
0064 to_bemanipulate.append(module_manipulate(module_name = 'rpcRecHits', manipulator_name = "RPCRecHit",  steps = ["SELECT","CLEAN"] ))
0065 
0066 
0067 def modify_outputModules(process, keep_drop_list = [], module_veto_list = [] ):
0068     outputModulesList = [key for key,value in process.outputModules.items()]
0069     for outputModule in outputModulesList:
0070         if outputModule in module_veto_list:
0071             continue
0072         outputModule = getattr(process, outputModule)
0073         for add_element in keep_drop_list:
0074             outputModule.outputCommands.extend(add_element)
0075     return process
0076 
0077 
0078 
0079 ################################ Customizer for Selecting ###########################
0080 
0081 def keepSelected(dataTier):
0082     ret_vstring = cms.untracked.vstring(
0083                   #  "drop *_*_*_"+dataTier,
0084                     "keep *_patMuonsAfterID_*_"+dataTier,
0085                     "keep *_slimmedMuons_*_"+dataTier,
0086                     "keep *_selectedMuonsForEmbedding_*_"+dataTier,
0087                     "keep recoVertexs_offlineSlimmedPrimaryVertices_*_"+dataTier,
0088                     "keep *_firstStepPrimaryVertices_*_"+dataTier,
0089                     "keep *_offlineBeamSpot_*_"+dataTier
0090                     )
0091     for akt_manimod in to_bemanipulate:
0092         if "CLEAN" in akt_manimod.steps:
0093             ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_"+dataTier)
0094     return ret_vstring
0095 
0096 def customiseSelecting(process,reselect=False):
0097     if reselect:
0098         process._Process__name = "RESELECT"
0099         dataTier="RESELECT"
0100     else:
0101         process._Process__name = "SELECT"
0102         dataTier="SELECT"
0103 
0104     process.load('TauAnalysis.MCEmbeddingTools.SelectingProcedure_cff')
0105     # don't rekey TrackExtra refs because the full original collections are anyways stored
0106     process.slimmedMuons.trackExtraAssocs = []
0107     process.patMuonsAfterKinCuts.src = cms.InputTag("slimmedMuons","",dataTier)
0108     process.patMuonsAfterID = process.patMuonsAfterLooseID.clone()
0109 
0110     process.selecting = cms.Path(process.makePatMuonsZmumuSelection)
0111     process.schedule.insert(-1, process.selecting)
0112 
0113     outputModulesList = [key for key,value in process.outputModules.items()]
0114     for outputModule in outputModulesList:
0115         outputModule = getattr(process, outputModule)
0116         outputModule.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring("selecting"))
0117         outputModule.outputCommands.extend(keepSelected(dataTier))
0118 
0119     process = customisoptions(process)
0120     return modify_outputModules(process,[keepSelected(dataTier)])
0121 
0122 def customiseSelecting_Reselect(process):
0123     return customiseSelecting(process,reselect=True)
0124 
0125 ################################ Customizer for cleaining ###########################
0126 def keepCleaned():
0127     ret_vstring = cms.untracked.vstring(
0128 #                        "drop *_*_*_LHEembeddingCLEAN",
0129 #                        "drop *_*_*_CLEAN"
0130                             )
0131 
0132     for akt_manimod in to_bemanipulate:
0133         if "MERGE" in akt_manimod.steps:
0134             ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_LHEembeddingCLEAN")
0135             ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_CLEAN")
0136     ret_vstring.append("keep *_standAloneMuons_*_LHEembeddingCLEAN")
0137     ret_vstring.append("keep *_glbTrackQual_*_LHEembeddingCLEAN")
0138     return ret_vstring
0139 
0140 
0141 
0142 def customiseCleaning(process, changeProcessname=True,reselect=False):
0143     if changeProcessname:
0144         process._Process__name = "CLEAN"
0145     if reselect:
0146         dataTier="RESELECT"
0147     else: 
0148         dataTier="SELECT"
0149     ## Needed for the Calo Cleaner, could also be put into a function wich fix the input parameters
0150     from TrackingTools.TrackAssociator.default_cfi import TrackAssociatorParameterBlock
0151     TrackAssociatorParameterBlock.TrackAssociatorParameters.CSCSegmentCollectionLabel = cms.InputTag("cscSegments","",dataTier)
0152     TrackAssociatorParameterBlock.TrackAssociatorParameters.CaloTowerCollectionLabel = cms.InputTag("towerMaker","",dataTier)
0153     TrackAssociatorParameterBlock.TrackAssociatorParameters.DTRecSegment4DCollectionLabel = cms.InputTag("dt4DSegments","",dataTier)
0154     TrackAssociatorParameterBlock.TrackAssociatorParameters.EBRecHitCollectionLabel = cms.InputTag("ecalRecHit","EcalRecHitsEB",dataTier)
0155     TrackAssociatorParameterBlock.TrackAssociatorParameters.EERecHitCollectionLabel = cms.InputTag("ecalRecHit","EcalRecHitsEE",dataTier)
0156     TrackAssociatorParameterBlock.TrackAssociatorParameters.HBHERecHitCollectionLabel = cms.InputTag("hbhereco","",dataTier)
0157     TrackAssociatorParameterBlock.TrackAssociatorParameters.HORecHitCollectionLabel = cms.InputTag("horeco","",dataTier)
0158 
0159 
0160     MuonImput = cms.InputTag("selectedMuonsForEmbedding","","")  ## This are the muon
0161     for akt_manimod in to_bemanipulate:
0162         if "CLEAN" in akt_manimod.steps:
0163             oldCollections_in = cms.VInputTag()
0164             for instance in akt_manimod.instance:
0165                 oldCollections_in.append(cms.InputTag(akt_manimod.module_name,instance,dataTier))
0166             setattr(process, akt_manimod.module_name, cms.EDProducer(akt_manimod.cleaner_name,MuonCollection = MuonImput,TrackAssociatorParameters = TrackAssociatorParameterBlock.TrackAssociatorParameters,oldCollection = oldCollections_in))
0167     process.ecalPreshowerRecHit.TrackAssociatorParameters.usePreshower = cms.bool(True)
0168     process = customisoptions(process)  
0169     return modify_outputModules(process,[keepSelected(dataTier),keepCleaned()],["MINIAODoutput"])
0170 
0171 
0172 ################################ Customizer for simulaton ###########################
0173 def keepLHE():
0174     ret_vstring = cms.untracked.vstring()
0175     ret_vstring.append("keep *_externalLHEProducer_*_LHEembedding")
0176     ret_vstring.append("keep *_externalLHEProducer_*_LHEembeddingCLEAN")
0177     return ret_vstring
0178 
0179 
0180 def keepSimulated():
0181     ret_vstring = cms.untracked.vstring()
0182     for akt_manimod in to_bemanipulate:
0183         if "MERGE" in akt_manimod.steps:
0184             ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_SIMembedding")
0185     ret_vstring.append("keep *_genParticles_*_SIMembedding")
0186     ret_vstring.append("keep *_standAloneMuons_*_SIMembedding")
0187     ret_vstring.append("keep *_glbTrackQual_*_SIMembedding")
0188     ret_vstring.append("keep *_generator_*_SIMembedding")
0189     ret_vstring.append("keep *_addPileupInfo_*_SIMembedding")
0190     ret_vstring.append("keep *_slimmedAddPileupInfo_*_*")
0191     return ret_vstring
0192 
0193 
0194 
0195 
0196 def customiseLHE(process, changeProcessname=True,reselect=False):
0197     if reselect:
0198         dataTier="RESELECT"
0199     else: 
0200         dataTier="SELECT"
0201     if changeProcessname:
0202         process._Process__name = "LHEembedding"
0203     process.load('TauAnalysis.MCEmbeddingTools.EmbeddingLHEProducer_cfi')
0204     if reselect:
0205         process.externalLHEProducer.vertices=cms.InputTag("offlineSlimmedPrimaryVertices","","RESELECT")
0206     process.lheproduction = cms.Path(process.makeexternalLHEProducer)
0207     process.schedule.insert(0,process.lheproduction)
0208 
0209 
0210     process = customisoptions(process)
0211     return modify_outputModules(process,[keepSelected(dataTier),keepCleaned(), keepLHE()],["MINIAODoutput"])
0212 
0213 
0214 def customiseGenerator(process, changeProcessname=True,reselect=False):
0215     if reselect:
0216         dataTier="RESELECT"
0217     else:
0218         dataTier="SELECT"
0219     if changeProcessname:
0220         process._Process__name = "SIMembedding"
0221 
0222     ## here correct the vertex collection
0223 
0224     process.load('TauAnalysis.MCEmbeddingTools.EmbeddingVertexCorrector_cfi')
0225     process.VtxSmeared = process.VtxCorrectedToInput.clone()
0226     print("Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector.")
0227 
0228     # Remove BeamSpot Production, use the one from selected data instead.
0229     process.reconstruction.remove(process.offlineBeamSpot)
0230 
0231     # Disable noise simulation
0232     process.mix.digitizers.castor.doNoise = cms.bool(False)
0233 
0234     process.mix.digitizers.ecal.doESNoise = cms.bool(False)
0235     process.mix.digitizers.ecal.doENoise = cms.bool(False)
0236 
0237     process.mix.digitizers.hcal.doNoise = cms.bool(False)
0238     process.mix.digitizers.hcal.doThermalNoise = cms.bool(False)
0239     process.mix.digitizers.hcal.doHPDNoise = cms.bool(False)
0240 
0241     process.mix.digitizers.pixel.AddNoisyPixels = cms.bool(False)
0242     process.mix.digitizers.pixel.AddNoise = cms.bool(False)
0243 
0244     process.mix.digitizers.strip.Noise = cms.bool(False)
0245 
0246 
0247     process = customisoptions(process) 
0248     ##process = fix_input_tags(process)
0249 
0250     return modify_outputModules(process,[keepSelected(dataTier),keepCleaned(),keepSimulated()],["AODSIMoutput"])
0251 
0252 def customiseGenerator_Reselect(process):
0253     return customiseGenerator(process,reselect=True)
0254 
0255 ################################ Customizer for merging ###########################
0256 def keepMerged(dataTier="SELECT"):
0257     ret_vstring = cms.untracked.vstring()
0258     ret_vstring.append("drop *_*_*_"+dataTier)
0259     ret_vstring.append("keep *_prunedGenParticles_*_MERGE")
0260     ret_vstring.append("keep *_generator_*_SIMembedding")
0261     return ret_vstring
0262 
0263 
0264 def customiseKeepPrunedGenParticles(process,reselect=False):
0265     if reselect:
0266         dataTier="RESELECT"
0267     else:
0268         dataTier="SELECT"
0269 
0270     process.load('PhysicsTools.PatAlgos.slimming.genParticles_cff')
0271     process.merge_step += process.prunedGenParticlesWithStatusOne
0272     process.load('PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi')
0273     process.merge_step += process.prunedGenParticles
0274     process.load('PhysicsTools.PatAlgos.slimming.packedGenParticles_cfi')
0275     process.merge_step += process.packedGenParticles
0276 
0277     process.load('PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi')
0278     process.merge_step += process.muonMatch
0279     process.load('PhysicsTools.PatAlgos.mcMatchLayer0.electronMatch_cfi')
0280     process.merge_step += process.electronMatch
0281     process.load('PhysicsTools.PatAlgos.mcMatchLayer0.photonMatch_cfi')
0282     process.merge_step += process.photonMatch
0283     process.load('PhysicsTools.PatAlgos.mcMatchLayer0.tauMatch_cfi')
0284     process.merge_step += process.tauMatch
0285     process.load('PhysicsTools.JetMCAlgos.TauGenJets_cfi')
0286     process.merge_step += process.tauGenJets
0287     process.load('PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff')
0288     process.merge_step += process.patJetPartons
0289     process.load('PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi')
0290     process.merge_step += process.patJetPartonMatch
0291 
0292     process.muonMatch.matched = "prunedGenParticles"
0293     process.electronMatch.matched = "prunedGenParticles"
0294     process.electronMatch.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons")
0295     process.photonMatch.matched = "prunedGenParticles"
0296     process.photonMatch.src = cms.InputTag("reducedEgamma","reducedGedPhotons")
0297     process.tauMatch.matched = "prunedGenParticles"
0298     process.tauGenJets.GenParticles = "prunedGenParticles"
0299     ##Boosted taus
0300     #process.tauMatchBoosted.matched = "prunedGenParticles"
0301     #process.tauGenJetsBoosted.GenParticles = "prunedGenParticles"
0302     process.patJetPartons.particles = "prunedGenParticles"
0303     process.patJetPartonMatch.matched = "prunedGenParticles"
0304     process.patJetPartonMatch.mcStatus = [ 3, 23 ]
0305     process.patJetGenJetMatch.matched = "slimmedGenJets"
0306     process.patJetGenJetMatchAK8.matched =  "slimmedGenJetsAK8"
0307     process.patJetGenJetMatchAK8Puppi.matched =  "slimmedGenJetsAK8"
0308     process.patMuons.embedGenMatch = False
0309     process.patElectrons.embedGenMatch = False
0310     process.patPhotons.embedGenMatch = False
0311     process.patTaus.embedGenMatch = False
0312     process.patTausBoosted.embedGenMatch = False
0313     process.patJets.embedGenPartonMatch = False
0314     #also jet flavour must be switched
0315     process.patJetFlavourAssociation.rParam = 0.4
0316 
0317     process.schedule.insert(0,process.merge_step)
0318     process = customisoptions(process)  
0319     return modify_outputModules(process, [keepMerged(dataTier)])
0320 
0321 
0322 def customiseMerging(process, changeProcessname=True,reselect=False):
0323     if changeProcessname:
0324         process._Process__name = "MERGE"
0325     if reselect:
0326         dataTier="RESELECT"
0327     else:
0328         dataTier="SELECT"
0329 
0330 
0331     process.source.inputCommands = cms.untracked.vstring()
0332     process.source.inputCommands.append("keep *_*_*_*")
0333 
0334     #process.source.inputCommands.append("drop *_*_*_SELECT")
0335     #process.source.inputCommands.append("drop *_*_*_SIMembedding")
0336     #process.source.inputCommands.append("drop *_*_*_LHEembeddingCLEAN")
0337     #process.source.inputCommands.extend(keepSimulated())
0338     #process.source.inputCommands.extend(keepCleaned())
0339 
0340     process.load('Configuration.StandardSequences.Reconstruction_Data_cff')
0341     process.merge_step = cms.Path()
0342 
0343 
0344     for akt_manimod in to_bemanipulate:
0345         if "MERGE" in akt_manimod.steps:
0346     #if akt_manimod.module_name != 'particleFlowTmp':
0347     #  continue
0348             print(akt_manimod.module_name)
0349             mergCollections_in = cms.VInputTag()
0350             for instance in akt_manimod.instance:
0351                 mergCollections_in.append(cms.InputTag(akt_manimod.merge_prefix+akt_manimod.module_name,instance,"SIMembedding"))
0352                 mergCollections_in.append(cms.InputTag(akt_manimod.merge_prefix+akt_manimod.module_name,instance,"LHEembeddingCLEAN"))##  Mayb make some process history magic which finds out if it was CLEAN or LHEembeddingCLEAN step
0353             setattr(process, akt_manimod.module_name, cms.EDProducer(akt_manimod.merger_name,
0354                                                      mergCollections = mergCollections_in
0355                                                      )
0356             )
0357             process.merge_step +=getattr(process, akt_manimod.module_name)
0358 
0359 
0360     process.merge_step += process.doAlldEdXEstimators
0361     process.merge_step += process.vertexreco
0362     process.unsortedOfflinePrimaryVertices.beamSpotLabel = cms.InputTag("offlineBeamSpot","",dataTier)
0363     process.ak4CaloJetsForTrk.srcPVs = cms.InputTag("firstStepPrimaryVertices","",dataTier)
0364 
0365     process.muons.FillDetectorBasedIsolation = cms.bool(False)
0366     process.muons.FillSelectorMaps = cms.bool(False)
0367     process.muons.FillShoweringInfo = cms.bool(False)
0368     process.muons.FillCosmicsIdMap = cms.bool(False)
0369 
0370     process.muonsFromCosmics.fillShowerDigis = cms.bool(False)
0371     process.muonsFromCosmics1Leg.fillShowerDigis = cms.bool(False)
0372 
0373     process.merge_step += process.highlevelreco
0374 
0375     #process.merge_step.remove(process.reducedEcalRecHitsEE)
0376     #process.merge_step.remove(process.reducedEcalRecHitsEB)
0377 
0378     process.merge_step.remove(process.ak4JetTracksAssociatorExplicit)
0379 
0380     process.merge_step.remove(process.pfTrack)
0381     process.merge_step.remove(process.pfConversions)
0382     process.merge_step.remove(process.pfV0)
0383     process.merge_step.remove(process.particleFlowDisplacedVertexCandidate)
0384     process.merge_step.remove(process.particleFlowDisplacedVertex)
0385     process.merge_step.remove(process.pfDisplacedTrackerVertex)
0386     process.merge_step.remove(process.pfTrackElec)
0387     process.merge_step.remove(process.electronsWithPresel)
0388     process.merge_step.remove(process.mvaElectrons)
0389     process.merge_step.remove(process.particleFlowBlock)
0390     process.merge_step.remove(process.particleFlowEGamma)
0391     process.merge_step.remove(process.gedGsfElectronCores)
0392     #  process.merge_step.remove(process.gedGsfElectronsTmp)
0393     process.merge_step.remove(process.gedPhotonCore)
0394     process.merge_step.remove(process.ecalDrivenGsfElectronCores)
0395     process.merge_step.remove(process.ecalDrivenGsfElectrons)
0396     process.merge_step.remove(process.uncleanedOnlyElectronSeeds)
0397     process.merge_step.remove(process.uncleanedOnlyAllConversions)
0398     process.merge_step.remove(process.uncleanedOnlyPfTrack)
0399     process.merge_step.remove(process.uncleanedOnlyPfTrackElec)
0400     process.merge_step.remove(process.uncleanedOnlyGsfElectrons)
0401     process.merge_step.remove(process.uncleanedOnlyElectronCkfTrackCandidates)
0402     process.merge_step.remove(process.cosmicsVeto)
0403     process.merge_step.remove(process.cosmicsVetoTrackCandidates)
0404  #   process.merge_step.remove(process.ecalDrivenGsfElectronCores)
0405  #   process.merge_step.remove(process.ecalDrivenGsfElectrons)
0406  #   process.merge_step.remove(process.gedPhotonsTmp)
0407  #   process.merge_step.remove(process.particleFlowTmp)
0408     process.merge_step.remove(process.hcalnoise)
0409     process.merge_step.remove(process.lowPtGsfElectronTask)
0410     process.merge_step.remove(process.gsfTracksOpenConversions)
0411 
0412     process.load('CommonTools.ParticleFlow.genForPF2PAT_cff')
0413 
0414     process.merge_step += process.genForPF2PATSequence
0415 
0416     process.slimmingTask.remove(process.slimmedLowPtElectronsTask)
0417 
0418     process.schedule.insert(0,process.merge_step)
0419     # process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi')
0420 
0421     process = customisoptions(process) 
0422     return modify_outputModules(process, [keepMerged(dataTier)])
0423 
0424 def customiseMerging_Reselect(process, changeProcessname=True):
0425     return customiseMerging(process, changeProcessname=changeProcessname, reselect=True)
0426 
0427 ################################ cross Customizers ###########################
0428 
0429 def customiseLHEandCleaning(process,reselect=False):
0430     process._Process__name = "LHEembeddingCLEAN"
0431     process = customiseCleaning(process,changeProcessname=False,reselect=reselect)
0432     process = customiseLHE(process,changeProcessname=False,reselect=reselect)
0433     return process
0434 
0435 def customiseLHEandCleaning_Reselect(process):
0436     return customiseLHEandCleaning(process,reselect=True)
0437 
0438 ################################ additionla Customizer ###########################
0439 
0440 def customisoptions(process):
0441     if not hasattr(process, "options"):
0442         process.options = cms.untracked.PSet()
0443     process.options.emptyRunLumiMode = cms.untracked.string('doNotHandleEmptyRunsAndLumis')
0444     if not hasattr(process, "bunchSpacingProducer"):
0445         process.load('RecoLuminosity.LumiProducer.bunchSpacingProducer_cfi')
0446         process.bunchSpacingProducer = process.bunchSpacingProducer.clone(overrideBunchSpacing = True)
0447     process.options.numberOfThreads = cms.untracked.uint32(1)
0448     process.options.numberOfStreams = cms.untracked.uint32(0)
0449     return process
0450 
0451 ############################### MC specific Customizer ###########################
0452 
0453 def customiseFilterZToMuMu(process):
0454     process.load("TauAnalysis.MCEmbeddingTools.DYToMuMuGenFilter_cfi")
0455     process.ZToMuMuFilter = cms.Path(process.dYToMuMuGenFilter)
0456     process.schedule.insert(-1,process.ZToMuMuFilter)
0457     return process
0458 
0459 def customiseFilterTTbartoMuMu(process):
0460     process.load("TauAnalysis.MCEmbeddingTools.TTbartoMuMuGenFilter_cfi")
0461     process.MCFilter = cms.Path(process.TTbartoMuMuGenFilter)
0462     return customiseMCFilter(process)
0463 
0464 def customiseMCFilter(process):
0465     process.schedule.insert(-1,process.MCFilter)
0466     outputModulesList = [key for key,value in process.outputModules.items()]
0467     for outputModule in outputModulesList:
0468         outputModule = getattr(process, outputModule)
0469         outputModule.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring("MCFilter"))
0470     return process
0471 
0472 def fix_input_tags(process, formodules = ["generalTracks","cscSegments","dt4DSegments","rpcRecHits"]):
0473     def change_tags_process(test_input):
0474         if isinstance(test_input, cms.InputTag):
0475             if test_input.getModuleLabel() in formodules:
0476                 test_input.setProcessName(process._Process__name)
0477 
0478     def search_for_tags(pset):
0479         if isinstance(pset, dict):
0480             for key in pset:
0481                 if isinstance(pset[key], cms.VInputTag):
0482                     for akt_inputTag in pset[key]:
0483                         change_tags_process(akt_inputTag)
0484                 elif isinstance(pset[key], cms.PSet):
0485                     search_for_tags(pset[key].__dict__)
0486                 elif isinstance(pset[key], cms.VPSet):
0487                     for akt_pset in pset[key]:
0488                         search_for_tags(akt_pset.__dict__)
0489                 else:
0490                     change_tags_process(pset[key])
0491         else:
0492             print("must be python dict not a ",type(pset))
0493 
0494     for module in process.producers_():
0495         search_for_tags(getattr(process, module).__dict__)
0496     for module in process.filters_():
0497         search_for_tags(getattr(process, module).__dict__)
0498     for module in process.analyzers_():
0499         search_for_tags(getattr(process, module).__dict__)
0500 
0501     return process