ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.MGC.MGControl Class Reference
Collaboration diagram for python.MGC.MGControl:

Public Member Functions

def __init__ (self, process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False)
 
def change_run_card (self, run_card_input=None, run_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, runArgs=None, settings={}, skipBaseFragment=False)
 
def change_config_card (self, config_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, settings={}, set_commented=True)
 

Public Attributes

 mglog
 
 process
 
 plugin
 
 keepJpegs
 
 usePMGSettings
 
 run_card_params
 
 is_gen_from_gridpack
 
 process_dir
 
 MADGRAPH_COMMAND_STACK
 
 runCardDict
 

Detailed Description

Definition at line 28 of file MGC.py.

Constructor & Destructor Documentation

◆ __init__()

def python.MGC.MGControl.__init__ (   self,
  process = 'generate p p > t t~\noutput -f',
  plugin = None,
  keepJpegs = False,
  usePMGSettings = False 
)
Generate a new process in madgraph.
Pass a process string.
Optionally request JPEGs to be kept and request for PMG settings to be used in the param card
Return the name of the process directory.

Definition at line 29 of file MGC.py.

29  def __init__(self, process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False):
30  """ Generate a new process in madgraph.
31  Pass a process string.
32  Optionally request JPEGs to be kept and request for PMG settings to be used in the param card
33  Return the name of the process directory.
34  """
35  self.mglog = Logging.logging.getLogger('MadGraphUtils')
36  self.process = process
37  self.plugin = plugin
38  self.keepJpegs = keepJpegs
39  self.usePMGSettings = usePMGSettings
40  self.run_card_params = []
41  #is_gen_from gridpack
42  self.is_gen_from_gridpack = os.access(MADGRAPH_GRIDPACK_LOCATION,os.R_OK)
43  # Don't run if generating events from gridpack
44  if self.is_gen_from_gridpack:
45  self.process_dir = MADGRAPH_GRIDPACK_LOCATION
46  return
47  # Actually just sent the process card contents - let's make a card
48  card_loc='proc_card_mg5.dat'
49  mglog.info('Writing process card to '+card_loc)
50  a_card = open( card_loc , 'w' )
51  for l in process.split('\n'):
52  if 'output' not in l:
53  a_card.write(l+'\n')
54  elif '-nojpeg' in l or keepJpegs:
55  a_card.write(l+'\n')
56  elif '#' in l:
57  a_card.write(l.split('#')[0]+' -nojpeg #'+l.split('#')[1]+'\n')
58  else:
59  a_card.write(l+' -nojpeg\n')
60  a_card.close()
61 
62  madpath=os.environ['MADPATH']
63  # Just in case
65 
66  # Check if we have a special output directory
67  process_dir = ''
68  for l in process.split('\n'):
69  # Look for an output line
70  if 'output' not in l.split('#')[0].split():
71  continue
72  # Check how many things before the options start
73  tmplist = l.split('#')[0].split(' -')[0]
74  # if two things, second is the directory
75  if len(tmplist.split())==2:
76  process_dir = tmplist.split()[1]
77  # if three things, third is the directory (second is the format)
78  elif len(tmplist.split())==3:
79  process_dir = tmplist.split()[2]
80  # See if we got a directory
81  if ''!=process_dir:
82  mglog.info('Saw that you asked for a special output directory: '+str(process_dir))
83  break
84 
85  mglog.info('Started process generation at '+str(time.asctime()))
86 
87  plugin_cmd = '--mode='+plugin if plugin is not None else ''
88 
89  # Note special handling here to explicitly print the process
90  self.MADGRAPH_COMMAND_STACK = [] #want to change to variable
91  self.MADGRAPH_COMMAND_STACK += ['# All jobs should start in a clean directory']
92  self.MADGRAPH_COMMAND_STACK += ['mkdir standalone_test; cd standalone_test']
93  self.MADGRAPH_COMMAND_STACK += [' '.join([python,madpath+'/bin/mg5_aMC '+plugin_cmd+' << EOF\n'+process+'\nEOF\n'])]
94  global MADGRAPH_CATCH_ERRORS
95  generate = subprocess.Popen([python,madpath+'/bin/mg5_aMC',plugin_cmd,card_loc],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
96  (out,err) = generate.communicate()
97  error_check(err,generate.returncode)
98 
99  mglog.info('Finished process generation at '+str(time.asctime()))
100 
101  # at this point process_dir is for sure defined - it's equal to '' in the worst case
102  if process_dir == '': # no user-defined value, need to find the directory created by MadGraph5
103  for adir in sorted(glob.glob( os.getcwd()+'/*PROC*' ),reverse=True):
104  if os.access('%s/SubProcesses/subproc.mg'%adir,os.R_OK):
105  if process_dir=='':
106  process_dir=adir
107  else:
108  mglog.warning('Additional possible process directory, '+adir+' found. Had '+process_dir)
109  mglog.warning('Likely this is because you did not run from a clean directory, and this may cause errors later.')
110  else: # user-defined directory
111  if not os.access('%s/SubProcesses/subproc.mg'%process_dir,os.R_OK):
112  raise RuntimeError('No diagrams for this process in user-define dir='+str(process_dir))
113  if process_dir=='':
114  raise RuntimeError('No diagrams for this process from list: '+str(sorted(glob.glob(os.getcwd()+'/*PROC*'),reverse=True)))
115 
116  # Special catch related to path setting and using afs
117  needed_options = ['ninja','collier','fastjet','lhapdf','syscalc_path']
118  in_config = open(os.environ['MADPATH']+'/input/mg5_configuration.txt','r')
119  option_paths = {}
120  for l in in_config.readlines():
121  for o in needed_options:
122  if o+' =' in l.split('#')[0] and 'MCGenerators' in l.split('#')[0]:
123  old_path = l.split('#')[0].split('=')[1].strip().split('MCGenerators')[1]
124  old_path = old_path[ old_path.find('/') : ]
125  if o =='lhapdf' and 'LHAPATH' in os.environ:
126  # Patch for LHAPDF version
127  version = os.environ['LHAPATH'].split('lhapdf/')[1].split('/')[0]
128  old_version = old_path.split('lhapdf/')[1].split('/')[0]
129  old_path = old_path.replace(old_version,version)
130  if o=='ninja':
131  # Patch for stupid naming problem
132  old_path.replace('gosam_contrib','gosam-contrib')
133  option_paths[o] = os.environ['MADPATH'].split('madgraph5amc')[0]+old_path
134  # Check to see if the option has been commented out
135  if o+' =' in l and o+' =' not in l.split('#')[0]:
136  mglog.info('Option '+o+' appears commented out in the config file')
137 
138  in_config.close()
139  for o in needed_options:
140  if o not in option_paths:
141  mglog.info('Path for option '+o+' not found in original config')
142 
143  mglog.info('Modifying config paths to avoid use of afs:')
144  mglog.info(option_paths)
145 
146  # Set the paths appropriately
147  self.change_config_card(process_dir=process_dir,settings=option_paths,set_commented=False)
148  # Done modifying paths
149 
150  # If requested, apply PMG default settings
151  if usePMGSettings:
152  do_PMG_updates(process_dir)
153 
154  # After 2.9.3, enforce the standard default sde_strategy, so that this won't randomly change on the user
155  if is_version_or_newer([2,9,3]) and not is_NLO_run(process_dir=process_dir):
156  mglog.info('Setting default sde_strategy to old default (1)')
157  my_settings = {'sde_strategy':1}
158  self.change_run_card(process_dir=process_dir,settings=my_settings,skipBaseFragment=True)
159 
160  #tell MadGraph not to bother trying to create popup windows since this is running in a CLI, this will save ~50 seconds every time MadGraph is called.
161  self.change_config_card(process_dir=process_dir,settings={'notification_center':'False'})
162 
163  # Make sure we store the resultant directory
164  self.MADGRAPH_COMMAND_STACK += ['export MGaMC_PROCESS_DIR='+os.path.basename(process_dir)]
165  self.runCardDict = getDictFromCard(process_dir+'/Cards/run_card.dat')
166  self.process_dir = process_dir
167 

Member Function Documentation

◆ change_config_card()

def python.MGC.MGControl.change_config_card (   self,
  config_card_backup = None,
  process_dir = MADGRAPH_GRIDPACK_LOCATION,
  settings = {},
  set_commented = True 
)

Definition at line 172 of file MGC.py.

172  def change_config_card(self, config_card_backup=None,process_dir=MADGRAPH_GRIDPACK_LOCATION,settings={},set_commented=True ):
173  self.mglog.warning('Do not call this function, just update self.run_card_params')
174  self.run_card_params += [ config_card_backup,process_dir,settings,set_commented ]

◆ change_run_card()

def python.MGC.MGControl.change_run_card (   self,
  run_card_input = None,
  run_card_backup = None,
  process_dir = MADGRAPH_GRIDPACK_LOCATION,
  runArgs = None,
  settings = {},
  skipBaseFragment = False 
)

Definition at line 168 of file MGC.py.

168  def change_run_card(self, run_card_input=None,run_card_backup=None,process_dir=MADGRAPH_GRIDPACK_LOCATION,runArgs=None,settings={},skipBaseFragment=False ):
169  self.mglog.warning('Do not call this function, just update self.run_card_params')
170  self.run_card_params += [run_card_input,run_card_backup,process_dir,runArgs,settings,skipBaseFragment ]
171 

Member Data Documentation

◆ is_gen_from_gridpack

python.MGC.MGControl.is_gen_from_gridpack

Definition at line 42 of file MGC.py.

◆ keepJpegs

python.MGC.MGControl.keepJpegs

Definition at line 38 of file MGC.py.

◆ MADGRAPH_COMMAND_STACK

python.MGC.MGControl.MADGRAPH_COMMAND_STACK

Definition at line 90 of file MGC.py.

◆ mglog

python.MGC.MGControl.mglog

Definition at line 35 of file MGC.py.

◆ plugin

python.MGC.MGControl.plugin

Definition at line 37 of file MGC.py.

◆ process

python.MGC.MGControl.process

Definition at line 36 of file MGC.py.

◆ process_dir

python.MGC.MGControl.process_dir

Definition at line 45 of file MGC.py.

◆ run_card_params

python.MGC.MGControl.run_card_params

Definition at line 40 of file MGC.py.

◆ runCardDict

python.MGC.MGControl.runCardDict

Definition at line 165 of file MGC.py.

◆ usePMGSettings

python.MGC.MGControl.usePMGSettings

Definition at line 39 of file MGC.py.


The documentation for this class was generated from the following file:
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.
python.MadGraphParamHelpers.do_PMG_updates
def do_PMG_updates(process_dir)
Definition: MadGraphParamHelpers.py:144
python.MadGraphUtilsHelpers.is_NLO_run
def is_NLO_run(process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtilsHelpers.py:268
python.MadGraphUtilsHelpers.setup_path_protection
def setup_path_protection()
Definition: MadGraphUtilsHelpers.py:234
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.MadGraphUtilsHelpers.error_check
def error_check(errors_a, return_code)
Definition: MadGraphUtilsHelpers.py:119
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.MadGraphUtilsHelpers.getDictFromCard
def getDictFromCard(card_loc, lowercase=False)
Definition: MadGraphUtilsHelpers.py:14
python.MadGraphUtilsHelpers.is_version_or_newer
def is_version_or_newer(args)
Definition: MadGraphUtilsHelpers.py:66