Belle II Software development
trg-cdc-deadch-writedb.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/database/DBImportObjPtr.h>
10#include <framework/database/DBObjPtr.h>
11#include <framework/database/DBStore.h>
12#include <framework/datastore/StoreObjPtr.h>
13#include <framework/datastore/DataStore.h>
14#include <framework/dataobjects/EventMetaData.h>
15#include <framework/logging/LogSystem.h>
16#include <trg/cdc/dbobjects/CDCTriggerDeadch.h>
17#include <iostream>
18#include <fstream>
19//#include <TFile.h>
20//#include <TH1F.h>
21
22using namespace Belle2;
23
24#define ONLINE 0
25//#define ONLINE 1
26
27bool get_wire_mgr(int mask_sl[], int mask_layer[], int mask_ch[], int mgr)
28{
29 int mgr_sl = mgr / 1000;
30 int mgr_i = (mgr - mgr_sl * 1000) / 10;
31 int mgr_u = mgr % 10;
32 //std::cout << mgr_sl << " " << mgr_i << " " << mgr_u << std::endl;
33 //MGR0 0-4 :L3-7 lch0-159
34 //MGR1 0-4 :L8-12 lch0-159
35 //MGR2 0-5 :L14-18 lch0-191
36 //MGR3 0-6 :L20-24 lch0-223
37 //MGR4 0-7 :L26-30 lch0-255
38 //MGR5 0-8 :L32-36 lch0-287
39 //MGR6 0-9 :L38-42 lch0-319
40 //MGR7 0-10:L44-48 lch0-351
41 //MGR8 0-11:L50-54 lch0-383
42 //160*8 + 160*6 + 192*6 + 224*6 + 256*6 + 288*6 + 320*6 + 352*6 + 384*6 = 14336 = nSenseWires
43
44 //first inner layer
45 for (int i = 0; i < 32; i++) {
46 mask_sl[i] = mgr_sl;
47 mask_ch[i] = mgr_i * 32 + i;
48 mask_layer[i] = 0;
49 if (mgr_u == 1) mask_layer[i] += 3;
50 if (mgr_sl == 0) mask_layer[i] += 2;
51 }
52 //second inner layer
53 for (int i = 0; i < 32; i++) {
54 mask_sl[i + 32] = mgr_sl;
55 mask_ch[i + 32] = mgr_i * 32 + i;
56 mask_layer[i + 32] = 1;
57 if (mgr_u == 1) mask_layer[i + 32] += 3;
58 if (mgr_sl == 0) mask_layer[i + 32] += 2;
59 }
60 //third inner layer
61 for (int i = 0; i < 32; i++) {
62 mask_sl[i + 64] = mgr_sl;
63 mask_ch[i + 64] = mgr_i * 32 + i;
64 mask_layer[i + 64] = 2;
65 if (mgr_u == 1) mask_layer[i + 64] += 3;
66 if (mgr_sl == 0) mask_layer[i + 64] += 2;
67 }
68
69 return true;
70}
71
72
73void setdeadch()
74{
75 const static int MAX_N_LAYERS = 8;
76
77 const int N_config = 82;
78
79 const int run[N_config][4] = { //itnitial exp, initial run, end exp, end run
80 {0, 0, 7, 3585}, // 0
81 {7, 3586, 8, 1052}, // 1
82 {8, 1053, 8, 1108}, // 2
83 {8, 1109, 8, 1115}, // 3
84 {8, 1116, 8, 1832}, // 4
85 {8, 1833, 8, 1916}, // 5
86 {8, 1917, 8, 2528}, // 6
87 {8, 2529, 8, 2550}, // 7
88 {8, 2551, 8, 2578}, // 8
89 {8, 2579, 8, 2580}, // 9
90 {8, 2581, 9, -1}, // 10
91 {10, 0, 10, 5210}, // 11
92 {10, 5211, 11, -1}, // 12
93 {12, 0, 12, 1197}, // 13
94 {12, 1198, 12, 1294}, // 14
95 {12, 1295, 12, 2830}, // 15
96 {12, 2831, 12, 2846}, // 16
97 {12, 2847, 12, 2883}, // 17
98 {12, 2884, 12, 3212}, // 18
99 {12, 3213, 12, 3489}, // 19
100 {12, 3490, 12, 4214}, // 20
101 {12, 4215, 12, 4406}, // 21
102 {12, 4407, 12, 4419}, // 22
103 {12, 4420, 14, 1382}, // 23
104 {14, 1383, 16, 685}, // 24
105 {16, 686, 18, 90}, // 25
106 {18, 91, 20, 207}, // 26
107 {20, 208, 20, 208}, // 27
108 {20, 209, 20, 272}, // 28
109 {20, 273, 20, 273}, // 29
110 {20, 274, 22, 102}, // 30
111 {22, 103, 22, 121}, // 31
112 {22, 122, 22, 135}, // 32
113 {22, 136, 22, 334}, // 33
114 {22, 335, 22, 523}, // 34
115 {22, 524, 22, 568}, // 35
116 {22, 569, 22, 596}, // 36
117 {22, 597, 22, 604}, // 37
118 {22, 605, 23, -1}, // 38
119 {24, 0, 24, 915}, // 39
120 {24, 916, 24, 923}, // 40
121 {24, 924, 24, 1184}, // 41
122 {24, 1185, 24, 1190}, // 42
123 {24, 1191, 24, 1404}, // 43
124 {24, 1405, 24, 1406}, // 44
125 {24, 1407, 24, 1599}, // 45
126 {24, 1600, 24, 1613}, // 46
127 {24, 1614, 24, 1618}, // 47
128 {24, 1619, 24, 1844}, // 48
129 {24, 1845, 24, 1852}, // 49
130 {24, 1853, 24, 2058}, // 50
131 {24, 2059, 24, 2061}, // 51
132 {24, 2062, 24, 2062}, // 52
133 {24, 2063, 24, 2315}, // 53
134 {24, 2316, 25, 99}, // 54
135 {25, 100, 25, 100}, // 55
136 {25, 101, 25, 314}, // 56
137 {25, 315, 25, 352}, // 57
138 {25, 353, 26, 96}, // 58
139 {26, 97, 26, 137}, // 59
140 {26, 138, 26, 147}, // 60
141 {26, 148, 26, 364}, // 61
142 {26, 365, 26, 368}, // 62
143 {26, 369, 26, 523}, // 63
144 {26, 524, 26, 531}, // 64
145 {26, 532, 26, 545}, // 65
146 {26, 546, 26, 564}, // 66
147 {26, 565, 26, 615}, // 67
148 {26, 616, 26, 644}, // 68
149 {26, 645, 26, 646}, // 69
150 {26, 647, 26, 904}, // 70
151 {26, 905, 26, 1389}, // 71
152 {26, 1390, 26, 1430}, // 72
153 {26, 1431, 26, 1431}, // 73
154 {26, 1432, 30, 1569}, // 74
155 {30, 1570, 30, 1755}, // 75 2024/2/26
156 {30, 1756, 30, 1923}, // 76 2024/3/4
157 {30, 1924, 30, 2979}, // 77 2024/3/8
158 {30, 2980, 33, 85}, // 78 2024/4/11
159 {33, 86, 33, 1010}, // 79 2024/5/18
160 {33, 1011, 33, 1062}, // 80 2024/6/21
161 {33, 1063, -1, -1} // 81 2024/6/23
162 };
163
164
165 std::vector<std::vector<int>> mgr(N_config);
166 //0 nomask
167 mgr[ 1].push_back(7010); //MGR7-1U1
168 mgr[ 2].push_back(7010); mgr[ 2].push_back(7071);
169 mgr[ 3].push_back(7010); mgr[ 3].push_back(7071); mgr[ 3].push_back(8110);
170 mgr[ 4].push_back(7010); mgr[ 4].push_back(7071);
171 mgr[ 5].push_back(7010); mgr[ 5].push_back(7071); mgr[ 5].push_back(1000);
172 mgr[ 6].push_back(7010); mgr[ 6].push_back(7071);
173 mgr[ 7].push_back(7010); mgr[ 7].push_back(7071); mgr[ 7].push_back(2030);
174 mgr[ 8].push_back(7010); mgr[ 8].push_back(7071);
175 mgr[ 9].push_back(7010); mgr[ 9].push_back(7071); mgr[ 9].push_back(6061);
176 mgr[10].push_back(7010); mgr[10].push_back(7071);
177 //11 nomask
178 mgr[12].push_back(7010);
179 mgr[13].push_back(7010); mgr[13].push_back(7090); mgr[13].push_back(3010);
180 mgr[14].push_back(7010); mgr[14].push_back(7090); mgr[14].push_back(3010); mgr[14].push_back(4040);
181 mgr[15].push_back(7010); mgr[15].push_back(7090); mgr[15].push_back(3010);
182 mgr[16].push_back(7010); mgr[16].push_back(7090);
183 mgr[17].push_back(7010); mgr[17].push_back(7090); mgr[17].push_back(3010);
184 mgr[18].push_back(7010); mgr[18].push_back(7090);
185 //19 nomask
186 mgr[20].push_back(3010);
187 //21 nomask
188 mgr[22].push_back(3031);
189 //23 nomask
190 mgr[24].push_back(3010);
191 //25 nomask
192 mgr[26].push_back(3010);
193 mgr[27].push_back(3010); mgr[27].push_back(2040); mgr[27].push_back(11); mgr[27].push_back(4060); mgr[27].push_back(4061);
194 mgr[27].push_back(8060); mgr[27].push_back(8061); mgr[27].push_back(8070);
195 mgr[28].push_back(3010);
196 mgr[29].push_back(3010); mgr[29].push_back(3031);
197 mgr[30].push_back(3010);
198 mgr[31].push_back(3010); mgr[31].push_back(8060); mgr[31].push_back(8061);
199 mgr[32].push_back(3010);
200 mgr[33].push_back(3010); mgr[33].push_back(8060); mgr[33].push_back(8061);
201 mgr[34].push_back(3010);
202 mgr[35].push_back(3010); mgr[35].push_back(4001);
203 mgr[36].push_back(3010);
204 mgr[37].push_back(3010); mgr[37].push_back(4001); mgr[37].push_back(5080);
205 mgr[38].push_back(3010);
206 mgr[39].push_back(3010); mgr[39].push_back(5050);
207 mgr[40].push_back(3010); mgr[40].push_back(5050); mgr[40].push_back(8021);
208 mgr[41].push_back(3010); mgr[41].push_back(5050);
209 mgr[42].push_back(3010); mgr[42].push_back(5050); mgr[42].push_back(21);
210 mgr[43].push_back(3010); mgr[43].push_back(5050);
211 mgr[44].push_back(3010); mgr[44].push_back(5050); mgr[44].push_back(30);
212 mgr[45].push_back(3010); mgr[45].push_back(5050);
213 mgr[46].push_back(3010); mgr[46].push_back(5050); mgr[46].push_back(1030);
214 mgr[47].push_back(3010); mgr[47].push_back(5050); mgr[47].push_back(1030); mgr[47].push_back(1011);
215 mgr[48].push_back(3010); mgr[48].push_back(5050); mgr[48].push_back(1030);
216 mgr[49].push_back(3010); mgr[49].push_back(5050); mgr[49].push_back(1030); mgr[49].push_back(2021);
217 mgr[50].push_back(3010); mgr[50].push_back(5050); mgr[50].push_back(1030);
218 mgr[51].push_back(3010); mgr[51].push_back(5050); mgr[51].push_back(1030); mgr[51].push_back(8020); mgr[51].push_back(8060);
219 mgr[51].push_back(8061);
220 mgr[52].push_back(3010); mgr[52].push_back(5050); mgr[52].push_back(1030); mgr[52].push_back(8060); mgr[52].push_back(8061);
221 mgr[53].push_back(3010); mgr[53].push_back(5050); mgr[53].push_back(1030); mgr[53].push_back(8020); mgr[53].push_back(8060);
222 mgr[53].push_back(8061);
223 mgr[54].push_back(3010); mgr[54].push_back(5450); mgr[54].push_back(1030);
224 mgr[55].push_back(3010); mgr[55].push_back(5050); mgr[55].push_back(1030); mgr[55].push_back(8020); mgr[55].push_back(8060);
225 mgr[55].push_back(8061);
226 mgr[56].push_back(3010); mgr[56].push_back(5050); mgr[56].push_back(1030);
227 mgr[57].push_back(3010); mgr[57].push_back(5050); mgr[57].push_back(1030); mgr[57].push_back(1000);
228 mgr[58].push_back(3010); mgr[58].push_back(5050); mgr[58].push_back(1030);
229 mgr[59].push_back(3010); mgr[59].push_back(5050); mgr[59].push_back(1030); mgr[59].push_back(6051);
230 mgr[60].push_back(3010); mgr[60].push_back(5050); mgr[60].push_back(1030); mgr[60].push_back(40); mgr[60].push_back(6051);
231 mgr[60].push_back(6060);
232 mgr[61].push_back(3010); mgr[61].push_back(5050); mgr[61].push_back(1030);
233 mgr[62].push_back(3010); mgr[62].push_back(5050); mgr[62].push_back(1030); mgr[62].push_back(6080); mgr[62].push_back(6081);
234 mgr[63].push_back(3010); mgr[63].push_back(5050); mgr[63].push_back(1030);
235 mgr[64].push_back(3010); mgr[64].push_back(5050); mgr[64].push_back(1030); mgr[64].push_back(8041);
236 mgr[65].push_back(3010); mgr[65].push_back(5050); mgr[65].push_back(1030);
237 mgr[66].push_back(3010); mgr[66].push_back(5050); mgr[66].push_back(1030); mgr[66].push_back(1021); mgr[66].push_back(8041);
238 mgr[67].push_back(3010); mgr[67].push_back(5050); mgr[67].push_back(1030);
239 mgr[68].push_back(3010); mgr[68].push_back(5050); mgr[68].push_back(1030); mgr[68].push_back(30);
240 mgr[69].push_back(3010); mgr[69].push_back(30); mgr[69].push_back(7000); mgr[69].push_back(7001); mgr[69].push_back(7010);
241 mgr[69].push_back(7011);
242 mgr[70].push_back(3010); mgr[70].push_back(30);
243 mgr[71].push_back(30);
244 //72 nomask
245 mgr[73].push_back(1010); mgr[73].push_back(2000); mgr[73].push_back(2001);
246 //74 nomask
247 mgr[75].push_back(3060); mgr[75].push_back(4050); mgr[75].push_back(4051);
248 mgr[76].push_back(6070);
249 mgr[77].push_back(4001); mgr[77].push_back(4011);
250 mgr[78].push_back(2051);
251 mgr[79].push_back(3051);
252 mgr[80].push_back(6070);
253 //81 no mask
254
255
256 auto badch_map = new bool[N_config][9][8][384]; //sl layer ch
257 for (int i = 0; i < N_config; i++) {
258 for (unsigned int j = 0; j < c_nSuperLayers; j++) {
259 for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
260 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
261 badch_map[i][j][k][l] = true;
262 }
263 }
264 }
265 }
266
267 //mask L54 for all runs
268 for (int i = 0; i < N_config; i++) {
269 for (unsigned int j = 8; j < 9; j++) {
270 for (unsigned int k = 4; k < 5; k++) {
271 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
272 badch_map[i][j][k][l] = false;
273 }
274 }
275 }
276 }
277
278 //mask merger
279 for (int i = 0; i < N_config; i++) {
280 for (unsigned int j = 0; j < mgr[i].size(); j++) {
281 int mgr_sl[96];
282 int mgr_layer[96];
283 int mgr_ch[96];
284 get_wire_mgr(mgr_sl, mgr_layer, mgr_ch, mgr[i][j]);
285 //std::cout << mgr[i][j] << std::endl;
286 for (int k = 0; k < 96; k++) {
287 //std::cout << mgr_sl[k] << " " << mgr_layer[k] << " " << mgr_ch[k] << std::endl;
288 badch_map[i][mgr_sl[k]][mgr_layer[k]][mgr_ch[k]] = false;
289 }
290 }
291 }
292
294 db_dead.construct();
295 if (ONLINE == 0) {
296 for (int i = 0; i < N_config; i++) {
297 //std::cout << i << " " << run[i][0] << " " << run[i][1] << " " << run[i][2] << " " << run[i][3] << std::endl;
298 //for(int j=0;j<mgr[i].size();j++)std::cout << mgr[i][j] << std::endl;
299 IntervalOfValidity iov(run[i][0], run[i][1], run[i][2], run[i][3]);
300 for (unsigned int j = 0; j < c_nSuperLayers; j++) {
301 for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
302 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
303 if (!badch_map[i][j][k][l]) {
304 //std::cout << j << " " << k << " " << l << std::endl;
305 db_dead->setdeadch(j, k, l, false);
306 } else {
307 db_dead->setdeadch(j, k, l, true);
308 }
309 }
310 }
311 }
312 db_dead.import(iov);
313 }
314 } else if (ONLINE == 1) {
315 for (int i = 0; i < 1; i++) { //no merger dead channel for run-independent MC. L54 is masked.
316 IntervalOfValidity iov(0, 0, -1, -1);
317 for (unsigned int j = 0; j < c_nSuperLayers; j++) {
318 for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
319 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
320 if (!badch_map[i][j][k][l]) {
321 //std::cout << j << " " << k << " " << l << std::endl;
322 db_dead->setdeadch(j, k, l, false);
323 } else {
324 db_dead->setdeadch(j, k, l, true);
325 }
326 }
327 }
328 }
329 db_dead.import(iov);
330 }
331 }
332 delete[] badch_map;
333}
334
335int main()
336{
337
338 setdeadch();
339
340}
341
342
bool import(const IntervalOfValidity &iov)
Import the object to database.
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
A class that describes the interval of experiments/runs for which an object in the database is valid.
Abstract base class for different kinds of events.