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] += (
"FE%02u: "% ife) + str1
79 report[key] += (
"FE%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] += (
"FE%02u: "% ife) + str1
94 report[key] += (
"FE%02u: "% ife) + str2
96 report[key] += (
"FE%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])
122 print(
"\n Threshold FE values validation:")
124 for key, val
in report.items():
131 print(
"\n\n\n\n Threshold MEAN values validation:")
133 for i
in [
"IBL",
"Blayer",
"L1",
"L2",
"Disk"]:
136 for j
in CalibThreshold[i]:
137 if len(CalibThreshold[i][j]) == 0:
139 _bool_, _str_ =
ValThreshold(i,j,np.average(CalibThreshold[i][j]))
143 figurIBL(i,CalibThreshold,
"Threshold",
"CalibThreshold_"+i+
".png")
144 figurIBL(i,CalibRMS ,
"RMS" ,
"CalibRMS_"+i+
".png")
146 figur(i,expectedTOTint,
"ToT for intime threshold",
"totIntime_"+i+
".png")
147 figur(i,CalibThreshold,
"Threshold",
"CalibThreshold_"+i+
".png")
148 figur(i,CalibRMS ,
"RMS" ,
"CalibRMS_"+i+
".png")
149 figur(i,CalibNoise ,
"Noise" ,
"CalibNoise_"+i+
".png")
150 figur(i,CalibIntime ,
"Intime" ,
"CalibIntime_"+i+
".png")
158 realThresholds = {
"IBL": 1500,
"Blayer": 4700 ,
"L1": 4300,
"L2": 4300,
"Disk": 4300}
160 dev = abs((realThresholds[layer]-listavg)/listavg*100)
164 status =
"NEEDS CHECKING!!!"
165 if perc != 1
and status ==
"OK":
168 _str_ =
"\t%-25s: %6.1fe (exp.: %4ue), dev.: %6.2f%% - status (>%i%%): %s\n" % (layer+
" avg. thr. ["+pix+
"]", listavg, realThresholds[layer], dev, perc, status)
172 fig = Figure(figsize=(13,10))
174 plot(fig.add_subplot(2,2,1),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal")
175 plot(fig.add_subplot(2,2,2),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - normal")
176 plot(fig.add_subplot(2,2,3),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal",
True)
177 plot(fig.add_subplot(2,2,4),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - normal",
True)
178 FigureCanvasAgg(fig).print_figure(
"plots/parameters/"+namef, dpi=150)
181 fig = Figure(figsize=(13,10))
183 plot(fig.add_subplot(2,3,1),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal")
184 plot(fig.add_subplot(2,3,2),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - long")
185 plot(fig.add_subplot(2,3,3),hist[title][
"ganged"]
if len(hist[title][
"ganged"])
else [-1], xlabel+
" - ganged")
186 plot(fig.add_subplot(2,3,4),hist[title][
"normal"]
if len(hist[title][
"normal"])
else [-1], xlabel+
" - normal" ,
True)
187 plot(fig.add_subplot(2,3,5),hist[title][
"long"]
if len(hist[title][
"long"])
else [-1], xlabel+
" - long" ,
True)
188 plot(fig.add_subplot(2,3,6),hist[title][
"ganged"]
if len(hist[title][
"ganged"])
else [-1], xlabel+
" - ganged" ,
True)
189 FigureCanvasAgg(fig).print_figure(
"plots/parameters/"+namef, dpi=150)
191 def plot(axs,arr, xlabel, islog = False):
192 axs.hist(arr, bins=60)
193 axs.set_xlabel(xlabel)
195 axs.set_yscale(
"log")
196 axs.set_ylabel(
"Counts [log scale]" if islog
else "Counts")
199 if __name__ ==
"__main__":
202 parser = argparse.ArgumentParser(prog=
'python -m PixelCalibAlgs.CheckValues',
203 description=
"""Checks the Threshold values.\n\n
204 Example: python -m PixelCalibAlgs.CheckValues -f "path/to/file" """)
206 parser.add_argument(
'-f' , required=
True, help=
"New calibration file (output format from the Recovery.py)")
207 parser.add_argument(
'--isDB' , action=
'store_true', help=
"File with a DB format (from MakeReferenceFile)")
208 args = parser.parse_args()
213 from PixelCalibAlgs.Recovery
import ReadDbFile
217 from PixelCalibAlgs.EvoMonitoring
import ReadCalibOutput