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

Public Member Functions

 __init__ (self, name, objType, tfile, rundir="", use_hist=False)
 
 objType (self)
 
 run (self)
 
 exp (self)
 
 beginRun (self)
 
 define_graphs (self, ytitle="")
 
 define_hists (self, name=None, title=None, ztitle=None, **kwargs)
 
 get_db_content (self)
 
 get_graph_value (self, sensor_db_content)
 
 get_graph_value_from_hist (self, h2=None)
 
 set_hist_content (self, h2, sensor_db_content)
 
 fill_plots (self)
 
 draw_plots (self, canvas=None, cname="", ymin=0., ymax=None, logy=False)
 
 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)
 
 run = self.graphs[sensorID.getID()]
 

Protected Attributes

 _objType = objType
 DBObj type.
 

Detailed Description

Abstract base class describing interfaces to make plots from condition db.

Definition at line 49 of file condition_checker.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
name,
objType,
tfile,
rundir = "",
use_hist = False )
 

Definition at line 52 of file condition_checker.py.

52 def __init__(self, name, objType, tfile, rundir="", use_hist=False):
53 """
54 """
55 super().__init__()
56
57 self.name = name
58
59 self._objType = objType
60
61 self.dbObj = Belle2.PyDBObj(self.name, self.objType.Class())
62
63 self.eventMetaData = Belle2.PyStoreObj("EventMetaData")
64
65 self.tfile = tfile
66
67 self.rundir = rundir # empty means skipping self.hists
68 if self.rundir != "":
69 self.tfile.cd()
70 self.tfile.mkdir(self.rundir)
71
72 self.graphs = {}
73
74 self.hists = {}
75
76 self.hist_title_suffix = ""
77
78 self.runstart = 999999 # a big number that will never be used
79
80 self.runend = -1
81
82 self.expstart = 999999
83
84 self.use_hist = use_hist
85
86 self.define_graphs()
87
Class to access a DBObjPtr from Python.
Definition PyDBObj.h:50
a (simplified) python wrapper for StoreObjPtr.
Definition PyStoreObj.h:67

Member Function Documentation

◆ beginRun()

beginRun ( self)
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,
ytitle = "" )
Method to define TGraph
Parameters:
  ytitle (str): Label for TGraph y-axis

Reimplemented in PXDDeadPixelsChecker, PXDGainMapChecker, PXDMaskedPixelsChecker, and PXDOccupancyInfoChecker.

Definition at line 116 of file condition_checker.py.

116 def define_graphs(self, ytitle=""):
117 """
118 Method to define TGraph
119 Parameters:
120 ytitle (str): Label for TGraph y-axis
121 """
122 self.tfile.cd()
123 self.graphs.update(get_sensor_graphs(ytitle))
124

◆ define_hists()

define_hists ( self,
name = None,
title = None,
ztitle = None,
** kwargs )
Method to define TH2
Parameters:
  name (str): name for TH2, to which sensor name will be attached
  title (str): title for TH2
  ztitle (str): title for z-axis (color bar)
  kwargs: additional arguments

Reimplemented in PXDDeadPixelsChecker, PXDGainMapChecker, and PXDMaskedPixelsChecker.

Definition at line 125 of file condition_checker.py.

125 def define_hists(self, name=None, title=None, ztitle=None, **kwargs):
126 """
127 Method to define TH2
128 Parameters:
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
133 """
134 if self.rundir:
135 self.tfile.cd(self.rundir)
136 self.hists.update(get_sensor_maps(name, title, ztitle, self.run, **kwargs))
137

◆ draw_plots()

draw_plots ( self,
canvas = None,
cname = "",
ymin = 0.,
ymax = None,
logy = False )
Method to draw plots on a TCanvas
Parameters:
  canvas (TCanvas): ROOT TCanvas for plotting
  canme (str): Name of the canvas
  ymin (float): Minimum value of y-axis for plotting
  ymax (float): Maximum of y-axis for plotting
  logy (bool): Flag to use log scale for y-axis

Reimplemented in PXDDeadPixelsChecker, PXDGainMapChecker, PXDMaskedPixelsChecker, and PXDOccupancyInfoChecker.

Definition at line 212 of file condition_checker.py.

212 def draw_plots(self, canvas=None, cname="", ymin=0., ymax=None, logy=False):
213 """
214 Method to draw plots on a TCanvas
215 Parameters:
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
221 """
222 if not canvas:
223 return
224 else:
225 canvas.Clear()
226 canvas.SetWindowSize(1000, 400)
227 canvas.SetLeftMargin(0.09)
228 canvas.SetRightMargin(0.05)
229 self.tfile.cd()
230 for i, sensorID in enumerate(sensorID_list):
231 sensor_id = sensorID.getID()
232 if i == 0:
233 if ymax is None:
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")
239 else:
240 self.graphs[sensor_id].Draw("P")
241 if self.graphs["TLegends"]:
242 for leg in self.graphs["TLegends"]:
243 leg.Draw()
244 self.save_canvas(canvas, cname, logy=logy)
245

◆ exp()

exp ( self)
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)
Method to fill plot objects

Definition at line 170 of file condition_checker.py.

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

◆ 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 in PXDDeadPixelsChecker, PXDGainMapChecker, PXDMaskedPixelsChecker, and PXDOccupancyInfoChecker.

Definition at line 139 of file condition_checker.py.

139 def get_db_content(self):
140 """
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
143 """
144

◆ 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 in PXDDeadPixelsChecker, PXDGainMapChecker, PXDMaskedPixelsChecker, and PXDOccupancyInfoChecker.

Definition at line 146 of file condition_checker.py.

146 def get_graph_value(self, sensor_db_content):
147 """
148 Abstract method to get a value for each TGraph
149 Parameters:
150 sensor_db_content (Any): Calibration results of a module
151 """
152

◆ get_graph_value_from_hist()

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

Reimplemented in PXDDeadPixelsChecker.

Definition at line 153 of file condition_checker.py.

153 def get_graph_value_from_hist(self, h2=None):
154 """
155 Method to get a value for each TGraph
156 Parameters:
157 h2 (TH2): If not none, get value from h2
158 """
159 return None
160

◆ objType()

objType ( self)
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)
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 )
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 246 of file condition_checker.py.

246 def save_canvas(self, canvas, cname, logy=False):
247 """
248 Save TCanvas to png/pdf format and do not write it to the ROOT file by default
249 Parameters:
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
253 """
254 if cname:
255 canvas.SetName(cname)
256 exp_run = f"e{self.expstart:05}_r{self.runstart:04}-{self.runend:04}"
257 # Draw Belle II label
258 latex_r.DrawLatex(0.95, 0.92, "Belle II Experiment: " + exp_run.replace("_", " "))
259 # Print and write TCanvas
260 if logy:
261 canvas.SetLogy(1)
262 canvas.Update()
263 canvas.Modified()
264 canvas.Print(f"{exp_run}_{cname}_vs_run_logy.png")
265 canvas.Print(f"{exp_run}_{cname}_vs_run_logy.pdf")
266 else:
267 canvas.SetLogy(0)
268 canvas.Print(f"{exp_run}_{cname}_vs_run.png")
269 canvas.Print(f"{exp_run}_{cname}_vs_run.pdf")
270 self.tfile.cd()
271
272

◆ 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 in PXDDeadPixelsChecker, PXDGainMapChecker, and PXDMaskedPixelsChecker.

Definition at line 161 of file condition_checker.py.

161 def set_hist_content(self, h2, sensor_db_content):
162 """
163 Method to set TH2 bins
164 Parameters:
165 h2 (TH2): TH2F object for handling values of a pixel matrix
166 sensor_db_content (Any): Calibration results of a module
167 """
168 pass
169

Member Data Documentation

◆ _objType

_objType = objType
protected

DBObj type.

Definition at line 59 of file condition_checker.py.

◆ dbObj

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

DBObjPtr for the condition.

Definition at line 61 of file condition_checker.py.

◆ eventMetaData

eventMetaData = Belle2.PyStoreObj("EventMetaData")

pointer to the event metadata

Definition at line 63 of file condition_checker.py.

◆ expstart

int expstart = 999999

The 1st exp.

Definition at line 82 of file condition_checker.py.

◆ graphs

dict graphs = {}

Dictionary of plots (TGraph) summarizing variables vs run.

Definition at line 72 of file condition_checker.py.

◆ hist_title_suffix

hist_title_suffix = ""

Hist title suffix.

Definition at line 76 of file condition_checker.py.

◆ hists

dict hists = {}

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

Definition at line 74 of file condition_checker.py.

◆ name

name = name

DBObj name.

Definition at line 57 of file condition_checker.py.

◆ run

run = self.graphs[sensorID.getID()]

Definition at line 136 of file condition_checker.py.

◆ rundir

rundir = rundir

Directory for writing histograms of each run.

Definition at line 67 of file condition_checker.py.

◆ runend

int runend = -1

The last run.

Definition at line 80 of file condition_checker.py.

◆ runstart

int runstart = 999999

The 1st run.

Definition at line 78 of file condition_checker.py.

◆ tfile

tfile = tfile

TFile for saving plots.

Definition at line 65 of file condition_checker.py.

◆ use_hist

use_hist = use_hist

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: