CMS 3D CMS Logo

HcalLogicalMapGenerator.cc
Go to the documentation of this file.
7 
8 #include <string>
9 #include <sstream>
10 #include <cstdio>
11 #include <iostream>
12 #include <cstring>
13 
14 using namespace std;
15 
16 /***************************************/
17 
19  //adc and qie table; qie is entry 0, adc is entry 1. Constant across HB, HE, HO
20  // int iadcquiHBHE[NRMFIBR][NFCH][2];
21 
22  for (i = 0; i < NRMFIBR; i++) {
23  for (j = 0; j < NFCH; j++) {
24  //Intentionally relying on integer truncation here
25  iadcquiHBHE[i][j][0] = i / 2 + 1;
26 
27  if (i % 2 == 0)
28  iadcquiHBHE[i][j][1] = j;
29  else
30  iadcquiHBHE[i][j][1] = NFCH + (j + 1) % 3;
31  }
32  }
33 }
34 
36 
38  mapIOV_ = mapIOV;
39 
40  std::vector<HBHEHFLogicalMapEntry> HBHEHFEntries;
41  std::vector<HOHXLogicalMapEntry> HOHXEntries;
42  std::vector<CALIBLogicalMapEntry> CALIBEntries;
43  std::vector<ZDCLogicalMapEntry> ZDCEntries;
44  std::vector<HTLogicalMapEntry> HTEntries;
45  std::vector<uint32_t> LinearIndex2Entry;
46  std::vector<uint32_t> HbHash2Entry;
47  std::vector<uint32_t> HeHash2Entry;
48  std::vector<uint32_t> HfHash2Entry;
49  std::vector<uint32_t> HtHash2Entry;
50  std::vector<uint32_t> HoHash2Entry;
51  std::vector<uint32_t> HxCalibHash2Entry;
52  //std::vector <uint32_t> CalibHash2Entry;
53  std::vector<uint32_t> ZdcHash2Entry;
54 
55  int HbHalf = 1296;
56  int HeHalf = 1296;
57  //if (h2mode_) HeHalf = 4032;
58  int HoHalf = 1080;
59  int HfHalf = 864;
60  int HtHalf = 2088;
61  int ZdcHalf = 11;
62  int CalibFull = 216 + 425 + 8;
63 
64  uint32_t illegal_value = 0;
65  for (int i = 0; i <= HcalElectronicsId::maxLinearIndex; i++)
66  LinearIndex2Entry.push_back(illegal_value);
67  for (int iHb = 0; iHb < 2 * HbHalf; iHb++)
68  HbHash2Entry.push_back(illegal_value);
69  for (int iHe = 0; iHe < 2 * HeHalf; iHe++)
70  HeHash2Entry.push_back(illegal_value);
71  for (int iHf = 0; iHf < 2 * HfHalf; iHf++)
72  HfHash2Entry.push_back(illegal_value);
73  for (int iHt = 0; iHt < 2 * HtHalf; iHt++)
74  HtHash2Entry.push_back(illegal_value);
75  for (int iHo = 0; iHo < 2 * HoHalf; iHo++)
76  HoHash2Entry.push_back(illegal_value);
77  for (int iHcalib = 0; iHcalib < CalibFull; iHcalib++)
78  HxCalibHash2Entry.push_back(illegal_value);
79  for (int iZdc = 0; iZdc < 2 * ZdcHalf; iZdc++)
80  ZdcHash2Entry.push_back(illegal_value);
81 
82  buildHBEFTMap(
83  topo, HBHEHFEntries, HTEntries, LinearIndex2Entry, HbHash2Entry, HeHash2Entry, HfHash2Entry, HtHash2Entry);
84  buildHOXMap(topo, HOHXEntries, LinearIndex2Entry, HoHash2Entry, HxCalibHash2Entry);
85  buildCALIBMap(topo, CALIBEntries, LinearIndex2Entry, HxCalibHash2Entry);
86  buildZDCMap(topo, ZDCEntries, LinearIndex2Entry, ZdcHash2Entry);
87 
88  return HcalLogicalMap(topo,
89  HBHEHFEntries,
90  HOHXEntries,
91  CALIBEntries,
92  ZDCEntries,
93  HTEntries,
94  LinearIndex2Entry,
95  HbHash2Entry,
96  HeHash2Entry,
97  HfHash2Entry,
98  HtHash2Entry,
99  HoHash2Entry,
100  HxCalibHash2Entry,
101  /*CalibHash2Entry,*/ ZdcHash2Entry);
102 }
103 
105  std::vector<HBHEHFLogicalMapEntry>& HBHEHFEntries,
106  std::vector<HTLogicalMapEntry>& HTEntries,
107  std::vector<uint32_t>& LinearIndex2Entry,
108  std::vector<uint32_t>& HbHash2Entry,
109  std::vector<uint32_t>& HeHash2Entry,
110  std::vector<uint32_t>& HfHash2Entry,
111  std::vector<uint32_t>& HtHash2Entry) {
112  /******************************/
113  /* HBHE crate numbering */
114  int hbhecrate_loc[NHBHECR] = {0, 1, 4, 5, 10, 11, 14, 15, 17};
115  memcpy(hbhecrate, hbhecrate_loc, sizeof(int) * NHBHECR);
116  /* HBHE FED numbering of DCCs */
117  int fedhbhenum_loc[NHBHECR][2] = {
118  {702, 703}, {704, 705}, {700, 701}, {706, 707}, {716, 717}, {708, 709}, {714, 715}, {710, 711}, {712, 713}};
119  memcpy(fedhbhenum, fedhbhenum_loc, sizeof(int) * NHBHECR * 2);
120  /* HBHE/HF htr slot offsets for set of three htrs */
121  int ihslot_loc[NHSETS] = {2, 5, 13, 16};
122  memcpy(ihslot, ihslot_loc, sizeof(int) * NHSETS);
123  /* iphi (lower) starting index for each HBHE crate */
124  int ihbhephis_loc[NHBHECR] = {11, 19, 3, 27, 67, 35, 59, 43, 51};
125  memcpy(ihbhephis, ihbhephis_loc, sizeof(int) * NHBHECR);
126  /* ihbheetadepth - unique HBHE {eta,depth} assignments per fiber and fiber channel */
127  int ihbheetadepth_loc[NHTRS][NTOPBOT][NFBR][NFCH][2] = {{{{{11, 1}, {7, 1}, {3, 1}}, /* htr 0 (HB) -bot(+top) */
128  {{5, 1}, {1, 1}, {9, 1}},
129  {{11, 1}, {7, 1}, {3, 1}},
130  {{5, 1}, {1, 1}, {9, 1}},
131  {{10, 1}, {6, 1}, {2, 1}},
132  {{8, 1}, {4, 1}, {12, 1}},
133  {{10, 1}, {6, 1}, {2, 1}},
134  {{8, 1}, {4, 1}, {12, 1}}},
135  {{{11, 1}, {7, 1}, {3, 1}}, /* htr 0 (HB) +bot(-top) */
136  {{5, 1}, {1, 1}, {9, 1}},
137  {{11, 1}, {7, 1}, {3, 1}},
138  {{5, 1}, {1, 1}, {9, 1}},
139  {{10, 1}, {6, 1}, {2, 1}},
140  {{8, 1}, {4, 1}, {12, 1}},
141  {{10, 1}, {6, 1}, {2, 1}},
142  {{8, 1}, {4, 1}, {12, 1}}}},
143  {{{{16, 2}, {15, 2}, {14, 1}}, /* htr 1 (HBHE) -bot(+top) */
144  {{15, 1}, {13, 1}, {16, 1}},
145  {{16, 2}, {15, 2}, {14, 1}},
146  {{15, 1}, {13, 1}, {16, 1}},
147  {{17, 1}, {16, 3}, {26, 1}},
148  {{18, 1}, {18, 2}, {26, 2}},
149  {{17, 1}, {16, 3}, {25, 1}},
150  {{18, 1}, {18, 2}, {25, 2}}},
151  {{{16, 2}, {15, 2}, {14, 1}}, /* htr 1 (HBHE) +bot(-top) */
152  {{15, 1}, {13, 1}, {16, 1}},
153  {{16, 2}, {15, 2}, {14, 1}},
154  {{15, 1}, {13, 1}, {16, 1}},
155  {{17, 1}, {16, 3}, {25, 1}},
156  {{18, 1}, {18, 2}, {25, 2}},
157  {{17, 1}, {16, 3}, {26, 1}},
158  {{18, 1}, {18, 2}, {26, 2}}}},
159  {{{{28, 1}, {28, 2}, {29, 1}}, /* htr 2 (HE) -bot(+top) */
160  {{28, 3}, {24, 2}, {24, 1}},
161  {{27, 1}, {27, 2}, {29, 2}},
162  {{27, 3}, {23, 2}, {23, 1}},
163  {{19, 2}, {20, 1}, {22, 2}},
164  {{19, 1}, {20, 2}, {22, 1}},
165  {{19, 2}, {20, 1}, {21, 2}},
166  {{19, 1}, {20, 2}, {21, 1}}},
167  {{{27, 1}, {27, 2}, {29, 2}}, /* htr 2 (HE) +bot(-top) */
168  {{27, 3}, {23, 2}, {23, 1}},
169  {{28, 1}, {28, 2}, {29, 1}},
170  {{28, 3}, {24, 2}, {24, 1}},
171  {{19, 2}, {20, 1}, {21, 2}},
172  {{19, 1}, {20, 2}, {21, 1}},
173  {{19, 2}, {20, 1}, {22, 2}},
174  {{19, 1}, {20, 2}, {22, 1}}}}};
175  memcpy(ihbheetadepth, ihbheetadepth_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * NFCH * 2);
176 
177  //Aram's insert: I shall now define an array which contains the RM and the RM fiber for HB HE
178  //and variables associated with this table
179  int irm_rmfiHBHE_loc[NHTRS][NTOPBOT][NFBR][2] = {
180  {{{6, 1}, {7, 1}, {6, 2}, {7, 2}, {4, 1}, {5, 1}, {4, 2}, {5, 2}}, // HTR 0 top
181  {{6, 3}, {7, 3}, {6, 4}, {7, 4}, {4, 3}, {5, 3}, {4, 4}, {5, 4}}}, // HTR 0 bot
182  {{{2, 1}, {3, 1}, {2, 2}, {3, 2}, {2, 1}, {3, 1}, {2, 2}, {3, 2}}, // HTR 1 top
183  {{2, 3}, {3, 3}, {2, 4}, {3, 4}, {2, 3}, {3, 3}, {2, 4}, {3, 4}}}, // HTR 1 bot
184  {{{4, 1}, {5, 1}, {4, 2}, {5, 2}, {6, 1}, {7, 1}, {6, 2}, {7, 2}}, // HTR 2 top
185  {{4, 3}, {5, 3}, {4, 4}, {5, 4}, {6, 3}, {7, 3}, {6, 4}, {7, 4}}} // HTR 2 bot
186  };
187  memcpy(irm_rmfiHBHE, irm_rmfiHBHE_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * 2);
188  //Pixel tables as a function of rm, rm fiber and fiber channel
189 
190  int ipixelHB_loc[NRMFIBR][NFCH][NRMSLOT] = {
191  // fch = 0 fch = 1 fch = 2
192  {{18, 17, 3, 2}, {13, 3, 17, 7}, {14, 1, 19, 6}}, //rmfiber = 2
193  {{19, 2, 18, 1}, {15, 7, 13, 5}, {17, 19, 1, 3}}, //rmfiber = 3
194  {{9, 4, 16, 11}, {5, 8, 12, 15}, {2, 13, 7, 18}}, //rmfiber = 4
195  {{12, 11, 9, 8}, {7, 15, 5, 13}, {16, 6, 14, 4}}, //rmfiber = 5
196  {{8, 5, 15, 12}, {4, 9, 11, 16}, {1, 14, 6, 19}}, //rmfiber = 6
197  {{6, 16, 4, 14}, {3, 18, 2, 17}, {11, 12, 8, 9}} //rmfiber = 7
198  };
199  memcpy(ipixelHB, ipixelHB_loc, sizeof(int) * NRMFIBR * NFCH * NRMSLOT);
200 
201  int ipixelHE_loc[NRMFIBR][NFCH][NRMSLOT] = {
202  // fch = 0 fch = 1 fch = 2
203  {{12, 12, 12, 12}, {16, 7, 16, 7}, {7, 16, 7, 16}}, //rmfiber = 2
204  {{11, 11, 11, 11}, {19, 3, 19, 3}, {3, 19, 3, 19}}, //rmfiber = 3
205  {{15, 15, 6, 6}, {2, 18, 2, 18}, {6, 6, 15, 15}}, //rmfiber = 4
206  {{5, 14, 5, 14}, {14, 5, 14, 5}, {18, 2, 18, 2}}, //rmfiber = 5
207  {{17, 1, 17, 1}, {9, 9, 9, 9}, {1, 17, 1, 17}}, //rmfiber = 6
208  {{13, 4, 13, 4}, {8, 8, 8, 8}, {4, 13, 4, 13}} //rmfiber = 7
209  };
210  memcpy(ipixelHE, ipixelHE_loc, sizeof(int) * NRMFIBR * NFCH * NRMSLOT);
211 
212  //slb and rct tables
213 
214  //HB and HE
215 
216  const char* S_slbin_odd_loc[] = {"A1", "B0", "B1", "A0", "A1", "B0", "B1", "A0"};
217  for (int gg = 0; gg < 8; gg++) {
218  S_slbin_odd[gg] = S_slbin_odd_loc[gg];
219  }
220  const char* S_slbin_even_loc[] = {"C1", "D0", "D1", "C0", "C1", "D0", "D1", "C0"};
221  for (int gg = 0; gg < 8; gg++) {
222  S_slbin_even[gg] = S_slbin_even_loc[gg];
223  }
224  const char* rct_rackHBHE_loc[] = {"S2E01-RH",
225  "S2E03-RH",
226  "S2E05-RH",
227  "S2E07-RH",
228  "S2E09-RH",
229  "S2E08-RL",
230  "S2E06-RL",
231  "S2E04-RL",
232  "S2E02-RL",
233  "S2E02-RH",
234  "S2E04-RH",
235  "S2E06-RH",
236  "S2E08-RH",
237  "S2E09-RL",
238  "S2E07-RL",
239  "S2E05-RL",
240  "S2E03-RL",
241  "S2E01-RL"};
242  for (int gg = 0; gg < 18; gg++) {
243  rct_rackHBHE[gg] = rct_rackHBHE_loc[gg];
244  }
245 
246  int slb_table_loc[29] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, // 1<=eta<=12
247  1, 1, 2, 2, 3, 3, 1, 1, // 13<=eta<=20
248  2, 2, 3, 3, 4, 4, 4, 4, 4}; // 21<=eta<=29
249  memcpy(slb_table, slb_table_loc, sizeof(int) * 29);
250  /********************/
251 
252  char tempbuff[30]{0};
253 
254  //Stream variable
255  stringstream mystream;
256 
257  /* all HBHE crates */
258  for (ic = 0; ic < NHBHECR; ic++) {
259  /* four sets of three htrs per crate */
260  for (is = 0; is < NHSETS; is++) {
261  /* three htrs per set */
262  for (ih = 0; ih < NHTRS; ih++) {
263  /* top and bottom */
264  for (itb = 0; itb < NTOPBOT; itb++) {
265  /* eight fibers per HTR FPGA */
266  for (ifb = 0; ifb < NFBR; ifb++) {
267  /* three channels per fiber */
268  for (ifc = 0; ifc < NFCH; ifc++) {
269  icrate = hbhecrate[ic];
270  iside = is < NHSETS / 2 ? -1 : 1;
271  ifwtb = (is / 2 + itb + 1) % 2;
272  ieta = ihbheetadepth[ih][ifwtb][ifb][ifc][0];
273  idepth = ihbheetadepth[ih][ifwtb][ifb][ifc][1];
274  ihtr = ihslot[is] + ih;
275  (ieta > 16 || idepth > 2) ? det = "HE" : det = "HB";
276  (itb % 2) == 1 ? fpga = "bot" : fpga = "top";
277  ihtr_fi = ifb + 1;
278  ifi_ch = ifc;
279  iphi = (ieta > 20) ? (ihbhephis[ic] + (is % 2) * 4 + itb * 2 - 1) % 72 + 1
280  : (ihbhephis[ic] + (is % 2) * 4 + itb * 2 + (ifb / 2 + is / 2 + 1) % 2 - 1) % 72 + 1;
281  ispigot = (is % 2) * 6 + ih * 2 + itb;
282  idcc = is < NHSETS / 2 ? 1 : 2;
283  idcc_sl = idcc == 1 ? 10 : 20;
284  ifed = fedhbhenum[ic][idcc - 1];
285  //Aram's insert: rm variables, rbx, wedge
286  //Careful here: per Pawel's map, the rm fiber is the first entry an the rm itself is the second.
287 
288  //If iside == -1, switch top and bottom. Why?
289  if (iside == -1) {
290  S_side = '-';
291  sidesign = 'M';
292  irm = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][1];
293  irm_fi = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][0];
294 
295  //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
296  if (ieta >= 21 && (irm == 1 || irm == 3))
297  iwedge = (iphi + 1 + irm + 1) / 4;
298  else
299  iwedge = (iphi + irm + 1) / 4;
300 
301  //Roll over the wedge
302  if (iwedge > 18)
303  iwedge -= 18;
304  } else {
305  S_side = '+';
306  sidesign = 'P';
307  irm = irm_rmfiHBHE[ih][itb][ifb][1];
308  irm_fi = irm_rmfiHBHE[ih][itb][ifb][0];
309 
310  //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
311  if (ieta >= 21 && (irm == 4 || irm == 2))
312  iwedge = (iphi + 1 - irm + 6) / 4;
313  else
314  iwedge = (iphi - irm + 6) / 4;
315 
316  //Roll over the wedge
317  if (iwedge > 18)
318  iwedge -= 18;
319  }
320 
321  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
322  mystream << tempbuff;
323  rbx = mystream.str();
324  mystream.str("");
325 
326  //Note that irm_fi ranges from 2 to 7 whereas arrays start at 0 so
327  //I use irm_fi - 2. Likewise, irm goes from 1 to 4 so use irm - 1
328 
329  //Pixel is split by HB and HE
330  if (ieta > 16 || idepth > 2)
331  ipixel = ipixelHE[irm_fi - 2][ifc][irm - 1]; //HE
332  else
333  ipixel = ipixelHB[irm_fi - 2][ifc][irm - 1]; //HB
334 
335  iqie = iadcquiHBHE[irm_fi - 2][ifc][0];
336  iadc = iadcquiHBHE[irm_fi - 2][ifc][1];
337 
338  phideg = iphi - 3;
339  if (phideg < 0)
340  phideg = phideg + 72;
341  phideg = (phideg / 4) * 20 + 10;
342  irctcra = ((89 - phideg + 720) % 360) / 20;
343  oddcard = irctcra % 2;
344  irctcra /= 2;
345  if (iside > 0)
346  irctcra = irctcra + 9;
347 
348  etaslb = ((ieta - 1) / 2) * 2 + 1;
349  if (etaslb > 27)
350  etaslb = 27;
351 
352  snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
353  mystream << tempbuff;
354  slnam = mystream.str();
355  mystream.str("");
356 
357  islb = slb_table[ieta - 1];
358 
359  // calculate RCT destination (that is, rctcon, rctcar and rctnam
360  if (ieta <= 24) { // these are the normal cards 0-5
361  irctcar = 2 * ((ieta - 1) / 8) + oddcard;
362  irctcon = 2 * (((ieta - 1) / 2) % 4);
363  } else { // these are on the special card 6 which folds back eta on the odd card half
364  irctcar = 6;
365  eta2 = ieta;
366  if (eta2 > 28)
367  eta2 = 28;
368  if (oddcard == 0)
369  eta3 = eta2;
370  else
371  eta3 = 57 - eta2;
372  irctcon = 2 * (((eta3 - 1) / 2) % 4);
373  }
374  irctcon = 11 * irctcon + 1;
375 
376  snprintf(tempbuff, sizeof tempbuff, "%s-%1d-HD%2.2d", rct_rackHBHE[irctcra], irctcar, irctcon);
377  mystream << tempbuff;
378  rctnam = mystream.str();
379  mystream.str("");
380 
381  //Finally, the slbin
382 
383  phimod8 = iphi % 8;
384 
385  for (i = 0; i < 18; i++) {
386  if (iphi < i * 4 + 3) {
387  crazy = i % 2;
388  break;
389  }
390  }
391 
392  int ietamod; // determine if eta is "odd" or "even".
393  if (ieta == 29)
394  ietamod = 0;
395  else
396  ietamod = ieta % 2;
397  if (ieta < 25) { // use the regular table
398  if (ietamod == 1)
399  mystream << S_slbin_odd[phimod8];
400  else
401  mystream << S_slbin_even[phimod8];
402  } else if (crazy == 0) { // use the regular table
403  if (ietamod == 1)
404  mystream << S_slbin_odd[phimod8];
405  else
406  mystream << S_slbin_even[phimod8];
407  } else { // swap odd/even!!!
408  if (ietamod == 1)
409  mystream << S_slbin_even[phimod8];
410  else
411  mystream << S_slbin_odd[phimod8];
412  }
413 
414  slbin = mystream.str();
415  mystream.str("");
416 
417  if (ieta > 20) {
418  idphi = 2;
419  slbin2 = slbin;
420  slbin2[1] = '1';
421  } else {
422  idphi = 1;
423  slbin2 = "NA";
424  }
425 
426  HBHEHFLogicalMapEntry hbeflmapentry(ifi_ch,
427  ihtr_fi,
428  ispigot,
429  ifed,
430  icrate,
431  ihtr,
432  fpga,
433  det,
434  iside,
435  ieta,
436  iphi,
437  idepth,
438  idphi,
439  iwedge,
440  irm,
441  irm_fi,
442  ipixel,
443  iqie,
444  iadc,
445  islb,
446  irctcra,
447  irctcar,
448  irctcon,
449  rbx,
450  slbin,
451  slbin2,
452  slnam,
453  rctnam);
454  HBHEHFEntries.push_back(hbeflmapentry);
455  LinearIndex2Entry.at(hbeflmapentry.getLinearIndex()) =
456  HcalLogicalMap::makeEntryNumber(true, 0, HBHEHFEntries.size() - 1);
457 
458  const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
459  unsigned int denseId;
460  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenBarrel) {
461  denseId = topo->detId2denseIdHB(hgdi);
462  HbHash2Entry.at(denseId) = HBHEHFEntries.size();
463  }
464  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
465  denseId = topo->detId2denseIdHE(hgdi);
466  HeHash2Entry.at(denseId) = HBHEHFEntries.size();
467  }
468  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenForward) {
469  denseId = topo->detId2denseIdHF(hgdi);
470  HfHash2Entry.at(denseId) = HBHEHFEntries.size();
471  }
472 
473  ConstructTriggerTower(topo,
474  HTEntries,
475  iside,
476  ieta,
477  iphi,
478  idphi,
479  idepth,
480  det,
481  iwedge,
482  irm,
483  ipixel,
484  iqie,
485  iadc,
486  irm_fi,
487  ifi_ch,
488  icrate,
489  ihtr,
490  fpga,
491  ihtr_fi,
492  ispigot,
493  islb,
494  slbin,
495  slbin2,
496  slnam,
497  irctcra,
498  irctcar,
499  irctcon,
500  rctnam,
501  ifed);
502  }
503  }
504  }
505  }
506  }
507  }
508 
509  /********************/
510  /* HF crate numbering */
511  int hfcrate_loc[NHFCR] = {2, 9, 12};
512  memcpy(hfcrate, hfcrate_loc, sizeof(int) * NHFCR);
513  /* HF FED numbering of DCCs */
514  int fedhfnum_loc[NHFCR][2] = {{718, 719}, {720, 721}, {722, 723}};
515  memcpy(fedhfnum, fedhfnum_loc, sizeof(int) * NHFCR * 2);
516  /* iphi (lower) starting index for each HF crate */
517  int ihfphis_loc[NHFCR] = {3, 27, 51};
518  memcpy(ihfphis, ihfphis_loc, sizeof(int) * NHFCR);
519  /* ihfetadepth - unique HF {eta,depth} assignments per fiber and fiber channel */
520  int ihfetadepth_loc[NTOPBOT][NFBR][NFCH][2] = {{{{33, 1}, {31, 1}, {29, 1}}, /* top */
521  {{32, 1}, {30, 1}, {34, 1}},
522  {{33, 2}, {31, 2}, {29, 2}},
523  {{32, 2}, {30, 2}, {34, 2}},
524  {{34, 2}, {32, 2}, {30, 2}},
525  {{31, 2}, {29, 2}, {33, 2}},
526  {{34, 1}, {32, 1}, {30, 1}},
527  {{31, 1}, {29, 1}, {33, 1}}},
528  {{{41, 1}, {37, 1}, {35, 1}}, /* bot */
529  {{38, 1}, {36, 1}, {39, 1}},
530  {{41, 2}, {37, 2}, {35, 2}},
531  {{38, 2}, {36, 2}, {39, 2}},
532  {{40, 2}, {38, 2}, {36, 2}},
533  {{37, 2}, {35, 2}, {39, 2}},
534  {{40, 1}, {38, 1}, {36, 1}},
535  {{37, 1}, {35, 1}, {39, 1}}}};
536  memcpy(ihfetadepth, ihfetadepth_loc, sizeof(int) * NTOPBOT * NFBR * NFCH * 2);
537 
538  int irm_rmfiHF_loc[NHTRS][NTOPBOT][NFBR][2] = {
539  {{{1, 2}, {2, 2}, {3, 2}, {4, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}}, // HTR 0 top
540  {{5, 2}, {6, 2}, {7, 2}, {8, 2}, {5, 3}, {6, 3}, {7, 3}, {8, 3}}}, // HTR 0 bot
541  {{{1, 1}, {2, 1}, {3, 1}, {4, 1}, {1, 2}, {2, 2}, {3, 2}, {4, 2}}, // HTR 1 top
542  {{5, 1}, {6, 1}, {7, 1}, {8, 1}, {5, 2}, {6, 2}, {7, 2}, {8, 2}}}, // HTR 1 bot
543  {{{1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 1}, {2, 1}, {3, 1}, {4, 1}}, // HTR 2 top
544  {{5, 3}, {6, 3}, {7, 3}, {8, 3}, {5, 1}, {6, 1}, {7, 1}, {8, 1}}} // HTR 2 bot
545  };
546  memcpy(irm_rmfiHF, irm_rmfiHF_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * 2);
547 
548  //HF
549  const char* S_slbin_7_loc[] = {"A0", "A1", "B0", "B1"};
550  for (int gg = 0; gg < 4; gg++) {
551  S_slbin_7[gg] = S_slbin_7_loc[gg];
552  }
553  const char* S_slbin_3_loc[] = {"C0", "C1", "D0", "D1"};
554  for (int gg = 0; gg < 4; gg++) {
555  S_slbin_3[gg] = S_slbin_3_loc[gg];
556  }
557  const char* rct_rackHF_loc[] = {"S2E01-FH",
558  "S2E03-FH",
559  "S2E05-FH",
560  "S2E07-FH",
561  "S2E09-FH",
562  "S2E08-FL",
563  "S2E06-FL",
564  "S2E04-FL",
565  "S2E02-FL",
566  "S2E02-FH",
567  "S2E04-FH",
568  "S2E06-FH",
569  "S2E08-FH",
570  "S2E09-FL",
571  "S2E07-FL",
572  "S2E05-FL",
573  "S2E03-FL",
574  "S2E01-FL"};
575  for (int gg = 0; gg < 18; gg++) {
576  rct_rackHF[gg] = rct_rackHF_loc[gg];
577  }
578 
579  /***************/
580 
581  /* all HF crates */
582  for (ic = 0; ic < NHFCR; ic++) {
583  /* four sets of three htrs per crate */
584  for (is = 0; is < NHSETS; is++) {
585  /* three htrs per set */
586  for (ih = 0; ih < NHTRS; ih++) {
587  /* top and bottom */
588  for (itb = 0; itb < NTOPBOT; itb++) {
589  /* eight fibers per HTR FPGA */
590  for (ifb = 0; ifb < NFBR; ifb++) {
591  /* three channels per fiber */
592  for (ifc = 0; ifc < NFCH; ifc++) {
593  icrate = hfcrate[ic];
594  iside = is < NHSETS / 2 ? -1 : 1;
595  ieta = ihfetadepth[itb][ifb][ifc][0];
596  idepth = ihfetadepth[itb][ifb][ifc][1];
597  ihtr = ihslot[is] + ih;
598  det = "HF";
599  (itb % 2) == 1 ? fpga = "bot" : fpga = "top";
600  ihtr_fi = ifb + 1;
601  ifi_ch = ifc;
602  iphi = (ieta > 39) ? (ihfphis[ic] + (is % 2) * 12 + ih * 4 - 1) % 72 + 1
603  : (ihfphis[ic] + (is % 2) * 12 + ih * 4 + (ifb / 4) * 2 - 1) % 72 + 1;
604  ispigot = (is % 2) * 6 + ih * 2 + itb;
605  idcc = is < NHSETS / 2 ? 1 : 2;
606  idcc_sl = idcc == 1 ? 10 : 20;
607  ifed = fedhfnum[ic][idcc - 1];
608 
609  irm_fi = irm_rmfiHF[ih][itb][ifb][0];
610 
611  //Don't switch in the HF. Why?
612  if (iside == -1) {
613  S_side = '-';
614  sidesign = 'M';
615 
616  if (ieta < 40) {
617  if (iphi == 1)
618  iphi = 71;
619  else if (iphi == 71)
620  iphi = 1;
621  else if (iphi % 4 == 1)
622  iphi -= 2;
623  else if (iphi % 4 == 3)
624  iphi += 2;
625  else
626  edm::LogInfo("HcalLogicalMapGenerator") << "Even iphi in HFM" << endl;
627  }
628  } else {
629  S_side = '+';
630  sidesign = 'P';
631  }
632 
633  //RM and RBX number
634  if ((iside == 1 && ieta == 40) || (iside == -1 && ieta == 41)) {
635  irm = ((iphi + 1) / 2) % 36 + 1;
636  hfphi = ((iphi + 1) / 6) % 12 + 1;
637  } else {
638  irm = (iphi + 1) / 2;
639  hfphi = (iphi - 1) / 6 + 1;
640  }
641  irm = (irm - 1) % 3 + 1;
642 
643  //Wedge
644  if (iphi >= 71)
645  iwedge = 1;
646  else
647  iwedge = (iphi + 1) / 4 + 1;
648 
649  //RBX
650  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, hfphi);
651  mystream << tempbuff;
652  rbx = mystream.str();
653  mystream.str("");
654 
655  //No pixel in HF, follow Fedor's convention
656  ipixel = 0;
657 
658  //Integer truncation again consistent with Fedor's map.
659  iqie = (irm_fi - 1) / 2 + 1;
660 
661  if (irm_fi % 2 != 0)
662  iadc = ifi_ch;
663  else
664  iadc = NFCH + (ifi_ch + 1) % 3;
665 
666  //slb and rct variables
667  //rctcrate
668  phideg = iphi - 3;
669  if (phideg < 0)
670  phideg = phideg + 72;
671  phideg = (phideg / 4) * 20 + 10;
672  irctcra = ((89 - phideg + 720) % 360) / 40;
673  if (iside > 0)
674  irctcra = irctcra + 9;
675 
676  //rct card and rct connector appear to be dummy here -- again, I follow Fedor's convention
677  irctcar = 99;
678  irctcon = 0;
679 
680  etaslb = 29;
681 
682  snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
683  mystream << tempbuff;
684  slnam = mystream.str();
685  mystream.str("");
686 
687  snprintf(tempbuff, sizeof tempbuff, "%s-JSC-HF_IN", rct_rackHF[irctcra]);
688  mystream << tempbuff;
689  rctnam = mystream.str();
690  mystream.str("");
691 
692  islb = 6;
693 
694  int phibin = (iphi + 1) % 8;
695  int etabin = (ieta - 29) / 3;
696  if (etabin < 0)
697  etabin = 0;
698  if (etabin > 3)
699  etabin = 3;
700  if (phibin < 4)
701  mystream << S_slbin_7[etabin];
702  else
703  mystream << S_slbin_3[etabin];
704 
705  slbin = mystream.str();
706  mystream.str("");
707 
708  slbin2 = "NA";
709 
710  if (ieta < 40)
711  idphi = 2;
712  else
713  idphi = 4;
714 
715  HBHEHFLogicalMapEntry hbeflmapentry(ifi_ch,
716  ihtr_fi,
717  ispigot,
718  ifed,
719  icrate,
720  ihtr,
721  fpga,
722  det,
723  iside,
724  ieta,
725  iphi,
726  idepth,
727  idphi,
728  iwedge,
729  irm,
730  irm_fi,
731  ipixel,
732  iqie,
733  iadc,
734  islb,
735  irctcra,
736  irctcar,
737  irctcon,
738  rbx,
739  slbin,
740  slbin2,
741  slnam,
742  rctnam);
743  HBHEHFEntries.push_back(hbeflmapentry);
744  LinearIndex2Entry.at(hbeflmapentry.getLinearIndex()) =
745  HcalLogicalMap::makeEntryNumber(true, 0, HBHEHFEntries.size() - 1);
746 
747  const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
748  unsigned int denseId;
749  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenBarrel) {
750  denseId = topo->detId2denseIdHB(hgdi);
751  HbHash2Entry.at(denseId) = HBHEHFEntries.size();
752  }
753  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
754  denseId = topo->detId2denseIdHE(hgdi);
755  HeHash2Entry.at(denseId) = HBHEHFEntries.size();
756  }
757  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenForward) {
758  denseId = topo->detId2denseIdHF(hgdi);
759  HfHash2Entry.at(denseId) = HBHEHFEntries.size();
760  }
761 
762  ConstructTriggerTower(topo,
763  HTEntries,
764  iside,
765  ieta,
766  iphi,
767  idphi,
768  idepth,
769  det,
770  iwedge,
771  irm,
772  ipixel,
773  iqie,
774  iadc,
775  irm_fi,
776  ifi_ch,
777  icrate,
778  ihtr,
779  fpga,
780  ihtr_fi,
781  ispigot,
782  islb,
783  slbin,
784  slbin2,
785  slnam,
786  irctcra,
787  irctcar,
788  irctcon,
789  rctnam,
790  ifed);
791  }
792  }
793  }
794  }
795  }
796  }
797 }
798 
800  std::vector<HOHXLogicalMapEntry>& HOHXEntries,
801  std::vector<uint32_t>& LinearIndex2Entry,
802  std::vector<uint32_t>& HoHash2Entry,
803  std::vector<uint32_t>& HxCalibHash2Entry) {
804  /******************************/
805  /* HO crate numbering */
806  int hocrate_loc[NHOCR] = {3, 7, 6, 13};
807  memcpy(hocrate, hocrate_loc, sizeof(int) * NHOCR);
808  /* HO FED numbering of DCCs */
809  int fedhonum_loc[NHOCR][2] = {{724, 725}, {726, 727}, {728, 729}, {730, 731}};
810  memcpy(fedhonum, fedhonum_loc, sizeof(int) * NHOCR * 2);
811  /* HO htr slot offsets for three sets of four htrs */
812  int ihslotho_loc[NHSETSHO][NHTRSHO] = {{2, 3, 4, 5}, {6, 7, 13, 14}, {15, 16, 17, 18}};
813  memcpy(ihslotho, ihslotho_loc, sizeof(int) * NHSETSHO * NHTRSHO);
814  /* iphi (lower) starting index for each HO crate */
815  int ihophis_loc[NHOCR] = {71, 17, 35, 53};
816  memcpy(ihophis, ihophis_loc, sizeof(int) * NHOCR);
817 
818  //RM for the HO as a function of eta, phi and side as implemented in complete_ho_map.txt
819  //There are only 24 phi columns because after that it begins to repeat. The relevant variable is phi mod 24.
820  //HX as the 16th eta entry
821  int HO_RM_table_loc[24][16][2] = {{{2, 2},
822  {2, 2},
823  {2, 2},
824  {2, 2},
825  {2, 2},
826  {2, 2},
827  {2, 2},
828  {2, 2},
829  {2, 2},
830  {2, 2},
831  {4, 2},
832  {4, 2},
833  {4, 2},
834  {4, 2},
835  {4, 2},
836  {4, 2}},
837  {{2, 2},
838  {2, 2},
839  {2, 2},
840  {2, 2},
841  {4, 4},
842  {4, 4},
843  {4, 4},
844  {4, 4},
845  {4, 4},
846  {4, 4},
847  {2, 4},
848  {2, 4},
849  {2, 4},
850  {2, 4},
851  {2, 4},
852  {2, 4}},
853  {{3, 3},
854  {3, 3},
855  {3, 3},
856  {3, 3},
857  {4, 4},
858  {4, 4},
859  {4, 4},
860  {4, 4},
861  {4, 4},
862  {4, 4},
863  {2, 4},
864  {2, 4},
865  {2, 4},
866  {2, 4},
867  {2, 4},
868  {2, 4}},
869  {{3, 3},
870  {3, 3},
871  {3, 3},
872  {3, 3},
873  {4, 4},
874  {4, 4},
875  {4, 4},
876  {4, 4},
877  {4, 4},
878  {4, 4},
879  {2, 4},
880  {2, 4},
881  {2, 4},
882  {2, 4},
883  {2, 4},
884  {2, 4}},
885  {{4, 4},
886  {4, 4},
887  {4, 4},
888  {4, 4},
889  {3, 3},
890  {3, 3},
891  {3, 3},
892  {3, 3},
893  {3, 3},
894  {3, 3},
895  {1, 3},
896  {1, 3},
897  {1, 3},
898  {1, 3},
899  {1, 3},
900  {1, 3}},
901  {{4, 4},
902  {4, 4},
903  {4, 4},
904  {4, 4},
905  {3, 3},
906  {3, 3},
907  {3, 3},
908  {3, 3},
909  {3, 3},
910  {3, 3},
911  {1, 3},
912  {1, 3},
913  {1, 3},
914  {1, 3},
915  {1, 3},
916  {1, 3}},
917  {{3, 3},
918  {3, 3},
919  {3, 3},
920  {3, 3},
921  {3, 3},
922  {3, 3},
923  {3, 3},
924  {3, 3},
925  {3, 3},
926  {3, 3},
927  {1, 3},
928  {1, 3},
929  {1, 3},
930  {1, 3},
931  {1, 3},
932  {1, 3}},
933  {{3, 3},
934  {3, 3},
935  {3, 3},
936  {3, 3},
937  {1, 1},
938  {1, 1},
939  {1, 1},
940  {1, 1},
941  {1, 1},
942  {1, 1},
943  {3, 1},
944  {3, 1},
945  {3, 1},
946  {3, 1},
947  {3, 1},
948  {3, 1}},
949  {{2, 2},
950  {2, 2},
951  {2, 2},
952  {2, 2},
953  {1, 1},
954  {1, 1},
955  {1, 1},
956  {1, 1},
957  {1, 1},
958  {1, 1},
959  {3, 1},
960  {3, 1},
961  {3, 1},
962  {3, 1},
963  {3, 1},
964  {3, 1}},
965  {{2, 2},
966  {2, 2},
967  {2, 2},
968  {2, 2},
969  {1, 1},
970  {1, 1},
971  {1, 1},
972  {1, 1},
973  {1, 1},
974  {1, 1},
975  {3, 1},
976  {3, 1},
977  {3, 1},
978  {3, 1},
979  {3, 1},
980  {3, 1}},
981  {{4, 4},
982  {4, 4},
983  {4, 4},
984  {4, 4},
985  {2, 2},
986  {2, 2},
987  {2, 2},
988  {2, 2},
989  {2, 2},
990  {2, 2},
991  {4, 2},
992  {4, 2},
993  {4, 2},
994  {4, 2},
995  {4, 2},
996  {4, 2}},
997  {{4, 4},
998  {4, 4},
999  {4, 4},
1000  {4, 4},
1001  {2, 2},
1002  {2, 2},
1003  {2, 2},
1004  {2, 2},
1005  {2, 2},
1006  {2, 2},
1007  {4, 2},
1008  {4, 2},
1009  {4, 2},
1010  {4, 2},
1011  {4, 2},
1012  {4, 2}},
1013  {{3, 3},
1014  {3, 3},
1015  {3, 3},
1016  {3, 3},
1017  {2, 2},
1018  {2, 2},
1019  {2, 2},
1020  {2, 2},
1021  {2, 2},
1022  {2, 2},
1023  {4, 2},
1024  {4, 2},
1025  {4, 2},
1026  {4, 2},
1027  {4, 2},
1028  {4, 2}},
1029  {{3, 3},
1030  {3, 3},
1031  {3, 3},
1032  {3, 3},
1033  {4, 4},
1034  {4, 4},
1035  {4, 4},
1036  {4, 4},
1037  {4, 4},
1038  {4, 4},
1039  {2, 4},
1040  {2, 4},
1041  {2, 4},
1042  {2, 4},
1043  {2, 4},
1044  {2, 4}},
1045  {{2, 2},
1046  {2, 2},
1047  {2, 2},
1048  {2, 2},
1049  {4, 4},
1050  {4, 4},
1051  {4, 4},
1052  {4, 4},
1053  {4, 4},
1054  {4, 4},
1055  {2, 4},
1056  {2, 4},
1057  {2, 4},
1058  {2, 4},
1059  {2, 4},
1060  {2, 4}},
1061  {{2, 2},
1062  {2, 2},
1063  {2, 2},
1064  {2, 2},
1065  {4, 4},
1066  {4, 4},
1067  {4, 4},
1068  {4, 4},
1069  {4, 4},
1070  {4, 4},
1071  {2, 4},
1072  {2, 4},
1073  {2, 4},
1074  {2, 4},
1075  {2, 4},
1076  {2, 4}},
1077  {{1, 1},
1078  {1, 1},
1079  {1, 1},
1080  {1, 1},
1081  {3, 3},
1082  {3, 3},
1083  {3, 3},
1084  {3, 3},
1085  {3, 3},
1086  {3, 3},
1087  {1, 3},
1088  {1, 3},
1089  {1, 3},
1090  {1, 3},
1091  {1, 3},
1092  {1, 3}},
1093  {{1, 1},
1094  {1, 1},
1095  {1, 1},
1096  {1, 1},
1097  {3, 3},
1098  {3, 3},
1099  {3, 3},
1100  {3, 3},
1101  {3, 3},
1102  {3, 3},
1103  {1, 3},
1104  {1, 3},
1105  {1, 3},
1106  {1, 3},
1107  {1, 3},
1108  {1, 3}},
1109  {{2, 2},
1110  {2, 2},
1111  {2, 2},
1112  {2, 2},
1113  {3, 3},
1114  {3, 3},
1115  {3, 3},
1116  {3, 3},
1117  {3, 3},
1118  {3, 3},
1119  {1, 3},
1120  {1, 3},
1121  {1, 3},
1122  {1, 3},
1123  {1, 3},
1124  {1, 3}},
1125  {{2, 2},
1126  {2, 2},
1127  {2, 2},
1128  {2, 2},
1129  {1, 1},
1130  {1, 1},
1131  {1, 1},
1132  {1, 1},
1133  {1, 1},
1134  {1, 1},
1135  {3, 1},
1136  {3, 1},
1137  {3, 1},
1138  {3, 1},
1139  {3, 1},
1140  {3, 1}},
1141  {{3, 3},
1142  {3, 3},
1143  {3, 3},
1144  {3, 3},
1145  {1, 1},
1146  {1, 1},
1147  {1, 1},
1148  {1, 1},
1149  {1, 1},
1150  {1, 1},
1151  {3, 1},
1152  {3, 1},
1153  {3, 1},
1154  {3, 1},
1155  {3, 1},
1156  {3, 1}},
1157  {{3, 3},
1158  {3, 3},
1159  {3, 3},
1160  {3, 3},
1161  {1, 1},
1162  {1, 1},
1163  {1, 1},
1164  {1, 1},
1165  {1, 1},
1166  {1, 1},
1167  {3, 1},
1168  {3, 1},
1169  {3, 1},
1170  {3, 1},
1171  {3, 1},
1172  {3, 1}},
1173  {{1, 1},
1174  {1, 1},
1175  {1, 1},
1176  {1, 1},
1177  {2, 2},
1178  {2, 2},
1179  {2, 2},
1180  {2, 2},
1181  {2, 2},
1182  {2, 2},
1183  {4, 2},
1184  {4, 2},
1185  {4, 2},
1186  {4, 2},
1187  {4, 2},
1188  {4, 2}},
1189  {{1, 1},
1190  {1, 1},
1191  {1, 1},
1192  {1, 1},
1193  {2, 2},
1194  {2, 2},
1195  {2, 2},
1196  {2, 2},
1197  {2, 2},
1198  {2, 2},
1199  {4, 2},
1200  {4, 2},
1201  {4, 2},
1202  {4, 2},
1203  {4, 2},
1204  {4, 2}}};
1205  memcpy(HO_RM_table, HO_RM_table_loc, sizeof(int) * 24 * 16 * 2);
1206 
1207  //For |eta| 5 to 15, rm_fi is a function of |eta| only while htr_fi is a function of side and |eta|
1208  int HO_RM_fi_eta5to15_loc[11] = {3, 2, 5, 4, 7, 6, 3, 2, 5, 4, 7};
1209  memcpy(HO_RM_fi_eta5to15, HO_RM_fi_eta5to15_loc, sizeof(int) * 11);
1210  //For eta=16 it is 6, declared in the header
1211  HO_RM_fi_eta16 = 6;
1212  //For eta in the YB0 region, rm_fi is dependent on side, 4 for -1, and 5 for +1
1213  //but the values won't be any different than when the regular loop is executed
1214  //int HO_RM_fi_etaYB0[2] = {4, 5}
1215 
1216  //For |eta| 1 to 4, it is a function of phi, eta and side. eta 1-3 always have the same value given a side,
1217  //eta 4 is separate and thus gets its own box
1218  //threefold symmetry in iphi, repeats every three groups of 8 i.e., 1to8 == 25to32 == 49to56,
1219  //similarly for the other iphi groups
1220  //[iphi][ieta 1-3/4][side m/p]
1221  //Actually has more modular structure which is not repetitive cyclicly
1222  // groups of 4 in iphi repeat 1to4 == 17to20 == 21to24
1223  // groups of 4 in iphi repeat 5to8 == 9to12 == 13to16
1224  int HO_RM_fi_eta1to4_loc[24][2][2] = {
1225  //side = -1 side = 1
1226  {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{2, 6}, {5, 4}},
1227  {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, //Phi 1 to 8, Phi 25 to 32, Phi 49 to 56
1228  {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}},
1229  {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, //Phi 9 to 16, Phi 33 to 40, Phi 57 to 64
1230  {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}},
1231  {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}} //Phi 17 to 24, Phi 41 to 48, Phi 65 to 72
1232  };
1233  memcpy(HO_RM_fi_eta1to4, HO_RM_fi_eta1to4_loc, sizeof(int) * 24 * 2 * 2);
1234 
1235  /* new mapping with SiPMs in HO ring-0 */
1236  //The mapping is different for HO ring-0 with HPDs (above) or SiPMs (here)
1237  // as the SiPM mapping is not cyclic in the same way as before
1238  //[iphi][ieta][side m/p]
1239  //threefold symmetry in iphi, repeats every three lines i.e., 1to8 == 25to32 == 49to56,
1240  //similarly for the other iphi groups
1241  //(iphi-1)mod(24)
1242  //ieta4,rm_fi5,fi_ch1 5 -> 3:{minus:evenphi,plus:oddphi}
1243  //ieta4,rm_fi5,fi_ch2 5 -> 2:{minus:oddphi,plus:evenphi}
1244  int HO_RM_fi_eta1to4_sipm_loc[24][4][2] = {
1245  //side = -1 side = 1
1246  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1247  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}}, //Phi 1 to 4
1248  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1249  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}}, //Phi 5 to 8
1250  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1251  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}}, //Phi 9 to 12
1252  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1253  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}}, //Phi 13 to 16
1254  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1255  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}}, //Phi 17 to 20
1256  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1257  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}}, //Phi 21 to 24
1258  };
1259  memcpy(HO_RM_fi_eta1to4_sipm, HO_RM_fi_eta1to4_sipm_loc, sizeof(int) * 24 * 4 * 2);
1260 
1261  // htr_fi
1262  int HO_htr_fi_450eta5to15_loc[2][11] = {{2, 2, 4, 6, 8, 2, 4, 6, 8, 4, 6}, //iside = -1
1263  {2, 8, 6, 4, 2, 8, 6, 4, 2, 4, 2}}; //iside = +1
1264  memcpy(HO_htr_fi_450eta5to15, HO_htr_fi_450eta5to15_loc, sizeof(int) * 2 * 11);
1265  // for the minus side, htr_fi is determined by the RM, will have to shift up one since rm is
1266  //numbered 1-4 not 0-3
1267  int HO_htr_fi_450eta16M_loc[4] = {7, 7, 8, 8}; //iside = -1
1268  memcpy(HO_htr_fi_450eta16M, HO_htr_fi_450eta16M_loc, sizeof(int) * 4);
1269  //For the plus side, there is a new htr so all values can be used, but only 6 are used
1270  //Depend on phi, but also on rm and sector (2,4,6,8,10,12)
1271  int HO_htr_fi_450eta16P_loc[4][6] = {
1272  {4, 2, 4, 4, 2, 6}, {2, 6, 6, 2, 6, 4}, {5, 3, 5, 5, 3, 7}, {3, 7, 7, 3, 7, 5}}; //iside = +1
1273  memcpy(HO_htr_fi_450eta16P, HO_htr_fi_450eta16P_loc, sizeof(int) * 4 * 6);
1274 
1275  //for |eta| <= 4, htr_fi is a function of side and phmod6
1276  int HO_htr_fi_eta4_loc[2][6] = {{6, 6, 8, 8, 7, 7}, //iside = -1
1277  {4, 4, 5, 5, 3, 3}}; //iside = +1
1278  if (mapIOV_ < 5)
1279  memcpy(HO_htr_fi_eta4, HO_htr_fi_eta4_loc, sizeof(int) * 2 * 6);
1280 
1281  int HO_htr_fi_eta123_loc[2][6] = {{6, 5, 4, 3, 8, 7}, //iside = -1
1282  {8, 7, 6, 5, 2, 1}}; //iside = +1
1283  if (mapIOV_ < 5)
1284  memcpy(HO_htr_fi_eta123, HO_htr_fi_eta123_loc, sizeof(int) * 2 * 6);
1285 
1286  //HO_htr_fi_123eta5to15[2][11] is unnecessary because
1287  // HO_htr_fi_123eta5to15[i][j] == int HO_htr_fi_450eta5to15[i][j] - 1
1288 
1289  //post SiPM card swap
1290  // htr_fi is a function of phmod6,eta,rm,side
1291  // rm is a function of phimod6: rm = 1,4 for phimod6 > 3, and 2,3 otherwise
1292  // to index the array, take rm/2 integer division
1293  // cross-talk channels are separate
1294  int HO_htr_fi_eta1234_sipm[6][5][2][2] = {
1295  {/*eta==1*/ /*eta==2*/ /*eta==3*/ /*eta==4*/ /*cross-talk*/
1296  {{4, 8}, {6, 4}},
1297  {{4, 4}, {4, 7}},
1298  {{6, 8}, {6, 7}},
1299  {{5, 8}, {6, 8}},
1300  {{5, 6}, {-1, -1}}}, //phm6==0
1301  {{{6, 7}, {5, 6}}, {{6, 6}, {6, 6}}, {{6, 7}, {5, 7}}, {{5, 7}, {5, 8}}, {{-1, -1}, {4, 8}}}, //phm6==1
1302  {{{4, 5}, {5, 6}}, {{5, 5}, {5, 5}}, {{4, 5}, {4, 6}}, {{4, 6}, {3, 6}}, {{-1, -1}, {3, 8}}}, //phm6==2
1303  {{{3, 8}, {8, 5}}, {{8, 8}, {4, 8}}, {{3, 5}, {4, 5}}, {{3, 6}, {3, 5}}, {{5, 6}, {-1, -1}}}, //phm6==3
1304  {
1305  {{3, 2}, {8, 3}},
1306  {{3, 3}, {3, 1}},
1307  {{8, 2}, {8, 1}},
1308  {{7, 2}, {8, 2}},
1309  {{7, 7}, {-1, -1}}}, //phm6==4
1310  {{{7, 1}, {7, 7}}, {{8, 7}, {7, 7}}, {{8, 1}, {7, 1}}, {{7, 1}, {7, 2}}, {{-1, -1}, {3, 2}}}, //phm6==5
1311  };
1312 
1313  // Pixel and letter code for HO.
1314  // Ring 0 is separate and goes into entry 0, Rings +/- 1,2 are all the same and go to entry 1.
1315  // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 4, pixel = 18, let_code = X
1316  // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 5, pixel = 2, let_code = X
1317  // Fiber Channel 0 1 2
1318  int ipixelHO_loc[NRMFIBR][NFCH][2] = {{{12, 12}, {7, 7}, {6, 3}}, //RM fiber 2
1319  {{4, 4}, {8, 8}, {5, 1}}, //RM fiber 3
1320  {{19, 11}, {18, 6}, {17, 2}}, //RM fiber 4
1321  {{2, 9}, {1, 13}, {3, 5}}, //RM fiber 5
1322  {{11, 19}, {16, 18}, {15, 17}}, //RM fiber 6
1323  {{13, 15}, {9, 14}, {14, 16}}}; //RM fiber 7
1324  //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
1325  int ipixelHO_sipm[NRMFIBR][NFCH][2] = {{{12, 12}, {7, 7}, {3, 3}}, //RM fibers 2
1326  {{4, 4}, {8, 8}, {1, 1}}, //RM fibers 3
1327  {{11, 11}, {6, 6}, {2, 2}}, //RM fibers 4
1328  {{9, 9}, {13, 13}, {5, 5}}, //RM fibers 5
1329  {{19, 19}, {18, 18}, {17, 17}}, //RM fibers 6
1330  {{15, 15}, {14, 14}, {16, 16}}}; //RM fibers 7
1331  if (mapIOV_ < 5)
1332  memcpy(ipixelHO, ipixelHO_loc, sizeof(int) * NRMFIBR * NFCH * 2);
1333  else
1334  memcpy(ipixelHO, ipixelHO_sipm, sizeof(int) * NRMFIBR * NFCH * 2);
1335 
1336  // Fiber Channel 0 1 2
1337  std::string letterHO_loc[NRMFIBR][NFCH][2] = {{{"E", "E"}, {"G", "L"}, {"F", "S"}}, //RM fiber 2
1338  {{"Q", "M"}, {"N", "T"}, {"P", "F"}}, //RM fiber 3
1339  {{"A", "C"}, {"X", "J"}, {"J", "Q"}}, //RM fiber 4
1340  {{"X", "K"}, {"R", "R"}, {"H", "D"}}, //RM fiber 5
1341  {{"D", "A"}, {"C", "G"}, {"B", "N"}}, //RM fiber 6
1342  {{"L", "H"}, {"M", "P"}, {"K", "B"}}}; //RM fiber 7
1343  //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
1344  std::string letterHO_sipm[NRMFIBR][NFCH][2] = {{{"E", "E"}, {"G", "L"}, {"H", "S"}}, //RM fibers 2
1345  {{"Q", "M"}, {"N", "T"}, {"R", "F"}}, //RM fibers 3
1346  {{"D", "C"}, {"F", "J"}, {"X", "Q"}}, //RM fibers 4
1347  {{"M", "K"}, {"L", "R"}, {"P", "D"}}, //RM fibers 5
1348  {{"A", "A"}, {"X", "G"}, {"J", "N"}}, //RM fibers 6
1349  {{"B", "H"}, {"K", "P"}, {"C", "B"}}}; //RM fibers 7
1350 
1351  for (int jj = 0; jj < NRMFIBR; jj++) {
1352  for (int kk = 0; kk < NFCH; kk++) {
1353  for (int ll = 0; ll < 2; ll++) {
1354  if (mapIOV_ < 5)
1355  letterHO[jj][kk][ll] = letterHO_loc[jj][kk][ll];
1356  else
1357  letterHO[jj][kk][ll] = letterHO_sipm[jj][kk][ll];
1358  }
1359  }
1360  }
1361 
1362  /******************************************************************************************/
1363  // Here is the section that deals with the miscabled HO RBXs.
1364  // To modify the code between IOVs, just note that inverted corresponds to -infinity to end of 2008
1365  // and otherwise, to 2009 to infinity.
1366  // Except for some small but major caveats:
1367  // HO2M04 (phi=16) was not able to be corrected, thus it is still inverted
1368  // HO2M06 (phi=31) has not been active in 2009, and the cables have not been switched officially
1369  // HO2P12 (phi=67) has not been active in 2009, and the cables have not been switched officially
1370  // In the map, the inactive RBXs have been switched since the changes will be effected when the HO SiPMs
1371  // are installed, also at that time, if it is possible, HO2M04 will be corrected as well.
1372  // Following intervention in May 2009, the aforementioned changes have been implemented.
1373  // All miscablings have been corrected
1374 
1375  // switched HO RM's need reversed eta values
1376  if (mapIOV_ == 1) {
1377  int rmspecialeta_loc[6][6] = {
1378  //there are 6 special cases, corresponding to 6 values of phi
1379  {14, 15, 14, 13, 12, 11}, // ring +2 phi = 5, inverted
1380  {14, 15, 14, 13, 12, 11}, // ring +2 phi = 67, inverted
1381  {10, 9, 8, 7, 6, 5}, // ring -1 phi = 57, inverted
1382  {10, 9, 8, 7, 6, 5}, // ring -1 phi = 65, inverted
1383  {14, 15, 14, 13, 12, 11}, // ring -2 phi = 16, inverted
1384  {14, 15, 14, 13, 12, 11} // ring -2 phi = 31, inverted
1385  };
1386 
1387  std::string rmspeciallet_code_loc[6][6] = {
1388  //there are 6 special cases, corresponding to 6 values of phi
1389  {"X", "B", "C", "D", "E", "F"}, // ring +2 phi = 5, inverted
1390  {"X", "P", "Q", "R", "S", "T"}, // ring +2 phi = 67, inverted
1391  {"G", "H", "J", "K", "L", "M"}, // ring -1 phi = 57, inverted
1392  {"A", "B", "C", "D", "E", "F"}, // ring -1 phi = 65, inverted
1393  {"X", "B", "C", "D", "E", "F"}, // ring -2 phi = 16, inverted
1394  {"X", "P", "Q", "R", "S", "T"} // ring -2 phi = 31, inverted
1395  };
1396 
1397  std::string rmspecialdet_loc[6][6] = {
1398  //there are 6 special cases, corresponding to 6 values of phi
1399  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring +2 phi = 5, inverted
1400  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring +2 phi = 67, inverted
1401  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 57, inverted
1402  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 65, inverted
1403  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring -2 phi = 16, inverted
1404  {"HOX", "HO", "HO", "HO", "HO", "HO"} // ring -2 phi = 31, inverted
1405  };
1406 
1407  memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1408  // switched HO RM's need revised letter codes
1409 
1410  for (int jj = 0; jj < 6; jj++) {
1411  for (int kk = 0; kk < 6; kk++) {
1412  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1413  }
1414  }
1415 
1416  for (int jj = 0; jj < 6; jj++) {
1417  for (int kk = 0; kk < 6; kk++) {
1418  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1419  }
1420  }
1421  }
1422 
1423  else if (mapIOV_ == 2) {
1424  int rmspecialeta_loc[6][6] = {
1425  //there are 6 special cases, corresponding to 6 values of phi
1426  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 5
1427  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 67
1428  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 57
1429  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 65
1430  {14, 15, 14, 13, 12, 11}, // ring -2 phi = 16, still inverted
1431  {11, 12, 13, 14, 15, 15} // ring -2 phi = 31
1432  };
1433 
1434  std::string rmspeciallet_code_loc[6][6] = {
1435  //there are 6 special cases, corresponding to 6 values of phi
1436  {"F", "E", "D", "C", "B", "X"}, // ring +2 phi = 5
1437  {"T", "S", "R", "Q", "P", "X"}, // ring +2 phi = 67
1438  {"M", "L", "K", "J", "H", "G"}, // ring -1 phi = 57
1439  {"F", "E", "D", "C", "B", "A"}, // ring -1 phi = 65
1440  {"X", "B", "C", "D", "E", "F"}, // ring -2 phi = 16,still inverted
1441  {"T", "S", "R", "Q", "P", "X"} // ring -2 phi = 31
1442  };
1443 
1444  std::string rmspecialdet_loc[6][6] = {
1445  //there are 6 special cases, corresponding to 6 values of phi
1446  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 5
1447  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 67
1448  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 57
1449  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 65
1450  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring -2 phi = 16, still inverted
1451  {"HO", "HO", "HO", "HO", "HO", "HOX"} // ring -2 phi = 31
1452  };
1453 
1454  memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1455  // switched HO RM's need revised letter codes
1456 
1457  for (int jj = 0; jj < 6; jj++) {
1458  for (int kk = 0; kk < 6; kk++) {
1459  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1460  }
1461  }
1462 
1463  for (int jj = 0; jj < 6; jj++) {
1464  for (int kk = 0; kk < 6; kk++) {
1465  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1466  }
1467  }
1468  }
1469 
1470  else {
1471  int rmspecialeta_loc[6][6] = {
1472  //there are 6 special cases, corresponding to 6 values of phi
1473  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 5
1474  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 67
1475  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 57
1476  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 65
1477  {11, 12, 13, 14, 15, 15}, // ring -2 phi = 16
1478  {11, 12, 13, 14, 15, 15} // ring -2 phi = 31
1479  };
1480 
1481  std::string rmspeciallet_code_loc[6][6] = {
1482  //there are 6 special cases, corresponding to 6 values of phi
1483  {"F", "E", "D", "C", "B", "X"}, // ring +2 phi = 5
1484  {"T", "S", "R", "Q", "P", "X"}, // ring +2 phi = 67
1485  {"M", "L", "K", "J", "H", "G"}, // ring -1 phi = 57
1486  {"F", "E", "D", "C", "B", "A"}, // ring -1 phi = 65
1487  {"F", "E", "D", "C", "B", "X"}, // ring -2 phi = 16
1488  {"T", "S", "R", "Q", "P", "X"} // ring -2 phi = 31
1489  };
1490 
1491  std::string rmspecialdet_loc[6][6] = {
1492  //there are 6 special cases, corresponding to 6 values of phi
1493  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 5
1494  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 67
1495  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 57
1496  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 65
1497  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring -2 phi = 16
1498  {"HO", "HO", "HO", "HO", "HO", "HOX"} // ring -2 phi = 31
1499  };
1500 
1501  memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1502  // switched HO RM's need revised letter codes
1503 
1504  for (int jj = 0; jj < 6; jj++) {
1505  for (int kk = 0; kk < 6; kk++) {
1506  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1507  }
1508  }
1509 
1510  for (int jj = 0; jj < 6; jj++) {
1511  for (int kk = 0; kk < 6; kk++) {
1512  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1513  }
1514  }
1515  }
1516 
1517  /******************************/
1518 
1519  char tempbuff[30]{0};
1520 
1521  //Stream variable
1522  stringstream mystream;
1523 
1524  //Radical change: HO iterates over eta and phi rather than crate, HTR, etc.
1525  for (isid = -1; isid < 2; isid += 2) {
1526  for (iph = 0; iph < NHOPHI; iph++) {
1527  for (iet = 0; iet < NHOETA; iet++) {
1528  iphi = iph + 1;
1529  ieta = iet + 1;
1530  iside = isid;
1531 
1532  if (iphi >= 71 || iphi < 17)
1533  ic = 0;
1534  else if (iphi >= 17 && iphi < 35)
1535  ic = 1;
1536  else if (iphi >= 35 && iphi < 53)
1537  ic = 2;
1538  else
1539  ic = 3;
1540 
1541  icrate = hocrate[ic];
1542  idepth = 4;
1543  det = "HO";
1544 
1545  //fpga = top/bottom for Ring 0 depends on a pattern that repeats every 30 degrees (6 phi)
1546  //Hence, phmod6 (not phi mod 6 because I don't want to separate 71 and 72, etc.)
1547 
1548  phmod6 = iph % 6;
1549  //Bools associated with phmod6 to be used with htr_fi and the patch panel
1550  phmod6e450 = (phmod6 == 4 || phmod6 == 5 || phmod6 == 0);
1551  phmod6e123 = (phmod6 == 1 || phmod6 == 2 || phmod6 == 3);
1552 
1553  //Ring 0 (HTR type 0) is special
1554  if (ieta <= 3 && (iside < 0 || phmod6 >= 4))
1555  fpga = "bot";
1556  else if (ieta <= 3 && iside > 0 && phmod6 < 4)
1557  fpga = "top";
1558  //new HX HTR
1559  else if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6))
1560  fpga = "top";
1561  else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13))
1562  fpga = "bot";
1563  //HTR types 0 and 1
1564  else if (ieta >= 10 && iside > 0)
1565  fpga = "top";
1566  else if (ieta < 10 && ieta >= 6 && iside > 0)
1567  fpga = "bot";
1568  //HTR types 2 and 3
1569  else if ((ieta == 5 && iside > 0) || ieta == 4)
1570  fpga = "top";
1571  else if ((ieta == 5 || ieta >= 10) && iside < 0)
1572  fpga = "bot";
1573  else if ((ieta < 10 && ieta >= 6) && iside < 0)
1574  fpga = "top";
1575  else
1576  edm::LogInfo("HcalLogicalMapGenerator") << "Bad fpga code" << endl;
1577 
1578  //dphi
1579  if (ieta <= 20)
1580  idphi = 1;
1581  else
1582  idphi = -1000;
1583 
1584  //create values usable in arrays from side and fpga
1585  if (iside == 1)
1586  sidear = 1;
1587  else
1588  sidear = 0;
1589 
1590  phmod24 = iph % 24;
1591 
1592  //Again, x - 1 because the array starts at 0 while the variables start at 1
1593  irm = HO_RM_table[phmod24][iet][sidear];
1594 
1595  //x - 5 for the eta array for the same reason
1596  // the new stuff for HX
1597  if (ieta == 16)
1598  irm_fi = HO_RM_fi_eta16;
1599  else if (ieta >= 5)
1600  irm_fi = HO_RM_fi_eta5to15[ieta - 5];
1601  else {
1602  if (mapIOV_ < 5) {
1603  if (ieta <= 3)
1604  irm_fi = HO_RM_fi_eta1to4[phmod24][0][sidear];
1605  else if (ieta == 4)
1606  irm_fi = HO_RM_fi_eta1to4[phmod24][1][sidear];
1607  else
1608  irm_fi = -1000;
1609  } else if (mapIOV_ >= 5) {
1610  irm_fi = HO_RM_fi_eta1to4_sipm[phmod24][ieta - 1][sidear];
1611  }
1612  }
1613 
1614  //HTR fiber
1615 
1616  //
1617  if (ieta >= 5 && phmod6e450)
1618  ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5];
1619  else if (ieta >= 5 && phmod6e123)
1620  ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5] - 1;
1621  else if (ieta <= 4) {
1622  if (mapIOV_ < 5) {
1623  if (ieta == 4)
1624  ihtr_fi = HO_htr_fi_eta4[sidear][phmod6];
1625  else if (ieta <= 3)
1626  ihtr_fi = HO_htr_fi_eta123[sidear][phmod6];
1627  } else if (mapIOV_ >= 5) {
1628  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][ieta - 1][(irm - 1) / 2][sidear];
1629  }
1630  } else
1631  ihtr_fi = -1000;
1632 
1633  //Fiber Channel
1634  //Eta >= 5 bools
1635  phi1458 = (iphi % 12 == 1 || iphi % 12 == 4 || iphi % 12 == 5 || iphi % 12 == 8);
1636  phi271011 = (iphi % 12 == 2 || iphi % 12 == 7 || iphi % 12 == 10 || iphi % 12 == 11);
1637 
1638  //Ring 0 bools
1639  phir0v1 = (iphi % 24 == 0 || iphi % 24 == 2 || iphi % 24 == 4 || iphi % 24 == 18 || iphi % 24 == 20 ||
1640  iphi % 24 == 22);
1641  phir0v2 = (iphi % 24 == 1 || iphi % 24 == 3 || iphi % 24 == 17 || iphi % 24 == 19 || iphi % 24 == 21 ||
1642  iphi % 24 == 23);
1643  //v3: phi 5 to 15 odd; v4: phi 6 to 16 even
1644  phir0v3 = (iphi % 24 == 5 || iphi % 24 == 7 || iphi % 24 == 9 || iphi % 24 == 11 || iphi % 24 == 13 ||
1645  iphi % 24 == 15);
1646  phir0v4 = (iphi % 24 == 6 || iphi % 24 == 8 || iphi % 24 == 10 || iphi % 24 == 12 || iphi % 24 == 14 ||
1647  iphi % 24 == 16);
1648 
1649  if (ieta >= 5) {
1650  if (ieta % 2 == 0 && phi1458)
1651  ifi_ch = 0;
1652  else if (ieta % 2 == 0 && iphi % 3 == 0)
1653  ifi_ch = 1;
1654  else if (ieta % 2 == 0 && phi271011)
1655  ifi_ch = 2;
1656  else if (ieta % 2 == 1 && iphi % 3 == 0)
1657  ifi_ch = 0;
1658  else if (ieta % 2 == 1 && phi271011)
1659  ifi_ch = 1;
1660  else if (ieta % 2 == 1 && phi1458)
1661  ifi_ch = 2;
1662  } else {
1663  if (mapIOV_ < 5) {
1664  if (ieta == 4) {
1665  if (iside == -1) {
1666  if (phir0v1)
1667  ifi_ch = 0;
1668  else if (phir0v4)
1669  ifi_ch = 1;
1670  else if (iphi % 2 == 1)
1671  ifi_ch = 2;
1672  } else {
1673  if (phir0v3)
1674  ifi_ch = 0;
1675  else if (phir0v2)
1676  ifi_ch = 1;
1677  else if (iphi % 2 == 0)
1678  ifi_ch = 2;
1679  }
1680  }
1681  //eta = -3 and eta = +2
1682  else if ((ieta == 3 && iside == -1) || (ieta == 2 && iside == 1)) {
1683  if (phir0v4)
1684  ifi_ch = 0;
1685  else if (phir0v3)
1686  ifi_ch = 1;
1687  else if (phir0v1 || phir0v2)
1688  ifi_ch = 2;
1689  }
1690  //eta = -2 and eta = +3
1691  else if ((ieta == 3 && iside == 1) || (ieta == 2 && iside == -1)) {
1692  if (phir0v2)
1693  ifi_ch = 0;
1694  else if (phir0v1)
1695  ifi_ch = 1;
1696  else if (phir0v3 || phir0v4)
1697  ifi_ch = 2;
1698  }
1699  //ieta = 1
1700  else if (ieta == 1) {
1701  if (phir0v1 || phir0v3)
1702  ifi_ch = 0;
1703  else if (phir0v2 || phir0v4)
1704  ifi_ch = 1;
1705  }
1706  } else {
1707  /*New code here for SiPM handling of rm fiber channel
1708  more challenging and requires some thought*/
1709  if (ieta == 4) {
1710  if (iside == -1) {
1711  if (phir0v1)
1712  ifi_ch = 0;
1713  else if (phir0v4)
1714  ifi_ch = 2;
1715  else if (iphi % 2 == 1)
1716  ifi_ch = 2;
1717  } else {
1718  if (phir0v3)
1719  ifi_ch = 0;
1720  else if (phir0v2)
1721  ifi_ch = 2;
1722  else if (iphi % 2 == 0)
1723  ifi_ch = 2;
1724  }
1725  }
1726  if (ieta == 2) {
1727  if (iside == -1) {
1728  if (iphi % 2 == 0)
1729  ifi_ch = 2;
1730  else if (iphi % 2 == 1)
1731  ifi_ch = 1;
1732  } else {
1733  if (iphi % 2 == 0)
1734  ifi_ch = 1;
1735  else if (iphi % 2 == 1)
1736  ifi_ch = 2;
1737  }
1738  }
1739  if (ieta == 3) {
1740  if (iside == -1) {
1741  if (iphi % 2 == 0)
1742  ifi_ch = 0;
1743  else if (iphi % 2 == 1)
1744  ifi_ch = 1;
1745  } else {
1746  if (iphi % 2 == 1)
1747  ifi_ch = 0;
1748  else if (iphi % 2 == 0)
1749  ifi_ch = 1;
1750  }
1751  }
1752  if (ieta == 1) {
1753  if (iside == -1) {
1754  if (phir0v1)
1755  ifi_ch = 0;
1756  else if (phir0v4)
1757  ifi_ch = 1;
1758  else if (iphi % 2 == 1)
1759  ifi_ch = 0;
1760  } else {
1761  if (phir0v3)
1762  ifi_ch = 0;
1763  else if (phir0v2)
1764  ifi_ch = 1;
1765  else if (iphi % 2 == 0)
1766  ifi_ch = 0;
1767  }
1768  }
1769  }
1770  }
1771 
1772  //Intentional integer truncation; iqie and iadc are the same across all subdetectors
1773  //(Although irm_fi for HF starts at 1 and for HO it starts at 2, so one can't just copy and paste)
1774  iqie = (irm_fi - 2) / 2 + 1;
1775 
1776  if (irm_fi % 2 == 0)
1777  iadc = ifi_ch;
1778  else
1779  iadc = NFCH + (ifi_ch + 1) % 3;
1780 
1781  //Pixel and Letter Code (Ring 0 is separate)
1782  if (ieta <= 4) {
1783  ipixel = ipixelHO[irm_fi - 2][ifi_ch][0];
1784  letter = letterHO[irm_fi - 2][ifi_ch][0];
1785  } else {
1786  ipixel = ipixelHO[irm_fi - 2][ifi_ch][1];
1787  letter = letterHO[irm_fi - 2][ifi_ch][1];
1788  }
1789 
1790  //special treatment for new ring-0 SiPMs fpga
1791  int mytype = -1; //variable that allows grouping of channels
1792  if (ieta <= 4 && mapIOV_ >= 5) {
1793  if (ipixel == 3 || ipixel == 7 || ipixel == 12 || ipixel == 14 || ipixel == 17 || ipixel == 18) {
1794  mytype = 1;
1795  if (phmod6 == 1 || phmod6 == 3)
1796  fpga = "top";
1797  else
1798  fpga = "bot";
1799  } else if (ipixel == 1 || ipixel == 4 || ipixel == 8 || ipixel == 15 || ipixel == 16 || ipixel == 19) {
1800  mytype = 2;
1801  if (phmod6 == 0 || phmod6 == 2)
1802  fpga = "top";
1803  else
1804  fpga = "bot";
1805  } else if (ipixel == 2 || ipixel == 5 || ipixel == 6 || ipixel == 9 || ipixel == 11 || ipixel == 13) {
1806  mytype = 3;
1807  fpga = "top";
1808  }
1809  }
1810 
1811  if (fpga == "bot")
1812  itb = 1; //convention different than for the
1813  else
1814  itb = 0; //electronics id, modified in the
1815  //MapEntry code
1816 
1817  //Determine which of HTR in the set belongs here. It depends only on eta and side.
1818  // the new stuff for HX
1819  if (ieta <= 3 || (ieta >= 14 && iside == 1))
1820  ih = 0;
1821  else if (ieta <= 13 && ieta >= 6 && iside == 1)
1822  ih = 1;
1823  else if (ieta <= 13 && ieta >= 6 && iside == -1)
1824  ih = 3;
1825  else
1826  ih = 2;
1827 
1829  // the htrs are grouped in chunks of ((ph+2) mod 18)/6
1830  //71,72,1,2,3,4
1831  // and indexed by the mytype variable previously defined
1832  int php2mod18 = (iph + 2) % 18;
1833  int php2mod18ov6 = php2mod18 / 6;
1834 
1835  //Each value of "is" covers 30 degrees (that is, 6 values of phi). To calculate which ones,
1836  //I use phi % 18. Crates start at phi = 71, 17, 35, 53
1837 
1838  if (iphi % 18 == 17 || iphi % 18 <= 4)
1839  is = 0;
1840  else if (iphi % 18 >= 5 && iphi % 18 <= 10)
1841  is = 1;
1842  else
1843  is = 2;
1844 
1845  if (ieta == 16 && iside > 0)
1846  ihtr = 21;
1847  else if (ieta > 4)
1848  ihtr = ihslotho[is][ih];
1849  else {
1850  //special treatment only for ring-0
1851  if (mapIOV_ < 5)
1852  ihtr = ihslotho[is][ih];
1853  else {
1854  if (mytype == 1 || mytype == 2)
1855  ih = 0;
1856  else
1857  ih = 2;
1858  ihtr = ihslotho[php2mod18ov6][ih];
1859  }
1860  }
1861 
1862  if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6))
1863  ispigot = 12;
1864  else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13))
1865  ispigot = 13;
1866  else
1867  ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
1868  idcc = ihtr < 9 ? 1 : 2;
1869  idcc_sl = idcc == 1 ? 10 : 20;
1870 
1871  ifed = fedhonum[ic][idcc - 1];
1872 
1873  //RBX and sector
1874 
1875  if (iside == -1)
1876  sidesign = 'M';
1877  else
1878  sidesign = 'P';
1879 
1880  if (ieta <= 4)
1881  ring = 0;
1882  else if (ieta >= 5 && ieta <= 10)
1883  ring = 1;
1884  else
1885  ring = 2;
1886 
1887  //Sector ranges from 1 to 12 depending on phi. Sector 1 goes 71,72,1,2,3,4 so I start at -2
1888  sector = 0;
1889  for (i = -2; i < iphi; i += 6) {
1890  sector++;
1891  }
1892  if (sector > 12)
1893  sector = 1; //It rolls over for phi = 71,72
1894 
1895  isector = sector;
1896 
1897  //For rings 1 and 2, we only want even sectors for the rbx
1898  if (ring != 0 && sector % 2 != 0)
1899  sector++;
1900 
1901  if (ring == 0)
1902  snprintf(tempbuff, sizeof tempbuff, "%s%i%2.2d", det.c_str(), ring, sector);
1903  else
1904  snprintf(tempbuff, sizeof tempbuff, "%s%i%c%2.2d", det.c_str(), ring, sidesign, sector);
1905  mystream << tempbuff;
1906  rbx = mystream.str();
1907  mystream.str("");
1908  if (ieta == 16) {
1909  det = "HOX";
1910  letter = "X";
1911  } else
1912  det = "HO";
1913 
1914  // the new htr_fi stuff for HX
1915  if (ieta == 16 && isid < 0)
1916  ihtr_fi = HO_htr_fi_450eta16M[irm - 1];
1917  else if (ieta == 16 && isid > 0)
1918  ihtr_fi = HO_htr_fi_450eta16P[irm - 1][sector / 2 - 1];
1919 
1920  if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 7)) {
1921  icrate = 6;
1922  ifed = 729;
1923  } else if ((ieta > 15 && iside > 0) && (icrate == 6 || icrate == 13)) {
1924  icrate = 7;
1925  ifed = 727;
1926  }
1927 
1928  if (ieta == 16)
1929  ieta = 15;
1930  // fixing the switched RM's
1931  if (iside == 1 && ring == 2) {
1932  if (iphi == 5) {
1933  ieta = rmspecialeta[0][iet - 10];
1934  letter = rmspeciallet_code[0][iet - 10];
1935  det = rmspecialdet[0][iet - 10];
1936  } else if (iphi == 67) {
1937  ieta = rmspecialeta[1][iet - 10];
1938  letter = rmspeciallet_code[1][iet - 10];
1939  det = rmspecialdet[1][iet - 10];
1940  }
1941  } else if (iside == -1) {
1942  if (ring == 1) {
1943  if (iphi == 57) {
1944  ieta = rmspecialeta[2][iet - 4];
1945  letter = rmspeciallet_code[2][iet - 4];
1946  det = rmspecialdet[2][iet - 4];
1947  } else if (iphi == 65) {
1948  ieta = rmspecialeta[3][iet - 4];
1949  letter = rmspeciallet_code[3][iet - 4];
1950  det = rmspecialdet[3][iet - 4];
1951  }
1952  } else if (ring == 2) {
1953  if (iphi == 16) {
1954  ieta = rmspecialeta[4][iet - 10];
1955  letter = rmspeciallet_code[4][iet - 10];
1956  det = rmspecialdet[4][iet - 10];
1957  } else if (iphi == 31) {
1958  ieta = rmspecialeta[5][iet - 10];
1959  letter = rmspeciallet_code[5][iet - 10];
1960  det = rmspecialdet[5][iet - 10];
1961  }
1962  }
1963  }
1964 
1965  HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
1966  ihtr_fi,
1967  ispigot,
1968  ifed,
1969  icrate,
1970  ihtr,
1971  fpga,
1972  det,
1973  iside,
1974  ieta,
1975  iphi,
1976  idepth,
1977  idphi,
1978  isector,
1979  irm,
1980  irm_fi,
1981  ipixel,
1982  iqie,
1983  iadc,
1984  rbx,
1985  letter);
1986  HOHXEntries.push_back(hoxlmapentry);
1987  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
1988  HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
1989 
1990  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
1991  unsigned int denseId;
1992  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
1993  denseId = topo->detId2denseIdHO(hgdi);
1994  HoHash2Entry.at(denseId) = HOHXEntries.size();
1995  } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
1996  denseId = topo->detId2denseIdCALIB(hgdi);
1997  HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
1998  }
1999 
2000  if (ring == 0) {
2001  if (ipixel == 1) {
2002  ipixel = 2;
2003  iadc = 4;
2004  if (mapIOV_ < 5)
2005  ifi_ch = 0;
2006  else {
2007  irm_fi = 4;
2008  ifi_ch = 2;
2009  if (irm_fi % 2 == 0)
2010  iadc = ifi_ch;
2011  else
2012  iadc = NFCH + (ifi_ch + 1) % 3;
2013  iqie = (irm_fi - 2) / 2 + 1;
2014  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm - 1) / 2][sidear];
2015  itb = 0;
2016  fpga = "top";
2017  mytype = 3;
2018  ih = 2;
2019  ihtr = ihslotho[php2mod18ov6][ih];
2020  ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
2021  idcc = ihtr < 9 ? 1 : 2;
2022  idcc_sl = idcc == 1 ? 10 : 20;
2023  ifed = fedhonum[ic][idcc - 1];
2024  }
2025  letter = "X";
2026  det = "HOX";
2027  HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
2028  ihtr_fi,
2029  ispigot,
2030  ifed,
2031  icrate,
2032  ihtr,
2033  fpga,
2034  det,
2035  iside,
2036  ieta,
2037  iphi,
2038  idepth,
2039  idphi,
2040  isector,
2041  irm,
2042  irm_fi,
2043  ipixel,
2044  iqie,
2045  iadc,
2046  rbx,
2047  letter);
2048  HOHXEntries.push_back(hoxlmapentry);
2049  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
2050  HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
2051 
2052  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
2053  unsigned int denseId;
2054  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2055  denseId = topo->detId2denseIdHO(hgdi);
2056  HoHash2Entry.at(denseId) = HOHXEntries.size();
2057  } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2058  denseId = topo->detId2denseIdCALIB(hgdi);
2059  HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2060  }
2061  } else if (ipixel == 17) {
2062  ipixel = 18;
2063  iadc = 1;
2064  if (mapIOV_ < 5)
2065  ifi_ch = 1;
2066  else {
2067  irm_fi = 6;
2068  ifi_ch = 1;
2069  if (irm_fi % 2 == 0)
2070  iadc = ifi_ch;
2071  else
2072  iadc = NFCH + (ifi_ch + 1) % 3;
2073  iqie = (irm_fi - 2) / 2 + 1;
2074  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm - 1) / 2][sidear];
2075  if (phmod6 == 1 || phmod6 == 3) {
2076  itb = 0;
2077  fpga = "top";
2078  } else {
2079  itb = 1;
2080  fpga = "bot";
2081  }
2082  ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
2083  idcc = ihtr < 9 ? 1 : 2;
2084  idcc_sl = idcc == 1 ? 10 : 20;
2085  ifed = fedhonum[ic][idcc - 1];
2086  }
2087  letter = "X";
2088  det = "HOX";
2089  HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
2090  ihtr_fi,
2091  ispigot,
2092  ifed,
2093  icrate,
2094  ihtr,
2095  fpga,
2096  det,
2097  iside,
2098  ieta,
2099  iphi,
2100  idepth,
2101  idphi,
2102  isector,
2103  irm,
2104  irm_fi,
2105  ipixel,
2106  iqie,
2107  iadc,
2108  rbx,
2109  letter);
2110  HOHXEntries.push_back(hoxlmapentry);
2111  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
2112  HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
2113 
2114  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
2115  unsigned int denseId;
2116  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2117  denseId = topo->detId2denseIdHO(hgdi);
2118  HoHash2Entry.at(denseId) = HOHXEntries.size();
2119  } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2120  denseId = topo->detId2denseIdCALIB(hgdi);
2121  HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2122  }
2123  }
2124  }
2125  }
2126  }
2127  }
2128 }
2129 
2131  std::vector<CALIBLogicalMapEntry>& CALIBEntries,
2132  std::vector<uint32_t>& LinearIndex2Entry,
2133  std::vector<uint32_t>& HxCalibHash2Entry) {
2134  /******************************/
2135  /* CALIB crate numbering in order of FEDID*/
2136  int calibcrate_loc[NCALIBCR] = {4, 0, 1, 5, 11, 15, 17, 14, 10, 9, 7, 6, 13}; //HBHE,HF,HO
2137  memcpy(calibcrate, calibcrate_loc, sizeof(int) * NCALIBCR);
2138  /* CALIB FED numbering of DCCs */
2139  int fedcalibnum_loc[NCALIBCR][2] = {{700, 701},
2140  {702, 703},
2141  {704, 705},
2142  {706, 707},
2143  {708, 709},
2144  {710, 711},
2145  {712, 713},
2146  {714, 715},
2147  {716, 717}, /*calib_hbhe 4,0,1,5,11,15,17,14,10*/
2148  {720, 721}, /*calib_hf 9*/
2149  {726, 727},
2150  {728, 729},
2151  {730, 731}}; //calib_ho 7,6,13
2152  memcpy(fedcalibnum, fedcalibnum_loc, sizeof(int) * NCALIBCR * 2);
2153  /* iphi (lower) starting index for each CALIB crate */
2154  int icalibphis_loc[NCALIBCR] = {3, 11, 19, 27, 35, 43, 51, 59, 67, 27, 17, 35, 53};
2155  memcpy(icalibphis, icalibphis_loc, sizeof(int) * NCALIBCR);
2156  /* icalibsector_min minimum sector on each crate {0,1,4,5,10,11,14,15,17,9,7,6,13}*/
2157  int icalibsector_min_loc[NCALIBCR] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 4, 7, 10};
2158  memcpy(icalibsector_min, icalibsector_min_loc, sizeof(int) * NCALIBCR);
2159  /* icalibsector_max maximum sector on each crate */
2160  int icalibsector_max_loc[NCALIBCR] = {3, 5, 7, 9, 11, 13, 15, 17, 1, 4, 6, 9, 12};
2161  memcpy(icalibsector_max, icalibsector_max_loc, sizeof(int) * NCALIBCR);
2162  //detectors represented on each crate (0 for top, 1 for bot)
2163  std::string detIDCALIB_loc[NCALIBCR][NTOPBOT] = {{"HB", "HE"}, /*crate 4*/
2164  {"HB", "HE"}, /*crate 0*/
2165  {"HB", "HE"}, /*crate 1*/
2166  {"HB", "HE"}, /*crate 5*/
2167  {"HB", "HE"}, /*crate 11*/
2168  {"HB", "HE"}, /*crate 15*/
2169  {"HB", "HE"}, /*crate 17*/
2170  {"HB", "HE"}, /*crate 14*/
2171  {"HB", "HE"}, /*crate 10*/
2172  {"HF", "HF"}, /*crate 9*/
2173  {"HO", "HO"}, /*crate 7*/
2174  {"HO", "HO"}, /*crate 6*/
2175  {"HO", "HO"}}; /*crate 13*/
2176  for (int jj = 0; jj < NCALIBCR; jj++) {
2177  for (int kk = 0; kk < NTOPBOT; kk++) {
2178  detIDCALIB[jj][kk] = detIDCALIB_loc[jj][kk];
2179  }
2180  }
2181 
2182  int nfbr_max_loc[NCALIBCR][NTOPBOT] = {
2183  {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 4}, {8, 4}, {8, 8}, {8, 4}};
2184  memcpy(nfbr_max, nfbr_max_loc, sizeof(int) * NCALIBCR * NTOPBOT);
2185  //HB only utilizes 4 htr_fibers HE all 8
2186  int calibHOinfo_loc[NHOCR][NTOPBOT][NFBR][2] = {
2187  /*sector and ring of HO for the calib channel*/
2188  {{{4, 0}, {5, 0}, {6, 0}, {}, {6, -2}, {6, -1}, {6, 1}, {6, 2}},
2189  {{4, -2}, {4, -1}, {4, 1}, {4, 2}, {}, {}, {}, {}}}, /*crate 7*/
2190 
2191  {{{7, 0}, {8, 0}, {9, 0}, {}, {8, -2}, {8, -1}, {8, 1}, {8, 2}},
2192  {{1, 0}, {2, 0}, {3, 0}, {}, {2, -2}, {2, -1}, {2, 1}, {2, 2}}}, /*crate 6*/
2193 
2194  {{{10, 0}, {11, 0}, {12, 0}, {}, {10, -2}, {10, -1}, {10, 1}, {10, 2}},
2195  {{12, -2}, {12, -1}, {12, 1}, {12, 2}, {}, {}, {}, {}}} /*crate 13*/
2196  };
2197  memcpy(calibHOinfo, calibHOinfo_loc, sizeof(int) * NHOCR * NTOPBOT * NFBR * 2);
2198 
2199  /*********************************/
2200 
2201  char tempbuff[30]{0};
2202 
2203  //Stream variable
2204 
2205  stringstream mystream;
2206 
2207  ihtr = 8; //calibration units are housed on htr slot 8
2208  idcc = 1;
2209  idcc_sl = 10;
2210  irm_fi = 1; // everything other than HE is on A
2211  det = "";
2212 
2213  /*****************************************************/
2214  /*HBHE calibration channels*/
2215  for (ic = 0; ic < NHBHECR; ic++) {
2216  icrate = calibcrate[ic];
2217  ifed = fedcalibnum[ic][idcc - 1];
2218  /* top and bottom */
2219  for (itb = 0; itb < NTOPBOT; itb++) {
2220  /* 4 or 8 fibers used per HTR FPGA */
2221  for (ifb = 0; ifb < nfbr_max[ic][itb]; ifb++) {
2222  det = detIDCALIB[ic][itb];
2223  ihtr_fi = ifb + 1;
2224  irm_fi = 1; // everything other than he is on A
2225  idphi = 4;
2226  if (itb == 1)
2227  if (ihtr_fi % 2 == 0)
2228  irm_fi = 2; //all of the even fibers in HE are on B rather than A
2229  if (det == "HE") {
2230  ispigot = 13;
2231  fpga = "bot";
2232  if (ihtr_fi == 1 || ihtr_fi == 2 || ihtr_fi == 5 || ihtr_fi == 6) {
2233  iwedge = icalibsector_min[ic];
2234  } else if (ihtr_fi == 3 || ihtr_fi == 4 || ihtr_fi == 7 || ihtr_fi == 8) {
2235  iwedge = icalibsector_max[ic];
2236  }
2237  if (ihtr_fi < 5) {
2238  sidesign = 'M';
2239  S_side = '1';
2240  ieta = -1;
2241  iside = -1;
2242  } else {
2243  sidesign = 'P';
2244  S_side = '1';
2245  ieta = 1;
2246  iside = 1;
2247  }
2248  } else if (det == "HB") {
2249  ispigot = 12;
2250  fpga = "top";
2251  (ihtr_fi % 2 == 1) ? iwedge = icalibsector_min[ic] : iwedge = icalibsector_max[ic];
2252  if (ihtr_fi < 3) {
2253  sidesign = 'M';
2254  S_side = '1';
2255  ieta = -1;
2256  iside = -1;
2257  } else {
2258  sidesign = 'P';
2259  S_side = '1';
2260  ieta = 1;
2261  iside = 1;
2262  }
2263  }
2264  iphi = ((iwedge * idphi) + 71 - idphi) % 72;
2265  subdet = "CALIB_" + det;
2266  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2267  mystream << tempbuff;
2268  rbx = mystream.str();
2269  mystream.str("");
2270  /* three channels per fiber */
2271  for (ifc = 0; ifc < NFCH; ifc++) {
2272  ifi_ch = ifc;
2273  if (irm_fi == 1) {
2274  if (ifc == 0)
2275  ich_type = 0;
2276  else if (ifc == 1)
2277  ich_type = 1;
2278  else if (ifc == 2) {
2279  if (det == "HB")
2280  ich_type = 2;
2281  else if (det == "HE")
2282  ich_type = 3;
2283  }
2284  } else if (irm_fi == 2) {
2285  if (ifc == 0)
2286  ich_type = 4;
2287  else if (ifc == 1)
2288  ich_type = 5;
2289  else if (ifc == 2)
2290  ich_type = 6;
2291  }
2292  CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2293  ihtr_fi,
2294  ispigot,
2295  ifed,
2296  icrate,
2297  ihtr,
2298  fpga,
2299  det,
2300  ieta,
2301  iphi,
2302  ich_type,
2303  iside,
2304  idphi,
2305  rbx,
2306  iwedge,
2307  irm_fi,
2308  subdet);
2309  CALIBEntries.push_back(caliblmapentry);
2310  LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2311  HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2312 
2313  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2314  const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2315  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2316  HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2317  }
2318  }
2319  }
2320  }
2321 
2322  /* only one CALIB HF crate */
2323  /* top and bottom */
2324  for (itb = 0; itb < NTOPBOT; itb++) {
2325  /* four CALIB HF fibers per HTR FPGA */
2326  for (ifb = 0; ifb < 4; ifb++) {
2327  /* three channels per fiber */
2328  for (ifc = 0; ifc < NFCH; ifc++) {
2329  icrate = calibcrate[ic];
2330  det = "HF";
2331  ihtr_fi = ifb + 1;
2332  ifi_ch = ifc;
2333  (ihtr_fi == 1) ? iphi = 1 : ((ihtr_fi == 2) ? iphi = 19 : ((ihtr_fi == 3) ? iphi = 37 : iphi = 55));
2334  idphi = 18;
2335  ifed = fedcalibnum[ic][idcc - 1];
2336  (ifc == 0) ? ich_type = 8 : (ifc == 1 ? ich_type = 0 : ich_type = 1);
2337  //changed ch_type of fibre channel 0 from 2 to 8, as per HcalCalibDetId specification
2338  irm_fi = 1;
2339  //Wedge has steps of 3, HF(P/M)2,5,8,11
2340  //iwedge=ihtr_fi;
2341  iwedge = 2 + (ifb * 3);
2342  if (itb == 0) {
2343  ispigot = 12;
2344  fpga = "top";
2345  sidesign = 'P';
2346  iside = 1;
2347  ieta = 1;
2348  } else {
2349  ispigot = 13;
2350  fpga = "bot";
2351  sidesign = 'M';
2352  iside = -1;
2353  ieta = -1;
2354  }
2355  subdet = "CALIB_" + det;
2356  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2357  mystream << tempbuff;
2358  rbx = mystream.str();
2359  mystream.str("");
2360  CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2361  ihtr_fi,
2362  ispigot,
2363  ifed,
2364  icrate,
2365  ihtr,
2366  fpga,
2367  det,
2368  ieta,
2369  iphi,
2370  ich_type,
2371  iside,
2372  idphi,
2373  rbx,
2374  iwedge,
2375  irm_fi,
2376  subdet);
2377  CALIBEntries.push_back(caliblmapentry);
2378  LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2379  HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2380 
2381  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2382  const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2383  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2384  HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2385  }
2386  }
2387  }
2388 
2389  /*HO calibration channels*/
2390  for (ic = ic + 1; ic < NCALIBCR; ic++) {
2391  icrate = calibcrate[ic];
2392  irm_fi = 1; // everything other than he is on A
2393  ifed = fedcalibnum[ic][idcc - 1];
2394  /* top and bottom */
2395  for (itb = 0; itb < NTOPBOT; itb++) {
2396  det = detIDCALIB[ic][itb];
2397  /* 4 or 8 fibers used per HTR FPGA */
2398  for (ifb = 0; ifb < nfbr_max[ic][itb]; ifb++) {
2399  if (itb == 1) {
2400  ispigot = 13;
2401  fpga = "bot";
2402  } else {
2403  ispigot = 12;
2404  fpga = "top";
2405  }
2406  ihtr_fi = ifb + 1;
2407  iwedge = calibHOinfo[ic - 10][itb][ifb][0];
2408  ieta = calibHOinfo[ic - 10][itb][ifb][1];
2409  if (ieta < 0) {
2410  iside = -1;
2411  sidesign = 'M';
2412  } else if (ieta > 0) {
2413  iside = 1;
2414  sidesign = 'P';
2415  } else {
2416  iside = 0;
2417  sidesign = '0';
2418  }
2419  if (ieta == -2)
2420  S_side = '2';
2421  else if (ieta == -1)
2422  S_side = '1';
2423  else if (ieta == 1)
2424  S_side = '1';
2425  else if (ieta == 2)
2426  S_side = '2';
2427 
2428  subdet = "CALIB_" + det;
2429  if (ieta == 0)
2430  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2431  else
2432  snprintf(tempbuff, sizeof tempbuff, "%s%c%c%2.2i", det.c_str(), S_side, sidesign, iwedge);
2433  mystream << tempbuff;
2434  rbx = mystream.str();
2435  mystream.str("");
2436  /* only two channels used in HO per fiber */
2437  //now new information suggests that the third channel is used for x-talk
2438  //but only in some of the rm's, seems to be dependent on whether nfbr_max
2439  //sector 10 on YB+2,1,0,-1, sector 12 on YB-2
2440  int NFCH_HO;
2441  //( nfbr_max[ic][itb] == 4 ) ? NFCH_HO = 2 : NFCH_HO = 3;
2442  (ieta == -2) ? (iwedge == 12 ? NFCH_HO = 3 : NFCH_HO = 2) : (iwedge == 10) ? NFCH_HO = 3 : NFCH_HO = 2;
2443  for (ifc = 0; ifc < NFCH_HO; ifc++) {
2444  ifi_ch = ifc;
2445  (ifi_ch == 2) ? ich_type = 7 : ich_type = ifi_ch;
2446  (ieta == 0) ? idphi = 6 : idphi = 12;
2447 
2448  (ieta == 0) ? iphi = ((iwedge * idphi) + 71 - idphi) % 72 : iphi = (((iwedge / 2) * idphi) + 71 - idphi) % 72;
2449  //nothing on htr_fi=4 for the top
2450  //do {
2451  if (iside == 0 && ifb == 3)
2452  continue; // adjust logic since no longer inside loop
2453  CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2454  ihtr_fi,
2455  ispigot,
2456  ifed,
2457  icrate,
2458  ihtr,
2459  fpga,
2460  det,
2461  ieta,
2462  iphi,
2463  ich_type,
2464  iside,
2465  idphi,
2466  rbx,
2467  iwedge,
2468  irm_fi,
2469  subdet);
2470  CALIBEntries.push_back(caliblmapentry);
2471  LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2472  HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2473 
2474  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2475  const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2476  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2477  HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2478  //} while (ifb!=ifb);
2479  }
2480  }
2481  }
2482  }
2483 }
2484 
2486  std::vector<ZDCLogicalMapEntry>& ZDCEntries,
2487  std::vector<uint32_t>& LinearIndex2Entry,
2488  std::vector<uint32_t>& ZdcHash2Entry) {
2489  /******************************/
2490  /*ZDC channels*/
2491  //Stream variable
2492  stringstream mystream;
2493 
2494  ifed = 722;
2495  iy = 1;
2496  ihtr = 8;
2497  icrate = 12;
2498  idcc = 1;
2499  idcc_sl = 10;
2500  ispigot = 12;
2501  /* side plus and minus */
2502  for (itb = 0; itb < NTOPBOT; itb++) {
2503  if (itb == 0) {
2504  iside = 1;
2505  irm = 1;
2506  fpga = "top";
2507  } else {
2508  iside = -1;
2509  irm = 2;
2510  if (mapIOV_ < 4) {
2511  fpga = "top";
2512  ispigot = 12;
2513  } else {
2514  fpga = "bot";
2515  ispigot = 13;
2516  }
2517  }
2518  /*loop over ZDC cables*/
2519  for (icab = 1; icab < NZDCCAB + 1; icab++) {
2520  if (icab < 4) {
2521  irm_fi = 1;
2522  iadc = icab - 1;
2523  ifi_ch = iadc;
2524  } else if (icab < 7) {
2525  irm_fi = 2;
2526  iadc = icab - 1;
2527  ifi_ch = iadc - 3;
2528  } else {
2529  irm_fi = 3;
2530  iadc = icab - 7;
2531  ifi_ch = iadc;
2532  }
2533  if (itb == 0) {
2534  ihtr_fi = irm_fi;
2535  } else {
2536  if (mapIOV_ < 4)
2537  ihtr_fi = irm_fi + 3;
2538  else
2539  ihtr_fi = irm_fi;
2540  }
2541  if (icab < 6) {
2542  ix = icab;
2543  idepth = 1;
2544  idx = 1;
2545  det = "ZDC_EM";
2546  idet_ch = ix;
2547  iqie = 1;
2548  } else {
2549  ix = 1;
2550  idepth = icab - 4;
2551  idx = 5;
2552  det = "ZDC_HAD";
2553  idet_ch = icab - 5;
2554  if (icab == 6)
2555  iqie = 1;
2556  else
2557  iqie = 2;
2558  }
2559  ZDCLogicalMapEntry zdclmapentry(ifi_ch,
2560  ihtr_fi,
2561  ispigot,
2562  ifed,
2563  icrate,
2564  ihtr,
2565  fpga,
2566  det,
2567  iside,
2568  idepth,
2569  ix,
2570  iy,
2571  idx,
2572  idet_ch,
2573  icab,
2574  irm,
2575  iqie,
2576  iadc,
2577  irm_fi);
2578  ZDCEntries.push_back(zdclmapentry);
2579  LinearIndex2Entry.at(zdclmapentry.getLinearIndex()) =
2580  HcalLogicalMap::makeEntryNumber(true, 3, ZDCEntries.size() - 1);
2581  }
2582  }
2583 }
2584 
2585 /********************************************************/
2587  std::vector<HTLogicalMapEntry>& HTEntries,
2588  int iside,
2589  int ieta,
2590  int iphi,
2591  int idphi,
2592  int idepth,
2593  std::string det,
2594  int iwedge,
2595  int irm,
2596  int ipixel,
2597  int iqie,
2598  int iadc,
2599  int irm_fi,
2600  int ifi_ch,
2601  int icrate,
2602  int ihtr,
2603  std::string fpga,
2604  int ihtr_fi,
2605  int ispigot,
2606  int islb,
2607  std::string slbin,
2608  std::string slbin2,
2609  std::string slnam,
2610  int irctcra,
2611  int irctcar,
2612  int irctcon,
2613  std::string rctnam,
2614  int ifed) {
2615  string t_chDet, t_fpga;
2616  string t_slnam, t_rctnam, t_slbin, t_slbin2;
2617 
2618  int t_nDat = -1;
2619  int t_side, t_iEta, t_iPhi, t_jPhi, t_iDep, t_topbot;
2620  int t_wedge, t_crate, t_htr;
2621  // int t_rm,t_pixel,t_qie,t_adc,t_rm_fi,t_fi_ch,t_htr_fi;
2622  int t_spigo, t_slb, t_rctcra, t_rctcar, t_rctcon, t_fedid;
2623 
2624  //making global variables local for modification
2625  (fpga == "bot") ? t_topbot = 1 : t_topbot = 0;
2626  t_side = iside;
2627  t_iEta = ieta;
2628  t_iPhi = iphi;
2629  t_jPhi = idphi;
2630  t_iDep = idepth;
2631  t_chDet = det;
2632  t_wedge = iwedge;
2633  // t_rm = irm;
2634  // t_pixel = ipixel;
2635  // t_qie = iqie;
2636  // t_adc = iadc;
2637  // t_rm_fi = irm_fi;
2638  // t_fi_ch = ifi_ch;
2639  t_crate = icrate;
2640  t_htr = ihtr;
2641  t_fpga = fpga;
2642  // t_htr_fi = ihtr_fi;
2643  t_spigo = ispigot;
2644  t_slb = islb;
2645  t_slbin = slbin;
2646  t_slbin2 = slbin2;
2647  t_slnam = slnam;
2648  t_rctcra = irctcra;
2649  t_rctcar = irctcar;
2650  t_rctcon = irctcon;
2651  t_rctnam = rctnam;
2652  t_fedid = ifed;
2653 
2654  do {
2655  if (t_iDep != 1)
2656  break;
2657  if (t_chDet == "HE" && t_iEta == 29)
2658  break;
2659 
2660  if (t_chDet == "HF") {
2661  t_jPhi = 4; //20 degree slices in HF
2662  if (t_iEta == 30 || t_iEta == 31 || t_iEta == 33 || t_iEta == 34 || t_iEta == 36 || t_iEta == 37 ||
2663  t_iEta == 39 || t_iEta == 40 || t_iEta == 41)
2664  break;
2665 
2666  else if (t_iEta == 32)
2667  t_iEta = 30;
2668  else if (t_iEta == 35)
2669  t_iEta = 31;
2670  else if (t_iEta == 38)
2671  t_iEta = 32;
2672 
2673  if (t_iPhi == 3 || t_iPhi == 7 || t_iPhi == 11 || t_iPhi == 15 || t_iPhi == 19 || t_iPhi == 23 || t_iPhi == 27 ||
2674  t_iPhi == 31 || t_iPhi == 35 || t_iPhi == 39 || t_iPhi == 43 || t_iPhi == 47 || t_iPhi == 51 ||
2675  t_iPhi == 55 || t_iPhi == 59 || t_iPhi == 63 || t_iPhi == 67 || t_iPhi == 71)
2676  break;
2677  }
2678 
2679  if (t_side < 0)
2680  t_iEta = -t_iEta;
2681  t_chDet = "HT";
2682 
2683  if (t_slbin != "NA") {
2684  if (t_slbin2 != "NA")
2685  t_jPhi = 1;
2686  if (t_slbin == "A0" || t_slbin == "B0")
2687  t_nDat = 0;
2688  else if (t_slbin == "A1" || t_slbin == "B1")
2689  t_nDat = 1;
2690  else if (t_slbin == "C0" || t_slbin == "D0")
2691  t_nDat = 2;
2692  else if (t_slbin == "C1" || t_slbin == "D1")
2693  t_nDat = 3;
2694 
2695  HTLogicalMapEntry htlmapentry(t_iEta,
2696  t_iPhi,
2697  t_side,
2698  t_jPhi,
2699  t_iDep,
2700  t_chDet,
2701  t_wedge,
2702  t_crate,
2703  t_htr,
2704  t_topbot,
2705  t_spigo,
2706  t_slb,
2707  t_slbin,
2708  t_slbin2,
2709  t_nDat,
2710  t_slnam,
2711  t_rctcra,
2712  t_rctcar,
2713  t_rctcon,
2714  t_rctnam,
2715  t_fedid);
2716  HTEntries.push_back(htlmapentry);
2717  }
2718  if (t_slbin2 != "NA") {
2719  if (t_slbin2 == "A0" || t_slbin2 == "B0")
2720  t_nDat = 0;
2721  else if (t_slbin2 == "A1" || t_slbin2 == "B1")
2722  t_nDat = 1;
2723  else if (t_slbin2 == "C0" || t_slbin2 == "D0")
2724  t_nDat = 2;
2725  else if (t_slbin2 == "C1" || t_slbin2 == "D1")
2726  t_nDat = 3;
2727  t_jPhi = 1; //after splitting up these towers, each half should have dphi of 1
2728  t_iPhi += 1;
2729 
2730  HTLogicalMapEntry htlmapentry(t_iEta,
2731  t_iPhi, //changed from t_iPhi + 1 here to the spot above
2732  t_side,
2733  t_jPhi,
2734  t_iDep,
2735  t_chDet,
2736  t_wedge,
2737  t_crate,
2738  t_htr,
2739  t_topbot,
2740  t_spigo,
2741  t_slb,
2742  t_slbin,
2743  t_slbin2,
2744  t_nDat,
2745  t_slnam,
2746  t_rctcra,
2747  t_rctcar,
2748  t_rctcon,
2749  t_rctnam,
2750  t_fedid);
2751  HTEntries.push_back(htlmapentry);
2752  }
2753  } while (1 != 1);
2754 }
static uint32_t makeEntryNumber(bool, int, int)
unsigned int detId2denseIdHF(const DetId &id) const
return a linear packed id from HF
unsigned int detId2denseIdHB(const DetId &id) const
return a linear packed id from HB
void buildZDCMap(const HcalTopology *topo, std::vector< ZDCLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
const uint32_t getLinearIndex() const
uint32_t getLinearIndex() const
const DetId getDetId() const
const DetId getDetId() const
HcalLogicalMap createMap(const HcalTopology *topo, unsigned int mapIOV=4)
const uint32_t getLinearIndex() const
void buildCALIBMap(const HcalTopology *topo, std::vector< CALIBLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
const uint32_t getLinearIndex() const
static const int maxLinearIndex
void buildHOXMap(const HcalTopology *topo, std::vector< HOHXLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
unsigned int detId2denseIdHO(const DetId &id) const
return a linear packed id from HO
unsigned int detId2denseIdHE(const DetId &id) const
return a linear packed id from HE
const DetId getDetId() const
void ConstructTriggerTower(const HcalTopology *topo, std::vector< HTLogicalMapEntry > &, int i_side, int i_eta, int i_phi, int i_dphi, int i_depth, std::string i_det, int i_wedge, int i_rm, int i_pixel, int i_qie, int i_adc, int i_rm_fi, int i_fi_ch, int i_crate, int i_htr, std::string i_fpga, int i_htr_fi, int i_spigot, int i_slb, std::string i_slbin, std::string i_slbin2, std::string i_slnam, int i_rctcra, int i_rctcar, int i_rctcon, std::string i_rctnam, int i_fed)
void buildHBEFTMap(const HcalTopology *topo, std::vector< HBHEHFLogicalMapEntry > &, std::vector< HTLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
unsigned int detId2denseIdCALIB(const DetId &id) const
return a linear packed id from CALIB