29 def __init__(self, process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False):
30 """ Generate a new process in madgraph.
31 Pass a process string.
32 Optionally request JPEGs to be kept and request for PMG settings to be used in the param card
33 Return the name of the process directory.
35 self.mglog = Logging.logging.getLogger(
'MadGraphUtils')
36 self.process = process
38 self.keepJpegs = keepJpegs
39 self.usePMGSettings = usePMGSettings
40 self.run_card_params = []
42 self.is_gen_from_gridpack = os.access(MADGRAPH_GRIDPACK_LOCATION,os.R_OK)
44 if self.is_gen_from_gridpack:
45 self.process_dir = MADGRAPH_GRIDPACK_LOCATION
48 card_loc=
'proc_card_mg5.dat'
49 mglog.info(
'Writing process card to '+card_loc)
50 a_card =
open( card_loc ,
'w' )
51 for l
in process.split(
'\n'):
54 elif '-nojpeg' in l
or keepJpegs:
57 a_card.write(l.split(
'#')[0]+
' -nojpeg #'+l.split(
'#')[1]+
'\n')
59 a_card.write(l+
' -nojpeg\n')
62 madpath=os.environ[
'MADPATH']
68 for l
in process.split(
'\n'):
70 if 'output' not in l.split(
'#')[0].
split():
73 tmplist = l.split(
'#')[0].
split(
' -')[0]
75 if len(tmplist.split())==2:
76 process_dir = tmplist.split()[1]
78 elif len(tmplist.split())==3:
79 process_dir = tmplist.split()[2]
82 mglog.info(
'Saw that you asked for a special output directory: '+
str(process_dir))
85 mglog.info(
'Started process generation at '+
str(time.asctime()))
87 plugin_cmd =
'--mode='+plugin
if plugin
is not None else ''
90 self.MADGRAPH_COMMAND_STACK = []
91 self.MADGRAPH_COMMAND_STACK += [
'# All jobs should start in a clean directory']
92 self.MADGRAPH_COMMAND_STACK += [
'mkdir standalone_test; cd standalone_test']
93 self.MADGRAPH_COMMAND_STACK += [
' '.
join([python,madpath+
'/bin/mg5_aMC '+plugin_cmd+
' << EOF\n'+process+
'\nEOF\n'])]
94 global MADGRAPH_CATCH_ERRORS
95 generate = subprocess.Popen([python,madpath+
'/bin/mg5_aMC',plugin_cmd,card_loc],stdin=subprocess.PIPE,stderr=subprocess.PIPE
if MADGRAPH_CATCH_ERRORS
else None)
96 (out,err) = generate.communicate()
99 mglog.info(
'Finished process generation at '+
str(time.asctime()))
102 if process_dir ==
'':
103 for adir
in sorted(glob.glob( os.getcwd()+
'/*PROC*' ),reverse=
True):
104 if os.access(
'%s/SubProcesses/subproc.mg'%adir,os.R_OK):
108 mglog.warning(
'Additional possible process directory, '+adir+
' found. Had '+process_dir)
109 mglog.warning(
'Likely this is because you did not run from a clean directory, and this may cause errors later.')
111 if not os.access(
'%s/SubProcesses/subproc.mg'%process_dir,os.R_OK):
112 raise RuntimeError(
'No diagrams for this process in user-define dir='+
str(process_dir))
114 raise RuntimeError(
'No diagrams for this process from list: '+
str(
sorted(glob.glob(os.getcwd()+
'/*PROC*'),reverse=
True)))
117 needed_options = [
'ninja',
'collier',
'fastjet',
'lhapdf',
'syscalc_path']
118 in_config =
open(os.environ[
'MADPATH']+
'/input/mg5_configuration.txt',
'r')
120 for l
in in_config.readlines():
121 for o
in needed_options:
122 if o+
' =' in l.split(
'#')[0]
and 'MCGenerators' in l.split(
'#')[0]:
123 old_path = l.split(
'#')[0].
split(
'=')[1].strip().
split(
'MCGenerators')[1]
124 old_path = old_path[ old_path.find(
'/') : ]
125 if o ==
'lhapdf' and 'LHAPATH' in os.environ:
127 version = os.environ[
'LHAPATH'].
split(
'lhapdf/')[1].
split(
'/')[0]
128 old_version = old_path.split(
'lhapdf/')[1].
split(
'/')[0]
129 old_path = old_path.replace(old_version,version)
132 old_path.replace(
'gosam_contrib',
'gosam-contrib')
133 option_paths[o] = os.environ[
'MADPATH'].
split(
'madgraph5amc')[0]+old_path
135 if o+
' =' in l
and o+
' =' not in l.split(
'#')[0]:
136 mglog.info(
'Option '+o+
' appears commented out in the config file')
139 for o
in needed_options:
140 if o
not in option_paths:
141 mglog.info(
'Path for option '+o+
' not found in original config')
143 mglog.info(
'Modifying config paths to avoid use of afs:')
144 mglog.info(option_paths)
147 self.change_config_card(process_dir=process_dir,settings=option_paths,set_commented=
False)
156 mglog.info(
'Setting default sde_strategy to old default (1)')
157 my_settings = {
'sde_strategy':1}
158 self.change_run_card(process_dir=process_dir,settings=my_settings,skipBaseFragment=
True)
161 self.change_config_card(process_dir=process_dir,settings={
'notification_center':
'False'})
164 self.MADGRAPH_COMMAND_STACK += [
'export MGaMC_PROCESS_DIR='+os.path.basename(process_dir)]
166 self.process_dir = process_dir