Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:57

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