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