Skip to content

Commit

Permalink
clean events.lhe/dir from channel splitting and an option to better c…
Browse files Browse the repository at this point in the history
…ontrol log of channel
  • Loading branch information
oliviermattelaer committed May 1, 2024
1 parent 31da1b9 commit 137474a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
18 changes: 12 additions & 6 deletions madgraph/interface/madevent_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4015,13 +4015,19 @@ def do_store_events(self, line):
#except Exception:
# continue
# Store log
try:
if os.path.exists(pjoin(G_path, 'log.txt')):
input = pjoin(G_path, 'log.txt')
input = pjoin(G_path, 'log.txt')
if os.path.exists(input):
if self.run_card['keep_log'] not in ["none", "minimal"]:
output = pjoin(G_path, '%s_log.txt' % run)
files.mv(input, output)
except Exception:
continue
try:
files.mv(input, output)
except Exception:
continue
elif self.run_card['keep_log'] == "none":
try:
os.remove(input)
except Exception:
continue
#try:
# # Grid
# for name in ['ftn26']:
Expand Down
10 changes: 9 additions & 1 deletion madgraph/madevent/combine_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from __future__ import absolute_import
import math
import os
import shutil
import re
import logging
from six.moves import range
Expand Down Expand Up @@ -117,6 +118,7 @@ def sum_multichannel(self, channel):

#Now read in all of the events and write them
#back out with the appropriate scaled weight
to_clean = []
fsock = open(pjoin(channel, 'events.lhe'), 'w')
wgt = results.axsec / results.nunwgt
tot_nevents, nb_file = 0, 0
Expand All @@ -129,8 +131,14 @@ def sum_multichannel(self, channel):
nw = self.copy_events(fsock, pjoin(path,'events.lhe'), wgt)
tot_nevents += nw
nb_file += 1
to_clean.append(path)
logger.debug("Combined %s file generating %s events for %s " , nb_file, tot_nevents, channel)

for path in to_clean:
try:
shutil.rmtree(path)
except Exception as error:
pass

@staticmethod
def get_fortran_str(nb):
data = '%E' % nb
Expand Down
2 changes: 1 addition & 1 deletion madgraph/madevent/gen_ximprove.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ def create_ajob(self, template, jobs, write_dir=None):
break
info = jobs[j]
info['script_name'] = 'ajob%i' % script_number
info['keeplog'] = 'false'
info['keeplog'] = 'false' if self.run_card['keep_log'] != 'debug' else 'true'
if "base_directory" not in info:
info["base_directory"] = "./"
fsock.write(template_text % info)
Expand Down
3 changes: 3 additions & 0 deletions madgraph/various/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4026,6 +4026,9 @@ def default_setup(self):
self.add_param('frame_id', 6, system=True)
self.add_param("event_norm", "average", allowed=['sum','average', 'unity'],
include=False, sys_default='sum', hidden=True)
self.add_param("keep_log", "normal", include=False, hidden=True,
comment="none: all log send to /dev/null.\n minimal: keep only log for survey of the last run.\n normal: keep only log for survey of all run. \n debug: keep all log (survey and refine)",
allowed=['none', 'minimal', 'normal', 'debug'])
#cut
self.add_param("auto_ptj_mjj", True, hidden=True)
self.add_param("bwcutoff", 15.0)
Expand Down

0 comments on commit 137474a

Please sign in to comment.