Commit 0284efcd authored by Olga Bessidskaia Bylund's avatar Olga Bessidskaia Bylund
Browse files

fixed do_driver_hacks so that it works in MG 2.6.7 (only needed for DR2) and...

fixed do_driver_hacks so that it works in MG 2.6.7 (only needed for DR2) and cleaned up, also cleaned up do_DR1_hacks
parent 137cf1d8
Pipeline #1502610 failed with stages
in 58 seconds
......@@ -10,6 +10,7 @@ import re
import glob
import shutil
import sys
import fileinput
#General functions
......@@ -94,24 +95,22 @@ def find_W_prepare_DRXhack(mfile,bindex,windex,redefine_twidth,which_DR):
#-------------------------------------
def do_DR1_hacks(mfile,tmpfile):
shutil.copyfile(mfile, mfile+"~" )
with open(mfile,"w") as destination, open(mfile+"~") as source, open(tmpfile,"r") as mytmp:
for line in source:
print("performing DR1 for file ", mfile)
with open(tmpfile,"r") as mytmp:
# fileinput redirects the print output to mfile
for line in fileinput.input(mfile, inplace=True):
if "JAMP(1)=" in line:
print("performing DR1 for file ", mfile)
destination.write("\nC DR hack\n")
print "\nC DR hack"
for hackline in mytmp:
destination.write(hackline)
#print(hackline)
destination.write("C End DR hack. \n\n")
destination.write( line)
print hackline,
print "C End DR hack. \n"
print line,
#-------------------------------
#DR2 helper functions
def do_driver_hacks(driver_file): #takes care of negative weights in code for driver.f for madspin
shutil.copyfile(driver_file, driver_file+"~" )
def do_driver_hacks(driver_filename): #takes care of negative weights in code for driver.f for madspin
test_string1 = "weight.gt."
repl_string1 = "abs(weight).gt."
......@@ -119,16 +118,16 @@ def do_driver_hacks(driver_file): #takes care of negative weights in code for dr
test_string2 = "maxweight=weight"
repl_string2 = "maxweight=abs(weight)"
with open(driver_file,"w") as destination, open(driver_file+"~","r") as source:
mylines = source.readlines()
source = open(driver_filename,"r")
mylines = source.readlines()
with open(driver_filename,"w") as source:
for i,line in enumerate(mylines):
if test_string1 in line:
line = line.replace(test_string1,repl_string1)
mylines[i] = line.replace(test_string1,repl_string1)
if test_string2 in line:
line = line.replace(test_string2,repl_string2)
destination.write(line)
mylines[i] = line.replace(test_string2,repl_string2)
source.write(mylines[i])
os.remove(driver_file+"~")
def do_fks_hacks(pdir): #takes care of negative weights for event generation code
shutil.copyfile(pdir+"fks_singular.f", pdir+"fks_singular.f~" )
......@@ -167,9 +166,8 @@ def do_coupl_hacks(pdir): #define the width of the top quark for the event gener
the_lines = pcard.readlines()
for line in the_lines:
if "DECAY" in line and " 6 " in line:
relevant_line = line
top_width = re.compile("(\d.\d+e\+\d\d)").search(relevant_line).group(1)
top_width = line.split(" 6 ")[-1].rstrip()
break
with open(pdir+"coupl.inc","w") as destination, open(pdir+"coupl.inc~") as source:
mylines = source.readlines()
......
Markdown is supported
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