Belle II Software  release-08-01-10
plotHotPixelMasks.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # Creates overview plots for hotpixel calibrations
12 #
13 # At first, you can extract the hotpixel calibration payloads from a localdb/centraldb using the tool
14 #
15 # b2conditionsdb-extract --exp 3 --runs 0-5614 --tag Calibration_Offline_Development --output hot_payloads.root PXDMaskedPixelPar
16 #
17 # Secondly, execute the script as
18 #
19 # basf2 plotHotPixelMasks.py
20 #
21 # basf2 plotHotPixelMasks.py -- --maps
22 
23 
24 import basf2 as b2
25 import ROOT
26 from ROOT import Belle2
27 from array import array
28 
29 import argparse
30 parser = argparse.ArgumentParser(description="Plot hotpixel maps")
31 parser.add_argument('--maps', dest='maps', action="store_true", help='Create maps from payloads. This can be slow!')
32 args = parser.parse_args()
33 
34 
35 sensor_list = [
36  Belle2.VxdID("1.1.1"), Belle2.VxdID("1.1.2"),
37  Belle2.VxdID("1.2.1"), Belle2.VxdID("1.2.2"),
38  Belle2.VxdID("1.3.1"), Belle2.VxdID("1.3.2"),
39  Belle2.VxdID("1.4.1"), Belle2.VxdID("1.4.2"),
40  Belle2.VxdID("1.5.1"), Belle2.VxdID("1.5.2"),
41  Belle2.VxdID("1.6.1"), Belle2.VxdID("1.6.2"),
42  Belle2.VxdID("1.7.1"), Belle2.VxdID("1.7.2"),
43  Belle2.VxdID("1.8.1"), Belle2.VxdID("1.8.2"),
44  Belle2.VxdID("2.4.1"), Belle2.VxdID("2.4.2"),
45  Belle2.VxdID("2.5.1"), Belle2.VxdID("2.5.2")]
46 
47 # Create output file wíth histos and plots
48 histofile = ROOT.TFile('hotpixel_histos.root', 'RECREATE')
49 histofile.cd()
50 histofile.mkdir("maps")
51 
52 # Open file with extracted payloads
53 rfile = ROOT.TFile("hot_payloads.root", "READ")
54 b2.conditions = rfile.Get("conditions")
55 
56 hotpixel_table = dict()
57 for sensorID in sensor_list:
58  hotpixel_table[sensorID.getID()] = list()
59 run_list = list()
60 
61 for condition in b2.conditions:
62  if condition.PXDMaskedPixelPar_valid:
63  print(f"Starting on run {condition.run}")
64  run_list.append(condition.run)
65 
66  for sensorID in sensor_list:
67 
68  nUCells = 250
69  nVCells = 768
70 
71  hotpixelmap = condition.PXDMaskedPixelPar.getMaskedPixelMap()
72 
73  layer = sensorID.getLayerNumber()
74  ladder = sensorID.getLadderNumber()
75  sensor = sensorID.getSensorNumber()
76 
77  counter = len(hotpixelmap[sensorID.getID()])
78 
79  if args.maps:
80  name = f"MaskedPixels_{layer:d}_{ladder:d}_{sensor:d}_run_{condition.run:d}"
81  title = f"Masked Pixels Sensor={layer:d}.{ladder:d}.{sensor:d} run={condition.run:d}"
82  hot_map = ROOT.TH2F(name, title, nUCells, 0, nUCells, nVCells, 0, nVCells)
83  hot_map.GetXaxis().SetTitle("uCell")
84  hot_map.GetYaxis().SetTitle("vCell")
85  hot_map.GetZaxis().SetTitle("isMasked")
86  hot_map.SetStats(0)
87 
88  for uCell in range(nUCells):
89  for vCell in range(nVCells):
90  pixID = uCell * nVCells + vCell
91  isMasked = not condition.PXDMaskedPixelPar.pixelOK(sensorID.getID(), pixID)
92  hot_map.SetBinContent(int(uCell + 1), int(vCell + 1), isMasked)
93 
94  histofile.cd("maps")
95  hot_map.Write()
96 
97  hotfraction = counter / (nUCells * nVCells)
98  hotpixel_table[sensorID.getID()].append(hotfraction)
99 
100 
101 histofile.cd()
102 c = ROOT.TCanvas('hotpixels_vs_runno', 'Hotpixel evolution vs. run number', 200, 10, 700, 500)
103 c.SetGrid()
104 
105 for sensorID in sensor_list:
106 
107  n = len(run_list)
108  x, y = array('d'), array('d')
109  for value in hotpixel_table[sensorID.getID()]:
110  y.append(value)
111  for run in run_list:
112  x.append(run)
113 
114  gr = ROOT.TGraph(n, x, y)
115  gr.SetLineColor(ROOT.kBlue)
116  gr.SetLineWidth(4)
117  gr.SetName(f"graph_{sensorID.getID()}")
118  gr.SetMarkerColor(ROOT.kBlue)
119  gr.SetMarkerStyle(21)
120  gr.SetTitle(f'Hotpixel evolution Sensor={sensorID}')
121  gr.GetXaxis().SetTitle('run number')
122  gr.GetYaxis().SetTitle('hotpixel fraction')
123  gr.GetYaxis().SetRangeUser(0.0, 1.0)
124  gr.Draw('AP')
125 
126  c.Update()
127  c.Modified()
128  c.Print(f'hotpixel_vs_runno_{sensorID.getID()}.png')
129  c.Write()
130 
131 
132 rfile.Close()
133 histofile.Close()
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33