ATLAS Offline Software
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 
7 import os
8 
9 from . import Herwig7Config as hw7Config
10 from . import Herwig7Control as hw7Control
11 from . import Herwig7Utils as hw7Utils
12 
13 from AthenaCommon import Logging
14 athMsgLog = Logging.logging.getLogger('Herwig7ConfigMerging')
15 
16 
17 
210 class 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
251 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:BinDir {0}
252 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:DataDir {1}
253 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:MadgraphPrefix {2}
254 
255 ##Fixing interface locations of Openloops
256 set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsLibs {4}
257 set /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
261 read snippets/DipoleMerging.in
262 read snippets/{3}Collider.in
263 read Merging/Merging-Dipole-FactorCMWSchemeTune.in
264 read 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 
279 do /Herwig/Merging/MergingFactory:ProductionMode
280 saverun {} /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 
291  if not self.set_printout_commands:
292  self.default_commands += self.printout_commands()
293  if not self.set_physics_parameter_commands:
294  self.default_commands += self.physics_parameter_commands()
295  if not self.set_technical_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
394 set /Herwig/Samplers/Sampler:BinSampler /Herwig/Samplers/{}
395 set /Herwig/Samplers/Sampler:BinSampler:InitialPoints {}
396 set /Herwig/Samplers/Sampler:BinSampler:NIterations {}
397 set /Herwig/Samplers/Sampler:BinSampler:RemapperPoints {}
398 """.format(bin_sampler, initial_points, n_iterations, remapper_points)
399 
400  if bin_sampler == "CellGridSampler":
401  self.commands += """
402 set /Herwig/Samplers/CellGridSampler:ExplorationSteps {}
403 set /Herwig/Samplers/CellGridSampler:ExplorationPoints {}
404 """.format(exploration_steps, exploration_points)
405 
406  if bin_sampler == "MonacoSampler":
407  self.commands += """
408 read 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
416 set /Herwig/Merging/MPreWeight:HTPower {}
417 set /Herwig/Merging/MPreWeight:MaxPTPower {}
418 set /Herwig/Merging/MPreWeight:OnlyColoured {}
419 """.format(htPower,maxPtPower,onlyColoured)
420 
Herwig7ConfigMerging.Hw7ConfigMerging
Configuration class for Matchbox runs with Herwig7.
Definition: Herwig7ConfigMerging.py:210
Herwig7ConfigMerging.Hw7ConfigMerging.do_integrate
def do_integrate(self, integration_job)
Atomic steering function for doing one specific integration job.
Definition: Herwig7ConfigMerging.py:340
vtune_athena.format
format
Definition: vtune_athena.py:14
Herwig7ConfigMerging.Hw7ConfigMerging.run
def run(self, integration_jobs=1, gridpack=None, cleanup_herwig_scratch=True)
High-level function for triggering the process setup and the event generation.
Definition: Herwig7ConfigMerging.py:314
Herwig7ConfigMerging.Hw7ConfigMerging.local_pre_commands
def local_pre_commands(self)
Definition: Herwig7ConfigMerging.py:226
Herwig7ConfigMerging.Hw7ConfigMerging.do_mergegrids
def do_mergegrids(self, integration_jobs, gridpack=None)
Atomic steering function for combining the integration grids and possibly creating a gridpack.
Definition: Herwig7ConfigMerging.py:349
Herwig7ConfigMerging.Hw7ConfigMerging.__configure
def __configure(self)
Definition: Herwig7ConfigMerging.py:284
Herwig7ConfigMerging.Hw7ConfigMerging.do_run
def do_run(self, gridpack=None, cleanup_herwig_scratch=True)
Atomic steering function for possibly unpacking a gridpack and generating events.
Definition: Herwig7ConfigMerging.py:360
Herwig7ConfigMerging.Hw7ConfigMerging.local_post_commands
def local_post_commands(self)
Definition: Herwig7ConfigMerging.py:272
Herwig7ConfigMerging.Hw7ConfigMerging.merging_weight
def merging_weight(self, htPower=0, maxPtPower=0, onlyColoured="No")
Definition: Herwig7ConfigMerging.py:410
Herwig7ConfigMerging.Hw7ConfigMerging.__init__
def __init__(self, genSeq, runArgs, run_name="Herwig", beams="pp")
Initialize a generator configuration object for the Matchbox run mode.
Definition: Herwig7ConfigMerging.py:214
Herwig7ConfigMerging.Hw7ConfigMerging.sampler_commands
def sampler_commands(self, bin_sampler="CellGridSampler", initial_points=10000, n_iterations=1, remapper_points=50000, exploration_steps=4, exploration_points=500)
Configure the sampler.
Definition: Herwig7ConfigMerging.py:383
Herwig7ConfigMerging.Hw7ConfigMerging.beams
beams
provide variables initialized by the parent class
Definition: Herwig7ConfigMerging.py:223
Herwig7ConfigMerging.Hw7ConfigMerging.do_build
def do_build(self, integration_jobs)
Atomic steering function for doing the build step alone.
Definition: Herwig7ConfigMerging.py:333