19 import matplotlib.pyplot
as plt
22 import multiprocessing
30 from typing
import Optional, Union
31 from pathlib
import Path
33 from orion.client
import build_experiment
35 srcDir = Path(__file__).resolve().parent
40 if len(params) != len(names):
41 raise Exception(
"Length of Params must equal names")
43 ckf_script = srcDir /
"ckf.py"
45 indir =
"--indir=" +
str(srcDir)
46 outdir =
"--output=" +
str(outDir)
49 ret.append(ckf_script)
56 arg =
"--sf_" + names[i] +
"=" +
str(param)
109 outputDir = Path(srcDir /
"Output_CKF")
110 outputfile = srcDir /
"Output_CKF/performance_ckf.root"
111 outputDir.mkdir(exist_ok=
True)
112 run_ckf(params, keys, outputDir)
113 rootFile = uproot.open(outputfile)
114 self.
res[
"eff"].append(rootFile[
"eff_particles"].member(
"fElements")[0])
115 self.
res[
"fakerate"].append(rootFile[
"fakerate_tracks"].member(
"fElements")[0])
116 self.
res[
"duplicaterate"].append(
117 rootFile[
"duplicaterate_tracks"].member(
"fElements")[0]
120 timingfile = srcDir /
"Output_CKF/timing.tsv"
121 timing = pd.read_csv(timingfile, sep=
"\t")
123 timing[timing[
"identifier"].str.match(
"Algorithm:TrackFindingAlgorithm")][
127 time_seeding = float(
128 timing[timing[
"identifier"].str.match(
"Algorithm:SeedingAlgorithm")][
132 self.
res[
"runtime"].append(time_ckf + time_seeding)
134 efficiency = self.
res[
"eff"][-1]
136 self.
res[
"fakerate"][-1]
137 + self.
res[
"duplicaterate"][-1] / self.
k_dup
142 {
"name":
"objective",
"type":
"objective",
"value": -(efficiency - penalty)}
156 "maxSeedsPerSpM":
"uniform(0,10,discrete=True)",
157 "cotThetaMax":
"uniform(5.0,10.0)",
158 "sigmaScattering":
"uniform(0.2,50.0)",
159 "radLengthPerSeed":
"uniform(.001,0.1)",
160 "impactMax":
"uniform(0.1,25.0)",
161 "maxPtScattering":
"uniform(1.0, 50.0)",
162 "deltaRMin":
"uniform(0.25, 30.0)",
163 "deltaRMax":
"uniform(50.0,300.0)",
167 if os.path.exists(
"./db.pkl"):
168 os.remove(
"./db.pkl")
180 experiment = build_experiment(
187 experiment.workon(objective, max_trials=3)
189 outputDir = Path(
"OrionResults")
190 outputDir.mkdir(exist_ok=
True)
193 df = experiment.to_pandas()
194 df.to_csv(outputDir /
"results.txt")
210 df_obj = df[
"objective"]
211 min_obj = df_obj.min()
212 df_final = df_imp[df_imp[
"objective"] == min_obj]
213 print(
"Best Score = %s" % (df_final[
"objective"]))
214 print(
"maxSeedsPerSpM = %s" % (df_final[
"maxSeedsPerSpM"]))
215 print(
"cotThetaMax = %s" % (df_final[
"cotThetaMax"]))
216 print(
"sigmaScattering = %s" % (df_final[
"sigmaScattering"]))
217 print(
"radLengthPerSeed = %s" % (df_final[
"radLengthPerSeed"]))
218 print(
"impactMax = %s" % (df_final[
"impactMax"]))
219 print(
"maxPtScattering = %s" % (df_final[
"maxPtScattering"]))
220 print(
"deltaRMin = %s" % (df_final[
"deltaRMin"]))
221 print(
"deltaRMax = %s" % (df_final[
"deltaRMax"]))
224 if __name__ ==
"__main__":