CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
ThrowAndSetRandomRun Namespace Reference

Functions

def throwAndSetRandomRun
 

Function Documentation

def ThrowAndSetRandomRun.throwAndSetRandomRun (   source,
  runsAndProbs 
)
Pass a list of tuple pairs, with the first item of the pair a run number
and the second number of the pair a weight.  The function will normalize the
weights so you do not have to worry about that.  The pairs will be used to randomly choose what Run
should be assigned to the job.

Definition at line 7 of file ThrowAndSetRandomRun.py.

References print().

7 
8 def throwAndSetRandomRun(source,runsAndProbs):
9  """Pass a list of tuple pairs, with the first item of the pair a run number
10  and the second number of the pair a weight. The function will normalize the
11  weights so you do not have to worry about that. The pairs will be used to randomly choose what Run
12  should be assigned to the job.
13  """
14  from random import SystemRandom
15  totalProb = 0.
16  for r,p in runsAndProbs:
17  totalProb+=p
18  #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
19  random = SystemRandom()
20  runProb = random.uniform(0,totalProb)
21  sumProb = 0
22  runNumber = 0
23  for r,p in runsAndProbs:
24  sumProb+=p
25  if sumProb >= runProb:
26  runNumber = r
27  break
28  print('setting runNumber to: ',runNumber)
29  if source.type_() == "PoolSource":
30  source.setRunNumber = cms.untracked.uint32(runNumber)
31  else:
32  #sources that inherit from ConfigurableInputSource use 'firstRun'
33  source.firstRun = cms.untracked.uint32(runNumber)
34 
35  return
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47