ATLAS Offline Software
Functions | Variables
python.MadGraphUtils Namespace Reference

Functions

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

Variables

 mglog = Logging.logging.getLogger('MadGraphUtils')
 
 my_MGC_instance = None
 
string python = 'python'
 
string MADGRAPH_GRIDPACK_LOCATION = 'madevent'
 
string MADGRAPH_RUN_NAME = 'run_01'
 
bool MADGRAPH_CATCH_ERRORS = True
 
 MADGRAPH_PDFSETTING = None
 
list MADGRAPH_COMMAND_STACK = []
 
string patched_shutil_loc = '/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/shutil_patch'
 

Function Documentation

◆ add_lifetimes()

def 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 738 of file MadGraphUtils.py.

738 def add_lifetimes(process_dir,threshold=None):
739  """ Add lifetimes to the generated LHE file. Should be
740  called after generate_events is called.
741  """
742 
743  me_exec=get_mg5_executable()
744 
745  if len(glob.glob(process_dir+'/Events/*'))<1:
746  mglog.error('Process dir '+process_dir+' does not contain events?')
747  run = glob.glob(process_dir+'/Events/*')[0].split('/')[-1]
748 
749  # Note : This slightly clunky implementation is needed for the time being
750  # See : https://answers.launchpad.net/mg5amcnlo/+question/267904
751 
752  tof_c = open('time_of_flight_exec_card','w')
753  tof_c.write('launch '+process_dir+''' -i
754 add_time_of_flight '''+run+((' --threshold='+str(threshold)) if threshold is not None else ''))
755  tof_c.close()
756 
757  mglog.info('Started adding time of flight info '+str(time.asctime()))
758 
759  global MADGRAPH_CATCH_ERRORS
760  generate = stack_subprocess([python,me_exec,'time_of_flight_exec_card'],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
761  (out,err) = generate.communicate()
762  error_check(err,generate.returncode)
763 
764  mglog.info('Finished adding time of flight information at '+str(time.asctime()))
765 
766  # Re-zip the file if needed
767  lhe_gz = glob.glob(process_dir+'/Events/*/*lhe.gz')[0]
768  if not os.access(lhe_gz,os.R_OK):
769  mglog.info('LHE file needs to be zipped')
770  lhe = glob.glob(process_dir+'/Events/*/*lhe.gz')[0]
771  rezip = stack_subprocess(['gzip',lhe])
772  rezip.wait()
773  mglog.info('Zipped')
774  else:
775  mglog.info('LHE file zipped by MadGraph automatically. Nothing to do')
776 
777  return True
778 
779 

◆ add_madspin()

def 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 780 of file MadGraphUtils.py.

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

◆ add_reweighting()

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

Definition at line 1985 of file MadGraphUtils.py.

1985 def add_reweighting(run_name,reweight_card=None,process_dir=MADGRAPH_GRIDPACK_LOCATION):
1986  mglog.info('Running reweighting module on existing events')
1987  if reweight_card is not None:
1988  mglog.info('Copying new reweight card from '+reweight_card)
1989  shutil.move(reweight_card,process_dir+'/Cards/reweight_card.dat')
1990  reweight_cmd='{}/bin/madevent reweight {} -f'.format(process_dir,run_name)
1991  global MADGRAPH_CATCH_ERRORS
1992  reweight = stack_subprocess([python]+reweight_cmd.split(),stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
1993  (out,err) = reweight.communicate()
1994  error_check(err,reweight.returncode)
1995  mglog.info('Finished reweighting')
1996 
1997 
1998 
1999 

◆ arrange_output()

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

Definition at line 923 of file MadGraphUtils.py.

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

◆ check_reweight_card()

def python.MadGraphUtils.check_reweight_card (   process_dir = MADGRAPH_GRIDPACK_LOCATION)

Definition at line 1289 of file MadGraphUtils.py.

1289 def check_reweight_card(process_dir=MADGRAPH_GRIDPACK_LOCATION):
1290  reweight_card=get_reweight_card(process_dir=process_dir)
1291  shutil.move(reweight_card,reweight_card+'.old')
1292  oldcard = open(reweight_card+'.old','r')
1293  newcard = open(reweight_card,'w')
1294  changed = False
1295  info_expression=r'launch.*--rwgt_info\s*=\s*(\S+).*'
1296  name_expression=info_expression.replace('info','name')
1297  goodname_expression=r'^[A-Za-z0-9_\-.]+$'
1298  for line in oldcard:
1299  # we are only interested in the 'launch' line
1300  if not line.strip().startswith('launch') :
1301  newcard.write(line)
1302  else:
1303  rwgt_name_match=re.match(name_expression,line.strip())
1304  rwgt_info_match=re.match(info_expression,line.strip())
1305  if rwgt_name_match is None and rwgt_info_match is None:
1306  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)
1307  for match in [rwgt_info_match,rwgt_name_match]:
1308  if match is None:
1309  continue
1310  if len(match.groups())!=1:
1311  raise RuntimeError('Unexpected format of reweight card in line: '+line)
1312  if not re.match(goodname_expression,match.group(1)):
1313  raise RuntimeError('No special character in reweighting info/name, only allowing '+goodname_expression)
1314  if rwgt_info_match is not None:
1315  newcard.write(line)
1316  elif rwgt_name_match is not None:
1317  newcard.write(line.strip()+' --rwgt_info={0}\n'.format(rwgt_name_match.group(1)))
1318  changed=True
1319  if changed:
1320  mglog.info('Updated reweight_card')
1321  newcard.close()
1322  oldcard.close()
1323 
1324 

◆ find_key_and_update()

def python.MadGraphUtils.find_key_and_update (   akey,
  dictionary 
)
Helper function when looking at param cards
In some cases it's tricky to match keys - they may differ
only in white space. This tries to sort out when we have
a match, and then uses the one in blockParams afterwards.
In the case of no match, it returns the original key.

Definition at line 1432 of file MadGraphUtils.py.

1432 def find_key_and_update(akey,dictionary):
1433  """ Helper function when looking at param cards
1434  In some cases it's tricky to match keys - they may differ
1435  only in white space. This tries to sort out when we have
1436  a match, and then uses the one in blockParams afterwards.
1437  In the case of no match, it returns the original key.
1438  """
1439  test_key = ' '.join(akey.strip().replace('\t',' ').split())
1440  for key in dictionary:
1441  mod_key = ' '.join(key.strip().replace('\t',' ').split())
1442  if mod_key==test_key:
1443  return key
1444  return akey
1445 
1446 

◆ fix_fks_makefile()

def python.MadGraphUtils.fix_fks_makefile (   process_dir)

Definition at line 2008 of file MadGraphUtils.py.

2008 def fix_fks_makefile(process_dir):
2009  makefile_fks=process_dir+'/SubProcesses/makefile_fks_dir'
2010  mglog.info('Fixing '+makefile_fks)
2011  shutil.move(makefile_fks,makefile_fks+'_orig')
2012  fin=open(makefile_fks+'_orig')
2013  fout=open(makefile_fks,'w')
2014  edit=False
2015  for line in fin:
2016  if 'FKSParams.mod' in line:
2017  fout.write(line.replace('FKSParams.mod','FKSParams.o'))
2018  edit=True
2019  elif edit and 'driver_mintFO' in line:
2020  fout.write('driver_mintFO.o: weight_lines.o mint_module.o FKSParams.o\n')
2021  elif edit and 'genps_fks.o' in line:
2022  fout.write('genps_fks.o: mint_module.o FKSParams.o\n')
2023  elif edit and 'test_soft_col_limits' in line:
2024  fout.write(line)
2025  fout.write('madfks_plot.o: mint_module.o\n')
2026  fout.write('cluster.o: weight_lines.o\n')
2027  else:
2028  fout.write(line)
2029  fin.close()
2030  fout.close()

◆ generate()

def 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 112 of file MadGraphUtils.py.

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

◆ generate_from_gridpack()

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

Definition at line 331 of file MadGraphUtils.py.

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

◆ generate_prep()

def python.MadGraphUtils.generate_prep (   process_dir)

Definition at line 56 of file MadGraphUtils.py.

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

◆ get_cluster_type()

def python.MadGraphUtils.get_cluster_type (   process_dir = MADGRAPH_GRIDPACK_LOCATION)

Definition at line 1839 of file MadGraphUtils.py.

1839 def get_cluster_type(process_dir=MADGRAPH_GRIDPACK_LOCATION):
1840  card_in = open(get_default_config_card(process_dir=process_dir),'r')
1841  for l in card_in.readlines():
1842  if 'cluster_type' not in l.split('#')[0]:
1843  continue
1844  cluster_type = l.split('#')[0].split('=')[1]
1845  mglog.info('Returning cluster type: '+cluster_type)
1846  return cluster_type
1847  return None
1848 
1849 
1850 

◆ get_default_runcard()

def 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 91 of file MadGraphUtils.py.

91 def get_default_runcard(process_dir=MADGRAPH_GRIDPACK_LOCATION):
92  """ Copy the default runcard from one of several locations
93  to a local file with name run_card.tmp.dat"""
94  output_name = 'run_card.tmp.dat'
95 
96  # Get the run card from the installation
97  run_card=process_dir+'/Cards/run_card.dat'
98  if os.access(run_card,os.R_OK):
99  mglog.info('Copying default run_card.dat from '+str(run_card))
100  shutil.copy(run_card,output_name)
101  return output_name
102  else:
103  run_card=process_dir+'/Cards/run_card_default.dat'
104  mglog.info('Fetching default run_card.dat from '+str(run_card))
105  if os.access(run_card,os.R_OK):
106  shutil.copy(run_card,output_name)
107  return output_name
108  else:
109  raise RuntimeError('Cannot find default run_card.dat or run_card_default.dat! I was looking here: %s'%run_card)
110 
111 

◆ get_expected_reweight_names()

def python.MadGraphUtils.get_expected_reweight_names (   reweight_card_loc)

Definition at line 1199 of file MadGraphUtils.py.

1199 def get_expected_reweight_names(reweight_card_loc):
1200  if reweight_card_loc is None:
1201  return []
1202  names=[]
1203  f_rw=open(reweight_card_loc)
1204  for line in f_rw:
1205  if 'launch' not in line:
1206  continue
1207  match=re.match(r'launch.*--rwgt_info\s*=\s*(\S+).*',line.strip())
1208  if len(match.groups())!=1:
1209  raise RuntimeError('Unexpected format of reweight card in line'+line)
1210  else:
1211  names+=[match.group(1)]
1212  f_rw.close()
1213  return names
1214 

◆ get_expected_systematic_names()

def python.MadGraphUtils.get_expected_systematic_names (   syst_setting)

Definition at line 1215 of file MadGraphUtils.py.

1215 def get_expected_systematic_names(syst_setting):
1216  names=[]
1217  if syst_setting is None or 'central_pdf' not in syst_setting:
1218  mglog.warning("Systematics have not been defined via base fragment or 'MADGRAPH_PDFSETTING', cannot check for expected weights")
1219  return []
1220  if 'pdf_variations' in syst_setting and isinstance(syst_setting['pdf_variations'],list):
1221  names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':1.0,'muf':1.0,'pdf':syst_setting['central_pdf']}]
1222  for pdf in syst_setting['pdf_variations']:
1223  names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':1.0,'muf':1.0,'pdf':pdf+1}]
1224  if 'alternative_pdfs' in syst_setting and isinstance(syst_setting['alternative_pdfs'],list):
1225  for pdf in syst_setting['alternative_pdfs']:
1226  names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':1.0,'muf':1.0,'pdf':pdf}]
1227  if 'scale_variations' in syst_setting and isinstance(syst_setting['scale_variations'],list):
1228  for mur in syst_setting['scale_variations']:
1229  for muf in syst_setting['scale_variations']:
1230  names+=[MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO%{'mur':mur,'muf':muf,'pdf':syst_setting['central_pdf']}]
1231  return names
1232 

◆ get_mg5_executable()

def python.MadGraphUtils.get_mg5_executable ( )

Definition at line 731 of file MadGraphUtils.py.

731 def get_mg5_executable():
732  madpath=os.environ['MADPATH']
733  if not os.access(madpath+'/bin/mg5_aMC',os.R_OK):
734  raise RuntimeError('mg5_aMC executable not found in '+madpath)
735  return madpath+'/bin/mg5_aMC'
736 
737 

◆ get_reweight_card()

def python.MadGraphUtils.get_reweight_card (   process_dir = MADGRAPH_GRIDPACK_LOCATION)

Definition at line 1283 of file MadGraphUtils.py.

1283 def get_reweight_card(process_dir=MADGRAPH_GRIDPACK_LOCATION):
1284  if os.access(process_dir+'/Cards/reweight_card.dat',os.R_OK):
1285  return process_dir+'/Cards/reweight_card.dat'
1286  return None
1287 
1288 

◆ is_gen_from_gridpack()

def 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 1647 of file MadGraphUtils.py.

1647 def is_gen_from_gridpack():
1648  """ Simple function for checking if there is a grid pack.
1649  Relies on the specific location of the unpacked gridpack (madevent)
1650  which is here set as a global variable. The gridpack is untarred by
1651  the transform (Gen_tf.py) and no sign is sent to the job itself
1652  that there is a gridpack in use except the file's existence"""
1653  if os.access(MADGRAPH_GRIDPACK_LOCATION,os.R_OK):
1654  mglog.info('Located input grid pack area')
1655  return True
1656  return False
1657 
1658 
1659 

◆ ls_dir()

def python.MadGraphUtils.ls_dir (   directory)

Definition at line 2000 of file MadGraphUtils.py.

2000 def ls_dir(directory):
2001  mglog.info('For your information, ls of '+directory+':')
2002  mglog.info( sorted( os.listdir( directory ) ) )
2003 
2004 # Final import of some code used in these functions

◆ madspin_on_lhe()

def 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 835 of file MadGraphUtils.py.

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

◆ modify_config_card()

def 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 1782 of file MadGraphUtils.py.

1782 def modify_config_card(config_card_backup=None,process_dir=MADGRAPH_GRIDPACK_LOCATION,settings={},set_commented=True):
1783  """Build a new configuration from an existing one.
1784  This function can get a fresh runcard from DATAPATH or start from the process directory.
1785  Settings is a dictionary of keys (no spaces needed) and values to replace.
1786  """
1787  # Check for the default config card location
1788  config_card=get_default_config_card(process_dir=process_dir)
1789 
1790  # The format is similar to the run card, but backwards
1791  mglog.info('Modifying config card located at '+config_card)
1792  if config_card_backup is not None:
1793  mglog.info('Keeping backup of original config card at '+config_card_backup)
1794  config_card_old = config_card_backup
1795  else:
1796  config_card_old = config_card+'.old_to_be_deleted'
1797  mglog.debug('Modifying config card settings: '+str(settings))
1798  if os.path.isfile(config_card_old):
1799  os.unlink(config_card_old) # delete old backup
1800  os.rename(config_card, config_card_old) # change name of original card
1801 
1802  oldCard = open(config_card_old, 'r')
1803  newCard = open(config_card, 'w')
1804  used_settings = []
1805  for line in iter(oldCard):
1806  lmod = line if set_commented else line.split('#')[0]
1807  if '=' in lmod:
1808  modified = False
1809  for setting in settings:
1810  if setting not in lmod:
1811  continue
1812  # Assume we hit
1813  mglog.info('Setting '+setting.strip()+' to '+str(settings[setting]))
1814  newCard.write(' '+str(setting.strip())+' = '+str(settings[setting])+'\n')
1815  used_settings += [ setting.strip() ]
1816  modified = True
1817  break
1818  if modified:
1819  continue
1820  newCard.write(line)
1821 
1822  # Clean up unused options
1823  for asetting in settings:
1824  if asetting in used_settings:
1825  continue
1826  if settings[asetting] is None:
1827  continue
1828  mglog.warning('Option '+asetting+' was not in the default config card. Adding by hand a setting to '+str(settings[asetting]) )
1829  newCard.write(' '+str(asetting)+' = '+str(settings[asetting])+'\n')
1830  # close files
1831  oldCard.close()
1832  newCard.close()
1833  mglog.info('Finished modification of config card.')
1834  if config_card_backup is None:
1835  os.unlink(config_card_old)
1836 
1837 
1838 

◆ modify_param_card()

def python.MadGraphUtils.modify_param_card (   param_card_input = None,
  param_card_backup = None,
  process_dir = MADGRAPH_GRIDPACK_LOCATION,
  params = {},
  output_location = None 
)
Build a new param_card.dat from an existing one.
Params should be a dictionary of dictionaries. The first key is the block name, and the second in the param name.
Keys can include MASS (for masses) and DECAY X (for decays of particle X)

Definition at line 1447 of file MadGraphUtils.py.

1447 def modify_param_card(param_card_input=None,param_card_backup=None,process_dir=MADGRAPH_GRIDPACK_LOCATION,params={},output_location=None):
1448  """Build a new param_card.dat from an existing one.
1449  Params should be a dictionary of dictionaries. The first key is the block name, and the second in the param name.
1450  Keys can include MASS (for masses) and DECAY X (for decays of particle X)"""
1451  # Grab the old param card and move it into place
1452 
1453  # Check for the default run card location
1454  if param_card_input is None:
1455  param_card_input=process_dir+'/Cards/param_card.dat'
1456  elif param_card_input is not None and not os.access(param_card_input,os.R_OK):
1457  paramcard = subprocess.Popen(['get_files','-data',param_card_input])
1458  paramcard.wait()
1459  if not os.access(param_card_input,os.R_OK):
1460  raise RuntimeError('Could not get param card '+param_card_input)
1461  mglog.info('Using input param card at '+param_card_input)
1462 
1463  #ensure all blocknames and paramnames are upper case
1464  paramsUpper = {}
1465  for blockName in list(params.keys()):
1466  paramsUpper[blockName.upper()] = {}
1467  for paramName in list(params[blockName].keys()):
1468  paramsUpper[blockName.upper()][paramName.upper()] = params[blockName][paramName]
1469 
1470  if param_card_backup is not None:
1471  mglog.info('Keeping backup of original param card at '+param_card_backup)
1472  param_card_old = param_card_backup
1473  else:
1474  param_card_old = param_card_input+'.old_to_be_deleted'
1475  if os.path.isfile(param_card_old):
1476  os.unlink(param_card_old) # delete old backup
1477  os.rename(param_card_input, param_card_old) # change name of original card
1478 
1479  oldcard = open(param_card_old,'r')
1480  param_card_location= process_dir+'/Cards/param_card.dat' if output_location is None else output_location
1481  newcard = open(param_card_location,'w')
1482  decayEdit = False #only becomes true in a DECAY block when specifying the BR
1483  blockName = ""
1484  doneParams = {} #tracks which params have been done
1485  for linewithcomment in oldcard:
1486  line=linewithcomment.split('#')[0]
1487  if line.strip().upper().startswith('BLOCK') or line.strip().upper().startswith('DECAY')\
1488  and len(line.strip().split()) > 1:
1489  if decayEdit and blockName == 'DECAY':
1490  decayEdit = False # Start a new DECAY block
1491  pos = 0 if line.strip().startswith('DECAY') else 1
1492  if blockName=='MASS' and 'MASS' in paramsUpper:
1493  # Any residual masses to set?
1494  if "MASS" in doneParams:
1495  leftOvers = [ x for x in paramsUpper['MASS'] if x not in doneParams['MASS'] ]
1496  else:
1497  leftOvers = [ x for x in paramsUpper['MASS'] ]
1498 
1499  for pdg_id in leftOvers:
1500  mglog.warning('Adding mass line for '+str(pdg_id)+' = '+str(paramsUpper['MASS'][pdg_id])+' which was not in original param card')
1501  newcard.write(' '+str(pdg_id)+' '+str(paramsUpper['MASS'][pdg_id])+'\n')
1502  doneParams['MASS'][pdg_id]=True
1503  if blockName=='DECAY' and 'DECAY' not in line.strip().upper() and 'DECAY' in paramsUpper:
1504  # Any residual decays to include?
1505  leftOvers = [ x for x in paramsUpper['DECAY'] if x not in doneParams['DECAY'] ]
1506  for pdg_id in leftOvers:
1507  mglog.warning('Adding decay for pdg id '+str(pdg_id)+' which was not in the original param card')
1508  newcard.write( paramsUpper['DECAY'][pdg_id].strip()+'\n' )
1509  doneParams['DECAY'][pdg_id]=True
1510  blockName = line.strip().upper().split()[pos]
1511  if decayEdit:
1512  continue #skipping these lines because we are in an edit of the DECAY BR
1513 
1514  akey = None
1515  if blockName != 'DECAY' and len(line.strip().split()) > 0:
1516  # The line is already without the comment.
1517  # In the case of mixing matrices this is a bit tricky
1518  if len(line.split())==2:
1519  akey = line.upper().strip().split()[0]
1520  else:
1521  # Take everything but the last word
1522  akey = line.upper().strip()[:line.strip().rfind(' ')].strip()
1523  elif blockName == 'DECAY' and len(line.strip().split()) > 1:
1524  akey = line.strip().split()[1]
1525  if akey is None:
1526  newcard.write(linewithcomment)
1527  continue
1528 
1529  #check if we have params for this block
1530  if blockName not in paramsUpper:
1531  newcard.write(linewithcomment)
1532  continue
1533  blockParams = paramsUpper[blockName]
1534  # Check the spacing in the key
1535  akey = find_key_and_update(akey,blockParams)
1536 
1537  # look for a string key, which would follow a #
1538  stringkey = None
1539  if '#' in linewithcomment: #ignores comment lines
1540  stringkey = linewithcomment[linewithcomment.find('#')+1:].strip()
1541  if len(stringkey.split()) > 0:
1542  stringkey = stringkey.split()[0].upper()
1543 
1544  if akey not in blockParams and not (stringkey is not None and stringkey in blockParams):
1545  newcard.write(linewithcomment)
1546  continue
1547 
1548  if akey in blockParams and (stringkey is not None and stringkey in blockParams):
1549  raise RuntimeError('Conflicting use of numeric and string keys '+akey+' and '+stringkey)
1550 
1551  theParam = blockParams.get(akey,blockParams[stringkey] if stringkey in blockParams else None)
1552  if blockName not in doneParams:
1553  doneParams[blockName] = {}
1554  if akey in blockParams:
1555  doneParams[blockName][akey]=True
1556  elif stringkey is not None and stringkey in blockParams:
1557  doneParams[blockName][stringkey]=True
1558 
1559  #do special case of DECAY block
1560  if blockName=="DECAY":
1561  if theParam.splitlines()[0].split()[0].upper()=="DECAY":
1562  #specifying the full decay block
1563  for newline in theParam.splitlines():
1564  newcard.write(newline+'\n')
1565  mglog.info(newline)
1566  decayEdit = True
1567  else: #just updating the total width
1568  newcard.write('DECAY '+akey+' '+str(theParam)+' # '+(linewithcomment[linewithcomment.find('#')+1:].strip() if linewithcomment.find('#')>0 else "")+'\n')
1569  mglog.info('DECAY '+akey+' '+str(theParam)+' # '+(linewithcomment[linewithcomment.find('#')+1:].strip() if linewithcomment.find('#')>0 else "")+'\n')
1570  # second special case of QNUMBERS
1571  elif blockName=='QNUMBERS':
1572  #specifying the full QNUMBERS block
1573  for newline in theParam.splitlines():
1574  newcard.write(newline+'\n')
1575  mglog.info(newline)
1576  decayEdit = True
1577  else: #just updating the parameter
1578  newcard.write(' '+akey+' '+str(theParam)+' # '+(linewithcomment[linewithcomment.find('#')+1:].strip() if linewithcomment.find('#')>0 else "")+'\n')
1579  mglog.info(' '+akey+' '+str(theParam)+' # '+(linewithcomment[linewithcomment.find('#')+1:].strip() if linewithcomment.find('#')>0 else "")+'\n')
1580  # Done editing the line!
1581 
1582  #check that all specified parameters have been updated (helps to catch typos)
1583  for blockName in paramsUpper:
1584  if blockName not in doneParams and len(paramsUpper[blockName].keys())>0:
1585  raise RuntimeError('Did not find any of the parameters for block '+blockName+' in param_card')
1586  for paramName in paramsUpper[blockName]:
1587  if paramName not in doneParams[blockName]:
1588  raise RuntimeError('Was not able to replace parameter '+paramName+' in param_card')
1589 
1590  # Close up and return
1591  oldcard.close()
1592  newcard.close()
1593 
1594 
1595 

◆ modify_run_card()

def 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 1660 of file MadGraphUtils.py.

1660 def modify_run_card(run_card_input=None,run_card_backup=None,process_dir=MADGRAPH_GRIDPACK_LOCATION,runArgs=None,settings={},skipBaseFragment=False):
1661  """Build a new run_card.dat from an existing one.
1662  This function can get a fresh runcard from DATAPATH or start from the process directory.
1663  Settings is a dictionary of keys (no spaces needed) and values to replace.
1664  """
1665 
1666  # Operate on lower case settings, and choose the capitalization MG5 has as the default (or all lower case)
1667  settings_lower = {}
1668  for s in list(settings.keys()):
1669  settings_lower[s.lower()] = settings[s]
1670 
1671  # Check for the default run card location
1672  if run_card_input is None:
1673  run_card_input=get_default_runcard(process_dir)
1674  elif run_card_input is not None and not os.access(run_card_input,os.R_OK):
1675  runcard = subprocess.Popen(['get_files','-data',run_card_input])
1676  runcard.wait()
1677  if not os.access(run_card_input,os.R_OK):
1678  raise RuntimeError('Could not get run card '+run_card_input)
1679 
1680  # guess NLO
1681  isNLO=is_NLO_run(process_dir=process_dir)
1682  # add gobal PDF and scale uncertainty config to extras, except PDF or weights for syscal config are explictly set
1683  if not skipBaseFragment:
1684  MadGraphControl.MadGraphSystematicsUtils.setup_pdf_and_systematic_weights(MADGRAPH_PDFSETTING,settings_lower,isNLO)
1685 
1686  # Get some info out of the runArgs
1687  if runArgs is not None:
1688  beamEnergy,rand_seed = get_runArgs_info(runArgs)
1689  if 'iseed' not in settings_lower:
1690  settings_lower['iseed']=rand_seed
1691  if not isNLO and 'python_seed' not in settings_lower:
1692  settings_lower['python_seed']=rand_seed
1693  if 'beamenergy' in settings_lower:
1694  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']))
1695  beamEnergy=settings_lower['beamenergy']
1696  settings_lower.pop('beamenergy')
1697  if 'ebeam1' not in settings_lower:
1698  settings_lower['ebeam1']=beamEnergy
1699  if 'ebeam2' not in settings_lower:
1700  settings_lower['ebeam2']=beamEnergy
1701  # Make sure nevents is an integer
1702  if 'nevents' in settings_lower:
1703  settings_lower['nevents'] = int(settings_lower['nevents'])
1704 
1705  # Normalise custom_fcts early so the rewritten run_card uses the full path
1706  if 'custom_fcts' in settings_lower and settings_lower['custom_fcts']:
1707  raw_name = str(settings_lower['custom_fcts']).split()[0]
1708  # Determine jobConfig directory
1709  if runArgs is not None and hasattr(runArgs, 'jobConfig'):
1710  cfgdir = runArgs.jobConfig[0] if isinstance(runArgs.jobConfig, (list, tuple)) else runArgs.jobConfig
1711  # Build full path and make absolute
1712  full_path = os.path.join(cfgdir, raw_name)
1713  settings_lower['custom_fcts'] = os.path.abspath(full_path)
1714  print(f"Using custom function(s), specified in custom_fcts with path: {settings_lower['custom_fcts']}")
1715  else:
1716  # For internal tests, where jobConfig is not set
1717  settings_lower['custom_fcts'] = os.path.abspath(raw_name)
1718 
1719  mglog.info('Modifying run card located at '+run_card_input)
1720  if run_card_backup is not None:
1721  mglog.info('Keeping backup of original run card at '+run_card_backup)
1722  run_card_old = run_card_backup
1723  else:
1724  run_card_old = run_card_input+'.old_to_be_deleted'
1725  mglog.debug('Modifying runcard settings: '+str(settings_lower))
1726  if os.path.isfile(run_card_old):
1727  os.unlink(run_card_old) # delete old backup
1728  os.rename(run_card_input, run_card_old) # change name of original card
1729 
1730  oldCard = open(run_card_old, 'r')
1731  newCard = open(process_dir+'/Cards/run_card.dat', 'w')
1732  used_settings = []
1733  for line in iter(oldCard):
1734  if not line.strip().startswith('#'): # line commented out
1735  command = line.split('!', 1)[0]
1736  comment = line.split('!', 1)[1] if '!' in line else ''
1737  if '=' in command:
1738  setting = command.split('=')[-1] #.strip()
1739  stripped_setting = setting.strip()
1740  oldValue = '='.join(command.split('=')[:-1])
1741  if stripped_setting.lower() in settings_lower:
1742  # if setting set to 'None' it will be removed from run_card
1743  if settings_lower[stripped_setting.lower()] is None:
1744  line=''
1745  mglog.info('Removing '+stripped_setting+'.')
1746  used_settings += [ stripped_setting.lower() ]
1747  else:
1748  if stripped_setting.lower() == 'custom_fcts':
1749  # Overwrite completely to avoid duplicating in custom_fcts, else MadGraph will crash
1750  line = ' '+str(settings_lower[stripped_setting.lower()])+' = '+setting
1751  if comment != '':
1752  line += ' !'+comment
1753  else:
1754  line = oldValue.replace(oldValue.strip(), str(settings_lower[stripped_setting.lower()]))+'='+setting
1755  if comment != '':
1756  line += ' !' + comment
1757  mglog.info('Setting '+stripped_setting+' = '+str(settings_lower[stripped_setting.lower()]))
1758  used_settings += [ stripped_setting.lower() ]
1759  newCard.write(line.strip()+'\n')
1760 
1761  # Check whether mcatnlo_delta is applied to setup pythia8 path
1762  if 'mcatnlo_delta' in settings_lower:
1763  if settings_lower['mcatnlo_delta'] == 'True':
1764  modify_config_card(process_dir=process_dir,settings={'pythia8_path':os.getenv("PY8PATH")})
1765 
1766  # Clean up unused options
1767  for asetting in settings_lower:
1768  if asetting in used_settings:
1769  continue
1770  if settings_lower[asetting] is None:
1771  continue
1772  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]) )
1773  newCard.write( ' '+str(settings_lower[asetting])+' = '+str(asetting)+'\n')
1774  # close files
1775  oldCard.close()
1776  newCard.close()
1777  mglog.info('Finished modification of run card.')
1778  if run_card_backup is None:
1779  os.unlink(run_card_old)
1780 
1781 

◆ new_process()

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

Definition at line 81 of file MadGraphUtils.py.

81 def new_process(process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False):
82  global my_MGC_instance
83  print(process,plugin,keepJpegs,usePMGSettings)
84  my_MGC_instance = MGControl(process, plugin, keepJpegs, usePMGSettings)
85  # Sync options as an intermediate solution until the full migration is done
86  modify_run_card(process_dir=my_MGC_instance.process_dir,settings=my_MGC_instance.runCardDict,skipBaseFragment=True)
87  # This should be enabled ASAP, but isn't yet ready
88  #modify_config_card(process_dir=my_MGC_instance.process_dir,settings=my_MGC_instance.configCardDict)
89  return my_MGC_instance.process_dir
90 

◆ print_cards()

def 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 1602 of file MadGraphUtils.py.

1602 def print_cards(proc_card='proc_card_mg5.dat',run_card=None,param_card=None,madspin_card=None,reweight_card=None,warn_on_missing=True):
1603  if os.access(proc_card,os.R_OK):
1604  mglog.info("proc_card:")
1605  procCard = subprocess.Popen(['cat',proc_card])
1606  procCard.wait()
1607  elif warn_on_missing:
1608  mglog.warning('No proc_card: '+proc_card+' found')
1609 
1610  if run_card is not None and os.access(run_card,os.R_OK):
1611  mglog.info("run_card:")
1612  runCard = subprocess.Popen(['cat',run_card])
1613  runCard.wait()
1614  elif run_card is not None and warn_on_missing:
1615  mglog.warning('No run_card: '+run_card+' found')
1616  else:
1617  mglog.info('Default run card in use')
1618 
1619  if param_card is not None and os.access(param_card,os.R_OK):
1620  mglog.info("param_card:")
1621  paramCard = subprocess.Popen(['cat',param_card])
1622  paramCard.wait()
1623  elif param_card is not None and warn_on_missing:
1624  mglog.warning('No param_card: '+param_card+' found')
1625  else:
1626  mglog.info('Default param card in use')
1627 
1628  if madspin_card is not None and os.access(madspin_card,os.R_OK):
1629  mglog.info("madspin_card:")
1630  madspinCard = subprocess.Popen(['cat',madspin_card])
1631  madspinCard.wait()
1632  elif madspin_card is not None and warn_on_missing:
1633  mglog.warning('No madspin_card: '+madspin_card+' found')
1634  else:
1635  mglog.info('No madspin card in use')
1636 
1637  if reweight_card is not None and os.access(reweight_card,os.R_OK):
1638  mglog.info("reweight_card:")
1639  madspinCard = subprocess.Popen(['cat',reweight_card])
1640  madspinCard.wait()
1641  elif reweight_card is not None and warn_on_missing:
1642  mglog.warning('No reweight_card: '+reweight_card+' found')
1643  else:
1644  mglog.info('No reweight card in use')
1645 
1646 

◆ print_cards_from_dir()

def python.MadGraphUtils.print_cards_from_dir (   process_dir = MADGRAPH_GRIDPACK_LOCATION)

Definition at line 1596 of file MadGraphUtils.py.

1596 def print_cards_from_dir(process_dir=MADGRAPH_GRIDPACK_LOCATION):
1597  card_dir=process_dir+'/Cards/'
1598  print_cards(proc_card=card_dir+'proc_card_mg5.dat',run_card=card_dir+'run_card.dat',param_card=card_dir+'param_card.dat',\
1599  madspin_card=card_dir+'madspin_card.dat',reweight_card=card_dir+'reweight_card.dat',warn_on_missing=False)
1600 
1601 

◆ run_card_consistency_check()

def python.MadGraphUtils.run_card_consistency_check (   isNLO = False,
  process_dir = '.' 
)

Definition at line 1851 of file MadGraphUtils.py.

1851 def run_card_consistency_check(isNLO=False,process_dir='.'):
1852  cardpath=process_dir+'/Cards/run_card.dat'
1853  mydict=getDictFromCard(cardpath)
1854  global my_MGC_instance
1855  # We should always use event_norm = average [AGENE-1725] otherwise Pythia cross sections are wrong
1856  # Modification: average or bias is ok; sum is incorrect. Change the test to set sum to average
1857  if checkSetting('event_norm','sum',mydict):
1858  modify_run_card(process_dir=process_dir,settings={'event_norm':'average'},skipBaseFragment=True)
1859  mglog.warning("setting event_norm to average, there is basically no use case where event_norm=sum is a good idea")
1860 
1861  if not isNLO:
1862  #Check CKKW-L setting
1863  if 'ktdurham' in mydict and float(mydict['ktdurham']) > 0 and int(mydict['ickkw']) != 0:
1864  log='Bad combination of settings for CKKW-L merging! ktdurham=%s and ickkw=%s.'%(mydict['ktdurham'],mydict['ickkw'])
1865  mglog.error(log)
1866  raise RuntimeError(log)
1867 
1868  # Check if user is trying to use deprecated syscalc arguments with the other systematics script
1869  if 'systematics_program' not in mydict or mydict['systematics_program']=='systematics':
1870  syscalc_settings=['sys_pdf', 'sys_scalefact', 'sys_alpsfact', 'sys_matchscale']
1871  found_syscalc_setting=False
1872  for s in syscalc_settings:
1873  if s in mydict:
1874  mglog.warning('Using syscalc setting '+s+' with new systematics script. Systematics script is default from 2.6.2 and steered differently (https://cp3.irmp.ucl.ac.be/projects/madgraph/wiki/Systematics#Systematicspythonmodule)')
1875  found_syscalc_setting=True
1876  if found_syscalc_setting:
1877  syst_arguments=MadGraphControl.MadGraphSystematicsUtils.convertSysCalcArguments(mydict)
1878  mglog.info('Converted syscalc arguments to systematics arguments: '+syst_arguments)
1879  syst_settings_update={'systematics_arguments':syst_arguments}
1880  for s in syscalc_settings:
1881  syst_settings_update[s]=None
1882  modify_run_card(process_dir=process_dir,settings=syst_settings_update,skipBaseFragment=True)
1883 
1884 
1885  # usually the pdf and systematics should be set during modify_run_card
1886  # but check again in case the user did not call the function or provides a different card here
1887  mglog.info('Checking PDF and systematics settings')
1888  if not MadGraphControl.MadGraphSystematicsUtils.base_fragment_setup_check(MADGRAPH_PDFSETTING,mydict,isNLO):
1889  # still need to set pdf and systematics
1890  syst_settings=MadGraphControl.MadGraphSystematicsUtils.get_pdf_and_systematic_settings(MADGRAPH_PDFSETTING,isNLO)
1891  modify_run_card(process_dir=process_dir,settings=syst_settings,skipBaseFragment=True)
1892 
1893  mydict_new=getDictFromCard(cardpath)
1894  if 'systematics_arguments' in mydict_new:
1895  systematics_arguments=MadGraphControl.MadGraphSystematicsUtils.parse_systematics_arguments(mydict_new['systematics_arguments'])
1896  if 'weight_info' not in systematics_arguments:
1897  mglog.info('Enforcing systematic weight name convention')
1898  dyn = None
1899  if '--dyn' in systematics_arguments or ' dyn' in systematics_arguments:
1900  if '--dyn' in systematics_arguments:
1901  dyn = systematics_arguments.split('--dyn')[1]
1902  if ' dyn' in systematics_arguments:
1903  dyn = systematics_arguments.split(' dyn')[1]
1904  dyn = dyn.replace('\'',' ').replace('=',' ').split()[0]
1905  if dyn is not None and len(dyn.split(','))>1:
1906  systematics_arguments['weight_info']=MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO_ALTDYNSCALES
1907  else:
1908  systematics_arguments['weight_info']=MadGraphControl.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO
1909  modify_run_card(process_dir=process_dir,settings={'systematics_arguments':MadGraphControl.MadGraphSystematicsUtils.write_systematics_arguments(systematics_arguments)},skipBaseFragment=True)
1910 
1911  if not isNLO:
1912  if 'python_seed' not in mydict:
1913  mglog.warning('No python seed set in run_card -- adding one with same value as iseed')
1914  modify_run_card(process_dir=process_dir,settings={'python_seed':mydict['iseed']},skipBaseFragment=True)
1915 
1916  # consistency check of 4/5 flavour shceme settings
1917  FS_updates={}
1918  proton_5flav = False
1919  jet_5flav = False
1920  with open(process_dir+'/Cards/proc_card_mg5.dat', 'r') as file:
1921  content = file.readlines()
1922  for rawline in content:
1923  line = rawline.split('#')[0]
1924  if line.startswith("define p"):
1925  if ('b' in line.split() and 'b~' in line.split()) or ('5' in line.split() and '-5' in line.split()):
1926  proton_5flav = True
1927  if 'j' in line.split() and jet_5flav:
1928  proton_5flav = True
1929  if line.startswith("define j"):
1930  if ('b' in line.split() and 'b~' in line.split()) or ('5' in line.split() and '-5' in line.split()):
1931  jet_5flav = True
1932  if 'p' in line.split() and proton_5flav:
1933  jet_5flav = True
1934  if proton_5flav or jet_5flav:
1935  FS_updates['asrwgtflavor'] = 5
1936  if not proton_5flav:
1937  mglog.warning('Found 5-flavour jets but 4-flavour proton. This is inconsistent - please pick one.')
1938  mglog.warning('Will proceed assuming 5-flavour scheme.')
1939  if not jet_5flav:
1940  mglog.warning('Found 5-flavour protons but 4-flavour jets. This is inconsistent - please pick one.')
1941  mglog.warning('Will proceed assuming 5-flavour scheme.')
1942  else:
1943  FS_updates['asrwgtflavor'] = 4
1944 
1945  if len(FS_updates)==0:
1946  mglog.warning(f'Could not identify 4- or 5-flavor scheme from process card {process_dir}/Cards/proc_card_mg5.dat')
1947 
1948  if 'asrwgtflavor' in mydict or 'maxjetflavor' in mydict or 'pdgs_for_merging_cut' in mydict:
1949  if FS_updates['asrwgtflavor'] == 5:
1950  # Process card says we are in the five-flavor scheme
1951  if ('asrwgtflavor' in mydict and int(mydict['asrwgtflavor']) != 5) or ('maxjetflavor' in mydict and int(mydict['maxjetflavor']) != 5) or ('pdgs_for_merging_cut' in mydict and '5' not in mydict['pdgs_for_merging_cut']):
1952  # Inconsistent setting detected; warn the users and correct the settings
1953  mglog.warning('b and b~ included in p and j for 5-flavor scheme but run card settings are inconsistent; adjusting run card')
1954  run_card_updates = {'asrwgtflavor': 5, 'maxjetflavor': 5, 'pdgs_for_merging_cut': '1, 2, 3, 4, 5, 21'}
1955  modify_run_card(process_dir=process_dir,settings=run_card_updates,skipBaseFragment=True)
1956  modify_param_card(process_dir=process_dir, params={'MASS': {'5': '0.000000e+00'}})
1957  else:
1958  mglog.debug('Consistent 5-flavor scheme setup detected.')
1959  if FS_updates['asrwgtflavor'] == 4:
1960  # Process card says we are in the four-flavor scheme
1961  if ('asrwgtflavor' in mydict and int(mydict['asrwgtflavor']) != 4) or ('maxjetflavor' in mydict and int(mydict['maxjetflavor']) != 4) or ('pdgs_for_merging_cut' in mydict and '5' in mydict['pdgs_for_merging_cut']):
1962  # Inconsistent setting detected; warn the users and correct the settings
1963  mglog.warning('b and b~ not included in p and j (4-flavor scheme) but run card settings are inconsistent; adjusting run card')
1964  run_card_updates = {'asrwgtflavor': 4, 'maxjetflavor': 4, 'pdgs_for_merging_cut': '1, 2, 3, 4, 21'}
1965  modify_run_card(process_dir=process_dir,settings=run_card_updates,skipBaseFragment=True)
1966  modify_param_card(process_dir=process_dir, params={'MASS': {'5': '4.700000e+00'}})
1967  else:
1968  mglog.debug('Consistent 4-flavor scheme setup detected.')
1969  else:
1970  # Flavor scheme setup is missing, adding by hand
1971  if FS_updates['asrwgtflavor'] == 4:
1972  # Warn the users and add the settings according to process card
1973  mglog.warning('Flavor scheme setup is missing, adding by hand according to process card - b and b~ not included in p and j, 4-flavor scheme setup will be used; adjusting run card.')
1974  run_card_updates = {'asrwgtflavor': 4, 'maxjetflavor': 4, 'pdgs_for_merging_cut': '1, 2, 3, 4, 21'}
1975  modify_run_card(process_dir=process_dir,settings=run_card_updates,skipBaseFragment=True)
1976  modify_param_card(process_dir=process_dir, params={'MASS': {'5': '4.700000e+00'}})
1977  elif FS_updates['asrwgtflavor'] == 5:
1978  mglog.warning('Flavor scheme setup is missing, adding by hand according to process card - b and b~ included in p and j, 5-flavor scheme setup will be used; adjusting run card.')
1979  run_card_updates = {'asrwgtflavor': 5, 'maxjetflavor': 5, 'pdgs_for_merging_cut': '1, 2, 3, 4, 5, 21'}
1980  modify_run_card(process_dir=process_dir,settings=run_card_updates,skipBaseFragment=True)
1981  modify_param_card(process_dir=process_dir, params={'MASS': {'5': '0.000000e+00'}})
1982 
1983  mglog.info('Finished checking run card - All OK!')
1984 

◆ setNCores()

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

Definition at line 713 of file MadGraphUtils.py.

713 def setNCores(process_dir, Ncores=None):
714  my_Ncores = Ncores
715  my_runMode = 2 if 'ATHENA_CORE_NUMBER' in os.environ else 0
716  if Ncores is None and 'ATHENA_CORE_NUMBER' in os.environ and int(os.environ['ATHENA_CORE_NUMBER'])>0:
717  my_Ncores = int(os.environ['ATHENA_CORE_NUMBER'])
718  my_runMode = 2
719  if my_Ncores is None:
720  mglog.info('Setting up for serial run')
721  my_Ncores = 1
722 
723  modify_config_card(process_dir=process_dir,settings={'nb_core':my_Ncores,'run_mode':my_runMode,'automatic_html_opening':'False'})
724 
725 
726 
727 
728 
729 
730 

◆ setup_bias_module()

def python.MadGraphUtils.setup_bias_module (   bias_module,
  process_dir 
)

Definition at line 1233 of file MadGraphUtils.py.

1233 def setup_bias_module(bias_module,process_dir):
1234  run_card = process_dir+'/Cards/run_card.dat'
1235  if isinstance(bias_module,tuple):
1236  mglog.info('Using bias module '+bias_module[0])
1237  the_run_card = open(run_card,'r')
1238  for line in the_run_card:
1239  if 'bias_module' in line and not bias_module[0] in line:
1240  raise RuntimeError('You need to add the bias module '+bias_module[0]+' to the run card to actually run it')
1241  the_run_card.close()
1242  if len(bias_module)!=3:
1243  raise RuntimeError('Please give a 3-tuple of strings containing bias module name, bias module, and makefile. Alternatively, give path to bias module tarball.')
1244  bias_module_newpath=process_dir+'/Source/BIAS/'+bias_module[0]
1245  os.makedirs(bias_module_newpath)
1246  bias_module_file=open(bias_module_newpath+'/'+bias_module[0]+'.f','w')
1247  bias_module_file.write(bias_module[1])
1248  bias_module_file.close()
1249  bias_module_make_file=open(bias_module_newpath+'/Makefile','w')
1250  bias_module_make_file.write(bias_module[2])
1251  bias_module_make_file.close()
1252  else:
1253  mglog.info('Using bias module '+bias_module)
1254  bias_module_name=bias_module.split('/')[-1].replace('.gz','')
1255  bias_module_name=bias_module_name.replace('.tar','')
1256  the_run_card = open(run_card,'r')
1257  for line in the_run_card:
1258  if 'bias_module' in line and bias_module_name not in line:
1259  raise RuntimeError('You need to add the bias module '+bias_module_name+' to the run card to actually run it')
1260  the_run_card.close()
1261 
1262  if os.path.exists(bias_module+'.tar.gz'):
1263  bias_module_path=bias_module+'.tar.gz'
1264  elif os.path.exists(bias_module+'.gz'):
1265  bias_module_path=bias_module+'.gz'
1266  elif os.path.exists(bias_module):
1267  bias_module_path=bias_module
1268  else:
1269  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')
1270  return 1
1271  bias_module_newpath=process_dir+'/Source/BIAS/'+bias_module_path.split('/')[-1]
1272  mglog.info('Copying bias module into place: '+bias_module_newpath)
1273  shutil.copy(bias_module_path,bias_module_newpath)
1274  mglog.info('Unpacking bias module')
1275  if bias_module_newpath.endswith('.tar.gz'):
1276  untar = stack_subprocess(['tar','xvzf',bias_module_newpath,'--directory='+process_dir+'/Source/BIAS/'])
1277  untar.wait()
1278  elif bias_module_path.endswith('.gz'):
1279  gunzip = stack_subprocess(['gunzip',bias_module_newpath])
1280  gunzip.wait()
1281 
1282 

◆ setupFastjet()

def python.MadGraphUtils.setupFastjet (   process_dir = None)

Definition at line 533 of file MadGraphUtils.py.

533 def setupFastjet(process_dir=None):
534 
535  isNLO=is_NLO_run(process_dir=process_dir)
536 
537  mglog.info('Path to fastjet install dir: '+os.environ['FASTJETPATH'])
538  fastjetconfig = os.environ['FASTJETPATH']+'/bin/fastjet-config'
539 
540  mglog.info('fastjet-config --version: '+str(subprocess.Popen([fastjetconfig, '--version'],stdout = subprocess.PIPE).stdout.read().strip()))
541  mglog.info('fastjet-config --prefix: '+str(subprocess.Popen([fastjetconfig, '--prefix'],stdout = subprocess.PIPE).stdout.read().strip()))
542 
543  if not isNLO:
544  config_card=process_dir+'/Cards/me5_configuration.txt'
545  else:
546  config_card=process_dir+'/Cards/amcatnlo_configuration.txt'
547 
548  oldcard = open(config_card,'r')
549  newcard = open(config_card+'.tmp','w')
550 
551  for line in oldcard:
552  if 'fastjet = ' in line:
553  newcard.write('fastjet = '+fastjetconfig+'\n')
554  mglog.info('Setting fastjet = '+fastjetconfig+' in '+config_card)
555  else:
556  newcard.write(line)
557  oldcard.close()
558  newcard.close()
559  shutil.move(config_card+'.tmp',config_card)
560 
561  return
562 
563 
564 

◆ setupLHAPDF()

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

Definition at line 565 of file MadGraphUtils.py.

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

◆ stack_subprocess()

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

Definition at line 47 of file MadGraphUtils.py.

47 def stack_subprocess(command,**kwargs):
48  global MADGRAPH_COMMAND_STACK
49  MADGRAPH_COMMAND_STACK += [' '.join(command)]
50  return subprocess.Popen(command,**kwargs)
51 
52 
53 
54 
55 

◆ update_lhe_file()

def 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 1325 of file MadGraphUtils.py.

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

Variable Documentation

◆ MADGRAPH_CATCH_ERRORS

bool python.MadGraphUtils.MADGRAPH_CATCH_ERRORS = True

Definition at line 26 of file MadGraphUtils.py.

◆ MADGRAPH_COMMAND_STACK

list python.MadGraphUtils.MADGRAPH_COMMAND_STACK = []

Definition at line 29 of file MadGraphUtils.py.

◆ MADGRAPH_GRIDPACK_LOCATION

string python.MadGraphUtils.MADGRAPH_GRIDPACK_LOCATION = 'madevent'

Definition at line 22 of file MadGraphUtils.py.

◆ MADGRAPH_PDFSETTING

python.MadGraphUtils.MADGRAPH_PDFSETTING = None

Definition at line 28 of file MadGraphUtils.py.

◆ MADGRAPH_RUN_NAME

string python.MadGraphUtils.MADGRAPH_RUN_NAME = 'run_01'

Definition at line 24 of file MadGraphUtils.py.

◆ mglog

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

Definition at line 16 of file MadGraphUtils.py.

◆ my_MGC_instance

python.MadGraphUtils.my_MGC_instance = None

Definition at line 17 of file MadGraphUtils.py.

◆ patched_shutil_loc

string python.MadGraphUtils.patched_shutil_loc = '/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/shutil_patch'

Definition at line 31 of file MadGraphUtils.py.

◆ python

string python.MadGraphUtils.python = 'python'

Definition at line 20 of file MadGraphUtils.py.

DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.LHAPDFsupport.get_LHAPDF_PATHS
def get_LHAPDF_PATHS()
Definition: LHAPDFsupport.py:17
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
vtune_athena.format
format
Definition: vtune_athena.py:14
python.MadGraphUtilsHelpers.checkSettingIsTrue
def checkSettingIsTrue(key_, mydict_)
Definition: MadGraphUtilsHelpers.py:52
python.MadGraphUtils.modify_param_card
def modify_param_card(param_card_input=None, param_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, params={}, output_location=None)
Definition: MadGraphUtils.py:1447
python.MadGraphUtilsHelpers.is_NLO_run
def is_NLO_run(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtilsHelpers.py:268
python.MadGraphUtils.arrange_output
def arrange_output(process_dir=MADGRAPH_GRIDPACK_LOCATION, lhe_version=None, saveProcDir=False, runArgs=None, fixEventWeightsForBridgeMode=False)
Definition: MadGraphUtils.py:923
python.MadGraphUtilsHelpers.get_runArgs_info
def get_runArgs_info(runArgs)
Definition: MadGraphUtilsHelpers.py:105
python.MadGraphUtils.setupLHAPDF
def setupLHAPDF(process_dir=None, extlhapath=None, allow_links=True)
Definition: MadGraphUtils.py:565
python.MadGraphUtils.ls_dir
def ls_dir(directory)
Definition: MadGraphUtils.py:2000
python.MadGraphUtilsHelpers.checkSetting
def checkSetting(key_, value_, mydict_)
Definition: MadGraphUtilsHelpers.py:44
python.MadGraphUtilsHelpers.setup_path_protection
def setup_path_protection()
Definition: MadGraphUtilsHelpers.py:234
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
python.MadGraphUtils.update_lhe_file
def update_lhe_file(lhe_file_old, param_card_old=None, lhe_file_new=None, masses={}, delete_old_lhe=True)
Definition: MadGraphUtils.py:1325
python.MadGraphParamHelpers.check_PMG_updates
def check_PMG_updates(process_dir)
Definition: MadGraphParamHelpers.py:154
python.MadGraphUtils.new_process
def new_process(process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False)
Definition: MadGraphUtils.py:81
python.MadGraphUtils.modify_config_card
def modify_config_card(config_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, settings={}, set_commented=True)
Definition: MadGraphUtils.py:1782
python.MadGraphUtils.check_reweight_card
def check_reweight_card(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:1289
python.MadGraphUtils.get_default_runcard
def get_default_runcard(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:91
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.MadGraphUtils.generate
def 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: MadGraphUtils.py:112
python.MadGraphUtils.print_cards
def 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: MadGraphUtils.py:1602
python.MadGraphUtils.is_gen_from_gridpack
def is_gen_from_gridpack()
Definition: MadGraphUtils.py:1647
python.MadGraphUtils.get_expected_systematic_names
def get_expected_systematic_names(syst_setting)
Definition: MadGraphUtils.py:1215
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
python.MadGraphUtils.add_madspin
def add_madspin(madspin_card=None, process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:780
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.MadGraphUtils.generate_prep
def generate_prep(process_dir)
Definition: MadGraphUtils.py:56
python.MadGraphUtils.modify_run_card
def modify_run_card(run_card_input=None, run_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, runArgs=None, settings={}, skipBaseFragment=False)
Definition: MadGraphUtils.py:1660
python.MadGraphUtils.setup_bias_module
def setup_bias_module(bias_module, process_dir)
Definition: MadGraphUtils.py:1233
python.MadGraphUtilsHelpers.get_default_config_card
def get_default_config_card(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtilsHelpers.py:253
python.MadGraphUtils.run_card_consistency_check
def run_card_consistency_check(isNLO=False, process_dir='.')
Definition: MadGraphUtils.py:1851
python.MadGraphUtils.setupFastjet
def setupFastjet(process_dir=None)
Definition: MadGraphUtils.py:533
python.MadGraphUtilsHelpers.error_check
def error_check(errors_a, return_code)
Definition: MadGraphUtilsHelpers.py:119
python.MadGraphUtilsHelpers.checkSettingExists
def checkSettingExists(key_, mydict_)
Definition: MadGraphUtilsHelpers.py:59
Trk::open
@ open
Definition: BinningType.h:40
python.MadGraphUtils.fix_fks_makefile
def fix_fks_makefile(process_dir)
Definition: MadGraphUtils.py:2008
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.MadGraphUtils.setNCores
def setNCores(process_dir, Ncores=None)
Definition: MadGraphUtils.py:713
python.MadGraphUtils.generate_from_gridpack
def generate_from_gridpack(runArgs=None, extlhapath=None, gridpack_compile=None, requirePMGSettings=False)
Definition: MadGraphUtils.py:331
python.JOsupport.get_physics_short
def get_physics_short()
Definition: JOsupport.py:12
python.MadGraphUtils.get_expected_reweight_names
def get_expected_reweight_names(reweight_card_loc)
Definition: MadGraphUtils.py:1199
python.MadGraphUtils.get_mg5_executable
def get_mg5_executable()
Definition: MadGraphUtils.py:731
python.MadGraphUtils.get_cluster_type
def get_cluster_type(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:1839
str
Definition: BTagTrackIpAccessor.cxx:11
python.MadGraphUtils.get_reweight_card
def get_reweight_card(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:1283
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
python.MadGraphUtils.madspin_on_lhe
def madspin_on_lhe(input_LHE, madspin_card, runArgs=None, keep_original=False)
Definition: MadGraphUtils.py:835
python.MadGraphUtils.print_cards_from_dir
def print_cards_from_dir(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:1596
python.LHAPDFsupport.get_lhapdf_id_and_name
def get_lhapdf_id_and_name(pdf)
Definition: LHAPDFsupport.py:33
python.MadGraphUtils.add_reweighting
def add_reweighting(run_name, reweight_card=None, process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:1985
python.MadGraphUtils.stack_subprocess
def stack_subprocess(command, **kwargs)
Definition: MadGraphUtils.py:47
python.MadGraphUtils.add_lifetimes
def add_lifetimes(process_dir, threshold=None)
Definition: MadGraphUtils.py:738
python.MadGraphUtils.find_key_and_update
def find_key_and_update(akey, dictionary)
Definition: MadGraphUtils.py:1432
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.MadGraphUtilsHelpers.getDictFromCard
def getDictFromCard(card_loc, lowercase=False)
Definition: MadGraphUtilsHelpers.py:14
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65