13from prompt
import ValidationSettings
19settings = ValidationSettings(name=
'CDC Tracking',
22 expert_config={
'file_extension':
'png',
29def findLastIteration(job_path, algorithm):
30 root = f
"{job_path}/{algorithm}/"
31 list_dirs = [item
for item
in os.listdir(root)
if item !=
'outputdb']
32 list_dirs.sort(reverse=
True)
33 print(f
"The following iterations are available for {algorithm} algorithm: {list_dirs}")
37def run_validation(job_path, input_data_path, requested_iov, expert_config):
42 expert_config = json.loads(expert_config)
43 file_extension = expert_config[
'file_extension']
44 algo_tz = expert_config[
'algo_tz']
45 algo_tw = expert_config[
'algo_tw']
46 algo_sr = expert_config[
'algo_sr']
47 algo_xt = expert_config[
'algo_xt']
52 ROOT.gROOT.SetBatch(
True)
53 ROOT.gStyle.SetOptStat(0)
55 plot_directory =
"plots"
56 if not os.path.exists(plot_directory):
57 os.makedirs(plot_directory)
60 print(
"**** T0 validation plots ****")
62 lastIt = findLastIteration(job_path, algo_tz)
63 histT0_tz = f
'{job_path}/{algo_tz}/{lastIt}/algorithm_output/histT0_{algo_tz}.root'
64 f_histT0_tz = ROOT.TFile(histT0_tz)
65 print(f
"Plots from {algo_tz}/{lastIt}/algorithm_output/histT0_{algo_tz}.root")
68 hm_All = f_histT0_tz.Get(
"hm_All")
70 hm_All.GetXaxis().SetRangeUser(-1, 0)
71 hm_All.GetXaxis().SetTitle(
r"<\Delta t> [ns]")
74 can1.SaveAs(f
"{plot_directory}/{algo_tz}_hm_All.{file_extension}")
76 hs_All = f_histT0_tz.Get(
"hs_All")
78 hs_All.GetXaxis().SetRangeUser(2, 8)
79 hs_All.GetXaxis().SetTitle(
r"\sigma(\Delta t) [ns]")
82 can2.SaveAs(f
"{plot_directory}/{algo_tz}_hs_All.{file_extension}")
85 hTotal = f_histT0_tz.Get(
"hTotal")
87 hTotal.GetXaxis().SetTitle(
r"<\Delta t> [ns]")
90 can3.SaveAs(f
"{plot_directory}/{algo_tz}_hTotal.{file_extension}")
93 gr1 = [f_histT0_tz.Get(f
'DeltaT0/lay{i}')
for i
in range(56)]
94 cs = [ROOT.TCanvas(f
'cs{i}',
'', 1200, 750)
for i
in range(7)]
98 pad = [cs[j].GetPrimitive(f
'cs{j}_{i + 1}')
for i
in range(8)]
108 cs[i].SaveAs(f
"{plot_directory}/{algo_tz}_layers-{i}.{file_extension}")
111 print(
"**** TW validation plots ****")
113 lastIt = findLastIteration(job_path, algo_tw)
114 histTW_tw = f
'{job_path}/{algo_tw}/{lastIt}/algorithm_output/histTW_{algo_tw}.root'
115 f_histTW_tw = ROOT.TFile(histTW_tw)
116 print(f
"Plots from {algo_tw}/{lastIt}/algorithm_output/histTW_{algo_tw}.root")
119 rangeBorad = range(1, 301)
120 board_1D = [f_histTW_tw.Get(f
'h1D/board_{boardID}_1')
for boardID
in rangeBorad]
121 can = [ROOT.TCanvas(f
'c{c}', f
'c{c}', 2000, 1500)
for c
in range(12)]
124 can[c].Divide(ni, nj)
125 for j
in range(ni * nj):
127 boardNumber = j + c * (ni * nj)
128 if board_1D[boardNumber]:
129 board_1D[boardNumber].SetMarkerStyle(2)
130 board_1D[boardNumber].SetTitle(f
'Board number {boardNumber}')
131 board_1D[boardNumber].GetXaxis().SetTitle(
"ADC count")
132 board_1D[boardNumber].GetYaxis().SetTitle(
r"$\Delta t$ [ns]")
133 board_1D[boardNumber].Draw()
135 can[c].SaveAs(f
"{plot_directory}/{algo_tw}_boards-{c}.{file_extension}")
138 print(
"**** sigma res validation plots ****")
140 lastIt = findLastIteration(job_path, algo_sr)
141 histsr_sr = f
'{job_path}/{algo_sr}/{lastIt}/algorithm_output/histSigma_{algo_sr}.root'
142 f_histsr_sr = ROOT.TFile(histsr_sr)
143 print(f
"Plots from {algo_sr}/{lastIt}/algorithm_output/histSigma_{algo_sr}.root")
148 histograms = [f_histsr_sr.Get(f
'lay_{ilay}/sigma2_lay{ilay}_lr{LR}_al{alpha}_th{theta}')
for ilay
in range(56)]
154 div, mod = count_h // ncols, count_h % ncols
159 print(f
"number of valid histograms = {count_h} => canvas layout = ({ncols}, {nrows})")
161 c2 = ROOT.TCanvas(
'c2',
'', ncols * 700, nrows * 400)
162 c2.Divide(ncols, nrows)
168 h.GetXaxis().SetTitle(
"drift length [cm]")
169 h.GetYaxis().SetTitle(
"#sigma_{r}^{2} = #sigma_{u}.#sigma_{d}")
173 c2.SaveAs(f
"{plot_directory}/{algo_sr}_lr{LR}_al{alpha}_th{theta}.{file_extension}")
176 print(
"**** XT validation plots ****")
178 lastIt = findLastIteration(job_path, algo_xt)
179 histXT_xt = f
'{job_path}/{algo_xt}/{lastIt}/algorithm_output/histXT_{algo_xt}.root'
180 f_histXT_xt = ROOT.TFile(histXT_xt)
181 print(f
"Plots from {algo_xt}/{lastIt}/algorithm_output/histXT_{algo_xt}.root")
187 histograms = [f_histXT_xt.Get(f
'lay_{layer}/m_hProf{layer}_{LR}_{alphaID}_{thetaID}')
for layer
in range(56)]
194 div, mod = count_h // ncols, count_h % ncols
199 c2 = ROOT.TCanvas(
'c2',
'', ncols * 900, nrows * 600)
200 c2.Divide(ncols, nrows)
202 for histo
in histograms:
206 histo.GetYaxis().SetRangeUser(-1.2, 1.2)
207 histo.SetMarkerStyle(2)
210 c2.SaveAs(f
"{plot_directory}/{algo_xt}_lr{LR}_al{alphaID}_th{thetaID}.{file_extension}")
213if __name__ ==
"__main__":