def insertSeeds(self, *seeds): """ _insertSeeds_ Given some list of specific seeds, insert them into the service. Length of seed list is required to be same as the seed count for the service. Usage: WM Tools. """ seeds = list(seeds) if len(seeds) < self.countSeeds(): msg = "Not enough seeds provided\n" msg += "Service requires %s seeds, only %s provided\n" msg += "to RandomeService.insertSeeds method\n" raise RuntimeError, msg for item in self.__psetsWithSeeds(): seedSet = getattr(item, "initialSeedSet", None) if seedSet != None: numSeeds = len(seedSet.value()) useSeeds = seeds[:numSeeds] seeds = seeds[numSeeds:] item.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(*useSeeds)) continue useSeed = seeds[0] seeds = seeds[1:] item.initialSeed = CfgTypes.untracked(CfgTypes.uint32(useSeed)) continue return
def insertOldSeeds(self, *seeds): """ _insertOldSeeds_ Backwards compatibility methods """ seedList = list(seeds) svc = self.data.services["RandomNumberGeneratorService"] # //=====Old methods, keep for backwards compat.======= # // #// srcSeedVec = getattr(svc, "sourceSeedVector", Utilities._CfgNoneType()).value() if srcSeedVec != None: numReq = len(srcSeedVec) seedsReq = seedList[0:numReq] seedList = seedList[numReq + 1:] svc.sourceSeedVector = CfgTypes.untracked( CfgTypes.vuint32(seedsReq)) else: svc.sourceSeed = CfgTypes.untracked( CfgTypes.uint32(seedList.pop(0))) modSeeds = getattr(svc, "moduleSeeds", Utilities._CfgNoneType()).value() if modSeeds != None: for param in modSeeds.parameterNames_(): setattr(modSeeds, param, CfgTypes.untracked(CfgTypes.uint32(seedList.pop(0)))) # // # // #//====End old stuff====================================== return
def insertSeeds(self, *seeds): """ _insertSeeds_ Given some list of specific seeds, insert them into the service. Length of seed list is required to be same as the seed count for the service. Usage: WM Tools. """ seeds = list(seeds) if len(seeds) < self.countSeeds(): msg = "Not enough seeds provided\n" msg += "Service requires %s seeds, only %s provided\n" msg += "to RandomeService.insertSeeds method\n" raise RuntimeError, msg for item in self.__psetsWithSeeds(): seedSet = getattr(item, "initialSeedSet", None) if seedSet != None: numSeeds = len(seedSet.value()) useSeeds = seeds[:numSeeds] seeds = seeds[numSeeds:] item.initialSeedSet = CfgTypes.untracked(CfgTypes.vuint32(*useSeeds)) continue useSeed = seeds[0] seeds = seeds[1:] item.initialSeed = CfgTypes.untracked(CfgTypes.uint32(useSeed)) continue return
def insertOldSeeds(self, *seeds): """ _insertOldSeeds_ Backwards compatibility methods """ seedList = list(seeds) svc = self.data.services["RandomNumberGeneratorService"] # //=====Old methods, keep for backwards compat.======= # // #// srcSeedVec = getattr(svc, "sourceSeedVector", Utilities._CfgNoneType()).value() if srcSeedVec != None: numReq = len(srcSeedVec) seedsReq = seedList[0:numReq] seedList = seedList[numReq + 1:] svc.sourceSeedVector = CfgTypes.untracked( CfgTypes.vuint32(seedsReq)) else: svc.sourceSeed = CfgTypes.untracked( CfgTypes.uint32(seedList.pop(0))) modSeeds = getattr(svc, "moduleSeeds", Utilities._CfgNoneType()).value() if modSeeds != None: for param in modSeeds.parameterNames_(): setattr(modSeeds, param, CfgTypes.untracked(CfgTypes.uint32(seedList.pop(0)))) # // # // #//====End old stuff====================================== return
def setRunAndLumi(process, run, lumi): """ _setRunAndLumi_ Set the run and lumi number for the process provided via the EmptySource instance """ process.source.firstRun = CmsTypes.untracked(CmsTypes.uint32(run)) process.source.firstLuminosityBlock = CmsTypes.untracked( CmsTypes.uint32(lumi)) return
def makeProcess(numEvents = 200): """ _makeProcess_ Create a new Process instance """ proc = Process("HLT") proc.include("FWCore/MessageLogger/data/MessageLogger.cfi") configName = "fake-streamer-config" configVersion = timestamp() configAnnot = "auto generated fake streamer config" proc.configurationMetadata = CmsTypes.untracked(CmsTypes.PSet()) proc.configurationMetadata.name = CmsTypes.untracked(CmsTypes.string( configName)) proc.configurationMetadata.version = CmsTypes.untracked(CmsTypes.string( configVersion)) proc.configurationMetadata.annotation = CmsTypes.untracked(CmsTypes.string( configAnnot)) proc.options = CmsTypes.untracked(CmsTypes.PSet()) proc.options.wantSummary = CmsTypes.untracked(CmsTypes.bool(True)) proc.source = Source("EmptySource") proc.maxEvents = CmsTypes.untracked(CmsTypes.PSet()) proc.maxEvents.input = CmsTypes.untracked(CmsTypes.int32(numEvents)) proc.prod = EDProducer("StreamThingProducer") proc.prod.array_size = CmsTypes.int32(2500) proc.prod.instance_count = CmsTypes.int32(150) proc.prod.apply_bit_mask = CmsTypes.untracked(CmsTypes.bool(True)) proc.prod.bit_mask = CmsTypes.untracked( CmsTypes.uint32( 16777215)) proc.add_(Service("RandomNumberGeneratorService")) svc = proc.services["RandomNumberGeneratorService"] svc.moduleSeeds = CmsTypes.PSet() proc.makeData = Path(proc.prod) return proc
def mergeProcess(*inputFiles, **options): """ _mergeProcess_ Creates and returns a merge process that will merge the provided filenames supported options: - process_name : name of the procee, defaults to Merge - output_file : sets the output file name - output_lfn : sets the output LFN """ # // # // process supported options #// processName = options.get("process_name", "Merge") outputFilename = options.get("output_file", "Merged.root") outputLFN = options.get("output_lfn", None) # // # // build process #// process = Process(processName) # // # // input source #// process.source = Source("PoolSource") process.source.fileNames = CfgTypes.untracked(CfgTypes.vstring()) for entry in inputFiles: process.source.fileNames.append(str(entry)) # // # // output module #// process.Merged = OutputModule("PoolOutputModule") process.Merged.fileName = CfgTypes.untracked(CfgTypes.string( outputFilename)) if outputLFN != None: process.Merged.logicalFileName = CfgTypes.untracked(CfgTypes.string( outputLFN)) process.outputPath = EndPath(process.Merged) return process
def setLogicalFileName(self, lfn): """ _setLogicalFileName_ """ self.data.logicalFileName = CfgTypes.untracked(CfgTypes.string(lfn)) return
def insertSeeds(self, *seeds): """ _insertSeeds_ Insert the list of seeds into the RandomNumber Service """ seedList = list(seeds) if "RandomNumberGeneratorService" not in self.data.services.keys(): return if self.hasOldSeeds(): self.insertOldSeeds(*seeds) return # // # // Use seed service utility to generate seeds on the fly #// svc = self.data.services["RandomNumberGeneratorService"] try: from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper except ImportError: msg = "Unable to import RandomeNumberServiceHelper" print msg raise RuntimeError, msg randHelper = RandomNumberServiceHelper(svc) randHelper.populate() svc.saveFileName = CfgTypes.untracked( CfgTypes.string("RandomEngineState.log")) return
def insertPileupFiles(self, *fileList): """ _insertPileupFiles_ Insert the files provided into all mixing modules """ for mixMod in self.mixingModules(): print "Processing MixingModule: %s " % mixMod secSource = getattr(mixMod, "input", None) if secSource == None: secSource = getattr(mixMod, "secsource", None) if secSource == None: msg = "==============WARNING================\n" msg += "No Input PoolRASource found for mixing module:\n" msg += mixMod.dumpConfig() msg += "\nCannot add Pileup Files...\n" msg += "======================================\n" print msg continue oldfileList = getattr(secSource, "fileNames", None) if oldfileList == None: print "No existing file list" continue setattr(secSource, 'fileNames', CfgTypes.untracked(CfgTypes.vstring())) for fileName in fileList: secSource.fileNames.append(str(fileName)) print "PileupFile: %s " % str(fileName) return
def applyJSON( process, json ): myLumis = lumiList( json ) import FWCore.ParameterSet.Types as CfgTypes process.source.lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange()) process.source.lumisToProcess.extend(myLumis)
def mergeProcess(*inputFiles, **options): """ _mergeProcess_ Creates and returns a merge process that will merge the provided filenames supported options: - process_name : name of the process, defaults to Merge - outputmod_label : label of the output module, defaults to Merged - newDQMIO : specifies if the new DQM format should be used to merge the files - output_file : sets the output file name - output_lfn : sets the output LFN """ # // # // process supported options #// processName = options.get("process_name", "Merge") outputModLabel = options.get("outputmod_label", "Merged") outputFilename = options.get("output_file", "Merged.root") outputLFN = options.get("output_lfn", None) dropDQM = options.get("drop_dqm", False) newDQMIO = options.get("newDQMIO", False) # // # // build process #// process = Process(processName) # // # // input source #// if newDQMIO: process.source = Source("DQMRootSource") process.add_(Service("DQMStore")) else: process.source = Source("PoolSource") if dropDQM: process.source.inputCommands = CfgTypes.untracked.vstring('keep *','drop *_EDMtoMEConverter_*_*') process.source.fileNames = CfgTypes.untracked(CfgTypes.vstring()) for entry in inputFiles: process.source.fileNames.append(str(entry)) # // # // output module #// if newDQMIO: outMod = OutputModule("DQMRootOutputModule") else: outMod = OutputModule("PoolOutputModule") outMod.fileName = CfgTypes.untracked.string(outputFilename) if outputLFN != None: outMod.logicalFileName = CfgTypes.untracked.string(outputLFN) setattr(process, outputModLabel, outMod) process.outputPath = EndPath(outMod) return process
def insertSeeds(self, *seeds): """ _insertSeeds_ Insert the list of seeds into the RandomNumber Service """ seedList = list(seeds) if "RandomNumberGeneratorService" not in self.data.services.keys(): return if self.hasOldSeeds(): self.insertOldSeeds(*seeds) return # // # // Use seed service utility to generate seeds on the fly #// svc = self.data.services["RandomNumberGeneratorService"] try: from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper except ImportError: msg = "Unable to import RandomeNumberServiceHelper" print msg raise RuntimeError, msg randHelper = RandomNumberServiceHelper(svc) randHelper.populate() svc.saveFileName = CfgTypes.untracked( CfgTypes.string("RandomEngineState.log")) return
def setPileupFilesForModule(self, sourceName, targetModule, *fileList): """ _setPileupFilesForSource Insert the files provided into all target modules for the secsource named sourceName """ for mixMod in self.findMixingModulesByType(targetModule): print "Processing %s: %s " % (targetModule, mixMod) secSource = getattr(mixMod, sourceName, None) if secSource == None: msg = "==============WARNING================\n" msg += "No Input PoolRASource found for mixing module:\n" msg += mixMod.dumpConfig() msg += "\n With secsource named %s\n" % sourceName msg += " Cannot add Pileup Files...\n" msg += "======================================\n" print msg continue oldfileList = getattr(secSource, "fileNames", None) if oldfileList == None: print "No existing file list in secsource %s" % sourceName continue setattr(secSource, 'fileNames', CfgTypes.untracked( CfgTypes.vstring())) for fileName in fileList: secSource.fileNames.append(str(fileName)) print "Adding %s PileupFile: %s " % (sourceName, str(fileName)) return
def insertPileupFiles(self, *fileList): """ _insertPileupFiles_ Insert the files provided into all mixing modules """ for mixMod in self.mixingModules(): print "Processing MixingModule: %s " % mixMod secSource = getattr(mixMod, "input", None) if secSource == None: secSource = getattr(mixMod, "secsource", None) if secSource == None: msg = "==============WARNING================\n" msg += "No Input PoolRASource found for mixing module:\n" msg += mixMod.dumpConfig() msg += "\nCannot add Pileup Files...\n" msg += "======================================\n" print msg continue oldfileList = getattr(secSource, "fileNames", None) if oldfileList == None: print "No existing file list" continue setattr(secSource, 'fileNames', CfgTypes.untracked( CfgTypes.vstring())) for fileName in fileList: secSource.fileNames.append(str(fileName)) print "PileupFile: %s " % str(fileName) return
def setFirstEvent(self, firstEv): """ set first event number """ self.data.firstEvent = CfgTypes.untracked( CfgTypes.uint32(int(firstEv)))
def mergeProcess(*inputFiles, **options): """ _mergeProcess_ Creates and returns a merge process that will merge the provided filenames supported options: - process_name : name of the process, defaults to Merge - outputmod_label : label of the output module, defaults to Merged - newDQMIO : specifies if the new DQM format should be used to merge the files - output_file : sets the output file name - output_lfn : sets the output LFN """ # // # // process supported options # // processName = options.get("process_name", "Merge") outputModLabel = options.get("outputmod_label", "Merged") outputFilename = options.get("output_file", "Merged.root") outputLFN = options.get("output_lfn", None) dropDQM = options.get("drop_dqm", False) newDQMIO = options.get("newDQMIO", False) # // # // build process # // process = Process(processName) # // # // input source # // if newDQMIO: process.source = Source("DQMRootSource") process.add_(Service("DQMStore")) else: process.source = Source("PoolSource") if dropDQM: process.source.inputCommands = CfgTypes.untracked.vstring("keep *", "drop *_EDMtoMEConverter_*_*") process.source.fileNames = CfgTypes.untracked(CfgTypes.vstring()) for entry in inputFiles: process.source.fileNames.append(str(entry)) # // # // output module # // if newDQMIO: outMod = OutputModule("DQMRootOutputModule") else: outMod = OutputModule("PoolOutputModule") outMod.fileName = CfgTypes.untracked.string(outputFilename) if outputLFN != None: outMod.logicalFileName = CfgTypes.untracked.string(outputLFN) setattr(process, outputModLabel, outMod) process.outputPath = EndPath(outMod) return process
def addLumifilter(process, fname=''): if (len(fname) > 0): myLumis = LumiList.LumiList(filename=fname).getCMSSWString().split(',') process.source.lumisToProcess = CfgTypes.untracked( CfgTypes.VLuminosityBlockRange()) process.source.lumisToProcess.extend(myLumis) print 'Lumi sections will be filtered with: ' + fname
def setLogicalFileName(self, lfn): """ _setLogicalFileName_ """ self.data.logicalFileName = CfgTypes.untracked(CfgTypes.string(lfn)) return
def setPileupFilesForModule(self, sourceName, targetModule, *fileList): """ _setPileupFilesForSource Insert the files provided into all target modules for the secsource named sourceName """ for mixMod in self.findMixingModulesByType(targetModule): print "Processing %s: %s " % (targetModule, mixMod) secSource = getattr(mixMod, sourceName, None) if secSource == None: msg = "==============WARNING================\n" msg += "No Input PoolRASource found for mixing module:\n" msg += mixMod.dumpConfig() msg += "\n With secsource named %s\n" % sourceName msg += " Cannot add Pileup Files...\n" msg += "======================================\n" print msg continue oldfileList = getattr(secSource, "fileNames", None) if oldfileList == None: print "No existing file list in secsource %s" % sourceName continue setattr(secSource, 'fileNames', CfgTypes.untracked(CfgTypes.vstring())) for fileName in fileList: secSource.fileNames.append(str(fileName)) print "Adding %s PileupFile: %s " % (sourceName, str(fileName)) return
def createMergePSet(self): """ _createMergePSet_ Merges are a little different since we have to build the entire process object from scratch. """ print "<<<<<<<<<<<<<<<<<<<<Merge>>>>>>>>>>>>>>>>>>>>>." cfgFile = self.config['Configuration'].get("CfgFile", "PSet.py")[0] cfgFile = str(cfgFile) self.jobSpecNode.loadConfiguration() cfgInt = self.jobSpecNode.cfgInterface from FWCore.ParameterSet.Config import Process, EndPath from FWCore.ParameterSet.Modules import OutputModule, Source import FWCore.ParameterSet.Types as CfgTypes process = Process("Merge") process.source = Source("PoolSource") process.source.fileNames = CfgTypes.untracked(CfgTypes.vstring()) for entry in cfgInt.inputFiles: process.source.fileNames.append(str(entry)) outMod = cfgInt.outputModules['Merged'] process.Merged = OutputModule("PoolOutputModule") process.Merged.fileName = CfgTypes.untracked(CfgTypes.string( outMod['fileName'])) process.Merged.logicalFileName = CfgTypes.untracked(CfgTypes.string( outMod['logicalFileName'])) process.Merged.catalog = CfgTypes.untracked(CfgTypes.string( outMod['catalog'])) process.outputPath = EndPath(process.Merged) cfgDump = open("CfgFileDump.log", 'w') cfgDump.write(process.dumpConfig()) cfgDump.close() handle = open(cfgFile, 'w') handle.write("import pickle\n") handle.write("pickledCfg=\"\"\"%s\"\"\"\n" % pickle.dumps(process)) handle.write("process = pickle.loads(pickledCfg)\n") handle.close() return
def setLumisToProcess(self, *lumiList): """set lumisToProcess vector""" self.data.lumisToProcess = CfgTypes.untracked( CfgTypes.VLuminosityBlockRange()) for entry in lumiList: self.data.lumisToProcess.append(entry) return
def setFileNames(self, *fileNames): """set fileNames vector""" if fileNames: self.data.fileNames = CfgTypes.untracked(CfgTypes.vstring()) for entry in fileNames: self.data.fileNames.append(entry) return
def setMaxEventsInput(self, maxEv): """ _setMaxEventsInput_ Set the input maxEvents limit for the source """ self.data.input = CfgTypes.untracked(CfgTypes.int32(maxEv)) return
def setMaxEventsInput(self, maxEv): """ _setMaxEventsInput_ Set the input maxEvents limit for the source """ self.data.input = CfgTypes.untracked(CfgTypes.int32(maxEv)) return
def setCatalog(self, newCatalog): """ _setCatalog_ Set the catalog name """ self.data.catalog = CfgTypes.untracked(CfgTypes.string(newCatalog)) return
def setCatalog(self, newCatalog): """ _setCatalog_ Set the catalog name """ self.data.catalog = CfgTypes.untracked(CfgTypes.string(newCatalog)) return
def applyJSON( process, json ): # import PhysicsTools.PythonAnalysis.LumiList as LumiList # import FWCore.ParameterSet.Types as CfgTypes # myLumis = LumiList.LumiList(filename = json ).getCMSSWString().split(',') myLumis = lumiList( json ) import FWCore.ParameterSet.Types as CfgTypes process.source.lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange()) process.source.lumisToProcess.extend(myLumis)
def addDataset(self, **datasetParams): """ _addDataset_ Add Dataset information to this cfg file. Each key, value pair provided in dataset Params is added as an untracked string to the datasets PSet in a PSet named entryName """ datasetPSet = getattr(self.data, "dataset", None) if datasetPSet == None: self.data.dataset = CfgTypes.untracked(CfgTypes.PSet()) datasetPSet = self.data.dataset for key, value in datasetParams.items(): setattr(datasetPSet, key, CfgTypes.untracked(CfgTypes.string(str(value)))) return
def setMaxEventsOutput(self, maxEv, moduleName=None): """ _setMaxEventsOutput_ """ value = CfgTypes.untracked(CfgTypes.int32(maxEv)) if moduleName == None: self.data.output = value return cfgType = getattr(self.data, "output", None) if cfgType.__class__.__name__ == "VPSet": # is a VPset so we append to that self.data.output.append( CfgTypes.untracked(CfgTypes.PSet(moduleName=value))) else: # add new VPset self.data.output = CfgTypes.untracked( CfgTypes.VPSet( CfgTypes.untracked(CfgTypes.PSet(moduleName=value)))) return
def applyJSON(process, json): # import PhysicsTools.PythonAnalysis.LumiList as LumiList # import FWCore.ParameterSet.Types as CfgTypes # myLumis = LumiList.LumiList(filename = json ).getCMSSWString().split(',') myLumis = lumiList(json) import FWCore.ParameterSet.Types as CfgTypes process.source.lumisToProcess = CfgTypes.untracked( CfgTypes.VLuminosityBlockRange()) process.source.lumisToProcess.extend(myLumis)
def setNamedSeed(self, psetName, *seeds): """ _setNamedSeed_ If a specific set of seeds is needed for a PSet in this service, they can be set by name using this method. - *psetName* : Name of the pset containing the seeds - *seeds* : list of seeds to be added, should be a single seed for initialSeed values. """ pset = getattr(self._randService, psetName, None) if pset == None: msg = "No PSet named %s belongs to this instance of the" % ( psetName,) msg += "Random Seed Service" raise RuntimeError, msg seedVal = getattr(pset, "initialSeed", None) if seedVal != None: pset.initialSeed = CfgTypes.untracked( CfgTypes.uint32(seeds[0]) ) return seedSet = getattr(pset, "initialSeedSet", None) if seedSet != None: # // # // Do we want to check the number of seeds?? #// #if len(seeds) != len( seedSet.value()): pass pset.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(*seeds)) return # // # // No seeds for that PSet #// Error throw? return
def setNamedSeed(self, psetName, *seeds): """ _setNamedSeed_ If a specific set of seeds is needed for a PSet in this service, they can be set by name using this method. - *psetName* : Name of the pset containing the seeds - *seeds* : list of seeds to be added, should be a single seed for initialSeed values. """ pset = getattr(self._randService, psetName, None) if pset == None: msg = "No PSet named %s belongs to this instance of the" % ( psetName,) msg += "Random Seed Service" raise RuntimeError, msg seedVal = getattr(pset, "initialSeed", None) if seedVal != None: pset.initialSeed = CfgTypes.untracked( CfgTypes.uint32(seeds[0]) ) return seedSet = getattr(pset, "initialSeedSet", None) if seedSet != None: # // # // Do we want to check the number of seeds?? #// #if len(seeds) != len( seedSet.value()): pass pset.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(*seeds)) return # // # // No seeds for that PSet #// Error throw? return
def __init__(self, cfgInstance): self.data = cfgInstance if not self.data.source: msg = "The config file has no Source" raise RuntimeError, msg self.inputSource = InputSource(self.data.source) self.outputModules = {} for omodName in self.data.outputModules: self.outputModules[omodName] = OutputModule( omodName, getattr(self.data, omodName)) if not self.data.psets.has_key('maxEvents'): self.data.maxEvents = CfgTypes.untracked(CfgTypes.PSet()) self.maxEvents = MaxEvents(self.data.maxEvents)
def addDataset(self, **datasetParams): """ _addDataset_ Add Dataset information to this cfg file. Each key, value pair provided in dataset Params is added as an untracked string to the datasets PSet in a PSet named entryName """ datasetPSet = getattr(self.data, "dataset", None) if datasetPSet == None: self.data.dataset = CfgTypes.untracked(CfgTypes.PSet()) datasetPSet = self.data.dataset for key, value in datasetParams.items(): setattr( datasetPSet, key, CfgTypes.untracked(CfgTypes.string(str(value))) ) return
def makeTriggerEntry(process, triggerPath, selectionEff): """ _makeTriggerEntry_ Add a single trigger entry to the configuration. This adds: - Random seed - """ modName = "mod%s" % triggerPath svc = process.services["RandomNumberGeneratorService"] setattr(svc.moduleSeeds, modName, CmsTypes.untracked( CmsTypes.uint32( seed() ))) filterMod = EDFilter("RandomFilter") filterMod.acceptRate = CmsTypes.untracked(CmsTypes.double(selectionEff)) setattr(process, modName, filterMod) setattr(process, triggerPath, Path(filterMod)) return
def __init__(self, cfgInstance): self.data = cfgInstance if not self.data.source: msg = "The config file has no Source" raise RuntimeError, msg self.inputSource = InputSource(self.data.source) self.outputModules = {} for omodName in self.data.outputModules: self.outputModules[omodName] = OutputModule( omodName, getattr(self.data, omodName)) if not self.data.psets.has_key('maxEvents'): self.data.maxEvents = CfgTypes.untracked( CfgTypes.PSet() ) self.maxEvents = MaxEvents(self.data.maxEvents)
def setMaxEventsOutput(self, maxEv, moduleName = None): """ _setMaxEventsOutput_ """ value = CfgTypes.untracked(CfgTypes.int32(maxEv)) if moduleName == None: self.data.output = value return cfgType = getattr(self.data, "output", None) if cfgType.__class__.__name__ == "VPSet": # is a VPset so we append to that self.data.output.append( CfgTypes.untracked( CfgTypes.PSet( moduleName = value) ) ) else: # add new VPset self.data.output = CfgTypes.untracked( CfgTypes.VPSet( CfgTypes.untracked(CfgTypes.PSet( moduleName = value)) ) ) return
def ioCustomization(self, config, custom_config, merge = False): """ Apply site specific io customizations """ # Don't do anything if no customization or job has no input files if not custom_config or (merge is False and not config.inputFiles): return import re version = lambda x: tuple(int(x) for x in re.compile('(\d+)').findall(x)) cmssw_version = version(os.environ['CMSSW_VERSION']) # Only implemented in CMSSW_2_1_8 and above if cmssw_version < (2, 1, 8): return print "Site specific IO parameters will be used:" # cacheSize is a property of InputSource cache_size = custom_config.get('cacheSize', None) if cache_size: # Merge pset creates process on fly so can't use CMSSWConfig object if merge: from ProdCommon.CMSConfigTools.ConfigAPI.InputSource import InputSource inputSource = InputSource(config.source) inputSource.setCacheSize(cache_size) else: config.sourceParams['cacheSize'] = cache_size if merge: from FWCore.ParameterSet.Modules import Service config.add_(Service('AdaptorConfig')) for param in custom_config: print " %s %s" % (param, custom_config[param]) if param == 'cacheSize': continue if merge: import FWCore.ParameterSet.Types as CfgTypes adaptor = config.services['AdaptorConfig'] setattr(adaptor, param, CfgTypes.untracked(CfgTypes.string(str(custom_config[param])))) else: config.tFileAdaptorConfig[param] = custom_config[param] return
def createPSet(self): """ _createPSet_ Create the PSet cfg File """ cfgFile = self.config['Configuration'].get("CfgFile", "PSet.py")[0] cfgFile = str(cfgFile) self.jobSpecNode.loadConfiguration() self.jobSpecNode.cfgInterface.rawCfg = self.workflowNode.cfgInterface.rawCfg # taken from cmssw environment # pylint: disable-msg=F0401 import FWCore.ParameterSet.Types as CfgTypes # pylint: enable-msg=F0401 workingDir = os.path.join(os.getcwd(), 'prestage') if os.path.exists(workingDir + '/prestageTFC.xml'): rawCfg = pickle.loads(self.jobSpecNode.cfgInterface.rawCfg) rawCfg.source.overrideCatalog = CfgTypes.untracked(CfgTypes.string('trivialcatalog_file:%s/prestageTFC.xml?protocol=local-stage-in' % workingDir)) self.jobSpecNode.cfgInterface.rawCfg = pickle.dumps(rawCfg) # Apply site specific customizations self.localCustomization(self.jobSpecNode.cfgInterface) for inpLink in self.jobSpecNode._InputLinks: # // # // We have in-job input links to be resolved #// self.handleInputLink(self.jobSpecNode.cfgInterface, inpLink) cmsProcess = self.jobSpecNode.cfgInterface.makeConfiguration() pycfgDump = open("PyCfgFileDump.log", 'w') try: pycfgDump.write(cmsProcess.dumpPython()) except Exception, ex: msg = "Error writing python format cfg dump:\n" msg += "%s\n" % str(ex) msg += "This needs to be reported to the framework team" pycfgDump.write(msg)
def setTFileAdaptorConfig(self, config): """ Give the TFileAdaptor the provided config options """ adaptor = self.data.services.get('AdaptorConfig') if adaptor is None: self.data.add_(CfgModules.Service('AdaptorConfig')) for option in config: value = str(config[option]) # so far only support boolean & string options if option in ('enable', 'stats'): thisType = CfgTypes.bool._valueFromString else: thisType = CfgTypes.string setattr(self.data.services['AdaptorConfig'], option, CfgTypes.untracked(thisType(value)))
def setTFileAdaptorConfig(self, config): """ Give the TFileAdaptor the provided config options """ adaptor = self.data.services.get('AdaptorConfig') if adaptor is None: self.data.add_(CfgModules.Service('AdaptorConfig')) for option in config: value = str(config[option]) # so far only support boolean & string options if option in ('enable', 'stats'): thisType = CfgTypes.bool._valueFromString else: thisType = CfgTypes.string setattr(self.data.services['AdaptorConfig'], option, CfgTypes.untracked(thisType(value)))
def buildPoolSourceLumiMask(self): # From https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideGoodLumiSectionsJSONFile#cmsRun jsonFile = self.lumiMask if not os.path.exists(jsonFile): raise IOError("Lumi mask file %s does not exist!" % jsonFile) lumiList = LumiList.LumiList(filename = jsonFile) runs = lumiList.getRuns() bad_runs = [] for run in runs: is_good = True if int(run) < self.firstRun: is_good = False if self.lastRun > -1 and int(run) > self.lastRun: is_good = False if not is_good: bad_runs.append(run) lumiList.removeRuns(bad_runs) lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange()) lumisToProcess.extend(lumiList.getCMSSWString().split(',')) return lumisToProcess
def buildPoolSourceLumiMask(self): # From https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideGoodLumiSectionsJSONFile#cmsRun jsonFile = self.lumiMask if not os.path.exists(jsonFile): raise IOError("Lumi mask file %s does not exist!" % jsonFile) lumiList = LumiList.LumiList(filename=jsonFile) runs = lumiList.getRuns() bad_runs = [] for run in runs: is_good = True if int(run) < self.firstRun: is_good = False if self.lastRun > -1 and int(run) > self.lastRun: is_good = False if not is_good: bad_runs.append(run) lumiList.removeRuns(bad_runs) lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange()) lumisToProcess.extend(lumiList.getCMSSWString().split(',')) return lumisToProcess
def addOutputModule(process, fileName): """ _addOutputModule_ """ outMod = OutputModule("EventStreamFileWriter") outMod.max_event_size = CmsTypes.untracked(CmsTypes.int32(7000000)) outMod.max_queue_depth = CmsTypes.untracked(CmsTypes.int32(5)) outMod.use_compression = CmsTypes.untracked(CmsTypes.bool(True)) outMod.compression_level = CmsTypes.untracked(CmsTypes.int32(1)) streamer = "%s.dat" % fileName indexFile = "%s.ind" % fileName outMod.fileName = CmsTypes.untracked(CmsTypes.string(streamer)) outMod.indexFileName = CmsTypes.untracked(CmsTypes.string(indexFile)) process.out = outMod process.o = EndPath(process.out) return
muon_collection = cms.InputTag('selectedPatMuonsPFlow'), electron_collection = cms.InputTag('selectedPatElectronsPFlow'), met_collection = cms.InputTag('patMETsPFlow'), type1corrmet_collection = cms.InputTag('pfType1CorrectedMet'), ) ####################################################### # # Input files # process.inputs = cms.PSet ( nEvents = cms.int32(50000), skipEvents = cms.int32(0), lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange()), fileNames = cms.vstring( 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_1_1_v0T.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_2_1_y3T.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_5_1_Qpb.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_101_1_2ah.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_100_1_JvB.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_103_1_bvI.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_102_1_uUQ.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_105_1_xR2.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_104_1_vMs.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_107_1_FgZ.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_106_1_qF5.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_109_1_cca.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_108_1_WVS.root', 'dcap:///pnfs/cms/WAX/11/store/user/lpctlbsm/meloam/TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/Summer12_DR53X-PU_S10_START53_V7A-v1_TLBSM_53x_v2/c04f3b4fa74c8266c913b71e0c74901d/tlbsm_53x_v2_mc_110_1_yh2.root',
def setNumberEventsInRun(self, numEvents): """ set numberEventsInRun parameter """ self.data.numberEventsInRun = CfgTypes.untracked( CfgTypes.uint32(numEvents))
#process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff') from Configuration.AlCa.GlobalTag import GlobalTag if config["RUNONMC"]: process.GlobalTag = GlobalTag(process.GlobalTag, '80X_mcRun2_asymptotic_2016_miniAODv2') # process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc') elif not(config["RUNONMC"]): process.GlobalTag = GlobalTag(process.GlobalTag, '80X_dataRun2_Prompt_v8') ######### read JSON file for data ########## if not(config["RUNONMC"]) and config["USEJSON"]: import FWCore.PythonUtilities.LumiList as LumiList import FWCore.ParameterSet.Types as CfgTypes process.source.lumisToProcess = CfgTypes.untracked(CfgTypes.VLuminosityBlockRange()) myLumis = LumiList.LumiList(filename = config["JSONFILE"]).getCMSSWString().split(',') process.source.lumisToProcess.extend(myLumis) ####### Redo Jet clustering sequence ########## betapar = cms.double(0.0) fatjet_ptmin = 100.0 from RecoJets.Configuration.RecoPFJets_cff import * from RecoJets.JetProducers.AnomalousCellParameters_cfi import * from RecoJets.JetProducers.PFJetParameters_cfi import * process.chs = cms.EDFilter("CandPtrSelector", src = cms.InputTag('packedPFCandidates'), cut = cms.string('fromPV') )
def main(argv) : """ writeCfg - Read in existing, user supplied pycfg or pickled pycfg file - Modify job specific parameters based on environment variables and arguments.xml - Write out pickled pycfg file required parameters: none optional parameters: --help : help --debug : debug statements """ # defaults inputFileNames = None parentFileNames = None debug = False _MAXINT = 900000000 try: opts, args = getopt.getopt(argv, "", ["debug", "help"]) except getopt.GetoptError: print main.__doc__ sys.exit(2) try: CMSSW = os.environ['CMSSW_VERSION'] parts = CMSSW.split('_') CMSSW_major = int(parts[1]) CMSSW_minor = int(parts[2]) except (KeyError, ValueError): msg = "Your environment doesn't specify the CMSSW version or specifies it incorrectly" raise ConfigException(msg) # Parse command line options for opt, arg in opts : if opt == "--help" : print main.__doc__ sys.exit() elif opt == "--debug" : debug = True # Parse remaining parameters try: fileName = args[0] outFileName = args[1] except IndexError: print main.__doc__ sys.exit() # Read in Environment, XML and get optional Parameters nJob = int(os.environ.get('NJob', '0')) preserveSeeds = os.environ.get('PreserveSeeds','') incrementSeeds = os.environ.get('IncrementSeeds','') # Defaults maxEvents = 0 skipEvents = 0 firstEvent = -1 compHEPFirstEvent = 0 firstRun = 0 # FUTURE: Remove firstRun firstLumi = 0 dom = xml.dom.minidom.parse(os.environ['RUNTIME_AREA']+'/arguments.xml') for elem in dom.getElementsByTagName("Job"): if nJob == int(elem.getAttribute("JobID")): if elem.getAttribute("MaxEvents"): maxEvents = int(elem.getAttribute("MaxEvents")) if elem.getAttribute("SkipEvents"): skipEvents = int(elem.getAttribute("SkipEvents")) if elem.getAttribute("FirstEvent"): firstEvent = int(elem.getAttribute("FirstEvent")) if elem.getAttribute("FirstRun"): firstRun = int(elem.getAttribute("FirstRun")) if elem.getAttribute("FirstLumi"): firstLumi = int(elem.getAttribute("FirstLumi")) generator = str(elem.getAttribute('Generator')) inputBlocks = str(elem.getAttribute('InputBlocks')) inputFiles = str(elem.getAttribute('InputFiles')) parentFiles = str(elem.getAttribute('ParentFiles')) lumis = str(elem.getAttribute('Lumis')) report(inputBlocks,inputFiles,parentFiles,lumis) # Read Input python config file handle = open(fileName, 'r') try: # Nested form for Python < 2.5 try: print "Importing .py file" cfo = imp.load_source("pycfg", fileName, handle) cmsProcess = cfo.process except Exception, ex: msg = "Your pycfg file is not valid python: %s" % str(ex) raise ConfigException(msg) finally: handle.close() cfg = CfgInterface(cmsProcess) # Set parameters for job print "Setting parameters" inModule = cfg.inputSource if maxEvents: cfg.maxEvents.setMaxEventsInput(maxEvents) if skipEvents and inModule.sourceType not in ['EmptySource']: inModule.setSkipEvents(skipEvents) # Set "skip events" for various generators if generator == 'comphep': cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent) elif generator == 'lhe': cmsProcess.source.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent+1)) elif firstEvent != -1: # (Old? Madgraph) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) if inputFiles: inputFileNames = inputFiles.split(',') inModule.setFileNames(*inputFileNames) # handle parent files if needed if parentFiles: parentFileNames = parentFiles.split(',') inModule.setSecondaryFileNames(*parentFileNames) if lumis: if CMSSW_major < 3: # FUTURE: Can remove this check print "Cannot skip lumis for CMSSW 2_x" else: lumiRanges = lumis.split(',') inModule.setLumisToProcess(*lumiRanges) # Pythia parameters if (firstRun): inModule.setFirstRun(firstRun) if (firstLumi): inModule.setFirstLumi(firstLumi) # Check if there are random #'s to deal with if cfg.data.services.has_key('RandomNumberGeneratorService'): print "RandomNumberGeneratorService found, will attempt to change seeds" from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper ranGenerator = cfg.data.services['RandomNumberGeneratorService'] ranModules = getattr(ranGenerator, "moduleSeeds", None) oldSource = getattr(ranGenerator, "sourceSeed", None) if ranModules != None or oldSource != None: msg = "Your random number seeds are set in an old,\n" msg += "deprecated style. Please change to new style:\n" msg += "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideEDMRandomNumberGeneratorService" raise ConfigException(msg) randSvc = RandomNumberServiceHelper(ranGenerator) incrementSeedList = [] preserveSeedList = [] if incrementSeeds: incrementSeedList = incrementSeeds.split(',') if preserveSeeds: preserveSeedList = preserveSeeds.split(',') # Increment requested seed sets for seedName in incrementSeedList: curSeeds = randSvc.getNamedSeed(seedName) newSeeds = [x+nJob for x in curSeeds] randSvc.setNamedSeed(seedName, *newSeeds) preserveSeedList.append(seedName) # Randomize remaining seeds randSvc.populate(*preserveSeedList) # Write out new config file pklFileName = outFileName + '.pkl' outFile = open(outFileName,"w") outFile.write("import FWCore.ParameterSet.Config as cms\n") outFile.write("import pickle\n") outFile.write("process = pickle.load(open('%s', 'rb'))\n" % pklFileName) outFile.close() pklFile = open(pklFileName,"wb") myPickle = pickle.Pickler(pklFile) myPickle.dump(cmsProcess) pklFile.close() if (debug): print "writeCfg output (May not be exact):" print "import FWCore.ParameterSet.Config as cms" print cmsProcess.dumpPython()
""" newSeeds = [ value for i in range(self.countSeeds())] self.insertSeeds(*newSeeds) return if __name__ == '__main__': # // # // Setup a test service and populate it #// randSvc = Service("RandomNumberGeneratorService") randHelper = RandomNumberServiceHelper(randSvc) randSvc.i1 = CfgTypes.untracked(CfgTypes.uint32(1)) randSvc.t1 = CfgTypes.PSet() randSvc.t2 = CfgTypes.PSet() randSvc.t3 = CfgTypes.PSet() randSvc.t1.initialSeed = CfgTypes.untracked( CfgTypes.uint32(123455678) ) randSvc.t2.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(12345,234567,345677) ) randSvc.t3.initialSeed = CfgTypes.untracked( CfgTypes.uint32(987654321)
def setFirstLumi(self, lumiId): """ set lumi id for this job """ self.data.firstLuminosityBlock = CfgTypes.untracked( CfgTypes.uint32(int(lumiId)))
def customise(process): # Define configuration parameter default values from TauAnalysis.MCEmbeddingTools.setDefaults import setDefaults setDefaults(process) inputProcess = process.customization_options.inputProcessRECO.value() print "Input process set to '%s'" % inputProcess process._Process__name = "EmbeddedRECO" # DQM store output for muon acceptance histograms process.DQMStore = cms.Service("DQMStore") if process.customization_options.isMC.value(): print "Input is MC" # select generator level muons process.genMuonsFromZs = cms.EDProducer( "GenParticlesFromZsSelectorForMCEmbedding", src=cms.InputTag( "genParticles", "", process.customization_options.inputProcessSIM.value()), pdgIdsMothers=cms.vint32(23, 22), pdgIdsDaughters=cms.vint32(13), maxDaughters=cms.int32(2), minDaughters=cms.int32(2), before_or_afterFSR=cms.string("afterFSR"), verbosity=cms.int32(0)) process.ProductionFilterSequence.replace( process.cleanedGeneralTracks, process.genMuonsFromZs * process.cleanedGeneralTracks) process.ProductionFilterSequence.replace( process.cleanedParticleFlow, process.genMuonsFromZs * process.cleanedParticleFlow) # produce generator level MET (= sum of neutrino momenta) # in case Embedding is run on Monte Carlo input process.genMetCalo = cms.EDProducer( "MixedGenMEtProducer", srcGenParticles1=cms.InputTag( "genParticles", "", process.customization_options.inputProcessSIM.value()), srcGenParticles2=cms.InputTag("genParticles"), srcRemovedMuons=cms.InputTag(process.customization_options. ZmumuCollection.getModuleLabel()), type=cms.string("calo"), isMC=cms.bool(True)) process.genMetTrue = process.genMetCalo.clone(type=cms.string("pf")) else: print "Input is Data" # produce generator level MET (= sum of neutrino momenta) # in case Embedding is run on real Data process.genMetCalo = cms.EDProducer( "MixedGenMEtProducer", srcGenParticles1=cms.InputTag(""), srcGenParticles2=cms.InputTag("genParticles"), srcRemovedMuons=cms.InputTag(process.customization_options. ZmumuCollection.getModuleLabel()), type=cms.string("calo"), isMC=cms.bool(False)) process.genMetTrue = process.genMetCalo.clone(type=cms.string("pf")) for p in process.paths: pth = getattr(process, p) if "genParticles" in pth.moduleNames(): pth.replace( process.genParticles, process.genParticles * process.genMetCalo * process.genMetTrue) # update InputTags defined in PFEmbeddingSource_cff.py print "Setting collection of Z->mumu candidates to '%s'" % process.customization_options.ZmumuCollection.getModuleLabel( ) if not (hasattr(process, "cleanedGeneralTracks") and hasattr(process, "cleanedParticleFlow")): process.load("TauAnalysis.MCEmbeddingTools.PFEmbeddingSource_cff") if process.customization_options.replaceGenOrRecMuonMomenta.value( ) == 'gen': print "Taking momenta of generated tau leptons from generator level muons" process.generator.src = cms.InputTag('genMuonsFromZs') elif process.customization_options.replaceGenOrRecMuonMomenta.value( ) == 'rec': print "Taking momenta of generated tau leptons from reconstructed muons" process.generator.src = process.customization_options.ZmumuCollection else: raise ValueError( "Invalid Configuration parameter 'replaceGenOrRecMuonMomenta' = %s !!" % process.customization_options.replaceGenOrRecMuonMomenta.value()) # update option for removing tracks/charged PFCandidates matched to reconstructed muon process.cleanedGeneralTracks.selectedMuons = process.customization_options.ZmumuCollection process.cleanedParticleFlow.selectedMuons = process.customization_options.ZmumuCollection if process.customization_options.muonTrackCleaningMode.value() == 1: process.cleanedGeneralTracks.removeDuplicates = cms.bool(False) process.cleanedParticleFlow.removeDuplicates = cms.bool(False) elif process.customization_options.muonTrackCleaningMode.value() == 2: process.cleanedGeneralTracks.removeDuplicates = cms.bool(True) process.cleanedParticleFlow.removeDuplicates = cms.bool(True) else: raise ValueError( "Invalid Configuration parameter 'muonTrackCleaningMode' = %i !!" % process.customization_options.muonTrackCleaningMode.value()) try: outputModule = process.output except: pass try: outputModule = getattr( process, str(getattr(process, list(process.endpaths)[-1]))) except: pass print "Changing event-content to AODSIM + Z->mumu candidates" outputModule.outputCommands = cms.untracked.vstring("drop *") outputModule.outputCommands.extend( process.AODSIMEventContent.outputCommands) # get rid of second "drop *" index = 0 for item in outputModule.outputCommands[:]: if item == "drop *" and index != 0: del outputModule.outputCommands[index] index -= 1 index += 1 # keep collections of generator level muons outputModule.outputCommands.extend(['keep *_genMuonsFromZs_*_*']) # keep collections of reconstructed muons outputModule.outputCommands.extend([ 'keep *_goodMuons_*_*', 'keep *_goodMuonsPFIso_*_*', 'keep *_highestPtMuPlus_*_*', 'keep *_highestPtMuMinus_*_*', 'keep *_highestPtMuPlusPFIso_*_*', 'keep *_highestPtMuMinusPFIso_*_*' ]) # keep collections of reconstructed Z -> mumu candidates # (with different muon isolation criteria applied) outputModule.outputCommands.extend([ 'keep *_goldenZmumuCandidatesGe0IsoMuons_*_*', 'keep *_goldenZmumuCandidatesGe1IsoMuons_*_*', 'keep *_goldenZmumuCandidatesGe2IsoMuons_*_*', 'keep TH2DMEtoEDM_MEtoEDMConverter_*_*' ]) # keep flag indicating whether event passes or fails # o Z -> mumu event selection # o muon -> muon + photon radiation filter outputModule.outputCommands.extend([ 'keep *_goldenZmumuFilterResult_*_*', 'keep *_muonRadiationFilterResult_*_*' ]) # CV: keep HepMCProduct for embedded event, # in order to run Validation/EventGenerator/python/TauValidation_cfi.py # for control plots of tau polarization and decay mode information outputModule.outputCommands.extend(['keep *HepMCProduct_generator_*_*']) # keep distance of muons traversed in ECAL and HCAL, # expected and removed muon energy deposits outputModule.outputCommands.extend([ 'keep *_muonCaloEnergyDepositsByDistance_totalDistanceMuPlus_*', 'keep *_muonCaloEnergyDepositsByDistance_totalEnergyDepositMuPlus_*', 'keep *_muonCaloEnergyDepositsByDistance_totalDistanceMuMinus_*', 'keep *_muonCaloEnergyDepositsByDistance_totalEnergyDepositMuMinus_*', 'keep *_castorreco_removedEnergyMuMinus*_*', 'keep *_castorreco_removedEnergyMuPlus*_*', 'keep *_hfreco_removedEnergyMuMinus*_*', 'keep *_hfreco_removedEnergyMuPlus*_*', 'keep *_ecalPreshowerRecHit_removedEnergyMuMinus*_*', 'keep *_ecalPreshowerRecHit_removedEnergyMuPlus*_*', 'keep *_ecalRecHit_removedEnergyMuMinus*_*', 'keep *_ecalRecHit_removedEnergyMuPlus*_*', 'keep *_hbhereco_removedEnergyMuMinus*_*', 'keep *_hbhereco_removedEnergyMuPlus*_*', 'keep *_horeco_removedEnergyMuMinus*_*', 'keep *_horeco_removedEnergyMuPlus*_*', ]) # replace HLT process name # (needed for certain reprocessed Monte Carlo samples) hltProcessName = "HLT" try: hltProcessName = __HLT__ except: pass try: process.dimuonsHLTFilter.TriggerResultsTag.processName = hltProcessName process.goodZToMuMuAtLeast1HLT.TrigTag.processName = hltProcessName process.goodZToMuMuAtLeast1HLT.triggerEvent.processName = hltProcessName process.hltTrigReport, HLTriggerResults.processName = hltProcessName except: pass # disable L1GtTrigReport module # (not used for anything yet, just prints error for every single event) if hasattr(process, 'HLTAnalyzerEndpath'): process.HLTAnalyzerEndpath.remove(process.hltL1GtTrigReport) # apply configuration parameters print "Setting mdtau to %i" % process.customization_options.mdtau.value() process.generator.Ztautau.TauolaOptions.InputCards.mdtau = process.customization_options.mdtau if hasattr(process.generator, "ParticleGun"): process.generator.ParticleGun.ExternalDecays.Tauola.InputCards.mdtau = process.customization_options.mdtau if process.customization_options.useTauolaPolarization.value(): print "Enabling tau polarization effects in TAUOLA" # NOTE: polarization effects are only approximate, # because Embedded events do not have proper parton history in HepMC::GenEvent # (cf. arXiv:hep-ph/0101311 and arXiv:1201.0117) process.generator.Ztautau.TauolaOptions.UseTauolaPolarization = cms.bool( True) else: print "Disabling tau polarization effects in TAUOLA" # NOTE: tau polarization effects need to be added by reweighting Embedded events # using weights computed by TauSpinner package process.generator.Ztautau.TauolaOptions.UseTauolaPolarization = cms.bool( False) print "Setting minVisibleTransverseMomentum to '%s'" % process.customization_options.minVisibleTransverseMomentum.value( ) process.generator.Ztautau.minVisibleTransverseMomentum = process.customization_options.minVisibleTransverseMomentum print "Setting transformationMode to %i" % process.customization_options.transformationMode.value( ) process.generator.Ztautau.transformationMode = process.customization_options.transformationMode print "Setting rfRotationAngle to %1.0f" % process.customization_options.rfRotationAngle.value( ) process.generator.Ztautau.rfRotationAngle = process.customization_options.rfRotationAngle if process.customization_options.overrideBeamSpot.value(): bs = cms.string("BeamSpotObjects_2009_LumiBased_SigmaZ_v28_offline") process.GlobalTag.toGet = cms.VPSet( cms.PSet(record=cms.string("BeamSpotObjectsRcd"), tag=bs, connect=cms.untracked.string( "frontier://FrontierProd/CMS_COND_31X_BEAMSPOT"))) print "BeamSpot in globaltag set to '%s'" % bs else: print "BeamSpot in globaltag not changed" # CV: disable gen. vertex smearing # (embed tau leptons exactly at Z->mumu event vertex) print "Disabling gen. vertex smearing" process.VtxSmeared = cms.EDProducer("FlatEvtVtxGenerator", MaxZ=cms.double(0.0), MaxX=cms.double(0.0), MaxY=cms.double(0.0), MinX=cms.double(0.0), MinY=cms.double(0.0), MinZ=cms.double(0.0), TimeOffset=cms.double(0.0), src=cms.InputTag( "generator", "unsmeared")) if process.customization_options.useJson.value(): print "Enabling event selection by JSON file" import PhysicsTools.PythonAnalysis.LumiList as LumiList import FWCore.ParameterSet.Types as CfgTypes myLumis = LumiList.LumiList( filename='my.json').getCMSSWString().split(',') process.source.lumisToProcess = CfgTypes.untracked( CfgTypes.VLuminosityBlockRange()) process.source.lumisToProcess.extend(myLumis) #---------------------------------------------------------------------------------------------------------------------- # CV: need to rerun particle-flow algorithm in order to create links between PFMuon -> PFBlocks -> PFClusters -> PFRecHits # (configure particle-flow sequence before overwriting modules in order to mix collections # of objects reconstructed and Z -> mu+ mu- event with simulated tau decay products) if process.customization_options.embeddingMode.value( ) == "RH" and process.customization_options.cleaningMode == 'PF': rerunParticleFlow(process, inputProcess) process.ProductionFilterSequence += process.rerunParticleFlowSequenceForPFMuonCleaning #---------------------------------------------------------------------------------------------------------------------- # mix "general" Track collection process.generalTracksORG = process.generalTracks.clone() process.generalTracks = cms.EDProducer( "TrackMixer", todo=cms.VPSet( cms.PSet(collection1=cms.InputTag("generalTracksORG", "", "EmbeddedRECO"), collection2=cms.InputTag("cleanedGeneralTracks"))), verbosity=cms.int32(0)) for p in process.paths: pth = getattr(process, p) if "generalTracks" in pth.moduleNames(): pth.replace(process.generalTracks, process.generalTracksORG * process.generalTracks) #---------------------------------------------------------------------------------------------------------------------- # CV/TF: mixing of std::vector<Trajectory> from Zmumu event and embedded tau decay products does not work yet. # For the time-being, we need to use the Trajectory objects from the embedded event process.trackerDrivenElectronSeedsORG = process.trackerDrivenElectronSeeds.clone( ) process.trackerDrivenElectronSeedsORG.TkColList = cms.VInputTag( cms.InputTag("generalTracksORG")) process.trackerDrivenElectronSeeds = cms.EDProducer( "ElectronSeedTrackRefUpdater", PreIdLabel=process.trackerDrivenElectronSeedsORG.PreIdLabel, PreGsfLabel=process.trackerDrivenElectronSeedsORG.PreGsfLabel, targetTracks=cms.InputTag("generalTracks"), inSeeds=cms.InputTag( "trackerDrivenElectronSeedsORG", process.trackerDrivenElectronSeedsORG.PreGsfLabel.value()), inPreId=cms.InputTag( "trackerDrivenElectronSeedsORG", process.trackerDrivenElectronSeedsORG.PreIdLabel.value()), ) for p in process.paths: pth = getattr(process, p) if "trackerDrivenElectronSeeds" in pth.moduleNames(): pth.replace( process.trackerDrivenElectronSeeds, process.trackerDrivenElectronSeedsORG * process.trackerDrivenElectronSeeds) # CV: need to keep 'generalTracksORG' collection in event-content, # as (at least electron based) PFCandidates will refer to it, # causing exception in 'pfNoPileUp' module otherwise outputModule.outputCommands.extend( ['keep recoTracks_generalTracksORG_*_*']) #---------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------- # mix collections of GSF electron tracks process.electronGsfTracksORG = process.electronGsfTracks.clone() process.electronGsfTracks = cms.EDProducer( "GsfTrackMixer", collection1=cms.InputTag("electronGsfTracksORG", "", "EmbeddedRECO"), collection2=cms.InputTag("electronGsfTracks", "", inputProcess)) process.gsfConversionTrackProducer.TrackProducer = cms.string( 'electronGsfTracksORG') for p in process.paths: pth = getattr(process, p) if "electronGsfTracks" in pth.moduleNames(): pth.replace( process.electronGsfTracks, process.electronGsfTracksORG * process.electronGsfTracks) process.generalConversionTrackProducer.TrackProducer = cms.string( 'generalTracksORG') process.uncleanedOnlyGeneralConversionTrackProducer.TrackProducer = cms.string( 'generalTracksORG') process.gsfElectronsORG = process.gsfElectrons.clone() process.gsfElectrons = cms.EDProducer("GSFElectronsMixer", col1=cms.InputTag("gsfElectronsORG"), col2=cms.InputTag( "gsfElectrons", "", inputProcess)) for p in process.paths: pth = getattr(process, p) if "gsfElectrons" in pth.moduleNames(): pth.replace(process.gsfElectrons, process.gsfElectronsORG * process.gsfElectrons) #---------------------------------------------------------------------------------------------------------------------- # dE/dx information for mixed track collections not yet implemented in 'TracksMixer' module, # disable usage of dE/dx information in all event reconstruction modules for now for p in process.paths: pth = getattr(process, p) for mod in pth.moduleNames(): if mod.find("dedx") != -1 and mod.find("Zmumu") == -1: if mod.find("ForPFMuonCleaning") == -1: print "Removing %s" % mod module = getattr(process, mod) pth.remove(module) # CV: Compute expected energy deposits of muon in EB/EE, HB/HE and HO: # (1) compute distance traversed by muons produced in Z -> mu+ mu- decay # through individual calorimeter cells # (2) scale distances by expected energy loss dE/dx of muon from TrackingTools.TrackAssociator.default_cfi import TrackAssociatorParameterBlock process.muonCaloDistances = cms.EDProducer( 'MuonCaloDistanceProducer', trackAssociator=TrackAssociatorParameterBlock. TrackAssociatorParameters, selectedMuons=process.customization_options.ZmumuCollection) process.ProductionFilterSequence += process.muonCaloDistances # mix collections of L1Extra objects l1ExtraCollections = [["L1EmParticle", "Isolated"], ["L1EmParticle", "NonIsolated"], ["L1EtMissParticle", "MET"], ["L1EtMissParticle", "MHT"], ["L1JetParticle", "Central"], ["L1JetParticle", "Forward"], ["L1JetParticle", "Tau"], ["L1MuonParticle", ""]] l1extraParticleCollections = [] for l1ExtraCollection in l1ExtraCollections: inputType = l1ExtraCollection[0] pluginType = None srcVeto = cms.InputTag('') dRveto = 0. if inputType == "L1EmParticle": pluginType = "L1ExtraEmParticleMixerPlugin" srcSelectedMuons = process.customization_options.ZmumuCollection dRveto = 0.3 elif inputType == "L1EtMissParticle": pluginType = "L1ExtraMEtMixerPlugin" elif inputType == "L1JetParticle": pluginType = "L1ExtraJetParticleMixerPlugin" srcSelectedMuons = process.customization_options.ZmumuCollection dRveto = 0.3 elif inputType == "L1MuonParticle": pluginType = "L1ExtraMuonParticleMixerPlugin" srcSelectedMuons = process.customization_options.ZmumuCollection dRveto = 0.8 else: raise ValueError("Invalid L1Extra type = %s !!" % inputType) instanceLabel = l1ExtraCollection[1] l1extraParticleCollections.append( cms.PSet(pluginType=cms.string(pluginType), instanceLabel=cms.string(instanceLabel), srcSelectedMuons2=srcSelectedMuons, dRveto2=cms.double(dRveto))) if inputType == 'L1EtMissParticle': l1extraParticleCollections[-1].srcMuons = cms.InputTag( "muonCaloDistances", "muons") l1extraParticleCollections[-1].distanceMapMuPlus = cms.InputTag( "muonCaloDistances", "distancesMuPlus") l1extraParticleCollections[-1].distanceMapMuMinus = cms.InputTag( "muonCaloDistances", "distancesMuPlus") l1extraParticleCollections[-1].H_Calo_AbsEtaLt12 = cms.double( process.customization_options.muonCaloCleaningSF.value() * 0.75) l1extraParticleCollections[-1].H_Calo_AbsEta12to17 = cms.double( process.customization_options.muonCaloCleaningSF.value() * 0.6) l1extraParticleCollections[-1].H_Calo_AbsEtaGt17 = cms.double( process.customization_options.muonCaloCleaningSF.value() * 0.3) process.l1extraParticlesORG = process.l1extraParticles.clone() process.l1extraParticles = cms.EDProducer( 'L1ExtraMixer', src1=cms.InputTag("l1extraParticlesORG"), src2=cms.InputTag("l1extraParticles", "", inputProcess), collections=cms.VPSet(l1extraParticleCollections)) for p in process.paths: pth = getattr(process, p) if "l1extraParticles" in pth.moduleNames(): pth.replace(process.l1extraParticles, process.l1extraParticlesORG * process.l1extraParticles) if process.customization_options.embeddingMode.value() == "PF": print "Using PF-embedding" from TauAnalysis.MCEmbeddingTools.embeddingCustomizePF import customise as customisePF customisePF(process) elif process.customization_options.embeddingMode.value() == "RH": print "Using RH-embedding" from TauAnalysis.MCEmbeddingTools.embeddingCustomizeRH import customise as customiseRH customiseRH(process, inputProcess) else: raise ValueError( "Invalid Configuration parameter 'embeddingMode' = %s !!" % process.customization_options.embeddingMode.value()) # it should be the best solution to take the original beam spot for the # reconstruction of the new primary vertex # use the one produced earlier, do not produce your own for s in process.sequences: seq = getattr(process, s) seq.remove(process.offlineBeamSpot) try: process.metreco.remove(process.BeamHaloId) except: pass try: outputModule = process.output except: pass try: outputModule = getattr( process, str(getattr(process, list(process.endpaths)[-1]))) except: pass process.filterEmptyEv.src = cms.untracked.InputTag("generatorSmeared", "", "EmbeddedRECO") try: process.schedule.remove(process.DQM_FEDIntegrity_v3) except: pass process.load("TauAnalysis/MCEmbeddingTools/ZmumuStandaloneSelection_cff") process.goldenZmumuFilter.src = process.customization_options.ZmumuCollection if process.customization_options.applyZmumuSkim.value(): print "Enabling Zmumu skim" process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi") for path in process.paths: if process.customization_options.isMC.value(): getattr( process, path)._seq = process.goldenZmumuFilterSequence * getattr( process, path)._seq else: getattr( process, path )._seq = process.goldenZmumuFilterSequenceData * getattr( process, path)._seq process.options = cms.untracked.PSet( wantSummary=cms.untracked.bool(True)) # CV: keep track of Z->mumu selection efficiency process.goldenZmumuFilterResult = cms.EDProducer( "CandViewCountEventSelFlagProducer", src=process.customization_options.ZmumuCollection, minNumber=cms.uint32(1)) process.goldenZmumuFilterEfficiencyPath = cms.Path( process.goldenZmumuSelectionSequence + process.goldenZmumuFilterResult + process.MEtoEDMConverter) process.schedule.append(process.goldenZmumuFilterEfficiencyPath) else: print "Zmumu skim disabled" process.load("TauAnalysis/MCEmbeddingTools/muonRadiationFilter_cfi") process.muonRadiationFilter.srcSelectedMuons = process.customization_options.ZmumuCollection if process.customization_options.applyMuonRadiationFilter.value(): print "Muon -> muon + photon radiation filter enabled" # CV: add filter at the end of reconstruction path # (filter needs mixed 'pfPileUp' and 'pfNoPileUp' collections) process.reconstruction_step += process.muonRadiationFilterSequence process.options = cms.untracked.PSet( wantSummary=cms.untracked.bool(True)) # CV: keep track of which events pass/fail muon -> muon + photon radiation filter process.muonRadiationFilterResult = cms.EDProducer( "DummyBoolEventSelFlagProducer") process.muonRadiationFilterEfficiencyPath = cms.Path( process.goldenZmumuSelectionSequence + process.muonRadiationFilterSequence + process.muonRadiationFilterResult) process.schedule.append(process.muonRadiationFilterEfficiencyPath) else: print "Muon -> muon + photon radiation filter disabled" # CV: disable ECAL/HCAL noise simulation if process.customization_options.disableCaloNoise.value(): print "Disabling ECAL/HCAL noise simulation" process.simEcalUnsuppressedDigis.doNoise = cms.bool(False) process.simEcalUnsuppressedDigis.doESNoise = cms.bool(False) process.simHcalUnsuppressedDigis.doNoise = cms.bool(False) process.simHcalUnsuppressedDigis.doThermalNoise = cms.bool(False) else: print "Keeping ECAL/HCAL noise simulation enabled" # CV: apply/do not apply muon momentum corrections determined by Rochester group if process.customization_options.replaceGenOrRecMuonMomenta.value( ) == "rec" and hasattr(process, "goldenZmumuSelectionSequence"): if process.customization_options.applyRochesterMuonCorr.value(): print "Enabling Rochester muon momentum corrections" process.patMuonsForZmumuSelectionRochesterMomentumCorr = cms.EDProducer( "RochesterCorrPATMuonProducer", src=cms.InputTag('patMuonsForZmumuSelection'), isMC=cms.bool(process.customization_options.isMC.value())) process.goldenZmumuSelectionSequence.replace( process.patMuonsForZmumuSelection, process.patMuonsForZmumuSelection * process.patMuonsForZmumuSelectionRochesterMomentumCorr) process.goodMuons.src = cms.InputTag( 'patMuonsForZmumuSelectionRochesterMomentumCorr') else: print "Rochester muon momentum corrections disabled" if process.customization_options.applyMuonRadiationCorrection.value( ) != "": print "Muon -> muon + photon radiation correction enabled" process.load( "TauAnalysis/MCEmbeddingTools/muonRadiationCorrWeightProducer_cfi") if process.customization_options.applyMuonRadiationCorrection.value( ) == "photos": process.muonRadiationCorrWeightProducer.lutDirectoryRef = cms.string( 'genMuonRadCorrAnalyzerPHOTOS') process.muonRadiationCorrWeightProducer.lutDirectoryOthers = cms.PSet( Summer12mcMadgraph=cms.string('genMuonRadCorrAnalyzer')) elif process.customization_options.applyMuonRadiationCorrection.value( ) == "pythia": process.muonRadiationCorrWeightProducer.lutDirectoryRef = cms.string( 'genMuonRadCorrAnalyzerPYTHIA') process.muonRadiationCorrWeightProducer.lutDirectoryOthers = cms.PSet( Summer12mcMadgraph=cms.string('genMuonRadCorrAnalyzer')) else: raise ValueError( "Invalid Configuration parameter 'applyMuonRadiationCorrection' = %s !!" % process.customization_options.applyMuonRadiationCorrection. value()) process.reconstruction_step += process.muonRadiationCorrWeightProducer outputModule.outputCommands.extend([ 'keep *_muonRadiationCorrWeightProducer_*_*', 'keep *_generator_muonsBeforeRad_*', 'keep *_generator_muonsAfterRad_*' ]) else: print "Muon -> muon + photon radiation correction disabled" # CV: compute reweighting factors to compensate for smearing of di-muon Pt and mass distributions caused by: # o (mis)reconstruction of muon momenta # o muon -> muon + photon radiation corrections process.load("TauAnalysis/MCEmbeddingTools/embeddingKineReweight_cff") if process.customization_options.applyMuonRadiationCorrection.value( ) != "": if process.customization_options.mdtau.value() == 116: process.embeddingKineReweightGENtoEmbedded.inputFileName = cms.FileInPath( "TauAnalysis/MCEmbeddingTools/data/makeEmbeddingKineReweightLUTs_GENtoEmbedded_mutau.root" ) process.reconstruction_step += process.embeddingKineReweightSequenceGENtoEmbedded elif process.customization_options.mdtau.value() == 115: process.embeddingKineReweightGENtoEmbedded.inputFileName = cms.FileInPath( "TauAnalysis/MCEmbeddingTools/data/makeEmbeddingKineReweightLUTs_GENtoEmbedded_etau.root" ) process.reconstruction_step += process.embeddingKineReweightSequenceGENtoEmbedded if process.customization_options.replaceGenOrRecMuonMomenta.value( ) == 'rec': process.reconstruction_step += process.embeddingKineReweightSequenceGENtoREC outputModule.outputCommands.extend(['keep *_embeddingKineReweight_*_*']) # CV: compute weights for correcting Embedded samples # for efficiency with which Zmumu events used as input for Embedding production were selected process.load( "TauAnalysis/MCEmbeddingTools/ZmumuEvtSelEffCorrWeightProducer_cfi") process.ZmumuEvtSelEffCorrWeightProducer.selectedMuons = process.customization_options.ZmumuCollection process.ZmumuEvtSelEffCorrWeightProducer.verbosity = cms.int32(0) process.reconstruction_step += process.ZmumuEvtSelEffCorrWeightProducer outputModule.outputCommands.extend( ['keep *_ZmumuEvtSelEffCorrWeightProducer_*_*']) return (process)
process.load( 'Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') process.GlobalTag.globaltag = options.globalTag #process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi") process.source = cms.Source("PoolSource", fileNames=cms.untracked.vstring() + options.inputFiles) # JSON file if not options.isMC and options.jsonFile != "": myLumis = \ LumiList.LumiList(filename = options.jsonFile ).getCMSSWString().split(',') process.source.lumisToProcess = \ CfgTypes.untracked(CfgTypes.VLuminosityBlockRange()) process.source.lumisToProcess.extend(myLumis) process.maxEvents = cms.untracked.PSet( input=cms.untracked.int32(options.maxEvents)) process.TFileService = cms.Service("TFileService", fileName=cms.string(options.outputFile)) from ElectroWeakAnalysis.MultiBosons.Selectors.muonSelector_cfi \ import muonSelection_FsrApr082011 as muonSelection from ElectroWeakAnalysis.MultiBosons.Selectors.diLeptonSelector_cfi \ import diMuonSelection_Fsr2011Apr11 as diMuonSelection
def main(argv) : """ writeCfg - Read in existing, user supplied pycfg or pickled pycfg file - Modify job specific parameters based on environment variables and arguments.xml - Write out pickled pycfg file required parameters: none optional parameters: --help : help --debug : debug statements """ # defaults inputFileNames = None parentFileNames = None debug = False _MAXINT = 900000000 try: opts, args = getopt.getopt(argv, "", ["debug", "help"]) except getopt.GetoptError: print main.__doc__ sys.exit(2) try: CMSSW = os.environ['CMSSW_VERSION'] parts = CMSSW.split('_') CMSSW_major = int(parts[1]) CMSSW_minor = int(parts[2]) CMSSW_patch = int(parts[3]) except (KeyError, ValueError): msg = "Your environment doesn't specify the CMSSW version or specifies it incorrectly" raise ConfigException(msg) # Parse command line options for opt, arg in opts : if opt == "--help" : print main.__doc__ sys.exit() elif opt == "--debug" : debug = True # Parse remaining parameters try: fileName = args[0] outFileName = args[1] except IndexError: print main.__doc__ sys.exit() # Read in Environment, XML and get optional Parameters nJob = int(os.environ.get('NJob', '0')) preserveSeeds = os.environ.get('PreserveSeeds','') incrementSeeds = os.environ.get('IncrementSeeds','') # Defaults maxEvents = 0 skipEvents = 0 firstEvent = -1 compHEPFirstEvent = 0 firstRun = 0 # FUTURE: Remove firstRun firstLumi = 0 dom = xml.dom.minidom.parse(os.environ['RUNTIME_AREA']+'/arguments.xml') for elem in dom.getElementsByTagName("Job"): if nJob == int(elem.getAttribute("JobID")): if elem.getAttribute("MaxEvents"): maxEvents = int(elem.getAttribute("MaxEvents")) if elem.getAttribute("SkipEvents"): skipEvents = int(elem.getAttribute("SkipEvents")) if elem.getAttribute("FirstEvent"): firstEvent = int(elem.getAttribute("FirstEvent")) if elem.getAttribute("FirstRun"): firstRun = int(elem.getAttribute("FirstRun")) if elem.getAttribute("FirstLumi"): firstLumi = int(elem.getAttribute("FirstLumi")) generator = str(elem.getAttribute('Generator')) inputFiles = str(elem.getAttribute('InputFiles')) parentFiles = str(elem.getAttribute('ParentFiles')) lumis = str(elem.getAttribute('Lumis')) # Read Input python config file handle = open(fileName, 'r') try: # Nested form for Python < 2.5 try: print "Importing .py file" cfo = imp.load_source("pycfg", fileName, handle) cmsProcess = cfo.process except Exception, ex: msg = "Your pycfg file is not valid python: %s" % str(ex) raise ConfigException(msg) finally: handle.close() cfg = CfgInterface(cmsProcess) # Set parameters for job print "Setting parameters" inModule = cfg.inputSource if maxEvents: cfg.maxEvents.setMaxEventsInput(maxEvents) if skipEvents: inModule.setSkipEvents(skipEvents) # Set "skip events" for various generators if generator == 'comphep': cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent) elif generator == 'lhe': cmsProcess.source.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent+1)) elif firstEvent != -1: # (Old? Madgraph) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) if inputFiles: inputFileNames = inputFiles.split(',') inModule.setFileNames(*inputFileNames) # handle parent files if needed if parentFiles: parentFileNames = parentFiles.split(',') inModule.setSecondaryFileNames(*parentFileNames) if lumis: if CMSSW_major < 3: # FUTURE: Can remove this check print "Cannot skip lumis for CMSSW 2_x" else: lumiRanges = lumis.split(',') inModule.setLumisToProcess(*lumiRanges) # Pythia parameters if (firstRun): inModule.setFirstRun(firstRun) if (firstLumi): inModule.setFirstLumi(firstLumi) # Check if there are random #'s to deal with if cfg.data.services.has_key('RandomNumberGeneratorService'): print "RandomNumberGeneratorService found, will attempt to change seeds" from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper ranGenerator = cfg.data.services['RandomNumberGeneratorService'] randSvc = RandomNumberServiceHelper(ranGenerator) incrementSeedList = [] preserveSeedList = [] if incrementSeeds: incrementSeedList = incrementSeeds.split(',') if preserveSeeds: preserveSeedList = preserveSeeds.split(',') # Increment requested seed sets for seedName in incrementSeedList: curSeeds = randSvc.getNamedSeed(seedName) newSeeds = [x+nJob for x in curSeeds] randSvc.setNamedSeed(seedName, *newSeeds) preserveSeedList.append(seedName) # Randomize remaining seeds randSvc.populate(*preserveSeedList) # Write out new config file outFile = open(outFileName,"w") outFile.write("import FWCore.ParameterSet.Config as cms\n") outFile.write("import pickle\n") outFile.write("pickledCfg=\"\"\"%s\"\"\"\n" % pickle.dumps(cmsProcess)) outFile.write("process = pickle.loads(pickledCfg)\n") outFile.close() if (debug): print "writeCfg output (May not be exact):" print "import FWCore.ParameterSet.Config as cms" print cmsProcess.dumpPython()
def mergeProcess(*inputFiles, **options): """ _mergeProcess_ Creates and returns a merge process that will merge the provided filenames supported options: - process_name : name of the process, defaults to Merge - outputmod_label : label of the output module, defaults to Merged - newDQMIO : specifies if the new DQM format should be used to merge the files - output_file : sets the output file name - output_lfn : sets the output LFN - mergeNANO : to merge NanoAOD - bypassVersionCheck : to bypass version check in case merging happened in lower version of CMSSW (i.e. UL HLT case). This will be TRUE by default. """ # // # // process supported options #// processName = options.get("process_name", "Merge") outputModLabel = options.get("outputmod_label", "Merged") outputFilename = options.get("output_file", "Merged.root") outputLFN = options.get("output_lfn", None) dropDQM = options.get("drop_dqm", False) newDQMIO = options.get("newDQMIO", False) mergeNANO = options.get("mergeNANO", False) bypassVersionCheck = options.get("bypassVersionCheck", True) # // # // build process #// process = Process(processName) # // # // input source #// if newDQMIO: process.source = Source("DQMRootSource") process.add_(Service("DQMStore")) else: process.source = Source("PoolSource") process.source.bypassVersionCheck = CfgTypes.untracked.bool(bypassVersionCheck) if dropDQM: process.source.inputCommands = CfgTypes.untracked.vstring('keep *','drop *_EDMtoMEConverter_*_*') process.source.fileNames = CfgTypes.untracked(CfgTypes.vstring()) for entry in inputFiles: process.source.fileNames.append(str(entry)) # // # // output module #// if newDQMIO: outMod = OutputModule("DQMRootOutputModule") elif mergeNANO: import Configuration.EventContent.EventContent_cff outMod = OutputModule("NanoAODOutputModule",Configuration.EventContent.EventContent_cff.NANOAODEventContent.clone()) process.add_(Service("InitRootHandlers", EnableIMT = CfgTypes.untracked.bool(False))) else: outMod = OutputModule("PoolOutputModule") outMod.fileName = CfgTypes.untracked.string(outputFilename) if outputLFN != None: outMod.logicalFileName = CfgTypes.untracked.string(outputLFN) setattr(process, outputModLabel, outMod) process.outputPath = EndPath(outMod) return process