12This module contains classes for plotting calibration constants.
15__all__ = [
"ConditionCheckerBase",
"PXDMaskedPixelsChecker",
"PXDDeadPixelsChecker",
"PXDOccupancyInfoChecker"]
17from abc
import ABC, abstractmethod
18from ROOT
import Belle2
21from hist_utils
import array2hist
22from pxd.utils import get_sensor_graphs, get_sensor_maps, sensorID_list
23from pxd.utils import latex_r, nPixels, nVCells, nUCells
36type_list = [
'hot',
'dead',
'hot_dead',
'occ_no_mask',
'occ_masked']
38label_list = [
'Hot pixels',
'Dead pixels',
'Hot/Dead pixels',
'No Mask',
'With Mask']
39color_list = [ROOT.kRed + 1, ROOT.kAzure - 5, ROOT.kGray + 2, ROOT.kOrange + 1, ROOT.kSpring + 5]
40max_list = [4., 4., 20., 3., 3.]
42 _type: {
'label': _label,
'color': _color,
'max': _max}
43 for (_type, _label, _color, _max)
in zip(type_list, label_list, color_list, max_list)
50 """Abstract base class describing interfaces to make plots from condition db."""
52 def __init__(self, name, objType, tfile, rundir="", use_hist=False):
91 DBObj type (read only)
111 Call functions at beginning of a run
118 Method to define TGraph
120 ytitle (str): Label for TGraph y-axis
123 self.
graphs.update(get_sensor_graphs(ytitle))
129 name (str): name for TH2, to which sensor name will be attached
130 title (str): title for TH2
131 ztitle (str): title for z-axis (color bar)
132 kwargs: additional arguments
137 self.
hists.update(get_sensor_maps(name, title, ztitle, self.
run, **kwargs))
143 Abstract method to get content of a payload
144 Should return a Dictionary with sensorID.getID() as key and relaated calibration results as value
150 Abstract method to get a value for each TGraph
152 sensor_db_content (Any): Calibration results of a module
157 Method to get a value for each TGraph
159 h2 (TH2): If not none, get value from h2
165 Method to set TH2 bins
167 h2 (TH2): TH2F object for handling values of a pixel matrix
168 sensor_db_content (Any): Calibration results of a module
174 Method to fill plot objects
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
183 db_content = self.get_db_content()
186 for sensorID
in sensorID_list:
187 sensor_db_content = db_content[sensorID.getID()]
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)
199 if self.rundir !=
"" and self.hists:
200 h2 = self.hists[sensorID.getID()]
201 self.set_hist_content(h2, sensor_db_content)
203 h2.SetTitle(h2.GetTitle() + self.hist_title_suffix)
204 self.tfile.cd(self.rundir)
207 values_dict[sensorID.getID()] = self.get_graph_value_from_hist(h2)
209 if values_dict != pre_values_dict:
210 for sensorID
in sensorID_list:
211 gr = self.graphs[sensorID.getID()]
213 gr.SetPoint(gr.GetN(), self.run, values_dict[sensorID.getID()])
216 def draw_plots(self, canvas=None, cname="", ymin=0., ymax=None, logy=False):
218 Method to draw plots on a TCanvas
220 canvas (TCanvas): ROOT TCanvas for plotting
221 canme (str): Name of the canvas
222 ymin (float): Minimum value of y-axis for plotting
223 ymax (float): Maximum of y-axis for plotting
224 logy (bool): Flag to use log scale for y-axis
230 canvas.SetWindowSize(1000, 400)
231 canvas.SetLeftMargin(0.09)
232 canvas.SetRightMargin(0.05)
234 for i, sensorID
in enumerate(sensorID_list):
235 sensor_id = sensorID.getID()
238 ymax = np.array([np.array(gr.GetY())
for gr
in list(self.
graphs.values())
239 if isinstance(gr, ROOT.TGraph)]).max()
240 self.
graphs[sensor_id].SetMaximum(ymax)
241 self.
graphs[sensor_id].SetMinimum(ymin)
242 self.
graphs[sensor_id].Draw(
"AP")
244 self.
graphs[sensor_id].Draw(
"P")
245 if self.
graphs[
"TLegends"]:
246 for leg
in self.
graphs[
"TLegends"]:
252 Save TCanvas to png/pdf format and do not write it to the ROOT file by default
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
259 canvas.SetName(cname)
260 exp_run = f
"e{self.expstart:05}_r{self.runstart:04}-{self.runend:04}"
262 latex_r.DrawLatex(0.95, 0.92,
"Belle II Experiment: " + exp_run.replace(
"_",
" "))
268 canvas.Print(f
"{exp_run}_{cname}_vs_run_logy.png")
269 canvas.Print(f
"{exp_run}_{cname}_vs_run_logy.pdf")
272 canvas.Print(f
"{exp_run}_{cname}_vs_run.png")
273 canvas.Print(f
"{exp_run}_{cname}_vs_run.pdf")
279 Checker for PXDOccupancyInfoPar
289 Method to define TGraph
295 for sensorID
in sensorID_list:
296 numID = sensorID.getID()
297 raw_occ = self.
dbObj.getOccupancy(numID)
299 content_dic[numID] = raw_occ
if raw_occ >= 0
else 0
304 return sensor_db_content * 100
308 Method to draw plots on a TCanvas
315class PXDMaskedPixelsChecker(ConditionCheckerBase):
317 Checker for PXDMaskedPixelPar
327 Method to define TGraph
335 super().
define_hists(name=
"MaskedPixels", title=
"Masked Pixels", ztitle=
"isMasked")
338 return self.
dbObj.getMaskedPixelMap()
341 hotcount = len(sensor_db_content)
344 return hotcount * 100. / nPixels
348 for pixelID
in sensor_db_content:
349 uCell = int(pixelID / nVCells)
350 vCell = pixelID % nVCells
351 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
353 def draw_plots(self, canvas=None, cname="PXDHotPixel", ymin=0., ymax=plot_type_dict["hot"]["max"], **kwargs):
355 Method to draw plots on a TCanvas
357 super().
draw_plots(canvas=canvas, cname=cname, ymin=ymin, ymax=ymax, **kwargs)
362 Checker for PXDDeadPixelPar
365 def __init__(self, name, tfile, rundir="maps", use_hist=True):
372 Method to define TGraph
380 super().
define_hists(name=
"DeadPixels", title=
"Dead Pixels", ztitle=
"isDead")
383 deadsensormap = self.
dbObj.getDeadSensorMap()
384 deaddrainmap = self.
dbObj.getDeadDrainMap()
385 deadrowmap = self.
dbObj.getDeadRowMap()
386 deadsinglesmap = self.
dbObj.getDeadSinglePixelMap()
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
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]
403 if sensor_db_content[
"deadsensor"]:
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:
410 deadcount = n_deaddrains * 192
414 deadcount += n_deadrows * 250
416 deadcount += len(sensor_db_content[
"deadsingles"])
419 h2 = list(get_sensor_maps(sensorID_list=sensorID_list[0:1]).values())[0]
421 deadcount = h2.Integral()
424 return min(deadcount, nPixels) * 100. / nPixels
427 return h2.Integral() * 100. / nPixels
431 if sensor_db_content[
"deadsensor"]:
432 ones = np.ones(nPixels)
435 for drainID
in sensor_db_content[
"deaddrains"]:
436 for iGate
in range(192):
438 vCell = drainID % 4 + iGate * 4
439 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
441 for vCell
in sensor_db_content[
"deadrows"]:
442 for uCell
in range(nUCells):
443 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
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)
450 def draw_plots(self, canvas=None, cname="PXDDeadPixel", ymin=0., ymax=plot_type_dict["dead"]["max"], **kwargs):
452 Method to draw plots on a TCanvas
454 super().
draw_plots(canvas=canvas, cname=cname, ymin=ymin, ymax=ymax, **kwargs)
459 Checker for PXDGainMapPar
469 Method to define TGraph
477 nU = self.
dbObj.getBinsU()
478 nV = self.
dbObj.getBinsV()
479 super().
define_hists(name=
"GainMap", title=
"Gain / MC default", ztitle=
"Relative gain", nUCells=nU, nVCells=nV)
482 gainMap = self.
dbObj.getCalibrationMap()
484 for sensorID
in sensorID_list:
485 numID = sensorID.getID()
486 content_dic[numID] = np.array(list(gainMap[numID]))
491 sensor_db_content (np.array): Array of gain factors of a module
493 return sensor_db_content.mean()
496 array2hist(sensor_db_content.reshape(h2.GetNbinsX(), h2.GetNbinsY()), h2)
498 def draw_plots(self, canvas=None, cname="PXDGain", ymin=0.5, ymax=2.5, **kwargs):
500 Method to draw plots on a TCanvas
502 super().
draw_plots(canvas=canvas, cname=cname, ymin=ymin, ymax=ymax, **kwargs)
The payload telling which PXD pixel is dead (=Readout system does not receive signals)
The payload class for PXD gain corrections.
The payload telling which PXD pixel to mask (ignore)
The payload collecting some meta information from running the masking algorithm.
Class to access a DBObjPtr from Python.
a (simplified) python wrapper for StoreObjPtr.
define_graphs(self, ytitle="")
eventMetaData
pointer to the event metadata
set_hist_content(self, h2, sensor_db_content)
save_canvas(self, canvas, cname, logy=False)
dbObj
DBObjPtr for the condition.
use_hist
Flag to get TGraph values from a histogram (TH2F)
get_graph_value(self, sensor_db_content)
rundir
Directory for writing histograms of each run.
dict hists
Dictionary of plots (TH1) to be saved for each run.
dict graphs
Dictionary of plots (TGraph) summarizing variables vs run.
str hist_title_suffix
Hist title suffix.
draw_plots(self, canvas=None, cname="", ymin=0., ymax=None, logy=False)
get_graph_value_from_hist(self, h2=None)
tfile
TFile for saving plots.
__init__(self, name, objType, tfile, rundir="", use_hist=False)
define_hists(self, name=None, title=None, ztitle=None, **kwargs)
set_hist_content(self, h2, sensor_db_content)
get_graph_value(self, sensor_db_content)
get_graph_value_from_hist(self, h2)
draw_plots(self, canvas=None, cname="PXDDeadPixel", ymin=0., ymax=plot_type_dict["dead"]["max"], **kwargs)
__init__(self, name, tfile, rundir="maps", use_hist=True)
set_hist_content(self, h2, sensor_db_content)
draw_plots(self, canvas=None, cname="PXDGain", ymin=0.5, ymax=2.5, **kwargs)
get_graph_value(self, sensor_db_content)
__init__(self, name, tfile, rundir="maps")
set_hist_content(self, h2, sensor_db_content)
get_graph_value(self, sensor_db_content)
__init__(self, name, tfile, rundir="maps")
draw_plots(self, canvas=None, cname="PXDHotPixel", ymin=0., ymax=plot_type_dict["hot"]["max"], **kwargs)
get_graph_value(self, sensor_db_content)
draw_plots(self, canvas=None, **kwargs)
__init__(self, name, tfile, rundir="")