CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/SimGeneral/Configuration/python/ThrowAndSetRandomRun.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.Config as cms
00002 
00003 # function to modify an existing Cms Source in order to set the run number
00004 # aimed at setting non trivial run number in MC production - be it GEN-SIM or DIGI step
00005 
00006 def throwAndSetRandomRun(source,runsAndProbs):
00007         """Pass a list of tuple pairs, with the first item of the pair a run number
00008         and the second number of the pair a weight.  The function will normalize the
00009         weights so you do not have to worry about that.  The pairs will be used to randomly choose what Run
00010         should be assigned to the job.
00011         """
00012         from random import SystemRandom
00013         totalProb = 0.
00014         for r,p in runsAndProbs:
00015             totalProb+=p
00016         #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
00017         random = SystemRandom()
00018         runProb = random.uniform(0,totalProb)
00019         sumProb = 0
00020         runNumber = 0
00021         for r,p in runsAndProbs:
00022             sumProb+=p
00023             if sumProb >= runProb:
00024                 runNumber = r
00025                 break
00026         print 'setting runNumber to: ',runNumber
00027         if source.type_() == "PoolSource":
00028             source.setRunNumber = cms.untracked.uint32(runNumber)
00029         else:
00030             #sources that inherit from ConfigurableInputSource use 'firstRun'
00031             source.firstRun = cms.untracked.uint32(runNumber)
00032 
00033         return