CMS 3D CMS Logo

EcalPreshowerNumberingScheme.cc
Go to the documentation of this file.
1 // File: EcalPreshowerNumberingScheme.cc
3 // Description: Numbering scheme for preshower detector
5 
8 #include <sstream>
9 
10 //#define EDM_ML_DEBUG
11 
13  // For SFLX2a, we use copy# 1-3
14  int vL2ax[3] = {4, 6, 10};
15  int vL2ay[3] = {29, 31, 35};
16  // For SFLX2b, we use copy# 1
17  int vL2bx[1] = {2};
18  int vL2by[1] = {25};
19  // For SFLX3a, we use copy# 4-6
20  int vL3ax[3] = {30, 34, 36};
21  int vL3ay[3] = {35, 31, 29};
22  // For SFLX3b, we use copy# 2
23  int vL3bx[1] = {38};
24  int vL3by[1] = {25};
25  // For SFLX1a, we use odd number in copy# 1-52
26  int vL1ax[26] = {2, 4, 4, 8, 8, 8, 8, 10, 12, 12, 14, 14, 20, 20, 26, 26, 28, 28, 30, 32, 32, 32, 32, 36, 36, 38};
27  int vL1ay[26] = {21, 25, 21, 33, 29, 25, 21, 21, 25, 21, 31, 27, 32,
28  28, 31, 27, 25, 21, 21, 33, 29, 25, 21, 25, 21, 21};
29  // For SFLX1b, we use copy# 2
30  int vL1bx[1] = {22};
31  int vL1by[1] = {27};
32  // For SFLX1c, we use copy# 1
33  int vL1cx[1] = {18};
34  int vL1cy[1] = {27};
35  // For SFLX1d, we use copy# 2
36  int vL1dx[1] = {26};
37  int vL1dy[1] = {23};
38  // For SFLX1e, we use copy# 1
39  int vL1ex[1] = {14};
40  int vL1ey[1] = {23};
41  // For SFLX0a, we use odd number if copy# 1-46
42  int vL0ax[23] = {6, 6, 10, 10, 12, 12, 14, 16, 16, 18, 18, 20, 22, 22, 24, 24, 26, 28, 28, 30, 30, 34, 34};
43  int vL0ay[23] = {26, 21, 30, 25, 34, 29, 35, 36, 31, 36, 31, 36, 36, 31, 36, 31, 35, 34, 29, 30, 25, 26, 21};
44  // For SFL0b, we use copy# 2
45  int vL0bx[1] = {24};
46  int vL0by[1] = {26};
47  // For SFL0c, we use copy# 1
48  int vL0cx[1] = {16};
49  int vL0cy[1] = {26};
50 
51  for (int i = 0; i < 1; ++i) {
52  L1bx[i] = vL1bx[i];
53  L1by[i] = vL1by[i];
54  L1cx[i] = vL1cx[i];
55  L1cy[i] = vL1cy[i];
56  L1dx[i] = vL1dx[i];
57  L1dy[i] = vL1dy[i];
58  L1ex[i] = vL1ex[i];
59  L1ey[i] = vL1ey[i];
60  L0bx[i] = vL0bx[i];
61  L0by[i] = vL0by[i];
62  L0cx[i] = vL0cx[i];
63  L0cy[i] = vL0cy[i];
64  L3bx[i] = vL3bx[i];
65  L3by[i] = vL3by[i];
66  L2bx[i] = vL2bx[i];
67  L2by[i] = vL2by[i];
68  }
69 
70  for (int i = 0; i < 3; ++i) {
71  L3ax[i] = vL3ax[i];
72  L3ay[i] = vL3ay[i];
73  L2ax[i] = vL2ax[i];
74  L2ay[i] = vL2ay[i];
75  }
76 
77  for (int i = 0; i < 23; ++i) {
78  L0ax[i] = vL0ax[i];
79  L0ay[i] = vL0ay[i];
80  }
81 
82  for (int i = 0; i < 26; ++i) {
83  L1ax[i] = vL1ax[i];
84  L1ay[i] = vL1ay[i];
85  }
86 
87  edm::LogVerbatim("EcalGeom") << "Creating EcalPreshowerNumberingScheme";
88 }
89 
91  edm::LogVerbatim("EcalGeom") << "Deleting EcalPreshowerNumberingScheme";
92 }
93 
94 /*
95  * Compute the Ecal Preshower DetId.
96  * General NB: if possible, it would be way better to just access the DetID from a hash map from G4 Volume,
97  * rather than recomputing it for each SimHit - see Tracker.
98  */
99 uint32_t EcalPreshowerNumberingScheme::getUnitID(const EcalBaseNumber& baseNumber) const {
100  const int numberOfHierarchyLevels = baseNumber.getLevels();
101  bool dd4hep = ((numberOfHierarchyLevels == 10) && (baseNumber.getCopyNumber(numberOfHierarchyLevels - 1) == 1) &&
102  (baseNumber.getLevelName(numberOfHierarchyLevels - 1) != "OCMS"));
103 #ifdef EDM_ML_DEBUG
104  std::ostringstream st1;
105  for (int k = 0; k < numberOfHierarchyLevels; ++k)
106  st1 << ", " << baseNumber.getLevelName(k) << ":" << baseNumber.getCopyNumber(k);
107  edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme: dd4hep " << dd4hep
108  << " witg geometry levels = " << numberOfHierarchyLevels << st1.str();
109 #endif
110  uint32_t intIndex = 0;
111  if (numberOfHierarchyLevels > 0) {
112  // depth index - silicon layer 1-st or 2-nd
113  int layer = 0;
114  if (baseNumber.getLevelName(0).find("SFSX") != std::string::npos) {
115  layer = 1;
116  } else if (baseNumber.getLevelName(0).find("SFSY") != std::string::npos) {
117  layer = 2;
118  } else {
119  edm::LogWarning("EcalGeom") << "EcalPreshowerNumberingScheme: Wrong name"
120  << " of Presh. Si. Strip : " << baseNumber.getLevelName(0);
121  }
122 
123  // Z index +Z = 1 ; -Z = 2
124 
125  int zs = dd4hep ? baseNumber.getCopyNumber(4) : baseNumber.getCopyNumber(5);
126  int zside = 2 * (1 - zs) + 1;
127 
128  // box numer and ladder copy number
129  int box(0), ladd_copy(0);
130  std::string ladd("");
131  if (dd4hep) {
132  auto num1 = numbers(baseNumber.getLevelName(2));
133  box = num1.second;
134  ladd_copy = num1.first;
135  ladd = baseNumber.getLevelName(2).substr(0, 6);
136  } else {
137  box = baseNumber.getCopyNumber(2);
138  ladd_copy = baseNumber.getCopyNumber(3);
139  ladd = baseNumber.getLevelName(3).substr(0, 6);
140  }
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme::Box " << box << " Ladder " << ladd << ":"
143  << ladd_copy;
144 #endif
145 
146  int x = 0, y = 0, ix, iy, id;
147  int mapX[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
148  int mapY[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
149 
150  if (ladd == "SFLX0a" || ladd == "SFLY0a") {
151  mapX[5] = mapX[6] = mapX[7] = mapX[8] = mapX[9] = 1;
152  mapY[0] = 0;
153  mapY[1] = 1;
154  mapY[2] = 2;
155  mapY[3] = 3;
156  mapY[4] = 4;
157  mapY[5] = 0;
158  mapY[6] = 1;
159  mapY[7] = 2;
160  mapY[8] = 3;
161  mapY[9] = 4;
162 
163  id = (int)((float)ladd_copy / 2 + 0.5);
164 
165  x = L0ax[id - 1] + mapX[box - 1000 - 1];
166  y = L0ay[id - 1] + mapY[box - 1000 - 1];
167 
168  if ((ladd_copy % 2) == 0) {
169  if (mapX[box - 1000 - 1] == 0)
170  x += 1;
171  else if (mapX[box - 1000 - 1] == 1)
172  x -= 1;
173  y = 41 - y;
174  }
175  }
176  if (ladd == "SFLX0b" || ladd == "SFLY0b") {
177  mapX[4] = mapX[5] = mapX[6] = mapX[7] = mapX[8] = 1;
178  mapY[0] = 1;
179  mapY[1] = 2;
180  mapY[2] = 3;
181  mapY[3] = 4;
182  mapY[4] = 0;
183  mapY[5] = 1;
184  mapY[6] = 2;
185  mapY[7] = 3;
186  mapY[8] = 4;
187  mapY[9] = 0;
188 
189  x = L0bx[0] + mapX[box - 2000 - 1];
190  y = L0by[0] + mapY[box - 2000 - 1];
191 
192  if (ladd_copy == 1) {
193  x = 41 - x;
194  y = 41 - y;
195  }
196  }
197  if (ladd == "SFLX0c" || ladd == "SFLY0c") {
198  mapX[5] = mapX[6] = mapX[7] = mapX[8] = 1;
199  mapY[0] = 0;
200  mapY[1] = 1;
201  mapY[2] = 2;
202  mapY[3] = 3;
203  mapY[4] = 4;
204  mapY[5] = 1;
205  mapY[6] = 2;
206  mapY[7] = 3;
207  mapY[8] = 4;
208  mapY[9] = 0;
209 
210  x = L0cx[0] + mapX[box - 3000 - 1];
211  y = L0cy[0] + mapY[box - 3000 - 1];
212 
213  if (ladd_copy == 2) {
214  x = 41 - x;
215  y = 41 - y;
216  }
217  }
218  if (ladd == "SFLX1a" || ladd == "SFLY1a") {
219  mapX[4] = mapX[5] = mapX[6] = mapX[7] = 1;
220  mapY[0] = 0;
221  mapY[1] = 1;
222  mapY[2] = 2;
223  mapY[3] = 3;
224  mapY[4] = 0;
225  mapY[5] = 1;
226  mapY[6] = 2;
227  mapY[7] = 3;
228  mapY[8] = 0;
229  mapY[9] = 0;
230 
231  id = (int)((float)ladd_copy / 2 + 0.5);
232 
233  x = L1ax[id - 1] + mapX[box - 4000 - 1];
234  y = L1ay[id - 1] + mapY[box - 4000 - 1];
235 
236  if ((ladd_copy % 2) == 0) {
237  if (mapX[box - 4000 - 1] == 0)
238  x += 1;
239  else if (mapX[box - 4000 - 1] == 1)
240  x -= 1;
241  y = 41 - y;
242  }
243  }
244  if (ladd == "SFLX1b" || ladd == "SFLY1b") {
245  mapX[3] = mapX[4] = mapX[5] = mapX[6] = 1;
246  mapY[0] = 1;
247  mapY[1] = 2;
248  mapY[2] = 3;
249  mapY[3] = 0;
250  mapY[4] = 1;
251  mapY[5] = 2;
252  mapY[6] = 3;
253  mapY[7] = 0;
254  mapY[8] = 0;
255  mapY[9] = 0;
256 
257  x = L1bx[0] + mapX[box - 5000 - 1];
258  y = L1by[0] + mapY[box - 5000 - 1];
259 
260  if (ladd_copy == 1) {
261  x = 41 - x;
262  y = 41 - y;
263  }
264  }
265  if (ladd == "SFLX1c" || ladd == "SFLY1c") {
266  mapX[4] = mapX[5] = mapX[6] = 1;
267  mapY[0] = 0;
268  mapY[1] = 1;
269  mapY[2] = 2;
270  mapY[3] = 3;
271  mapY[4] = 1;
272  mapY[5] = 2;
273  mapY[6] = 3;
274  mapY[7] = 0;
275  mapY[8] = 0;
276  mapY[9] = 0;
277 
278  x = L1cx[0] + mapX[box - 6000 - 1];
279  y = L1cy[0] + mapY[box - 6000 - 1];
280 
281  if (ladd_copy == 2) {
282  x = 41 - x;
283  y = 41 - y;
284  }
285  }
286  if (ladd == "SFLX1d" || ladd == "SFLY1d") {
287  mapX[2] = mapX[3] = mapX[4] = mapX[5] = 1;
288  mapY[0] = 2;
289  mapY[1] = 3;
290  mapY[2] = 0;
291  mapY[3] = 1;
292  mapY[4] = 2;
293  mapY[5] = 3;
294  mapY[6] = 0;
295  mapY[7] = 0;
296  mapY[8] = 0;
297  mapY[9] = 0;
298 
299  x = L1dx[0] + mapX[box - 7000 - 1];
300  y = L1dy[0] + mapY[box - 7000 - 1];
301 
302  if (ladd_copy == 1) {
303  x = 41 - x;
304  y = 41 - y;
305  }
306  }
307  if (ladd == "SFLX1e" || ladd == "SFLY1e") {
308  mapX[4] = mapX[5] = 1;
309  mapY[0] = 0;
310  mapY[1] = 1;
311  mapY[2] = 2;
312  mapY[3] = 3;
313  mapY[4] = 2;
314  mapY[5] = 3;
315  mapY[6] = 0;
316  mapY[7] = 0;
317  mapY[8] = 0;
318  mapY[9] = 0;
319 
320  x = L1ex[0] + mapX[box - 8000 - 1];
321  y = L1ey[0] + mapY[box - 8000 - 1];
322 
323  if (ladd_copy == 2) {
324  x = 41 - x;
325  y = 41 - y;
326  }
327  }
328  if (ladd == "SFLX3a" || ladd == "SFLY3a") {
329  mapX[4] = mapX[5] = mapX[6] = 1;
330  mapY[0] = 0;
331  mapY[1] = 1;
332  mapY[2] = 2;
333  mapY[3] = 3;
334  mapY[4] = 0;
335  mapY[5] = 1;
336  mapY[6] = 2;
337  mapY[7] = 0;
338  mapY[8] = 0;
339  mapY[9] = 0;
340 
341  id = (ladd_copy > 3) ? ladd_copy - 3 : 4 - ladd_copy;
342 
343  x = L3ax[id - 1] + mapX[box - 9000 - 1];
344  y = L3ay[id - 1] + mapY[box - 9000 - 1];
345 
346  if (ladd_copy < 4) {
347  x = 41 - x;
348  y = 41 - y;
349  }
350  }
351  if (ladd == "SFLX3b" || ladd == "SFLY3b") {
352  mapX[4] = mapX[5] = 1;
353  mapY[0] = 0;
354  mapY[1] = 1;
355  mapY[2] = 2;
356  mapY[3] = 3;
357  mapY[4] = 0;
358  mapY[5] = 1;
359  mapY[6] = 0;
360  mapY[7] = 0;
361  mapY[8] = 0;
362  mapY[9] = 0;
363 
364  x = L3bx[0] + mapX[box - 11000 - 1];
365  y = L3by[0] + mapY[box - 11000 - 1];
366 
367  if (ladd_copy == 1) {
368  x = 41 - x;
369  y = 41 - y;
370  }
371  }
372  if (ladd == "SFLX2a" || ladd == "SFLY2a") {
373  mapX[3] = mapX[4] = mapX[5] = mapX[6] = 1;
374  mapY[0] = 0;
375  mapY[1] = 1;
376  mapY[2] = 2;
377  mapY[3] = 0;
378  mapY[4] = 1;
379  mapY[5] = 2;
380  mapY[6] = 3;
381  mapY[7] = 0;
382  mapY[8] = 0;
383  mapY[9] = 0;
384 
385  id = (ladd_copy > 3) ? 7 - ladd_copy : ladd_copy;
386 
387  x = L2ax[id - 1] + mapX[box - 10000 - 1];
388  y = L2ay[id - 1] + mapY[box - 10000 - 1];
389 
390  if (ladd_copy > 3) {
391  x = 41 - x;
392  y = 41 - y;
393  }
394  }
395  if (ladd == "SFLX2b" || ladd == "SFLY2b") {
396  mapX[2] = mapX[3] = mapX[4] = mapX[5] = 1;
397  mapY[0] = 0;
398  mapY[1] = 1;
399  mapY[2] = 0;
400  mapY[3] = 1;
401  mapY[4] = 2;
402  mapY[5] = 3;
403  mapY[6] = 0;
404  mapY[7] = 0;
405  mapY[8] = 0;
406  mapY[9] = 0;
407 
408  x = L2bx[0] + mapX[box - 12000 - 1];
409  y = L2by[0] + mapY[box - 12000 - 1];
410 
411  if (ladd_copy == 2) {
412  x = 41 - x;
413  y = 41 - y;
414  }
415  }
416 
417  if (zside < 0 && layer == 1)
418  x = 41 - x;
419 
420  ix = x;
421  iy = y;
422 
423  if (layer == 2) {
424  x = (zside > 0) ? iy : 41 - iy;
425  y = 41 - ix;
426  }
427 
428  // strip number inside wafer
429  int strip = baseNumber.getCopyNumber(0);
430 
431  if (layer == 1) {
432  if (zside > 0 && y <= 20)
433  strip = 33 - strip;
434  else if (zside < 0 && y > 20)
435  strip = 33 - strip;
436  } else if (layer == 2) {
437  if (zside > 0 && x <= 20)
438  strip = 33 - strip;
439  else if (zside < 0 && x > 20)
440  strip = 33 - strip;
441  }
442 
443  intIndex = ESDetId(strip, x, y, layer, zside).rawId();
444 
445 #ifdef EDM_ML_DEBUG
446  edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme : zside " << zs << ":" << zside << " Ladd " << ladd
447  << " ladd_copy: " << ladd_copy << " box " << box << " x " << x << " y " << y
448  << " layer " << layer << " strip " << strip << " UnitID 0x" << std::hex << intIndex
449  << std::dec;
450 
451  for (int ich = 0; ich < numberOfHierarchyLevels; ich++)
452  edm::LogVerbatim("EcalGeom") << "Name = " << baseNumber.getLevelName(ich)
453  << " copy = " << baseNumber.getCopyNumber(ich);
454 #endif
455  }
456 
457  return intIndex;
458 }
459 
460 std::pair<int, int> EcalPreshowerNumberingScheme::numbers(const std::string& name) const {
461  int num1(-1), num2(-1);
462  if (name.find('#') != std::string::npos) {
463  uint32_t ip1 = name.find('#');
464  if (name.find('!') != std::string::npos) {
465  uint32_t ip2 = name.find('!');
466  num1 = ::atoi(name.substr(ip1 + 1, ip2 - ip1 - 1).c_str());
467  if (name.find('#', ip2) != std::string::npos) {
468  uint32_t ip3 = name.find('#', ip2);
469  num2 = ::atoi(name.substr(ip3 + 1, name.size() - ip3 - 1).c_str());
470  }
471  }
472  }
473 #ifdef EDM_ML_DEBUG
474  edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme::Numbers from " << name << " are " << num1 << " and "
475  << num2;
476 #endif
477  return std::make_pair(num1, num2);
478 }
Log< level::Info, true > LogVerbatim
std::string const & getLevelName(int level) const
int getCopyNumber(int level) const
int zside(DetId const &)
uint32_t getUnitID(const EcalBaseNumber &baseNumber) const override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int getLevels() const
Log< level::Warning, false > LogWarning
std::pair< int, int > numbers(const std::string &) const