From 6dbf3960de95dd9c1de4e20d253907fb5db46e87 Mon Sep 17 00:00:00 2001
From: Ewelina Maria Lobodzinska <ewelina.maria.lobodzinska@cern.ch>
Date: Wed, 23 Dec 2020 15:49:35 +0000
Subject: [PATCH] H7 art tests

---
 Generators/Herwig7_i/CMakeLists.txt           |  17 +-
 .../Herwig7_i/python/Herwig72ConfigLHEF.py    | 293 ++++++++++++++++++
 Generators/Herwig7_i/python/Herwig7Config.py  |  83 +++--
 Generators/Herwig7_i/src/Herwig7.cxx          |  47 +++
 Generators/Starlight_i/CMakeLists.txt         |   5 +-
 .../share/common/Starlight_Common.py          |  13 +
 .../starlight.example.joboption.py            |   0
 7 files changed, 418 insertions(+), 40 deletions(-)
 create mode 100644 Generators/Herwig7_i/python/Herwig72ConfigLHEF.py
 create mode 100644 Generators/Starlight_i/share/common/Starlight_Common.py
 rename Generators/Starlight_i/share/{ => example}/starlight.example.joboption.py (100%)

diff --git a/Generators/Herwig7_i/CMakeLists.txt b/Generators/Herwig7_i/CMakeLists.txt
index 65d4fb39621..3c9ed90737d 100644
--- a/Generators/Herwig7_i/CMakeLists.txt
+++ b/Generators/Herwig7_i/CMakeLists.txt
@@ -8,13 +8,17 @@ find_package( Boost )
 find_package( Herwig3 COMPONENTS HerwigAPI )
 find_package( ThePEG )
 find_package( GSL )
-# find_package( OpenLoops )
-find_package( VBFNLO )
+find_package( OpenLoops )
+# find_package( VBFNLO )
 find_package( hepmc3 )
 
 # Remove the --as-needed linker flags:
 atlas_disable_as_needed()
 
+# Add extra flag for H7 versions >=7.2
+set( _extraDefs )
+list( APPEND _extraDefs -DHWVER_IS_72=1 )
+
 # Component(s) in the package:
 if (HEPMC3_USE)
 atlas_add_component( Herwig7_i
@@ -32,14 +36,15 @@ else()
 atlas_add_component( Herwig7_i
    Herwig7_i/*.h src/*.cxx src/components/*.cxx
    INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${HERWIG3_INCLUDE_DIRS}
-   ${THEPEG_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} ${VBFNLO_INCLUDE_DIRS}
+   ${THEPEG_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} ${OPENLOOPS_INCLUDE_DIRS}
    DEFINITIONS -DHWVERSION=\"${HERWIG3_LCGVERSION}\"
    -DHWVER_IS_72=\"${HW3_VER_IS_72}\"
    LINK_LIBRARIES ${HERWIG3_LIBRARIES}  ${Boost_LIBRARIES} 
-   ${THEPEG_LIBRARIES} ${GSL_LIBRARIES} ${VBFNLO_LIBRARIES}
+   ${THEPEG_LIBRARIES} ${GSL_LIBRARIES} ${OPENLOOPS_LIBRARIES}
    GeneratorModulesLib EventInfo GaudiKernel PathResolver AtlasHepMCLib )
 endif()
-# ${OPENLOOPS_INCLUDE_DIRS} ${OPENLOOPS_LIBRARIES}
+
+# ${VBFNLO_INCLUDE_DIRS} ${VBFNLO_LIBRARIES}
 
 # Install files from the package:
 atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} )
@@ -50,3 +55,5 @@ atlas_install_runtime( share/file/*.pdt share/file/*.dat )
 set( Herwig7Environment_DIR ${CMAKE_CURRENT_SOURCE_DIR}
    CACHE PATH "Location of Herwig7Environment.cmake" )
 find_package( Herwig7Environment )
+
+
diff --git a/Generators/Herwig7_i/python/Herwig72ConfigLHEF.py b/Generators/Herwig7_i/python/Herwig72ConfigLHEF.py
new file mode 100644
index 00000000000..4ca4153d044
--- /dev/null
+++ b/Generators/Herwig7_i/python/Herwig72ConfigLHEF.py
@@ -0,0 +1,293 @@
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+
+## \file Herwig7ConfigLHEF.py
+## \brief Configuration class for showering LHE files from MG5_aMC@NLO or PowhegBox
+## \author Daniel Rauch (daniel.rauch@desy.de)
+
+import os
+
+import Herwig7Config as hw7Config
+import Herwig7Control as hw7Control
+import Herwig7Utils as hw7Utils
+
+
+## Configuration class for showering LHE files from MG5_aMC@NLO or PowhegBox
+##
+## Example JobOptions are available in [`examples/LHEF`](https://svnweb.cern.ch/trac/atlasoff/browser/Generators/Herwig7_i/trunk/examples/LHEF) and [`tests/athenaLHEF/jobOptions`](https://svnweb.cern.ch/trac/atlasoff/browser/Generators/Herwig7_i/trunk/tests/athenaLHEF/jobOptions).
+## 
+##
+## Process Setup and Generator Configuration
+## =========================================
+##
+## The LHE files have to follow a specific naming scheme which is detailed
+## [here](https://twiki.cern.ch/twiki/bin/view/AtlasProtected/PreparingLesHouchesEven).
+## The name of the LHE file is added as the command line parameter `--inputGeneratorFile`
+## to the `Generate_tf.py` command and can be accessed using the variable
+## `runArgs.inputGeneratorFile` in the JobOptions where they can be passed to the
+## functions [lhef_mg5amc_commands](\ref Herwig7ConfigLHEF::Hw7ConfigLHEF#lhef_mg5amc_commands)
+## or [lhef_powhegbox_commands](\ref Herwig7ConfigLHEF::Hw7ConfigLHEF#lhef_powhegbox_commands)
+## in order to communicate the LHE file names to %Herwig7, e.g.
+## 
+## \code{.py}
+## generator.lhef_mg5amc_commands(lhe_filename=runArgs.inputGeneratorFile, me_pdf_order="NLO")
+## \endcode
+## 
+## or
+## 
+## \code{.py}
+## generator.lhef_powhegbox_commands(lhe_filename=runArgs.inputGeneratorFile, me_pdf_order="NLO")
+## \endcode
+##
+##
+## Event Generation
+## ================
+##
+## To trigger the actual running of %Herwig7 in Athena please end the JobOptions with
+## 
+## \code{.py}
+## # run the generator
+## generator.run()
+## \endcode
+##
+## More specifically, the `run()` function triggers the creation of the %Herwig7 input
+## file and the preparation of the run (i.e. the `Herwig read` step).
+## 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.
+##
+class Hw72ConfigLHEF(hw7Config.Hw7Config):
+
+
+  def __init__(self, genSeq, runArgs, run_name="Herwig", beams="pp"):
+
+    beams = beams.upper()
+    if beams not in ["EE", "EP" , "PP"]:
+      raise RuntimeError(hw7Utils.ansi_format_error("Parameter 'beams' must be one of the following: ['EE', 'EP' , 'PP']"))
+
+    ## provide variables initialized by the parent class
+    super(Hw72ConfigLHEF, self).__init__(genSeq, runArgs, run_name)
+
+    self.beams = beams
+
+    self.set_lhef_mg5amc_commands = False
+    self.set_lhef_powhegbox_commands = False
+
+
+  def local_pre_commands(self):
+
+    return """
+## ============================================
+## Local Pre-Commands from Herwig7ConfigLHEF.py
+## ============================================
+
+# > no local pre-commands at the moment
+"""
+
+
+  def local_post_commands(self):
+
+    return """
+## =============================================
+## Local Post-Commands from Herwig7ConfigLHEF.py
+## =============================================
+
+saverun {} /Herwig/Generators/EventGenerator
+""".format(self.run_name)
+
+
+
+  ## High-level function for triggering the process setup and the event generation.
+  ##
+  ## \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
+  ##
+  def run(self):
+
+    ## add default settings if they were not overwritten in the JobOptions
+
+    self.default_commands += self.beam_commands()
+    self.default_commands += self.random_seed_commands()
+    
+    if not self.set_printout_commands:
+      self.default_commands += self.printout_commands()
+    if not self.set_physics_parameter_commands:
+      self.default_commands += self.physics_parameter_commands()
+    if not self.set_technical_parameter_commands:
+      self.default_commands += self.technical_parameter_commands()
+
+    ## check for configuration errors
+
+    if self.set_lhef_mg5amc_commands and self.set_lhef_powhegbox_commands:
+      raise RuntimeError(hw7Utils.ansi_format_error("Please do not use both 'lhef_mg5amc_commands()' and 'lhef_powhegbox_commands()' at the same time!"))
+    if not self.set_lhef_mg5amc_commands and not self.set_lhef_powhegbox_commands:
+      raise RuntimeError(hw7Utils.ansi_format_error("Please use either 'lhef_mg5amc_commands()' or 'lhef_powhegbox_commands()' in the JobOptions!"))
+
+    ## do read and run step in one go
+
+    hw7Control.run(self)
+
+
+  ## Sets up reading of events from an LHE file
+  ##
+  ## \param usespin Use the spin of tau leptons from the LHE file (spins of other particles are ignored anyways)
+  ## \param usepwghlhereader Uses a different LHE reader, which is able to propagte multiple event weights
+  def __lhef_commands(self, lhe_filename="events.lhe", me_pdf_order="NLO", usespin=True, usepwghlhereader=False):
+
+    if me_pdf_order not in ["LO", "NLO"]:
+      raise RuntimeError(hw7Utils.ansi_format_error("Herwig7ConfigLHEF.py:__lhef_commands: Parameter 'me_pdf_order' must either be 'LO' or 'NLO'!"))
+
+    if lhe_filename.endswith(".tar.gz"): # athena will decompress the LHE file for us
+      lhe_filename = lhe_filename.replace(".tar.gz", ".events")
+      if not os.path.isfile(lhe_filename):
+        raise RuntimeError(hw7Utils.ansi_format_error("Herwig7ConfigLHEF.py:__lhef_commands: Could not find decompressed LHE file '{}'!".format(lhe_filename)))
+
+    momentum_treatment = ""
+    beam_commands = ""
+    if self.beams == "EE":
+      momentum_treatment = "Accept"
+    elif self.beams == "EP":
+      momentum_treatment = "RescaleEnergy"
+      beam_commands = """
+## Set the PDF for the LHE reader
+# set /Herwig/EventHandlers/LHEReader:PDFA /Herwig/Partons/Hard{MEPDFOrder}PDF
+""".format(MEPDFOrder = me_pdf_order)
+    elif self.beams == "PP":
+      momentum_treatment = "RescaleEnergy"
+      beam_commands = """
+## Set the PDF for the LHE reader
+# set /Herwig/EventHandlers/LHEReader:PDFA /Herwig/Partons/Hard{MEPDFOrder}PDF
+# set /Herwig/EventHandlers/LHEReader:PDFB /Herwig/Partons/Hard{MEPDFOrder}PDF
+""".format(MEPDFOrder = me_pdf_order)
+
+    pwg_reader_lib = "library powhegHerwig.so" 
+
+
+    self.commands += """
+## ----------------------------
+## Read in Events from LHE File
+## ----------------------------
+
+## Create the Handler and Reader
+{PwgReaderLib}
+library LesHouches.so
+create ThePEG::{PwgReader}LesHouchesFileReader /Herwig/EventHandlers/LHEReader
+create ThePEG::LesHouchesEventHandler /Herwig/EventHandlers/LHEHandler
+
+## Set LHE filename
+set /Herwig/EventHandlers/LHEReader:FileName {FileName}
+
+## Setup LHE event handler and LHE reader
+set /Herwig/Generators/EventGenerator:EventHandler /Herwig/EventHandlers/LHEHandler
+insert /Herwig/EventHandlers/LHEHandler:LesHouchesReaders 0 /Herwig/EventHandlers/LHEReader
+set /Herwig/EventHandlers/LHEHandler:PartonExtractor /Herwig/Partons/{Beams}Extractor
+set /Herwig/EventHandlers/LHEHandler:CascadeHandler /Herwig/Shower/ShowerHandler
+set /Herwig/EventHandlers/LHEHandler:HadronizationHandler /Herwig/Hadronization/ClusterHadHandler
+set /Herwig/EventHandlers/LHEHandler:DecayHandler /Herwig/Decays/DecayHandler
+set /Herwig/EventHandlers/LHEHandler:WeightNormalization CrossSection
+set /Herwig/EventHandlers/LHEHandler:WeightOption VarNegWeight
+set /Herwig/EventHandlers/LHEReader:IncludeSpin {IncludeSpin}
+set /Herwig/EventHandlers/LHEReader:MomentumTreatment {MomentumTreatment}
+set /Herwig/EventHandlers/LHEReader:AllowedToReOpen No
+
+## Parton shower settings
+set /Herwig/Shower/ShowerHandler:MaxPtIsMuF Yes
+set /Herwig/Shower/ShowerHandler:RestrictPhasespace Yes
+# treatment of wide angle radiation
+set /Herwig/Shower/PartnerFinder:PartnerMethod Random
+set /Herwig/Shower/PartnerFinder:ScaleChoice Partner
+
+## Don't use any cuts on LHE files
+create ThePEG::Cuts /Herwig/Cuts/NoCuts
+set /Herwig/EventHandlers/LHEReader:Cuts /Herwig/Cuts/NoCuts
+
+{BeamCommands}
+""".format(FileName = lhe_filename,
+           PwgReaderLib = pwg_reader_lib if usepwghlhereader is True else "",
+           PwgReader = "powheg" if usepwghlhereader is True else "",
+           Beams = self.beams,
+           IncludeSpin = "Yes" if usespin is True else "No",
+           MomentumTreatment = momentum_treatment,
+           BeamCommands = beam_commands)
+
+
+  ## Commands specific to showering of events produced with MG5_aMC@NLO
+  ##
+  ## \param[in] lhe_filename name of the LHE file that is to be showered
+  ## \param[in] me_pdf_order order (either `LO` or `NLO`) of the matrix element PDF.
+  ##                         This has to be consistent with the PDF used in the
+  ##                         hard process generation and the PDF set with
+  ##                         generator.me_pdf_commands.
+  ##
+  ## The reason for these specific settings is that for MC@NLO-like matching schemes
+  ## the subtraction of the parton shower contribution in the hard process and the
+  ## parton shower settings have to be consistent in order to recover the
+  ## correct terms at the NLO.
+  ##
+  ## For showering of previously existing LHE files
+  ##
+  ##     generator.lhef_powhegbox_commands(lhe_filename=runArgs.inputGeneratorFile)
+  ##
+  ## will work.
+  ##
+  def lhef_mg5amc_commands(self, lhe_filename="events.lhe", me_pdf_order="NLO", usespin=True):
+
+    if me_pdf_order not in ["LO", "NLO"]:
+      raise RuntimeError(hw7Utils.ansi_format_error("Herwig7ConfigLHEF.py:lhef_mg5amc_commands: Parameter 'me_pdf_order' must either be 'LO' or 'NLO'!"))
+
+    self.set_lhef_mg5amc_commands = True
+
+    self.__lhef_commands(lhe_filename, me_pdf_order, usespin)
+
+    self.commands += """
+## Commands specific to showering of events produced with MG5_aMC@NLO
+set /Herwig/Shower/KinematicsReconstructor:ReconstructionOption General
+set /Herwig/Shower/KinematicsReconstructor:InitialInitialBoostOption LongTransBoost
+set /Herwig/Shower/KinematicsReconstructor:InitialStateReconOption Rapidity
+# this option is not available anymore in Herwig 7.2:
+# set /Herwig/Shower/KinematicsReconstructor:FinalStateReconOption Default
+set /Herwig/Shower/ShowerHandler:SpinCorrelations No
+"""
+
+
+  ## Commands specific to showering of events produced with PowhegBox
+  ##
+  ## \param[in] lhe_filename name of the LHE file that is to be showered
+  ## \param[in] me_pdf_order order (either `LO` or `NLO`) of the matrix element PDF.
+  ##                         This has to be consistent with the PDF used in the
+  ##                         hard process generation and the PDF set with
+  ##                         generator.me_pdf_commands.
+  ## \param[in] usespin 
+  ## \param[in] usepwghlhereader 
+  ##
+  ## Specifying the LHE file name with
+  ##
+  ##     generator.lhef_powhegbox_commands(lhe_filename=runArgs.inputGeneratorFile)
+  ## 
+  ## should work both for showering existing LHE files as well as for on-the-fly (OTF)
+  ## running of PowhegBox and %Herwig7.
+  ##
+  ## Since for OTF running the LHE file generated by PowhegBox is usually
+  ## called `PowhegOTF._1.events` using
+  ##
+  ##     generator.lhef_powhegbox_commands(lhe_filename="PowhegOTF._1.events")
+  ## 
+  ## will normally also work in this case. If a different name for the LHE file
+  ## generated by PowhegBox is specified with the `--outputTXTFile` argument to
+  ## `Generate_tf.py` then `PowhegControl` will update the value of
+  ## `runArgs.inputGeneratorFile` accordingly and
+  ##
+  ##     generator.lhef_powhegbox_commands(lhe_filename=runArgs.inputGeneratorFile)
+  ##
+  ## should still work.
+  ##
+  ## If you want to use the pwglhereader, needed to propagte multiple event weights
+  ## you need to use a gridpack contains the powhegHerwig.so 
+  ## 
+  def lhef_powhegbox_commands(self, lhe_filename="events.lhe", me_pdf_order="NLO", usespin=True, usepwhglhereader=False):
+
+    if me_pdf_order not in ["LO", "NLO"]:
+      raise RuntimeError(hw7Utils.ansi_format_error("Herwig7ConfigLHEF.py:lhef_powhegbox_commands: Parameter 'me_pdf_order' must either be 'LO' or 'NLO'!"))
+
+    self.set_lhef_powhegbox_commands = True
+
+    self.__lhef_commands(lhe_filename, me_pdf_order, usespin, usepwhglhereader)
diff --git a/Generators/Herwig7_i/python/Herwig7Config.py b/Generators/Herwig7_i/python/Herwig7Config.py
index 31255e34697..5c283c879b2 100644
--- a/Generators/Herwig7_i/python/Herwig7Config.py
+++ b/Generators/Herwig7_i/python/Herwig7Config.py
@@ -25,11 +25,11 @@ class Hw7Config(object):
     self.set_printout_commands            = False
     self.set_physics_parameter_commands   = False
     self.set_technical_parameter_commands = False
+    self.use_PDGparams = False
 
     self.default_commands = hw7Utils.ConfigurationCommands()
     self.commands         = hw7Utils.ConfigurationCommands()
 
-
   ## \brief Commands applied to all configuration classes before commands from the JobOptions
   ## \todo  Remove `AngularOrdered` settungs once they are included in %Herwig7 by default
   def global_pre_commands(self):
@@ -38,19 +38,6 @@ class Hw7Config(object):
 ## Global Pre-Commands from Herwig7Config.py
 ## =========================================
 
-## fix for global default settings until released with Herwig7 itself
-set /Herwig/Shower/GtoQQbarSplitFn:AngularOrdered Yes
-set /Herwig/Shower/GammatoQQbarSplitFn:AngularOrdered Yes
-
-## fix for GeV-mass photon radiation until released with Herwig7 itself
-set /Herwig/Shower/GammatoQQbarSudakov:Alpha /Herwig/Shower/AlphaQED
-
-## fix for initial-state (backward evolution) splitting (AGENE-1384)
-set /Herwig/Shower/QtoGammaQSudakov:Alpha /Herwig/Shower/AlphaQED
-
-## fix for QED lepton radiation scale (ATLMCPROD-5138)
-set /Herwig/Shower/LtoLGammaSudakov:pTmin 0.000001
-
 ## ensure JetFinder uses AntiKt with R=0.4
 set /Herwig/Cuts/JetFinder:Variant AntiKt
 set /Herwig/Cuts/JetFinder:ConeRadius 0.4
@@ -121,28 +108,63 @@ set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy {}
   def printout_commands(self):
 
     self.set_printout_commands = True
-
+    
     return("""
+
 ## Verbosity and printout settings
 set /Herwig/Generators/EventGenerator:DebugLevel 1
 set /Herwig/Generators/EventGenerator:PrintEvent 2
 set /Herwig/Generators/EventGenerator:UseStdout Yes
 set /Herwig/Generators/EventGenerator:NumberOfEvents 1000000000
-set /Herwig/Generators/EventGenerator:MaxErrors 1000000
+set /Herwig/Generators/EventGenerator:MaxErrors 500
 
 ## Make sampler print out cross sections for each subprocess
 set /Herwig/Samplers/Sampler:Verbose Yes
 """)
 
+    ## Before there were used the ATLAS MC15 default parameters for particle masses and widths and Weinberg angle
+    ##
+    ## As specified in https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/McProductionCommonParametersMC15
+    ## Now the PDG API is used to set the parameters via the python file Generators/EvgenProdTools/python/physics_parameters.py that generates the dictionary offline_dict.py with the parameters
 
-  ## ATLAS MC15 default parameters for particle masses and widths and Weinberg angle
-  ##
-  ## As specified in https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/McProductionCommonParametersMC15
   def physics_parameter_commands(self):
+    if self.use_PDGparams:
+       paramlist = []
+       self.physics_parameter_commands = True
+    
+       paramlist.append("## Masses and widths: PDG 2019 values")
+    
+    ## Load the dictionary and extract the values of the variables that were defined here before (top quark, W and Z boson)
+       from EvgenProdTools.offline_dict import parameters
+       for k,v in parameters.items():
+         if k == 'particles':
+           for key,value in v.items():
+             if int(key) == 24:
+               paramlist.append("set /Herwig/Particles/"+value['name']+"+:NominalMass "+value['mass'])
+               paramlist.append("set /Herwig/Particles/"+value['name']+"+:Width "+value['width'])
+               paramlist.append("set /Herwig/Particles/"+value['name']+"-:NominalMass "+value['mass'])
+               paramlist.append("set /Herwig/Particles/"+value['name']+"-:Width "+value['width'])
+             if int(key) == 23:
+               paramlist.append("set /Herwig/Particles/"+value['name']+"0:NominalMass "+value['mass'])
+               paramlist.append("set /Herwig/Particles/"+value['name']+"0:Width "+value['width'])
+             if int(key) == 6:
+               paramlist.append("set /Herwig/Particles/"+value['name']+"bar:NominalMass "+value['mass'])
+               paramlist.append("set /Herwig/Particles/"+value['name']+"bar:Width "+value['width'])         
+               paramlist.append("set /Herwig/Particles/"+value['name']+":NominalMass "+value['mass'])
+               paramlist.append("set /Herwig/Particles/"+value['name']+":Width "+value['width'])
+   
+    ## Take the value of sin2thetaW from the EW_parameters dictionary      
+         if k == 'EW_parameters':
+           for key,value in v.items():
+             if key[2] == "Sin2ThetaW":
+               paramlist.append("set /Herwig/Model:EW/"+str(key[2])+" "+str(value))
+       paramstring = '\n'.join(paramlist)
+       return(paramstring)
 
-    self.physics_parameter_commands = True
+    else:
+       self.physics_parameter_commands = True
 
-    return("""
+       return("""
 ## Masses and widths: PDG 2010 values (except TOP mass; kept at PDG2007)
 set /Herwig/Particles/t:NominalMass 172.5*GeV
 set /Herwig/Particles/tbar:NominalMass 172.5*GeV
@@ -157,7 +179,6 @@ set /Herwig/Particles/Z0:Width 2.4952*GeV
 set /Herwig/Model:EW/Sin2ThetaW 0.23113
 """)
 
-
   def technical_parameter_commands(self):
 
     self.set_technical_parameter_commands = True
@@ -168,10 +189,6 @@ set /Herwig/Particles/pomeron:PDF /Herwig/Partons/NoPDF
 
 ## Set long-lived particles stable
 set /Herwig/Decays/DecayHandler:MaxLifeTime 10*mm
-
-# Turn off intermediate photons inserted explicitly into the event record with an incorrect life length in the pi0 -> e+e-e+e- decay mode 
-# This is the default from H++ 2.6.1
-set /Herwig/Decays/PScalar4f:GenerateIntermediates 0
 """)
 
 
@@ -291,7 +308,7 @@ set /Herwig/Partons/RemnantPDF:MaxFlav {}
   ## \param[in] ps_tune_name name identifying the PS/hadronization tune
   ## \param[in] ue_tune_name name identifying the UE/MPI tune
   ## \return    Nothing, adds the corresponding commands directly to the generator configuration object
-  def tune_commands(self, ps_tune_name = "H7-PS-MMHT2014LO", ue_tune_name = "H7-UE-MMHT"):
+  def tune_commands(self, ps_tune_name = "H7-PS-MMHT2014LO", ue_tune_name = "H7.1-Default"):
 
     cmds = """
 ## -------------
@@ -299,7 +316,7 @@ set /Herwig/Partons/RemnantPDF:MaxFlav {}
 ## -------------
 """
     self.commands += cmds
-    self.ps_tune_commands(tune_name = ps_tune_name)
+    # self.ps_tune_commands(tune_name = ps_tune_name) # the name of the default PS tune may be obsolete
     self.ue_tune_commands(tune_name = ue_tune_name)
 
 
@@ -337,15 +354,15 @@ set /Herwig/Partons/RemnantPDF:MaxFlav {}
   ##
   ## \param[in] tune_name name identifying the UE/MPI tune
   ## \return    Nothing, adds the corresponding commands directly to the generator configuration object
-  def ue_tune_commands(self, tune_name = "H7-UE-MMHT"):
+  def ue_tune_commands(self, tune_name = "H7.1-Default"):
 
     cmds = """
 ## Underlying event tune settings
 """
 
-    if tune_name == "H7-UE-MMHT":
+    if tune_name == "H7.1-Default":
       cmds += """
-# > The underlying event tune "H7-UE-MMHT" is already
+# > The underlying event tune "H7.1-Default" is already
 # > configured in Herwig7 via the default settings.
 """
     # elif tune_name == "some-other-name":
@@ -399,7 +416,7 @@ set /Herwig/Particles/pomeron:PDF /Herwig/Partons/PomeronPDF
 
 # Technical parameters for this run
 set /Herwig/Generators/EventGenerator:EventHandler:Sampler:Ntry 100000
-set /Herwig/Generators/EventGenerator:MaxErrors 100000
+set /Herwig/Generators/EventGenerator:MaxErrors 500
 
 # MPI doesn't work
 # TODO: Is this a problem?
@@ -433,5 +450,3 @@ set /Herwig/Particles/pbar-:PDF /Herwig/Partons/BudnevPDF
 set /Herwig/Generators/EventGenerator:EventHandler:CascadeHandler:MPIHandler NULL
 
 """
-
-
diff --git a/Generators/Herwig7_i/src/Herwig7.cxx b/Generators/Herwig7_i/src/Herwig7.cxx
index 26cf4046333..1204b9744e9 100644
--- a/Generators/Herwig7_i/src/Herwig7.cxx
+++ b/Generators/Herwig7_i/src/Herwig7.cxx
@@ -33,6 +33,53 @@
 #include "boost/thread/thread.hpp"
 #include "boost/filesystem.hpp"
 #include "boost/algorithm/string.hpp"
+#include "boost/foreach.hpp"
+#define foreach BOOST_FOREACH
+
+
+// Setup HepMC traits definition for ThePEG's converter to work
+#include "ThePEG/Vectors/HepMCConverter.h"
+#ifdef HWVER_IS_72
+namespace ThePEG {
+  template<>
+  struct HepMCTraits<HepMC::GenEvent>
+    : public HepMCTraitsBase<HepMC::GenEvent,
+                             HepMC::GenParticle,
+                             HepMC::GenParticle *,
+                             HepMC::GenVertex,
+                             HepMC::GenVertex *,
+                             HepMC::Polarization,
+                             HepMC::PdfInfo>
+  {
+    static bool hasUnits() {
+      #ifdef HEPMC_HAS_UNITS
+      return true;
+      #else
+      return false;
+      #endif
+    }
+  };
+}
+#else
+namespace ThePEG {
+  template<>
+  struct HepMCTraits<HepMC::GenEvent>
+    : public HepMCTraitsBase<HepMC::GenEvent,
+                            HepMC::GenParticle,
+                             HepMC::GenVertex,
+                             HepMC::Polarization,
+                             HepMC::PdfInfo>
+  {
+    static bool hasUnits() {
+      #ifdef HEPMC_HAS_UNITS
+      return true;
+      #else
+      return false;
+      #endif
+    }
+  };
+}
+#endif
 
 void   convert_to_HepMC(const ThePEG::Event & m_event, HepMC::GenEvent & evt, bool nocopies,ThePEG::Energy eunit, ThePEG::Length lunit);
 
diff --git a/Generators/Starlight_i/CMakeLists.txt b/Generators/Starlight_i/CMakeLists.txt
index 8dfb8fbf4e6..018b4756c1a 100644
--- a/Generators/Starlight_i/CMakeLists.txt
+++ b/Generators/Starlight_i/CMakeLists.txt
@@ -27,4 +27,7 @@ atlas_add_component( Starlight_i
    LINK_LIBRARIES Starlight_iLib )
 
 # Install files from the package:
-atlas_install_joboptions( share/*.py )
+atlas_install_joboptions( share/common/*.py 
+                          share/example/*.py )
+
+
diff --git a/Generators/Starlight_i/share/common/Starlight_Common.py b/Generators/Starlight_i/share/common/Starlight_Common.py
new file mode 100644
index 00000000000..e6e724e814d
--- /dev/null
+++ b/Generators/Starlight_i/share/common/Starlight_Common.py
@@ -0,0 +1,13 @@
+from Starlight_i.Starlight_iConf import Starlight_i
+genSeq += Starlight_i("Starlight")
+genSeq.Starlight.McEventKey = "GEN_EVENT"
+
+evgenConfig.generators += ["Starlight"]
+
+## Extra stream persistency
+## 2101 == EventInfo, 133273 == MCTruth (HepMC)
+from AthenaPoolCnvSvc.WriteAthenaPool import AthenaPoolOutputStream
+_evgenstream = AthenaPoolOutputStream("StreamEVGEN")
+_evgenstream.ItemList = ["2101#*","133273#GEN_EVENT"]
+del _evgenstream
+
diff --git a/Generators/Starlight_i/share/starlight.example.joboption.py b/Generators/Starlight_i/share/example/starlight.example.joboption.py
similarity index 100%
rename from Generators/Starlight_i/share/starlight.example.joboption.py
rename to Generators/Starlight_i/share/example/starlight.example.joboption.py
-- 
GitLab