12Validation plots for TOP calibration.
15from prompt
import ValidationSettings
16from ROOT
import TFile, TH1F, TGraph, TCanvas, TLegend, gROOT, gStyle, PyConfig
17from basf2
import B2ERROR
21settings = ValidationSettings(name=
'TOP post-tracking calibration',
27def run_validation(job_path, input_data_path, requested_iov, expert_config):
29 Makes validation plots
30 :job_path: path to top posttracking calibration output
31 :input_data_path: required argument but not used
32 :requested_iov: required argument but
not used
33 :expert_config: required argument but
not used
38 inputFileName = job_path +
'/TOP_validation/0/algorithm_output/TOPCalValidation.root'
39 outputFileName =
'TOPValidation.pdf'
43 PyConfig.IgnoreCommandLineOptions =
True
48 gStyle.SetHistMinimumZero(
True)
49 gStyle.SetLabelSize(0.05,
"X")
50 gStyle.SetLabelSize(0.05,
"Y")
51 gStyle.SetTitleSize(0.06,
"X")
52 gStyle.SetTitleSize(0.06,
"Y")
53 gStyle.SetTitleOffset(0.7,
"X")
54 gStyle.SetTitleOffset(0.8,
"Y")
55 gStyle.SetGridColor(11)
59 file_in = TFile.Open(inputFileName)
61 B2ERROR(inputFileName +
": file not found")
63 canvas = TCanvas(
"c1",
"c1", 1000, 750)
69 residuals_all = TH1F(
"residuals_all",
"ChannelT0 residuals; residuals [ns]", 200, -1.0, 1.0)
70 h_rms = TH1F(
"h_rms",
"Width of residuals (rms); slot; r.m.s [ps]", 16, 0.5, 16.5)
71 h_core = TH1F(
"h_core",
"Core width of residuals; slot; sigma [ps]", 16, 0.5, 16.5)
72 h_out = TH1F(
"h_out",
"Outlayers (more than 3 sigma); slot; fraction [%]", 16, 0.5, 16.5)
73 for slot
in range(1, 17):
74 name =
"slot" + f
'{slot:02d}'
75 h = file_in.Get(
"channelT0_" + name)
77 r = TH1F(
"residuals_" + name,
"ChannelT0, " + name +
"; residuals [ns]", 200, -1.0, 1.0)
81 for i
in range(1, h.GetNbinsX() + 1):
82 if h.GetBinError(i) > 0:
83 r.Fill(h.GetBinContent(i))
84 residuals_all.Fill(h.GetBinContent(i))
86 residuals_all.Fit(
"gaus",
"Q")
87 h_rms.SetBinContent(slot, r.GetRMS() * 1000)
88 fun = r.GetFunction(
"gaus")
92 h_core.SetBinContent(slot, fun.GetParameter(2) * 1000)
93 mean = fun.GetParameter(1)
94 wid = fun.GetParameter(2)
97 for i
in range(1, h.GetNbinsX() + 1):
98 if h.GetBinError(i) == 0:
101 if abs(h.GetBinContent(i) - mean) < 3 * wid:
104 h_out.SetBinContent(slot, (1 - n_in / n_all) * 100)
105 residuals_all.Fit(
"gaus",
"Q")
109 canvas.Print(outputFileName +
"[")
116 for i, h
in enumerate(channelT0s):
124 for ibin
in range(1, h.GetNbinsX() + 1):
125 if h.GetBinContent(ibin) > 1.0:
126 g_over.SetPoint(g_over.GetN(), h.GetBinCenter(ibin), 0.95)
127 elif h.GetBinContent(ibin) < -1.0:
128 g_under.SetPoint(g_under.GetN(), h.GetBinCenter(ibin), -0.95)
129 if g_over.GetN() > 0:
130 g_over.SetMarkerStyle(22)
131 g_over.SetMarkerColor(2)
133 graphs.append(g_over)
134 if g_under.GetN() > 0:
135 g_under.SetMarkerStyle(23)
136 g_under.SetMarkerColor(2)
138 graphs.append(g_under)
139 canvas.Print(outputFileName)
146 gStyle.SetOptStat(
"oue")
147 W = gStyle.GetStatW()
148 H = gStyle.GetStatH()
151 for i, h
in enumerate(residuals):
154 canvas.Print(outputFileName)
162 gStyle.SetOptFit(111)
164 histos = [residuals_all, h_rms, h_core, h_out]
165 for i, h
in enumerate(histos):
168 canvas.Print(outputFileName)
172 commonT0 = file_in.Get(
"commonT0")
175 commonT0.SetYTitle(commonT0.GetYaxis().GetTitle().replace(
'[ns]',
'[ps]'))
176 commonT0.SetMinimum(-100)
177 commonT0.SetMaximum(100)
178 commonT0.Fit(
"pol0",
"Q")
184 canvas.GetPad(2).SetGrid()
185 gStyle.SetHistMinimumZero(
False)
186 histos = [commonT0, file_in.Get(
"runIndex")]
187 for i, h
in enumerate(histos):
193 canvas.Print(outputFileName)
194 gStyle.SetHistMinimumZero(
True)
201 for slot
in range(1, 17):
203 h = file_in.Get(
"moduleT0_slot" + f
'{slot:02d}')
206 h.SetYTitle(h.GetYaxis().GetTitle().replace(
'[ns]',
'[ps]'))
211 canvas.Print(outputFileName)
215 h_offset = TH1F(
"h_offset",
"ModuleT0: fitted offset; slot; p0 [ps]", 16, 0.5, 16.5)
216 h_chi = TH1F(
"h_chi",
"ModuleT0: chi2/ndf; slot; #chi^{2}/ndf", 16, 0.5, 16.5)
217 h_res = TH1F(
"h_res",
"ModuleT0: residuals; residual - p0 [ps]", 200, -100, 100)
218 h_pul = TH1F(
"h_pul",
"ModuleT0: pulls; (residual - p0) / error", 200, -10, 10)
219 for i, h
in enumerate(histos):
222 fun = h.GetFunction(
"pol0")
225 p0 = fun.GetParameter(0)
226 err = fun.GetParError(0)
227 h_offset.SetBinContent(i + 1, p0)
228 h_offset.SetBinError(i + 1, err)
229 h_chi.SetBinContent(i + 1, fun.GetChisquare() / max(fun.GetNDF(), 1))
230 for ibin
in range(1, h.GetNbinsX() + 1):
231 err = h.GetBinError(ibin)
233 h_res.Fill(h.GetBinContent(ibin) - p0)
234 h_pul.Fill((h.GetBinContent(ibin) - p0) / err)
240 histos = [h_offset, h_chi, h_res, h_pul]
241 h_offset.SetStats(
False)
242 h_chi.SetStats(
False)
243 gStyle.SetOptStat(
"rme")
244 for i, h
in enumerate(histos):
247 canvas.Print(outputFileName)
255 for slot
in range(1, 17):
257 name =
"slot" + f
'{slot:02d}'
258 histos = [file_in.Get(
"numActive_" + name), file_in.Get(
"numActiveCalibrated_" + name)]
259 legend = TLegend(0.1, 0.1, 0.7, 0.3)
260 legends.append(legend)
262 for i, h
in enumerate(histos):
266 text = h.GetTitle().split(
',')[0]
271 legend.AddEntry(h, text)
272 if legend.GetNRows() > 0:
274 canvas.Print(outputFileName)
281 for slot
in range(1, 17):
283 name =
"slot" + f
'{slot:02d}'
284 histos = [file_in.Get(
"numTBCalibrated_" + name), file_in.Get(
"numT0Calibrated_" + name)]
285 legend = TLegend(0.1, 0.1, 0.7, 0.3)
286 legends.append(legend)
288 for i, h
in enumerate(histos):
292 text = h.GetTitle().split(
',')[0]
297 legend.AddEntry(h, text)
298 if legend.GetNRows() > 0:
300 canvas.Print(outputFileName)
307 for slot
in range(1, 17):
309 name =
"slot" + f
'{slot:02d}'
310 h = file_in.Get(
"thrEffi_slot" + f
'{slot:02d}')
311 legend = TLegend(0.1, 0.1, 0.7, 0.3)
312 legends.append(legend)
316 text = h.GetTitle().split(
',')[0]
319 legend.AddEntry(h, text)
321 canvas.Print(outputFileName)
329 canvas.GetPad(cb + 1).SetGrid()
330 h = file_in.Get(
"asicShifts_" + str(cb))
335 canvas.Print(outputFileName)
341 offsets = [file_in.Get(
"svdOffset"), file_in.Get(
"cdcOffset")]
342 sigmas = [file_in.Get(
"svdSigma"), file_in.Get(
"cdcSigma")]
343 components = [
'SVD',
'CDC']
351 hmin = min(hmin, h.GetMinimum())
352 hmax = max(hmax, h.GetMaximum())
353 hmin = round(hmin, 0) - 1
354 hmax = round(hmax, 0) + 1
355 for i, h
in enumerate(offsets):
360 h.SetMarkerColor(colors[i])
361 h.SetLineColor(colors[i])
364 for i, h
in enumerate(offsets):
365 if not h
or not sigmas[i]
or sigmas[i].Integral() == 0:
372 legend1.AddEntry(h, components[i])
379 hmax = max(hmax, h.GetMaximum())
380 for i, h
in enumerate(sigmas):
383 h.SetMaximum(hmax * 1.1)
385 h.SetMarkerColor(colors[i])
386 h.SetLineColor(colors[i])
389 for i, h
in enumerate(sigmas):
390 if not h
or h.Integral() == 0:
397 legend2.AddEntry(h, components[i])
400 fillPatt = [file_in.Get(
"fillPatternOffset"), file_in.Get(
"fillPatternFract")]
401 for i, h
in enumerate(fillPatt):
405 for k
in range(h.GetNbinsX()):
406 h.SetBinError(k + 1, h.GetBinContent(k + 1) / 1000)
409 canvas.Print(outputFileName)
413 canvas.Print(outputFileName +
"]")
419 for slot
in range(1, 17):
421 h = file_in.Get(
"hits_slot" + f
'{slot:02d}')
424 canvas.SaveAs(outputFileName.replace(
'.pdf',
'Hits.png'))
427if __name__ ==
"__main__":