diff --git a/Examples/Scripts/Optimization/Optuna_tuning.py b/Examples/Scripts/Optimization/Optuna_tuning.py index f99c827933c..f4e26342f11 100644 --- a/Examples/Scripts/Optimization/Optuna_tuning.py +++ b/Examples/Scripts/Optimization/Optuna_tuning.py @@ -79,7 +79,7 @@ def __init__(self, k_dup, k_time): self.k_dup = k_dup self.k_time = k_time - def __call__(self, trial): + def __call__(self, trial, ckf_perf=True): params = [] maxSeedsPerSpM = trial.suggest_int("maxSeedsPerSpM", 0, 10) @@ -109,30 +109,7 @@ def __call__(self, trial): "deltaRMax", ] - outputDir = Path(srcDir / "Output_CKF") - outputfile = srcDir / "Output_CKF/performance_ckf.root" - outputDir.mkdir(exist_ok=True) - run_ckf(params, keys, outputDir) - rootFile = uproot.open(outputfile) - self.res["eff"].append(rootFile["eff_particles"].member("fElements")[0]) - self.res["fakerate"].append(rootFile["fakerate_tracks"].member("fElements")[0]) - self.res["duplicaterate"].append( - rootFile["duplicaterate_tracks"].member("fElements")[0] - ) - - timingfile = srcDir / "Output_CKF/timing.tsv" - timing = pd.read_csv(timingfile, sep="\t") - time_ckf = float( - timing[timing["identifier"].str.match("Algorithm:TrackFindingAlgorithm")][ - "time_perevent_s" - ] - ) - time_seeding = float( - timing[timing["identifier"].str.match("Algorithm:SeedingAlgorithm")][ - "time_perevent_s" - ] - ) - self.res["runtime"].append(time_ckf + time_seeding) + get_tracking_perf(self, ckf_perf, params, keys) efficiency = self.res["eff"][-1] penalty = ( @@ -144,6 +121,49 @@ def __call__(self, trial): return efficiency - penalty +def get_tracking_perf(self, ckf_perf, params, keys): + if ckf_perf: + outDirName = "Output_CKF" + outputfile = srcDir / outDirName / "performance_ckf.root" + effContName = "particles" + contName = "tracks" + else: + outDirName = "Output_Seeding" + outputfile = srcDir / outDirName / "performance_seeding.root" + effContName = "seeds" + contName = "seeds" + + outputDir = Path(srcDir / outDirName) + outputDir.mkdir(exist_ok=True) + run_ckf(params, keys, outputDir) + rootFile = uproot.open(outputfile) + self.res["eff"].append(rootFile["eff_" + effContName].member("fElements")[0]) + self.res["fakerate"].append(rootFile["fakerate_" + contName].member("fElements")[0]) + self.res["duplicaterate"].append( + rootFile["duplicaterate_" + contName].member("fElements")[0] + ) + + timingfile = srcDir / outDirName / "timing.tsv" + timing = pd.read_csv(timingfile, sep="\t") + + if ckf_perf: + time_ckf = float( + timing[timing["identifier"].str.match("Algorithm:TrackFindingAlgorithm")][ + "time_perevent_s" + ] + ) + + time_seeding = float( + timing[timing["identifier"].str.match("Algorithm:SeedingAlgorithm")][ + "time_perevent_s" + ] + ) + if ckf_perf: + self.res["runtime"].append(time_ckf + time_seeding) + else: + self.res["runtime"].append(time_seeding) + + def main(): k_dup = 5 k_time = 5 diff --git a/Examples/Scripts/Optimization/Orion_tuning.py b/Examples/Scripts/Optimization/Orion_tuning.py index fd7b91caee9..57942b0763e 100644 --- a/Examples/Scripts/Optimization/Orion_tuning.py +++ b/Examples/Scripts/Optimization/Orion_tuning.py @@ -32,6 +32,8 @@ from orion.client import build_experiment +from Optuna_tuning import get_tracking_perf, run_ckf + srcDir = Path(__file__).resolve().parent @@ -82,6 +84,7 @@ def __call__( maxPtScattering, deltaRMin, deltaRMax, + ckf_perf=True, ): params = [ maxSeedsPerSpM, @@ -104,30 +107,7 @@ def __call__( "deltaRMax", ] - outputDir = Path(srcDir / "Output_CKF") - outputfile = srcDir / "Output_CKF/performance_ckf.root" - outputDir.mkdir(exist_ok=True) - run_ckf(params, keys, outputDir) - rootFile = uproot.open(outputfile) - self.res["eff"].append(rootFile["eff_particles"].member("fElements")[0]) - self.res["fakerate"].append(rootFile["fakerate_tracks"].member("fElements")[0]) - self.res["duplicaterate"].append( - rootFile["duplicaterate_tracks"].member("fElements")[0] - ) - - timingfile = srcDir / "Output_CKF/timing.tsv" - timing = pd.read_csv(timingfile, sep="\t") - time_ckf = float( - timing[timing["identifier"].str.match("Algorithm:TrackFindingAlgorithm")][ - "time_perevent_s" - ] - ) - time_seeding = float( - timing[timing["identifier"].str.match("Algorithm:SeedingAlgorithm")][ - "time_perevent_s" - ] - ) - self.res["runtime"].append(time_ckf + time_seeding) + get_tracking_perf(self, ckf_perf, params, keys) efficiency = self.res["eff"][-1] penalty = (