Skip to content

Commit

Permalink
Merge branch 'main' of github.com:key4hep/k4GeneratorsConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkzerwas committed Sep 26, 2024
2 parents a8bd31e + a0d9d20 commit aa01fab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
6 changes: 6 additions & 0 deletions python/Generators/GeneratorBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def write_analysis(self):
else:
return ""
analysis += "-i {0}.edm4hep -o {0}.root\n".format(self.GeneratorDatacardBase)
if self.settings.IsRivet():
yodaout = self.settings.yodaoutput + f"/{self.procinfo.get('procname')}.yoda"
analysis += f"rivet"
for ana in self.settings.analysisname:
analysis += f" -a {ana}"
analysis+=f" -o {yodaout} {self.procinfo.get('procname')}.{self.procinfo.get('output_format')}\n"
return analysis

def write_GeneratorDatacard(self, content):
Expand Down
5 changes: 4 additions & 1 deletion python/Generators/SherpaProcDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ def write_DBInfo(self):
self.write_Difermion()
if label == "15_15":
self.write_Difermion()
self.runout += " MASSIVE[15] 1\n"
if label == "16_16":
self.write_Difermion()
if label == "12_12":
self.write_Difermion()
elif label == "23_25":
if label == "23_25":
self.write_run_ZH()
if label == "5_5":
self.runout = " MASSIVE[5] 1\n"

def write_Difermion(self):
self.runout = ""
Expand Down
37 changes: 37 additions & 0 deletions python/Input.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Input:
def __init__(self, file):
self.file = file
self.settings = None
self.anatool = None
if not os.path.isfile(file):
raise FileNotFoundError(file)
else:
Expand All @@ -29,6 +30,7 @@ def __init__(self, file):
setattr(self, key.lower(), value)
self.LoadCuts()
self.CheckDefaults()
self.LoadAnalysis()

def load_file(self):
with open(self.file, "r") as file:
Expand Down Expand Up @@ -161,6 +163,41 @@ def LoadCuts(self):
name.lower(), self.settings["selectors"][name]
)

def LoadAnalysis(self):
self.anasettings = self.get_block("analysis")
if self.anasettings is not None:
self.anasettings = {k.lower(): v for k, v in self.anasettings.items()}
self.anatool = self.anasettings["tool"]
self.anatool = self.anatool.lower()
if self.anatool=="rivet":
# check for rivet path
if "RIVET_ANALYSIS_PATH" in os.environ:
self.rivetpath = os.environ["RIVET_ANALYSIS_PATH"]
if "rivetpath" in self.settings:
self.rivetpath = self.anasettings["rivetpath"]
else:
try:
self.rivetpath = self.anasettings["rivetpath"]
except:
print("Rivet Analysis path has not been found")
self.anatool=None
# Set the analysis name
try:
self.analysisname = self.anasettings["rivetanalysis"]
except:
print("No rivet analysis specified. Using MC_XS instead.")
print("Set an analysis with Analysis: RivetAnalysis: Name")
self.analysisname = ["MC_XS"]
# Set yoda info
try:
self.yodaoutput = self.anasettings["yodaoutdir"]
except:
self.yodaoutput = os.getcwd()+"/yodafiles"
if not os.path.isdir(self.yodaoutput):
os.mkdir(self.yodaoutput)

def IsRivet(self):
return self.anatool=="rivet"

class ECMSInput:
"""Class for loading YAML files with center of mass energies"""
Expand Down
4 changes: 3 additions & 1 deletion python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ def executeFiles(files, sqrts, rndmSeedFallback=4711, events=-1):

for yaml_file in files:
settings = Settings.Input(yaml_file)
# ana = analysis.Analysis(settings)
if settings.IsRivet():
print("Rivet enabled")
if events != -1:
print(events)
settings.set("events", events)
settings.gens()
processes = settings.get_processes(sqrts)
Expand Down

0 comments on commit aa01fab

Please sign in to comment.