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:
238  OpenLoops_path= os.environ['OPENLOOPSPATH']
239  except KeyError:
240  raise RuntimeError("OPENLOOPSPATH environment variable not set")
241  if not os.path.isdir(os.path.join(OpenLoops_path, "proclib")):
242  athMsgLog.warn(hw7Utils.ansi_format_warning("The OpenLoops process libraries can't be found from $OPENLOOPS_PATH = {}".format(OpenLoops_path)))
243 
244  return """
245 ## ================================================
246 ## Local Pre-Commands from Herwig7ConfigMatchbox.py
247 ## ================================================
248 
249 ## Fixing interface locations for MadGraph
250 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:BinDir {0}
251 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:DataDir {1}
252 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:MadgraphPrefix {2}
253 
254 ##Fixing interface locations of Openloops
255 set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsLibs {3}
256 set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsPrefix {4}
257 
258 read snippets/Matchbox.in
259 read snippets/{4}Collider.in
260 """.format(hw7Control.herwig7_bin_path,
261  hw7Control.herwig7_share_path,
262  MG5aMC_path,
263  os.path.join(OpenLoops_path,"proclib"),
264  OpenLoops_path)
265 
266 
268 
269  return """
270 ## =================================================
271 ## Local Post-Commands from Herwig7ConfigMatchbox.py
272 ## =================================================
273 
274 do /Herwig/MatrixElements/Matchbox/Factory:ProductionMode
275 saverun {} /Herwig/Generators/EventGenerator
276 """.format(self.run_name)
277 
278 
279  def __configure(self):
280 
281 
282 
283  self.default_commands += self.energy_commands()
284  self.default_commands += self.random_seed_commands()
285 
286  if not self.set_printout_commands:
287  self.default_commands += self.printout_commands()
288  if not self.set_physics_parameter_commands:
289  self.default_commands += self.physics_parameter_commands()
290  if not self.set_technical_parameter_commands:
291  self.default_commands += self.technical_parameter_commands()
292 
293 
294 
309  def run(self, integration_jobs=1, gridpack=None, cleanup_herwig_scratch=True, integrate=False):
310 
311  self.__configure()
312 
313  if gridpack:
314  hw7Control.matchbox_run_gridpack(self, integration_jobs, gridpack, cleanup_herwig_scratch, integrate)
315  else:
316  hw7Control.matchbox_run(self, integration_jobs, cleanup_herwig_scratch)
317 
318 
319  # atomic functions for complete control from within the JobOptions ----------
320 
321 
328  def do_build(self, integration_jobs):
329  self.__configure()
330  hw7Control.do_build(self, integration_jobs)
331  hw7Control.do_abort()
332 
333 
335  def do_integrate(self, integration_job):
336  hw7Control.do_integrate(self.run_name, integration_job)
337  hw7Control.do_abort()
338 
339 
344  def do_mergegrids(self, integration_jobs, gridpack=None):
345  hw7Control.do_mergegrids(self.run_name, integration_jobs)
346  if gridpack:
347  hw7Control.do_compress_gridpack(self.run_name, gridpack)
348  hw7Control.do_abort()
349 
350 
355  def do_run(self, gridpack=None, cleanup_herwig_scratch=True):
356  if gridpack:
357  hw7Control.do_uncompress_gridpack(gridpack)
358  hw7Control.do_run(self, cleanup_herwig_scratch)
359 
360 
361  # configuration commands ----------------------------------------------------
362 
363 
378  def sampler_commands(self, bin_sampler="CellGridSampler",
379  initial_points=10000, n_iterations=1, remapper_points=50000,
380  exploration_steps=4, exploration_points=500, alpha=0.8, grid_divisions=48):
381 
382  bin_samplers = ["CellGridSampler", "MonacoSampler", "FlatBinSampler"]
383 
384  if bin_sampler not in bin_samplers:
385  raise RuntimeError(hw7Utils.ansi_format_error("Parameter 'bin_sampler' must be one of {}!".format(bin_samplers)))
386 
387  self.commands += """
388 ##################################################
389 ## Sampler Configuration
390 ##################################################
391 set /Herwig/Samplers/Sampler:BinSampler /Herwig/Samplers/{}
392 set /Herwig/Samplers/Sampler:BinSampler:InitialPoints {}
393 set /Herwig/Samplers/Sampler:BinSampler:NIterations {}
394 set /Herwig/Samplers/Sampler:BinSampler:RemapperPoints {}
395 set /Herwig/Samplers/Sampler:BinSampler:Alpha {}
396 set /Herwig/Samplers/Sampler:BinSampler:GridDivisions {}
397 """.format(bin_sampler, initial_points, n_iterations, remapper_points, alpha, grid_divisions)
398 
399  if bin_sampler == "CellGridSampler":
400  self.commands += """
401 set /Herwig/Samplers/CellGridSampler:ExplorationSteps {}
402 set /Herwig/Samplers/CellGridSampler:ExplorationPoints {}
403 """.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:335
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:355
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.__configure
def __configure(self)
Definition: Herwig7ConfigMatchbox.py:279
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:309
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.local_post_commands
def local_post_commands(self)
Definition: Herwig7ConfigMatchbox.py:267
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:328
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:378
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:344
Herwig7ConfigMatchbox.Hw7ConfigMatchbox.beams
beams
provide variables initialized by the parent class
Definition: Herwig7ConfigMatchbox.py:224