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
2 changes: 1 addition & 1 deletion python/Generators/Babayaga.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
73 changes: 16 additions & 57 deletions python/Generators/Generators.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,29 @@
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:
# import the generators
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:
print("Requested Generator: "+generatorName+" could not be configured for "+self.proc_info.get("_proclabel"))
2 changes: 1 addition & 1 deletion python/Generators/KKMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion python/Generators/Madgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion python/Generators/Pythia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion python/Generators/Sherpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion python/Generators/Whizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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