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 = 96;
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, 34, -1}, // 81 2024/6/23
162 {35, 0, 35, 307}, // 82 2024/10/2
163 {35, 308, 35, 344}, // 83 2024/10/11
164 {35, 345, 35, 414}, // 84 2024/10/13
165 {35, 415, 35, 777}, // 85 2024/10/16
166 {35, 778, 35, 1073}, // 86 2024/10/29
167 {35, 1074, 35, 1178}, // 87 2024/11/07
168 {35, 1179, 35, 1239}, // 88 2024/11/09
169 {35, 1240, 35, 1279}, // 89 2024/11/12
170 {35, 1280, 35, 1458}, // 90 2024/11/13
171 {35, 1459, 35, 1782}, // 91 2024/11/20
172 {35, 1783, 35, 1970}, // 92 2024/12/02
173 {35, 1971, 35, 2246}, // 93 2024/12/09
174 {35, 2247, 35, 2478}, // 94 2024/12/16
175 {35, 2479, -1, -1} // 95 2024/12/20
176 };
177
178
179 std::vector<std::vector<int>> mgr(N_config);
180 //0 nomask
181 mgr[ 1].push_back(7010); //MGR7-1U1
182 mgr[ 2].push_back(7010); mgr[ 2].push_back(7071);
183 mgr[ 3].push_back(7010); mgr[ 3].push_back(7071); mgr[ 3].push_back(8110);
184 mgr[ 4].push_back(7010); mgr[ 4].push_back(7071);
185 mgr[ 5].push_back(7010); mgr[ 5].push_back(7071); mgr[ 5].push_back(1000);
186 mgr[ 6].push_back(7010); mgr[ 6].push_back(7071);
187 mgr[ 7].push_back(7010); mgr[ 7].push_back(7071); mgr[ 7].push_back(2030);
188 mgr[ 8].push_back(7010); mgr[ 8].push_back(7071);
189 mgr[ 9].push_back(7010); mgr[ 9].push_back(7071); mgr[ 9].push_back(6061);
190 mgr[10].push_back(7010); mgr[10].push_back(7071);
191 //11 nomask
192 mgr[12].push_back(7010);
193 mgr[13].push_back(7010); mgr[13].push_back(7090); mgr[13].push_back(3010);
194 mgr[14].push_back(7010); mgr[14].push_back(7090); mgr[14].push_back(3010); mgr[14].push_back(4040);
195 mgr[15].push_back(7010); mgr[15].push_back(7090); mgr[15].push_back(3010);
196 mgr[16].push_back(7010); mgr[16].push_back(7090);
197 mgr[17].push_back(7010); mgr[17].push_back(7090); mgr[17].push_back(3010);
198 mgr[18].push_back(7010); mgr[18].push_back(7090);
199 //19 nomask
200 mgr[20].push_back(3010);
201 //21 nomask
202 mgr[22].push_back(3031);
203 //23 nomask
204 mgr[24].push_back(3010);
205 //25 nomask
206 mgr[26].push_back(3010);
207 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);
208 mgr[27].push_back(8060); mgr[27].push_back(8061); mgr[27].push_back(8070);
209 mgr[28].push_back(3010);
210 mgr[29].push_back(3010); mgr[29].push_back(3031);
211 mgr[30].push_back(3010);
212 mgr[31].push_back(3010); mgr[31].push_back(8060); mgr[31].push_back(8061);
213 mgr[32].push_back(3010);
214 mgr[33].push_back(3010); mgr[33].push_back(8060); mgr[33].push_back(8061);
215 mgr[34].push_back(3010);
216 mgr[35].push_back(3010); mgr[35].push_back(4001);
217 mgr[36].push_back(3010);
218 mgr[37].push_back(3010); mgr[37].push_back(4001); mgr[37].push_back(5080);
219 mgr[38].push_back(3010);
220 mgr[39].push_back(3010); mgr[39].push_back(5050);
221 mgr[40].push_back(3010); mgr[40].push_back(5050); mgr[40].push_back(8021);
222 mgr[41].push_back(3010); mgr[41].push_back(5050);
223 mgr[42].push_back(3010); mgr[42].push_back(5050); mgr[42].push_back(21);
224 mgr[43].push_back(3010); mgr[43].push_back(5050);
225 mgr[44].push_back(3010); mgr[44].push_back(5050); mgr[44].push_back(30);
226 mgr[45].push_back(3010); mgr[45].push_back(5050);
227 mgr[46].push_back(3010); mgr[46].push_back(5050); mgr[46].push_back(1030);
228 mgr[47].push_back(3010); mgr[47].push_back(5050); mgr[47].push_back(1030); mgr[47].push_back(1011);
229 mgr[48].push_back(3010); mgr[48].push_back(5050); mgr[48].push_back(1030);
230 mgr[49].push_back(3010); mgr[49].push_back(5050); mgr[49].push_back(1030); mgr[49].push_back(2021);
231 mgr[50].push_back(3010); mgr[50].push_back(5050); mgr[50].push_back(1030);
232 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);
233 mgr[51].push_back(8061);
234 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);
235 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);
236 mgr[53].push_back(8061);
237 mgr[54].push_back(3010); mgr[54].push_back(5450); mgr[54].push_back(1030);
238 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);
239 mgr[55].push_back(8061);
240 mgr[56].push_back(3010); mgr[56].push_back(5050); mgr[56].push_back(1030);
241 mgr[57].push_back(3010); mgr[57].push_back(5050); mgr[57].push_back(1030); mgr[57].push_back(1000);
242 mgr[58].push_back(3010); mgr[58].push_back(5050); mgr[58].push_back(1030);
243 mgr[59].push_back(3010); mgr[59].push_back(5050); mgr[59].push_back(1030); mgr[59].push_back(6051);
244 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);
245 mgr[60].push_back(6060);
246 mgr[61].push_back(3010); mgr[61].push_back(5050); mgr[61].push_back(1030);
247 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);
248 mgr[63].push_back(3010); mgr[63].push_back(5050); mgr[63].push_back(1030);
249 mgr[64].push_back(3010); mgr[64].push_back(5050); mgr[64].push_back(1030); mgr[64].push_back(8041);
250 mgr[65].push_back(3010); mgr[65].push_back(5050); mgr[65].push_back(1030);
251 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);
252 mgr[67].push_back(3010); mgr[67].push_back(5050); mgr[67].push_back(1030);
253 mgr[68].push_back(3010); mgr[68].push_back(5050); mgr[68].push_back(1030); mgr[68].push_back(30);
254 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);
255 mgr[69].push_back(7011);
256 mgr[70].push_back(3010); mgr[70].push_back(30);
257 mgr[71].push_back(30);
258 //72 nomask
259 mgr[73].push_back(1010); mgr[73].push_back(2000); mgr[73].push_back(2001);
260 //74 nomask
261 mgr[75].push_back(3060); mgr[75].push_back(4050); mgr[75].push_back(4051);
262 mgr[76].push_back(6070);
263 mgr[77].push_back(4001); mgr[77].push_back(4011);
264 mgr[78].push_back(2051);
265 mgr[79].push_back(3051);
266 mgr[80].push_back(6070);
267 //81 no mask
268 mgr[82].push_back(2001); mgr[82].push_back(4001); mgr[82].push_back(5080);
269 mgr[83].push_back(4010);
270 mgr[84].push_back(4010);
271 mgr[85].push_back(4010); mgr[85].push_back(3050);
272 mgr[86].push_back(4010); mgr[86].push_back(5081);
273 mgr[87].push_back(4010); mgr[87].push_back(3050);
274 mgr[88].push_back(4010); mgr[88].push_back(4020); mgr[88].push_back(4021);
275 //89 no mask
276 mgr[90].push_back(4011); mgr[90].push_back(5001); mgr[90].push_back(5060); mgr[90].push_back(5081);
277 mgr[91].push_back(4020); mgr[91].push_back(4021); mgr[91].push_back(5081);
278 mgr[92].push_back(4020); mgr[92].push_back(4021);
279 mgr[93].push_back(4020); mgr[93].push_back(4021); mgr[93].push_back(4010); mgr[93].push_back(4011);
280 mgr[94].push_back(4020); mgr[94].push_back(4021); mgr[94].push_back(4010); mgr[94].push_back(4011);
281 mgr[95].push_back(4020); mgr[95].push_back(4021); mgr[95].push_back(4010); mgr[95].push_back(4011);
282
283 auto badch_map = new bool[N_config][9][8][384]; //sl layer ch
284 for (int i = 0; i < N_config; i++) {
285 for (unsigned int j = 0; j < c_nSuperLayers; j++) {
286 for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
287 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
288 badch_map[i][j][k][l] = true;
289 }
290 }
291 }
292 }
293
294 //mask L54 for all runs
295 for (int i = 0; i < N_config; i++) {
296 for (unsigned int j = 8; j < 9; j++) {
297 for (unsigned int k = 4; k < 5; k++) {
298 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
299 badch_map[i][j][k][l] = false;
300 }
301 }
302 }
303 }
304
305 //mask merger
306 for (int i = 0; i < N_config; i++) {
307 for (unsigned int j = 0; j < mgr[i].size(); j++) {
308 int mgr_sl[96];
309 int mgr_layer[96];
310 int mgr_ch[96];
311 get_wire_mgr(mgr_sl, mgr_layer, mgr_ch, mgr[i][j]);
312 //std::cout << mgr[i][j] << std::endl;
313 for (int k = 0; k < 96; k++) {
314 //std::cout << mgr_sl[k] << " " << mgr_layer[k] << " " << mgr_ch[k] << std::endl;
315 badch_map[i][mgr_sl[k]][mgr_layer[k]][mgr_ch[k]] = false;
316 }
317 }
318 }
319
321 db_dead.construct();
322 if (ONLINE == 0) {
323 for (int i = 0; i < N_config; i++) {
324 //std::cout << i << " " << run[i][0] << " " << run[i][1] << " " << run[i][2] << " " << run[i][3] << std::endl;
325 //for(int j=0;j<mgr[i].size();j++)std::cout << mgr[i][j] << std::endl;
326 IntervalOfValidity iov(run[i][0], run[i][1], run[i][2], run[i][3]);
327 for (unsigned int j = 0; j < c_nSuperLayers; j++) {
328 for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
329 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
330 if (!badch_map[i][j][k][l]) {
331 //std::cout << j << " " << k << " " << l << std::endl;
332 db_dead->setdeadch(j, k, l, false);
333 } else {
334 db_dead->setdeadch(j, k, l, true);
335 }
336 }
337 }
338 }
339 db_dead.import(iov);
340 }
341 } else if (ONLINE == 1) {
342 for (int i = 0; i < 1; i++) { //no merger dead channel for run-independent MC. L54 is masked.
343 IntervalOfValidity iov(0, 0, -1, -1);
344 for (unsigned int j = 0; j < c_nSuperLayers; j++) {
345 for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
346 for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
347 if (!badch_map[i][j][k][l]) {
348 //std::cout << j << " " << k << " " << l << std::endl;
349 db_dead->setdeadch(j, k, l, false);
350 } else {
351 db_dead->setdeadch(j, k, l, true);
352 }
353 }
354 }
355 }
356 db_dead.import(iov);
357 }
358 }
359 delete[] badch_map;
360}
361
362int main()
363{
364
365 setdeadch();
366
367}
368
369
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.