-
Notifications
You must be signed in to change notification settings - Fork 7
/
emcal_cell.h
326 lines (293 loc) · 13.8 KB
/
emcal_cell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// -*- mode: c++; -*-
#ifndef EMCAL_CELL_H_
#define EMCAL_CELL_H_
namespace {
void to_sm_nphi(unsigned int &sm, unsigned int &nphi,
unsigned int n)
{
sm = n < 11520 ? n / 1152 :
n < 12288 ? 10 + (n - 11520) / 384 :
n < 16896 ? 12 + (n - 12288) / 768 :
18 + (n - 16896) / 384;
nphi = sm < 10 ? 24 : sm < 12 ? 8 : sm < 18 ? 24 : 8;
}
void to_sm_ieta_iphi(unsigned int &sm, unsigned int &ieta,
unsigned int &iphi, unsigned int n)
{
unsigned int nphi;
to_sm_nphi(sm, nphi, n);
const unsigned int n0 =
sm < 10 ? sm * 1152 :
sm < 12 ? 11520 + (sm - 10) * 384 :
sm < 18 ? 12288 + (sm - 12) * 768 :
16896 + (sm - 18) * 384;
const unsigned int n1 = n - n0;
ieta = 2 * (n1 / (2 * nphi)) + 1 - (n1 % 2);
iphi = (n1 / 2) % nphi;
}
unsigned int from_sm_ieta_iphi(unsigned int sm,
unsigned int ieta,
unsigned int iphi)
{
const unsigned int n0 =
sm < 10 ? sm * 1152 :
sm < 12 ? 11520 + (sm - 10) * 384 :
sm < 18 ? 12288 + (sm - 12) * 768 :
16896 + (sm - 18) * 384;
const unsigned int nphi =
sm < 10 ? 24 : sm < 12 ? 8 : sm < 18 ? 24 : 8;
return n0 + nphi * (ieta - 1) +
(nphi + 1) * ((ieta - 1) % 2) + iphi * 2;
}
void neta_nphi(unsigned int &neta, unsigned int &nphi,
const unsigned int sm)
{
neta = sm < 12 ? 48 : sm < 18 ? 32 : 48;
nphi = sm < 10 ? 24 : sm < 12 ? 8 : sm < 18 ? 24 : 8;
}
bool inside_edge(unsigned int n, unsigned int d)
{
unsigned int sm;
unsigned int ieta;
unsigned int iphi;
to_sm_ieta_iphi(sm, ieta, iphi, n);
unsigned int neta;
unsigned int nphi;
neta_nphi(neta, nphi, sm);
return (ieta >= d && iphi >= d &&
ieta < neta - d && iphi < nphi - d);
}
void cell_3_3(unsigned int n_3_3[], const unsigned int n,
const unsigned int ld = 3)
{
unsigned int sm;
unsigned int nphi;
to_sm_nphi(sm, nphi, n);
if (n % 2 == 0) {
n_3_3[0 * ld + 0] = n - 1;
n_3_3[0 * ld + 1] = n + 1;
n_3_3[0 * ld + 2] = n + 3;
}
else {
n_3_3[0 * ld + 0] = n - 2 * nphi - 3;
n_3_3[0 * ld + 1] = n - 2 * nphi - 1;
n_3_3[0 * ld + 2] = n - 2 * nphi + 1;
}
n_3_3[1 * ld + 0] = n - 2;
n_3_3[1 * ld + 1] = n;
n_3_3[1 * ld + 2] = n + 2;
if (n % 2 == 0) {
n_3_3[2 * ld + 0] = n + 2 * nphi - 1;
n_3_3[2 * ld + 1] = n + 2 * nphi + 1;
n_3_3[2 * ld + 2] = n + 2 * nphi + 3;
}
else {
n_3_3[2 * ld + 0] = n - 3;
n_3_3[2 * ld + 1] = n - 1;
n_3_3[2 * ld + 2] = n + 1;
}
}
void cell_5_5(unsigned int n_5_5[], const unsigned int n,
const unsigned int ld = 5)
{
const unsigned int sm = n < 11520 ? n / 1152 :
n < 12288 ? 10 + (n - 11520) / 384 :
n < 16896 ? 12 + (n - 12288) / 768 :
18 + (n - 16896) / 384;
const unsigned int nphi =
sm < 10 ? 24 : sm < 12 ? 8 : sm < 18 ? 24 : 8;
n_5_5[0 * ld + 0] = n - 2 * nphi - 4;
n_5_5[0 * ld + 1] = n - 2 * nphi - 2;
n_5_5[0 * ld + 2] = n - 2 * nphi;
n_5_5[0 * ld + 3] = n - 2 * nphi + 2;
n_5_5[0 * ld + 4] = n - 2 * nphi + 4;
if (n % 2 == 0) {
n_5_5[1 * ld + 0] = n - 3;
n_5_5[1 * ld + 1] = n - 1;
n_5_5[1 * ld + 2] = n + 1;
n_5_5[1 * ld + 3] = n + 3;
n_5_5[1 * ld + 4] = n + 5;
}
else {
n_5_5[1 * ld + 0] = n - 2 * nphi - 5;
n_5_5[1 * ld + 1] = n - 2 * nphi - 3;
n_5_5[1 * ld + 2] = n - 2 * nphi - 1;
n_5_5[1 * ld + 3] = n - 2 * nphi + 1;
n_5_5[1 * ld + 4] = n - 2 * nphi + 3;
}
n_5_5[2 * ld + 0] = n - 4;
n_5_5[2 * ld + 1] = n - 2;
n_5_5[2 * ld + 2] = n;
n_5_5[2 * ld + 3] = n + 2;
n_5_5[2 * ld + 4] = n + 4;
if (n % 2 == 0) {
n_5_5[3 * ld + 0] = n + 2 * nphi - 3;
n_5_5[3 * ld + 1] = n + 2 * nphi - 1;
n_5_5[3 * ld + 2] = n + 2 * nphi + 1;
n_5_5[3 * ld + 3] = n + 2 * nphi + 3;
n_5_5[3 * ld + 4] = n + 2 * nphi + 5;
}
else {
n_5_5[3 * ld + 0] = n - 5;
n_5_5[3 * ld + 1] = n - 3;
n_5_5[3 * ld + 2] = n - 1;
n_5_5[3 * ld + 3] = n + 1;
n_5_5[3 * ld + 4] = n + 3;
}
n_5_5[4 * ld + 0] = n + 2 * nphi - 4;
n_5_5[4 * ld + 1] = n + 2 * nphi - 2;
n_5_5[4 * ld + 2] = n + 2 * nphi;
n_5_5[4 * ld + 3] = n + 2 * nphi + 2;
n_5_5[4 * ld + 4] = n + 2 * nphi + 4;
}
void cell_neighbor(unsigned int n_m_m[], const unsigned int n,
const unsigned int m = 5, unsigned int ld = 0)
{
if (ld == 0) {
ld = m;
}
const unsigned int sm = n < 11520 ? n / 1152 :
n < 12288 ? 10 + (n - 11520) / 384 :
n < 16896 ? 12 + (n - 12288) / 768 :
18 + (n - 16896) / 384;
const unsigned int nphi =
sm < 10 ? 24 : sm < 12 ? 8 : sm < 18 ? 24 : 8;
for (unsigned int i = 0; i < m; i++) {
const unsigned int i_centered = i - (m - 1) / 2;
const unsigned int offset_i = (i_centered & 1) == 0 ?
i_centered * nphi :
(n & 1) == 0 ?
((i_centered + 2) & ~1) * nphi + 1 :
(i_centered & ~1) * nphi - 1;
for (unsigned int j = 0; j < m; j++) {
const unsigned int j_times_2_centered =
2 * j - (m - 1);
n_m_m[i * ld + j] =
n + offset_i + j_times_2_centered;
}
}
}
void cell_cross(unsigned int n_cross[], const unsigned int n)
{
// Note that the "cross" happens to correspond to the odd
// entries in the 3x3 array
unsigned int sm;
unsigned int nphi;
to_sm_nphi(sm, nphi, n);
n_cross[0] = n % 2 == 0 ? n + 1 : n - 2 * nphi - 1;
n_cross[1] = n - 2;
n_cross[2] = n + 2;
n_cross[3] = n % 2 == 0 ? n + 2 * nphi + 1 : n - 1;
}
// Counter-clockwise outer perimeter cell ID for EMCAL and DCAL,
// starting with the highest eta and lowest phi (corresponding to
// ieta = 0, iphi = 0). The starting point is *not* repeated at
// the end.
static const unsigned short nboundary_emcal = 444;
static const unsigned short boundary_emcal_cell_id[444] = {
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33,
35, 37, 39, 41, 43, 45, 47, 2305, 2307, 2309, 2311, 2313,
2315, 2317, 2319, 2321, 2323, 2325, 2327, 2329, 2331, 2333,
2335, 2337, 2339, 2341, 2343, 2345, 2347, 2349, 2351, 4609,
4611, 4613, 4615, 4617, 4619, 4621, 4623, 4625, 4627, 4629,
4631, 4633, 4635, 4637, 4639, 4641, 4643, 4645, 4647, 4649,
4651, 4653, 4655, 6913, 6915, 6917, 6919, 6921, 6923, 6925,
6927, 6929, 6931, 6933, 6935, 6937, 6939, 6941, 6943, 6945,
6947, 6949, 6951, 6953, 6955, 6957, 6959, 9217, 9219, 9221,
9223, 9225, 9227, 9229, 9231, 9233, 9235, 9237, 9239, 9241,
9243, 9245, 9247, 9249, 9251, 9253, 9255, 9257, 9259, 9261,
9263, 11521, 11523, 11525, 11527, 11529, 11531, 11533, 11535,
11534, 11551, 11550, 11567, 11566, 11583, 11582, 11599, 11598,
11615, 11614, 11631, 11630, 11647, 11646, 11663, 11662, 11679,
11678, 11695, 11694, 11711, 11710, 11727, 11726, 11743, 11742,
11759, 11758, 11775, 11774, 11791, 11790, 11807, 11806, 11823,
11822, 11839, 11838, 11855, 11854, 11871, 11870, 11887, 11886,
11903, 11902, 11919, 11918, 11935, 11934, 11951, 11950, 11967,
11966, 11983, 11982, 11999, 11998, 12015, 12014, 12031, 12030,
12047, 12046, 12063, 12062, 12079, 12078, 12095, 12094, 12111,
12110, 12127, 12126, 12143, 12142, 12159, 12158, 12175, 12174,
12191, 12190, 12207, 12206, 12223, 12222, 12239, 12238, 12255,
12254, 12271, 12270, 12287, 12286, 12284, 12282, 12280, 12278,
12276, 12274, 12272, 11518, 11516, 11514, 11512, 11510, 11508,
11506, 11504, 11502, 11500, 11498, 11496, 11494, 11492, 11490,
11488, 11486, 11484, 11482, 11480, 11478, 11476, 11474, 11472,
9214, 9212, 9210, 9208, 9206, 9204, 9202, 9200, 9198, 9196,
9194, 9192, 9190, 9188, 9186, 9184, 9182, 9180, 9178, 9176,
9174, 9172, 9170, 9168, 6910, 6908, 6906, 6904, 6902, 6900,
6898, 6896, 6894, 6892, 6890, 6888, 6886, 6884, 6882, 6880,
6878, 6876, 6874, 6872, 6870, 6868, 6866, 6864, 4606, 4604,
4602, 4600, 4598, 4596, 4594, 4592, 4590, 4588, 4586, 4584,
4582, 4580, 4578, 4576, 4574, 4572, 4570, 4568, 4566, 4564,
4562, 4560, 2302, 2300, 2298, 2296, 2294, 2292, 2290, 2288,
2286, 2284, 2282, 2280, 2278, 2276, 2274, 2272, 2270, 2268,
2266, 2264, 2262, 2260, 2258, 2256, 2257, 2208, 2209, 2160,
2161, 2112, 2113, 2064, 2065, 2016, 2017, 1968, 1969, 1920,
1921, 1872, 1873, 1824, 1825, 1776, 1777, 1728, 1729, 1680,
1681, 1632, 1633, 1584, 1585, 1536, 1537, 1488, 1489, 1440,
1441, 1392, 1393, 1344, 1345, 1296, 1297, 1248, 1249, 1200,
1201, 1152, 1153, 1104, 1105, 1056, 1057, 1008, 1009, 960,
961, 912, 913, 864, 865, 816, 817, 768, 769, 720, 721, 672,
673, 624, 625, 576, 577, 528, 529, 480, 481, 432, 433, 384,
385, 336, 337, 288, 289, 240, 241, 192, 193, 144, 145, 96, 97,
48, 49, 0
};
static const unsigned short nboundary_dcal = 492;
static const unsigned short boundary_dcal_cell_id[492] = {
12289, 12291, 12293, 12295, 12297, 12299, 12301, 12303, 12305,
12307, 12309, 12311, 12313, 12315, 12317, 12319, 12321, 12323,
12325, 12327, 12329, 12331, 12333, 12335, 13825, 13827, 13829,
13831, 13833, 13835, 13837, 13839, 13841, 13843, 13845, 13847,
13849, 13851, 13853, 13855, 13857, 13859, 13861, 13863, 13865,
13867, 13869, 13871, 15361, 15363, 15365, 15367, 15369, 15371,
15373, 15375, 15377, 15379, 15381, 15383, 15385, 15387, 15389,
15391, 15393, 15395, 15397, 15399, 15401, 15403, 15405, 15407,
16897, 16899, 16901, 16903, 16905, 16907, 16909, 16911, 16910,
16927, 16926, 16943, 16942, 16959, 16958, 16975, 16974, 16991,
16990, 17007, 17006, 17023, 17022, 17039, 17038, 17055, 17054,
17071, 17070, 17087, 17086, 17103, 17102, 17119, 17118, 17135,
17134, 17151, 17150, 17167, 17166, 17183, 17182, 17199, 17198,
17215, 17214, 17231, 17230, 17247, 17246, 17263, 17262, 17279,
17278, 17295, 17294, 17311, 17310, 17327, 17326, 17343, 17342,
17359, 17358, 17375, 17374, 17391, 17390, 17407, 17406, 17423,
17422, 17439, 17438, 17455, 17454, 17471, 17470, 17487, 17486,
17503, 17502, 17519, 17518, 17535, 17534, 17551, 17550, 17567,
17566, 17583, 17582, 17599, 17598, 17615, 17614, 17631, 17630,
17647, 17646, 17663, 17662, 17660, 17658, 17656, 17654, 17652,
17650, 17648, 16894, 16892, 16890, 16888, 16886, 16884, 16882,
16880, 16878, 16876, 16874, 16872, 16870, 16868, 16866, 16864,
16862, 16860, 16858, 16856, 16854, 16852, 16850, 16848, 15358,
15356, 15354, 15352, 15350, 15348, 15346, 15344, 15342, 15340,
15338, 15336, 15334, 15332, 15330, 15328, 15326, 15324, 15322,
15320, 15318, 15316, 15314, 15312, 13822, 13820, 13818, 13816,
13814, 13812, 13810, 13808, 13806, 13804, 13802, 13800, 13798,
13796, 13794, 13792, 13790, 13788, 13786, 13784, 13782, 13780,
13778, 13776, 13777, 13728, 13729, 13680, 13681, 13632, 13633,
13584, 13585, 13536, 13537, 13488, 13489, 13440, 13441, 13392,
13393, 13344, 13345, 13296, 13297, 13248, 13249, 13200, 13201,
13152, 13153, 13104, 13105, 13056, 13057, 13059, 13061, 13063,
13065, 13067, 13069, 13071, 13073, 13075, 13077, 13079, 13081,
13083, 13085, 13087, 13089, 13091, 13093, 13095, 13097, 13099,
13101, 13103, 14593, 14595, 14597, 14599, 14601, 14603, 14605,
14607, 14609, 14611, 14613, 14615, 14617, 14619, 14621, 14623,
14625, 14627, 14629, 14631, 14633, 14635, 14637, 14639, 16129,
16131, 16133, 16135, 16137, 16139, 16141, 16143, 16145, 16147,
16149, 16151, 16153, 16155, 16157, 16159, 16161, 16163, 16165,
16167, 16169, 16171, 16173, 16175, 17409, 17392, 17393, 17376,
17377, 17360, 17361, 17344, 17345, 17328, 17329, 17312, 17313,
17296, 17297, 17280, 17281, 17264, 17265, 17248, 17249, 17232,
17233, 17216, 17217, 17200, 17201, 17184, 17185, 17168, 17169,
17152, 17153, 17136, 16126, 16124, 16122, 16120, 16118, 16116,
16114, 16112, 16110, 16108, 16106, 16104, 16102, 16100, 16098,
16096, 16094, 16092, 16090, 16088, 16086, 16084, 16082, 16080,
14590, 14588, 14586, 14584, 14582, 14580, 14578, 14576, 14574,
14572, 14570, 14568, 14566, 14564, 14562, 14560, 14558, 14556,
14554, 14552, 14550, 14548, 14546, 14544, 13054, 13052, 13050,
13048, 13046, 13044, 13042, 13040, 13038, 13036, 13034, 13032,
13030, 13028, 13026, 13024, 13022, 13020, 13018, 13016, 13014,
13012, 13010, 13008, 13009, 12960, 12961, 12912, 12913, 12864,
12865, 12816, 12817, 12768, 12769, 12720, 12721, 12672, 12673,
12624, 12625, 12576, 12577, 12528, 12529, 12480, 12481, 12432,
12433, 12384, 12385, 12336, 12337, 12288
};
}
#endif // EMCAL_CELL_H_