Belle II Software  release-06-01-15
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 = 42;
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, -1, -1 // 41
122  };
123 
124 
125  std::vector<std::vector<int>> mgr(N_config);
126  //0 nomask
127  mgr[ 1].push_back(7010); //MGR7-1U1
128  mgr[ 2].push_back(7010); mgr[ 2].push_back(7071);
129  mgr[ 3].push_back(7010); mgr[ 3].push_back(7071); mgr[ 3].push_back(8110);
130  mgr[ 4].push_back(7010); mgr[ 4].push_back(7071);
131  mgr[ 5].push_back(7010); mgr[ 5].push_back(7071); mgr[ 5].push_back(1000);
132  mgr[ 6].push_back(7010); mgr[ 6].push_back(7071);
133  mgr[ 7].push_back(7010); mgr[ 7].push_back(7071); mgr[ 7].push_back(2030);
134  mgr[ 8].push_back(7010); mgr[ 8].push_back(7071);
135  mgr[ 9].push_back(7010); mgr[ 9].push_back(7071); mgr[ 9].push_back(6061);
136  mgr[10].push_back(7010); mgr[10].push_back(7071);
137  //11 nomask
138  mgr[12].push_back(7010);
139  mgr[13].push_back(7010); mgr[13].push_back(7090); mgr[13].push_back(3010);
140  mgr[14].push_back(7010); mgr[14].push_back(7090); mgr[14].push_back(3010); mgr[14].push_back(4040);
141  mgr[15].push_back(7010); mgr[15].push_back(7090); mgr[15].push_back(3010);
142  mgr[16].push_back(7010); mgr[16].push_back(7090);
143  mgr[17].push_back(7010); mgr[17].push_back(7090); mgr[17].push_back(3010);
144  mgr[18].push_back(7010); mgr[18].push_back(7090);
145  //19 nomask
146  mgr[20].push_back(3010);
147  //21 nomask
148  mgr[22].push_back(3031);
149  //23 nomask
150  mgr[24].push_back(3010);
151  //25 nomask
152  mgr[26].push_back(3010);
153  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);
154  mgr[27].push_back(8060); mgr[27].push_back(8061); mgr[27].push_back(8070);
155  mgr[28].push_back(3010);
156  mgr[29].push_back(3010); mgr[29].push_back(3031);
157  mgr[30].push_back(3010);
158  mgr[31].push_back(3010); mgr[31].push_back(8060); mgr[31].push_back(8061);
159  mgr[32].push_back(3010);
160  mgr[33].push_back(3010); mgr[33].push_back(8060); mgr[33].push_back(8061);
161  mgr[34].push_back(3010);
162  mgr[35].push_back(3010); mgr[35].push_back(4001);
163  mgr[36].push_back(3010);
164  mgr[37].push_back(3010); mgr[37].push_back(4001); mgr[37].push_back(5080);
165  mgr[38].push_back(3010);
166  mgr[39].push_back(3010); mgr[39].push_back(5050);
167  mgr[40].push_back(3010); mgr[40].push_back(5050); mgr[40].push_back(8021);
168  mgr[41].push_back(3010); mgr[41].push_back(5050);
169 
170 
171  bool badch_map[N_config][9][8][384]; //sl layer ch
172  for (int i = 0; i < N_config; i++) {
173  for (unsigned int j = 0; j < nSuperLayers; j++) {
174  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
175  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
176  badch_map[i][j][k][l] = true;
177  }
178  }
179  }
180  }
181 
182  //mask L54 for all runs
183  for (int i = 0; i < N_config; i++) {
184  for (unsigned int j = 8; j < 9; j++) {
185  for (unsigned int k = 4; k < 5; k++) {
186  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
187  badch_map[i][j][k][l] = false;
188  }
189  }
190  }
191  }
192 
193  //mask merger
194  for (int i = 0; i < N_config; i++) {
195  for (int j = 0; j < mgr[i].size(); j++) {
196  int mgr_sl[96];
197  int mgr_layer[96];
198  int mgr_ch[96];
199  get_wire_mgr(mgr_sl, mgr_layer, mgr_ch, mgr[i][j]);
200  //std::cout << mgr[i][j] << std::endl;
201  for (int k = 0; k < 96; k++) {
202  //std::cout << mgr_sl[k] << " " << mgr_layer[k] << " " << mgr_ch[k] << std::endl;
203  badch_map[i][mgr_sl[k]][mgr_layer[k]][mgr_ch[k]] = false;
204  }
205  }
206  }
207 
209  db_dead.construct();
210  if (ONLINE == 0) {
211  for (int i = 0; i < N_config; i++) {
212  //std::cout << i << " " << run[i][0] << " " << run[i][1] << " " << run[i][2] << " " << run[i][3] << std::endl;
213  //for(int j=0;j<mgr[i].size();j++)std::cout << mgr[i][j] << std::endl;
214  IntervalOfValidity iov(run[i][0], run[i][1], run[i][2], run[i][3]);
215  for (unsigned int j = 0; j < nSuperLayers; j++) {
216  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
217  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
218  if (!badch_map[i][j][k][l]) {
219  //std::cout << j << " " << k << " " << l << std::endl;
220  db_dead->setdeadch(j, k, l, false);
221  } else {
222  db_dead->setdeadch(j, k, l, true);
223  }
224  }
225  }
226  }
227  db_dead.import(iov);
228  }
229  } else if (ONLINE == 1) {
230  for (int i = 0; i < 1; i++) { //no merger dead channel for run-independent MC. L54 is masked.
231  IntervalOfValidity iov(0, 0, -1, -1);
232  for (unsigned int j = 0; j < nSuperLayers; j++) {
233  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
234  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
235  if (!badch_map[i][j][k][l]) {
236  //std::cout << j << " " << k << " " << l << std::endl;
237  db_dead->setdeadch(j, k, l, false);
238  } else {
239  db_dead->setdeadch(j, k, l, true);
240  }
241  }
242  }
243  }
244  db_dead.import(iov);
245  }
246  }
247 }
248 
249 int main()
250 {
251 
252  setdeadch();
253 
254 }
255 
256 
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:75