Skip to content

Commit

Permalink
Merge pull request #14 from key4hep/add-kkmc
Browse files Browse the repository at this point in the history
Add kkmc
  • Loading branch information
apricePhy committed May 31, 2024
2 parents eecfdb1 + 70b7e67 commit 2f5f6ca
Show file tree
Hide file tree
Showing 8 changed files with 559 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/FermionProduction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Generators:
- Sherpa
- Whizard
- Madgraph
- KKMC

OutputFormat: hepmc3
OutDir: Run-Cards
Expand Down
420 changes: 420 additions & 0 deletions python/Generators/.KKMCDefaults

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion python/Generators/Babayaga.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, procinfo, settings):
self.procDB.write_DBInfo()

self.executable = "babayaga-fcc.exe"
self.gen_settings = settings.get_block("whizard")
self.gen_settings = settings.get_block("babayaga")
if self.gen_settings is not None:
self.gen_settings = {k.lower(): v for k, v in self.gen_settings.items()}

Expand Down
8 changes: 8 additions & 0 deletions python/Generators/Generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Whizard
import Madgraph
import Babayaga
import KKMC

class Generators:
"""Generator class"""
Expand Down Expand Up @@ -48,3 +49,10 @@ def initialize_generators(self):
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.")
92 changes: 92 additions & 0 deletions python/Generators/KKMC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from GeneratorBase import GeneratorBase
import Particles
import KKMCProcDB
import os,sys

class KKMC(GeneratorBase):
"""KKMC class"""
def __init__(self, procinfo, settings):
super().__init__(procinfo, settings,"KKMC","dat")

self.version = "x.y.z"
self.file = ""
self.process = ""
self.cuts = ""

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

self.executable = "KKMC-fcc.exe"
self.gen_settings = settings.get_block("kkmc")
if self.gen_settings is not None:
self.gen_settings = {k.lower(): v for k, v in self.gen_settings.items()}

self.procs = []
# Load default settigns
defaultfile=os.path.dirname(__file__)+"/.KKMCDefaults"
with open(defaultfile, 'r') as file:
self.defaults = file.read()

def write_process(self):
if abs(self.procinfo.get_beam_flavour(1)) != 11 or abs(self.procinfo.get_beam_flavour(1)) != 11:
print(f"KKMC not implemented for initial state {self.KKMC_beam1} {self.KKMC_beam2}")
return

finalstate = self.procinfo.get_final_pdg().split(' ')
if len(finalstate)!=2:
print("WARNING: KKMC is only for e+e- -> f fbar")
sys.exit()
if abs(int(finalstate[0]))!=abs(int(finalstate[1])):
print(f"WARNING: Final states {finalstate} not allowed in KKMC")
sys.exit()
self.finalstate = self.pdg_to_KKMC(finalstate[0])
self.add_process_option("_seed",self.procinfo.get_rndmSeed())
self.add_process_option("_energy", self.procinfo.get("sqrts"))
# TODO add bes
self.add_process_option("_besdelta", 0)
self.add_process_option("_ewmode", self.procinfo.get("ewmode"))
self.add_process_option("_isrmode", self.procinfo.get("isrmode"))
self.add_process_option("_fsrmode", self.settings.get("fsrmode",0))
self.add_final_State()

# output format only hepm2 or hepmc3, the actual version is detected by the linked library, so strip the number
if self.procinfo.eventmode == "unweighted":
self.add_process_option("_wgtmode", "0")
else:
self.add_process_option("_wgtmode", "1")

def add_decay(self):
print("DECAY specified, cannot be implmented in KKMC")

def add_final_State(self):
fs = f" {self.finalstate} 1"
self.add_process_option("_FINALSTATES", fs)
def add_process_option(self, key, value):
if not isinstance(value, str):
value = str(value)
if key in self.process:
print(f"{key} has already been defined in {self.name}.")
return
if f"{key}" in self.procDB.get_run_out():
self.procDB.remove_option(key)
if key in self.defaults:
self.defaults = self.defaults.replace(key, value)
else:
print(f"Warning: {key} not set as defaults in KKCM. Ignoring")

def write_file(self):
self.write_process()
self.write_GeneratorDatacard(self.defaults)

def write_key4hepfile(self):
key4hepRun = ""
key4hepRun += "KKMCee -c "+self.GeneratorDatacardName + " -o events.lhe"+ "\n"
key4hepRun += "$CONVERTHEPMC2EDM4HEP/convertHepMC2EDM4HEP -i lhe -o {0} events.lhe {1}.{0}\n".format(self.procinfo.get("output_format"),self.GeneratorDatacardBase)
key4hepRun += "$CONVERTHEPMC2EDM4HEP/convertHepMC2EDM4HEP -i {0} -o edm4hep {1}.{0} {1}.edm4hep\n".format(self.procinfo.get("output_format"),self.GeneratorDatacardBase)
self.write_Key4hepScript(key4hepRun)

def pdg_to_KKMC(self, pdg):
apdg = abs(400+int(pdg))
return f"{apdg}"

33 changes: 33 additions & 0 deletions python/Generators/KKMCProcDB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class KKMCProcDB:
"""KKMCProcDB class"""
def __init__(self, process):
self.process = process
self.runout = ""
self.procout = ""

def write_DBInfo(self):
# choose as function of generatorDBLabel
label = self.process.get_generatorDBLabel()
if ( label == "11_11" ):
self.write_Difermion()
if ( label == "13_13" ):
self.write_Difermion()
if ( label == "22_22" ):
self.write_Diphoton()

def write_Difermion(self):
self.runout = ""

def write_Diphoton(self):
self.runout = ""

def get_run_out(self):
return self.runout

def get_proc_out(self):
return self.procout

def remove_option(self,opt):
lines = self.runout.split("\n")
filter_lines = [line for line in lines if opt not in line]
self.runout = "\n".join(filter_lines)
3 changes: 3 additions & 0 deletions python/Input.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def get_event_number(self):
def get_isr_mode(self):
return self.get("isrmode", 0)

def get_ew_mode(self):
return self.get("ewmode",0)


def get_weighted_mode(self):
return self.get("eventmode", "unweighted")
Expand Down
1 change: 1 addition & 0 deletions python/Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ def __init__(self, settings):
self.PositronPolarisation = settings.get_PositronPolarisation()
self.PolDensity = settings.get_PolDensity()
self.eventmode = settings.get_weighted_mode()
self.ewmode = settings.get_ew_mode()

0 comments on commit 2f5f6ca

Please sign in to comment.