5 This module contains classes for plotting calibration constants.
6 Author: qingyuan.liu@desy.de
9 from abc
import ABC, abstractmethod
10 from ROOT
import Belle2
11 from ROOT.Belle2
import PXDMaskedPixelPar, PXDDeadPixelPar, PXDOccupancyInfoPar
13 from copy
import deepcopy
15 from pxd.utils import get_sensor_graphs, sensorID_list
22 __cal_checker_dict__ = {
23 "PXDHotPixelMaskCalibrationChecker": set([PXDMaskedPixelPar, PXDDeadPixelPar, PXDOccupancyInfoPar]),
30 Abstract base class for generating plots from calibrations which save multiple payloads.
36 objType_list (list): a list of db objects used as keys to their checker.
37 e.g., [Belle2.PXDMaskedPixelPar, Belle2.PXDDeadPixelPar]
41 for objType
in objType_list:
46 Initialize condition_checker according to condition objType
48 checker_list (list): list of objType checkers
51 for checker
in checker_list:
53 if objType == checker.objType:
57 print(f
"root file path: {checker.tfile}")
80 Method to fill TGraphs
86 Generate summary plots from TGraphs of all condition checkers
91 function to be executed at the beginning of a run
98 Execute when terminating a basf2 module.
99 All required TGraphs should be ready at this stage.
107 Checker for PXDHotPixelMaskCalibration
112 Initial with related condition db object types
122 Define TGraphs for filling
133 legsum = ROOT.TLegend(0.75, 0.65, 0.90, 0.85)
134 legsum.SetFillStyle(0)
135 legsum.SetBorderSize(0)
136 legsum.SetTextFont(43)
137 legsum.SetTextSize(18)
138 legocc = deepcopy(legsum)
139 self.
sum_graphs[
"TLegends"] = {
"sum": legsum,
"occ": legocc}
141 for category, style_dict
in plot_type_dict.items():
142 agraph = ROOT.TGraph()
143 agraph.SetLineColor(style_dict[
"color"])
144 agraph.SetMarkerColor(style_dict[
"color"])
145 agraph.SetMarkerStyle(20)
146 if category ==
"hot_dead":
147 agraph.GetYaxis().SetTitle(
'Total Hot/Dead pixels [%]')
148 agraph.SetMaximum(style_dict[
"max"])
149 elif category ==
"occ_no_mask":
150 agraph.GetYaxis().SetTitle(
'Average occupancy [%]')
151 agraph.SetMaximum(style_dict[
"max"])
152 agraph.GetXaxis().SetTitle(
'run #')
153 agraph.GetYaxis().SetTitleOffset(0.9)
154 agraph.SetMinimum(0.0)
159 Fill TGraphs, will be executed for each run
166 current_run = dead_checker.run
170 sum_deadfraction = 0.
171 sum_hotdeadfraction = 0.
172 sum_occupancymasked = 0.
173 sum_occupancynomask = 0.
174 for sensorID
in sensorID_list:
175 numID = sensorID.getID()
177 g1 = masked_graphs[numID]
178 g2 = dead_graphs[numID]
179 g3 = occ_graphs[numID]
181 hotfraction = g1.GetPointY(g1.GetN() - 1)
182 deadfraction = g2.GetPointY(g2.GetN() - 1)
183 occupancymasked = g3.GetPointY(g3.GetN() - 1)
186 saved_run = max(g1.GetPointX(g1.GetN() - 1), g2.GetPointX(g2.GetN() - 1))
187 saved_run_occ = max(saved_run, g3.GetPointX(g3.GetN() - 1))
188 if current_run == saved_run:
189 self.
hotdead_graphs[numID].append(current_run, hotfraction + deadfraction)
190 sum_hotfraction += hotfraction
191 sum_deadfraction += deadfraction
192 sum_hotdeadfraction += hotfraction + deadfraction
193 if current_run == saved_run_occ:
196 if deadfraction != 100.:
197 occupancynomask = (occupancymasked + hotfraction) / (1. - deadfraction / 100)
198 occupancymasked = occupancymasked / (1. - deadfraction / 100)
201 sum_occupancymasked += occupancymasked
202 sum_occupancynomask += occupancynomask
210 nSensors = len(sensorID_list)
211 if current_run == saved_run:
212 self.
sum_graphs[
"hot"].append(current_run, sum_hotfraction / nSensors)
213 self.
sum_graphs[
"dead"].append(current_run, sum_deadfraction / nSensors)
214 self.
sum_graphs[
"hot_dead"].append(current_run, sum_hotdeadfraction / nSensors)
216 nSensors = nSensors - len(dead_checker.dbObj.getDeadSensorMap())
217 if current_run == saved_run_occ:
218 self.
sum_graphs[
"occ_masked"].append(current_run, sum_occupancymasked / nSensors)
219 self.
sum_graphs[
"occ_no_mask"].append(current_run, sum_occupancynomask / nSensors)
223 Generate summary plots from TGraphs of all condition checkers
233 canvas = ROOT.TCanvas(
'c_pxd',
'c_pxd', 1000, 400)
240 canvas=canvas, cname=
"PXDHotnDeadPixel", ymin=0., ymax=plot_type_dict[
"hot_dead"][
"max"])
244 canvas=canvas, cname=
"PXDOccupancyWithMask", ymin=0., ymax=plot_type_dict[
"occ_masked"][
"max"])
247 canvas=canvas, cname=
"PXDOccupancyNoMask", ymin=0., ymax=plot_type_dict[
"occ_no_mask"][
"max"])
261 leg.AddEntry(g1,
'Hot+Dead pixels',
'p')
262 leg.AddEntry(g2,
'Hot pixels',
'p')
263 leg.AddEntry(g3,
'Dead pixels',
'p')
265 checker.save_canvas(canvas,
"PXDTotalHotnDeadPixel", with_logy=
True)
273 leg.AddEntry(g1,
'No Mask',
'p')
274 leg.AddEntry(g2,
'With Mask',
'p')
276 checker.save_canvas(canvas,
"PXDTotalOccupancy", with_logy=
True)