10 with open(name)
as fp:
11 lines = fp.readlines()
13 if(line.startswith(
'[\'')):
15 line = line.rstrip(
']\n')
17 arrayline = line.split(
' : ')
18 mydict = json.loads(arrayline[1])
20 iov = line[:line.find(
" - ")]
21 print(
"Data base IOV: %s" % line)
28 report_dict = {
"Blayer":0 ,
"L1":0 ,
"L2":0 ,
"Disk":0,
"unexp.":0}
29 with open(name)
as fp:
30 lines = fp.readlines()
33 if line.startswith(
"L")
or line.startswith(
"D"):
35 if line.startswith(
"L0"): report_dict[
"Blayer"] += 1
36 elif line.startswith(
"L1"): report_dict[
"L1"] += 1
37 elif line.startswith(
"L2"): report_dict[
"L2"] += 1
38 elif line.startswith(
"D"): report_dict[
"Disk"] += 1
41 report_dict[
"unexp."] += 1
43 splitline = line.rstrip(
"\n").
split(
" ")
44 if len(splitline) == 2:
45 mydict[splitline[1]] = []
48 print(
"ReadNewCalib - ERROR Length of the module is not the correct one. Expected ['module_name', 'hash_ID']. Value:", splitline)
49 elif line.startswith(
"I"):
50 splitline = line.rstrip(
"\n").
split(
" ")
52 float_splitline = [
float(string)
for string
in splitline]
53 mydict[mod].
append(float_splitline)
55 return mydict, report_dict
59 with open(name)
as fp:
60 lines = fp.readlines()
63 if line.startswith(
"L")
or line.startswith(
"D"):
65 splitline = line.rstrip(
"\n").
split(
" : ")
67 if len(splitline) == 2:
68 mydict[splitline[0]] = []
71 print(
"ReadNewCalib - ERROR Length of the module is not the correct one. Expected ['module_name', 'hash_ID']. Value:", splitline)
72 elif line.startswith(
"I"):
73 splitline = line.rstrip(
"\n").
split(
" ")
75 float_splitline = [
float(string)
for string
in splitline]
76 mydict[mod].
append(float_splitline)
85 recovered_value =
avg(thr1, thr2)
87 if recovered_value == 0:
89 recovered_value = ref_val
91 recovered_value =
sum(listarray)/len(listarray)
92 return recovered_value
101 return sum(listarray)/len(listarray)
108 report_counter_dict = {
"empty" : 0 ,
"all_zeros":0}
110 for module, frontEnds
in new_calib.items():
114 for itr_fe
in range(nFE):
116 failures = frontEnds[itr_fe].
count(0) + frontEnds[itr_fe].
count(-28284.3)
119 if module
not in report_dict:
120 report_dict[module] = []
123 if failures != len(frontEnds[itr_fe]):
124 report_counter_dict[
"empty"] += 1
125 report_dict[module].
append(
" FE%02d with %i zeros. Positions:" % (itr_fe,failures))
128 for itr_par
in range(len(frontEnds[itr_fe])):
129 if( frontEnds[itr_fe][itr_par] == 0
or frontEnds[itr_fe][itr_par] == -28284.3):
131 report_dict[module][-1] = report_dict[module][-1] + (
" %s,"%(
str(itr_par)))
134 val_list = [new_calib[module][i][itr_par]
for i
in range(nFE)
if new_calib[module][i][itr_par] != 0 ]
135 val_list_fit = [new_calib[module][i][itr_par]
for i
in range(nFE)
if new_calib[module][i][itr_par] != 0
and new_calib[module][i][itr_par] != -28284.3 ]
139 new_calib[module][itr_fe][itr_par] =
recover_thr(frontEnds[itr_fe][4], frontEnds[itr_fe][8], val_list, ref_calib[module][itr_fe][itr_par] )
143 new_calib[module][itr_fe][itr_par] =
recover_thr(frontEnds[itr_fe][0], frontEnds[itr_fe][8], val_list, ref_calib[module][itr_fe][itr_par])
147 new_calib[module][itr_fe][itr_par] =
recover_thr(frontEnds[itr_fe][0], frontEnds[itr_fe][4], val_list, ref_calib[module][itr_fe][itr_par])
152 if itr_par == 13
or itr_par == 16:
153 new_calib[module][itr_fe][itr_par] =
recover(val_list_fit, ref_calib[module][itr_fe][itr_par])
155 new_calib[module][itr_fe][itr_par] =
recover(val_list, ref_calib[module][itr_fe][itr_par])
159 report_counter_dict[
"all_zeros"] += 1
160 report_dict[module].
append(
" FE%02d full copy" % itr_fe)
161 new_calib[module][itr_fe] = ref_calib[module][itr_fe]
163 return report_dict, report_counter_dict
168 from PixelCalibAlgs.CheckValues
import CheckThresholds
172 updated_calib = ref_calib.copy()
175 updated_calib.update(new_calib)
178 for key, values
in updated_calib.items():
179 total_fe += len(values)
182 print(
"%-45s: %6i" % (
"Total modules in the calibration candidate",len(updated_calib)))
183 print(
"%-45s: %6i\n" % (
"Total FE in the calibration candidate",total_fe))
190 Fprint(updated_calib,
"PIX_FINAL_calibration_candidate.txt")
196 for key, values
in dict.items():
199 f.write(
"%s %i %i %i %i %i %i %i %i %i %i %i %i %.6g %.6g %.6g %.6g %.6g %.6g %.6g %.6g\n" % (
201 value[ 0], value[ 1], value[ 2], value[ 3],
202 value[ 4], value[ 5], value[ 6], value[ 7],
203 value[ 8], value[ 9], value[10], value[11],
204 value[12], value[13], value[14],
205 value[15], value[16], value[17],
211 new_calib, read_report =
ReadNewCalib(
"calibration_merged.txt")
214 print(
"Recovering missing information..")
217 print(
"Validating and updating reference calibration.. ")
218 UpdateAndSave(new_calib,
"latest",
"calibration_merged.txt",ref_calib)
220 f =
open(
"log_recovery.txt",
"w")
221 str =
"-------- SUMMARY OF PIXEL CALIB RECOVERY --------\n"
222 str +=
"Modules Calibrated:\n"
224 for key,value
in read_report.items():
225 str +=
"%10s read: %4i\n" % (key, value)
228 str +=
"Error counters:\n"
229 str +=
" %15s: %5i\n" % (
"Empty values", counter_report[
"empty"])
230 str +=
" %15s: %5i\n" % (
"Full FE copied", counter_report[
"all_zeros"])
233 print(
"More information in: log_recovery.txt")
234 print(
"NEW CALIBRATION file to update the DB: PIX_FINAL_calibration_candidate.txt")
236 str +=
"""Positions of single 0's:
237 0: normal_threshold, 1: normal_RMS, 2: normal_noise, 3: normal_intime
238 4: long_threshold , 5: long_RMS , 6: long_noise , 7: long_intime
239 8: ganged_threshold, 9: ganged_RMS, 10: ganged_noise, 11: ganged_intime
240 12: 13: 14: Fitting for normal pixels
241 15: 16: 17: Fitting for long and ganged pixels
242 18: 19: quality and smearing (used for MC)\n\n"""
244 str +=
"Modules with empties:\n"
245 for key,values
in report.items():
246 str +=
"HashID: %4s\n" % (key)
255 if __name__ ==
"__main__":
257 UpdateCalib(
"PixelChargeCalibration-DATA-RUN2-UPD4-27")