ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | List of all members
Herwig7ConfigMerging.Hw7ConfigMerging Class Reference

Configuration class for Matchbox runs with Herwig7. More...

Inheritance diagram for Herwig7ConfigMerging.Hw7ConfigMerging:
Collaboration diagram for Herwig7ConfigMerging.Hw7ConfigMerging:

Public Member Functions

def __init__ (self, genSeq, runArgs, run_name="Herwig", beams="pp")
 Initialize a generator configuration object for the Matchbox run mode. More...
 
def local_pre_commands (self)
 
def local_post_commands (self)
 
def run (self, integration_jobs=1, gridpack=None, cleanup_herwig_scratch=True)
 High-level function for triggering the process setup and the event generation. More...
 
def do_build (self, integration_jobs)
 Atomic steering function for doing the build step alone. More...
 
def do_integrate (self, integration_job)
 Atomic steering function for doing one specific integration job. More...
 
def do_mergegrids (self, integration_jobs, gridpack=None)
 Atomic steering function for combining the integration grids and possibly creating a gridpack. More...
 
def do_run (self, gridpack=None, cleanup_herwig_scratch=True)
 Atomic steering function for possibly unpacking a gridpack and generating events. More...
 
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. More...
 
def merging_weight (self, htPower=0, maxPtPower=0, onlyColoured="No")
 

Public Attributes

 beams
 provide variables initialized by the parent class More...
 

Private Member Functions

def __configure (self)
 

Detailed Description

Configuration class for Matchbox runs with Herwig7.

Example JobOptions are available in examples/Matchbox and tests/athenaMatchbox/jobOptions.

Process Setup and Generator Configuration

To use the Matchbox run mode of Herwig7 load the corresponding modules and add Herwig7 to the generator sequence

from Herwig7_i.Herwig7_iConf import Herwig7
from Herwig7_i.Herwig7ConfigMatchbox import Hw7ConfigMatchbox
genSeq += Herwig7()

You may specify details of the run a la

# Provide config information
evgenConfig.generators += ["Herwig7"]
evgenConfig.tune = "MMHT2014"
evgenConfig.description = "Herwig7 Zee sample with CT10 ME PDF and MMHT2014 PS and UE tune"
evgenConfig.keywords = ["SM","Z","electron"]
evgenConfig.contact = ["Your Name (your.name@cern.ch)"]

You can initialize a generator configuration object with

# initialize generator configuration object
generator = Hw7ConfigMatchbox(genSeq, runArgs, run_name="HerwigMatchbox", beams="pp")

Please see the constructor for more information on the arguments.

You can use the functions me_alphas_commands, me_pdf_commands and tune_commands from Herwig7Config::Hw7Config to configure the strong coupling and the PDFs for the hard process and the parton shower and underlying event tunes, e.g.

# configure generator
generator.me_pdf_commands(order="NLO", name="CT10")
generator.tune_commands()

You can add direct Herwig7 commands like this

generator.add_commands("""
# Model assumptions
read Matchbox/StandardModelLike.in
# Set the hard process
set /Herwig/MatrixElements/Matchbox/Factory:OrderInAlphaS 0
set /Herwig/MatrixElements/Matchbox/Factory:OrderInAlphaEW 2
do /Herwig/MatrixElements/Matchbox/Factory:Process p p -> e+ e-
# Cut selection (see the documentation for more options)
set /Herwig/Cuts/ChargedLeptonPairMassCut:MinMass 60*GeV
set /Herwig/Cuts/ChargedLeptonPairMassCut:MaxMass 120*GeV
# Scale choice (see the documentation for more options)
cd /Herwig/MatrixElements/Matchbox
set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale
# Matching and shower selection
read Matchbox/MCatNLO-DefaultShower.in
# Choose a flavour scheme
read Matchbox/FiveFlavourScheme.in
""")

Please see the Herwig7 tutorial page for in-depth information on the different settings and have a look at Herwig7ConfigMatchbox::Hw7ConfigMatchbox and Herwig7Config::Hw7Config to see if there are convenience functions that accomplish the task provided in the interface already.

Integration and Event Generation

To trigger the actual running of Herwig7 in Athena please end the JobOptions with

# run the generator
generator.run()

More specifically, the run() function triggers the creation of the Herwig7 input file and the preparation of the run (i.e. the Herwig [build, integrate, mergegrids] sequence). This means, that no Herwig7 settings should be modified after calling the run() function because the changed settings would not be applied during the event generation.

Cleanup After the Event Generation

By default the folder Herwig-scratch which created by Herwig7 and contains the process libraries and several other files (e.g. integration grids) will be cleaned up and deleted after the event generation in order to save disk space. You can prevent this with:

# run the generator
generator.run(cleanup_herwig_scratch=True)

Parallel Integration

Machine-local parallelization of the integration can be achieved with

# run the generator
generator.run(integration_jobs=2)

Generate_tf.py comes with the command line parameter --generatorJobNumber that can be used to specify the number of integration jobs dynamically, instead of fixing it in the JobOptions

# run the generator
generator.run(integration_jobs=runArgs.generatorJobNumber)

Gridpacks

A gridpack can be created with

# run the generator
generator.run(gridpack="gridpack.tar.gz")

The JobOptions can be run in athena with a command such as

Generate_tf.py --jobConfig=MC15.999999.H7_MB_Int_Zee_MCatLO_QTilde_H7_UE_MMHT2014.py --runNumber=999999 --ecmEnergy=13000 --randomSeed=12011988 --maxEvents=100 --outputEVNTFile=evgen.root

If you have previously created a gridpack called gridpack.tar.gz and want to generate events from it, specify the name of the compressed gridpack using the --inputGenConfFile command line parameter, e.g.

Generate_tf.py --jobConfig=MC15.999999.H7_MB_Int_Zee_MCatLO_QTilde_H7_UE_MMHT2014.py --inputGenConfFile=gridpack.tar.gz --runNumber=999999 --ecmEnergy=13000 --randomSeed=12011988 --maxEvents=100 --outputEVNTFile=evgen.root

Full Flexibility and Batch-Parallel Integration

The --generatorRunMode command line argument for Generate_tf.py can be used to put in place a very fine-grained control over the various steps that happen before the event generation.

In the following example this is combined with the creation and use of a gridpack. This, however, doesn't have to be done and can be left out.

if runArgs.generatorRunMode == 'build':
# use the --generatorJobNumber command line parameter to dynamically
# specify the total number of parallel integration jobs
generator.do_build(integration_jobs=runArgs.generatorJobNumber)
elif runArgs.generatorRunMode == 'integrate':
# use the --generatorJobNumber command line parameter to dynamically
# specify which specific integration job is to be run
generator.do_integrate(runArgs.generatorJobNumber)
elif runArgs.generatorRunMode == 'mergegrids':
# combine integration grids and prepare a gridpack
# use the --generatorJobNumber command line parameter to dynamically
# specify the total number of parallel integration jobs
generator.do_mergegrids(integration_jobs=runArgs.generatorJobNumber, gridpack="gridpack.tar.gz")
elif runArgs.generatorRunMode == 'run':
# generate events using the specified gridpack
generator.do_run(gridpack="gridpack.tar.gz")

Please note that for the do_build() function the same caveat applies as for the run() function: The Herwig7 generator configuration should not be modified afterwards in the job options as the new settings would not be applied in the event generation.

Note
Currently the build, the integration and the mergegrids steps have to run in the same directory which means that the files written by athena will be re-created and overwritten. In one of the next releases Herwig7 will bring infrastructure to re-use Herwig-scratch folders from a different location which will allow for a full batch parallelization of the integration in athena.

Definition at line 210 of file Herwig7ConfigMerging.py.

Constructor & Destructor Documentation

◆ __init__()

def Herwig7ConfigMerging.Hw7ConfigMerging.__init__ (   self,
  genSeq,
  runArgs,
  run_name = "Herwig",
  beams = "pp" 
)

Initialize a generator configuration object for the Matchbox run mode.

Definition at line 214 of file Herwig7ConfigMerging.py.

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 

Member Function Documentation

◆ __configure()

def Herwig7ConfigMerging.Hw7ConfigMerging.__configure (   self)
private

Definition at line 298 of file Herwig7ConfigMerging.py.

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 

◆ do_build()

def Herwig7ConfigMerging.Hw7ConfigMerging.do_build (   self,
  integration_jobs 
)

Atomic steering function for doing the build step alone.

Parameters
[in]integration_jobsNumber of integration jobs to be prepared
Warning
Please do not modify the generator configuration in the job options after calling the do_build() function as the modified settings would not be applied in the event generation

Definition at line 347 of file Herwig7ConfigMerging.py.

347  def do_build(self, integration_jobs):
348  self.__configure()
349  hw7Control.do_build(self, integration_jobs)
350  hw7Control.do_abort()
351 

◆ do_integrate()

def Herwig7ConfigMerging.Hw7ConfigMerging.do_integrate (   self,
  integration_job 
)

Atomic steering function for doing one specific integration job.

Todo:
provide info about the range

Definition at line 354 of file Herwig7ConfigMerging.py.

354  def do_integrate(self, integration_job):
355  hw7Control.do_integrate(self.run_name, integration_job)
356  hw7Control.do_abort()
357 

◆ do_mergegrids()

def Herwig7ConfigMerging.Hw7ConfigMerging.do_mergegrids (   self,
  integration_jobs,
  gridpack = None 
)

Atomic steering function for combining the integration grids and possibly creating a gridpack.

Parameters
[in]integration_jobsNumber of integration jobs
[in]gridpackName of the gridpack to be created. No gridpack is created if the parameter is not specified.

Definition at line 363 of file Herwig7ConfigMerging.py.

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 

◆ do_run()

def Herwig7ConfigMerging.Hw7ConfigMerging.do_run (   self,
  gridpack = None,
  cleanup_herwig_scratch = True 
)

Atomic steering function for possibly unpacking a gridpack and generating events.

Parameters
[in]gridpackName of the gridpack to be used. No gridpack is used if the parameter is not specified.
[in]cleanup_herwig_scratchRemove the Herwig-scratch folder after event generation to save disk space

Definition at line 374 of file Herwig7ConfigMerging.py.

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 

◆ local_post_commands()

def Herwig7ConfigMerging.Hw7ConfigMerging.local_post_commands (   self)

Definition at line 286 of file Herwig7ConfigMerging.py.

286  def local_post_commands(self):
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 

◆ local_pre_commands()

def Herwig7ConfigMerging.Hw7ConfigMerging.local_pre_commands (   self)

Definition at line 226 of file Herwig7ConfigMerging.py.

226  def local_pre_commands(self):
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 

◆ merging_weight()

def Herwig7ConfigMerging.Hw7ConfigMerging.merging_weight (   self,
  htPower = 0,
  maxPtPower = 0,
  onlyColoured = "No" 
)

Definition at line 424 of file Herwig7ConfigMerging.py.

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 

◆ run()

def Herwig7ConfigMerging.Hw7ConfigMerging.run (   self,
  integration_jobs = 1,
  gridpack = None,
  cleanup_herwig_scratch = True 
)

High-level function for triggering the process setup and the event generation.

Parameters
[in]integration_jobsNumber of threads for machine-local parallelization of the integration
[in]gridpackName of the gridpack that possibly is to be created (after the integration) or to be used (for the event generation). No gridpack is created or used if the parameter is not specified. If you have created a gridpack and would like to generate events from it, please pass the name of the gridpack to the Generate_tf.py command using the --inputGenConfFile command line argument
[in]cleanup_herwig_scratchRemove the Herwig-scratch folder after event generation to save disk space
Warning
Please do not modify the generator configuration in the job options after calling the run() function as the modified settings would not be applied in the event generation

Definition at line 328 of file Herwig7ConfigMerging.py.

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 

◆ sampler_commands()

def Herwig7ConfigMerging.Hw7ConfigMerging.sampler_commands (   self,
  bin_sampler = "CellGridSampler",
  initial_points = 10000,
  n_iterations = 1,
  remapper_points = 50000,
  exploration_steps = 4,
  exploration_points = 500 
)

Configure the sampler.

Warning
Please be very careful when modifying the sampler settings and ensure that the statistics in the integration phase is sufficient to provide an adequate phase space sampling and setup. The total cross section estimated after the integration is output before the event generation, please watch out for the corresponding lines beginning with
Py:Herwig7Utils      INFO Calculating cross section after integration

If the statistical uncertainty on this estimated total cross section is larger than 0.2% a warning is printed, encouraging you to consider increasing the statistics of the integration.

Definition at line 397 of file Herwig7ConfigMerging.py.

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 

Member Data Documentation

◆ beams

Herwig7ConfigMerging.Hw7ConfigMerging.beams

provide variables initialized by the parent class

Definition at line 223 of file Herwig7ConfigMerging.py.


The documentation for this class was generated from the following file:
Herwig7Control.do_integrate
def do_integrate(run_name, integration_job)
Do the integrate step for one specific integration job.
Definition: Herwig7Control.py:196
Herwig7Control.do_build
def do_build(gen_config, integration_jobs)
Do the build step.
Definition: Herwig7Control.py:178
vtune_athena.format
format
Definition: vtune_athena.py:14
Herwig7Control.do_mergegrids
def do_mergegrids(run_name, integration_jobs)
This function provides the mergegrids step.
Definition: Herwig7Control.py:209
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
Herwig7
Interface to athena.
Definition: Herwig7.h:133
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Herwig7Control.do_run
def do_run(gen_config, cleanup_herwig_scratch=True)
Definition: Herwig7Control.py:273