ProtoduneChannelHelper.cxx
Go to the documentation of this file.
1 // ProtoduneChannelHelper.cxx
2 
4 #include <iostream>
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 #include <sstream>
9 
10 using std::string;
11 using std::cout;
12 using std::endl;
13 using std::ostringstream;
14 
17 
18 //**********************************************************************
19 
21  return chan/2560;
22 }
23 
24 //**********************************************************************
25 
27  static std::vector<Index> apas = {3, 5, 2, 6, 1, 4};
28  Index itps = tpcSet(chan, false);
29  return itps < apas.size() ? apas[itps] : 0;
30 }
31 
32 //**********************************************************************
33 
35  Index chanOn = isOff ? onlineChannel(chan) : chan;
36  return (chanOn%2560)/128 + 1;
37 }
38 
39 //**********************************************************************
40 
42  Index chanOn = isOff ? onlineChannel(chan) : chan;
43  return (chanOn%128)/16 + 1;
44 }
45 
46 //**********************************************************************
47 
49  Index chanOn = isOff ? onlineChannel(chan) : chan;
50  return chanOn%16;
51 }
52 
53 //**********************************************************************
54 
56  const string myname = "ProtoduneChannelHelper::get: ";
57  static bool init = false;
58  static Index nwirPlane[4] = {800, 800, 480, 480};
59  static Index nwirFemb[4] = {40, 40, 48, 48};
60  static Index uch[40];
61  static Index vch[40];
62  static Index zch[48];
63  if ( ! init ) {
64  if ( dbg ) cout << myname << "Initializing FEMB channel map." << endl;
65  Index val = 0;
66  // Create the maps from the to CCW wire numbers for each plane to
67  // the FEMB channel number.
68  // We follow DUNE DocDB 4064 except numberings start from 0 instead of 1.
69  // ASIC 0
70  uch[18] = val++;
71  uch[16] = val++;
72  uch[14] = val++;
73  uch[12] = val++;
74  uch[10] = val++;
75  vch[18] = val++;
76  vch[16] = val++;
77  vch[14] = val++;
78  vch[12] = val++;
79  vch[10] = val++;
80  zch[22] = val++;
81  zch[20] = val++;
82  zch[18] = val++;
83  zch[16] = val++;
84  zch[14] = val++;
85  zch[12] = val++;
86  // ASIC 1
87  uch[ 8] = val++;
88  uch[ 6] = val++;
89  uch[ 4] = val++;
90  uch[ 2] = val++;
91  uch[ 0] = val++;
92  vch[ 8] = val++;
93  vch[ 6] = val++;
94  vch[ 4] = val++;
95  vch[ 2] = val++;
96  vch[ 0] = val++;
97  zch[10] = val++;
98  zch[ 8] = val++;
99  zch[ 6] = val++;
100  zch[ 4] = val++;
101  zch[ 2] = val++;
102  zch[ 0] = val++;
103  // ASIC 2
104  zch[13] = val++;
105  zch[15] = val++;
106  zch[17] = val++;
107  zch[19] = val++;
108  zch[21] = val++;
109  zch[23] = val++;
110  vch[11] = val++;
111  vch[13] = val++;
112  vch[15] = val++;
113  vch[17] = val++;
114  vch[19] = val++;
115  uch[11] = val++;
116  uch[13] = val++;
117  uch[15] = val++;
118  uch[17] = val++;
119  uch[19] = val++;
120  // ASIC 3
121  zch[ 1] = val++;
122  zch[ 3] = val++;
123  zch[ 5] = val++;
124  zch[ 7] = val++;
125  zch[ 9] = val++;
126  zch[11] = val++;
127  vch[ 1] = val++;
128  vch[ 3] = val++;
129  vch[ 5] = val++;
130  vch[ 7] = val++;
131  vch[ 9] = val++;
132  uch[ 1] = val++;
133  uch[ 3] = val++;
134  uch[ 5] = val++;
135  uch[ 7] = val++;
136  uch[ 9] = val++;
137  // ASIC 4
138  uch[28] = val++;
139  uch[26] = val++;
140  uch[24] = val++;
141  uch[22] = val++;
142  uch[20] = val++;
143  vch[28] = val++;
144  vch[26] = val++;
145  vch[24] = val++;
146  vch[22] = val++;
147  vch[20] = val++;
148  zch[34] = val++;
149  zch[32] = val++;
150  zch[30] = val++;
151  zch[28] = val++;
152  zch[26] = val++;
153  zch[24] = val++;
154  // ASIC 5
155  uch[38] = val++;
156  uch[36] = val++;
157  uch[34] = val++;
158  uch[32] = val++;
159  uch[30] = val++;
160  vch[38] = val++;
161  vch[36] = val++;
162  vch[34] = val++;
163  vch[32] = val++;
164  vch[30] = val++;
165  zch[46] = val++;
166  zch[44] = val++;
167  zch[42] = val++;
168  zch[40] = val++;
169  zch[38] = val++;
170  zch[36] = val++;
171  // ASIC 6
172  zch[25] = val++;
173  zch[27] = val++;
174  zch[29] = val++;
175  zch[31] = val++;
176  zch[33] = val++;
177  zch[35] = val++;
178  vch[21] = val++;
179  vch[23] = val++;
180  vch[25] = val++;
181  vch[27] = val++;
182  vch[29] = val++;
183  uch[21] = val++;
184  uch[23] = val++;
185  uch[25] = val++;
186  uch[27] = val++;
187  uch[29] = val++;
188  // ASIC 7
189  zch[37] = val++;
190  zch[39] = val++;
191  zch[41] = val++;
192  zch[43] = val++;
193  zch[45] = val++;
194  zch[47] = val++;
195  vch[31] = val++;
196  vch[33] = val++;
197  vch[35] = val++;
198  vch[37] = val++;
199  vch[39] = val++;
200  uch[31] = val++;
201  uch[33] = val++;
202  uch[35] = val++;
203  uch[37] = val++;
204  uch[39] = val++;
205  if ( val != 128 ) abort();
206  }
207  if ( chanOff >= 15360 ) {
208  if ( dbg ) cout << myname << "Invalid offline channel: " << chanOff << endl;
209  return badIndex();
210  }
211  // Get the TPC set.
212  Index itps = chanOff/2560;
213  // Get the channel in the apa.
214  Index ichApa = chanOff%2560;
215  // Get the plane (ipla) and wire number in the plane (ichPla).
216  Index ipla = 0;
217  Index ichPla = ichApa;
218  while ( ichPla >= nwirPlane[ipla] ) {
219  ichPla -= nwirPlane[ipla];
220  ++ipla;
221  }
222  // Get the FEMB # in the detector ifmbDet.
223  Index ifmbApa = ichPla/nwirFemb[ipla];
224  if ( ipla == 0 ) {
225  ifmbApa = (ifmbApa + 10) % 20;
226  } else if ( ipla == 1 ) {
227  ifmbApa = 19 - ifmbApa;
228  } else if ( ipla == 2 ) {
229  ifmbApa = 19 - ifmbApa;
230  }
231  // Get the FEMB number in protoDune (0-119)
232  Index ifmbDet = 20*itps + ifmbApa;
233  // Get the wire number in the FEMB.
234  Index iwchFemb = ichPla % nwirFemb[ipla]; // Wire number in the plane and FEMB.
235  if ( iwchFemb > nwirFemb[ipla] ) {
236  if ( dbg > 1 ) cout << myname << "ERROR: Invalid FEMB channel: " << chanOff
237  << " --> " << iwchFemb << endl;
238  return badIndex();
239  }
240  // Note the wire numbers in the channel-to-wire tables increase CCW while
241  // offline is CW for u and z2 and CCW for v and z1.
242  // Flip the wire numbers for the former.
243  if ( ipla == 0 || ipla == 3 ) iwchFemb = nwirFemb[ipla] - 1 - iwchFemb;
244  // Find the FEMB channel for the wire.
245  Index ichFemb = ipla == 0 ? uch[iwchFemb] :
246  ipla == 1 ? vch[iwchFemb] :
247  zch[iwchFemb];
248  // Build offline index.
249  Index ichOn = 128*ifmbDet + ichFemb;
250  return ichOn;
251 }
252 
253 //**********************************************************************
254 
256 : m_isOff(isOff) { }
257 
258 //**********************************************************************
259 
261  ostringstream ssout;
262  Index iapa = apa(icha);
263  Index ifmb = femb(icha);
264  Index iasc = asic(icha);
265  Index iach = asicChannel(icha);
266  ssout << iapa << (ifmb < 10 ? "0" : "") << ifmb
267  << "-" << iasc << (iach<10 ? "0" : "") << iach;
268  return ssout.str();
269 }
270 //**********************************************************************
static Index onlineChannel(Index chanOff, Index dbg=0)
bool dbg
Name asicChannelName(Index icha) const
std::string string
Definition: nybbler.cc:12
ChannelGroupService::Name Name
unsigned int Index
init
Definition: train.py:42
static Index femb(Index chan, bool isOff)
static Index asicChannel(Index chan, bool isOff)
static Index apa(Index chan, bool isOff)
static Index asic(Index chan, bool isOff)
static Index tpcSet(Index chan, bool isOff)
QTextStream & endl(QTextStream &s)