12Validation plots for TOP calibration.
15from prompt
import ValidationSettings
16from ROOT
import TFile, TH1F, TGraph, TCanvas, TLegend, gROOT, gStyle, PyConfig
17from basf2
import B2ERROR
22settings = ValidationSettings(name=
'TOP post-tracking calibration',
28def run_validation(job_path, input_data_path, requested_iov, expert_config):
30 Makes validation plots
31 :job_path: path to top posttracking calibration output
32 :input_data_path: required argument but not used
33 :requested_iov: required argument but not used
34 :expert_config: required argument but not used
39 inputFileName = job_path +
'/TOP_validation/0/algorithm_output/TOPCalValidation.root'
40 outputFileName =
'TOPValidation.pdf'
44 PyConfig.IgnoreCommandLineOptions =
True
49 gStyle.SetHistMinimumZero(
True)
50 gStyle.SetLabelSize(0.05,
"X")
51 gStyle.SetLabelSize(0.05,
"Y")
52 gStyle.SetTitleSize(0.06,
"X")
53 gStyle.SetTitleSize(0.06,
"Y")
54 gStyle.SetTitleOffset(0.7,
"X")
55 gStyle.SetTitleOffset(0.8,
"Y")
56 gStyle.SetGridColor(11)
60 file_in = TFile.Open(inputFileName)
62 B2ERROR(inputFileName +
": file not found")
64 canvas = TCanvas(
"c1",
"c1", 1000, 750)
70 residuals_all = TH1F(
"residuals_all",
"ChannelT0 residuals; residuals [ns]", 200, -1.0, 1.0)
71 h_rms = TH1F(
"h_rms",
"Width of residuals (rms); slot; r.m.s [ps]", 16, 0.5, 16.5)
72 h_core = TH1F(
"h_core",
"Core width of residuals; slot; sigma [ps]", 16, 0.5, 16.5)
73 h_out = TH1F(
"h_out",
"Outlayers (more than 3 sigma); slot; fraction [%]", 16, 0.5, 16.5)
74 for slot
in range(1, 17):
75 name =
"slot" + f
'{slot:02d}'
76 h = file_in.Get(
"channelT0_" + name)
78 r = TH1F(
"residuals_" + name,
"ChannelT0, " + name +
"; residuals [ns]", 200, -1.0, 1.0)
82 for i
in range(1, h.GetNbinsX() + 1):
83 if h.GetBinError(i) > 0:
84 r.Fill(h.GetBinContent(i))
85 residuals_all.Fill(h.GetBinContent(i))
87 residuals_all.Fit(
"gaus",
"Q")
88 h_rms.SetBinContent(slot, r.GetRMS() * 1000)
89 fun = r.GetFunction(
"gaus")
93 h_core.SetBinContent(slot, fun.GetParameter(2) * 1000)
94 mean = fun.GetParameter(1)
95 wid = fun.GetParameter(2)
98 for i
in range(1, h.GetNbinsX() + 1):
99 if h.GetBinError(i) == 0:
102 if abs(h.GetBinContent(i) - mean) < 3 * wid:
105 h_out.SetBinContent(slot, (1 - n_in / n_all) * 100)
106 residuals_all.Fit(
"gaus",
"Q")
110 canvas.Print(outputFileName +
"[")
117 for i, h
in enumerate(channelT0s):
125 for ibin
in range(1, h.GetNbinsX() + 1):
126 if h.GetBinContent(ibin) > 1.0:
127 g_over.SetPoint(g_over.GetN(), h.GetBinCenter(ibin), 0.95)
128 elif h.GetBinContent(ibin) < -1.0:
129 g_under.SetPoint(g_under.GetN(), h.GetBinCenter(ibin), -0.95)
130 if g_over.GetN() > 0:
131 g_over.SetMarkerStyle(22)
132 g_over.SetMarkerColor(2)
134 graphs.append(g_over)
135 if g_under.GetN() > 0:
136 g_under.SetMarkerStyle(23)
137 g_under.SetMarkerColor(2)
139 graphs.append(g_under)
140 canvas.Print(outputFileName)
147 gStyle.SetOptStat(
"oue")
148 W = gStyle.GetStatW()
149 H = gStyle.GetStatH()
152 for i, h
in enumerate(residuals):
155 canvas.Print(outputFileName)
163 gStyle.SetOptFit(111)
165 histos = [residuals_all, h_rms, h_core, h_out]
166 for i, h
in enumerate(histos):
169 canvas.Print(outputFileName)
173 commonT0 = file_in.Get(
"commonT0")
176 commonT0.SetYTitle(commonT0.GetYaxis().GetTitle().replace(
'[ns]',
'[ps]'))
177 commonT0.SetMinimum(-100)
178 commonT0.SetMaximum(100)
179 commonT0.Fit(
"pol0",
"Q")
185 canvas.GetPad(2).SetGrid()
186 gStyle.SetHistMinimumZero(
False)
187 histos = [commonT0, file_in.Get(
"runIndex")]
188 for i, h
in enumerate(histos):
194 canvas.Print(outputFileName)
195 gStyle.SetHistMinimumZero(
True)
202 for slot
in range(1, 17):
204 h = file_in.Get(
"moduleT0_slot" + f
'{slot:02d}')
207 h.SetYTitle(h.GetYaxis().GetTitle().replace(
'[ns]',
'[ps]'))
212 canvas.Print(outputFileName)
216 h_offset = TH1F(
"h_offset",
"ModuleT0: fitted offset; slot; p0 [ps]", 16, 0.5, 16.5)
217 h_chi = TH1F(
"h_chi",
"ModuleT0: chi2/ndf; slot; #chi^{2}/ndf", 16, 0.5, 16.5)
218 h_res = TH1F(
"h_res",
"ModuleT0: residuals; residual - p0 [ps]", 200, -100, 100)
219 h_pul = TH1F(
"h_pul",
"ModuleT0: pulls; (residual - p0) / error", 200, -10, 10)
220 for i, h
in enumerate(histos):
223 fun = h.GetFunction(
"pol0")
226 p0 = fun.GetParameter(0)
227 err = fun.GetParError(0)
228 h_offset.SetBinContent(i + 1, p0)
229 h_offset.SetBinError(i + 1, err)
230 h_chi.SetBinContent(i + 1, fun.GetChisquare() / max(fun.GetNDF(), 1))
231 for ibin
in range(1, h.GetNbinsX() + 1):
232 err = h.GetBinError(ibin)
234 h_res.Fill(h.GetBinContent(ibin) - p0)
235 h_pul.Fill((h.GetBinContent(ibin) - p0) / err)
241 histos = [h_offset, h_chi, h_res, h_pul]
242 h_offset.SetStats(
False)
243 h_chi.SetStats(
False)
244 gStyle.SetOptStat(
"rme")
245 for i, h
in enumerate(histos):
248 canvas.Print(outputFileName)
256 for slot
in range(1, 17):
258 name =
"slot" + f
'{slot:02d}'
259 histos = [file_in.Get(
"numActive_" + name), file_in.Get(
"numActiveCalibrated_" + name)]
260 legend = TLegend(0.1, 0.1, 0.7, 0.3)
261 legends.append(legend)
263 for i, h
in enumerate(histos):
267 text = h.GetTitle().split(
',')[0]
274 legend.AddEntry(h, text)
275 if legend.GetNRows() > 0:
277 canvas.Print(outputFileName)
284 for slot
in range(1, 17):
286 name =
"slot" + f
'{slot:02d}'
287 histos = [file_in.Get(
"numTBCalibrated_" + name), file_in.Get(
"numT0Calibrated_" + name)]
288 legend = TLegend(0.1, 0.1, 0.7, 0.3)
289 legends.append(legend)
291 for i, h
in enumerate(histos):
295 text = h.GetTitle().split(
',')[0]
300 legend.AddEntry(h, text)
301 if legend.GetNRows() > 0:
303 canvas.Print(outputFileName)
310 for slot
in range(1, 17):
312 name =
"slot" + f
'{slot:02d}'
313 h = file_in.Get(
"thrEffi_slot" + f
'{slot:02d}')
314 legend = TLegend(0.1, 0.1, 0.7, 0.3)
315 legends.append(legend)
319 text = h.GetTitle().split(
',')[0]
322 legend.AddEntry(h, text)
324 canvas.Print(outputFileName)
332 canvas.GetPad(cb + 1).SetGrid()
333 h = file_in.Get(
"asicShifts_" + str(cb))
338 canvas.Print(outputFileName)
344 gStyle.SetOptStat(
"e")
345 gStyle.SetStatY(0.99)
347 offsets = [file_in.Get(
"svdOffset"), file_in.Get(
"cdcOffset")]
348 sigmas = [file_in.Get(
"svdSigma"), file_in.Get(
"cdcSigma")]
349 components = [
'SVD',
'CDC']
357 hmin = min(hmin, h.GetMinimum())
358 hmax = max(hmax, h.GetMaximum())
359 hmin = round(hmin, 0) - 1
360 hmax = round(hmax, 0) + 1
361 for i, h
in enumerate(offsets):
366 h.SetMarkerColor(colors[i])
367 h.SetLineColor(colors[i])
370 for i, h
in enumerate(offsets):
371 if not h
or not sigmas[i]
or sigmas[i].Integral() == 0:
378 legend1.AddEntry(h, components[i])
385 hmax = max(hmax, h.GetMaximum())
386 for i, h
in enumerate(sigmas):
389 h.SetMaximum(hmax * 1.1)
391 h.SetMarkerColor(colors[i])
392 h.SetLineColor(colors[i])
395 for i, h
in enumerate(sigmas):
396 if not h
or h.Integral() == 0:
403 legend2.AddEntry(h, components[i])
406 fillPatt = [file_in.Get(
"fillPatternOffset"), file_in.Get(
"fillPatternFract")]
407 for i, h
in enumerate(fillPatt):
411 for k
in range(h.GetNbinsX()):
412 h.SetBinError(k + 1, h.GetBinContent(k + 1) / 1000)
415 canvas.Print(outputFileName)
420 gStyle.SetOptStat(
"rmei")
424 rqe_path = job_path +
'/TOP_photonYields/0/algorithm_output/photonYields-*.root'
425 rqeFileNames = glob.glob(rqe_path)
426 if len(rqeFileNames) == 0:
427 B2ERROR(rqe_path +
": no such files")
430 for fileName
in sorted(rqeFileNames):
431 rqeFile = TFile.Open(fileName)
433 B2ERROR(rqeFile +
": can't be open")
435 rqeFiles.append(rqeFile)
436 histos = [rqeFile.Get(
"RQE"), rqeFile.Get(
"RQEerr")]
437 expNo = fileName.split(
'/')[-1].split(
'-')[1]
442 if len(rqeHistos) == 4:
443 for i, h
in enumerate(rqeHistos):
447 canvas.Print(outputFileName)
452 if len(rqeHistos) > 0:
453 for i, h
in enumerate(rqeHistos):
457 canvas.Print(outputFileName)
462 canvas.Print(outputFileName +
"]")
468 for slot
in range(1, 17):
470 h = file_in.Get(
"hits_slot" + f
'{slot:02d}')
473 canvas.SaveAs(outputFileName.replace(
'.pdf',
'Hits.png'))
476if __name__ ==
"__main__":