Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
SimGeneral
Configuration
python
ThrowAndSetRandomRun.py
Go to the documentation of this file.
1
import
FWCore.ParameterSet.Config
as
cms
2
3
# function to modify an existing Cms Source in order to set the run number
4
# aimed at setting non trivial run number in MC production - be it GEN-SIM or DIGI step
5
6
def
throwAndSetRandomRun
(source,runsAndProbs):
7
"""Pass a list of tuple pairs, with the first item of the pair a run number
8
and the second number of the pair a weight. The function will normalize the
9
weights so you do not have to worry about that. The pairs will be used to randomly choose what Run
10
should be assigned to the job.
11
"""
12
from
random
import
SystemRandom
13
totalProb = 0.
14
for
r,p
in
runsAndProbs:
15
totalProb+=p
16
#this is the same random generator used to set the seeds for the RandomNumberGeneratorService
17
random = SystemRandom()
18
runProb = random.uniform(0,totalProb)
19
sumProb = 0
20
runNumber = 0
21
for
r,p
in
runsAndProbs:
22
sumProb+=p
23
if
sumProb >= runProb:
24
runNumber = r
25
break
26
print
'setting runNumber to: '
,runNumber
27
if
source.type_() ==
"PoolSource"
:
28
source.setRunNumber = cms.untracked.uint32(runNumber)
29
else
:
30
#sources that inherit from ConfigurableInputSource use 'firstRun'
31
source.firstRun = cms.untracked.uint32(runNumber)
32
33
return
Config
ThrowAndSetRandomRun.throwAndSetRandomRun
def throwAndSetRandomRun
Definition:
ThrowAndSetRandomRun.py:6
Generated for CMSSW Reference Manual by
1.8.5