ATLAS Offline Software
Loading...
Searching...
No Matches
Herwig7ConfigMerging.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
6
7import os
8
9from . import Herwig7Config as hw7Config
10from . import Herwig7Control as hw7Control
11from . import Herwig7Utils as hw7Utils
12
13from AthenaCommon import Logging
14athMsgLog = Logging.logging.getLogger('Herwig7ConfigMerging')
15
16
17
210class Hw7ConfigMerging(hw7Config.Hw7Config):
211
212
213
214 def __init__(self, genSeq, runArgs, run_name="Herwig", beams="pp"):
215
216 beams = beams.upper()
217 if beams not in ["EE", "EP", "PP"]:
218 raise RuntimeError(hw7Utils.ansi_format_error("Parameter 'beams' must be one of the following ['EE', 'EP', 'PP']!"))
219
220
221 super(Hw7ConfigMerging, self).__init__(genSeq, runArgs, run_name)
222
223 self.beams = beams
224
225
227
228 # try to locate the MG5_aMC@NLO installation
229 try:
230 MG5aMC_path = os.environ['MADPATH']
231 except KeyError:
232 raise RuntimeError("MADPATH environment variable not set")
233 if not os.path.isfile(os.path.join(MG5aMC_path, 'bin', 'mg5_aMC')):
234 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)))
235
236 try:
237 OpenLoops_path= os.environ['OPENLOOPSPATH']
238 except KeyError:
239 raise RuntimeError("OPENLOOPSPATH environment variable not set")
240 if not os.path.isdir(os.path.join(OpenLoops_path, "proclib")):
241 athMsgLog.warn(hw7Utils.ansi_format_warning("The OpenLoops process libraries can't be found from $OPENLOOPSPATH = {}".format(OpenLoops_path)))
242
243
244
245 return """
246## ================================================
247## Local Pre-Commands from Herwig7ConfigMerging.py
248## ================================================
249
250## Fixing interface locations for MadGraph
251set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:BinDir {0}
252set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:DataDir {1}
253set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:MadgraphPrefix {2}
254
255##Fixing interface locations of Openloops
256set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsLibs {4}
257set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsPrefix {5}
258
259# Currently the Dipole Snippet is broken (reads to the Rivet interface which we don't build)
260# For now manually copy all the relevant settings in
261read snippets/DipoleMerging.in
262read snippets/{3}Collider.in
263read Merging/Merging-Dipole-FactorCMWSchemeTune.in
264read Merging/FactorCMWScheme.in
265""".format(hw7Control.herwig7_bin_path,
266 hw7Control.herwig7_share_path,
267 MG5aMC_path,
268 self.beams,
269 os.path.join(OpenLoops_path,"proclib"),
270 OpenLoops_path)
271
273
274 return """
275## =================================================
276## Local Post-Commands from Herwig7ConfigMerging.py
277## =================================================
278
279do /Herwig/Merging/MergingFactory:ProductionMode
280saverun {} /Herwig/Generators/EventGenerator
281""".format(self.run_name)
282
283
284 def __configure(self):
285
286
287
288 self.default_commands += self.energy_commands()
289 self.default_commands += self.random_seed_commands()
290
292 self.default_commands += self.printout_commands()
294 self.default_commands += self.physics_parameter_commands()
296 self.default_commands += self.technical_parameter_commands()
297
298
299
314 def run(self, integration_jobs=1, gridpack=None, cleanup_herwig_scratch=True):
315
316 self.__configure()
317
318 if gridpack:
319 hw7Control.matchbox_run_gridpack(self, integration_jobs, gridpack, cleanup_herwig_scratch)
320 else:
321 hw7Control.matchbox_run(self, integration_jobs, cleanup_herwig_scratch)
322
323
324 # atomic functions for complete control from within the JobOptions ----------
325
326
333 def do_build(self, integration_jobs):
334 self.__configure()
335 hw7Control.do_build(self, integration_jobs)
336 hw7Control.do_abort()
337
338
340 def do_integrate(self, integration_job):
341 hw7Control.do_integrate(self.run_name, integration_job)
342 hw7Control.do_abort()
343
344
349 def do_mergegrids(self, integration_jobs, gridpack=None):
350 hw7Control.do_mergegrids(self.run_name, integration_jobs)
351 if gridpack:
352 hw7Control.do_compress_gridpack(self.run_name, gridpack)
353 hw7Control.do_abort()
354
355
360 def do_run(self, gridpack=None, cleanup_herwig_scratch=True):
361 if gridpack:
362 hw7Control.do_uncompress_gridpack(gridpack)
363 hw7Control.do_run(self, cleanup_herwig_scratch)
364
365
366 # configuration commands ----------------------------------------------------
367
368
383 def sampler_commands(self, bin_sampler="CellGridSampler",
384 initial_points=10000, n_iterations=1, remapper_points=50000,
385 exploration_steps=4, exploration_points=500):
386
387 bin_samplers = ["CellGridSampler", "MonacoSampler", "FlatBinSampler"]
388
389 if bin_sampler not in bin_samplers:
390 raise RuntimeError(hw7Utils.ansi_format_error("Parameter 'bin_sampler' must be one of {}!".format(bin_samplers)))
391
392 self.commands += """
393## Sampler Configuration
394set /Herwig/Samplers/Sampler:BinSampler /Herwig/Samplers/{}
395set /Herwig/Samplers/Sampler:BinSampler:InitialPoints {}
396set /Herwig/Samplers/Sampler:BinSampler:NIterations {}
397set /Herwig/Samplers/Sampler:BinSampler:RemapperPoints {}
398""".format(bin_sampler, initial_points, n_iterations, remapper_points)
399
400 if bin_sampler == "CellGridSampler":
401 self.commands += """
402set /Herwig/Samplers/CellGridSampler:ExplorationSteps {}
403set /Herwig/Samplers/CellGridSampler:ExplorationPoints {}
404""".format(exploration_steps, exploration_points)
405
406 if bin_sampler == "MonacoSampler":
407 self.commands += """
408read snippets/MonacoSampler.in"""
409
410 def merging_weight(self, htPower=0, maxPtPower=0, onlyColoured="No"):
411 if onlyColoured not in ["Yes","No"]:
412 raise RuntimeError(hw7Utils.ansi_format_error("OnlyColoured must be Yes or No"))
413
414 self.commands+="""
415##Merging Weighter for better phase space coverage
416set /Herwig/Merging/MPreWeight:HTPower {}
417set /Herwig/Merging/MPreWeight:MaxPTPower {}
418set /Herwig/Merging/MPreWeight:OnlyColoured {}
419""".format(htPower,maxPtPower,onlyColoured)
420
Configuration class for Matchbox runs with Herwig7.
merging_weight(self, htPower=0, maxPtPower=0, onlyColoured="No")
do_integrate(self, integration_job)
Atomic steering function for doing one specific integration job.
sampler_commands(self, bin_sampler="CellGridSampler", initial_points=10000, n_iterations=1, remapper_points=50000, exploration_steps=4, exploration_points=500)
Configure the sampler.
beams
provide variables initialized by the parent class
do_build(self, integration_jobs)
Atomic steering function for doing the build step alone.
do_mergegrids(self, integration_jobs, gridpack=None)
Atomic steering function for combining the integration grids and possibly creating a gridpack.
do_run(self, gridpack=None, cleanup_herwig_scratch=True)
Atomic steering function for possibly unpacking a gridpack and generating events.
__init__(self, genSeq, runArgs, run_name="Herwig", beams="pp")
Initialize a generator configuration object for the Matchbox run mode.
Definition run.py:1