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