Belle II Software development
klm_channel_status.py
1
8
9'''
10Validation of KLM channel status calibration.
11'''
12
13# import math
14import numpy
15import ROOT
16# from ROOT.Belle2 import KLMChannelStatus
17from prompt import ValidationSettings
18import argparse
19import matplotlib.pyplot as plt
20
21
22settings = ValidationSettings(name='KLM channel status',
23 description=__doc__,
24 download_files=['stdout'],
25 expert_config={
26 "chunk_size": 100
27 })
28
29
30def parse_args():
31 parser = argparse.ArgumentParser()
32 parser.add_argument('job_path')
33 parser.add_argument('input_data_path')
34 parser.add_argument('requested_iov')
35 parser.add_argument('expert_config')
36 return parser.parse_args()
37
38
39def plot(run_num_arry, eklm_dead_arry, eklm_hot_arry, bklm_dead_arry, bklm_hot_arry,
40 fname='plots.pdf', drawLims=False):
41 fig, axs = plt.subplots(2, 2, sharex=True)
42 axs = axs.ravel()
43
44 axs[0].plot(run_num_arry, eklm_dead_arry, '.', color='C0')
45 axs[0].set_ylabel("EKLM dead channels")
46 axs[0].set_xlabel("Run numbers")
47
48 axs[1].plot(run_num_arry, eklm_hot_arry, '.', color='C1')
49 axs[1].set_ylabel("EKLM hot channels")
50 axs[1].set_xlabel("Run numbers")
51
52 axs[2].plot(run_num_arry, bklm_dead_arry, '.', color='C0')
53 axs[2].set_ylabel("BKLM dead channels")
54 axs[2].set_xlabel("Run numbers")
55
56 axs[3].plot(run_num_arry, bklm_hot_arry, '.', color='C1')
57 axs[3].set_ylabel("BKLM hot channels")
58 axs[3].set_xlabel("Run numbers")
59
60 if drawLims:
61 axs[0].axhline(300, ls='--', color='r')
62 axs[1].axhline(8, ls='--', color='r')
63 axs[2].axhline(300, ls='--', color='r')
64 axs[3].axhline(8, ls='--', color='r')
65
66 fig.savefig(fname)
67
68
69if __name__ == '__main__':
70 args = parse_args()
71 job_path = args.job_path
72 input_data_path = args.input_data_path
73 requested_iov = args.requested_iov
74 expert_config = args.expert_config
75
76 database_file = f'{job_path}/KLMChannelStatus/outputdb/database.txt'
77
78 rev = []
79 ini = []
80 fin = []
81
82 # if len(sys.argv) != 2:
83 # print('Usage: basf2 generateValidationRoot.py dirName')
84 # print('')
85 # sys.exit(1)
86 # dirName = str(sys.argv[1])
87 # caliDir = dirName
88
89 iovfile = open(database_file, 'r')
90 for line in iovfile:
91 lst = line.split()
92 rev.append(lst[1])
93 iov = lst[2].split(',')
94 ini.append(int(iov[1]))
95 fin.append(int(iov[3]))
96 iovfile.close()
97
98 rev_num = numpy.zeros(1, dtype=str)
99 run_num = numpy.zeros(1, dtype=int)
100
101 eklm_normal = numpy.zeros(1, dtype=int)
102 eklm_dead = numpy.zeros(1, dtype=int)
103 eklm_hot = numpy.zeros(1, dtype=int)
104
105 bklm_normal = numpy.zeros(1, dtype=int)
106 bklm_dead = numpy.zeros(1, dtype=int)
107 bklm_hot = numpy.zeros(1, dtype=int)
108
109 tree = ROOT.TTree('tree', '')
110 tree.Branch('rev_num', rev_num, 'rev_num/S')
111 tree.Branch('run_num', run_num, 'run_num/I')
112 tree.Branch('eklm_normal', eklm_normal, 'eklm_normal/I')
113 tree.Branch('eklm_dead', eklm_dead, 'eklm_dead/I')
114 tree.Branch('eklm_hot', eklm_hot, 'eklm_hot/I')
115 tree.Branch('bklm_normal', bklm_normal, 'bklm_normal/I')
116 tree.Branch('bklm_dead', bklm_dead, 'bklm_dead/I')
117 tree.Branch('bklm_hot', bklm_hot, 'bklm_hot/I')
118
119 # store all entries for plot
120 run_num_arry = []
121 eklm_dead_arry = []
122 eklm_hot_arry = []
123 bklm_dead_arry = []
124 bklm_hot_arry = []
125
126 for x in range(0, len(rev)):
127 filename = f'{job_path}/KLMChannelStatus/outputdb/dbstore_KLMChannelStatus_rev_'+str(rev[x])+'.root'
128 channel_status_file = ROOT.TFile(filename)
129 channel_status_obj = channel_status_file.Get("KLMChannelStatus")
130 eklm_normal[0] = 0
131 eklm_dead[0] = 0
132 eklm_hot[0] = 0
133 bklm_normal[0] = 0
134 bklm_dead[0] = 0
135 bklm_hot[0] = 0
136 for i in range(1, 65536):
137 status = channel_status_obj.getChannelStatus(i)
138 if (status == 1):
139 if (i <= 15600):
140 eklm_normal[0] += 1
141 else:
142 bklm_normal[0] += 1
143 elif (status != 1 and status != 0):
144 if (i <= 15600):
145 if (status == 2):
146 eklm_dead[0] += 1
147 elif (status == 3):
148 eklm_hot[0] += 1
149 else:
150 if (status == 2):
151 bklm_dead[0] += 1
152 elif (status == 3):
153 bklm_hot[0] += 1
154 channel_status_file.Close()
155 rev_num[0] = rev[x]
156 run_num[0] = ini[x]
157 tree.Fill()
158 myIni = int(ini[x])
159 myFin = int(fin[x])
160 '''
161 #undesired behavior because this crowds the histogram too much
162 while(myIni<myFin):
163 myIni+=1
164 run_num[0]=myIni
165 rev_num[0]=rev[x]
166 tree.Fill()
167 '''
168 run_num_arry.append(run_num[0])
169 eklm_dead_arry.append(eklm_dead[0])
170 eklm_hot_arry.append(eklm_hot[0])
171 bklm_dead_arry.append(bklm_dead[0])
172 bklm_hot_arry.append(bklm_hot[0])
173
174 outfile = ROOT.TFile('validation.root', 'recreate')
175 tree.Write()
176 outfile.Close()
177
178 plot(run_num_arry, eklm_dead_arry, eklm_hot_arry, bklm_dead_arry, bklm_hot_arry)
Definition: plot.py:1