Belle II Software  release-06-00-14
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 = 27;
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, -1, -1 // 26
107  };
108 
109 
110  std::vector<std::vector<int>> mgr(N_config);
111  //0 nomask
112  mgr[ 1].push_back(7010); //MGR7-1U1
113  mgr[ 2].push_back(7010); mgr[ 2].push_back(7071);
114  mgr[ 3].push_back(7010); mgr[ 3].push_back(7071); mgr[ 3].push_back(8110);
115  mgr[ 4].push_back(7010); mgr[ 4].push_back(7071);
116  mgr[ 5].push_back(7010); mgr[ 5].push_back(7071); mgr[ 5].push_back(1000);
117  mgr[ 6].push_back(7010); mgr[ 6].push_back(7071);
118  mgr[ 7].push_back(7010); mgr[ 7].push_back(7071); mgr[ 7].push_back(2030);
119  mgr[ 8].push_back(7010); mgr[ 8].push_back(7071);
120  mgr[ 9].push_back(7010); mgr[ 9].push_back(7071); mgr[ 9].push_back(6061);
121  mgr[10].push_back(7010); mgr[10].push_back(7071);
122  //11 nomask
123  mgr[12].push_back(7010);
124  mgr[13].push_back(7010); mgr[13].push_back(7090); mgr[13].push_back(3010);
125  mgr[14].push_back(7010); mgr[14].push_back(7090); mgr[14].push_back(3010); mgr[14].push_back(4040);
126  mgr[15].push_back(7010); mgr[15].push_back(7090); mgr[15].push_back(3010);
127  mgr[16].push_back(7010); mgr[16].push_back(7090);
128  mgr[17].push_back(7010); mgr[17].push_back(7090); mgr[17].push_back(3010);
129  mgr[18].push_back(7010); mgr[18].push_back(7090);
130  //19 nomask
131  mgr[20].push_back(3010);
132  //21 nomask
133  mgr[22].push_back(3031);
134  //23 nomask
135  mgr[24].push_back(3010);
136  //25 nomask
137  mgr[26].push_back(3010);
138 
139  bool badch_map[N_config][9][8][384]; //sl layer ch
140  for (int i = 0; i < N_config; i++) {
141  for (unsigned int j = 0; j < nSuperLayers; j++) {
142  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
143  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
144  badch_map[i][j][k][l] = true;
145  }
146  }
147  }
148  }
149 
150  //mask L54 for all runs
151  for (int i = 0; i < N_config; i++) {
152  for (unsigned int j = 8; j < 9; j++) {
153  for (unsigned int k = 4; k < 5; k++) {
154  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
155  badch_map[i][j][k][l] = false;
156  }
157  }
158  }
159  }
160 
161  //mask merger
162  for (int i = 0; i < N_config; i++) {
163  for (int j = 0; j < mgr[i].size(); j++) {
164  int mgr_sl[96];
165  int mgr_layer[96];
166  int mgr_ch[96];
167  get_wire_mgr(mgr_sl, mgr_layer, mgr_ch, mgr[i][j]);
168  //std::cout << mgr[i][j] << std::endl;
169  for (int k = 0; k < 96; k++) {
170  //std::cout << mgr_sl[k] << " " << mgr_layer[k] << " " << mgr_ch[k] << std::endl;
171  badch_map[i][mgr_sl[k]][mgr_layer[k]][mgr_ch[k]] = false;
172  }
173  }
174  }
175 
177  db_dead.construct();
178  if (ONLINE == 0) {
179  for (int i = 0; i < N_config; i++) {
180  //std::cout << i << " " << run[i][0] << " " << run[i][1] << " " << run[i][2] << " " << run[i][3] << std::endl;
181  //for(int j=0;j<mgr[i].size();j++)std::cout << mgr[i][j] << std::endl;
182  IntervalOfValidity iov(run[i][0], run[i][1], run[i][2], run[i][3]);
183  for (unsigned int j = 0; j < nSuperLayers; j++) {
184  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
185  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
186  if (!badch_map[i][j][k][l]) {
187  //std::cout << j << " " << k << " " << l << std::endl;
188  db_dead->setdeadch(j, k, l, false);
189  }
190  }
191  }
192  }
193  db_dead.import(iov);
194  }
195  } else if (ONLINE == 1) {
196  for (int i = 0; i < 1; i++) { //no merger dead channel for run-independent MC. L54 is masked.
197  IntervalOfValidity iov(0, 0, -1, -1);
198  for (unsigned int j = 0; j < nSuperLayers; j++) {
199  for (unsigned int k = 0; k < MAX_N_LAYERS; k++) {
200  for (unsigned int l = 0; l < MAX_N_SCELLS; l++) {
201  if (!badch_map[i][j][k][l]) {
202  //std::cout << j << " " << k << " " << l << std::endl;
203  db_dead->setdeadch(j, k, l, false);
204  }
205  }
206  }
207  }
208  db_dead.import(iov);
209  }
210  }
211 }
212 
213 int main()
214 {
215 
216  setdeadch();
217 
218 }
219 
220 
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