15 from prompt
import ValidationSettings
18 from pathlib
import Path
27 settings = ValidationSettings(name=
'ECL_timing',
29 download_files=[
'stdout'],
33 def run_validation(job_path, input_data_path, requested_iov, expert_config, **kwargs):
38 from ROOT
import TH1F, TCanvas, TFile, TGraph, TLine, kRed, gStyle
41 from array
import array
44 r.gStyle.SetPadTickX(1)
45 r.gStyle.SetPadTickY(1)
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)
53 if not os.path.exists(
'plots'):
57 gStyle.SetOptStat(1111111)
58 gStyle.SetOptFit(1111)
62 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal = TH1F(
63 "clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal",
64 "Bhabha: Cluster t means;Block of runs with one crystal calibration;Mean elec ECL cluster time / run block. Err = RMS",
66 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal = TH1F(
67 "peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal",
68 "Bhabha: Mean(cluster t fit means);Runs of const crys calib;Mean(elec time fit mean / crys)/run block. Err=fit sigma",
71 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal = TH1F(
72 "clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal",
73 "Hadron: Cluster t means;Block of runs with one crystal calibration;Mean photon ECL cluster time / run block. Err = RMS",
75 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal = TH1F(
76 "peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal",
77 "Hadron: Mean(cluster t fit means);Runs of const crys calib;Mean(photon time fit mean / crys)/run block. Err=fit sigma",
84 print(
"\n---------------------------------------- \nBhabha self-consistency check: \n\n")
85 bhabhaVal_alg_output_dir = Path(job_path) /
'ECLcrystalTimeCalValidation_bhabhaPhysics/0/algorithm_output/'
86 bhabhaVal_files = sorted(bhabhaVal_alg_output_dir.glob(
'**/eclBhabhaTValidationAlgorithm_*.root'))
88 print(
"List of bhabha validation files:\n")
89 print(bhabhaVal_files)
91 num_files = len(bhabhaVal_files)
92 print(f
'Looping over {num_files} files')
93 for count, in_file_name
in enumerate(bhabhaVal_files, start=1):
94 in_file = r.TFile(str(in_file_name))
95 print(
"--------------------\nReading file ", in_file,
", crystal calib block # = ", count,
"\n")
97 inFileBaseName = str(in_file_name)
98 inFileBaseName = os.path.basename(inFileBaseName)
99 inFileBaseName = inFileBaseName[:-5]
100 print(
"inFileBaseName = ", inFileBaseName)
103 peakClusterTimesGoodFit = in_file.Get(
"peakClusterTimesGoodFit")
104 clusterTime = in_file.Get(
"clusterTime")
107 title =
"From: " + inFileBaseName
108 title = title +
" : cluster time" +
", block " + str(count)
109 clusterTime.SetTitle(title)
111 clusterTime.Fit(
"gaus")
113 clusterTimeFilename = str(
"plots/clusterTime__" + inFileBaseName +
"__block" + str(count) +
".pdf")
114 print(
"clusterTimeFilename = ", clusterTimeFilename)
115 myC.Print(clusterTimeFilename)
117 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinContent(count, clusterTime.GetMean())
118 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinError(count, clusterTime.GetStdDev())
121 title =
"From: " + inFileBaseName
122 title = title +
" : cluster time fits" +
", block " + str(count)
123 peakClusterTimesGoodFit.SetTitle(title)
124 peakClusterTimesGoodFit.Draw(
"")
125 peakClusterTimesGoodFit.Fit(
"gaus")
127 peakClusterTimesGoodFitFilename = str(
"plots/peakClusterTimesGoodFit__" + inFileBaseName +
"__block" + str(count) +
".pdf")
128 print(
"peakClusterTimesGoodFitFilename = ", peakClusterTimesGoodFitFilename)
129 myC.Print(peakClusterTimesGoodFitFilename)
131 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinContent(count, peakClusterTimesGoodFit.GetMean())
132 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.SetBinError(count, peakClusterTimesGoodFit.GetStdDev())
134 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Draw(
"")
135 myC.Print(
"plots/clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.pdf")
137 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Draw(
"")
138 myC.Print(
"plots/peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.pdf")
142 print(
"\n---------------------------------------- \nHadron self-consistency check: \n\n")
143 hadronVal_alg_output_dir = Path(job_path) /
'ECLcrystalTimeCalValidation_hadronPhysics/0/algorithm_output/'
144 hadronVal_files = sorted(hadronVal_alg_output_dir.glob(
'**/eclHadronTValidationAlgorithm_*.root'))
146 print(
"List of hadron validation files:\n")
147 print(hadronVal_files)
149 num_files = len(hadronVal_files)
150 print(f
'Looping over {num_files} files')
151 for count, in_file_name
in enumerate(hadronVal_files, start=1):
152 in_file = r.TFile(str(in_file_name))
153 print(
"--------------------\nReading file ", in_file,
", crystal calib block # = ", count,
"\n")
155 inFileBaseName = str(in_file_name)
156 inFileBaseName = os.path.basename(inFileBaseName)
157 inFileBaseName = inFileBaseName[:-5]
158 print(
"inFileBaseName = ", inFileBaseName)
161 peakClusterTimesGoodFit = in_file.Get(
"peakClusterTimesGoodFit")
162 clusterTime = in_file.Get(
"clusterTime")
165 title =
"From: " + inFileBaseName
166 title = title +
" : cluster time" +
", block " + str(count)
167 clusterTime.SetTitle(title)
169 clusterTime.Fit(
"gaus")
171 clusterTimeFilename = str(
"plots/clusterTime__" + inFileBaseName +
"__block" + str(count) +
".pdf")
172 print(
"clusterTimeFilename = ", clusterTimeFilename)
173 myC.Print(clusterTimeFilename)
175 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinContent(count, clusterTime.GetMean())
176 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinError(count, clusterTime.GetStdDev())
179 title =
"From: " + inFileBaseName
180 title = title +
" : cluster time fits" +
", block " + str(count)
181 peakClusterTimesGoodFit.SetTitle(title)
182 peakClusterTimesGoodFit.Draw(
"")
183 peakClusterTimesGoodFit.Fit(
"gaus")
185 peakClusterTimesGoodFitFilename = str(
"plots/peakClusterTimesGoodFit__" + inFileBaseName +
"__block" + str(count) +
".pdf")
186 print(
"peakClusterTimesGoodFitFilename = ", peakClusterTimesGoodFitFilename)
187 myC.Print(peakClusterTimesGoodFitFilename)
189 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinContent(count, peakClusterTimesGoodFit.GetMean())
190 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.SetBinError(count, peakClusterTimesGoodFit.GetStdDev())
192 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.Draw(
"")
193 myC.Print(
"plots/clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.pdf")
195 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.Draw(
"")
196 myC.Print(
"plots/peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.pdf")
200 fout = TFile(
"ecl_timing_validateAirflow.root",
"recreate")
202 clusterTime_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Write()
203 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksBhabhaVal.Write()
204 clusterTime_histMeanStdDev_CrystalCalibBlocksHadronVal.Write()
205 peakClusterTimesGoodFit_histMeanStdDev_CrystalCalibBlocksHadronVal.Write()
210 if __name__ ==
"__main__":
211 run_validation(*sys.argv[1:])