ATLAS Offline Software
Functions
Herwig7_UFO Namespace Reference

Functions

def generateFRModel (UFOModel, overWriteLocalDir=False)
 

Function Documentation

◆ generateFRModel()

def Herwig7_UFO.generateFRModel (   UFOModel,
  overWriteLocalDir = False 
)
    UFOModel (string) :: name of UFO model that is imported for the event generation

Definition at line 9 of file Herwig7_UFO.py.

9 def generateFRModel(UFOModel, overWriteLocalDir=False):
10  """
11  UFOModel (string) :: name of UFO model that is imported for the event generation
12  """
13 
14  # find UFO directory
15  MGModelsLatest = '/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/'
16  MGModelDirCVMFS = os.path.join(MGModelsLatest, UFOModel)
17  if not MGModelDirCVMFS:
18  athMsgLog.error(f'could not find UFO model {UFOModel} on cvmfs.' \
19  f' Are you sure it is available on {MGModelsLatest} ?')
20  exit(1)
21 
22  try:
23  shutil.copytree(MGModelDirCVMFS, UFOModel)
24  except FileExistsError:
25  if not overWriteLocalDir:
26  athMsgLog.error(f'{UFOModel} already exists in your local directory.' \
27  ' Please (re)move this directory yourself to avoid it' \
28  ' being overwritten, or set `overWriteLocalDir` to True.' \
29  ' Exiting gracefully...')
30  exit(1)
31  else:
32  shutil.rmtree(UFOModel)
33  shutil.copytree(MGModelDirCVMFS, UFOModel)
34 
35  # find ufo2herwig command
36  try:
37  HERWIG7_PATH = os.environ['HERWIG7_PATH']
38  except KeyError:
39  raise RuntimeError("HERWIG7_PATH environment variable not set")
40  ufo2herwig = os.path.join(HERWIG7_PATH, 'bin/ufo2herwig')
41  if not ufo2herwig:
42  athMsgLog.error(f'could not find Herwig7 ufo2herwig command: {ufo2herwig}')
43  exit(1)
44 
45  # generate FRModel.model file
46  try:
47  subprocess.run([ufo2herwig, UFOModel], check = True)
48 
49  # it might be needed to convert python2 models to python3
50  except subprocess.CalledProcessError:
51 
52  # fresh copy of UFO model, as the previous attempt for `ufo2herwig`
53  # will have made modifications in this directory
54  shutil.rmtree(UFOModel)
55  shutil.copytree(MGModelDirCVMFS, UFOModel)
56  subprocess.run([ufo2herwig, '--convert', UFOModel], check = True)
57 
58  subprocess.run(['make'], shell = True, check = True)
59 
60  # add "read FRModel.model" to the Herwig7 command
61  Herwig7Config.add_commands("""
62 read FRModel.model
63 #""")
64 
65 
Herwig7_UFO.generateFRModel
def generateFRModel(UFOModel, overWriteLocalDir=False)
Definition: Herwig7_UFO.py:9
calibdata.exit
exit
Definition: calibdata.py:236