Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic generators #25

Merged
merged 9 commits into from
Dec 20, 2024
4 changes: 2 additions & 2 deletions python/Generators/Babayaga.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .GeneratorBase import GeneratorBase
from . import BabayagaProcDB
from .BabayagaProcDB import BabayagaProcDB


class Babayaga(GeneratorBase):
Expand All @@ -13,7 +13,7 @@ def __init__(self, procinfo, settings):
self.process = ""
self.cuts = ""

self.procDB = BabayagaProcDB.BabayagaProcDB(self.procinfo)
self.procDB = BabayagaProcDB(self.procinfo)
if settings.get("usedefaults", True):
self.procDB.write_DBInfo()

Expand Down
79 changes: 22 additions & 57 deletions python/Generators/Generators.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,35 @@
from . import Sherpa
from . import Whizard
from . import Madgraph
from . import Babayaga
from . import KKMC
from . import Pythia

import importlib

class Generators:
"""Generator class"""

def __init__(self, settings):
self.settings = settings
self.generator_list = settings.gens()
self.sherpa = None
self.whizard = None
self.madgraph = None
self.babayaga = None
self.proc_info = None

def set_process_info(self, proc_info):
self.proc_info = proc_info

def initialize_generators(self):
if "Sherpa" in self.generator_list:
if Sherpa is not None:
self.sherpa = Sherpa.Sherpa(self.proc_info, self.settings)
self.sherpa.write_file()
self.sherpa.write_key4hepfile()
else:
print("Sherpa module not found. Unable to initialize Sherpa.")
if "Whizard" in self.generator_list:
if Whizard is not None:
self.whizard = Whizard.Whizard(self.proc_info, self.settings)
self.whizard.write_file()
self.whizard.write_key4hepfile()
else:
print("Whizard module not found. Unable to initialize Whizard.")

if "Madgraph" in self.generator_list:
if Madgraph is not None:
self.madgraph = Madgraph.Madgraph(self.proc_info, self.settings)
self.madgraph.write_file()
self.madgraph.write_key4hepfile()
else:
print("Madgraph module not found. Unable to initialize Madgraph.")

if "Babayaga" in self.generator_list:
if Babayaga is not None:
self.babayaga = Babayaga.Babayaga(self.proc_info, self.settings)
self.babayaga.write_file()
self.babayaga.write_key4hepfile()
else:
print("Babayaga module not found. Unable to initialize Babayaga.")

if "KKMC" in self.generator_list:
if KKMC is not None:
self.kkmc = KKMC.KKMC(self.proc_info, self.settings)
self.kkmc.write_file()
self.kkmc.write_key4hepfile()
else:
print("KKMC module not found. Unable to initialize KKMC.")

if "Pythia" in self.generator_list:
if Pythia is not None:
self.pythia = Pythia.Pythia(self.proc_info, self.settings)
self.pythia.write_file()
self.pythia.write_key4hepfile()
else:
print("Pythia module not found. Unable to initialize Pythia.")
for generatorName in self.generator_list:
# get the module
try:
generator = importlib.import_module(f"Generators.{generatorName}")
# get the ClassObject
generatorClass = getattr(generator,generatorName)
# execute the object
generatorObj = generatorClass(self.proc_info, self.settings)
#writing file
generatorObj.write_file()
#writing key4hep file
generatorObj.write_key4hepfile()

except ModuleNotFoundError:
print(f"{generatorName} python module not found for {self.proc_info.get('_proclabel')}")
except AttributeError:
print(f"{generatorName} class could not be loaded with getattr for {self.proc_info.get('_proclabel')}")
except:
# all that remains is an excption from the execution of the modules
print(f"Execution of {generatorName} for {self.proc_info.get('_proclabel')} resulted in an exception, check the module for problems with loading doownstream modules like the corresponding ProcDB etc")
print("Datacard files and execution scripts not written for this generator")
4 changes: 2 additions & 2 deletions python/Generators/KKMC.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .GeneratorBase import GeneratorBase
from . import KKMCProcDB
from .KKMCProcDB import KKMCProcDB
import os, sys


Expand All @@ -14,7 +14,7 @@ def __init__(self, procinfo, settings):
self.process = ""
self.cuts = ""

self.procDB = KKMCProcDB.KKMCProcDB(self.procinfo)
self.procDB = KKMCProcDB(self.procinfo)
if settings.get("usedefaults", True):
self.procDB.write_DBInfo()

Expand Down
4 changes: 2 additions & 2 deletions python/Generators/Madgraph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .GeneratorBase import GeneratorBase
from . import MadgraphProcDB
from .MadgraphProcDB import MadgraphProcDB
from Particles import Particle as part


Expand All @@ -14,7 +14,7 @@ def __init__(self, procinfo, settings):

self.add_header()
self.executable = "mg5_aMC"
self.procDB = MadgraphProcDB.MadgraphProcDB(self.procinfo)
self.procDB = MadgraphProcDB(self.procinfo)
if settings.get("usedefaults", True):
self.procDB.write_DBInfo()

Expand Down
4 changes: 2 additions & 2 deletions python/Generators/Pythia.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .GeneratorBase import GeneratorBase
from . import PythiaProcDB
from .PythiaProcDB import PythiaProcDB


class Pythia(GeneratorBase):
Expand All @@ -13,7 +13,7 @@ def __init__(self, procinfo, settings):
self.cuts = ""
self.PythiaSelectorFileExtension = "selectors"

self.procDB = PythiaProcDB.PythiaProcDB(self.procinfo)
self.procDB = PythiaProcDB(self.procinfo)
if settings.get("usedefaults", True):
self.procDB.write_DBInfo()

Expand Down
4 changes: 2 additions & 2 deletions python/Generators/Sherpa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .GeneratorBase import GeneratorBase
from . import SherpaProcDB
from .SherpaProcDB import SherpaProcDB


class Sherpa(GeneratorBase):
Expand All @@ -12,7 +12,7 @@ def __init__(self, procinfo, settings):
self.file = ""
self.cuts = ""

self.procDB = SherpaProcDB.SherpaProcDB(self.procinfo)
self.procDB = SherpaProcDB(self.procinfo)
if settings.get("usedefaults", True):
self.procDB.write_DBInfo()

Expand Down
4 changes: 2 additions & 2 deletions python/Generators/Whizard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .GeneratorBase import GeneratorBase
from . import WhizardProcDB
from .WhizardProcDB import WhizardProcDB


class Whizard(GeneratorBase):
Expand All @@ -13,7 +13,7 @@ def __init__(self, procinfo, settings):
self.cuts = ""
self.integrate = ""

self.procDB = WhizardProcDB.WhizardProcDB(self.procinfo)
self.procDB = WhizardProcDB(self.procinfo)
if settings.get("usedefaults", True):
self.procDB.write_DBInfo()

Expand Down
Loading