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
136 self.
hists.update(get_sensor_maps(name, title, ztitle, self.
run, **kwargs))
141 Abstract method to get content of a payload
142 Should return a Dictionary
with sensorID.getID()
as key
and relaated calibration results
as value
148 Abstract method to get a value for each TGraph
150 sensor_db_content (Any): Calibration results of a module
155 Method to get a value for each TGraph
157 h2 (TH2): If
not none, get value
from h2
163 Method to set TH2 bins
165 h2 (TH2): TH2F object for handling values of a pixel matrix
166 sensor_db_content (Any): Calibration results of a module
172 Method to fill plot objects
184 for sensorID
in sensorID_list:
185 sensor_db_content = db_content[sensorID.getID()]
188 values_dict[sensorID.getID()] = self.
get_graph_value(sensor_db_content)
189 gr = self.
graphs[sensorID.getID()]
190 pre_values_dict[sensorID.getID()] = gr.GetPointY(gr.GetN() - 1)
198 h2 = self.
hists[sensorID.getID()]
207 if values_dict != pre_values_dict:
208 for sensorID
in sensorID_list:
209 gr = self.
graphs[sensorID.getID()]
210 gr.SetPoint(gr.GetN(), self.
run, values_dict[sensorID.getID()])
212 def draw_plots(self, canvas=None, cname="", ymin=0., ymax=None, logy=False):
214 Method to draw plots on a TCanvas
216 canvas (TCanvas): ROOT TCanvas for plotting
217 canme (str): Name of the canvas
218 ymin (float): Minimum value of y-axis
for plotting
219 ymax (float): Maximum of y-axis
for plotting
220 logy (bool): Flag to use log scale
for y-axis
226 canvas.SetWindowSize(1000, 400)
227 canvas.SetLeftMargin(0.09)
228 canvas.SetRightMargin(0.05)
230 for i, sensorID
in enumerate(sensorID_list):
231 sensor_id = sensorID.getID()
234 ymax = np.array([np.array(gr.GetY())
for gr
in list(self.
graphs.values())
235 if isinstance(gr, ROOT.TGraph)]).max()
236 self.
graphs[sensor_id].SetMaximum(ymax)
237 self.
graphs[sensor_id].SetMinimum(ymin)
238 self.
graphs[sensor_id].Draw(
"AP")
240 self.
graphs[sensor_id].Draw(
"P")
241 if self.
graphs[
"TLegends"]:
242 for leg
in self.
graphs[
"TLegends"]:
248 Save TCanvas to png/pdf format and do
not write it to the ROOT file by default
250 canvas (TCanvas): ROOT TCanvas
for plotting
251 canme (str): Name of the canvas
252 logy (bool): Flag to use log scale
for y-axis
255 canvas.SetName(cname)
256 exp_run = f
"e{self.expstart:05}_r{self.runstart:04}-{self.runend:04}"
258 latex_r.DrawLatex(0.95, 0.92,
"Belle II Experiment: " + exp_run.replace(
"_",
" "))
264 canvas.Print(f
"{exp_run}_{cname}_vs_run_logy.png")
265 canvas.Print(f
"{exp_run}_{cname}_vs_run_logy.pdf")
268 canvas.Print(f
"{exp_run}_{cname}_vs_run.png")
269 canvas.Print(f
"{exp_run}_{cname}_vs_run.pdf")
275 Checker for PXDOccupancyInfoPar
285 Method to define TGraph
291 for sensorID
in sensorID_list:
292 numID = sensorID.getID()
293 raw_occ = self.
dbObj.getOccupancy(numID)
295 content_dic[numID] = raw_occ
if raw_occ >= 0
else 0
300 return sensor_db_content * 100
304 Method to draw plots on a TCanvas
313 Checker for PXDMaskedPixelPar
323 Method to define TGraph
331 super().define_hists(name="MaskedPixels", title=
"Masked Pixels", ztitle=
"isMasked")
334 return self.
dbObj.getMaskedPixelMap()
337 hotcount = len(sensor_db_content)
340 return hotcount * 100. / nPixels
344 for pixelID
in sensor_db_content:
345 uCell = int(pixelID / nVCells)
346 vCell = pixelID % nVCells
347 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
349 def draw_plots(self, canvas=None, cname="PXDHotPixel", ymin=0., ymax=plot_type_dict["hot"]["max"], **kwargs):
351 Method to draw plots on a TCanvas
353 super().draw_plots(canvas=canvas, cname=cname, ymin=ymin, ymax=ymax, **kwargs)
358 Checker for PXDDeadPixelPar
361 def __init__(self, name, tfile, rundir="maps", use_hist=True):
368 Method to define TGraph
376 super().define_hists(name="DeadPixels", title=
"Dead Pixels", ztitle=
"isDead")
379 deadsensormap = self.
dbObj.getDeadSensorMap()
380 deaddrainmap = self.
dbObj.getDeadDrainMap()
381 deadrowmap = self.
dbObj.getDeadRowMap()
382 deadsinglesmap = self.
dbObj.getDeadSinglePixelMap()
385 for sensorID
in sensorID_list:
386 numID = sensorID.getID()
387 content_dic[numID] = {}
388 if numID
in deadsensormap:
389 content_dic[numID][
"deadsensor"] =
True
391 content_dic[numID][
"deadsensor"] =
False
392 content_dic[numID][
"deaddrains"] = deaddrainmap[numID]
393 content_dic[numID][
"deadrows"] = deadrowmap[numID]
394 content_dic[numID][
"deadsingles"] = deadsinglesmap[numID]
399 if sensor_db_content[
"deadsensor"]:
402 n_deaddrains = len(sensor_db_content[
"deaddrains"])
403 n_deadrows = len(sensor_db_content[
"deadrows"])
404 if n_deaddrains == 0
or n_deadrows == 0:
406 deadcount = n_deaddrains * 192
410 deadcount += n_deadrows * 250
412 deadcount += len(sensor_db_content[
"deadsingles"])
415 h2 = list(get_sensor_maps(sensorID_list=sensorID_list[0:1]).values())[0]
417 deadcount = h2.Integral()
420 return min(deadcount, nPixels) * 100. / nPixels
423 return h2.Integral() * 100. / nPixels
427 if sensor_db_content[
"deadsensor"]:
428 ones = np.ones(nPixels)
431 for drainID
in sensor_db_content[
"deaddrains"]:
432 for iGate
in range(192):
434 vCell = drainID % 4 + iGate * 4
435 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
437 for vCell
in sensor_db_content[
"deadrows"]:
438 for uCell
in range(nUCells):
439 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
441 for pixelID
in sensor_db_content[
"deadsingles"]:
442 uCell = int(pixelID / nVCells)
443 vCell = pixelID % nVCells
444 h2.SetBinContent(int(uCell + 1), int(vCell + 1), 1)
446 def draw_plots(self, canvas=None, cname="PXDDeadPixel", ymin=0., ymax=plot_type_dict["dead"]["max"], **kwargs):
448 Method to draw plots on a TCanvas
450 super().draw_plots(canvas=canvas, cname=cname, ymin=ymin, ymax=ymax, **kwargs)
455 Checker for PXDGainMapPar
465 Method to define TGraph
473 nU = self.dbObj.getBinsU()
474 nV = self.dbObj.getBinsV()
475 super().define_hists(name="GainMap", title=
"Gain / MC default", ztitle=
"Relative gain", nUCells=nU, nVCells=nV)
478 gainMap = self.
dbObj.getCalibrationMap()
480 for sensorID
in sensorID_list:
481 numID = sensorID.getID()
482 content_dic[numID] = np.array(list(gainMap[numID]))
487 sensor_db_content (np.array): Array of gain factors of a module
489 return sensor_db_content.mean()
492 array2hist(sensor_db_content.reshape(h2.GetNbinsX(), h2.GetNbinsY()), h2)
494 def draw_plots(self, canvas=None, cname="PXDGain", ymin=0.5, ymax=2.5, **kwargs):
496 Method to draw plots on a TCanvas
498 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.
eventMetaData
pointer to the event metadata
def set_hist_content(self, h2, sensor_db_content)
graphs
Dictionary of plots (TGraph) summarizing variables vs run.
dbObj
DBObjPtr for the condition.
use_hist
Flag to get TGraph values from a histogram (TH2F)
rundir
Directory for writing histograms of each run.
def save_canvas(self, canvas, cname, logy=False)
def draw_plots(self, canvas=None, cname="", ymin=0., ymax=None, logy=False)
def define_hists(self, name=None, title=None, ztitle=None, **kwargs)
hist_title_suffix
Hist title suffix.
def define_graphs(self, ytitle="")
def get_graph_value_from_hist(self, h2=None)
tfile
TFile for saving plots.
def get_graph_value(self, sensor_db_content)
hists
Dictionary of plots (TH1) to be saved for each run.
def __init__(self, name, objType, tfile, rundir="", use_hist=False)
def set_hist_content(self, h2, sensor_db_content)
hist_title_suffix
Hist title suffix.
def get_graph_value_from_hist(self, h2)
def draw_plots(self, canvas=None, cname="PXDDeadPixel", ymin=0., ymax=plot_type_dict["dead"]["max"], **kwargs)
def __init__(self, name, tfile, rundir="maps", use_hist=True)
def get_graph_value(self, sensor_db_content)
def set_hist_content(self, h2, sensor_db_content)
def __init__(self, name, tfile, rundir="maps")
def draw_plots(self, canvas=None, cname="PXDGain", ymin=0.5, ymax=2.5, **kwargs)
def get_graph_value(self, sensor_db_content)
def set_hist_content(self, h2, sensor_db_content)
def __init__(self, name, tfile, rundir="maps")
hist_title_suffix
Hist title suffix.
def draw_plots(self, canvas=None, cname="PXDHotPixel", ymin=0., ymax=plot_type_dict["hot"]["max"], **kwargs)
def get_graph_value(self, sensor_db_content)
def __init__(self, name, tfile, rundir="")
def draw_plots(self, canvas=None, **kwargs)
def get_graph_value(self, sensor_db_content)