ATLAS Offline Software
Herwig7ConfigMatchbox.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 
7 
8 import os
9 
10 from . import Herwig7Config as hw7Config
11 from . import Herwig7Control as hw7Control
12 from . import Herwig7Utils as hw7Utils
13 
14 from AthenaCommon import Logging
15 athMsgLog = Logging.logging.getLogger('Herwig7ConfigMatchbox')
16 
17 
18 
211 class Hw7ConfigMatchbox(hw7Config.Hw7Config):
212 
213 
214 
215  def __init__(self, genSeq, runArgs, run_name="Herwig", beams="pp"):
216 
217  beams = beams.upper()
218  if beams not in ["EE", "EP", "PP"]:
219  raise RuntimeError(hw7Utils.ansi_format_error("Parameter 'beams' must be one of the following ['EE', 'EP', 'PP']!"))
220 
221 
222  super(Hw7ConfigMatchbox, self).__init__(genSeq, runArgs, run_name)
223 
224  self.beams = beams
225 
226 
228 
229  # try to locate the MG5_aMC@NLO installation
230  try:
231  MG5aMC_path = os.environ['MADPATH']
232  except KeyError:
233  raise RuntimeError("MADPATH environment variable not set")
234  if not os.path.isfile(os.path.join(MG5aMC_path, 'bin', 'mg5_aMC')):
235  athMsgLog.warn(hw7Utils.ansi_format_warning("The MadGraph5_aMC@NLO installation can't be found from $MADPATH = {}, so don't be surprised if your run crashes in you are using matrix elements from MG5_aMC@NLO in Herwig7 / Matchbox. Please ensure that the location exists, that you have permissions to access it and that it contains the executable 'bin/mg5_aMC'".format(MG5aMC_path)))
236 
237  # try to locate the GoSam installation
238  try:
239  GoSam_path = os.environ['GOSAM_PATH']
240  except KeyError:
241  raise RuntimeError("GOSAM_PATH environment variable not set")
242  if not os.path.isfile(os.path.join(GoSam_path, 'bin', 'gosam.py')):
243  athMsgLog.warn(hw7Utils.ansi_format_warning("The GoSam installation can't be found from $GOSAMPATH = {}, so don't be surprised if your run crashes in you are using matrix elements from GoSam in Herwig7 / Matchbox. Please ensure that the location exists, that you have permissions to access it and that it contains the script 'bin/gosam.py'".format(GoSam_path)))
244 
245  try:
246  OpenLoops_path= os.environ['OPENLOOPSPATH']
247  except KeyError:
248  raise RuntimeError("OPENLOOPSPATH environment variable not set")
249  if not os.path.isdir(os.path.join(OpenLoops_path, "proclib")):
250  athMsgLog.warn(hw7Utils.ansi_format_warning("The OpenLoops process libraries can't be found from $OPENLOOPS_PATH = {}".format(OpenLoops_path)))
251 
252  return """
253 ## ================================================
254 ## Local Pre-Commands from Herwig7ConfigMatchbox.py
255 ## ================================================
256 
257 ## Fixing interface locations for MadGraph
258 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:BinDir {0}
259 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:DataDir {1}
260 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:MadgraphPrefix {2}
261 
262 ## Fixing interface locations for GoSam
263 set /Herwig/MatrixElements/Matchbox/Amplitudes/GoSam:BinDir {0}
264 set /Herwig/MatrixElements/Matchbox/Amplitudes/GoSam:DataDir {1}
265 set /Herwig/MatrixElements/Matchbox/Amplitudes/GoSam:GoSamPrefix {3}
266 
267 ##Fixing interface locations of Openloops
268 set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsLibs {5}
269 set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsPrefix {6}
270 
271 read snippets/Matchbox.in
272 read snippets/{4}Collider.in
273 """.format(hw7Control.herwig7_bin_path,
274  hw7Control.herwig7_share_path,
275  MG5aMC_path,
276  GoSam_path,
277  self.beams,
278  os.path.join(OpenLoops_path,"proclib"),
279  OpenLoops_path)
280 
281 
283 
284  return """
285 ## =================================================
286 ## Local Post-Commands from Herwig7ConfigMatchbox.py
287 ## =================================================
288 
289 do /Herwig/MatrixElements/Matchbox/Factory:ProductionMode
290 saverun {} /Herwig/Generators/EventGenerator
291 """.format(self.run_name)
292 
293 
294  def __configure(self):
295 
296 
297 
298  self.default_commands += self.energy_commands()
299  self.default_commands += self.random_seed_commands()
300 
301  if not self.set_printout_commands:
302  self.default_commands += self.printout_commands()
303  if not self.set_physics_parameter_commands:
304  self.default_commands += self.physics_parameter_commands()
305  if not self.set_technical_parameter_commands:
306  self.default_commands += self.technical_parameter_commands()
307 
308 
309 
324  def run(self, integration_jobs=1, gridpack=None, cleanup_herwig_scratch=True, integrate=False):
325 
326  self.__configure()
327 
328  if gridpack:
329  hw7Control.matchbox_run_gridpack(self, integration_jobs, gridpack, cleanup_herwig_scratch, integrate)
330  else:
331  hw7Control.matchbox_run(self, integration_jobs, cleanup_herwig_scratch)
332 
333 
334  # atomic functions for complete control from within the JobOptions ----------
335 
336 
343  def do_build(self, integration_jobs):
344  self.__configure()
345  hw7Control.do_build(self, integration_jobs)
346  hw7Control.do_abort()
347 
348 
350  def do_integrate(self, integration_job):
351  hw7Control.do_integrate(self.run_name, integration_job)
352  hw7Control.do_abort()
353 
354 
359  def do_mergegrids(self, integration_jobs, gridpack=None):
360  hw7Control.do_mergegrids(self.run_name, integration_jobs)
361  if gridpack:
362  hw7Control.do_compress_gridpack(self.run_name, gridpack)
363  hw7Control.do_abort()
364 
365 
370  def do_run(self, gridpack=None, cleanup_herwig_scratch=True):
371  if gridpack:
372  hw7Control.do_uncompress_gridpack(gridpack)
373  hw7Control.do_run(self, cleanup_herwig_scratch)
374 
375 
376  # configuration commands ----------------------------------------------------
377 
378 
393  def sampler_commands(self, bin_sampler="CellGridSampler",
394  initial_points=10000, n_iterations=1, remapper_points=50000,
395  exploration_steps=4, exploration_points=500, alpha=0.8, grid_divisions=48):
396 
397  bin_samplers = ["CellGridSampler", "MonacoSampler", "FlatBinSampler"]
398 
399  if bin_sampler not in bin_samplers:
400  raise RuntimeError(hw7Utils.ansi_format_error("Parameter 'bin_sampler' must be one of {}!".format(bin_samplers)))
401 
402  self.commands += """
403 ##################################################
404 ## Sampler Configuration
405 ##################################################
406 set /Herwig/Samplers/Sampler:BinSampler /Herwig/Samplers/{}
407 set /Herwig/Samplers/Sampler:BinSampler:InitialPoints {}
408 set /Herwig/Samplers/Sampler:BinSampler:NIterations {}
409 set /Herwig/Samplers/Sampler:BinSampler:RemapperPoints {}
410 set /Herwig/Samplers/Sampler:BinSampler:Alpha {}
411 set /Herwig/Samplers/Sampler:BinSampler:GridDivisions {}
412 """.format(bin_sampler, initial_points, n_iterations, remapper_points, alpha, grid_divisions)
413 
414  if bin_sampler == "CellGridSampler":
415  self.commands += """
416 set /Herwig/Samplers/CellGridSampler:ExplorationSteps {}
417 set /Herwig/Samplers/CellGridSampler:ExplorationPoints {}
418 """.format(exploration_steps, exploration_points)
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.do_integrate
def do_integrate(self, integration_job)
Atomic steering function for doing one specific integration job.
Definition: Herwig7ConfigMatchbox.py:350
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.do_run
def do_run(self, gridpack=None, cleanup_herwig_scratch=True)
Atomic steering function for possibly unpacking a gridpack and generating events.
Definition: Herwig7ConfigMatchbox.py:370
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.__configure
def __configure(self)
Definition: Herwig7ConfigMatchbox.py:294
vtune_athena.format
format
Definition: vtune_athena.py:14
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.run
def run(self, integration_jobs=1, gridpack=None, cleanup_herwig_scratch=True, integrate=False)
High-level function for triggering the process setup and the event generation.
Definition: Herwig7ConfigMatchbox.py:324
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.local_post_commands
def local_post_commands(self)
Definition: Herwig7ConfigMatchbox.py:282
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.local_pre_commands
def local_pre_commands(self)
Definition: Herwig7ConfigMatchbox.py:227
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.do_build
def do_build(self, integration_jobs)
Atomic steering function for doing the build step alone.
Definition: Herwig7ConfigMatchbox.py:343
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.sampler_commands
def sampler_commands(self, bin_sampler="CellGridSampler", initial_points=10000, n_iterations=1, remapper_points=50000, exploration_steps=4, exploration_points=500, alpha=0.8, grid_divisions=48)
Configure the sampler.
Definition: Herwig7ConfigMatchbox.py:393
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.__init__
def __init__(self, genSeq, runArgs, run_name="Herwig", beams="pp")
Initialize a generator configuration object for the Matchbox run mode.
Definition: Herwig7ConfigMatchbox.py:215
Herwig7ConfigMatchbox.Hw7ConfigMatchbox
Configuration class for Matchbox runs with Herwig7.
Definition: Herwig7ConfigMatchbox.py:211
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.do_mergegrids
def do_mergegrids(self, integration_jobs, gridpack=None)
Atomic steering function for combining the integration grids and possibly creating a gridpack.
Definition: Herwig7ConfigMatchbox.py:359
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.beams
beams
provide variables initialized by the parent class
Definition: Herwig7ConfigMatchbox.py:224