Belle II Software development
ecl_timing.py
1
8
9"""
10ECL Timing Validation
11"""
12
13from prompt import ValidationSettings
14import sys
15from pathlib import Path
16
17
21
22
23settings = ValidationSettings(name='ECL crystal and crate time calibrations and validations',
24 description=__doc__,
25 download_files=['stdout'],
26 expert_config=None)
27
28
29def run_validation(job_path, input_data_path, requested_iov, expert_config, **kwargs):
30 # job_path will be replaced with path/to/calibration_results
31 # input_data_path will be replaced with path/to/data_path used for calibration, e.g. /group/belle2/dataprod/Data/PromptSkim/
32
33 # Verify that output from airflow is OK
34 from ROOT import TH1F, TCanvas, TFile, gStyle
35 import os
36
37 # Set root style so that there are ticks on all four sides of the plots
38 gStyle.SetPadTickX(1)
39 gStyle.SetPadTickY(1)
40
41 # Output information about the parameters passed to the function
42 print("job_path = ", job_path)
43 print("input_data_path = ", input_data_path)
44 print("requested_iov = ", requested_iov)
45 print("expert_config = ", expert_config)
46
47 if not os.path.exists('plots'):
48 os.makedirs('plots')
49
50 # Add underflow, overflow and fit result
51 gStyle.SetOptStat(1111111)
52 gStyle.SetOptFit(1111)
53
54 # ------------------------------------------------------------------------
55 # ------------------------------------------------------------------------
56 # ------------------------------------------------------------------------
57 # Define new validation histograms
58 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal = TH1F(
59 "clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal",
60 "Bhabha: Cluster t means;Block of runs with one crystal calibration;Mean elec ECL cluster time / run block. Err = RMS",
61 30, 1, 30)
62 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal = TH1F(
63 "peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal",
64 "Bhabha: Mean(cluster t fit means);Runs of const crys calib;Mean(elec time fit mean / crys)/run block. Err=fit sigma",
65 30, 1, 30)
66
67 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal = TH1F(
68 "clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal",
69 "Hadron: Cluster t means;Block of runs with one crystal calibration;Mean photon ECL cluster time / run block. Err = RMS",
70 30, 1, 30)
71 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal = TH1F(
72 "peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal",
73 "Hadron: Mean(cluster t fit means);Runs of const crys calib;Mean(photon time fit mean / crys)/run block. Err=fit sigma",
74 30, 1, 30)
75
76 myC = TCanvas("myC")
77
78 # ------------------------------------------------------------------------
79 # ------------------------------------------------------------------------
80 # ------------------------------------------------------------------------
81 # Crate calibrations
82 print("\n---------------------------------------- \nBhabha crate calibrations: \n\n")
83 crate_calib_output_dir = Path(job_path)
84 crate_calib_files = sorted(crate_calib_output_dir.glob('**/eclBhabhaTAlgorithm_cratesAllRuns.root'))
85
86 print("List of crate calibration files:\n")
87 print(crate_calib_files)
88
89 num_files = len(crate_calib_files)
90 print(f'Looping over {num_files} files')
91 for count, in_file_name in enumerate(crate_calib_files, start=1):
92 in_file = TFile(str(in_file_name))
93 print("--------------------\nReading file ", in_file, "\n Crate calib iteration = ", count, "\n")
94
95 inFileBaseName = str(in_file_name)
96 inFileBaseName = os.path.basename(inFileBaseName)
97 inFileBaseName = inFileBaseName[:-5]
98 print("inFileBaseName = ", inFileBaseName)
99
100 # ECLcrateTimeCalibration_physics_#, where # sets the iteration
101 crate_calib_directory_iter = os.path.split(os.path.split(os.path.split(os.path.dirname(in_file_name))[0])[0])[1]
102
103 # Plots to read in and save as pdfs
104 tcrateNew_MINUS_tcrateOld_allRuns = in_file.Get("tcrateNew_MINUS_tcrateOld_allRuns")
105 tcrateNew_MINUS_tcrateOld_allRuns_allCrates = in_file.Get("tcrateNew_MINUS_tcrateOld_allRuns_allCrates")
106
107
108 tcrateNew_MINUS_tcrateOld_allRuns.Draw("")
109 tcrateNew_MINUS_tcrateOld_allRuns__Filename = str(
110 "plots/" +
111 crate_calib_directory_iter +
112 "__" +
113 "tcrateNew_MINUS_tcrateOld_allRuns__" +
114 inFileBaseName +
115 "__counter" +
116 str(count) +
117 ".pdf")
118 print("tcrateNew_MINUS_tcrateOld_allRuns__Filename = ", tcrateNew_MINUS_tcrateOld_allRuns__Filename)
119 myC.Print(tcrateNew_MINUS_tcrateOld_allRuns__Filename)
120
121 myC.SetLogy(1)
122 tcrateNew_MINUS_tcrateOld_allRuns.Draw("")
123 tcrateNew_MINUS_tcrateOld_allRunsLogY__Filename = str("plots/" + crate_calib_directory_iter + "__" +
124 "tcrateNew_MINUS_tcrateOld_allRuns__logY__" +
125 inFileBaseName + "__counter" + str(count) + ".pdf")
126 print("tcrateNew_MINUS_tcrateOld_allRunsLogY__Filename = ", tcrateNew_MINUS_tcrateOld_allRunsLogY__Filename)
127 myC.Print(tcrateNew_MINUS_tcrateOld_allRunsLogY__Filename)
128 myC.SetLogy(0)
129
130
131 tcrateNew_MINUS_tcrateOld_allRuns_allCrates.Draw("")
132 tcrateNew_MINUS_tcrateOld_allRuns_allCrates__Filename = str("plots/" + crate_calib_directory_iter + "__" +
133 "tcrateNew_MINUS_tcrateOld_allRuns_allCrates__" +
134 inFileBaseName + "__counter" + str(count) + ".pdf")
135 print("tcrateNew_MINUS_tcrateOld_allRuns_allCrates__Filename = ", tcrateNew_MINUS_tcrateOld_allRuns_allCrates__Filename)
136 myC.Print(tcrateNew_MINUS_tcrateOld_allRuns_allCrates__Filename)
137
138 myC.SetLogy(1)
139 tcrateNew_MINUS_tcrateOld_allRuns_allCrates.Draw("")
140 tcrateNew_MINUS_tcrateOld_allRuns_allCratesLogY__Filename = str(
141 "plots/" +
142 crate_calib_directory_iter +
143 "__" +
144 "tcrateNew_MINUS_tcrateOld_allRuns_allCrates__logY__" +
145 inFileBaseName +
146 "__counter" +
147 str(count) +
148 ".pdf")
149 print("tcrateNew_MINUS_tcrateOld_allRuns_allCratesLogY__Filename = ",
150 tcrateNew_MINUS_tcrateOld_allRuns_allCratesLogY__Filename)
151 myC.Print(tcrateNew_MINUS_tcrateOld_allRuns_allCratesLogY__Filename)
152 myC.SetLogy(0)
153
154 # ------------------------------------------------------------------------
155 # ------------------------------------------------------------------------
156 # ------------------------------------------------------------------------
157 # Crystal calibrations - before the crystal merger
158 print("\n---------------------------------------- \nBhabha crystal calibrations: \n\n")
159 crystal_calib_output_dir = Path(job_path)
160 crystal_calib_files = sorted(crystal_calib_output_dir.glob(
161 '**/ECLcrystalTimeCalibration_physics_*/*/*/eclBhabhaTAlgorithm_*.root'))
162
163 print("List of crystal calibration files:\n")
164 print(crystal_calib_files)
165
166 num_files = len(crystal_calib_files)
167 print(f'Looping over {num_files} files')
168 for count, in_file_name in enumerate(crystal_calib_files, start=1):
169 in_file = TFile(str(in_file_name))
170 print("--------------------\nReading file ", in_file, "\n crystal calib iteration = ", count, "\n")
171
172 inFileBaseName = str(in_file_name)
173 inFileBaseName = os.path.basename(inFileBaseName)
174 inFileBaseName = inFileBaseName[:-5]
175 print("inFileBaseName = ", inFileBaseName)
176
177 # ECLcrystalTimeCalibration_physics_#, where # sets the iteration
178 crystal_calib_directory_iter = os.path.split(os.path.split(os.path.split(os.path.dirname(in_file_name))[0])[0])[1]
179
180 # Plots to read in and save as pdfs
181 tsNew_MINUS_tsOld__cid = in_file.Get("tsNew_MINUS_tsOld__cid")
182 tsNew_MINUS_tsOld = in_file.Get("tsNew_MINUS_tsOld")
183 tsNew_MINUS_tsCustomPrev__cid = in_file.Get("tsNew_MINUS_tsCustomPrev__cid")
184 tsNew_MINUS_tsCustomPrev = in_file.Get("tsNew_MINUS_tsCustomPrev")
185 tsNew_MINUS_tsOldBhabha__cid = in_file.Get("tsNew_MINUS_tsOldBhabha__cid")
186 tsNew_MINUS_tsOldBhabha = in_file.Get("tsNew_MINUS_tsOldBhabha")
187 cutflow = in_file.Get("cutflow")
188 h_crysHits = in_file.Get("h_crysHits")
189
190
191 tsNew_MINUS_tsOld__cid.Draw("")
192 tsNew_MINUS_tsOld__cid.SetStats(0)
193 tsNew_MINUS_tsOld__cid.Draw("")
194 tsNew_MINUS_tsOld__cid__Filename = str("plots/" + crystal_calib_directory_iter + "__" + "tsNew_MINUS_tsOld__cid__" +
195 inFileBaseName + "__counter" + str(count) + ".pdf")
196 print("tsNew_MINUS_tsOld__cid__Filename = ", tsNew_MINUS_tsOld__cid__Filename)
197 myC.Print(tsNew_MINUS_tsOld__cid__Filename)
198
199
200 tsNew_MINUS_tsOld.Draw("")
201 tsNew_MINUS_tsOld__Filename = str("plots/" + crystal_calib_directory_iter + "__" + "tsNew_MINUS_tsOld__" +
202 inFileBaseName + "__counter" + str(count) + ".pdf")
203 print("tsNew_MINUS_tsOld__Filename = ", tsNew_MINUS_tsOld__Filename)
204 myC.Print(tsNew_MINUS_tsOld__Filename)
205
206 myC.SetLogy(1)
207 tsNew_MINUS_tsOld.Draw("")
208 tsNew_MINUS_tsOldLogY__Filename = str("plots/" + crystal_calib_directory_iter + "__" + "tsNew_MINUS_tsOld__logY__" +
209 inFileBaseName + "__counter" + str(count) + ".pdf")
210 print("tsNew_MINUS_tsOldLogY__Filename = ", tsNew_MINUS_tsOldLogY__Filename)
211 myC.Print(tsNew_MINUS_tsOldLogY__Filename)
212 myC.SetLogy(0)
213
214
215 tsNew_MINUS_tsCustomPrev__cid.Draw("")
216 tsNew_MINUS_tsCustomPrev__cid.SetStats(0)
217 tsNew_MINUS_tsCustomPrev__cid.Draw("")
218 tsNew_MINUS_tsCustomPrev__cid__Filename = str(
219 "plots/" +
220 crystal_calib_directory_iter +
221 "__" +
222 "tsNew_MINUS_tsCustomPrev__cid__" +
223 inFileBaseName +
224 "__counter" +
225 str(count) +
226 ".pdf")
227 print("tsNew_MINUS_tsCustomPrev__cid__Filename = ", tsNew_MINUS_tsCustomPrev__cid__Filename)
228 myC.Print(tsNew_MINUS_tsCustomPrev__cid__Filename)
229
230
231 tsNew_MINUS_tsCustomPrev.Draw("")
232 tsNew_MINUS_tsCustomPrev__Filename = str("plots/" + crystal_calib_directory_iter + "__" + "tsNew_MINUS_tsCustomPrev__" +
233 inFileBaseName + "__counter" + str(count) + ".pdf")
234 print("tsNew_MINUS_tsCustomPrev__Filename = ", tsNew_MINUS_tsCustomPrev__Filename)
235 myC.Print(tsNew_MINUS_tsCustomPrev__Filename)
236
237 myC.SetLogy(1)
238 tsNew_MINUS_tsCustomPrev.Draw("")
239 tsNew_MINUS_tsCustomPrevLogY__Filename = str(
240 "plots/" +
241 crystal_calib_directory_iter +
242 "__" +
243 "tsNew_MINUS_tsCustomPrev__logY__" +
244 inFileBaseName +
245 "__counter" +
246 str(count) +
247 ".pdf")
248 print("tsNew_MINUS_tsCustomPrevLogY__Filename = ", tsNew_MINUS_tsCustomPrevLogY__Filename)
249 myC.Print(tsNew_MINUS_tsCustomPrevLogY__Filename)
250 myC.SetLogy(0)
251
252
253 tsNew_MINUS_tsOldBhabha__cid.Draw("")
254 tsNew_MINUS_tsOldBhabha__cid.SetStats(0)
255 tsNew_MINUS_tsOldBhabha__cid.Draw("")
256 tsNew_MINUS_tsOldBhabha__cid__Filename = str(
257 "plots/" +
258 crystal_calib_directory_iter +
259 "__" +
260 "tsNew_MINUS_tsOldBhabha__cid__" +
261 inFileBaseName +
262 "__counter" +
263 str(count) +
264 ".pdf")
265 print("tsNew_MINUS_tsOldBhabha__cid__Filename = ", tsNew_MINUS_tsOldBhabha__cid__Filename)
266 myC.Print(tsNew_MINUS_tsOldBhabha__cid__Filename)
267
268
269 tsNew_MINUS_tsOldBhabha.Draw("")
270 tsNew_MINUS_tsOldBhabha__Filename = str("plots/" + crystal_calib_directory_iter + "__" + "tsNew_MINUS_tsOldBhabha__" +
271 inFileBaseName + "__counter" + str(count) + ".pdf")
272 print("tsNew_MINUS_tsOldBhabha__Filename = ", tsNew_MINUS_tsOldBhabha__Filename)
273 myC.Print(tsNew_MINUS_tsOldBhabha__Filename)
274
275 myC.SetLogy(1)
276 tsNew_MINUS_tsOldBhabha.Draw("")
277 tsNew_MINUS_tsOldBhabhaLogY__Filename = str(
278 "plots/" +
279 crystal_calib_directory_iter +
280 "__" +
281 "tsNew_MINUS_tsOldBhabha__logY__" +
282 inFileBaseName +
283 "__counter" +
284 str(count) +
285 ".pdf")
286 print("tsNew_MINUS_tsOldBhabhaLogY__Filename = ", tsNew_MINUS_tsOldBhabhaLogY__Filename)
287 myC.Print(tsNew_MINUS_tsOldBhabhaLogY__Filename)
288 myC.SetLogy(0)
289
290
291 cutflow.Draw("")
292 cutflow__Filename = str("plots/" + crystal_calib_directory_iter + "__" + "cutflow__" +
293 inFileBaseName + "__counter" + str(count) + ".pdf")
294 print("cutflow__Filename = ", cutflow__Filename)
295 myC.Print(cutflow__Filename)
296
297
298 myC.SetLogy(1)
299 h_crysHits.Draw("")
300 h_crysHits.SetStats(0)
301 h_crysHits.Draw("")
302 h_crysHits__Filename = str("plots/" + crystal_calib_directory_iter + "__" + "h_crysHits__" +
303 inFileBaseName + "__counter" + str(count) + ".pdf")
304 print("h_crysHits__Filename = ", h_crysHits__Filename)
305 myC.Print(h_crysHits__Filename)
306 myC.SetLogy(0)
307
308 # ------------------------------------------------------------------------
309 # ------------------------------------------------------------------------
310 # ------------------------------------------------------------------------
311 # crystal mergers
312 print("\n---------------------------------------- \nBhabha calibration crystal mergers: \n\n")
313 merger_alg_output_dir = Path(job_path)
314 merger_files = sorted(merger_alg_output_dir.glob('**/ECLCrystalTimeOffsetMerged_*.root'))
315
316 print("List of bhabha validation files:\n")
317 print(merger_files)
318
319 num_files = len(merger_files)
320 print(f'Looping over {num_files} files')
321 for count, in_file_name in enumerate(merger_files, start=1):
322 in_file = TFile(str(in_file_name))
323 print("--------------------\nReading file ", in_file, "\n Crystal calib iteration or blocks = ", count, "\n")
324
325 inFileBaseName = str(in_file_name)
326 inFileBaseName = os.path.basename(inFileBaseName)
327 inFileBaseName = inFileBaseName[:-5]
328 print("inFileBaseName = ", inFileBaseName)
329
330 # ecl_t_merge_#, where # sets the iteration
331 merge_directory_iter = os.path.split(os.path.split(os.path.split(os.path.dirname(in_file_name))[0])[0])[1]
332
333 # Plots to read in and save as pdfs
334 newBhabhaMinusCustomPrev__cid = in_file.Get("newBhabhaMinusCustomPrev__cid")
335 newBhabhaMinusCustomPrevBhabha__cid = in_file.Get("newBhabhaMinusCustomPrevBhabha__cid")
336 TsNewBhabha_MINUS_TsCustomPrev = in_file.Get("TsNewBhabha_MINUS_TsCustomPrev")
337 TsNewBhabha_MINUS_TsCustomPrevBhabha = in_file.Get("TsNewBhabha_MINUS_TsCustomPrevBhabha")
338
339
340 newBhabhaMinusCustomPrev__cid.Draw("")
341 newBhabhaMinusCustomPrev__cid.SetStats(0)
342 newBhabhaMinusCustomPrev__cid.Draw("")
343 newBhabhaMinusCustomPrev__cid__Filename = str("plots/" + merge_directory_iter + "__" + "newBhabhaMinusCustomPrev__cid__" +
344 inFileBaseName + "__counter" + str(count) + ".pdf")
345 print("newBhabhaMinusCustomPrev__cid__Filename = ", newBhabhaMinusCustomPrev__cid__Filename)
346 myC.Print(newBhabhaMinusCustomPrev__cid__Filename)
347
348
349 newBhabhaMinusCustomPrevBhabha__cid.Draw("")
350 newBhabhaMinusCustomPrevBhabha__cid.SetStats(0)
351 newBhabhaMinusCustomPrevBhabha__cid.Draw("")
352 newBhabhaMinusCustomPrevBhabha__cid__Filename = str(
353 "plots/" +
354 merge_directory_iter +
355 "__" +
356 "newBhabhaMinusCustomPrevBhabha__cid__" +
357 inFileBaseName +
358 "__counter" +
359 str(count) +
360 ".pdf")
361 print("newBhabhaMinusCustomPrevBhabha__cid__Filename = ", newBhabhaMinusCustomPrevBhabha__cid__Filename)
362 myC.Print(newBhabhaMinusCustomPrevBhabha__cid__Filename)
363
364
365 TsNewBhabha_MINUS_TsCustomPrev.Draw("")
366 TsNewBhabha_MINUS_TsCustomPrev__Filename = str("plots/" + merge_directory_iter + "__" + "TsNewBhabha_MINUS_TsCustomPrev__" +
367 inFileBaseName + "__counter" + str(count) + ".pdf")
368 print("TsNewBhabha_MINUS_TsCustomPrev__Filename = ", TsNewBhabha_MINUS_TsCustomPrev__Filename)
369 myC.Print(TsNewBhabha_MINUS_TsCustomPrev__Filename)
370
371 myC.SetLogy(1)
372 TsNewBhabha_MINUS_TsCustomPrev.Draw("")
373 TsNewBhabha_MINUS_TsCustomPrevLogY__Filename = str(
374 "plots/" +
375 merge_directory_iter +
376 "__" +
377 "TsNewBhabha_MINUS_TsCustomPrev__logY__" +
378 inFileBaseName +
379 "__counter" +
380 str(count) +
381 ".pdf")
382 print("TsNewBhabha_MINUS_TsCustomPrevLogY__Filename = ", TsNewBhabha_MINUS_TsCustomPrevLogY__Filename)
383 myC.Print(TsNewBhabha_MINUS_TsCustomPrevLogY__Filename)
384 myC.SetLogy(0)
385
386
387 TsNewBhabha_MINUS_TsCustomPrevBhabha.Draw("")
388 TsNewBhabha_MINUS_TsCustomPrevBhabha__Filename = str(
389 "plots/" +
390 merge_directory_iter +
391 "__" +
392 "TsNewBhabha_MINUS_TsCustomPrevBhabha__" +
393 inFileBaseName +
394 "__counter" +
395 str(count) +
396 ".pdf")
397 print("TsNewBhabha_MINUS_TsCustomPrevBhabha__Filename = ", TsNewBhabha_MINUS_TsCustomPrevBhabha__Filename)
398 myC.Print(TsNewBhabha_MINUS_TsCustomPrevBhabha__Filename)
399
400 myC.SetLogy(1)
401 TsNewBhabha_MINUS_TsCustomPrevBhabha.Draw("")
402 TsNewBhabha_MINUS_TsCustomPrevBhabhaLogY__Filename = str("plots/" + merge_directory_iter +
403 "__" + "TsNewBhabha_MINUS_TsCustomPrevBhabha__logY__" +
404 inFileBaseName + "__counter" + str(count) + ".pdf")
405 print("TsNewBhabha_MINUS_TsCustomPrevBhabhaLogY__Filename = ", TsNewBhabha_MINUS_TsCustomPrevBhabhaLogY__Filename)
406 myC.Print(TsNewBhabha_MINUS_TsCustomPrevBhabhaLogY__Filename)
407 myC.SetLogy(0)
408
409 # ------------------------------------------------------------------------
410 # ------------------------------------------------------------------------
411 # ------------------------------------------------------------------------
412 # bhabha self-consistency
413 print("\n---------------------------------------- \nBhabha self-consistency check: \n\n")
414 bhabhaVal_alg_output_dir = Path(job_path) / 'ECLcrystalTimeCalValidation_bhabhaPhysics/0/algorithm_output/'
415 bhabhaVal_files = sorted(bhabhaVal_alg_output_dir.glob('**/eclBhabhaTValidationAlgorithm_*.root'))
416
417 print("List of bhabha validation files:\n")
418 print(bhabhaVal_files)
419
420 num_files = len(bhabhaVal_files)
421 print(f'Looping over {num_files} files')
422 for count, in_file_name in enumerate(bhabhaVal_files, start=1):
423 in_file = TFile(str(in_file_name))
424 print("--------------------\nReading file ", in_file, ", crystal calib block # = ", count, "\n")
425
426 inFileBaseName = str(in_file_name)
427 inFileBaseName = os.path.basename(inFileBaseName)
428 inFileBaseName = inFileBaseName[:-5]
429 print("inFileBaseName = ", inFileBaseName)
430
431 bhabhaVal_directory = "ECLcrystalTimeCalValidation_bhabhaPhysics"
432
433 # Read in the plots
434 peakClusterTimesGoodFit = in_file.Get("peakClusterTimesGoodFit")
435 clusterTime = in_file.Get("clusterTime")
436
437 # Analyse the straight up cluster time histogram
438 title = "From: " + inFileBaseName
439 title = title + " : cluster time" + ", block " + str(count)
440 clusterTime.SetTitle(title)
441 clusterTime.Draw("")
442 clusterTime.Fit("gaus")
443
444 clusterTimeFilename = str("plots/" + inFileBaseName + "__clusterTime__block" + str(count) + ".pdf")
445 print("clusterTimeFilename = ", clusterTimeFilename)
446 myC.Print(clusterTimeFilename)
447
448 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinContent(count, clusterTime.GetMean())
449 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinError(count, clusterTime.GetStdDev())
450
451 # Analyse the histogram of the mean of the fit to the cluster times
452 title = "From: " + inFileBaseName
453 title = title + " : cluster time fits" + ", block " + str(count)
454 peakClusterTimesGoodFit.SetTitle(title)
455 peakClusterTimesGoodFit.Draw("")
456 peakClusterTimesGoodFit.Fit("gaus")
457
458 peakClusterTimesGoodFitFilename = str("plots/" + inFileBaseName + "__peakClusterTimesGoodFit__block" + str(count) + ".pdf")
459 print("peakClusterTimesGoodFitFilename = ", peakClusterTimesGoodFitFilename)
460 myC.Print(peakClusterTimesGoodFitFilename)
461
462 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinContent(count, peakClusterTimesGoodFit.GetMean())
463 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinError(count, peakClusterTimesGoodFit.GetStdDev())
464
465 # Plots to read in and save as pdfs
466 tsNew_MINUS_tsCustomPrev__cid = in_file.Get("tsNew_MINUS_tsCustomPrev__cid")
467 tsNew_MINUS_tsCustomPrev = in_file.Get("tsNew_MINUS_tsCustomPrev")
468 clusterTimePeak_ClusterEnergy_varBin = in_file.Get("clusterTimePeak_ClusterEnergy_varBin")
469 peakClusterTime_cid = in_file.Get("peakClusterTime_cid")
470 peakClusterTimes = in_file.Get("peakClusterTimes")
471 g_clusterTimeFractionInWindowInGoodECLRings__cid = in_file.Get("g_clusterTimeFractionInWindowInGoodECLRings__cid")
472 clusterTimeFractionInWindow = in_file.Get("clusterTimeFractionInWindow")
473
474
475 tsNew_MINUS_tsCustomPrev__cid.Draw("")
476 tsNew_MINUS_tsCustomPrev__cid.SetStats(0)
477 tsNew_MINUS_tsCustomPrev__cid.Draw("")
478 tsNew_MINUS_tsCustomPrev__cid__Filename = str("plots/" + bhabhaVal_directory + "__" + "tsNew_MINUS_tsCustomPrev__cid__" +
479 inFileBaseName + "__block" + str(count) + ".pdf")
480 print("tsNew_MINUS_tsCustomPrev__cid__Filename = ", tsNew_MINUS_tsCustomPrev__cid__Filename)
481 myC.Print(tsNew_MINUS_tsCustomPrev__cid__Filename)
482
483
484 tsNew_MINUS_tsCustomPrev.Draw("")
485 tsNew_MINUS_tsCustomPrev__Filename = str("plots/" + bhabhaVal_directory + "__" + "tsNew_MINUS_tsCustomPrev__" +
486 inFileBaseName + "__block" + str(count) + ".pdf")
487 print("tsNew_MINUS_tsCustomPrev__Filename = ", tsNew_MINUS_tsCustomPrev__Filename)
488 myC.Print(tsNew_MINUS_tsCustomPrev__Filename)
489
490 myC.SetLogy(1)
491 tsNew_MINUS_tsCustomPrev.Draw("")
492 tsNew_MINUS_tsCustomPrevLogY__Filename = str("plots/" + bhabhaVal_directory + "__" + "tsNew_MINUS_tsCustomPrev__logY__" +
493 inFileBaseName + "__block" + str(count) + ".pdf")
494 print("tsNew_MINUS_tsCustomPrevLogY__Filename = ", tsNew_MINUS_tsCustomPrevLogY__Filename)
495 myC.Print(tsNew_MINUS_tsCustomPrevLogY__Filename)
496 myC.SetLogy(0)
497
498
499 clusterTimePeak_ClusterEnergy_varBin.Draw("")
500 clusterTimePeak_ClusterEnergy_varBin.SetStats(0)
501 clusterTimePeak_ClusterEnergy_varBin.Draw("")
502 clusterTimePeak_ClusterEnergy_varBin.SetMinimum(-3)
503 clusterTimePeak_ClusterEnergy_varBin.SetMaximum(3)
504 clusterTimePeak_ClusterEnergy_varBinLogX__Filename = str("plots/" + bhabhaVal_directory +
505 "__" + "clusterTimePeak_ClusterEnergy_varBin__logX__" +
506 inFileBaseName + "__block" + str(count) + ".pdf")
507 print("clusterTimePeak_ClusterEnergy_varBinLogX__Filename = ", clusterTimePeak_ClusterEnergy_varBinLogX__Filename)
508 myC.Print(clusterTimePeak_ClusterEnergy_varBinLogX__Filename)
509
510
511 peakClusterTime_cid.Draw("")
512 peakClusterTime_cid.SetStats(0)
513 peakClusterTime_cid.Draw("")
514 peakClusterTime_cid__Filename = str("plots/" + bhabhaVal_directory + "__" + "peakClusterTime_cid__" +
515 inFileBaseName + "__block" + str(count) + ".pdf")
516 print("peakClusterTime_cid__Filename = ", peakClusterTime_cid__Filename)
517 myC.Print(peakClusterTime_cid__Filename)
518
519
520 peakClusterTimes.Draw("")
521 peakClusterTimes__Filename = str("plots/" + bhabhaVal_directory + "__" + "peakClusterTimes__" +
522 inFileBaseName + "__block" + str(count) + ".pdf")
523 print("peakClusterTimes__Filename = ", peakClusterTimes__Filename)
524 myC.Print(peakClusterTimes__Filename)
525
526
527 g_clusterTimeFractionInWindowInGoodECLRings__cid.Draw("")
528 g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename = str(
529 "plots/" +
530 bhabhaVal_directory +
531 "__" +
532 "g_clusterTimeFractionInWindowInGoodECLRings__cid__" +
533 inFileBaseName +
534 "__block" +
535 str(count) +
536 ".pdf")
537 print("g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename = ",
538 g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename)
539 myC.Print(g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename)
540
541
542 clusterTimeFractionInWindow.Draw("")
543 clusterTimeFractionInWindow__Filename = str("plots/" + bhabhaVal_directory + "__" + "clusterTimeFractionInWindow__" +
544 inFileBaseName + "__block" + str(count) + ".pdf")
545 print("clusterTimeFractionInWindow__Filename = ", clusterTimeFractionInWindow__Filename)
546 myC.Print(clusterTimeFractionInWindow__Filename)
547
548 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Draw("")
549 myC.Print("plots/crystalCalibBlocksBhabhaVal__clusterTime_histMeanStdDev.pdf")
550
551 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Draw("")
552 myC.Print("plots/crystalCalibBlocksBhabhaVal__peakClusterTimesGoodFit_histMeanStdDev.pdf")
553
554 # ------------------------------------------------------------------------
555 # ------------------------------------------------------------------------
556 # ------------------------------------------------------------------------
557 # Hadron validation
558 print("\n---------------------------------------- \nHadron self-consistency check: \n\n")
559 hadronVal_alg_output_dir = Path(job_path) / 'ECLcrystalTimeCalValidation_hadronPhysics/0/algorithm_output/'
560 hadronVal_files = sorted(hadronVal_alg_output_dir.glob('**/eclHadronTValidationAlgorithm_*.root'))
561
562 print("List of hadron validation files:\n")
563 print(hadronVal_files)
564
565 num_files = len(hadronVal_files)
566 print(f'Looping over {num_files} files')
567 for count, in_file_name in enumerate(hadronVal_files, start=1):
568 in_file = TFile(str(in_file_name))
569 print("--------------------\nReading file ", in_file, ", crystal calib block # = ", count, "\n")
570
571 inFileBaseName = str(in_file_name)
572 inFileBaseName = os.path.basename(inFileBaseName)
573 inFileBaseName = inFileBaseName[:-5]
574 print("inFileBaseName = ", inFileBaseName)
575
576 hadVal_directory = "ECLcrystalTimeCalValidation_hadronPhysics"
577
578 # Read in the plots
579 peakClusterTimesGoodFit = in_file.Get("peakClusterTimesGoodFit")
580 clusterTime = in_file.Get("clusterTime")
581
582 # Analyse the straight up cluster time histogram
583 title = "From: " + inFileBaseName
584 title = title + " : cluster time" + ", block " + str(count)
585 clusterTime.SetTitle(title)
586 clusterTime.Draw("")
587 clusterTime.Fit("gaus")
588
589 clusterTimeFilename = str("plots/" + inFileBaseName + "__clusterTime__block" + str(count) + ".pdf")
590 print("clusterTimeFilename = ", clusterTimeFilename)
591 myC.Print(clusterTimeFilename)
592
593 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinContent(count, clusterTime.GetMean())
594 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinError(count, clusterTime.GetStdDev())
595
596 # Analyse the histogram of the mean of the fit to the cluster times
597 title = "From: " + inFileBaseName
598 title = title + " : cluster time fits" + ", block " + str(count)
599 peakClusterTimesGoodFit.SetTitle(title)
600 peakClusterTimesGoodFit.Draw("")
601 peakClusterTimesGoodFit.Fit("gaus")
602
603 peakClusterTimesGoodFitFilename = str("plots/" + inFileBaseName + "__peakClusterTimesGoodFit __block" + str(count) + ".pdf")
604 print("peakClusterTimesGoodFitFilename = ", peakClusterTimesGoodFitFilename)
605 myC.Print(peakClusterTimesGoodFitFilename)
606
607 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinContent(count, peakClusterTimesGoodFit.GetMean())
608 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinError(count, peakClusterTimesGoodFit.GetStdDev())
609
610 # Plots to read in and save as pdfs
611 tsNew_MINUS_tsCustomPrev__cid = in_file.Get("tsNew_MINUS_tsCustomPrev__cid")
612 tsNew_MINUS_tsCustomPrev = in_file.Get("tsNew_MINUS_tsCustomPrev")
613 clusterTimePeak_ClusterEnergy_varBin = in_file.Get("clusterTimePeak_ClusterEnergy_varBin")
614 peakClusterTime_cid = in_file.Get("peakClusterTime_cid")
615 peakClusterTimes = in_file.Get("peakClusterTimes")
616 g_clusterTimeFractionInWindowInGoodECLRings__cid = in_file.Get("g_clusterTimeFractionInWindowInGoodECLRings__cid")
617 clusterTimeFractionInWindow = in_file.Get("clusterTimeFractionInWindow")
618
619
620 tsNew_MINUS_tsCustomPrev__cid.Draw("")
621 tsNew_MINUS_tsCustomPrev__cid.SetStats(0)
622 tsNew_MINUS_tsCustomPrev__cid.Draw("")
623 tsNew_MINUS_tsCustomPrev__cid__Filename = str("plots/" + hadVal_directory + "__" + "tsNew_MINUS_tsCustomPrev__cid__" +
624 inFileBaseName + "__block" + str(count) + ".pdf")
625 print("tsNew_MINUS_tsCustomPrev__cid__Filename = ", tsNew_MINUS_tsCustomPrev__cid__Filename)
626 myC.Print(tsNew_MINUS_tsCustomPrev__cid__Filename)
627
628
629 tsNew_MINUS_tsCustomPrev.Draw("")
630 tsNew_MINUS_tsCustomPrev__Filename = str("plots/" + hadVal_directory + "__" + "tsNew_MINUS_tsCustomPrev__" +
631 inFileBaseName + "__block" + str(count) + ".pdf")
632 print("tsNew_MINUS_tsCustomPrev__Filename = ", tsNew_MINUS_tsCustomPrev__Filename)
633 myC.Print(tsNew_MINUS_tsCustomPrev__Filename)
634
635 myC.SetLogy(1)
636 tsNew_MINUS_tsCustomPrev.Draw("")
637 tsNew_MINUS_tsCustomPrevLogY__Filename = str("plots/" + hadVal_directory + "__" + "tsNew_MINUS_tsCustomPrev__logY__" +
638 inFileBaseName + "__block" + str(count) + ".pdf")
639 print("tsNew_MINUS_tsCustomPrevLogY__Filename = ", tsNew_MINUS_tsCustomPrevLogY__Filename)
640 myC.Print(tsNew_MINUS_tsCustomPrevLogY__Filename)
641 myC.SetLogy(0)
642
643
644 myC.SetLogx(1)
645 clusterTimePeak_ClusterEnergy_varBin.Draw("")
646 clusterTimePeak_ClusterEnergy_varBin.SetStats(0)
647 clusterTimePeak_ClusterEnergy_varBin.Draw("")
648 clusterTimePeak_ClusterEnergy_varBin.SetMinimum(-10)
649 clusterTimePeak_ClusterEnergy_varBin.SetMaximum(5)
650 clusterTimePeak_ClusterEnergy_varBinLogX__Filename = str("plots/" + hadVal_directory +
651 "__" + "clusterTimePeak_ClusterEnergy_varBin__logX__" +
652 inFileBaseName + "__block" + str(count) + ".pdf")
653 print("clusterTimePeak_ClusterEnergy_varBinLogX__Filename = ", clusterTimePeak_ClusterEnergy_varBinLogX__Filename)
654 myC.Print(clusterTimePeak_ClusterEnergy_varBinLogX__Filename)
655 myC.SetLogx(0)
656
657
658 peakClusterTime_cid.Draw("")
659 peakClusterTime_cid.SetStats(0)
660 peakClusterTime_cid.Draw("")
661 peakClusterTime_cid__Filename = str("plots/" + hadVal_directory + "__" + "peakClusterTime_cid__" +
662 inFileBaseName + "__block" + str(count) + ".pdf")
663 print("peakClusterTime_cid__Filename = ", peakClusterTime_cid__Filename)
664 myC.Print(peakClusterTime_cid__Filename)
665
666
667 peakClusterTimes.Draw("")
668 peakClusterTimes__Filename = str("plots/" + hadVal_directory + "__" + "peakClusterTimes__" +
669 inFileBaseName + "__block" + str(count) + ".pdf")
670 print("peakClusterTimes__Filename = ", peakClusterTimes__Filename)
671 myC.Print(peakClusterTimes__Filename)
672
673
674 g_clusterTimeFractionInWindowInGoodECLRings__cid.Draw("")
675 g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename = str(
676 "plots/" +
677 hadVal_directory +
678 "__" +
679 "g_clusterTimeFractionInWindowInGoodECLRings__cid__" +
680 inFileBaseName +
681 "__block" +
682 str(count) +
683 ".pdf")
684 print("g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename = ",
685 g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename)
686 myC.Print(g_clusterTimeFractionInWindowInGoodECLRings__cid__Filename)
687
688
689 clusterTimeFractionInWindow.Draw("")
690 clusterTimeFractionInWindow__Filename = str("plots/" + hadVal_directory + "__" + "clusterTimeFractionInWindow__" +
691 inFileBaseName + "__block" + str(count) + ".pdf")
692 print("clusterTimeFractionInWindow__Filename = ", clusterTimeFractionInWindow__Filename)
693 myC.Print(clusterTimeFractionInWindow__Filename)
694
695 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.Draw("")
696 myC.Print("plots/crystalCalibBlocksHadronVal__clusterTime_histMeanStdDev.pdf")
697
698 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.Draw("")
699 myC.Print("plots/crystalCalibBlocksHadronVal__peakClusterTimesGoodFit_histMeanStdDev.pdf")
700
701 # ------------------------------------------------------------------------
702 # Write out histograms
703 fout = TFile("ecl_timing_validateAirflow.root", "recreate")
704
705 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Write()
706 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Write()
707 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.Write()
708 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.Write()
709
710 fout.Close()
711
712
713if __name__ == "__main__":
714 run_validation(*sys.argv[1:])