ATLAS Offline Software
Loading...
Searching...
No Matches
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
8import os
9
10from . import Herwig7Config as hw7Config
11from . import Herwig7Control as hw7Control
12from . import Herwig7Utils as hw7Utils
13
14from AthenaCommon import Logging
15athMsgLog = Logging.logging.getLogger('Herwig7ConfigMatchbox')
16
17
18
211class 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
250set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:BinDir {0}
251set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:DataDir {1}
252set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:MadgraphPrefix {2}
253
254##Fixing interface locations of Openloops
255set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsLibs {3}
256set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsPrefix {4}
257
258read snippets/Matchbox.in
259read 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
274do /Herwig/MatrixElements/Matchbox/Factory:ProductionMode
275saverun {} /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
287 self.default_commands += self.printout_commands()
289 self.default_commands += self.physics_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##################################################
391set /Herwig/Samplers/Sampler:BinSampler /Herwig/Samplers/{}
392set /Herwig/Samplers/Sampler:BinSampler:InitialPoints {}
393set /Herwig/Samplers/Sampler:BinSampler:NIterations {}
394set /Herwig/Samplers/Sampler:BinSampler:RemapperPoints {}
395set /Herwig/Samplers/Sampler:BinSampler:Alpha {}
396set /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 += """
401set /Herwig/Samplers/CellGridSampler:ExplorationSteps {}
402set /Herwig/Samplers/CellGridSampler:ExplorationPoints {}
403""".format(exploration_steps, exploration_points)
Configuration class for Matchbox runs with Herwig7.
do_run(self, gridpack=None, cleanup_herwig_scratch=True)
Atomic steering function for possibly unpacking a gridpack and generating events.
do_build(self, integration_jobs)
Atomic steering function for doing the build step alone.
__init__(self, genSeq, runArgs, run_name="Herwig", beams="pp")
Initialize a generator configuration object for the Matchbox run mode.
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.
do_integrate(self, integration_job)
Atomic steering function for doing one specific integration job.
do_mergegrids(self, integration_jobs, gridpack=None)
Atomic steering function for combining the integration grids and possibly creating a gridpack.
beams
provide variables initialized by the parent class
Definition run.py:1