ATLAS Offline Software
Loading...
Searching...
No Matches
python.MadGraphUtils Namespace Reference

Functions

 stack_subprocess (command, **kwargs)
 generate_prep (process_dir)
 new_process (process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False)
 get_default_runcard (process_dir=MADGRAPH_GRIDPACK_LOCATION)
 generate (process_dir='PROC_mssm_0', grid_pack=False, gridpack_compile=False, extlhapath=None, required_accuracy=0.01, runArgs=None, bias_module=None, requirePMGSettings=False)
 generate_from_gridpack (runArgs=None, extlhapath=None, gridpack_compile=None, requirePMGSettings=False)
 setupFastjet (process_dir=None)
 setupLHAPDF (process_dir=None, extlhapath=None, allow_links=True)
 setNCores (process_dir, Ncores=None)
 get_mg5_executable ()
 add_lifetimes (process_dir, threshold=None)
 add_madspin (madspin_card=None, process_dir=MADGRAPH_GRIDPACK_LOCATION)
 madspin_on_lhe (input_LHE, madspin_card, runArgs=None, keep_original=False)
 arrange_output (process_dir=MADGRAPH_GRIDPACK_LOCATION, lhe_version=None, saveProcDir=False, runArgs=None, fixEventWeightsForBridgeMode=False)
 get_expected_reweight_names (reweight_card_loc)
 get_expected_systematic_names (syst_setting)
 setup_bias_module (bias_module, process_dir)
 get_reweight_card (process_dir=MADGRAPH_GRIDPACK_LOCATION)
 check_reweight_card (process_dir=MADGRAPH_GRIDPACK_LOCATION)
 update_lhe_file (lhe_file_old, param_card_old=None, lhe_file_new=None, masses={}, delete_old_lhe=True)
 print_cards_from_dir (process_dir=MADGRAPH_GRIDPACK_LOCATION)
 print_cards (proc_card='proc_card_mg5.dat', run_card=None, param_card=None, madspin_card=None, reweight_card=None, warn_on_missing=True)
 is_gen_from_gridpack ()
 modify_run_card (run_card_input=None, run_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, runArgs=None, settings={}, skipBaseFragment=False)
 modify_config_card (config_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, settings={}, set_commented=True)
 get_cluster_type ()
 add_reweighting (run_name, reweight_card=None, process_dir=MADGRAPH_GRIDPACK_LOCATION)
 ls_dir (directory)
 fix_fks_makefile (process_dir)

Variables

 mglog = Logging.logging.getLogger('MadGraphUtils')
 my_MGC_instance = None
str python = 'python'
str MADGRAPH_GRIDPACK_LOCATION = 'madevent'
str MADGRAPH_RUN_NAME = 'run_01'
bool MADGRAPH_CATCH_ERRORS = True
 MADGRAPH_PDFSETTING = None
list MADGRAPH_COMMAND_STACK = []

Function Documentation

◆ add_lifetimes()

python.MadGraphUtils.add_lifetimes ( process_dir,
threshold = None )
 Add lifetimes to the generated LHE file.  Should be
called after generate_events is called.

Definition at line 760 of file MadGraphUtils.py.

760def add_lifetimes(process_dir,threshold=None):
761 """ Add lifetimes to the generated LHE file. Should be
762 called after generate_events is called.
763 """
764
765 me_exec=get_mg5_executable()
766
767 if len(glob.glob(process_dir+'/Events/*'))<1:
768 mglog.error('Process dir '+process_dir+' does not contain events?')
769 run = glob.glob(process_dir+'/Events/*')[0].split('/')[-1]
770
771 # Note : This slightly clunky implementation is needed for the time being
772 # See : https://answers.launchpad.net/mg5amcnlo/+question/267904
773
774 tof_c = open('time_of_flight_exec_card','w')
775 tof_c.write('launch '+process_dir+''' -i
776add_time_of_flight '''+run+((' --threshold='+str(threshold)) if threshold is not None else ''))
777 tof_c.close()
778
779 mglog.info('Started adding time of flight info '+str(time.asctime()))
780
781 generate = stack_subprocess([python,me_exec,'time_of_flight_exec_card'],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
782 (out,err) = generate.communicate()
783 error_check(err,generate.returncode)
784
785 mglog.info('Finished adding time of flight information at '+str(time.asctime()))
786
787 # Re-zip the file if needed
788 lhe_gz = glob.glob(process_dir+'/Events/*/*lhe.gz')[0]
789 if not os.access(lhe_gz,os.R_OK):
790 mglog.info('LHE file needs to be zipped')
791 lhe = glob.glob(process_dir+'/Events/*/*lhe.gz')[0]
792 rezip = stack_subprocess(['gzip',lhe])
793 rezip.wait()
794 mglog.info('Zipped')
795 else:
796 mglog.info('LHE file zipped by MadGraph automatically. Nothing to do')
797
798 return True
799
800
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ add_madspin()

python.MadGraphUtils.add_madspin ( madspin_card = None,
process_dir = MADGRAPH_GRIDPACK_LOCATION )
 Run madspin on the generated LHE file.  Should be
run when you have inputGeneratorFile set.
Only requires a simplified process with the same model that you are
interested in (needed to set up a process directory for MG5_aMC)

Definition at line 801 of file MadGraphUtils.py.

801def add_madspin(madspin_card=None,process_dir=MADGRAPH_GRIDPACK_LOCATION):
802 """ Run madspin on the generated LHE file. Should be
803 run when you have inputGeneratorFile set.
804 Only requires a simplified process with the same model that you are
805 interested in (needed to set up a process directory for MG5_aMC)
806 """
807
808 me_exec=get_mg5_executable()
809
810 if madspin_card is not None:
811 shutil.copyfile(madspin_card,process_dir+'/Cards/madspin_card.dat')
812
813 if len(glob.glob(process_dir+'/Events/*'))<1:
814 mglog.error('Process dir '+process_dir+' does not contain events?')
815 proc_dir_list = glob.glob(process_dir+'/Events/*')
816 run=None
817 for adir in proc_dir_list:
818 if 'GridRun_' in adir:
819 run=adir.split('/')[-1]
820 break
821 else:
822 run=proc_dir_list[0].split('/')[-1]
823
824 # Note : This slightly clunky implementation is needed for the time being
825 # See : https://answers.launchpad.net/mg5amcnlo/+question/267904
826
827 ms_c = open('madspin_exec_card','w')
828 ms_c.write('launch '+process_dir+''' -i
829decay_events '''+run)
830 ms_c.close()
831
832 mglog.info('Started running madspin at '+str(time.asctime()))
833
834 generate = stack_subprocess([python,me_exec,'madspin_exec_card'],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
835 (out,err) = generate.communicate()
836 error_check(err,generate.returncode)
837 if len(glob.glob(process_dir+'/Events/'+run+'_decayed_*/')) == 0:
838 mglog.error('No '+process_dir+'/Events/'+run+'_decayed_*/ can be found')
839 raise RuntimeError('Problem while running MadSpin')
840
841 mglog.info('Finished running madspin at '+str(time.asctime()))
842
843 # Re-zip the file if needed
844 lhe_gz = glob.glob(process_dir+'/Events/*/*lhe.gz')[0]
845 if not os.access(lhe_gz,os.R_OK):
846 mglog.info('LHE file needs to be zipped')
847 lhe = glob.glob(process_dir+'/Events/*/*lhe.gz')[0]
848 rezip = stack_subprocess(['gzip',lhe])
849 rezip.wait()
850 mglog.info('Zipped')
851 else:
852 mglog.info('LHE file zipped by MadGraph automatically. Nothing to do')
853
854

◆ add_reweighting()

python.MadGraphUtils.add_reweighting ( run_name,
reweight_card = None,
process_dir = MADGRAPH_GRIDPACK_LOCATION )

Definition at line 1713 of file MadGraphUtils.py.

1713def add_reweighting(run_name,reweight_card=None,process_dir=MADGRAPH_GRIDPACK_LOCATION):
1714 mglog.info('Running reweighting module on existing events')
1715 if reweight_card is not None:
1716 mglog.info('Copying new reweight card from '+reweight_card)
1717 shutil.move(reweight_card,process_dir+'/Cards/reweight_card.dat')
1718 reweight_cmd='{}/bin/madevent reweight {} -f'.format(process_dir,run_name)
1719 reweight = stack_subprocess([python]+reweight_cmd.split(),stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
1720 (out,err) = reweight.communicate()
1721 error_check(err,reweight.returncode)
1722 mglog.info('Finished reweighting')
1723
1724
1725
1726

◆ arrange_output()

python.MadGraphUtils.arrange_output ( process_dir = MADGRAPH_GRIDPACK_LOCATION,
lhe_version = None,
saveProcDir = False,
runArgs = None,
fixEventWeightsForBridgeMode = False )

Definition at line 942 of file MadGraphUtils.py.

942def arrange_output(process_dir=MADGRAPH_GRIDPACK_LOCATION,lhe_version=None,saveProcDir=False,runArgs=None,fixEventWeightsForBridgeMode=False):
943
944 # NLO is not *really* the question here, we need to know if we should look for weighted or
945 # unweighted events in the output directory. MadSpin (above) only seems to give weighted
946 # results for now?
947 if len(glob.glob(os.path.join(process_dir, 'Events','*')))<1:
948 mglog.error('Process dir '+process_dir+' does not contain events?')
949 proc_dir_list = glob.glob(os.path.join(process_dir, 'Events', '*'))
950 this_run_name=None
951 # looping over possible directories to find the right one
952 for adir in proc_dir_list:
953 if 'decayed' in adir:# skipping '*decayed*' directories produced by MadSpin, will be picked later if they exist
954 continue
955 else:
956 if 'GridRun_' in adir:
957 this_run_name=adir
958 break # GridRun_* directories have priority
959 elif os.path.join(process_dir, 'Events',MADGRAPH_RUN_NAME) in adir:
960 this_run_name=adir
961 if not os.access(this_run_name,os.R_OK):
962 raise RuntimeError('Unable to locate run directory')
963
964 hasUnweighted = os.access(this_run_name+'/unweighted_events.lhe.gz',os.R_OK)
965
966 hasRunMadSpin=False
967 madspinDirs=sorted(glob.glob(this_run_name+'_decayed_*/'))
968 if len(madspinDirs):
969 hasRunMadSpin=True
970 if hasRunMadSpin and not hasUnweighted:
971 # check again:
972 hasUnweighted = os.access(madspinDirs[-1]+'/unweighted_events.lhe.gz',os.R_OK)
973
974 global MADGRAPH_COMMAND_STACK
975 if hasRunMadSpin:
976 if len(madspinDirs):
977 if hasUnweighted:
978 # so this is a bit of a mess now...
979 # if madspin is run from an NLO grid pack the correct lhe events are at both
980 # madevent/Events/run_01/unweighted_events.lhe.gz
981 # and madevent/Events/run_01_decayed_1/events.lhe.gz
982 # so there are unweighted events but not in the madspinDir...
983 if os.path.exists(madspinDirs[-1]+'/unweighted_events.lhe.gz'):
984 MADGRAPH_COMMAND_STACK += ['mv '+madspinDirs[-1]+'/unweighted_events.lhe.gz'+' '+this_run_name+'/unweighted_events.lhe.gz']
985 shutil.move(madspinDirs[-1]+'/unweighted_events.lhe.gz',this_run_name+'/unweighted_events.lhe.gz')
986 mglog.info('Moving MadSpin events from '+madspinDirs[-1]+'/unweighted_events.lhe.gz to '+this_run_name+'/unweighted_events.lhe.gz')
987 elif os.path.exists(madspinDirs[-1]+'/events.lhe.gz'):
988 MADGRAPH_COMMAND_STACK += ['mv '+madspinDirs[-1]+'/events.lhe.gz'+' '+this_run_name+'/unweighted_events.lhe.gz']
989 shutil.move(madspinDirs[-1]+'/events.lhe.gz',this_run_name+'/unweighted_events.lhe.gz')
990 mglog.info('Moving MadSpin events from '+madspinDirs[-1]+'/events.lhe.gz to '+this_run_name+'/unweighted_events.lhe.gz')
991 else:
992 raise RuntimeError('MadSpin was run but can\'t find files :(')
993
994 else:
995 MADGRAPH_COMMAND_STACK += ['mv '+madspinDirs[-1]+'/events.lhe.gz '+this_run_name+'/events.lhe.gz']
996 shutil.move(madspinDirs[-1]+'/events.lhe.gz',this_run_name+'/events.lhe.gz')
997 mglog.info('Moving MadSpin events from '+madspinDirs[-1]+'/events.lhe.gz to '+this_run_name+'/events.lhe.gz')
998
999 else:
1000 mglog.error('MadSpin was run but can\'t find output folder '+(this_run_name+'_decayed_1/'))
1001 raise RuntimeError('MadSpin was run but can\'t find output folder '+(this_run_name+'_decayed_1/'))
1002
1003 if fixEventWeightsForBridgeMode:
1004 mglog.info("Fixing event weights after MadSpin... initial checks.")
1005
1006 # get the cross section from the undecayed LHE file
1007 spinmodenone=False
1008 MGnumevents=-1
1009 MGintweight=-1
1010
1011 if hasUnweighted:
1012 eventsfilename="unweighted_events"
1013 else:
1014 eventsfilename="events"
1015 unzip = stack_subprocess(['gunzip','-f',this_run_name+'/%s.lhe.gz' % eventsfilename])
1016 unzip.wait()
1017
1018 for line in open(process_dir+'/Events/'+MADGRAPH_RUN_NAME+'/%s.lhe'%eventsfilename):
1019 if "Number of Events" in line:
1020 sline=line.split()
1021 MGnumevents=int(sline[-1])
1022 elif "Integrated weight (pb)" in line:
1023 sline=line.split()
1024 MGintweight=float(sline[-1])
1025 elif "set spinmode none" in line:
1026 spinmodenone=True
1027 elif "</header>" in line:
1028 break
1029
1030 if spinmodenone and MGnumevents>0 and MGintweight>0:
1031 mglog.info("Fixing event weights after MadSpin... modifying LHE file.")
1032 newlhe=open(this_run_name+'/%s_fixXS.lhe'%eventsfilename,'w')
1033 initlinecount=0
1034 eventlinecount=0
1035 inInit=False
1036 inEvent=False
1037
1038 # new default for MG 2.6.1+ (https://its.cern.ch/jira/browse/AGENE-1725)
1039 # but verified from LHE below.
1040 event_norm_setting="average"
1041
1042 for line in open(this_run_name+'/%s.lhe'%eventsfilename):
1043
1044 newline=line
1045 if "<init>" in line:
1046 inInit=True
1047 initlinecount=0
1048 elif "</init>" in line:
1049 inInit=False
1050 elif inInit and initlinecount==0:
1051 initlinecount=1
1052 # check event_norm setting in LHE file, deteremines how Pythia interprets event weights
1053 sline=line.split()
1054 if abs(int(sline[-2])) == 3:
1055 event_norm_setting="sum"
1056 elif abs(int(sline[-2])) == 4:
1057 event_norm_setting="average"
1058 elif inInit and initlinecount==1:
1059 sline=line.split()
1060 # update the global XS info
1061 relunc=float(sline[1])/float(sline[0])
1062 sline[0]=str(MGintweight)
1063 sline[1]=str(float(sline[0])*relunc)
1064 if event_norm_setting=="sum":
1065 sline[2]=str(MGintweight/MGnumevents)
1066 elif event_norm_setting=="average":
1067 sline[2]=str(MGintweight)
1068 newline=' '.join(sline)
1069 newline+="\n"
1070 initlinecount+=1
1071 elif inInit and initlinecount>1:
1072 initlinecount+=1
1073 elif "<event>" in line:
1074 inEvent=True
1075 eventlinecount=0
1076 elif "</event>" in line:
1077 inEvent=False
1078 elif inEvent and eventlinecount==0:
1079 sline=line.split()
1080 # next change the per-event weights
1081 if event_norm_setting=="sum":
1082 sline[2]=str(MGintweight/MGnumevents)
1083 elif event_norm_setting=="average":
1084 sline[2]=str(MGintweight)
1085 newline=' '.join(sline)
1086 newline+="\n"
1087 eventlinecount+=1
1088 newlhe.write(newline)
1089 newlhe.close()
1090
1091 mglog.info("Fixing event weights after MadSpin... cleaning up.")
1092 shutil.copyfile(this_run_name+'/%s.lhe' % eventsfilename,
1093 this_run_name+'/%s_badXS.lhe' % eventsfilename)
1094
1095 shutil.move(this_run_name+'/%s_fixXS.lhe' % eventsfilename,
1096 this_run_name+'/%s.lhe' % eventsfilename)
1097
1098 rezip = stack_subprocess(['gzip',this_run_name+'/%s.lhe' % eventsfilename])
1099 rezip.wait()
1100
1101 rezip = stack_subprocess(['gzip',this_run_name+'/%s_badXS.lhe' % eventsfilename])
1102 rezip.wait()
1103
1104 # Clean up in case a link or file was already there
1105 if os.path.exists(os.getcwd()+'/events.lhe'):
1106 os.remove(os.getcwd()+'/events.lhe')
1107
1108 mglog.info('Unzipping generated events.')
1109 if hasUnweighted:
1110 unzip = stack_subprocess(['gunzip','-f',this_run_name+'/unweighted_events.lhe.gz'])
1111 unzip.wait()
1112 else:
1113 unzip = stack_subprocess(['gunzip','-f',this_run_name+'/events.lhe.gz'])
1114 unzip.wait()
1115
1116 mglog.info('Putting a copy in place for the transform.')
1117 if hasUnweighted:
1118 orig_input = this_run_name+'/unweighted_events.lhe'
1119 mod_output = open(os.getcwd()+'/events.lhe','w')
1120 else:
1121 orig_input = this_run_name+'/events.lhe'
1122 mod_output = open(os.getcwd()+'/events.lhe','w')
1123
1124 #Removing empty lines and bad comments in LHE
1125 #and check for existence of weights
1126 initrwgt=None
1127 nEmpty=0
1128 lhe_weights=[]
1129 with open(orig_input,'r') as fileobject:
1130 for line in fileobject:
1131 if line.strip():
1132 # search for bad characters (neccessary until at least MG5 2.8.1)
1133 newline=line
1134 if '#' not in newline:
1135 newline=newline
1136 elif '>' not in newline[ newline.find('#'): ]:
1137 newline=newline
1138 else:
1139 mglog.info('Found bad LHE line with an XML mark in a comment: "'+newline.strip()+'"')
1140 newline=newline[:newline.find('#')]+'#'+ (newline[newline.find('#'):].replace('>','-'))
1141 # check for weightnames that should exist, simplify nominal weight names
1142 if initrwgt is False:
1143 pass
1144 elif "</initrwgt>" in newline:
1145 initrwgt=False
1146 elif "<initrwgt>" in newline:
1147 initrwgt=True
1148 elif initrwgt is not None:
1149 newline=newline.replace('_DYNSCALE-1','')
1150 if '</weight>' in newline:
1151 iend=newline.find('</weight>')
1152 istart=newline[:iend].rfind('>')
1153 lhe_weights+=[newline[istart+1:iend].strip()]
1154 mod_output.write(newline)
1155 else:
1156 nEmpty=nEmpty+1
1157 mod_output.close()
1158 mglog.info('Removed '+str(nEmpty)+' empty lines from LHEF')
1159
1160 mglog.info("The following "+str(len(lhe_weights))+" weights have been written to the LHE file: "+",".join(lhe_weights))
1161 expected_weights=get_expected_reweight_names(get_reweight_card(process_dir))
1162 expected_weights+=get_expected_systematic_names(MADGRAPH_PDFSETTING)
1163 mglog.info("Checking whether the following expected weights are in LHE file: "+",".join(expected_weights))
1164 for w in expected_weights:
1165 if w not in lhe_weights:
1166 raise RuntimeError("Did not find expected weight "+w+" in lhe file. Did the reweight or systematics module crash?")
1167 mglog.info("Found all required weights!")
1168
1169 if lhe_version:
1170 mod_output2 = open(os.getcwd()+'/events.lhe','r')
1171 test=mod_output2.readline()
1172 if 'version="' in test:
1173 mglog.info('Applying LHE version hack')
1174 final_file = open(os.getcwd()+'/events.lhe.copy','w')
1175 final_file.write('<LesHouchesEvents version="%i.0">\n'%lhe_version)
1176 shutil.copyfileobj(mod_output2, final_file)
1177 final_file.close()
1178 shutil.copy(os.getcwd()+'/events.lhe.copy',os.getcwd()+'/events.lhe')
1179 # Clean up after ourselves
1180 os.remove(os.getcwd()+'/events.lhe.copy')
1181 mod_output2.close()
1182
1183 # Actually move over the dataset
1184 if runArgs is None:
1185 raise RuntimeError('Must provide runArgs to arrange_output')
1186
1187 if hasattr(runArgs,'outputTXTFile'):
1188 outputDS = runArgs.outputTXTFile
1189 else:
1190 outputDS = 'tmp_LHE_events.tar.gz'
1191
1192 mglog.info('Moving file over to '+outputDS.split('.tar.gz')[0]+'.events')
1193
1194 shutil.move(os.getcwd()+'/events.lhe',outputDS.split('.tar.gz')[0]+'.events')
1195
1196 mglog.info('Re-zipping into dataset name '+outputDS)
1197 rezip = stack_subprocess(['tar','cvzf',outputDS,outputDS.split('.tar.gz')[0]+'.events'])
1198 rezip.wait()
1199
1200 if not saveProcDir:
1201 mglog.info('Removing the process directory')
1202 shutil.rmtree(process_dir,ignore_errors=True)
1203
1204 if os.path.isdir('MGC_LHAPDF/'):
1205 shutil.rmtree('MGC_LHAPDF/',ignore_errors=True)
1206
1207 # shortening the outputDS in the case of an output TXT file
1208 if hasattr(runArgs,'outputTXTFile') and runArgs.outputTXTFile is not None:
1209 outputDS = outputDS.split('.TXT')[0]
1210 # Do some fixing up for them
1211 if runArgs is not None:
1212 mglog.debug('Setting inputGenerator file to '+outputDS)
1213 runArgs.inputGeneratorFile=outputDS
1214
1215 mglog.info('All done with output arranging!')
1216 return outputDS
1217
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310

◆ check_reweight_card()

python.MadGraphUtils.check_reweight_card ( process_dir = MADGRAPH_GRIDPACK_LOCATION)

Definition at line 1308 of file MadGraphUtils.py.

1308def check_reweight_card(process_dir=MADGRAPH_GRIDPACK_LOCATION):
1309 reweight_card=get_reweight_card(process_dir=process_dir)
1310 shutil.move(reweight_card,reweight_card+'.old')
1311 oldcard = open(reweight_card+'.old','r')
1312 newcard = open(reweight_card,'w')
1313 changed = False
1314 info_expression=r'launch.*--rwgt_info\s*=\s*(\S+).*'
1315 name_expression=info_expression.replace('info','name')
1316 goodname_expression=r'^[A-Za-z0-9_\-.]+$'
1317 for line in oldcard:
1318 # we are only interested in the 'launch' line
1319 if not line.strip().startswith('launch') :
1320 newcard.write(line)
1321 else:
1322 rwgt_name_match=re.match(name_expression,line.strip())
1323 rwgt_info_match=re.match(info_expression,line.strip())
1324 if rwgt_name_match is None and rwgt_info_match is None:
1325 raise RuntimeError('Every reweighting should have a --rwgt_info (see https://cp3.irmp.ucl.ac.be/projects/madgraph/wiki/Reweight), please update your reweight_card accordingly. Line to fix: '+line)
1326 for match in [rwgt_info_match,rwgt_name_match]:
1327 if match is None:
1328 continue
1329 if len(match.groups())!=1:
1330 raise RuntimeError('Unexpected format of reweight card in line: '+line)
1331 if not re.match(goodname_expression,match.group(1)):
1332 raise RuntimeError('No special character in reweighting info/name, only allowing '+goodname_expression)
1333 if rwgt_info_match is not None:
1334 newcard.write(line)
1335 elif rwgt_name_match is not None:
1336 newcard.write(line.strip()+' --rwgt_info={0}\n'.format(rwgt_name_match.group(1)))
1337 changed=True
1338 if changed:
1339 mglog.info('Updated reweight_card')
1340 newcard.close()
1341 oldcard.close()
1342
1343

◆ fix_fks_makefile()

python.MadGraphUtils.fix_fks_makefile ( process_dir)

Definition at line 1735 of file MadGraphUtils.py.

1735def fix_fks_makefile(process_dir):
1736 makefile_fks=process_dir+'/SubProcesses/makefile_fks_dir'
1737 mglog.info('Fixing '+makefile_fks)
1738 shutil.move(makefile_fks,makefile_fks+'_orig')
1739 fin=open(makefile_fks+'_orig')
1740 fout=open(makefile_fks,'w')
1741 edit=False
1742 for line in fin:
1743 if 'FKSParams.mod' in line:
1744 fout.write(line.replace('FKSParams.mod','FKSParams.o'))
1745 edit=True
1746 elif edit and 'driver_mintFO' in line:
1747 fout.write('driver_mintFO.o: weight_lines.o mint_module.o FKSParams.o\n')
1748 elif edit and 'genps_fks.o' in line:
1749 fout.write('genps_fks.o: mint_module.o FKSParams.o\n')
1750 elif edit and 'test_soft_col_limits' in line:
1751 fout.write(line)
1752 fout.write('madfks_plot.o: mint_module.o\n')
1753 fout.write('cluster.o: weight_lines.o\n')
1754 else:
1755 fout.write(line)
1756 fin.close()
1757 fout.close()

◆ generate()

python.MadGraphUtils.generate ( process_dir = 'PROC_mssm_0',
grid_pack = False,
gridpack_compile = False,
extlhapath = None,
required_accuracy = 0.01,
runArgs = None,
bias_module = None,
requirePMGSettings = False )

Definition at line 101 of file MadGraphUtils.py.

101def generate(process_dir='PROC_mssm_0', grid_pack=False, gridpack_compile=False, extlhapath=None, required_accuracy=0.01, runArgs=None, bias_module=None, requirePMGSettings=False):
102 global my_MGC_instance # noqa: F824
103
104
105 # Just in case
106 setup_path_protection()
107
108 # Set consistent mode and number of jobs
109 mode = 0
110 njobs = 1
111 if 'ATHENA_CORE_NUMBER' in os.environ and int(os.environ['ATHENA_CORE_NUMBER'])>0:
112 njobs = int(os.environ['ATHENA_CORE_NUMBER'])
113 mglog.info('Lucky you - you are running on a full node queue. Will re-configure for '+str(njobs)+' jobs.')
114 mode = 2
115
116 cluster_type = get_cluster_type()
117 if cluster_type is not None:
118 mode = 1
119
120 if is_gen_from_gridpack():
121 mglog.info('Running event generation from gridpack (using smarter mode from generate() function)')
122 generate_from_gridpack(runArgs=runArgs,extlhapath=extlhapath,gridpack_compile=gridpack_compile,requirePMGSettings=requirePMGSettings)
123 return
124 else:
125 mglog.info('Did not identify an input gridpack.')
126 if grid_pack:
127 mglog.info('The grid_pack flag is set, so I am expecting to create a gridpack in this job')
128
129 # Now get a variety of info out of the runArgs
130 beamEnergy,random_seed = get_runArgs_info(runArgs)
131
132 # Check if process is NLO or LO
133 isNLO = my_MGC_instance.isNLO
134
135 # Setup PDF and systematics
136 setup_pdf_and_systematic_weights(MADGRAPH_PDFSETTING,my_MGC_instance.runCardDict,isNLO)
137
138
139 # temporary fix of makefile, needed for 3.3.1., remove in future
140 if isNLO:
141 fix_fks_makefile(process_dir=process_dir)
142
143 # if f2py not available
144 if get_reweight_card(process_dir=process_dir) is not None:
145 if shutil.which('f2py') is not None:
146 mglog.info('Found f2py, will use it for reweighting')
147 else:
148 raise RuntimeError('Could not find f2py, needed for reweighting')
149 check_reweight_card(process_dir)
150
151 global MADGRAPH_COMMAND_STACK
152
153 if grid_pack:
154 #Running in gridpack mode
155 mglog.info('Started generating gridpack at '+str(time.asctime()))
156 mglog.warning(' >>>>>> THIS KIND OF JOB SHOULD ONLY BE RUN LOCALLY - NOT IN GRID JOBS <<<<<<')
157
158 # Some events required if we specify MadSpin usage!
159 my_settings = {'nevents':'1000'}
160
161 if isNLO:
162 my_settings['req_acc']=str(required_accuracy)
163 else:
164 # At LO, no events are generated. That means we need to move the MS card aside and back.
165 LO_has_madspin = False
166 if os.access(f'{process_dir}/Cards/madspin_card.dat',os.R_OK):
167 MADGRAPH_COMMAND_STACK += [f'mv {process_dir}/Cards/madspin_card.dat {process_dir}/Cards/madspin_card.tmp.dat']
168 os.rename(f'{process_dir}/Cards/madspin_card.dat',f'{process_dir}/Cards/madspin_card.tmp.dat')
169 LO_has_madspin = True
170 my_settings = {'gridpack':'true'}
171 my_MGC_instance.runCardDict.update(my_settings)
172 else:
173 #Running in on-the-fly mode
174 mglog.info('Started generating at '+str(time.asctime()))
175
176 mglog.info('Run '+MADGRAPH_RUN_NAME+' will be performed in mode '+str(mode)+' with '+str(njobs)+' jobs in parallel.')
177
178 # Ensure that things are set up normally
179 if not os.access(process_dir,os.R_OK):
180 raise RuntimeError('No process directory found at '+process_dir)
181 if not os.access(process_dir+'/bin/generate_events',os.R_OK):
182 raise RuntimeError('No generate_events module found in '+process_dir)
183
184 mglog.info('For your information, the libraries available are (should include LHAPDF):')
185 ls_dir(process_dir+'/lib')
186
187 setupFastjet(process_dir=process_dir)
188 if bias_module is not None:
189 setup_bias_module(bias_module,process_dir)
190
191 mglog.info('Now I will hack the make files a bit. Apologies, but there seems to be no good way around this.')
192 shutil.copyfile(process_dir+'/Source/make_opts',process_dir+'/Source/make_opts_old')
193 old_opts = open(process_dir+'/Source/make_opts_old','r')
194 new_opts = open(process_dir+'/Source/make_opts','w')
195 for aline in old_opts:
196 if 'FC=g' in aline:
197 mglog.info('Configuring the fancy gfortran compiler instead of g77 / f77')
198 new_opts.write(' FC=gfortran\n')
199 else:
200 new_opts.write(aline)
201 old_opts.close()
202 new_opts.close()
203 mglog.info('Make file hacking complete.')
204
205 # Change directories
206 currdir=os.getcwd()
207 os.chdir(process_dir)
208 # Record the change
209 MADGRAPH_COMMAND_STACK += [ 'cd ${MGaMC_PROCESS_DIR}' ]
210
211 # Check the run card
212 my_MGC_instance.run_card_consistency_check()
213
214
215 # For grid packs we also need to move the systematics program aside
216 if grid_pack:
217 original_systematics_program = None if 'systematics_program' not in my_MGC_instance.runCardDict else my_MGC_instance.runCardDict['systematics_program']
218 my_MGC_instance.runCardDict['systematics_program'] = 'None'
219 mglog.info('systematics set to NONE')
220
221
222
223
224
225 # Check the param card
226 code = check_PMG_updates(process_dir=os.getcwd())
227 if requirePMGSettings and code!=0:
228 raise RuntimeError('Settings are not compliant with PMG defaults! Please use do_PMG_updates function to get PMG default params.')
229
230 # Build up the generate command
231 # Use the new-style way of passing things: just --name, everything else in config
232 command = [python,'bin/generate_events']
233 if isNLO:
234 command += ['--name='+MADGRAPH_RUN_NAME]
235 mglog.info('Removing Cards/shower_card.dat to ensure we get parton level events only')
236 try:
237 os.unlink('Cards/shower_card.dat')
238 except FileNotFoundError:
239 mglog.info('Cannot find Cards/shower_card.dat.')
240 else:
241 command += [MADGRAPH_RUN_NAME]
242 # Set the number of cores to be used
243 setNCores(process_dir=os.getcwd(), Ncores=njobs)
244 # Special handling for mode 1
245 if mode==1:
246 mglog.info('Setting up cluster running')
247 my_MGC_instance.configCardDict['run_mode'] = 1
248
249 if cluster_type=='pbs':
250 mglog.info('Modifying bin/internal/cluster.py for PBS cluster running')
251 os.system("sed -i \"s:text += prog:text += './'+prog:g\" bin/internal/cluster.py")
252 elif mode==2:
253 mglog.info('Setting up multi-core running on '+os.environ['ATHENA_CORE_NUMBER']+' cores')
254 elif mode==0:
255 mglog.info('Setting up serial generation.')
256
257 # Writing cards to disk
258 my_MGC_instance.write_configCard()
259 my_MGC_instance.write_runCard(runArgs=runArgs)
260
261 print_cards_from_dir(process_dir=my_MGC_instance.process_dir)
262
263
264 generate_prep(process_dir=os.getcwd())
265 generate = stack_subprocess(command,stdin=subprocess.PIPE, stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
266 (out,err) = generate.communicate()
267 error_check(err,generate.returncode)
268
269 # Get back to where we came from
270 os.chdir(currdir)
271 MADGRAPH_COMMAND_STACK += [ 'cd -' ]
272
273 if grid_pack:
274 # Name dictacted by https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/PmgMcSoftware
275 # MG version included for traceability (e.g. MG351 for version 3.5.1)
276 energy = '%1.1f'%(beamEnergy*2./1000.)
277 energy = energy.replace('.0','').replace('.','p')
278 gridpack_name='mc_'+energy+'TeV.'+get_physics_short()+'.MG'+get_mg5_version().replace('.','')+'.GRID.tar.gz'
279 mglog.info('Tidying up gridpack '+gridpack_name)
280
281 # Return the setting for the systematics_program
282 my_MGC_instance.runCardDict.update({'systematics_program':original_systematics_program})
283 # Write out run Card Dictionary
284 my_MGC_instance.write_runCard(runArgs=runArgs)
285
286 if not isNLO:
287 # At LO, no events are generated. That means we need to move the MS card aside and back.
288 if LO_has_madspin:
289 MADGRAPH_COMMAND_STACK += [f'mv {process_dir}/Cards/madspin_card.tmp.dat {process_dir}/Cards/madspin_card.dat']
290 os.rename(f'{process_dir}/Cards/madspin_card.tmp.dat',f'{process_dir}/Cards/madspin_card.dat')
291
292
293 MADGRAPH_COMMAND_STACK += ['cp '+glob.glob(process_dir+'/'+MADGRAPH_RUN_NAME+'_*gridpack.tar.gz')[0]+' '+gridpack_name]
294 shutil.copy(glob.glob(process_dir+'/'+MADGRAPH_RUN_NAME+'_*gridpack.tar.gz')[0],gridpack_name)
295
296 if gridpack_compile:
297 MADGRAPH_COMMAND_STACK += ['mkdir tmp%i/'%os.getpid(),'cd tmp%i/'%os.getpid()]
298 os.mkdir('tmp%i/'%os.getpid())
299 os.chdir('tmp%i/'%os.getpid())
300 mglog.info('untar gridpack')
301 untar = stack_subprocess(['tar','xvzf',('../'+gridpack_name)])
302 untar.wait()
303 mglog.info('compile and clean up')
304 MADGRAPH_COMMAND_STACK += ['cd madevent']
305 os.chdir('madevent/')
306 compilep = stack_subprocess(['./bin/compile'],stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
307 (out,err) = compilep.communicate()
308 error_check(err,compilep.returncode)
309 clean = stack_subprocess(['./bin/clean4grid'],stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
310 (out,err) = clean.communicate()
311 error_check(err,clean.returncode)
312 clean.wait()
313 MADGRAPH_COMMAND_STACK += ['cd ..','rm ../'+gridpack_name]
314 os.chdir('../')
315 mglog.info('remove old tarball')
316 os.unlink('../'+gridpack_name)
317 mglog.info('Package up new tarball')
318 tar = stack_subprocess(['tar','--exclude=SubProcesses/P*/G*/*_results.dat','--exclude=SubProcesses/P*/G*/*.log','--exclude=SubProcesses/P*/G*/*.txt','-cvsf','../'+gridpack_name,'.'])
319 tar.wait()
320 MADGRAPH_COMMAND_STACK += ['cd ..','rm -r tmp%i/'%os.getpid()]
321 os.chdir('../')
322 mglog.info('Remove temporary directory')
323 shutil.rmtree('tmp%i/'%os.getpid())
324 mglog.info('Tidying up complete!')
325
326 else:
327 my_MGC_instance.write_runCard(runArgs=runArgs)
328
329 mglog.info('Package up process_dir')
330 MADGRAPH_COMMAND_STACK += ['mv '+process_dir+' '+MADGRAPH_GRIDPACK_LOCATION]
331 os.rename(process_dir,MADGRAPH_GRIDPACK_LOCATION)
332 tar = stack_subprocess(['tar','--exclude=Events/*/*events*gz','--exclude=SubProcesses/P*/G*/log*txt','--exclude=SubProcesses/P*/G*/events.lhe*','--exclude=*/*.o','--exclude=*/*/*.o','--exclude=*/*/*/*.o','--exclude=*/*/*/*/*.o','-czf',gridpack_name,MADGRAPH_GRIDPACK_LOCATION])
333 tar.wait()
334 MADGRAPH_COMMAND_STACK += ['mv '+MADGRAPH_GRIDPACK_LOCATION+' '+process_dir]
335 os.rename(MADGRAPH_GRIDPACK_LOCATION,process_dir)
336
337 mglog.info('Gridpack sucessfully created, exiting the transform')
338 if hasattr(runArgs,'outputTXTFile'):
339 mglog.info('Touching output TXT (LHE) file for the transform')
340 open(runArgs.outputTXTFile, 'w').close()
341 from AthenaCommon.AppMgr import theApp
342 theApp.finalize()
343 theApp.exit()
344
345 mglog.info('Finished at '+str(time.asctime()))
346 return 0
347
348

◆ generate_from_gridpack()

python.MadGraphUtils.generate_from_gridpack ( runArgs = None,
extlhapath = None,
gridpack_compile = None,
requirePMGSettings = False )

Definition at line 349 of file MadGraphUtils.py.

349def generate_from_gridpack(runArgs=None, extlhapath=None, gridpack_compile=None, requirePMGSettings=False):
350 global my_MGC_instance # noqa: F824
351
352 # Get of info out of the runArgs
353 beamEnergy,random_seed = get_runArgs_info(runArgs)
354
355 # Just in case
356 setup_path_protection()
357
358 isNLO = my_MGC_instance.isNLO
359
360 setupFastjet(process_dir=MADGRAPH_GRIDPACK_LOCATION)
361
362 # This is hard-coded as a part of MG5_aMC :'(
363 gridpack_run_name = 'GridRun_'+str(random_seed)
364
365 # Ensure that we only do madspin at the end
366 if os.access(MADGRAPH_GRIDPACK_LOCATION+'/Cards/madspin_card.dat',os.R_OK):
367 os.rename(MADGRAPH_GRIDPACK_LOCATION+'/Cards/madspin_card.dat',MADGRAPH_GRIDPACK_LOCATION+'/Cards/backup_madspin_card.dat')
368 do_madspin=True
369 else:
370 do_madspin=False
371
372 if get_reweight_card(process_dir=MADGRAPH_GRIDPACK_LOCATION) is not None:
373 check_reweight_card(MADGRAPH_GRIDPACK_LOCATION)
374
375 # Check the param card
376 code = check_PMG_updates(process_dir=MADGRAPH_GRIDPACK_LOCATION)
377 if requirePMGSettings and code!=0:
378 raise RuntimeError('Settings are not compliant with PMG defaults! Please use do_PMG_updates function to get PMG default params.')
379
380 # Modify run card, then print
381 settings={'iseed':str(random_seed)}
382 if not isNLO:
383 settings['python_seed']=str(random_seed)
384 my_MGC_instance.runCardDict.update(settings)
385
386 mglog.info('Generating events from gridpack')
387
388 # Ensure that things are set up normally
389 if not os.path.exists(MADGRAPH_GRIDPACK_LOCATION):
390 raise RuntimeError('Gridpack directory not found at '+MADGRAPH_GRIDPACK_LOCATION)
391
392 nevents = my_MGC_instance.runCardDict['nevents']
393 mglog.info('>>>> FOUND GRIDPACK <<<< <- This will be used for generation')
394 mglog.info('Generation of '+str(int(nevents))+' events will be performed using the supplied gridpack with random seed '+str(random_seed))
395 mglog.info('Started generating events at '+str(time.asctime()))
396
397 #Remove addmasses if it's there
398 if os.access(MADGRAPH_GRIDPACK_LOCATION+'/bin/internal/addmasses.py',os.R_OK):
399 os.remove(MADGRAPH_GRIDPACK_LOCATION+'/bin/internal/addmasses.py')
400
401 currdir=os.getcwd()
402
403 # Make sure we've set the number of processes appropriately
404 setNCores(process_dir=MADGRAPH_GRIDPACK_LOCATION)
405
406 # Run the consistency check, print some useful info
407 ls_dir(currdir)
408 ls_dir(MADGRAPH_GRIDPACK_LOCATION)
409
410 # Update the run card according to consistency checks
411 my_MGC_instance.run_card_consistency_check()
412
413 # Now all done with updates, so print the cards with the final settings
414 print_cards_from_dir(process_dir=MADGRAPH_GRIDPACK_LOCATION)
415
416 if isNLO:
417 #turn off systematics for gridpack generation and store settings for standalone run
418 run_card_dict= my_MGC_instance.runCardDict
419 systematics_settings=None
420 if checkSetting('systematics_program','systematics',run_card_dict):
421 if not checkSettingIsTrue('store_rwgt_info',run_card_dict):
422 raise RuntimeError('Trying to run NLO systematics but reweight info not stored')
423 if checkSettingExists('systematics_arguments',run_card_dict):
424 systematics_settings=MadGraphControl.MadGraphSystematicsUtils.parse_systematics_arguments(run_card_dict['systematics_arguments'])
425 else:
426 systematics_settings={}
427 mglog.info('Turning off systematics for now, running standalone later')
428
429 my_MGC_instance.runCardDict['systematics_program'] = 'none'
430
431 # Writing run card to disk
432 my_MGC_instance.write_runCard(runArgs=runArgs)
433
434 global MADGRAPH_COMMAND_STACK
435 if not isNLO:
436
437 if not os.access(MADGRAPH_GRIDPACK_LOCATION+'/bin/gridrun',os.R_OK):
438 mglog.error('/bin/gridrun not found at '+MADGRAPH_GRIDPACK_LOCATION)
439 raise RuntimeError('Could not find gridrun executable')
440 else:
441 mglog.info('Found '+MADGRAPH_GRIDPACK_LOCATION+'/bin/gridrun, starting generation.')
442 generate_prep(MADGRAPH_GRIDPACK_LOCATION)
443 granularity=1
444 mglog.info("Now generating {} events with random seed {} and granularity {}".format(int(nevents),int(random_seed),granularity))
445 # not sure whether this is needed but it is done in the old "run.sh" script
446 new_ld_path=":".join([os.environ['LD_LIBRARY_PATH'],os.getcwd()+'/'+MADGRAPH_GRIDPACK_LOCATION+'/madevent/lib',os.getcwd()+'/'+MADGRAPH_GRIDPACK_LOCATION+'/HELAS/lib'])
447 os.environ['LD_LIBRARY_PATH']=new_ld_path
448 MADGRAPH_COMMAND_STACK+=["export LD_LIBRARY_PATH="+":".join(['${LD_LIBRARY_PATH}',new_ld_path])]
449 generate = stack_subprocess([python,MADGRAPH_GRIDPACK_LOCATION+'/bin/gridrun',str(int(nevents)),str(int(random_seed)),str(granularity)],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
450 (out,err) = generate.communicate()
451 error_check(err,generate.returncode)
452 gp_events=MADGRAPH_GRIDPACK_LOCATION+"/Events/GridRun_{}/unweighted_events.lhe.gz".format(int(random_seed))
453 if not os.path.exists(gp_events):
454 mglog.error('Error in gp generation, did not find events at '+gp_events)
455
456 # add reweighting, which is not run automatically from LO GPs
457 reweight_card=get_reweight_card(MADGRAPH_GRIDPACK_LOCATION)
458 if reweight_card is not None:
459 pythonpath_backup=os.environ['PYTHONPATH']
460 # workaround as madevent crashes when path to mg in PYTHONPATH
461 os.environ['PYTHONPATH']=':'.join([p for p in pythonpath_backup.split(':') if 'madgraph5amc' not in p])
462 add_reweighting('GridRun_{}'.format(int(random_seed)))
463 os.environ['PYTHONPATH']=pythonpath_backup
464
465 shutil.move(gp_events,'events.lhe.gz')
466
467 else:
468
469 if not os.access(MADGRAPH_GRIDPACK_LOCATION+'/bin/generate_events',os.R_OK):
470 raise RuntimeError('Could not find generate_events executable at '+MADGRAPH_GRIDPACK_LOCATION)
471 else:
472 mglog.info('Found '+MADGRAPH_GRIDPACK_LOCATION+'/bin/generate_events, starting generation.')
473
474 ls_dir(MADGRAPH_GRIDPACK_LOCATION+'/Events/')
475 if os.access(MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name, os.F_OK):
476 mglog.info('Removing '+MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+' directory from gridpack generation')
477 MADGRAPH_COMMAND_STACK += ['rm -rf '+MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name]
478 shutil.rmtree(MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name)
479
480 # Delete events generated when setting up MadSpin during gridpack generation
481 if os.access(MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'_decayed_1', os.F_OK):
482 mglog.info('Removing '+MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'_decayed_1 directory from gridpack generation')
483 MADGRAPH_COMMAND_STACK += ['rm -rf '+MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'_decayed_1']
484 shutil.rmtree(MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'_decayed_1')
485
486 ls_dir(MADGRAPH_GRIDPACK_LOCATION+'/Events/')
487
488 if not gridpack_compile:
489 mglog.info('Copying make_opts from Template')
490 shutil.copy(os.environ['MADPATH']+'/Template/LO/Source/make_opts',MADGRAPH_GRIDPACK_LOCATION+'/Source/')
491
492 generate_prep(MADGRAPH_GRIDPACK_LOCATION)
493 generate = stack_subprocess([python,MADGRAPH_GRIDPACK_LOCATION+'/bin/generate_events','--parton','--nocompile','--only_generation','-f','--name='+gridpack_run_name],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
494 (out,err) = generate.communicate()
495 error_check(err,generate.returncode)
496 else:
497 mglog.info('Allowing recompilation of gridpack')
498 if os.path.islink(MADGRAPH_GRIDPACK_LOCATION+'/lib/libLHAPDF.a'):
499 mglog.info('Unlinking '+MADGRAPH_GRIDPACK_LOCATION+'/lib/libLHAPDF.a')
500 os.unlink(MADGRAPH_GRIDPACK_LOCATION+'/lib/libLHAPDF.a')
501
502 generate_prep(MADGRAPH_GRIDPACK_LOCATION)
503 generate = stack_subprocess([python,MADGRAPH_GRIDPACK_LOCATION+'/bin/generate_events','--parton','--only_generation','-f','--name='+gridpack_run_name],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
504 (out,err) = generate.communicate()
505 error_check(err,generate.returncode)
506 if isNLO and systematics_settings is not None:
507 # run systematics
508 mglog.info('Running systematics standalone')
509 systematics_path=MADGRAPH_GRIDPACK_LOCATION+'/bin/internal/systematics.py'
510 events_location=MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'/events.lhe.gz'
511 syst_cmd=[python,systematics_path]+[events_location]*2+["--"+k+"="+systematics_settings[k] for k in systematics_settings]
512 mglog.info('running: '+' '.join(syst_cmd))
513 systematics = stack_subprocess(syst_cmd)
514 systematics.wait()
515
516
517 # See if MG5 did the job for us already
518 if not os.access('events.lhe.gz',os.R_OK):
519 mglog.info('Copying generated events to '+currdir)
520 if not os.path.exists(MADGRAPH_GRIDPACK_LOCATION+'Events/'+gridpack_run_name):
521 shutil.copy(MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'/events.lhe.gz','events.lhe.gz')
522 else:
523 mglog.info('Events were already in place')
524
525 ls_dir(currdir)
526
527 mglog.info('Moving generated events to be in correct format for arrange_output().')
528 mglog.info('Unzipping generated events.')
529 unzip = stack_subprocess(['gunzip','-f','events.lhe.gz'])
530 unzip.wait()
531
532 mglog.info('Moving file over to '+MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'/unweighted_events.lhe')
533 mkdir = stack_subprocess(['mkdir','-p',(MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name)])
534 mkdir.wait()
535 shutil.move('events.lhe',MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'/unweighted_events.lhe')
536
537 mglog.info('Re-zipping into dataset name '+MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'/unweighted_events.lhe.gz')
538 rezip = stack_subprocess(['gzip',MADGRAPH_GRIDPACK_LOCATION+'/Events/'+gridpack_run_name+'/unweighted_events.lhe'])
539 rezip.wait()
540
541 os.chdir(currdir)
542
543 # Now consider MadSpin:
544 if do_madspin:
545 # Move card back
546 os.rename(MADGRAPH_GRIDPACK_LOCATION+'/Cards/backup_madspin_card.dat',MADGRAPH_GRIDPACK_LOCATION+'/Cards/madspin_card.dat')
547 mglog.info('Decaying with MadSpin.')
548 add_madspin(process_dir=MADGRAPH_GRIDPACK_LOCATION)
549
550 mglog.info('Finished at '+str(time.asctime()))
551
552 return 0
553
554

◆ generate_prep()

python.MadGraphUtils.generate_prep ( process_dir)

Definition at line 50 of file MadGraphUtils.py.

50def generate_prep(process_dir):
51 global MADGRAPH_COMMAND_STACK
52 if not os.access('Cards_bkup',os.R_OK):
53 shutil.copytree(process_dir+'/Cards','Cards_bkup')
54 shutil.copyfile(process_dir+'/Source/make_opts','Cards_bkup/make_opts_bkup')
55 MADGRAPH_COMMAND_STACK += ['# In case this fails, Cards_bkup should be in your original run directory']
56 MADGRAPH_COMMAND_STACK += ['# And ${MGaMC_PROCESS_DIR} can be replaced with whatever process directory exists in your stand-alone test']
57 MADGRAPH_COMMAND_STACK += ['cp '+os.getcwd()+'/Cards_bkup/*dat ${MGaMC_PROCESS_DIR}/Cards/']
58 MADGRAPH_COMMAND_STACK += ['cp '+os.getcwd()+'/Cards_bkup/make_opts_bkup ${MGaMC_PROCESS_DIR}/Source/make_opts']
59 else:
60 mglog.warning('Found Cards_bkup directory existing. Suggests you are either running generation twice (a little funny) or are not using a clean directory.')
61 bkup_v = 1
62 while os.access('Cards_bkup_'+str(bkup_v),os.R_OK) and bkup_v<100:
63 bkup_v += 1
64 if bkup_v<100:
65 shutil.copytree(process_dir+'/Cards','Cards_bkup_'+str(bkup_v))
66 shutil.copyfile(process_dir+'/Source/make_opts','Cards_bkup_'+str(bkup_v)+'/make_opts_bkup')
67 MADGRAPH_COMMAND_STACK += ['# In case this fails, Cards_bkup should be in your original run directory']
68 MADGRAPH_COMMAND_STACK += ['# And ${MGaMC_PROCESS_DIR} can be replaced with whatever process directory exists in your stand-alone test']
69 MADGRAPH_COMMAND_STACK += ['cp '+os.getcwd()+'/Cards_bkup_'+str(bkup_v)+'/*dat ${MGaMC_PROCESS_DIR}/Cards/']
70 MADGRAPH_COMMAND_STACK += ['cp '+os.getcwd()+'/Cards_bkup_'+str(bkup_v)+'/make_opts_bkup ${MGaMC_PROCESS_DIR}/Source/make_opts']
71 else:
72 mglog.warning('Way too many Cards_bkup* directories found. Giving up -- standalone script may not work.')
73
74

◆ get_cluster_type()

python.MadGraphUtils.get_cluster_type ( )

Definition at line 1703 of file MadGraphUtils.py.

1703def get_cluster_type():
1704 global my_MGC_instance # noqa: F824
1705 if 'cluster_type' in my_MGC_instance.configCardDict:
1706 return my_MGC_instance.configCardDict['cluster_type']
1707 else:
1708 return None
1709
1710
1711
1712

◆ get_default_runcard()

python.MadGraphUtils.get_default_runcard ( process_dir = MADGRAPH_GRIDPACK_LOCATION)
 Copy the default runcard from one of several locations
to a local file with name run_card.tmp.dat

Definition at line 80 of file MadGraphUtils.py.

80def get_default_runcard(process_dir=MADGRAPH_GRIDPACK_LOCATION):
81 """ Copy the default runcard from one of several locations
82 to a local file with name run_card.tmp.dat"""
83 output_name = 'run_card.tmp.dat'
84
85 # Get the run card from the installation
86 run_card=process_dir+'/Cards/run_card.dat'
87 if os.access(run_card,os.R_OK):
88 mglog.info('Copying default run_card.dat from '+str(run_card))
89 shutil.copy(run_card,output_name)
90 return output_name
91 else:
92 run_card=process_dir+'/Cards/run_card_default.dat'
93 mglog.info('Fetching default run_card.dat from '+str(run_card))
94 if os.access(run_card,os.R_OK):
95 shutil.copy(run_card,output_name)
96 return output_name
97 else:
98 raise RuntimeError('Cannot find default run_card.dat or run_card_default.dat! I was looking here: %s'%run_card)
99
100

◆ get_expected_reweight_names()

python.MadGraphUtils.get_expected_reweight_names ( reweight_card_loc)

Definition at line 1218 of file MadGraphUtils.py.

1218def get_expected_reweight_names(reweight_card_loc):
1219 if reweight_card_loc is None:
1220 return []
1221 names=[]
1222 f_rw=open(reweight_card_loc)
1223 for line in f_rw:
1224 if 'launch' not in line:
1225 continue
1226 match=re.match(r'launch.*--rwgt_info\s*=\s*(\S+).*',line.strip())
1227 if len(match.groups())!=1:
1228 raise RuntimeError('Unexpected format of reweight card in line'+line)
1229 else:
1230 names+=[match.group(1)]
1231 f_rw.close()
1232 return names
1233

◆ get_expected_systematic_names()

python.MadGraphUtils.get_expected_systematic_names ( syst_setting)

Definition at line 1234 of file MadGraphUtils.py.

1234def get_expected_systematic_names(syst_setting):
1235 names=[]
1236 if syst_setting is None or 'central_pdf' not in syst_setting:
1237 mglog.warning("Systematics have not been defined via base fragment or 'MADGRAPH_PDFSETTING', cannot check for expected weights")
1238 return []
1239 if 'pdf_variations' in syst_setting and isinstance(syst_setting['pdf_variations'],list):
1240 names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':1.0,'muf':1.0,'pdf':syst_setting['central_pdf']}]
1241 for pdf in syst_setting['pdf_variations']:
1242 names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':1.0,'muf':1.0,'pdf':pdf+1}]
1243 if 'alternative_pdfs' in syst_setting and isinstance(syst_setting['alternative_pdfs'],list):
1244 for pdf in syst_setting['alternative_pdfs']:
1245 names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':1.0,'muf':1.0,'pdf':pdf}]
1246 if 'scale_variations' in syst_setting and isinstance(syst_setting['scale_variations'],list):
1247 for mur in syst_setting['scale_variations']:
1248 for muf in syst_setting['scale_variations']:
1249 names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':mur,'muf':muf,'pdf':syst_setting['central_pdf']}]
1250 return names
1251

◆ get_mg5_executable()

python.MadGraphUtils.get_mg5_executable ( )

Definition at line 753 of file MadGraphUtils.py.

753def get_mg5_executable():
754 madpath=os.environ['MADPATH']
755 if not os.access(madpath+'/bin/mg5_aMC',os.R_OK):
756 raise RuntimeError('mg5_aMC executable not found in '+madpath)
757 return madpath+'/bin/mg5_aMC'
758
759

◆ get_reweight_card()

python.MadGraphUtils.get_reweight_card ( process_dir = MADGRAPH_GRIDPACK_LOCATION)

Definition at line 1302 of file MadGraphUtils.py.

1302def get_reweight_card(process_dir=MADGRAPH_GRIDPACK_LOCATION):
1303 if os.access(process_dir+'/Cards/reweight_card.dat',os.R_OK):
1304 return process_dir+'/Cards/reweight_card.dat'
1305 return None
1306
1307

◆ is_gen_from_gridpack()

python.MadGraphUtils.is_gen_from_gridpack ( )
 Simple function for checking if there is a grid pack.
Relies on the specific location of the unpacked gridpack (madevent)
which is here set as a global variable. The gridpack is untarred by
the transform (Gen_tf.py) and no sign is sent to the job itself
that there is a gridpack in use except the file's existence

Definition at line 1502 of file MadGraphUtils.py.

1502def is_gen_from_gridpack():
1503 """ Simple function for checking if there is a grid pack.
1504 Relies on the specific location of the unpacked gridpack (madevent)
1505 which is here set as a global variable. The gridpack is untarred by
1506 the transform (Gen_tf.py) and no sign is sent to the job itself
1507 that there is a gridpack in use except the file's existence"""
1508 if os.access(MADGRAPH_GRIDPACK_LOCATION,os.R_OK):
1509 mglog.info('Located input grid pack area')
1510 return True
1511 return False
1512
1513
1514

◆ ls_dir()

python.MadGraphUtils.ls_dir ( directory)

Definition at line 1727 of file MadGraphUtils.py.

1727def ls_dir(directory):
1728 mglog.info('For your information, ls of '+directory+':')
1729 mglog.info( sorted( os.listdir( directory ) ) )
1730
1731# Final import of some code used in these functions

◆ madspin_on_lhe()

python.MadGraphUtils.madspin_on_lhe ( input_LHE,
madspin_card,
runArgs = None,
keep_original = False )
 Run MadSpin on an input LHE file. Takes the process
from the LHE file, so you don't need to have a process directory
set up in advance. Runs MadSpin and packs the LHE file up appropriately
Needs runArgs for the file handling

Definition at line 855 of file MadGraphUtils.py.

855def madspin_on_lhe(input_LHE,madspin_card,runArgs=None,keep_original=False):
856 """ Run MadSpin on an input LHE file. Takes the process
857 from the LHE file, so you don't need to have a process directory
858 set up in advance. Runs MadSpin and packs the LHE file up appropriately
859 Needs runArgs for the file handling"""
860 if not os.access(input_LHE,os.R_OK):
861 raise RuntimeError('Could not find LHE file '+input_LHE)
862 if not os.access(madspin_card,os.R_OK):
863 raise RuntimeError('Could not find input MadSpin card '+madspin_card)
864 if keep_original:
865 shutil.copy(input_LHE,input_LHE+'.original')
866 mglog.info('Put backup copy of LHE file at '+input_LHE+'.original')
867 # Start writing the card for execution
868 madspin_exec_card = open('madspin_exec_card','w')
869 madspin_exec_card.write('import '+input_LHE+'\n')
870 # Based on the original card
871 input_madspin_card = open(madspin_card,'r')
872 has_launch = False
873 for l in input_madspin_card.readlines():
874 commands = l.split('#')[0].split()
875 # Skip import of a file name that isn't our file
876 if len(commands)>1 and 'import'==commands[0] and not 'model'==commands[1]:
877 continue
878 # Check for a launch command
879 if len(commands)>0 and 'launch' == commands[0]:
880 has_launch = True
881 madspin_exec_card.write(l.strip()+'\n')
882 if not has_launch:
883 madspin_exec_card.write('launch\n')
884 madspin_exec_card.close()
885 input_madspin_card.close()
886 # Now get the madspin executable
887 madpath=os.environ['MADPATH']
888 if not os.access(madpath+'/MadSpin/madspin',os.R_OK):
889 raise RuntimeError('madspin executable not found in '+madpath)
890 mglog.info('Starting madspin at '+str(time.asctime()))
891 generate = stack_subprocess([python,madpath+'/MadSpin/madspin','madspin_exec_card'],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
892 (out,err) = generate.communicate()
893 error_check(err,generate.returncode)
894 mglog.info('Done with madspin at '+str(time.asctime()))
895 # Should now have a re-zipped LHE file
896 # We now have to do a shortened version of arrange_output below
897 # Clean up in case a link or file was already there
898 if os.path.exists(os.getcwd()+'/events.lhe'):
899 os.remove(os.getcwd()+'/events.lhe')
900
901 mglog.info('Unzipping generated events.')
902 unzip = stack_subprocess(['gunzip','-f',input_LHE+'.gz'])
903 unzip.wait()
904
905 mglog.info('Putting a copy in place for the transform.')
906 mod_output = open(os.getcwd()+'/events.lhe','w')
907
908 #Removing empty lines in LHE
909 nEmpty=0
910 with open(input_LHE,'r') as fileobject:
911 for line in fileobject:
912 if line.strip():
913 mod_output.write(line)
914 else:
915 nEmpty=nEmpty+1
916 mod_output.close()
917
918 mglog.info('Removed '+str(nEmpty)+' empty lines from LHEF')
919
920 # Actually move over the dataset - this first part is horrible...
921 if runArgs is None:
922 raise RuntimeError('Must provide runArgs to madspin_on_lhe')
923
924 outputDS = runArgs.outputTXTFile if hasattr(runArgs,'outputTXTFile') else 'tmp_LHE_events.tar.gz'
925
926 mglog.info('Moving file over to '+outputDS.split('.tar.gz')[0]+'.events')
927 shutil.move(os.getcwd()+'/events.lhe',outputDS.split('.tar.gz')[0]+'.events')
928
929 mglog.info('Re-zipping into dataset name '+outputDS)
930 rezip = stack_subprocess(['tar','cvzf',outputDS,outputDS.split('.tar.gz')[0]+'.events'])
931 rezip.wait()
932
933 # shortening the outputDS in the case of an output TXT file
934 if hasattr(runArgs,'outputTXTFile') and runArgs.outputTXTFile is not None:
935 outputDS = outputDS.split('.TXT')[0]
936 # Do some fixing up for them
937 if runArgs is not None:
938 mglog.debug('Setting inputGenerator file to '+outputDS)
939 runArgs.inputGeneratorFile=outputDS
940
941

◆ modify_config_card()

python.MadGraphUtils.modify_config_card ( config_card_backup = None,
process_dir = MADGRAPH_GRIDPACK_LOCATION,
settings = {},
set_commented = True )
Build a new configuration from an existing one.
This function can get a fresh runcard from DATAPATH or start from the process directory.
Settings is a dictionary of keys (no spaces needed) and values to replace.

Definition at line 1643 of file MadGraphUtils.py.

1643def modify_config_card(config_card_backup=None,process_dir=MADGRAPH_GRIDPACK_LOCATION,settings={},set_commented=True):
1644 """Build a new configuration from an existing one.
1645 This function can get a fresh runcard from DATAPATH or start from the process directory.
1646 Settings is a dictionary of keys (no spaces needed) and values to replace.
1647 """
1648 global my_MGC_instance # noqa: F824
1649
1650 my_MGC_instance.configCardDict.update(settings)
1651 # Check for the default config card location
1652 config_card = my_MGC_instance.config_path
1653
1654 # The format is similar to the run card, but backwards
1655 mglog.info('Modifying config card located at '+config_card)
1656 if config_card_backup is not None:
1657 mglog.info('Keeping backup of original config card at '+config_card_backup)
1658 config_card_old = config_card_backup
1659 else:
1660 config_card_old = config_card+'.old_to_be_deleted'
1661 mglog.debug('Modifying config card settings: '+str(settings))
1662 if os.path.isfile(config_card_old):
1663 os.unlink(config_card_old) # delete old backup
1664 os.rename(config_card, config_card_old) # change name of original card
1665
1666 oldCard = open(config_card_old, 'r')
1667 newCard = open(config_card, 'w')
1668 used_settings = []
1669 for line in iter(oldCard):
1670 lmod = line if set_commented else line.split('#')[0]
1671 if '=' in lmod:
1672 modified = False
1673 for setting in settings:
1674 if setting not in lmod:
1675 continue
1676 # Assume we hit
1677 mglog.info('Setting '+setting.strip()+' to '+str(settings[setting]))
1678 newCard.write(' '+str(setting.strip())+' = '+str(settings[setting])+'\n')
1679 used_settings += [ setting.strip() ]
1680 modified = True
1681 break
1682 if modified:
1683 continue
1684 newCard.write(line)
1685
1686 # Clean up unused options
1687 for asetting in settings:
1688 if asetting in used_settings:
1689 continue
1690 if settings[asetting] is None:
1691 continue
1692 mglog.warning('Option '+asetting+' was not in the default config card. Adding by hand a setting to '+str(settings[asetting]) )
1693 newCard.write(' '+str(asetting)+' = '+str(settings[asetting])+'\n')
1694 # close files
1695 oldCard.close()
1696 newCard.close()
1697 mglog.info('Finished modification of config card.')
1698 if config_card_backup is None:
1699 os.unlink(config_card_old)
1700
1701
1702

◆ modify_run_card()

python.MadGraphUtils.modify_run_card ( run_card_input = None,
run_card_backup = None,
process_dir = MADGRAPH_GRIDPACK_LOCATION,
runArgs = None,
settings = {},
skipBaseFragment = False )
Build a new run_card.dat from an existing one.
This function can get a fresh runcard from DATAPATH or start from the process directory.
Settings is a dictionary of keys (no spaces needed) and values to replace.

Definition at line 1515 of file MadGraphUtils.py.

1515def modify_run_card(run_card_input=None,run_card_backup=None,process_dir=MADGRAPH_GRIDPACK_LOCATION,runArgs=None,settings={},skipBaseFragment=False):
1516 """Build a new run_card.dat from an existing one.
1517 This function can get a fresh runcard from DATAPATH or start from the process directory.
1518 Settings is a dictionary of keys (no spaces needed) and values to replace.
1519 """
1520
1521 global my_MGC_instance # noqa: F824
1522 # my_MGC_instance.getRunCardDict(card_loc=process_dir+'/Cards/run_card.dat')
1523 my_MGC_instance.runCardDict.update(settings)
1524 # my_MGC_instance.write_runCard()
1525
1526 # Operate on lower case settings, and choose the capitalization MG5 has as the default (or all lower case)
1527 settings_lower = {}
1528 for s in list(settings.keys()):
1529 settings_lower[s.lower()] = settings[s]
1530
1531 # Check for the default run card location
1532 if run_card_input is None:
1533 run_card_input=get_default_runcard(process_dir)
1534 elif run_card_input is not None and not os.access(run_card_input,os.R_OK):
1535 runcard = subprocess.Popen(['get_files','-data',run_card_input])
1536 runcard.wait()
1537 if not os.access(run_card_input,os.R_OK):
1538 raise RuntimeError('Could not get run card '+run_card_input)
1539
1540 # guess NLO
1541 isNLO = my_MGC_instance.isNLO
1542 # add gobal PDF and scale uncertainty config to extras, except PDF or weights for syscal config are explictly set
1543 if not skipBaseFragment:
1544 setup_pdf_and_systematic_weights(MADGRAPH_PDFSETTING,settings_lower,isNLO)
1545
1546 # Get some info out of the runArgs
1547 if runArgs is not None:
1548 beamEnergy,rand_seed = get_runArgs_info(runArgs)
1549 if 'iseed' not in settings_lower:
1550 settings_lower['iseed']=rand_seed
1551 if not isNLO and 'python_seed' not in settings_lower:
1552 settings_lower['python_seed']=rand_seed
1553 if 'beamenergy' in settings_lower:
1554 mglog.warning('Do not set beam energy in MG settings. The variables are ebeam1 and ebeam2. Will use your setting of '+str(settings_lower['beamenergy']))
1555 beamEnergy=settings_lower['beamenergy']
1556 settings_lower.pop('beamenergy')
1557 if 'ebeam1' not in settings_lower:
1558 settings_lower['ebeam1']=beamEnergy
1559 if 'ebeam2' not in settings_lower:
1560 settings_lower['ebeam2']=beamEnergy
1561 # Make sure nevents is an integer
1562 if 'nevents' in settings_lower:
1563 settings_lower['nevents'] = int(settings_lower['nevents'])
1564
1565 # Normalise custom_fcts early so the rewritten run_card uses the full path
1566 if 'custom_fcts' in settings_lower and settings_lower['custom_fcts']:
1567 raw_name = str(settings_lower['custom_fcts']).split()[0]
1568 # Determine jobConfig directory
1569 if runArgs is not None and hasattr(runArgs, 'jobConfig'):
1570 cfgdir = runArgs.jobConfig[0] if isinstance(runArgs.jobConfig, (list, tuple)) else runArgs.jobConfig
1571 # Build full path and make absolute
1572 full_path = os.path.join(cfgdir, raw_name)
1573 settings_lower['custom_fcts'] = os.path.abspath(full_path)
1574 print(f"Using custom function(s), specified in custom_fcts with path: {settings_lower['custom_fcts']}")
1575 else:
1576 # For internal tests, where jobConfig is not set
1577 settings_lower['custom_fcts'] = os.path.abspath(raw_name)
1578
1579 mglog.info('Modifying run card located at '+run_card_input)
1580 if run_card_backup is not None:
1581 mglog.info('Keeping backup of original run card at '+run_card_backup)
1582 run_card_old = run_card_backup
1583 else:
1584 run_card_old = run_card_input+'.old_to_be_deleted'
1585 mglog.debug('Modifying runcard settings: '+str(settings_lower))
1586 if os.path.isfile(run_card_old):
1587 os.unlink(run_card_old) # delete old backup
1588 os.rename(run_card_input, run_card_old) # change name of original card
1589
1590 oldCard = open(run_card_old, 'r')
1591 newCard = open(process_dir+'/Cards/run_card.dat', 'w')
1592 used_settings = []
1593 for line in iter(oldCard):
1594 if not line.strip().startswith('#'): # line commented out
1595 command = line.split('!', 1)[0]
1596 comment = line.split('!', 1)[1] if '!' in line else ''
1597 if '=' in command:
1598 setting = command.split('=')[-1] #.strip()
1599 stripped_setting = setting.strip()
1600 oldValue = '='.join(command.split('=')[:-1])
1601 if stripped_setting.lower() in settings_lower:
1602 # if setting set to 'None' it will be removed from run_card
1603 if settings_lower[stripped_setting.lower()] is None:
1604 line=''
1605 mglog.info('Removing '+stripped_setting+'.')
1606 used_settings += [ stripped_setting.lower() ]
1607 else:
1608 if stripped_setting.lower() == 'custom_fcts':
1609 # Overwrite completely to avoid duplicating in custom_fcts, else MadGraph will crash
1610 line = ' '+str(settings_lower[stripped_setting.lower()])+' = '+setting
1611 if comment != '':
1612 line += ' !'+comment
1613 else:
1614 line = oldValue.replace(oldValue.strip(), str(settings_lower[stripped_setting.lower()]))+'='+setting
1615 if comment != '':
1616 line += ' !' + comment
1617 mglog.info('Setting '+stripped_setting+' = '+str(settings_lower[stripped_setting.lower()]))
1618 used_settings += [ stripped_setting.lower() ]
1619 newCard.write(line.strip()+'\n')
1620
1621 # Check whether mcatnlo_delta is applied to setup pythia8 path
1622 if 'mcatnlo_delta' in settings_lower:
1623 if settings_lower['mcatnlo_delta'] == 'True':
1624 modify_config_card(process_dir=process_dir,settings={'pythia8_path':os.getenv("PY8PATH")})
1625
1626
1627 # Clean up unused options
1628 for asetting in settings_lower:
1629 if asetting in used_settings:
1630 continue
1631 if settings_lower[asetting] is None:
1632 continue
1633 mglog.info('Option '+asetting+' was not in the default run_card (normal for hidden options). Adding by hand a setting to '+str(settings_lower[asetting]) )
1634 newCard.write( ' '+str(settings_lower[asetting])+' = '+str(asetting)+'\n')
1635 # close files
1636 oldCard.close()
1637 newCard.close()
1638 mglog.info('Finished modification of run card.')
1639 if run_card_backup is None:
1640 os.unlink(run_card_old)
1641
1642
void print(char *figname, TCanvas *c1)

◆ new_process()

python.MadGraphUtils.new_process ( process = 'generate p p > t t~\noutput -f',
plugin = None,
keepJpegs = False,
usePMGSettings = False )

Definition at line 75 of file MadGraphUtils.py.

75def new_process(process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False):
76 global my_MGC_instance
77 my_MGC_instance = MGControl(process, plugin, keepJpegs, usePMGSettings)
78 return my_MGC_instance.process_dir
79

◆ print_cards()

python.MadGraphUtils.print_cards ( proc_card = 'proc_card_mg5.dat',
run_card = None,
param_card = None,
madspin_card = None,
reweight_card = None,
warn_on_missing = True )

Definition at line 1457 of file MadGraphUtils.py.

1457def print_cards(proc_card='proc_card_mg5.dat',run_card=None,param_card=None,madspin_card=None,reweight_card=None,warn_on_missing=True):
1458 if os.access(proc_card,os.R_OK):
1459 mglog.info("proc_card:")
1460 procCard = subprocess.Popen(['cat',proc_card])
1461 procCard.wait()
1462 elif warn_on_missing:
1463 mglog.warning('No proc_card: '+proc_card+' found')
1464
1465 if run_card is not None and os.access(run_card,os.R_OK):
1466 mglog.info("run_card:")
1467 runCard = subprocess.Popen(['cat',run_card])
1468 runCard.wait()
1469 elif run_card is not None and warn_on_missing:
1470 mglog.warning('No run_card: '+run_card+' found')
1471 else:
1472 mglog.info('Default run card in use')
1473
1474 if param_card is not None and os.access(param_card,os.R_OK):
1475 mglog.info("param_card:")
1476 paramCard = subprocess.Popen(['cat',param_card])
1477 paramCard.wait()
1478 elif param_card is not None and warn_on_missing:
1479 mglog.warning('No param_card: '+param_card+' found')
1480 else:
1481 mglog.info('Default param card in use')
1482
1483 if madspin_card is not None and os.access(madspin_card,os.R_OK):
1484 mglog.info("madspin_card:")
1485 madspinCard = subprocess.Popen(['cat',madspin_card])
1486 madspinCard.wait()
1487 elif madspin_card is not None and warn_on_missing:
1488 mglog.warning('No madspin_card: '+madspin_card+' found')
1489 else:
1490 mglog.info('No madspin card in use')
1491
1492 if reweight_card is not None and os.access(reweight_card,os.R_OK):
1493 mglog.info("reweight_card:")
1494 madspinCard = subprocess.Popen(['cat',reweight_card])
1495 madspinCard.wait()
1496 elif reweight_card is not None and warn_on_missing:
1497 mglog.warning('No reweight_card: '+reweight_card+' found')
1498 else:
1499 mglog.info('No reweight card in use')
1500
1501

◆ print_cards_from_dir()

python.MadGraphUtils.print_cards_from_dir ( process_dir = MADGRAPH_GRIDPACK_LOCATION)

Definition at line 1451 of file MadGraphUtils.py.

1451def print_cards_from_dir(process_dir=MADGRAPH_GRIDPACK_LOCATION):
1452 card_dir=process_dir+'/Cards/'
1453 print_cards(proc_card=card_dir+'proc_card_mg5.dat',run_card=card_dir+'run_card.dat',param_card=card_dir+'param_card.dat',\
1454 madspin_card=card_dir+'madspin_card.dat',reweight_card=card_dir+'reweight_card.dat',warn_on_missing=False)
1455
1456

◆ setNCores()

python.MadGraphUtils.setNCores ( process_dir,
Ncores = None )

Definition at line 735 of file MadGraphUtils.py.

735def setNCores(process_dir, Ncores=None):
736 global my_MGC_instance # noqa: F824
737
738 my_Ncores = Ncores
739 my_runMode = 2 if 'ATHENA_CORE_NUMBER' in os.environ else 0
740 if Ncores is None and 'ATHENA_CORE_NUMBER' in os.environ and int(os.environ['ATHENA_CORE_NUMBER'])>0:
741 my_Ncores = int(os.environ['ATHENA_CORE_NUMBER'])
742 my_runMode = 2
743 if my_Ncores is None:
744 mglog.info('Setting up for serial run')
745 my_Ncores = 1
746 my_MGC_instance.configCardDict.update({'nb_core':my_Ncores,'run_mode':my_runMode,'automatic_html_opening':'False'})
747
748
749
750
751
752

◆ setup_bias_module()

python.MadGraphUtils.setup_bias_module ( bias_module,
process_dir )

Definition at line 1252 of file MadGraphUtils.py.

1252def setup_bias_module(bias_module,process_dir):
1253 run_card = process_dir+'/Cards/run_card.dat'
1254 if isinstance(bias_module,tuple):
1255 mglog.info('Using bias module '+bias_module[0])
1256 the_run_card = open(run_card,'r')
1257 for line in the_run_card:
1258 if 'bias_module' in line and not bias_module[0] in line:
1259 raise RuntimeError('You need to add the bias module '+bias_module[0]+' to the run card to actually run it')
1260 the_run_card.close()
1261 if len(bias_module)!=3:
1262 raise RuntimeError('Please give a 3-tuple of strings containing bias module name, bias module, and makefile. Alternatively, give path to bias module tarball.')
1263 bias_module_newpath=process_dir+'/Source/BIAS/'+bias_module[0]
1264 os.makedirs(bias_module_newpath)
1265 bias_module_file=open(bias_module_newpath+'/'+bias_module[0]+'.f','w')
1266 bias_module_file.write(bias_module[1])
1267 bias_module_file.close()
1268 bias_module_make_file=open(bias_module_newpath+'/Makefile','w')
1269 bias_module_make_file.write(bias_module[2])
1270 bias_module_make_file.close()
1271 else:
1272 mglog.info('Using bias module '+bias_module)
1273 bias_module_name=bias_module.split('/')[-1].replace('.gz','')
1274 bias_module_name=bias_module_name.replace('.tar','')
1275 the_run_card = open(run_card,'r')
1276 for line in the_run_card:
1277 if 'bias_module' in line and bias_module_name not in line:
1278 raise RuntimeError('You need to add the bias module '+bias_module_name+' to the run card to actually run it')
1279 the_run_card.close()
1280
1281 if os.path.exists(bias_module+'.tar.gz'):
1282 bias_module_path=bias_module+'.tar.gz'
1283 elif os.path.exists(bias_module+'.gz'):
1284 bias_module_path=bias_module+'.gz'
1285 elif os.path.exists(bias_module):
1286 bias_module_path=bias_module
1287 else:
1288 mglog.error('Did not find bias module '+bias_module+' , this path should point to folder or tarball. Alternatively give a tuple of strings containing module name, module, and makefile')
1289 return 1
1290 bias_module_newpath=process_dir+'/Source/BIAS/'+bias_module_path.split('/')[-1]
1291 mglog.info('Copying bias module into place: '+bias_module_newpath)
1292 shutil.copy(bias_module_path,bias_module_newpath)
1293 mglog.info('Unpacking bias module')
1294 if bias_module_newpath.endswith('.tar.gz'):
1295 untar = stack_subprocess(['tar','xvzf',bias_module_newpath,'--directory='+process_dir+'/Source/BIAS/'])
1296 untar.wait()
1297 elif bias_module_path.endswith('.gz'):
1298 gunzip = stack_subprocess(['gunzip',bias_module_newpath])
1299 gunzip.wait()
1300
1301

◆ setupFastjet()

python.MadGraphUtils.setupFastjet ( process_dir = None)

Definition at line 555 of file MadGraphUtils.py.

555def setupFastjet(process_dir=None):
556 global my_MGC_instance # noqa: F824
557
558 isNLO = my_MGC_instance.isNLO
559
560 mglog.info('Path to fastjet install dir: '+os.environ['FASTJETPATH'])
561 fastjetconfig = os.environ['FASTJETPATH']+'/bin/fastjet-config'
562
563 mglog.info('fastjet-config --version: '+str(subprocess.Popen([fastjetconfig, '--version'],stdout = subprocess.PIPE).stdout.read().strip()))
564 mglog.info('fastjet-config --prefix: '+str(subprocess.Popen([fastjetconfig, '--prefix'],stdout = subprocess.PIPE).stdout.read().strip()))
565
566 if not isNLO:
567 config_card=process_dir+'/Cards/me5_configuration.txt'
568 else:
569 config_card=process_dir+'/Cards/amcatnlo_configuration.txt'
570
571 oldcard = open(config_card,'r')
572 newcard = open(config_card+'.tmp','w')
573
574 for line in oldcard:
575 if 'fastjet = ' in line:
576 newcard.write('fastjet = '+fastjetconfig+'\n')
577 mglog.info('Setting fastjet = '+fastjetconfig+' in '+config_card)
578 else:
579 newcard.write(line)
580 oldcard.close()
581 newcard.close()
582 shutil.move(config_card+'.tmp',config_card)
583
584 return
585
586
587

◆ setupLHAPDF()

python.MadGraphUtils.setupLHAPDF ( process_dir = None,
extlhapath = None,
allow_links = True )

Definition at line 588 of file MadGraphUtils.py.

588def setupLHAPDF(process_dir=None, extlhapath=None, allow_links=True):
589 global my_MGC_instance # noqa: F824
590
591 isNLO = my_MGC_instance.isNLO
592
593 origLHAPATH=os.environ['LHAPATH']
594 origLHAPDF_DATA_PATH=os.environ['LHAPDF_DATA_PATH']
595
596 LHAPATH,LHADATAPATH=get_LHAPDF_PATHS()
597
598 pdfname=''
599 pdfid=-999
600
601
602 mydict= my_MGC_instance.runCardDict
603 if mydict["pdlabel"].replace("'","") == 'lhapdf':
604 #Make local LHAPDF dir
605 mglog.info('creating local LHAPDF dir: MGC_LHAPDF/')
606 if os.path.islink('MGC_LHAPDF/'):
607 os.unlink('MGC_LHAPDF/')
608 elif os.path.isdir('MGC_LHAPDF/'):
609 shutil.rmtree('MGC_LHAPDF/')
610
611 newMGCLHA='MGC_LHAPDF/'
612
613 mkdir = subprocess.Popen(['mkdir','-p',newMGCLHA])
614 mkdir.wait()
615
616 pdfs_used=[ int(x) for x in mydict['lhaid'].replace(' ',',').split(',') ]
617 # included systematics pdfs here
618 if 'sys_pdf' in mydict:
619 sys_pdf=mydict['sys_pdf'].replace('&&',' ').split()
620 for s in sys_pdf:
621 if s.isdigit():
622 idx=int(s)
623 if idx>1000: # the sys_pdf syntax is such that small numbers are used to specify the subpdf index
624 pdfs_used.append(idx)
625 else:
626 pdfs_used.append(s)
627 if 'systematics_arguments' in mydict:
628 systematics_arguments=MadGraphControl.MadGraphSystematicsUtils.parse_systematics_arguments(mydict['systematics_arguments'])
629 if 'pdf' in systematics_arguments:
630 sys_pdf=systematics_arguments['pdf'].replace(',',' ').replace('@',' ').split()
631 for s in sys_pdf:
632 if s.isdigit():
633 idx=int(s)
634 if idx>1000: # the sys_pdf syntax is such that small numbers are used to specify the subpdf index
635 pdfs_used.append(idx)
636 else:
637 pdfs_used.append(s)
638 for pdf in pdfs_used:
639 if isinstance(pdf,str) and (pdf.lower()=='errorset' or pdf.lower()=='central'):
640 continue
641 # new function to get both lhapdf id and name
642 pdfid,pdfname=get_lhapdf_id_and_name(pdf)
643 mglog.info("Found LHAPDF ID="+str(pdfid)+", name="+pdfname)
644
645 if not os.path.exists(newMGCLHA+pdfname) and not os.path.lexists(newMGCLHA+pdfname):
646 if not os.path.exists(LHADATAPATH+'/'+pdfname):
647 mglog.warning('PDF not installed at '+LHADATAPATH+'/'+pdfname)
648 if allow_links:
649 mglog.info('linking '+LHADATAPATH+'/'+pdfname+' --> '+newMGCLHA+pdfname)
650 os.symlink(LHADATAPATH+'/'+pdfname,newMGCLHA+pdfname)
651 else:
652 mglog.info('copying '+LHADATAPATH+'/'+pdfname+' --> '+newMGCLHA+pdfname)
653 shutil.copytree(LHADATAPATH+'/'+pdfname,newMGCLHA+pdfname)
654
655 if allow_links:
656 mglog.info('linking '+LHADATAPATH+'/pdfsets.index --> '+newMGCLHA+'pdfsets.index')
657 os.symlink(LHADATAPATH+'/pdfsets.index',newMGCLHA+'pdfsets.index')
658
659 atlasLHADATAPATH=LHADATAPATH.replace('sft.cern.ch/lcg/external/lhapdfsets/current','atlas.cern.ch/repo/sw/Generators/lhapdfsets/current')
660 mglog.info('linking '+atlasLHADATAPATH+'/lhapdf.conf --> '+newMGCLHA+'lhapdf.conf')
661 os.symlink(atlasLHADATAPATH+'/lhapdf.conf',newMGCLHA+'lhapdf.conf')
662 else:
663 mglog.info('copying '+LHADATAPATH+'/pdfsets.index --> '+newMGCLHA+'pdfsets.index')
664 shutil.copy2(LHADATAPATH+'/pdfsets.index',newMGCLHA+'pdfsets.index')
665
666 atlasLHADATAPATH=LHADATAPATH.replace('sft.cern.ch/lcg/external/lhapdfsets/current','atlas.cern.ch/repo/sw/Generators/lhapdfsets/current')
667 mglog.info('copying '+atlasLHADATAPATH+'/lhapdf.conf -->'+newMGCLHA+'lhapdf.conf')
668 shutil.copy2(atlasLHADATAPATH+'/lhapdf.conf',newMGCLHA+'lhapdf.conf')
669
670
671 LHADATAPATH=os.getcwd()+'/MGC_LHAPDF'
672
673 else:
674 mglog.info('Not using LHAPDF')
675 return (LHAPATH,origLHAPATH,origLHAPDF_DATA_PATH)
676
677
678 if isNLO:
679 os.environ['LHAPDF_DATA_PATH']=LHADATAPATH
680
681 mglog.info('Path to LHAPDF install dir: '+LHAPATH)
682 mglog.info('Path to LHAPDF data dir: '+LHADATAPATH)
683 if not os.path.isdir(LHADATAPATH):
684 raise RuntimeError('LHAPDF data dir not accesible: '+LHADATAPATH)
685 if not os.path.isdir(LHAPATH):
686 raise RuntimeError('LHAPDF path dir not accesible: '+LHAPATH)
687
688 # Dealing with LHAPDF
689 if extlhapath:
690 lhapdfconfig=extlhapath
691 if not os.access(lhapdfconfig,os.X_OK):
692 raise RuntimeError('Failed to find valid external lhapdf-config at '+lhapdfconfig)
693 LHADATAPATH=subprocess.Popen([lhapdfconfig, '--datadir'],stdout = subprocess.PIPE).stdout.read().strip()
694 mglog.info('Changing LHAPDF_DATA_PATH to '+LHADATAPATH)
695 os.environ['LHAPDF_DATA_PATH']=LHADATAPATH
696 else:
697 getlhaconfig = subprocess.Popen(['get_files','-data','lhapdf-config'])
698 getlhaconfig.wait()
699 #Get custom lhapdf-config
700 if not os.access(os.getcwd()+'/lhapdf-config',os.X_OK):
701 mglog.error('Failed to get lhapdf-config from MadGraphControl')
702 return 1
703 lhapdfconfig = os.getcwd()+'/lhapdf-config'
704
705 mglog.info('lhapdf-config --version: '+str(subprocess.Popen([lhapdfconfig, '--version'],stdout = subprocess.PIPE).stdout.read().strip()))
706 mglog.info('lhapdf-config --prefix: '+str(subprocess.Popen([lhapdfconfig, '--prefix'],stdout = subprocess.PIPE).stdout.read().strip()))
707 mglog.info('lhapdf-config --libdir: '+str(subprocess.Popen([lhapdfconfig, '--libdir'],stdout = subprocess.PIPE).stdout.read().strip()))
708 mglog.info('lhapdf-config --datadir: '+str(subprocess.Popen([lhapdfconfig, '--datadir'],stdout = subprocess.PIPE).stdout.read().strip()))
709 mglog.info('lhapdf-config --pdfsets-path: '+str(subprocess.Popen([lhapdfconfig, '--pdfsets-path'],stdout = subprocess.PIPE).stdout.read().strip()))
710
711
712 my_MGC_instance.configCardDict.update({'lhapdf':lhapdfconfig,'lhapdf_py3':lhapdfconfig})
713
714 mglog.info('Creating links for LHAPDF')
715 if os.path.islink(process_dir+'/lib/PDFsets'):
716 os.unlink(process_dir+'/lib/PDFsets')
717 elif os.path.isdir(process_dir+'/lib/PDFsets'):
718 shutil.rmtree(process_dir+'/lib/PDFsets')
719 if allow_links:
720 os.symlink(LHADATAPATH,process_dir+'/lib/PDFsets')
721 else:
722 shutil.copytree(LHADATAPATH,process_dir+'/lib/PDFsets')
723 mglog.info('Available PDFs are:')
724 mglog.info( sorted( [ x for x in os.listdir(process_dir+'/lib/PDFsets') if ".tar.gz" not in x ] ) )
725
726 global MADGRAPH_COMMAND_STACK
727 MADGRAPH_COMMAND_STACK += [ '# Copy the LHAPDF files locally' ]
728 MADGRAPH_COMMAND_STACK += [ 'cp -r '+os.getcwd()+'/MGC_LHAPDF .' ]
729 MADGRAPH_COMMAND_STACK += [ 'cp -r '+process_dir+'/lib/PDFsets ${MGaMC_PROCESS_DIR}/lib/' ]
730
731 return (LHAPATH,origLHAPATH,origLHAPDF_DATA_PATH)
732
733
734# Function to set the number of cores and the running mode in the run card

◆ stack_subprocess()

python.MadGraphUtils.stack_subprocess ( command,
** kwargs )

Definition at line 45 of file MadGraphUtils.py.

45def stack_subprocess(command,**kwargs):
46 global MADGRAPH_COMMAND_STACK
47 MADGRAPH_COMMAND_STACK += [' '.join(command)]
48 return subprocess.Popen(command,**kwargs)
49

◆ update_lhe_file()

python.MadGraphUtils.update_lhe_file ( lhe_file_old,
param_card_old = None,
lhe_file_new = None,
masses = {},
delete_old_lhe = True )
Build a new LHE file from an old one and an updated param card.
The masses of some particles can be changed via the masses dictionary.  No particles that appear in the events
may have their masses changed.
If the param card is provided, the decay block in the LHE file will be replaced with the one in the param card.
By default, the old LHE file is removed.
If None is provided as a new LHE file name, the new file will replace the old one.

Definition at line 1344 of file MadGraphUtils.py.

1344def update_lhe_file(lhe_file_old,param_card_old=None,lhe_file_new=None,masses={},delete_old_lhe=True):
1345 """Build a new LHE file from an old one and an updated param card.
1346 The masses of some particles can be changed via the masses dictionary. No particles that appear in the events
1347 may have their masses changed.
1348 If the param card is provided, the decay block in the LHE file will be replaced with the one in the param card.
1349 By default, the old LHE file is removed.
1350 If None is provided as a new LHE file name, the new file will replace the old one."""
1351 # If we want to just use a temp file, then put in a little temp holder
1352 lhe_file_new_tmp = lhe_file_new if lhe_file_new is not None else lhe_file_old+'.tmp'
1353 # Make sure the LHE file is there
1354 if not os.access(lhe_file_old,os.R_OK):
1355 raise RuntimeError('Could not access old LHE file at '+str(lhe_file_old)+'. Please check the file location.')
1356 # Grab the old param card
1357 if param_card_old is not None:
1358 paramcard = subprocess.Popen(['get_files','-data',param_card_old])
1359 paramcard.wait()
1360 if not os.access(param_card_old,os.R_OK):
1361 raise RuntimeError('Could not get param card '+param_card_old)
1362 # Don't overwrite old param cards
1363 if os.access(lhe_file_new_tmp,os.R_OK):
1364 raise RuntimeError('Old file at'+str(lhe_file_new_tmp)+' in the current directory. Dont want to clobber it. Please move it first.')
1365
1366 newlhe = open(lhe_file_new_tmp,'w')
1367 blockName = None
1368 decayEdit = False
1369 eventRead = False
1370 particles_in_events = []
1371 # Decay block ends with </slha>
1372
1373 with open(lhe_file_old,'r') as fileobject:
1374 for line in fileobject:
1375 if decayEdit and '</slha>' not in line:
1376 continue
1377 if decayEdit and '</slha>' in line:
1378 decayEdit = False
1379 if line.strip().upper().startswith('BLOCK') or line.strip().upper().startswith('DECAY')\
1380 and len(line.strip().split()) > 1:
1381 pos = 0 if line.strip().startswith('DECAY') else 1
1382 blockName = line.strip().upper().split()[pos]
1383
1384 akey = None
1385 if blockName != 'DECAY' and len(line.strip().split()) > 0:
1386 akey = line.strip().split()[0]
1387 elif blockName == 'DECAY' and len(line.strip().split()) > 1:
1388 akey = line.strip().split()[1]
1389
1390 # Replace the masses with those in the dictionary
1391 if akey is not None and blockName == 'MASS' and akey in masses:
1392 newlhe.write(' '+akey+' '+str(masses[akey])+' # \n')
1393 mglog.info(' '+akey+' '+str(masses[akey])+' #')
1394 decayEdit = False
1395 continue
1396
1397 # Replace the entire decay section of the LHE file with the one from the param card
1398 if blockName == 'DECAY' and param_card_old is not None:
1399 # We are now reading the decay blocks! Take them from the param card
1400 oldparam = open(param_card_old,'r')
1401 newDecays = False
1402 for old_line in oldparam.readlines():
1403 newBlockName = None
1404 if old_line.strip().upper().startswith('DECAY') and len(old_line.strip().split()) > 1:
1405 newBlockName = line.strip().upper().split()[pos]
1406 if newDecays:
1407 newlhe.write(old_line)
1408 elif newBlockName == 'DECAY':
1409 newDecays = True
1410 newlhe.write(old_line)
1411 oldparam.close()
1412 # Done adding the decays
1413 decayEdit = True
1414 blockName = None
1415 continue
1416
1417 # Keep a record of the particles that are in the events
1418 if not eventRead and '<event>' in line:
1419 eventRead = True
1420 if eventRead:
1421 if len(line.split())==11:
1422 aparticle = line.split()[0]
1423 if aparticle not in particles_in_events:
1424 particles_in_events += [aparticle]
1425
1426 # Otherwise write the line again
1427 newlhe.write(line)
1428
1429 # Check that none of the particles that we were setting the masses of appear in the LHE events
1430 for akey in masses:
1431 if akey in particles_in_events:
1432 mglog.error('Attempted to change mass of a particle that was in an LHE event! This is not allowed!')
1433 return -1
1434
1435 # Close up and return
1436 newlhe.close()
1437
1438 # Move the new file to the old file location
1439 if lhe_file_new is None:
1440 os.remove(lhe_file_old)
1441 shutil.move(lhe_file_new_tmp,lhe_file_old)
1442 lhe_file_new_tmp = lhe_file_old
1443 # Delete the old file if requested
1444 elif delete_old_lhe:
1445 os.remove(lhe_file_old)
1446
1447 return lhe_file_new_tmp
1448
1449
1450
int upper(int c)

Variable Documentation

◆ MADGRAPH_CATCH_ERRORS

bool python.MadGraphUtils.MADGRAPH_CATCH_ERRORS = True

Definition at line 32 of file MadGraphUtils.py.

◆ MADGRAPH_COMMAND_STACK

list python.MadGraphUtils.MADGRAPH_COMMAND_STACK = []

Definition at line 35 of file MadGraphUtils.py.

◆ MADGRAPH_GRIDPACK_LOCATION

str python.MadGraphUtils.MADGRAPH_GRIDPACK_LOCATION = 'madevent'

Definition at line 28 of file MadGraphUtils.py.

◆ MADGRAPH_PDFSETTING

python.MadGraphUtils.MADGRAPH_PDFSETTING = None

Definition at line 34 of file MadGraphUtils.py.

◆ MADGRAPH_RUN_NAME

str python.MadGraphUtils.MADGRAPH_RUN_NAME = 'run_01'

Definition at line 30 of file MadGraphUtils.py.

◆ mglog

python.MadGraphUtils.mglog = Logging.logging.getLogger('MadGraphUtils')

Definition at line 19 of file MadGraphUtils.py.

◆ my_MGC_instance

python.MadGraphUtils.my_MGC_instance = None

Definition at line 20 of file MadGraphUtils.py.

◆ python

str python.MadGraphUtils.python = 'python'

Definition at line 26 of file MadGraphUtils.py.