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

int MaxThreshold = 10
 
int MaxSlope = 10
 
 parser
 
 default
 
 help
 
 args = parser.parse_args()
 

Function Documentation

◆ arrayCharge()

def EvoMonitoring.arrayCharge (   parameters,
  layer 
)

Definition at line 19 of file EvoMonitoring.py.

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

◆ charge()

def EvoMonitoring.charge (   parameters,
  tot 
)

Definition at line 30 of file EvoMonitoring.py.

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

◆ EvoMon()

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

Definition at line 63 of file EvoMonitoring.py.

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

◆ failsCheckTuning()

def EvoMonitoring.failsCheckTuning (   parameters,
  layer 
)

Definition at line 39 of file EvoMonitoring.py.

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

◆ percent()

def EvoMonitoring.percent (   a,
  b 
)

Definition at line 35 of file EvoMonitoring.py.

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

◆ ReadCalibOutput()

def EvoMonitoring.ReadCalibOutput (   file)

Definition at line 215 of file EvoMonitoring.py.

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

◆ ReadCSV()

def EvoMonitoring.ReadCSV ( )

Definition at line 206 of file EvoMonitoring.py.

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

◆ setupRunEvo()

def EvoMonitoring.setupRunEvo (   path_newCalib,
  path_oldCalib 
)

Definition at line 233 of file EvoMonitoring.py.

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

Variable Documentation

◆ args

EvoMonitoring.args = parser.parse_args()

Definition at line 314 of file EvoMonitoring.py.

◆ default

EvoMonitoring.default

Definition at line 311 of file EvoMonitoring.py.

◆ help

EvoMonitoring.help

Definition at line 311 of file EvoMonitoring.py.

◆ MaxSlope

int EvoMonitoring.MaxSlope = 10

Definition at line 17 of file EvoMonitoring.py.

◆ MaxThreshold

int EvoMonitoring.MaxThreshold = 10

Definition at line 16 of file EvoMonitoring.py.

◆ parser

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

Definition at line 307 of file EvoMonitoring.py.

EvoMonitoring.arrayCharge
def arrayCharge(parameters, layer)
Definition: EvoMonitoring.py:19
PathResolver::FindCalibFile
static std::string FindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.h:63
EvoMonitoring.percent
def percent(a, b)
Definition: EvoMonitoring.py:35
EvoMonitoring.EvoMon
def EvoMon(old_calib, new_calib, mapping, old_iov, new_iov)
Definition: EvoMonitoring.py:63
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:39
EvoMonitoring.setupRunEvo
def setupRunEvo(path_newCalib, path_oldCalib)
Definition: EvoMonitoring.py:233
Recovery.ReadNewCalib
def ReadNewCalib(name)
Definition: Recovery.py:26
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
Recovery.ReadDbFile
def ReadDbFile(name)
Definition: Recovery.py:7
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
charge
double charge(const T &p)
Definition: AtlasPID.h:991
EvoMonitoring.ReadCalibOutput
def ReadCalibOutput(file)
Definition: EvoMonitoring.py:215
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
EvoMonitoring.ReadCSV
def ReadCSV()
Definition: EvoMonitoring.py:206
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
str
Definition: BTagTrackIpAccessor.cxx:11
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65