CMS 3D CMS Logo

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