Commit 04e7023b authored by Ewelina Maria Lobodzinska's avatar Ewelina Maria Lobodzinska
Browse files

Merge branch '21.6-python-seed' into '21.6'

set MG python seed to increase reproducibility

See merge request !27834
parents 5c1511ab 457d4006
......@@ -684,7 +684,8 @@ def generate_from_gridpack(run_name='Test',gridpack_dir='madevent/',nevents=-1,r sorted( os.listdir( currdir ) ) )'For your information, ls of '+gridpack_dir+':') sorted( os.listdir( gridpack_dir ) ) )
if is_version_or_newer([2,6,3]):
modify_run_card(gridpack_dir+'/Cards/run_card.dat',gridpack_dir+'/Cards/run_card.backup',{'python_seed' : random_seed})
generate = subprocess.Popen([gridpack_dir+'/bin/',str(int(nevents)),str(int(random_seed))],stdin=subprocess.PIPE)
......@@ -2208,6 +2209,7 @@ def build_run_card(run_card_old='run_card.SM.dat',run_card_new='run_card.dat',
oldcard = open(run_card_old,'r')
newcard = open(run_card_new,'w')
used_options = []
for line in oldcard:
if '= xqcut ' in line:
newcard.write('%f = xqcut ! minimum kt jet measure between partons \n'%(xqcut))
......@@ -2215,6 +2217,9 @@ def build_run_card(run_card_old='run_card.SM.dat',run_card_new='run_card.dat',
newcard.write(' %i = nevents ! Number of unweighted events requested \n'%(nevts))
elif ' iseed ' in line:
newcard.write(' %i = iseed ! rnd seed (0=assigned automatically=default)) \n'%(rand_seed))
elif ' python_seed ' in line:
newcard.write(' %i = python_seed ! python seed (hidden parameter) \n'%(rand_seed))
elif ' ebeam1 ' in line:
newcard.write(' %i = ebeam1 ! beam 1 energy in GeV \n'%(int(beamEnergy)))
elif ' ebeam2 ' in line:
......@@ -2225,7 +2230,7 @@ def build_run_card(run_card_old='run_card.SM.dat',run_card_new='run_card.dat',
newcard.write(' %3.2f = alpsfact ! scale factor for QCD emission vx \n'%(alpsfact))
for ak in extras:
if ak in excludeList:
mglog.error('You are trying to set "%s" with the extras parameter in build_run_card, this must be set in the build_run_card arguments instead.'%ak)
raise RuntimeError('You are trying to set "%s" with the extras parameter in build_run_card, this must be set in the build_run_card arguments instead.'%ak)
......@@ -2254,6 +2259,8 @@ def build_run_card(run_card_old='run_card.SM.dat',run_card_new='run_card.dat',
# Clean up options that weren't used
if not python_seed_set and not isNLO and is_version_or_newer([2,6,3]):
newcard.write(' %i = python_seed ! python seed (hidden parameter) \n'%(rand_seed))
for ak in extras:
if ak in used_options: continue
mglog.warning('Option '+ak+' was not in the default run_card. Adding by hand a setting to '+str(extras[ak]) )
......@@ -2499,6 +2506,13 @@ def run_card_consistency_check(isNLO=False,path='.'):
if not isNLO and is_version_or_newer([2,6,3]):
if not 'python_seed' in mydict:
mglog.warning('No python seed set in run_card -- adding one with same value as iseed')
modify_run_card(cardpath,cardpath+'.iseed.backup',{'python_seed' : mydict['iseed']})
elif int(mydict['python_seed'])!=int(mydict['iseed']):
raise RuntimeError('python_seed and iseed do not agree')'Finished checking run card - All OK!')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment