Belle II Software  release-08-00-10
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 
22 using namespace Belle2;
23 
24 #define ONLINE 0
25 //#define ONLINE 1
26 
27 bool 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 
73 void setdeadch()
74 {
75  const static int MAX_N_LAYERS = 8;
76 
77  const int N_config = 75;
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, -1, -1} // 74
155  };
156 
157 
158  std::vector<std::vector<int>> mgr(N_config);
159  //0 nomask
160  mgr[ 1].push_back(7010); //MGR7-1U1
161  mgr[ 2].push_back(7010); mgr[ 2].push_back(7071);
162  mgr[ 3].push_back(7010); mgr[ 3].push_back(7071); mgr[ 3].push_back(8110);
163  mgr[ 4].push_back(7010); mgr[ 4].push_back(7071);
164  mgr[ 5].push_back(7010); mgr[ 5].push_back(7071); mgr[ 5].push_back(1000);
165  mgr[ 6].push_back(7010); mgr[ 6].push_back(7071);
166  mgr[ 7].push_back(7010); mgr[ 7].push_back(7071); mgr[ 7].push_back(2030);
167  mgr[ 8].push_back(7010); mgr[ 8].push_back(7071);
168  mgr[ 9].push_back(7010); mgr[ 9].push_back(7071); mgr[ 9].push_back(6061);
169  mgr[10].push_back(7010); mgr[10].push_back(7071);
170  //11 nomask
171  mgr[12].push_back(7010);
172  mgr[13].push_back(7010); mgr[13].push_back(7090); mgr[13].push_back(3010);
173  mgr[14].push_back(7010); mgr[14].push_back(7090); mgr[14].push_back(3010); mgr[14].push_back(4040);
174  mgr[15].push_back(7010); mgr[15].push_back(7090); mgr[15].push_back(3010);
175  mgr[16].push_back(7010); mgr[16].push_back(7090);
176  mgr[17].push_back(7010); mgr[17].push_back(7090); mgr[17].push_back(3010);
177  mgr[18].push_back(7010); mgr[18].push_back(7090);
178  //19 nomask
179  mgr[20].push_back(3010);
180  //21 nomask
181  mgr[22].push_back(3031);
182  //23 nomask
183  mgr[24].push_back(3010);
184  //25 nomask
185  mgr[26].push_back(3010);
186  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);
187  mgr[27].push_back(8060); mgr[27].push_back(8061); mgr[27].push_back(8070);
188  mgr[28].push_back(3010);
189  mgr[29].push_back(3010); mgr[29].push_back(3031);
190  mgr[30].push_back(3010);
191  mgr[31].push_back(3010); mgr[31].push_back(8060); mgr[31].push_back(8061);
192  mgr[32].push_back(3010);
193  mgr[33].push_back(3010); mgr[33].push_back(8060); mgr[33].push_back(8061);
194  mgr[34].push_back(3010);
195  mgr[35].push_back(3010); mgr[35].push_back(4001);
196  mgr[36].push_back(3010);
197  mgr[37].push_back(3010); mgr[37].push_back(4001); mgr[37].push_back(5080);
198  mgr[38].push_back(3010);
199  mgr[39].push_back(3010); mgr[39].push_back(5050);
200  mgr[40].push_back(3010); mgr[40].push_back(5050); mgr[40].push_back(8021);
201  mgr[41].push_back(3010); mgr[41].push_back(5050);
202  mgr[42].push_back(3010); mgr[42].push_back(5050); mgr[42].push_back(21);
203  mgr[43].push_back(3010); mgr[43].push_back(5050);
204  mgr[44].push_back(3010); mgr[44].push_back(5050); mgr[44].push_back(30);
205  mgr[45].push_back(3010); mgr[45].push_back(5050);
206  mgr[46].push_back(3010); mgr[46].push_back(5050); mgr[46].push_back(1030);
207  mgr[47].push_back(3010); mgr[47].push_back(5050); mgr[47].push_back(1030); mgr[47].push_back(1011);
208  mgr[48].push_back(3010); mgr[48].push_back(5050); mgr[48].push_back(1030);
209  mgr[49].push_back(3010); mgr[49].push_back(5050); mgr[49].push_back(1030); mgr[49].push_back(2021);
210  mgr[50].push_back(3010); mgr[50].push_back(5050); mgr[50].push_back(1030);
211  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);
212  mgr[51].push_back(8061);
213  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);
214  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);
215  mgr[53].push_back(8061);
216  mgr[54].push_back(3010); mgr[54].push_back(5450); mgr[54].push_back(1030);
217  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);
218  mgr[55].push_back(8061);
219  mgr[56].push_back(3010); mgr[56].push_back(5050); mgr[56].push_back(1030);
220  mgr[57].push_back(3010); mgr[57].push_back(5050); mgr[57].push_back(1030); mgr[57].push_back(1000);
221  mgr[58].push_back(3010); mgr[58].push_back(5050); mgr[58].push_back(1030);
222  mgr[59].push_back(3010); mgr[59].push_back(5050); mgr[59].push_back(1030); mgr[59].push_back(6051);
223  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);
224  mgr[60].push_back(6060);
225  mgr[61].push_back(3010); mgr[61].push_back(5050); mgr[61].push_back(1030);
226  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);
227  mgr[63].push_back(3010); mgr[63].push_back(5050); mgr[63].push_back(1030);
228  mgr[64].push_back(3010); mgr[64].push_back(5050); mgr[64].push_back(1030); mgr[64].push_back(8041);
229  mgr[65].push_back(3010); mgr[65].push_back(5050); mgr[65].push_back(1030);
230  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);
231  mgr[67].push_back(3010); mgr[67].push_back(5050); mgr[67].push_back(1030);
232  mgr[68].push_back(3010); mgr[68].push_back(5050); mgr[68].push_back(1030); mgr[68].push_back(30);
233  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);
234  mgr[69].push_back(7011);
235  mgr[70].push_back(3010); mgr[70].push_back(30);
236  mgr[71].push_back(30);
237  //72 nomask
238  mgr[73].push_back(1010); mgr[73].push_back(2000); mgr[73].push_back(2001);
239  //74 nomask
240 
241 
242  auto badch_map = new bool[N_config][9][8][384]; //sl layer ch
243  for (int i = 0; i < N_config; i++) {
244  for (unsigned int j = 0; j < c_nSuperLayers; j++) {
245  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
246  for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
247  badch_map[i][j][k][l] = true;
248  }
249  }
250  }
251  }
252 
253  //mask L54 for all runs
254  for (int i = 0; i < N_config; i++) {
255  for (unsigned int j = 8; j < 9; j++) {
256  for (unsigned int k = 4; k < 5; k++) {
257  for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
258  badch_map[i][j][k][l] = false;
259  }
260  }
261  }
262  }
263 
264  //mask merger
265  for (int i = 0; i < N_config; i++) {
266  for (unsigned int j = 0; j < mgr[i].size(); j++) {
267  int mgr_sl[96];
268  int mgr_layer[96];
269  int mgr_ch[96];
270  get_wire_mgr(mgr_sl, mgr_layer, mgr_ch, mgr[i][j]);
271  //std::cout << mgr[i][j] << std::endl;
272  for (int k = 0; k < 96; k++) {
273  //std::cout << mgr_sl[k] << " " << mgr_layer[k] << " " << mgr_ch[k] << std::endl;
274  badch_map[i][mgr_sl[k]][mgr_layer[k]][mgr_ch[k]] = false;
275  }
276  }
277  }
278 
280  db_dead.construct();
281  if (ONLINE == 0) {
282  for (int i = 0; i < N_config; i++) {
283  //std::cout << i << " " << run[i][0] << " " << run[i][1] << " " << run[i][2] << " " << run[i][3] << std::endl;
284  //for(int j=0;j<mgr[i].size();j++)std::cout << mgr[i][j] << std::endl;
285  IntervalOfValidity iov(run[i][0], run[i][1], run[i][2], run[i][3]);
286  for (unsigned int j = 0; j < c_nSuperLayers; j++) {
287  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
288  for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
289  if (!badch_map[i][j][k][l]) {
290  //std::cout << j << " " << k << " " << l << std::endl;
291  db_dead->setdeadch(j, k, l, false);
292  } else {
293  db_dead->setdeadch(j, k, l, true);
294  }
295  }
296  }
297  }
298  db_dead.import(iov);
299  }
300  } else if (ONLINE == 1) {
301  for (int i = 0; i < 1; i++) { //no merger dead channel for run-independent MC. L54 is masked.
302  IntervalOfValidity iov(0, 0, -1, -1);
303  for (unsigned int j = 0; j < c_nSuperLayers; j++) {
304  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
305  for (unsigned int l = 0; l < c_maxNDriftCells; l++) {
306  if (!badch_map[i][j][k][l]) {
307  //std::cout << j << " " << k << " " << l << std::endl;
308  db_dead->setdeadch(j, k, l, false);
309  } else {
310  db_dead->setdeadch(j, k, l, true);
311  }
312  }
313  }
314  }
315  db_dead.import(iov);
316  }
317  }
318  delete[] badch_map;
319 }
320 
321 int main()
322 {
323 
324  setdeadch();
325 
326 }
327 
328 
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:36
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.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91