3 from PixelCalibAlgs.EvoMonitoring
import ReadCSV
4 from matplotlib.backends.backend_agg
import FigureCanvasAgg
5 from matplotlib.figure
import Figure
14 return params[0]*(num/den)
19 os.makedirs(
"plots/parameters", exist_ok=
True)
23 expectedTOTint = {
"IBL": {
"normal":[],
"long":[]},
24 "Blayer": {
"normal":[],
"long":[],
"ganged":[]},
25 "L1" : {
"normal":[],
"long":[],
"ganged":[]},
26 "L2" : {
"normal":[],
"long":[],
"ganged":[]},
27 "Disk" : {
"normal":[],
"long":[],
"ganged":[]}}
28 CalibThreshold = {
"IBL": {
"normal":[],
"long":[]},
29 "Blayer": {
"normal":[],
"long":[],
"ganged":[]},
30 "L1" : {
"normal":[],
"long":[],
"ganged":[]},
31 "L2" : {
"normal":[],
"long":[],
"ganged":[]},
32 "Disk" : {
"normal":[],
"long":[],
"ganged":[]}}
33 CalibRMS = {
"IBL": {
"normal":[],
"long":[]},
34 "Blayer": {
"normal":[],
"long":[],
"ganged":[]},
35 "L1" : {
"normal":[],
"long":[],
"ganged":[]},
36 "L2" : {
"normal":[],
"long":[],
"ganged":[]},
37 "Disk" : {
"normal":[],
"long":[],
"ganged":[]}}
38 CalibNoise = {
"IBL": {
"normal":[],
"long":[]},
39 "Blayer": {
"normal":[],
"long":[],
"ganged":[]},
40 "L1" : {
"normal":[],
"long":[],
"ganged":[]},
41 "L2" : {
"normal":[],
"long":[],
"ganged":[]},
42 "Disk" : {
"normal":[],
"long":[],
"ganged":[]}}
43 CalibIntime = {
"IBL": {
"normal":[],
"long":[]},
44 "Blayer": {
"normal":[],
"long":[],
"ganged":[]},
45 "L1" : {
"normal":[],
"long":[],
"ganged":[]},
46 "L2" : {
"normal":[],
"long":[],
"ganged":[]},
47 "Disk" : {
"normal":[],
"long":[],
"ganged":[]}}
50 for mod, FEs
in calib.items():
51 mod_name = mapping[
str(mod)]
53 if mod_name.startswith(
"L0"):
55 elif mod_name.startswith(
"L1"):
57 elif mod_name.startswith(
"L2"):
59 elif mod_name.startswith(
"D"):
63 if mod_name.startswith(
"LI_S15"):
66 key =
"%-16s - %s" % (mod_name,mod)
70 for ife
in range(len(FEs)):
72 if mod_layer ==
"IBL":
77 report[key] += (
"\tFE%02u: "% ife) + str1
79 report[key] += (
"\tFE%02u: "% ife) + str2
81 CalibThreshold[mod_layer][
"normal"].
append(fe[0])
82 CalibThreshold[mod_layer][
"long"].
append(fe[2])
84 CalibRMS[mod_layer][
"normal"].
append(fe[1])
85 CalibRMS[mod_layer][
"long"].
append(fe[3])
92 report[key] += (
"\tFE%02u: "% ife) + str1
94 report[key] += (
"\tFE%02u: "% ife) + str2
96 report[key] += (
"\tFE%02u: "% ife) + str3
102 expectedTOTint[mod_layer][
"normal"].
append(totint_nor)
103 expectedTOTint[mod_layer][
"long"].
append(totint_lon)
104 expectedTOTint[mod_layer][
"ganged"].
append(totint_gan)
106 CalibThreshold[mod_layer][
"normal"].
append(fe[0])
107 CalibThreshold[mod_layer][
"long"].
append(fe[4])
108 CalibThreshold[mod_layer][
"ganged"].
append(fe[8])
110 CalibRMS[mod_layer][
"normal"].
append(fe[1])
111 CalibRMS[mod_layer][
"long"].
append(fe[5])
112 CalibRMS[mod_layer][
"ganged"].
append(fe[9])
114 CalibNoise[mod_layer][
"normal"].
append(fe[2])
115 CalibNoise[mod_layer][
"long"].
append(fe[6])
116 CalibNoise[mod_layer][
"ganged"].
append(fe[10])
118 CalibIntime[mod_layer][
"normal"].
append(fe[3])
119 CalibIntime[mod_layer][
"long"].
append(fe[7])
120 CalibIntime[mod_layer][
"ganged"].
append(fe[11])
123 fout =
open(
"CheckValues_log.txt",
"w")
125 fout.write(
"_______________ LOG _______________\n\n" )
126 fout.write(
"File chosen:\n" )
127 fout.write(
"Calibration : '%s'\n" % (_file) )
128 fout.write(
"Data base IOV: %s\n\n" % (iov) )
130 fout.write(
"\n Threshold FE values validation:\n")
131 fout.write(
"-"*40+
"\n")
132 for key, val
in report.items():
139 fout.write(
"\n\n\n\n Threshold MEAN values validation:\n")
140 fout.write(
"-"*40+
"\n")
141 for i
in [
"IBL",
"Blayer",
"L1",
"L2",
"Disk"]:
143 for j
in CalibThreshold[i]:
144 if len(CalibThreshold[i][j]) == 0:
146 _bool_, _str_ =
ValThreshold(i,j,np.average(CalibThreshold[i][j]))
147 fout.write(
"\t"+_str_)
150 figurIBL(i,CalibThreshold,
"Threshold",
"CalibThreshold_"+i+
".png")
151 figurIBL(i,CalibRMS ,
"RMS" ,
"CalibRMS_"+i+
".png")
153 figur(i,expectedTOTint,
"ToT for intime threshold",
"totIntime_"+i+
".png")
154 figur(i,CalibThreshold,
"Threshold",
"CalibThreshold_"+i+
".png")
155 figur(i,CalibRMS ,
"RMS" ,
"CalibRMS_"+i+
".png")
156 figur(i,CalibNoise ,
"Noise" ,
"CalibNoise_"+i+
".png")
157 figur(i,CalibIntime ,
"Intime" ,
"CalibIntime_"+i+
".png")
159 fout.write(
"-"*40+
"\n\n")
163 fe_indiv = {
"IBL":0,
"Blayer":0,
"L1":0,
"L2":0,
"Disk":0}
164 params_indiv = {
"IBL":0,
"Blayer":0,
"L1":0,
"L2":0,
"Disk":0}
165 for key, FEs
in calib.items():
167 mod_name = mapping[
str(key)]
169 if mod_name.startswith(
"L0"):
171 elif mod_name.startswith(
"L1"):
173 elif mod_name.startswith(
"L2"):
175 elif mod_name.startswith(
"D"):
181 fe_indiv[mod_layer] += len(FEs)
183 totalParams += len(fe)
184 params_indiv[mod_layer] += len(fe)
187 fout.write(
"Modules checked : %6u\n" % (len(calib)))
188 fout.write(
"FrontEnds checked : %6u\n" % (totalFE))
189 for key, value
in fe_indiv.items():
190 fout.write(
" - %-6s:%6u \n" % (key,value))
191 fout.write(
"Parameters checked: %6u\n" % (totalParams))
192 for key, value
in params_indiv.items():
193 fout.write(
" - %-6s:%6u \n" % (key,value))
199 fin =
open(
"CheckValues_log.txt",
"r")
207 realThresholds = {
"IBL": 1500,
"Blayer": 4700 ,
"L1": 4300,
"L2": 4300,
"Disk": 4300}
209 dev = abs((realThresholds[layer]-listavg)/listavg*100)
213 status =
"NEEDS CHECKING!!!"
214 if perc != 1
and status ==
"OK":
217 _str_ =
"%-25s: %6.1fe (exp.: %4ue), dev.: %6.2f%% - status (>%i%%): %s\n" % (layer+
" avg. thr. ["+pix+
"]", listavg, realThresholds[layer], dev, perc, status)
221 fig = Figure(figsize=(13,10))
223 plot(fig.add_subplot(2,2,1),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal")
224 plot(fig.add_subplot(2,2,2),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - normal")
225 plot(fig.add_subplot(2,2,3),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal",
True)
226 plot(fig.add_subplot(2,2,4),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - normal",
True)
227 FigureCanvasAgg(fig).print_figure(
"plots/parameters/"+namef, dpi=150)
230 fig = Figure(figsize=(13,10))
232 plot(fig.add_subplot(2,3,1),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal")
233 plot(fig.add_subplot(2,3,2),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - long")
234 plot(fig.add_subplot(2,3,3),hist[title][
"ganged"]
if len(hist[title][
"ganged"])
else [-1], xlabel+
" - ganged")
235 plot(fig.add_subplot(2,3,4),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal" ,
True)
236 plot(fig.add_subplot(2,3,5),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - long" ,
True)
237 plot(fig.add_subplot(2,3,6),hist[title][
"ganged"]
if len(hist[title][
"ganged"])
else [-1], xlabel+
" - ganged" ,
True)
238 FigureCanvasAgg(fig).print_figure(
"plots/parameters/"+namef, dpi=150)
240 def plot(axs,arr, xlabel, islog = False):
241 axs.hist(arr, bins=60)
242 axs.set_xlabel(xlabel)
244 axs.set_yscale(
"log")
245 axs.set_ylabel(
"Counts [log scale]" if islog
else "Counts")
249 from PixelCalibAlgs.EvoMonitoring
import ReadCalibOutput
255 if __name__ ==
"__main__":
258 parser = argparse.ArgumentParser(prog=
'python -m PixelCalibAlgs.CheckValues',
259 description=
"""Checks the Threshold values.\n\n
260 Example: python -m PixelCalibAlgs.CheckValues -f "path/to/file" """)
262 parser.add_argument(
'-f' , required=
True, help=
"New calibration file (output format from the Recovery.py)")
263 parser.add_argument(
'--isDB' , action=
'store_true', help=
"File with a DB format (from MakeReferenceFile)")
264 args = parser.parse_args()
269 from PixelCalibAlgs.Recovery
import ReadDbFile
273 from PixelCalibAlgs.EvoMonitoring
import ReadCalibOutput