Belle II Software development
PXDDeadPixelsChecker Class Reference
Inheritance diagram for PXDDeadPixelsChecker:
ConditionCheckerBase

Public Member Functions

 __init__ (self, name, tfile, rundir="maps", use_hist=True)
 
 define_graphs (self)
 
 define_hists (self)
 
 get_db_content (self)
 
 get_graph_value (self, sensor_db_content)
 
 get_graph_value_from_hist (self, h2)
 
 set_hist_content (self, h2, sensor_db_content)
 
 draw_plots (self, canvas=None, cname="PXDDeadPixel", ymin=0., ymax=plot_type_dict["dead"]["max"], **kwargs)
 
 objType (self)
 
 run (self)
 
 exp (self)
 
 beginRun (self)
 
 fill_plots (self)
 
 save_canvas (self, canvas, cname, logy=False)
 

Public Attributes

 name = name
 DBObj name.
 
 dbObj = Belle2.PyDBObj(self.name, self.objType.Class())
 DBObjPtr for the condition.
 
 eventMetaData = Belle2.PyStoreObj("EventMetaData")
 pointer to the event metadata
 
 tfile = tfile
 TFile for saving plots.
 
 rundir = rundir
 Directory for writing histograms of each run.
 
dict graphs = {}
 Dictionary of plots (TGraph) summarizing variables vs run.
 
dict hists = {}
 Dictionary of plots (TH1) to be saved for each run.
 
str hist_title_suffix = ""
 Hist title suffix.
 
int runstart = 999999
 The 1st run.
 
int runend = -1
 The last run.
 
int expstart = 999999
 The 1st exp.
 
 use_hist = use_hist
 Flag to get TGraph values from a histogram (TH2F)
 

Protected Attributes

 _objType = objType
 DBObj type.
 

Detailed Description

Checker for PXDDeadPixelPar

Definition at line 360 of file condition_checker.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
name,
tfile,
rundir = "maps",
use_hist = True )
 

Definition at line 365 of file condition_checker.py.

365 def __init__(self, name, tfile, rundir="maps", use_hist=True):
366 """
367 """
368 super().__init__(name, Belle2.PXDDeadPixelPar, tfile, rundir)
369
The payload telling which PXD pixel is dead (=Readout system does not receive signals)

Member Function Documentation

◆ beginRun()

beginRun ( self)
inherited
Call functions at beginning of a run

Definition at line 109 of file condition_checker.py.

109 def beginRun(self):
110 """
111 Call functions at beginning of a run
112 """
113 self.define_hists()
114 self.fill_plots()
115

◆ define_graphs()

define_graphs ( self)
Method to define TGraph

Reimplemented from ConditionCheckerBase.

Definition at line 370 of file condition_checker.py.

370 def define_graphs(self):
371 """
372 Method to define TGraph
373 """
374 super().define_graphs(ytitle="Dead pixels [%]")
375

◆ define_hists()

define_hists ( self)
Method to define TH2

Reimplemented from ConditionCheckerBase.

Definition at line 376 of file condition_checker.py.

376 def define_hists(self):
377 """
378 Method to define TH2
379 """
380 super().define_hists(name="DeadPixels", title="Dead Pixels", ztitle="isDead")
381

◆ draw_plots()

draw_plots ( self,
canvas = None,
cname = "PXDDeadPixel",
ymin = 0.,
ymax = plot_type_dict["dead"]["max"],
** kwargs )
Method to draw plots on a TCanvas

Reimplemented from ConditionCheckerBase.

Definition at line 450 of file condition_checker.py.

450 def draw_plots(self, canvas=None, cname="PXDDeadPixel", ymin=0., ymax=plot_type_dict["dead"]["max"], **kwargs):
451 """
452 Method to draw plots on a TCanvas
453 """
454 super().draw_plots(canvas=canvas, cname=cname, ymin=ymin, ymax=ymax, **kwargs)
455
456

◆ exp()

exp ( self)
inherited
Experiment number

Definition at line 103 of file condition_checker.py.

103 def exp(self):
104 """
105 Experiment number
106 """
107 return self.eventMetaData.getExperiment()
108

◆ fill_plots()

fill_plots ( self)
inherited
Method to fill plot objects

Definition at line 172 of file condition_checker.py.

172 def fill_plots(self):
173 """
174 Method to fill plot objects
175 """
176 if self.exp < self.expstart:
177 self.expstart = self.exp
178 if self.run < self.runstart:
179 self.runstart = self.run
180 if self.run > self.runend:
181 self.runend = self.run
182
183 db_content = self.get_db_content()
184 values_dict = {}
185 pre_values_dict = {}
186 for sensorID in sensorID_list:
187 sensor_db_content = db_content[sensorID.getID()]
188 if self.graphs:
189 if not self.use_hist:
190 values_dict[sensorID.getID()] = self.get_graph_value(sensor_db_content)
191 gr = self.graphs[sensorID.getID()]
192 pre_values_dict[sensorID.getID()] = gr.GetPointY(gr.GetN() - 1)
193 # Saving graph points only for different values (sensor-wise)
194 # value = self.get_graph_value(sensor_db_content)
195 # pre_value = gr.GetPointY(gr.GetN()-1)
196 # if value != pre_value:
197 # gr.SetPoint(gr.GetN(), self.run, value)
198 # Saving masked map
199 if self.rundir != "" and self.hists:
200 h2 = self.hists[sensorID.getID()]
201 self.set_hist_content(h2, sensor_db_content)
202 # Update title with total count
203 h2.SetTitle(h2.GetTitle() + self.hist_title_suffix)
204 self.tfile.cd(self.rundir)
205 h2.Write()
206 if self.use_hist:
207 values_dict[sensorID.getID()] = self.get_graph_value_from_hist(h2)
208 # Saving graph points only for different conditions
209 if values_dict != pre_values_dict:
210 for sensorID in sensorID_list:
211 gr = self.graphs[sensorID.getID()]
212 # \cond false positive doxygen warning
213 gr.SetPoint(gr.GetN(), self.run, values_dict[sensorID.getID()])
214 # \endcond
215

◆ get_db_content()

get_db_content ( self)
Abstract method to get content of a payload
Should return a Dictionary with sensorID.getID() as key and relaated calibration results as value

Reimplemented from ConditionCheckerBase.

Definition at line 382 of file condition_checker.py.

382 def get_db_content(self):
383 deadsensormap = self.dbObj.getDeadSensorMap()
384 deaddrainmap = self.dbObj.getDeadDrainMap()
385 deadrowmap = self.dbObj.getDeadRowMap()
386 deadsinglesmap = self.dbObj.getDeadSinglePixelMap()
387
388 content_dic = {}
389 for sensorID in sensorID_list:
390 numID = sensorID.getID()
391 content_dic[numID] = {}
392 if numID in deadsensormap:
393 content_dic[numID]["deadsensor"] = True
394 else:
395 content_dic[numID]["deadsensor"] = False
396 content_dic[numID]["deaddrains"] = deaddrainmap[numID]
397 content_dic[numID]["deadrows"] = deadrowmap[numID]
398 content_dic[numID]["deadsingles"] = deadsinglesmap[numID]
399 return content_dic
400

◆ get_graph_value()

get_graph_value ( self,
sensor_db_content )
Abstract method to get a value for each TGraph
Parameters:
  sensor_db_content (Any): Calibration results of a module

Reimplemented from ConditionCheckerBase.

Definition at line 401 of file condition_checker.py.

401 def get_graph_value(self, sensor_db_content):
402 deadcount = 0
403 if sensor_db_content["deadsensor"]:
404 deadcount = nPixels
405 else:
406 n_deaddrains = len(sensor_db_content["deaddrains"])
407 n_deadrows = len(sensor_db_content["deadrows"])
408 if n_deaddrains == 0 or n_deadrows == 0:
409 # Every dead drain counts for 192 dead pixels
410 deadcount = n_deaddrains * 192
411 # Every dead row counts for 250 dead pixels
412 # This can lead to double counting of dead pixel from dead drains
413 # The double counting can be avoided by using TH2.Integral().
414 deadcount += n_deadrows * 250
415 # Every dead single pixels
416 deadcount += len(sensor_db_content["deadsingles"])
417 else: # Using a histogram to avoid double counting
418 # Just create a temporary TH2
419 h2 = list(get_sensor_maps(sensorID_list=sensorID_list[0:1]).values())[0]
420 self.set_hist_content(h2, sensor_db_content)
421 deadcount = h2.Integral()
422
423 self.hist_title_suffix = f" ({deadcount} pixels)"
424 return min(deadcount, nPixels) * 100. / nPixels
425

◆ get_graph_value_from_hist()

get_graph_value_from_hist ( self,
h2 )
Method to get a value for each TGraph
Parameters:
  h2 (TH2): If not none, get value from h2

Reimplemented from ConditionCheckerBase.

Definition at line 426 of file condition_checker.py.

426 def get_graph_value_from_hist(self, h2):
427 return h2.Integral() * 100. / nPixels
428

◆ objType()

objType ( self)
inherited
DBObj type (read only)

Definition at line 89 of file condition_checker.py.

89 def objType(self):
90 """
91 DBObj type (read only)
92 """
93 return self._objType
94

◆ run()

run ( self)
inherited
Run number

Definition at line 96 of file condition_checker.py.

96 def run(self):
97 """
98 Run number
99 """
100 return self.eventMetaData.getRun()
101

◆ save_canvas()

save_canvas ( self,
canvas,
cname,
logy = False )
inherited
Save TCanvas to png/pdf format and do not write it to the ROOT file by default
Parameters:
  canvas (TCanvas): ROOT TCanvas for plotting
  canme (str): Name of the canvas
  logy (bool): Flag to use log scale for y-axis

Definition at line 250 of file condition_checker.py.

250 def save_canvas(self, canvas, cname, logy=False):
251 """
252 Save TCanvas to png/pdf format and do not write it to the ROOT file by default
253 Parameters:
254 canvas (TCanvas): ROOT TCanvas for plotting
255 canme (str): Name of the canvas
256 logy (bool): Flag to use log scale for y-axis
257 """
258 if cname:
259 canvas.SetName(cname)
260 exp_run = f"e{self.expstart:05}_r{self.runstart:04}-{self.runend:04}"
261 # Draw Belle II label
262 latex_r.DrawLatex(0.95, 0.92, "Belle II Experiment: " + exp_run.replace("_", " "))
263 # Print and write TCanvas
264 if logy:
265 canvas.SetLogy(1)
266 canvas.Update()
267 canvas.Modified()
268 canvas.Print(f"{exp_run}_{cname}_vs_run_logy.png")
269 canvas.Print(f"{exp_run}_{cname}_vs_run_logy.pdf")
270 else:
271 canvas.SetLogy(0)
272 canvas.Print(f"{exp_run}_{cname}_vs_run.png")
273 canvas.Print(f"{exp_run}_{cname}_vs_run.pdf")
274 self.tfile.cd()
275
276

◆ set_hist_content()

set_hist_content ( self,
h2,
sensor_db_content )
Method to set TH2 bins
Parameters:
  h2 (TH2): TH2F object for handling values of a pixel matrix
  sensor_db_content (Any): Calibration results of a module

Reimplemented from ConditionCheckerBase.

Definition at line 429 of file condition_checker.py.

429 def set_hist_content(self, h2, sensor_db_content):
430 # loop over all dead pixels
431 if sensor_db_content["deadsensor"]:
432 ones = np.ones(nPixels)
433 h2.SetContent(ones)
434 else:
435 for drainID in sensor_db_content["deaddrains"]:
436 for iGate in range(192):
437 uCell = drainID / 4
438 vCell = drainID % 4 + iGate * 4
439 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
440
441 for vCell in sensor_db_content["deadrows"]:
442 for uCell in range(nUCells):
443 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
444
445 for pixelID in sensor_db_content["deadsingles"]:
446 uCell = int(pixelID / nVCells)
447 vCell = pixelID % nVCells
448 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
449

Member Data Documentation

◆ _objType

_objType = objType
protectedinherited

DBObj type.

Definition at line 59 of file condition_checker.py.

◆ dbObj

dbObj = Belle2.PyDBObj(self.name, self.objType.Class())
inherited

DBObjPtr for the condition.

Definition at line 61 of file condition_checker.py.

◆ eventMetaData

eventMetaData = Belle2.PyStoreObj("EventMetaData")
inherited

pointer to the event metadata

Definition at line 63 of file condition_checker.py.

◆ expstart

int expstart = 999999
inherited

The 1st exp.

Definition at line 82 of file condition_checker.py.

◆ graphs

dict graphs = {}
inherited

Dictionary of plots (TGraph) summarizing variables vs run.

Definition at line 72 of file condition_checker.py.

◆ hist_title_suffix

hist_title_suffix = ""
inherited

Hist title suffix.

Definition at line 76 of file condition_checker.py.

◆ hists

dict hists = {}
inherited

Dictionary of plots (TH1) to be saved for each run.

Definition at line 74 of file condition_checker.py.

◆ name

name = name
inherited

DBObj name.

Definition at line 57 of file condition_checker.py.

◆ rundir

rundir = rundir
inherited

Directory for writing histograms of each run.

Definition at line 67 of file condition_checker.py.

◆ runend

int runend = -1
inherited

The last run.

Definition at line 80 of file condition_checker.py.

◆ runstart

int runstart = 999999
inherited

The 1st run.

Definition at line 78 of file condition_checker.py.

◆ tfile

tfile = tfile
inherited

TFile for saving plots.

Definition at line 65 of file condition_checker.py.

◆ use_hist

use_hist = use_hist
inherited

Flag to get TGraph values from a histogram (TH2F)

Definition at line 84 of file condition_checker.py.


The documentation for this class was generated from the following file: