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 to locate the GoSam installation
237  try:
238  GoSam_path = os.environ['GOSAM_PATH']
239  except KeyError:
240  raise RuntimeError("GOSAM_PATH environment variable not set")
241  if not os.path.isfile(os.path.join(GoSam_path, 'bin', 'gosam.py')):
242  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)))
243 
244  try:
245  OpenLoops_path= os.environ['OPENLOOPSPATH']
246  except KeyError:
247  raise RuntimeError("OPENLOOPSPATH environment variable not set")
248  if not os.path.isdir(os.path.join(OpenLoops_path, "proclib")):
249  athMsgLog.warn(hw7Utils.ansi_format_warning("The OpenLoops process libraries can't be found from $OPENLOOPSPATH = {}".format(OpenLoops_path)))
250 
251 
252 
253  return """
254 ## ================================================
255 ## Local Pre-Commands from Herwig7ConfigMerging.py
256 ## ================================================
257 
258 ## Fixing interface locations for MadGraph
259 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:BinDir {0}
260 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:DataDir {1}
261 set /Herwig/MatrixElements/Matchbox/Amplitudes/MadGraph:MadgraphPrefix {2}
262 
263 ## Fixing interface locations for GoSam
264 set /Herwig/MatrixElements/Matchbox/Amplitudes/GoSam:BinDir {0}
265 set /Herwig/MatrixElements/Matchbox/Amplitudes/GoSam:DataDir {1}
266 set /Herwig/MatrixElements/Matchbox/Amplitudes/GoSam:GoSamPrefix {3}
267 
268 ##Fixing interface locations of Openloops
269 set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsLibs {5}
270 set /Herwig/MatrixElements/Matchbox/Amplitudes/OpenLoops:OpenLoopsPrefix {6}
271 
272 # Currently the Dipole Snippet is broken (reads to the Rivet interface which we don't build)
273 # For now manually copy all the relevant settings in
274 read snippets/DipoleMerging.in
275 read snippets/{4}Collider.in
276 read Merging/Merging-Dipole-FactorCMWSchemeTune.in
277 read Merging/FactorCMWScheme.in
278 """.format(hw7Control.herwig7_bin_path,
279  hw7Control.herwig7_share_path,
280  MG5aMC_path,
281  GoSam_path,
282  self.beams,
283  os.path.join(OpenLoops_path,"proclib"),
284  OpenLoops_path)
285 
287 
288  return """
289 ## =================================================
290 ## Local Post-Commands from Herwig7ConfigMerging.py
291 ## =================================================
292 
293 do /Herwig/Merging/MergingFactory:ProductionMode
294 saverun {} /Herwig/Generators/EventGenerator
295 """.format(self.run_name)
296 
297 
298  def __configure(self):
299 
300 
301 
302  self.default_commands += self.energy_commands()
303  self.default_commands += self.random_seed_commands()
304 
305  if not self.set_printout_commands:
306  self.default_commands += self.printout_commands()
307  if not self.set_physics_parameter_commands:
308  self.default_commands += self.physics_parameter_commands()
309  if not self.set_technical_parameter_commands:
310  self.default_commands += self.technical_parameter_commands()
311 
312 
313 
328  def run(self, integration_jobs=1, gridpack=None, cleanup_herwig_scratch=True):
329 
330  self.__configure()
331 
332  if gridpack:
333  hw7Control.matchbox_run_gridpack(self, integration_jobs, gridpack, cleanup_herwig_scratch)
334  else:
335  hw7Control.matchbox_run(self, integration_jobs, cleanup_herwig_scratch)
336 
337 
338  # atomic functions for complete control from within the JobOptions ----------
339 
340 
347  def do_build(self, integration_jobs):
348  self.__configure()
349  hw7Control.do_build(self, integration_jobs)
350  hw7Control.do_abort()
351 
352 
354  def do_integrate(self, integration_job):
355  hw7Control.do_integrate(self.run_name, integration_job)
356  hw7Control.do_abort()
357 
358 
363  def do_mergegrids(self, integration_jobs, gridpack=None):
364  hw7Control.do_mergegrids(self.run_name, integration_jobs)
365  if gridpack:
366  hw7Control.do_compress_gridpack(self.run_name, gridpack)
367  hw7Control.do_abort()
368 
369 
374  def do_run(self, gridpack=None, cleanup_herwig_scratch=True):
375  if gridpack:
376  hw7Control.do_uncompress_gridpack(gridpack)
377  hw7Control.do_run(self, cleanup_herwig_scratch)
378 
379 
380  # configuration commands ----------------------------------------------------
381 
382 
397  def sampler_commands(self, bin_sampler="CellGridSampler",
398  initial_points=10000, n_iterations=1, remapper_points=50000,
399  exploration_steps=4, exploration_points=500):
400 
401  bin_samplers = ["CellGridSampler", "MonacoSampler", "FlatBinSampler"]
402 
403  if bin_sampler not in bin_samplers:
404  raise RuntimeError(hw7Utils.ansi_format_error("Parameter 'bin_sampler' must be one of {}!".format(bin_samplers)))
405 
406  self.commands += """
407 ## Sampler Configuration
408 set /Herwig/Samplers/Sampler:BinSampler /Herwig/Samplers/{}
409 set /Herwig/Samplers/Sampler:BinSampler:InitialPoints {}
410 set /Herwig/Samplers/Sampler:BinSampler:NIterations {}
411 set /Herwig/Samplers/Sampler:BinSampler:RemapperPoints {}
412 """.format(bin_sampler, initial_points, n_iterations, remapper_points)
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)
419 
420  if bin_sampler == "MonacoSampler":
421  self.commands += """
422 read snippets/MonacoSampler.in"""
423 
424  def merging_weight(self, htPower=0, maxPtPower=0, onlyColoured="No"):
425  if onlyColoured not in ["Yes","No"]:
426  raise RuntimeError(hw7Utils.ansi_format_error("OnlyColoured must be Yes or No"))
427 
428  self.commands+="""
429 ##Merging Weighter for better phase space coverage
430 set /Herwig/Merging/MPreWeight:HTPower {}
431 set /Herwig/Merging/MPreWeight:MaxPTPower {}
432 set /Herwig/Merging/MPreWeight:OnlyColoured {}
433 """.format(htPower,maxPtPower,onlyColoured)
434 
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:354
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:328
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:363
Herwig7ConfigMerging.Hw7ConfigMerging.__configure
def __configure(self)
Definition: Herwig7ConfigMerging.py:298
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:374
Herwig7ConfigMerging.Hw7ConfigMerging.local_post_commands
def local_post_commands(self)
Definition: Herwig7ConfigMerging.py:286
Herwig7ConfigMerging.Hw7ConfigMerging.merging_weight
def merging_weight(self, htPower=0, maxPtPower=0, onlyColoured="No")
Definition: Herwig7ConfigMerging.py:424
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:397
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:347