ATLAS Offline Software
Functions | Variables
EvoMonitoring Namespace Reference

Functions

def arrayCharge (parameters, layer)
 
def charge (parameters, tot)
 
def percent (a, b)
 
def failsCheckTuning (parameters, layer)
 
def EvoMon (old_calib, new_calib, mapping, old_iov, new_iov)
 
def ReadCSV ()
 
def ReadCalibOutput (file)
 
def setupRunEvo (path_newCalib, path_oldCalib)
 

Variables

 parser
 
 default
 
 help
 
 args = parser.parse_args()
 

Function Documentation

◆ arrayCharge()

def EvoMonitoring.arrayCharge (   parameters,
  layer 
)

Definition at line 17 of file EvoMonitoring.py.

17 def arrayCharge(parameters, layer):
18 
19  if layer == "Blayer":
20  # Range [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42] (includes the ToT tuning point: 18)
21  m_array = [charge(parameters, 3*(1+i)) for i in range(14)]
22  else:
23  # Range [5, 10, 15, 20, 25, 30, 35, 40] (includes the ToT tuning point: 30)
24  m_array = [charge(parameters, 5*(1+i)) for i in range(8)]
25 
26  return ar.array('d',m_array)
27 

◆ charge()

def EvoMonitoring.charge (   parameters,
  tot 
)

Definition at line 28 of file EvoMonitoring.py.

28 def charge(parameters, tot):
29  num = tot*parameters[2] - parameters[0]*parameters[1]
30  den = parameters[0] - tot
31  return (num/den) if den != 0 else 0
32 

◆ EvoMon()

def EvoMonitoring.EvoMon (   old_calib,
  new_calib,
  mapping,
  old_iov,
  new_iov 
)

Definition at line 61 of file EvoMonitoring.py.

61 def EvoMon(old_calib, new_calib, mapping, old_iov, new_iov):
62 
63  save = 1
64  log_info = {}
65 
66  slopes = []
67  information = {"Total_mods": 0,
68  "Total_FE" : 0,
69  "IBL" :{"bad":0, "ok":0},
70  "Blayer":{"bad":0, "ok":0},
71  "L1" :{"bad":0, "ok":0},
72  "L2" :{"bad":0, "ok":0},
73  "Disk" :{"bad":0, "ok":0}
74  }
75 
76  # There are 2048 modules in the structure
77  for mod in range(2048):
78 
79  mod_str = mapping[str(mod)]
80  mod_layer = ""
81  print( "%-18s - %4i" % (mod_str, mod), end='\r')
82  plot_range = np.array([0,75000])
83  # Skipping modules that have not been calibrated
84  if str(mod) not in new_calib:
85  continue
86 
87  if mod_str.startswith("L0"):
88  mod_layer = "Blayer"
89  elif mod_str.startswith("L1"):
90  mod_layer = "L1"
91  elif mod_str.startswith("L2"):
92  mod_layer = "L2"
93  elif mod_str.startswith("D"):
94  mod_layer = "Disk"
95  else:
96  mod_layer = "IBL"
97  if mod_str.startswith("LI_S15"):
98  continue
99 
100  information["Total_mods"] += 1
101  fig = Figure(figsize=(13,10))
102  axs = fig.add_subplot(1,1,1)
103  status = "_OK"
104 
105  for fe in range(len(new_calib[str(mod)])):
106 
107  information["Total_FE"] += 1
108  newQ = []
109  oldQ = []
110  boolTOT = False
111  realQ = []
112 
113  if mod_layer != "IBL":
114  newCal_normal_pix = new_calib[str(mod)][fe][12:15]
115  oldCal_normal_pix = old_calib[str(mod)][fe][12:15]
116  boolTOT, realQ = failsCheckTuning(newCal_normal_pix, mod_layer)
117 
118  # We just fit the first point since we loose linearity afterwards
119  newQ = arrayCharge(newCal_normal_pix,mod_layer)
120  oldQ = arrayCharge(oldCal_normal_pix,mod_layer)
121  else:
122  # For IBL we dont need to convert TOT into charge, DB already in charge
123  newQ = new_calib[str(mod)][fe][4:20]
124  oldQ = old_calib[str(mod)][fe][4:20]
125 
126  plot_range = np.array([0,35000])
127  boolTOT, realQ = failsCheckTuning(newQ, mod_layer)
128 
129  m,b = np.polyfit(newQ ,oldQ,1)
130  slopes.append(m)
131  boolFit = (abs((1-m)/m)*100) > 5
132 
133  if boolFit or boolTOT:
134  key = "%-18s - %i" % (mod_str, mod)
135  if boolFit:
136  if key not in log_info:
137  log_info[key] = "\tFE%02i ---> slope: %5.2f - dev: %5.1f%%\n" % (fe,m, abs((1-m)/m)*100)
138  else:
139  log_info[key] += "\tFE%02i ---> slope: %5.2f - dev: %5.1f%%\n" % (fe,m, abs((1-m)/m)*100)
140  if boolTOT:
141  if key not in log_info:
142  log_info[key] = "\tFE%02i ---> Charge= %5ie (dev %6.2f%%) out of error bars. Expected: %5ie\n" % (fe, realQ[0], realQ[1], realQ[2])
143  else:
144  log_info[key] += "\tFE%02i ---> Charge= %5ie (dev %6.2f%%) out of error bars. Expected: %5ie\n" % (fe, realQ[0], realQ[1], realQ[2])
145 
146  information[mod_layer]["bad"] += 1
147  status = "_BAD"
148  if boolTOT:
149  # Fails charge tuning
150  status += "_Q"
151  if boolFit:
152  # Fails the slope at y = x (old vs. new calib)
153  status += "_Slope"
154  else:
155  information[mod_layer]["ok"] += 1
156 
157 
158  if save:
159  lstyle = "dotted" if fe < 8 else "solid"
160  axs.plot(newQ ,oldQ, marker='o', linestyle=lstyle, label = ("FE%02d" % (fe)))
161  axs.set_xlim(plot_range)
162  axs.set_ylim(plot_range)
163 
164  if save:
165  fig.suptitle("Hash ID %d - %s" % (mod, mod_str))
166  axs.legend(loc='upper left', ncol=4)
167  axs.set_xlabel(new_iov+" - Charge[e]")
168  axs.set_ylabel(old_iov+" - Charge[e]")
169  axs.plot(plot_range,plot_range,"k:",lw=1)
170 
171  if mod_layer == 'IBL':
172  axs.plot([16000,16000],plot_range,"k:",lw=1)
173  axs.text(17000,1000,"TOT@10 = 16 ke")
174  elif mod_layer == 'Blayer':
175  axs.plot([20000,20000],plot_range,"k:",lw=1)
176  axs.text(21000,1000,"TOT@18 = 20 ke")
177  else:
178  axs.plot([20000,20000],plot_range,"k:",lw=1)
179  axs.text(21000,1000,"TOT@30 = 20 ke")
180 
181  storage = "plots/" + mod_layer + "/"
182 
183  canvas = FigureCanvasAgg(fig)
184  canvas.print_figure(storage+"Id"+str(mod)+ "_" +mod_str+status+".png", dpi=150)
185 
186  if(save):
187  fig = Figure(figsize=(13,10))
188  fig.suptitle("Fit slopes for all modules")
189  axs = fig.add_subplot(1,1,1)
190  axs.hist(np.clip(slopes, -1, 2), bins=100)
191  axs.set_xlabel("Fit slope")
192  axs.set_ylabel("Counts")
193  # add text box for the statistics
194  stats = (f'$\\mu$ = {np.mean(np.clip(slopes, -1, 2)):.3f}\n'
195  f'$\\sigma$ = {np.std(np.clip(slopes, -1, 2)):.3f}')
196  bbox = dict(boxstyle='round', fc='blanchedalmond', ec='orange', alpha=0.5)
197  axs.text(0.95, 0.07, stats, fontsize=9, bbox=bbox, transform=axs.transAxes)
198 
199  FigureCanvasAgg(fig).print_figure("plots/FitSlopes.png", dpi=150)
200 
201  return information, log_info
202 
203 

◆ failsCheckTuning()

def EvoMonitoring.failsCheckTuning (   parameters,
  layer 
)

Definition at line 37 of file EvoMonitoring.py.

37 def failsCheckTuning(parameters, layer):
38  tot = 30
39  error = 5 # percentage
40  expected_charge = 20000 # electrons
41 
42  if layer == "Blayer":
43  tot = 18
44 
45  if layer == "IBL":
46  tot = 10
47  expected_charge = 16000 # electrons
48 
49  if abs(parameters[9]-expected_charge)/expected_charge*100 > 5:
50  return True, [parameters[9], abs(parameters[9]-expected_charge)/expected_charge*100, expected_charge]
51  return False, [0,0,0]
52 
53  low = expected_charge*(1-error/100)
54  high = expected_charge*(1+error/100)
55  realQ = charge(parameters, tot)
56 
57  if realQ < low or realQ > high:
58  return True, [charge(parameters, tot), abs(charge(parameters, tot)-expected_charge)/expected_charge*100,expected_charge]
59  return False, [0,0,0]
60 

◆ percent()

def EvoMonitoring.percent (   a,
  b 
)

Definition at line 33 of file EvoMonitoring.py.

33 def percent( a,b):
34  return a/(a+b)*100 if (a+b) != 0 else 999.99
35 
36 

◆ ReadCalibOutput()

def EvoMonitoring.ReadCalibOutput (   file)

Definition at line 213 of file EvoMonitoring.py.

213 def ReadCalibOutput(file):
214  mydict = {}
215  with open(file) as fp:
216  lines = fp.readlines()
217  for line in lines:
218  arrayline = line.rstrip("\n").split(' ')
219 
220  if arrayline[0] not in mydict:
221  mydict[arrayline[0]] = []
222 
223  # Removing empty values. This is usually used for IBL calib file
224  while("" in arrayline):
225  arrayline.remove("")
226 
227  mydict[arrayline[0]].append([ int(arrayline[i]) if i<13 else float(arrayline[i]) for i in range(1,len(arrayline)) ])
228 
229  return mydict, "[latest,0]"
230 

◆ ReadCSV()

def EvoMonitoring.ReadCSV ( )

Definition at line 204 of file EvoMonitoring.py.

204 def ReadCSV():
205  mydict = {}
206  with open(PathResolver.FindCalibFile("PixelCalibAlgs/mapping.csv")) as fp:
207  lines = fp.readlines()
208  for line in lines:
209  arrayline = line.rstrip("\n").split(', ')
210  mydict[arrayline[1]] = arrayline[0]
211  return mydict
212 

◆ setupRunEvo()

def EvoMonitoring.setupRunEvo (   path_newCalib,
  path_oldCalib 
)

Definition at line 231 of file EvoMonitoring.py.

231 def setupRunEvo(path_newCalib, path_oldCalib):
232  new_iov = "Latest IOV"
233  old_iov = "Older IOV"
234 
235  print("Files chosen for the comparison:")
236 
237  print("New calibration: '%s'" % path_newCalib)
238  new_calib, new_iov = "", ""
239  if "PIX_FINAL_calibration_candidate.txt" in path_newCalib:
240  new_calib, new_iov = ReadCalibOutput(path_newCalib)
241  elif "ChargeCalib_" in path_newCalib:
242  new_calib, new_iov = ReadCalibOutput(path_newCalib)
243  else:
244  new_calib, read_report = ReadNewCalib(path_newCalib)
245 
246  print("Old calibration: '%s'" % path_oldCalib)
247  old_calib, old_iov = ReadDbFile(path_oldCalib)
248 
249  mapping = ReadCSV()
250 
251  import os
252  os.makedirs("plots/Blayer", exist_ok=True)
253  os.makedirs("plots/L1" , exist_ok=True)
254  os.makedirs("plots/L2" , exist_ok=True)
255  os.makedirs("plots/Disk" , exist_ok=True)
256  os.makedirs("plots/IBL" , exist_ok=True)
257 
258  information, log_info = EvoMon(old_calib, new_calib, mapping, old_iov, new_iov )
259 
260  # writing log files
261  fout = open("EvoMonitoring_log.txt", "w")
262 
263  fout.write("_______________ LOG _______________\n\n" )
264  fout.write("Files chosen for the comparison:\n" )
265  fout.write("New calibration: '%s'\n" % (path_newCalib) )
266  fout.write("Old calibration: '%s'\n" % (path_oldCalib) )
267  fout.write("Data base IOV: %s\n\n" % (old_iov) )
268 
269  fout.write("-"*20+" SUMMARY "+"-"*20+"\n" )
270  fout.write("%-20s: %5i\n" % ("Total mods in det.", information["Total_mods"]))
271  fout.write("%-20s: %5i\n" % ("Total FE in det." , information["Total_FE"] ))
272  fout.write("%-20s: %5i\n" % ("Total FE IBL" , information["IBL"]["ok"] +information["IBL"]["bad"] ))
273  fout.write("%-20s: %5i\n" % ("Total FE Blayer" , information["Blayer"]["ok"]+information["Blayer"]["bad"]))
274  fout.write("%-20s: %5i\n" % ("Total FE L1" , information["L1"]["ok"] +information["L1"]["bad"] ))
275  fout.write("%-20s: %5i\n" % ("Total FE L2" , information["L2"]["ok"] +information["L2"]["bad"] ))
276  fout.write("%-20s: %5i\n\n" % ("Total FE Disk" , information["Disk"]["ok"] +information["Disk"]["bad"] ))
277 
278  fout.write('FrontEnds deviating more than 5% of TOT vs charge gradient between new and previous calibration:\n')
279  fout.write("%-11s: %-4i (%6.2f%%)\n" % ("IBL FEs" , information["IBL"]["bad"] , percent(information["IBL"]["bad"] ,information["IBL"]["ok"]) ))
280  fout.write("%-11s: %-4i (%6.2f%%)\n" % ("Blayer FEs", information["Blayer"]["bad"], percent(information["Blayer"]["bad"],information["Blayer"]["ok"])))
281  fout.write("%-11s: %-4i (%6.2f%%)\n" % ("L1 FEs" , information["L1"]["bad"] , percent(information["L1"]["bad"] ,information["L1"]["ok"]) ))
282  fout.write("%-11s: %-4i (%6.2f%%)\n" % ("L2 FEs" , information["L2"]["bad"] , percent(information["L2"]["bad"] ,information["L2"]["ok"]) ))
283  fout.write("%-11s: %-4i (%6.2f%%)\n\n" % ("Disk FEs" , information["Disk"]["bad"] , percent(information["Disk"]["bad"] ,information["Disk"]["ok"]) ))
284 
285  fout.write("+"*20+" List of bad FE "+"+"*20+"\n" )
286  fout.write("Expected TOT vs. charge for the different layers:\n")
287  fout.write("%-10s: TOT@%2i = %2ike\n" % ("IBL" , 10, 16))
288  fout.write("%-10s: TOT@%2i = %2ike\n" % ("Blayer" , 18, 20))
289  fout.write("%-10s: TOT@%2i = %2ike\n\n" % ("L1/L2/Disk", 30, 20))
290 
291  for key, val in log_info.items():
292  fout.write(key+"\n")
293  fout.write(val+"\n")
294 
295  fout.close()
296 
297  #open and read the file for terminal print:
298  fin = open("EvoMonitoring_log.txt", "r")
299  print(fin.read())
300 
301 

Variable Documentation

◆ args

EvoMonitoring.args = parser.parse_args()

Definition at line 312 of file EvoMonitoring.py.

◆ default

EvoMonitoring.default

Definition at line 309 of file EvoMonitoring.py.

◆ help

EvoMonitoring.help

Definition at line 309 of file EvoMonitoring.py.

◆ parser

EvoMonitoring.parser
Initial value:
1 = argparse.ArgumentParser(prog='python -m PixelCalibAlgs.EvoMonitoring',
2  description=)

Definition at line 305 of file EvoMonitoring.py.

EvoMonitoring.arrayCharge
def arrayCharge(parameters, layer)
Definition: EvoMonitoring.py:17
PathResolver::FindCalibFile
static std::string FindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.h:108
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
EvoMonitoring.percent
def percent(a, b)
Definition: EvoMonitoring.py:33
EvoMonitoring.EvoMon
def EvoMon(old_calib, new_calib, mapping, old_iov, new_iov)
Definition: EvoMonitoring.py:61
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
while
while((inf=(TStreamerInfo *) nextinfo()) !=0)
Definition: liststreamerinfos.cxx:13
EvoMonitoring.failsCheckTuning
def failsCheckTuning(parameters, layer)
Definition: EvoMonitoring.py:37
EvoMonitoring.setupRunEvo
def setupRunEvo(path_newCalib, path_oldCalib)
Definition: EvoMonitoring.py:231
Recovery.ReadNewCalib
def ReadNewCalib(name)
Definition: Recovery.py:26
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Recovery.ReadDbFile
def ReadDbFile(name)
Definition: Recovery.py:7
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
charge
double charge(const T &p)
Definition: AtlasPID.h:756
EvoMonitoring.ReadCalibOutput
def ReadCalibOutput(file)
Definition: EvoMonitoring.py:213
Trk::open
@ open
Definition: BinningType.h:40
EvoMonitoring.ReadCSV
def ReadCSV()
Definition: EvoMonitoring.py:204
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38