Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-27 03:18:08

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 # function to modify an existing Cms Source in order to set the run number
0004 # aimed at setting non trivial run number in MC production - be it GEN-SIM or DIGI step
0005 
0006 def throwAndSetRandomRun(source,runsAndProbs):
0007     """Pass a list of tuple pairs, with the first item of the pair a run number
0008     and the second number of the pair a weight.  The function will normalize the
0009     weights so you do not have to worry about that.  The pairs will be used to randomly choose what Run
0010     should be assigned to the job.
0011     """
0012     from random import SystemRandom
0013     totalProb = 0.
0014     for r,p in runsAndProbs:
0015         totalProb+=p
0016     #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
0017     random = SystemRandom()
0018     runProb = random.uniform(0,totalProb)
0019     sumProb = 0
0020     runNumber = 0
0021     for r,p in runsAndProbs:
0022         sumProb+=p
0023         if sumProb >= runProb:
0024             runNumber = r
0025             break
0026     print('setting runNumber to: ',runNumber)
0027     if source.type_() == "PoolSource":
0028         source.setRunNumber = cms.untracked.uint32(runNumber)
0029     else:
0030         #sources that inherit from ConfigurableInputSource use 'firstRun'
0031         source.firstRun = cms.untracked.uint32(runNumber)
0032 
0033     return