13 Validation plots for TOP calibration.
16 from prompt
import ValidationSettings
17 from ROOT
import TFile, TH1F, TGraph, TCanvas, TLegend, gROOT, gStyle, PyConfig
18 from basf2
import B2ERROR
22 settings = ValidationSettings(name=
'TOP post-tracking calibration',
28 def 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" +
'{:0=2d}'.format(slot)
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" +
'{:0=2d}'.format(slot))
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" +
'{:0=2d}'.format(slot)
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]
272 legend.AddEntry(h, text)
273 if legend.GetNRows() > 0:
275 canvas.Print(outputFileName)
282 for slot
in range(1, 17):
284 name =
"slot" +
'{:0=2d}'.format(slot)
285 histos = [file_in.Get(
"numTBCalibrated_" + name), file_in.Get(
"numT0Calibrated_" + name)]
286 legend = TLegend(0.1, 0.1, 0.7, 0.3)
287 legends.append(legend)
289 for i, h
in enumerate(histos):
293 text = h.GetTitle().split(
',')[0]
298 legend.AddEntry(h, text)
299 if legend.GetNRows() > 0:
301 canvas.Print(outputFileName)
308 for slot
in range(1, 17):
310 name =
"slot" +
'{:0=2d}'.format(slot)
311 h = file_in.Get(
"thrEffi_slot" +
'{:0=2d}'.format(slot))
312 legend = TLegend(0.1, 0.1, 0.7, 0.3)
313 legends.append(legend)
317 text = h.GetTitle().split(
',')[0]
320 legend.AddEntry(h, text)
322 canvas.Print(outputFileName)
330 canvas.GetPad(cb + 1).SetGrid()
331 h = file_in.Get(
"asicShifts_" + str(cb))
336 canvas.Print(outputFileName)
340 canvas.Print(outputFileName +
"]")
346 for slot
in range(1, 17):
348 h = file_in.Get(
"hits_slot" +
'{:0=2d}'.format(slot))
351 canvas.SaveAs(outputFileName.replace(
'.pdf',
'Hits.png'))
354 if __name__ ==
"__main__":