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 
20  //adc and qie table; qie is entry 0, adc is entry 1. Constant across HB, HE, HO
21  // int iadcquiHBHE[NRMFIBR][NFCH][2];
22 
23  for (i = 0; i < NRMFIBR; i++){
24  for (j = 0; j < NFCH; j++){
25  //Intentionally relying on integer truncation here
26  iadcquiHBHE[i][j][0] = i / 2 + 1;
27 
28  if (i % 2 == 0) iadcquiHBHE[i][j][1] = j;
29  else iadcquiHBHE[i][j][1] = NFCH + (j + 1) % 3;
30  }
31  }
32 }
33 
35 
36 }
37 
38 HcalLogicalMap HcalLogicalMapGenerator::createMap( const HcalTopology* topo, unsigned int mapIOV ) {
39 
40  mapIOV_ = mapIOV;
41 
42  std::vector <HBHEHFLogicalMapEntry> HBHEHFEntries;
43  std::vector <HOHXLogicalMapEntry> HOHXEntries;
44  std::vector <CALIBLogicalMapEntry> CALIBEntries;
45  std::vector <ZDCLogicalMapEntry> ZDCEntries;
46  std::vector <HTLogicalMapEntry> HTEntries;
47  std::vector <uint32_t> LinearIndex2Entry;
48  std::vector <uint32_t> HbHash2Entry;
49  std::vector <uint32_t> HeHash2Entry;
50  std::vector <uint32_t> HfHash2Entry;
51  std::vector <uint32_t> HtHash2Entry;
52  std::vector <uint32_t> HoHash2Entry;
53  std::vector <uint32_t> HxCalibHash2Entry;
54  //std::vector <uint32_t> CalibHash2Entry;
55  std::vector <uint32_t> ZdcHash2Entry;
56 
57  int HbHalf = 1296;
58  int HeHalf = 1296;
59  //if (h2mode_) HeHalf = 4032;
60  int HoHalf = 1080;
61  int HfHalf = 864;
62  int HtHalf = 2088;
63  int ZdcHalf = 11;
64  int CalibFull=216+425+8;
65 
66  uint32_t illegal_value=0;
67  for (int i=0;i<=HcalElectronicsId::maxLinearIndex;i++) LinearIndex2Entry.push_back(illegal_value);
68  for (int iHb=0;iHb<2*HbHalf;iHb++) HbHash2Entry.push_back(illegal_value);
69  for (int iHe=0;iHe<2*HeHalf;iHe++) HeHash2Entry.push_back(illegal_value);
70  for (int iHf=0;iHf<2*HfHalf;iHf++) HfHash2Entry.push_back(illegal_value);
71  for (int iHt=0;iHt<2*HtHalf;iHt++) HtHash2Entry.push_back(illegal_value);
72  for (int iHo=0;iHo<2*HoHalf;iHo++) HoHash2Entry.push_back(illegal_value);
73  for (int iHcalib=0;iHcalib<CalibFull;iHcalib++) HxCalibHash2Entry.push_back(illegal_value);
74  for (int iZdc=0;iZdc<2*ZdcHalf;iZdc++) ZdcHash2Entry.push_back(illegal_value);
75 
76  buildHBEFTMap(topo,HBHEHFEntries,HTEntries,LinearIndex2Entry,HbHash2Entry,HeHash2Entry,HfHash2Entry,HtHash2Entry);
77  buildHOXMap(topo,HOHXEntries,LinearIndex2Entry,HoHash2Entry,HxCalibHash2Entry);
78  buildCALIBMap(topo,CALIBEntries,LinearIndex2Entry,HxCalibHash2Entry);
79  buildZDCMap(topo,ZDCEntries,LinearIndex2Entry,ZdcHash2Entry);
80 
81  return HcalLogicalMap(topo,HBHEHFEntries,HOHXEntries,CALIBEntries,ZDCEntries,HTEntries,
82  LinearIndex2Entry,HbHash2Entry,HeHash2Entry,HfHash2Entry,HtHash2Entry,
83  HoHash2Entry,HxCalibHash2Entry,/*CalibHash2Entry,*/ZdcHash2Entry);
84 }
85 
87  std::vector <HBHEHFLogicalMapEntry>& HBHEHFEntries,
88  std::vector <HTLogicalMapEntry>& HTEntries,
89  std::vector <uint32_t>& LinearIndex2Entry,
90  std::vector <uint32_t>& HbHash2Entry,
91  std::vector <uint32_t>& HeHash2Entry,
92  std::vector <uint32_t>& HfHash2Entry,
93  std::vector <uint32_t>& HtHash2Entry) {
94 
95  /******************************/
96  /* HBHE crate numbering */
97  int hbhecrate_loc[NHBHECR]={0,1,4,5,10,11,14,15,17};
98  memcpy( hbhecrate, hbhecrate_loc, sizeof(int)*NHBHECR );
99  /* HBHE FED numbering of DCCs */
100  int fedhbhenum_loc[NHBHECR][2]={{702,703},{704,705},{700,701},
101  {706,707},{716,717},{708,709},
102  {714,715},{710,711},{712,713}};
103  memcpy( fedhbhenum, fedhbhenum_loc, sizeof(int)*NHBHECR*2 );
104  /* HBHE/HF htr slot offsets for set of three htrs */
105  int ihslot_loc[NHSETS]={2,5,13,16};
106  memcpy( ihslot, ihslot_loc, sizeof(int)*NHSETS );
107  /* iphi (lower) starting index for each HBHE crate */
108  int ihbhephis_loc[NHBHECR]={11,19,3,27,67,35,59,43,51};
109  memcpy( ihbhephis, ihbhephis_loc, sizeof(int)*NHBHECR );
110  /* ihbheetadepth - unique HBHE {eta,depth} assignments per fiber and fiber channel */
111  int ihbheetadepth_loc[NHTRS][NTOPBOT][NFBR][NFCH][2]={
112  {{{{11,1},{ 7,1},{ 3,1}}, /* htr 0 (HB) -bot(+top) */
113  {{ 5,1},{ 1,1},{ 9,1}},
114  {{11,1},{ 7,1},{ 3,1}},
115  {{ 5,1},{ 1,1},{ 9,1}},
116  {{10,1},{ 6,1},{ 2,1}},
117  {{ 8,1},{ 4,1},{12,1}},
118  {{10,1},{ 6,1},{ 2,1}},
119  {{ 8,1},{ 4,1},{12,1}}},
120  {{{11,1},{ 7,1},{ 3,1}}, /* htr 0 (HB) +bot(-top) */
121  {{ 5,1},{ 1,1},{ 9,1}},
122  {{11,1},{ 7,1},{ 3,1}},
123  {{ 5,1},{ 1,1},{ 9,1}},
124  {{10,1},{ 6,1},{ 2,1}},
125  {{ 8,1},{ 4,1},{12,1}},
126  {{10,1},{ 6,1},{ 2,1}},
127  {{ 8,1},{ 4,1},{12,1}}}},
128  {{{{16,2},{15,2},{14,1}}, /* htr 1 (HBHE) -bot(+top) */
129  {{15,1},{13,1},{16,1}},
130  {{16,2},{15,2},{14,1}},
131  {{15,1},{13,1},{16,1}},
132  {{17,1},{16,3},{26,1}},
133  {{18,1},{18,2},{26,2}},
134  {{17,1},{16,3},{25,1}},
135  {{18,1},{18,2},{25,2}}},
136  {{{16,2},{15,2},{14,1}}, /* htr 1 (HBHE) +bot(-top) */
137  {{15,1},{13,1},{16,1}},
138  {{16,2},{15,2},{14,1}},
139  {{15,1},{13,1},{16,1}},
140  {{17,1},{16,3},{25,1}},
141  {{18,1},{18,2},{25,2}},
142  {{17,1},{16,3},{26,1}},
143  {{18,1},{18,2},{26,2}}}},
144  {{{{28,1},{28,2},{29,1}}, /* htr 2 (HE) -bot(+top) */
145  {{28,3},{24,2},{24,1}},
146  {{27,1},{27,2},{29,2}},
147  {{27,3},{23,2},{23,1}},
148  {{19,2},{20,1},{22,2}},
149  {{19,1},{20,2},{22,1}},
150  {{19,2},{20,1},{21,2}},
151  {{19,1},{20,2},{21,1}}},
152  {{{27,1},{27,2},{29,2}}, /* htr 2 (HE) +bot(-top) */
153  {{27,3},{23,2},{23,1}},
154  {{28,1},{28,2},{29,1}},
155  {{28,3},{24,2},{24,1}},
156  {{19,2},{20,1},{21,2}},
157  {{19,1},{20,2},{21,1}},
158  {{19,2},{20,1},{22,2}},
159  {{19,1},{20,2},{22,1}}}}
160  };
161  memcpy( ihbheetadepth, ihbheetadepth_loc, sizeof(int)*NHTRS*NTOPBOT*NFBR*NFCH*2 );
162 
163  //Aram's insert: I shall now define an array which contains the RM and the RM fiber for HB HE
164  //and variables associated with this table
165  int irm_rmfiHBHE_loc[NHTRS][NTOPBOT][NFBR][2]={
166  {{{6,1},{7,1},{6,2},{7,2},{4,1},{5,1},{4,2},{5,2}}, // HTR 0 top
167  {{6,3},{7,3},{6,4},{7,4},{4,3},{5,3},{4,4},{5,4}}}, // HTR 0 bot
168  {{{2,1},{3,1},{2,2},{3,2},{2,1},{3,1},{2,2},{3,2}}, // HTR 1 top
169  {{2,3},{3,3},{2,4},{3,4},{2,3},{3,3},{2,4},{3,4}}}, // HTR 1 bot
170  {{{4,1},{5,1},{4,2},{5,2},{6,1},{7,1},{6,2},{7,2}}, // HTR 2 top
171  {{4,3},{5,3},{4,4},{5,4},{6,3},{7,3},{6,4},{7,4}}} // HTR 2 bot
172  };
173  memcpy( irm_rmfiHBHE, irm_rmfiHBHE_loc, sizeof(int)*NHTRS*NTOPBOT*NFBR*2 );
174  //Pixel tables as a function of rm, rm fiber and fiber channel
175 
176  int ipixelHB_loc[NRMFIBR][NFCH][NRMSLOT] = { // fch = 0 fch = 1 fch = 2
177  {{18, 17, 3, 2 }, {13, 3, 17, 7 }, {14, 1, 19, 6 }}, //rmfiber = 2
178  {{19, 2, 18, 1 }, {15, 7, 13, 5 }, {17, 19, 1, 3 }}, //rmfiber = 3
179  {{9, 4, 16, 11}, {5, 8, 12, 15}, {2, 13, 7, 18}}, //rmfiber = 4
180  {{12, 11, 9, 8 }, {7, 15, 5, 13}, {16, 6, 14, 4 }}, //rmfiber = 5
181  {{8, 5, 15, 12}, {4, 9, 11, 16}, {1, 14, 6, 19}}, //rmfiber = 6
182  {{6, 16, 4, 14}, {3, 18, 2, 17}, {11, 12, 8, 9 }} //rmfiber = 7
183  };
184  memcpy( ipixelHB, ipixelHB_loc, sizeof(int)*NRMFIBR*NFCH*NRMSLOT );
185 
186  int ipixelHE_loc[NRMFIBR][NFCH][NRMSLOT] = { // fch = 0 fch = 1 fch = 2
187  {{12, 12, 12, 12}, {16, 7, 16, 7 }, {7, 16, 7, 16}}, //rmfiber = 2
188  {{11, 11, 11, 11}, {19, 3, 19, 3 }, {3, 19, 3, 19}}, //rmfiber = 3
189  {{15, 15, 6, 6 }, {2, 18, 2, 18}, {6, 6, 15, 15}}, //rmfiber = 4
190  {{5, 14, 5, 14}, {14, 5, 14, 5 }, {18, 2, 18, 2 }}, //rmfiber = 5
191  {{17, 1, 17, 1 }, {9, 9, 9, 9 }, {1, 17, 1, 17}}, //rmfiber = 6
192  {{13, 4, 13, 4 }, {8, 8, 8, 8 }, {4, 13, 4, 13}} //rmfiber = 7
193  };
194  memcpy( ipixelHE, ipixelHE_loc, sizeof(int)*NRMFIBR*NFCH*NRMSLOT );
195 
196  //slb and rct tables
197 
198  //HB and HE
199 
200  const char* S_slbin_odd_loc[] ={"A1","B0","B1","A0","A1","B0","B1","A0"};
201  for (int gg = 0; gg < 8; gg++) {
202  S_slbin_odd[gg] = S_slbin_odd_loc[gg];
203  }
204  const char* S_slbin_even_loc[]={"C1","D0","D1","C0","C1","D0","D1","C0"};
205  for (int gg = 0; gg < 8; gg++) {
206  S_slbin_even[gg] = S_slbin_even_loc[gg];
207  }
208  const char* rct_rackHBHE_loc[]={"S2E01-RH","S2E03-RH","S2E05-RH","S2E07-RH","S2E09-RH","S2E08-RL","S2E06-RL","S2E04-RL","S2E02-RL",
209  "S2E02-RH","S2E04-RH","S2E06-RH","S2E08-RH","S2E09-RL","S2E07-RL","S2E05-RL","S2E03-RL","S2E01-RL"};
210  for (int gg = 0; gg < 18; gg++) {
211  rct_rackHBHE[gg] = rct_rackHBHE_loc[gg];
212  }
213 
214  int slb_table_loc[29] = {1,1,2,2,3,3,4,4,5,5,6,6, // 1<=eta<=12
215  1,1,2,2,3,3,1,1, // 13<=eta<=20
216  2,2,3,3,4,4,4,4,4}; // 21<=eta<=29
217  memcpy( slb_table, slb_table_loc, sizeof(int)*29 );
218  /********************/
219 
220  char tempbuff[30]{0};
221 
222  //Stream variable
223  stringstream mystream;
224 
225  /* all HBHE crates */
226  for(ic=0; ic<NHBHECR; ic++){
227  /* four sets of three htrs per crate */
228  for(is=0; is<NHSETS; is++){
229  /* three htrs per set */
230  for(ih=0; ih<NHTRS; ih++){
231  /* top and bottom */
232  for(itb=0; itb<NTOPBOT; itb++){
233  /* eight fibers per HTR FPGA */
234  for(ifb=0; ifb<NFBR; ifb++){
235  /* three channels per fiber */
236  for(ifc=0; ifc<NFCH; ifc++){
237  icrate=hbhecrate[ic];
238  iside=is<NHSETS/2?-1:1;
239  ifwtb=(is/2+itb+1)%2;
240  ieta=ihbheetadepth[ih][ifwtb][ifb][ifc][0];
241  idepth=ihbheetadepth[ih][ifwtb][ifb][ifc][1];
242  ihtr=ihslot[is]+ih;
243  (ieta>16||idepth>2) ? det = "HE": det = "HB";
244  (itb%2)==1 ? fpga = "bot" : fpga = "top";
245  ihtr_fi=ifb+1;
246  ifi_ch=ifc;
247  iphi=(ieta>20)?(ihbhephis[ic]+(is%2)*4+itb*2-1)%72+1:(ihbhephis[ic]+(is%2)*4+itb*2+(ifb/2+is/2+1)%2-1)%72+1;
248  ispigot=(is%2)*6+ih*2+itb;
249  idcc=is<NHSETS/2?1:2;
250  idcc_sl=idcc==1?10:20;
251  ifed=fedhbhenum[ic][idcc-1];
252  //Aram's insert: rm variables, rbx, wedge
253  //Careful here: per Pawel's map, the rm fiber is the first entry an the rm itself is the second.
254 
255  //If iside == -1, switch top and bottom. Why?
256  if (iside == -1){
257  S_side = '-';
258  sidesign = 'M';
259  irm = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][1];
260  irm_fi = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][0];
261 
262  //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
263  if (ieta >= 21 && (irm == 1 || irm == 3)) iwedge = (iphi + 1 + irm + 1) / 4;
264  else iwedge = (iphi + irm + 1) / 4;
265 
266  //Roll over the wedge
267  if (iwedge > 18) iwedge -= 18;
268  }
269  else{
270  S_side = '+';
271  sidesign = 'P';
272  irm = irm_rmfiHBHE[ih][itb][ifb][1];
273  irm_fi = irm_rmfiHBHE[ih][itb][ifb][0];
274 
275  //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
276  if (ieta >= 21 && (irm == 4 || irm == 2)) iwedge = (iphi + 1 - irm + 6) / 4;
277  else iwedge = (iphi - irm + 6) / 4;
278 
279  //Roll over the wedge
280  if (iwedge > 18) iwedge -= 18;
281  }
282 
283  snprintf (tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
284  mystream<<tempbuff;
285  rbx = mystream.str();
286  mystream.str("");
287 
288  //Note that irm_fi ranges from 2 to 7 whereas arrays start at 0 so
289  //I use irm_fi - 2. Likewise, irm goes from 1 to 4 so use irm - 1
290 
291  //Pixel is split by HB and HE
292  if (ieta > 16 || idepth > 2) ipixel = ipixelHE[irm_fi - 2][ifc][irm - 1]; //HE
293  else ipixel = ipixelHB[irm_fi - 2][ifc][irm - 1]; //HB
294 
295  iqie = iadcquiHBHE[irm_fi - 2][ifc][0];
296  iadc = iadcquiHBHE[irm_fi - 2][ifc][1];
297 
298  phideg = iphi - 3;
299  if (phideg < 0) phideg = phideg + 72;
300  phideg = (phideg / 4) * 20 + 10;
301  irctcra = (( 89 - phideg + 720)%360)/20;
302  oddcard = irctcra % 2;
303  irctcra /= 2;
304  if (iside > 0) irctcra = irctcra + 9;
305 
306  etaslb = ((ieta - 1) / 2) * 2 + 1;
307  if (etaslb > 27) etaslb = 27;
308 
309 
310  snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
311  mystream<<tempbuff;
312  slnam = mystream.str();
313  mystream.str("");
314 
315  islb = slb_table[ieta - 1];
316 
317  // calculate RCT destination (that is, rctcon, rctcar and rctnam
318  if (ieta <= 24) { // these are the normal cards 0-5
319  irctcar = 2 * ((ieta - 1)/8) + oddcard;
320  irctcon = 2 * (((ieta - 1)/2)%4);
321  }
322  else { // these are on the special card 6 which folds back eta on the odd card half
323  irctcar = 6;
324  eta2 = ieta;
325  if (eta2 > 28) eta2 = 28;
326  if (oddcard == 0) eta3 = eta2;
327  else eta3 = 57 - eta2;
328  irctcon = 2 * (((eta3 - 1) / 2) % 4);
329  }
330  irctcon = 11 * irctcon + 1;
331 
332  snprintf(tempbuff, sizeof tempbuff, "%s-%1d-HD%2.2d", rct_rackHBHE[irctcra], irctcar, irctcon);
333  mystream<<tempbuff;
334  rctnam = mystream.str();
335  mystream.str("");
336 
337  //Finally, the slbin
338 
339  phimod8 = iphi % 8;
340 
341  for (i = 0; i < 18; i++) {
342  if (iphi < i * 4 + 3) {
343  crazy = i % 2;
344  break;
345  }
346  }
347 
348  int ietamod; // determine if eta is "odd" or "even".
349  if (ieta == 29) ietamod = 0;
350  else ietamod = ieta % 2;
351  if (ieta < 25) { // use the regular table
352  if (ietamod == 1) mystream<<S_slbin_odd[phimod8];
353  else mystream<<S_slbin_even[phimod8];
354  }
355  else if (crazy == 0) { // use the regular table
356  if (ietamod == 1) mystream<<S_slbin_odd[phimod8];
357  else mystream<<S_slbin_even[phimod8];
358  }
359  else { // swap odd/even!!!
360  if (ietamod == 1) mystream<<S_slbin_even[phimod8];
361  else mystream<<S_slbin_odd[phimod8];
362  }
363 
364  slbin = mystream.str();
365  mystream.str("");
366 
367  if (ieta > 20){
368  idphi = 2;
369  slbin2 = slbin;
370  slbin2[1] = '1';
371  }
372  else{
373  idphi = 1;
374  slbin2 = "NA";
375  }
376 
377  HBHEHFLogicalMapEntry hbeflmapentry(
378  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
379  det, iside, ieta, iphi, idepth,
380  idphi, iwedge, irm, irm_fi, ipixel, iqie, iadc,
381  islb, irctcra, irctcar, irctcon,
382  rbx, slbin, slbin2, slnam, rctnam
383  );
384  HBHEHFEntries.push_back(hbeflmapentry);
385  LinearIndex2Entry.at(hbeflmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,0,HBHEHFEntries.size()-1);
386 
387  const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
388  unsigned int denseId;
389  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenBarrel) {
390  denseId=topo->detId2denseIdHB(hgdi);
391  HbHash2Entry.at(denseId)=HBHEHFEntries.size();
392  }
393  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenEndcap) {
394  denseId=topo->detId2denseIdHE(hgdi);
395  HeHash2Entry.at(denseId)=HBHEHFEntries.size();
396  }
397  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenForward) {
398  denseId=topo->detId2denseIdHF(hgdi);
399  HfHash2Entry.at(denseId)=HBHEHFEntries.size();
400  }
401 
402  ConstructTriggerTower(topo,
403  HTEntries,
404  iside, ieta, iphi, idphi, idepth, det, iwedge, irm,
405  ipixel, iqie, iadc, irm_fi, ifi_ch, icrate, ihtr, fpga,
406  ihtr_fi, ispigot, islb, slbin, slbin2,
407  slnam, irctcra, irctcar, irctcon, rctnam, ifed
408  );
409  }
410  }
411  }
412  }
413  }
414  }
415 
416  /********************/
417  /* HF crate numbering */
418  int hfcrate_loc[NHFCR]={2,9,12};
419  memcpy( hfcrate, hfcrate_loc, sizeof(int)*NHFCR );
420  /* HF FED numbering of DCCs */
421  int fedhfnum_loc[NHFCR][2]={{718,719},{720,721},{722,723}};
422  memcpy( fedhfnum, fedhfnum_loc, sizeof(int)*NHFCR*2 );
423  /* iphi (lower) starting index for each HF crate */
424  int ihfphis_loc[NHFCR]={3,27,51};
425  memcpy( ihfphis, ihfphis_loc, sizeof(int)*NHFCR );
426  /* ihfetadepth - unique HF {eta,depth} assignments per fiber and fiber channel */
427  int ihfetadepth_loc[NTOPBOT][NFBR][NFCH][2]={
428  {{{33,1},{31,1},{29,1}}, /* top */
429  {{32,1},{30,1},{34,1}},
430  {{33,2},{31,2},{29,2}},
431  {{32,2},{30,2},{34,2}},
432  {{34,2},{32,2},{30,2}},
433  {{31,2},{29,2},{33,2}},
434  {{34,1},{32,1},{30,1}},
435  {{31,1},{29,1},{33,1}}},
436  {{{41,1},{37,1},{35,1}}, /* bot */
437  {{38,1},{36,1},{39,1}},
438  {{41,2},{37,2},{35,2}},
439  {{38,2},{36,2},{39,2}},
440  {{40,2},{38,2},{36,2}},
441  {{37,2},{35,2},{39,2}},
442  {{40,1},{38,1},{36,1}},
443  {{37,1},{35,1},{39,1}}}
444  };
445  memcpy( ihfetadepth, ihfetadepth_loc, sizeof(int)*NTOPBOT*NFBR*NFCH*2 );
446 
447 
448  int irm_rmfiHF_loc[NHTRS][NTOPBOT][NFBR][2]={
449  {{{1,2},{2,2},{3,2},{4,2},{1,3},{2,3},{3,3},{4,3}}, // HTR 0 top
450  {{5,2},{6,2},{7,2},{8,2},{5,3},{6,3},{7,3},{8,3}}}, // HTR 0 bot
451  {{{1,1},{2,1},{3,1},{4,1},{1,2},{2,2},{3,2},{4,2}}, // HTR 1 top
452  {{5,1},{6,1},{7,1},{8,1},{5,2},{6,2},{7,2},{8,2}}}, // HTR 1 bot
453  {{{1,3},{2,3},{3,3},{4,3},{1,1},{2,1},{3,1},{4,1}}, // HTR 2 top
454  {{5,3},{6,3},{7,3},{8,3},{5,1},{6,1},{7,1},{8,1}}} // HTR 2 bot
455  };
456  memcpy( irm_rmfiHF, irm_rmfiHF_loc, sizeof(int)*NHTRS*NTOPBOT*NFBR*2 );
457 
458  //HF
459  const char* S_slbin_7_loc[] ={"A0","A1","B0","B1"};
460  for (int gg = 0; gg < 4; gg++) {
461  S_slbin_7[gg] = S_slbin_7_loc[gg];
462  }
463  const char* S_slbin_3_loc[] ={"C0","C1","D0","D1"};
464  for (int gg = 0; gg < 4; gg++) {
465  S_slbin_3[gg] = S_slbin_3_loc[gg];
466  }
467  const char* rct_rackHF_loc[]={"S2E01-FH","S2E03-FH","S2E05-FH","S2E07-FH","S2E09-FH","S2E08-FL","S2E06-FL","S2E04-FL","S2E02-FL",
468  "S2E02-FH","S2E04-FH","S2E06-FH","S2E08-FH","S2E09-FL","S2E07-FL","S2E05-FL","S2E03-FL","S2E01-FL"};
469  for (int gg = 0; gg < 18; gg++) {
470  rct_rackHF[gg] = rct_rackHF_loc[gg];
471  }
472 
473 
474  /***************/
475 
476  /* all HF crates */
477  for(ic=0; ic<NHFCR; ic++){
478  /* four sets of three htrs per crate */
479  for(is=0; is<NHSETS; is++){
480  /* three htrs per set */
481  for(ih=0; ih<NHTRS; ih++){
482  /* top and bottom */
483  for(itb=0; itb<NTOPBOT; itb++){
484  /* eight fibers per HTR FPGA */
485  for(ifb=0; ifb<NFBR; ifb++){
486  /* three channels per fiber */
487  for(ifc=0; ifc<NFCH; ifc++){
488  icrate=hfcrate[ic];
489  iside=is<NHSETS/2?-1:1;
490  ieta=ihfetadepth[itb][ifb][ifc][0];
491  idepth=ihfetadepth[itb][ifb][ifc][1];
492  ihtr=ihslot[is]+ih;
493  det = "HF";
494  (itb%2)== 1 ? fpga = "bot" : fpga = "top";
495  ihtr_fi=ifb+1;
496  ifi_ch=ifc;
497  iphi=(ieta>39)?(ihfphis[ic]+(is%2)*12+ih*4-1)%72+1:(ihfphis[ic]+(is%2)*12+ih*4+(ifb/4)*2-1)%72+1;
498  ispigot=(is%2)*6+ih*2+itb;
499  idcc=is<NHSETS/2?1:2;
500  idcc_sl=idcc==1?10:20;
501  ifed=fedhfnum[ic][idcc-1];
502 
503  irm_fi = irm_rmfiHF[ih][itb][ifb][0];
504 
505  //Don't switch in the HF. Why?
506  if (iside == -1){
507  S_side = '-';
508  sidesign = 'M';
509 
510  if (ieta < 40){
511  if (iphi == 1) iphi = 71;
512  else if (iphi == 71) iphi = 1;
513  else if (iphi % 4 == 1) iphi -= 2;
514  else if (iphi % 4 == 3) iphi += 2;
515  else edm::LogInfo( "HcalLogicalMapGenerator") <<"Even iphi in HFM"<<endl;
516  }
517  }
518  else{
519  S_side = '+';
520  sidesign = 'P';
521  }
522 
523  //RM and RBX number
524  if ((iside == 1 && ieta == 40) || (iside == -1 && ieta == 41)){
525  irm = ((iphi + 1) / 2) % 36 + 1;
526  hfphi = ((iphi + 1) / 6) % 12 + 1;
527  }
528  else{
529  irm = ( iphi + 1) / 2;
530  hfphi = (iphi - 1) / 6 + 1;
531  }
532  irm = (irm - 1) % 3 + 1;
533 
534  //Wedge
535  if (iphi >= 71) iwedge = 1;
536  else iwedge = (iphi + 1) / 4 + 1;
537 
538  //RBX
539  snprintf (tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, hfphi);
540  mystream<<tempbuff;
541  rbx = mystream.str();
542  mystream.str("");
543 
544  //No pixel in HF, follow Fedor's convention
545  ipixel = 0;
546 
547  //Integer truncation again consistent with Fedor's map.
548  iqie = (irm_fi - 1) / 2 + 1;
549 
550  if (irm_fi % 2 != 0) iadc = ifi_ch;
551  else iadc = NFCH + (ifi_ch + 1) % 3;
552 
553  //slb and rct variables
554  //rctcrate
555  phideg = iphi - 3;
556  if (phideg < 0) phideg = phideg + 72;
557  phideg = (phideg / 4) * 20 + 10;
558  irctcra = (( 89 - phideg + 720)%360)/40;
559  if (iside > 0) irctcra = irctcra + 9;
560 
561  //rct card and rct connector appear to be dummy here -- again, I follow Fedor's convention
562  irctcar = 99;
563  irctcon = 0;
564 
565  etaslb = 29;
566 
567  snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
568  mystream<<tempbuff;
569  slnam = mystream.str();
570  mystream.str("");
571 
572  snprintf(tempbuff, sizeof tempbuff, "%s-JSC-HF_IN", rct_rackHF[irctcra]);
573  mystream<<tempbuff;
574  rctnam = mystream.str();
575  mystream.str("");
576 
577  islb = 6;
578 
579  int phibin = (iphi + 1) % 8 ;
580  int etabin = (ieta - 29) / 3;
581  if (etabin < 0) etabin = 0;
582  if (etabin > 3) etabin = 3;
583  if (phibin < 4) mystream<<S_slbin_7[etabin];
584  else mystream<<S_slbin_3[etabin];
585 
586  slbin = mystream.str();
587  mystream.str("");
588 
589  slbin2 = "NA";
590 
591  if (ieta < 40) idphi = 2;
592  else idphi = 4;
593 
594  HBHEHFLogicalMapEntry hbeflmapentry(
595  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
596  det, iside, ieta, iphi, idepth,
597  idphi, iwedge, irm, irm_fi, ipixel, iqie, iadc,
598  islb, irctcra, irctcar, irctcon,
599  rbx, slbin, slbin2, slnam, rctnam
600  );
601  HBHEHFEntries.push_back(hbeflmapentry);
602  LinearIndex2Entry.at(hbeflmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,0,HBHEHFEntries.size()-1);
603 
604  const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
605  unsigned int denseId;
606  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenBarrel) {
607  denseId=topo->detId2denseIdHB(hgdi);
608  HbHash2Entry.at(denseId)=HBHEHFEntries.size();
609  }
610  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenEndcap) {
611  denseId=topo->detId2denseIdHE(hgdi);
612  HeHash2Entry.at(denseId)=HBHEHFEntries.size();
613  }
614  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenForward) {
615  denseId=topo->detId2denseIdHF(hgdi);
616  HfHash2Entry.at(denseId)=HBHEHFEntries.size();
617  }
618 
619  ConstructTriggerTower(topo,
620  HTEntries,
621  iside, ieta, iphi, idphi, idepth, det, iwedge, irm,
622  ipixel, iqie, iadc, irm_fi, ifi_ch, icrate, ihtr, fpga,
623  ihtr_fi, ispigot, islb, slbin, slbin2,
624  slnam, irctcra, irctcar, irctcon, rctnam, ifed
625  );
626  }
627  }
628  }
629  }
630  }
631  }
632 }
633 
635  std::vector <HOHXLogicalMapEntry>& HOHXEntries,
636  std::vector <uint32_t>& LinearIndex2Entry,
637  std::vector <uint32_t>& HoHash2Entry,
638  std::vector <uint32_t>& HxCalibHash2Entry) {
639  /******************************/
640  /* HO crate numbering */
641  int hocrate_loc[NHOCR]={3,7,6,13};
642  memcpy( hocrate, hocrate_loc, sizeof(int)*NHOCR );
643  /* HO FED numbering of DCCs */
644  int fedhonum_loc[NHOCR][2]={{724,725},{726,727},{728,729},{730,731}};
645  memcpy( fedhonum, fedhonum_loc, sizeof(int)*NHOCR*2 );
646  /* HO htr slot offsets for three sets of four htrs */
647  int ihslotho_loc[NHSETSHO][NHTRSHO]={{2,3,4,5},{6,7,13,14},{15,16,17,18}};
648  memcpy( ihslotho, ihslotho_loc, sizeof(int)*NHSETSHO*NHTRSHO );
649  /* iphi (lower) starting index for each HO crate */
650  int ihophis_loc[NHOCR]={71,17,35,53};
651  memcpy( ihophis, ihophis_loc, sizeof(int)*NHOCR );
652 
653  //RM for the HO as a function of eta, phi and side as implemented in complete_ho_map.txt
654  //There are only 24 phi columns because after that it begins to repeat. The relevant variable is phi mod 24.
655  //HX as the 16th eta entry
656  int HO_RM_table_loc[24][16][2] =
657  {
658  {{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
659  {{2,2},{2,2},{2,2},{2,2},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
660  {{3,3},{3,3},{3,3},{3,3},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
661  {{3,3},{3,3},{3,3},{3,3},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
662  {{4,4},{4,4},{4,4},{4,4},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
663  {{4,4},{4,4},{4,4},{4,4},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
664  {{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
665  {{3,3},{3,3},{3,3},{3,3},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
666  {{2,2},{2,2},{2,2},{2,2},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
667  {{2,2},{2,2},{2,2},{2,2},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
668  {{4,4},{4,4},{4,4},{4,4},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
669  {{4,4},{4,4},{4,4},{4,4},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
670  {{3,3},{3,3},{3,3},{3,3},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
671  {{3,3},{3,3},{3,3},{3,3},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
672  {{2,2},{2,2},{2,2},{2,2},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
673  {{2,2},{2,2},{2,2},{2,2},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
674  {{1,1},{1,1},{1,1},{1,1},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
675  {{1,1},{1,1},{1,1},{1,1},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
676  {{2,2},{2,2},{2,2},{2,2},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
677  {{2,2},{2,2},{2,2},{2,2},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
678  {{3,3},{3,3},{3,3},{3,3},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
679  {{3,3},{3,3},{3,3},{3,3},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
680  {{1,1},{1,1},{1,1},{1,1},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
681  {{1,1},{1,1},{1,1},{1,1},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2}}
682  };
683  memcpy( HO_RM_table, HO_RM_table_loc, sizeof(int)*24*16*2 );
684 
685  //For |eta| 5 to 15, rm_fi is a function of |eta| only while htr_fi is a function of side and |eta|
686  int HO_RM_fi_eta5to15_loc[11] = {3, 2, 5, 4, 7, 6, 3, 2, 5, 4, 7};
687  memcpy( HO_RM_fi_eta5to15, HO_RM_fi_eta5to15_loc, sizeof(int)*11 );
688  //For eta=16 it is 6, declared in the header
689  HO_RM_fi_eta16 = 6;
690  //For eta in the YB0 region, rm_fi is dependent on side, 4 for -1, and 5 for +1
691  //but the values won't be any different than when the regular loop is executed
692  //int HO_RM_fi_etaYB0[2] = {4, 5}
693 
694  //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,
695  //eta 4 is separate and thus gets its own box
696  //threefold symmetry in iphi, repeats every three groups of 8 i.e., 1to8 == 25to32 == 49to56,
697  //similarly for the other iphi groups
698  //[iphi][ieta 1-3/4][side m/p]
699  //Actually has more modular structure which is not repetitive cyclicly
700  // groups of 4 in iphi repeat 1to4 == 17to20 == 21to24
701  // groups of 4 in iphi repeat 5to8 == 9to12 == 13to16
702  int HO_RM_fi_eta1to4_loc[24][2][2] =
703  { //side = -1 side = 1
704  {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}}, //Phi 1 to 8, Phi 25 to 32, Phi 49 to 56
705  {{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}}, //Phi 9 to 16, Phi 33 to 40, Phi 57 to 64
706  {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}} //Phi 17 to 24, Phi 41 to 48, Phi 65 to 72
707  };
708  memcpy( HO_RM_fi_eta1to4, HO_RM_fi_eta1to4_loc, sizeof(int)*24*2*2 );
709 
710  /* new mapping with SiPMs in HO ring-0 */
711  //The mapping is different for HO ring-0 with HPDs (above) or SiPMs (here)
712  // as the SiPM mapping is not cyclic in the same way as before
713  //[iphi][ieta][side m/p]
714  //threefold symmetry in iphi, repeats every three lines i.e., 1to8 == 25to32 == 49to56,
715  //similarly for the other iphi groups
716  //(iphi-1)mod(24)
717  //ieta4,rm_fi5,fi_ch1 5 -> 3:{minus:evenphi,plus:oddphi}
718  //ieta4,rm_fi5,fi_ch2 5 -> 2:{minus:oddphi,plus:evenphi}
719  int HO_RM_fi_eta1to4_sipm_loc[24][4][2] =
720  { //side = -1 side = 1
721  {{5,3},{5,5},{7,3},{6,3}}, {{4,2},{7,4},{7,2},{6,2}}, {{5,3},{5,5},{7,3},{6,3}}, {{4,2},{7,4},{7,2},{6,2}}, //Phi 1 to 4
722  {{2,4},{4,7},{2,7},{2,6}}, {{3,5},{5,5},{3,7},{3,6}}, {{2,4},{4,7},{2,7},{2,6}}, {{3,5},{5,5},{3,7},{3,6}}, //Phi 5 to 8
723  {{2,4},{4,7},{2,7},{2,6}}, {{3,5},{5,5},{3,7},{3,6}}, {{2,4},{4,7},{2,7},{2,6}}, {{3,5},{5,5},{3,7},{3,6}}, //Phi 9 to 12
724  {{2,4},{4,7},{2,7},{2,6}}, {{3,5},{5,5},{3,7},{3,6}}, {{2,4},{4,7},{2,7},{2,6}}, {{3,5},{5,5},{3,7},{3,6}}, //Phi 13 to 16
725  {{5,3},{5,5},{7,3},{6,3}}, {{4,2},{7,4},{7,2},{6,2}}, {{5,3},{5,5},{7,3},{6,3}}, {{4,2},{7,4},{7,2},{6,2}}, //Phi 17 to 20
726  {{5,3},{5,5},{7,3},{6,3}}, {{4,2},{7,4},{7,2},{6,2}}, {{5,3},{5,5},{7,3},{6,3}}, {{4,2},{7,4},{7,2},{6,2}}, //Phi 21 to 24
727  };
728  memcpy( HO_RM_fi_eta1to4_sipm, HO_RM_fi_eta1to4_sipm_loc, sizeof(int)*24*4*2 );
729 
730  // htr_fi
731  int HO_htr_fi_450eta5to15_loc[2][11] = {{2, 2, 4, 6, 8, 2, 4, 6, 8, 4, 6}, //iside = -1
732  {2, 8, 6, 4, 2, 8, 6, 4, 2, 4, 2}}; //iside = +1
733  memcpy( HO_htr_fi_450eta5to15, HO_htr_fi_450eta5to15_loc, sizeof(int)*2*11 );
734  // for the minus side, htr_fi is determined by the RM, will have to shift up one since rm is
735  //numbered 1-4 not 0-3
736  int HO_htr_fi_450eta16M_loc[4] = {7, 7, 8, 8};//iside = -1
737  memcpy( HO_htr_fi_450eta16M, HO_htr_fi_450eta16M_loc, sizeof(int)*4 );
738  //For the plus side, there is a new htr so all values can be used, but only 6 are used
739  //Depend on phi, but also on rm and sector (2,4,6,8,10,12)
740  int HO_htr_fi_450eta16P_loc[4][6] = { {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
741  memcpy( HO_htr_fi_450eta16P, HO_htr_fi_450eta16P_loc, sizeof(int)*4*6 );
742 
743  //for |eta| <= 4, htr_fi is a function of side and phmod6
744  int HO_htr_fi_eta4_loc[2][6] = {{6, 6, 8, 8, 7, 7}, //iside = -1
745  {4, 4, 5, 5, 3, 3}}; //iside = +1
746  if (mapIOV_<5)
747  memcpy( HO_htr_fi_eta4, HO_htr_fi_eta4_loc, sizeof(int)*2*6 );
748 
749  int HO_htr_fi_eta123_loc[2][6] = {{6, 5, 4, 3, 8, 7}, //iside = -1
750  {8, 7, 6, 5, 2, 1}}; //iside = +1
751  if (mapIOV_<5)
752  memcpy( HO_htr_fi_eta123, HO_htr_fi_eta123_loc, sizeof(int)*2*6 );
753 
754  //HO_htr_fi_123eta5to15[2][11] is unnecessary because
755  // HO_htr_fi_123eta5to15[i][j] == int HO_htr_fi_450eta5to15[i][j] - 1
756 
757  //post SiPM card swap
758  // htr_fi is a function of phmod6,eta,rm,side
759  // rm is a function of phimod6: rm = 1,4 for phimod6 > 3, and 2,3 otherwise
760  // to index the array, take rm/2 integer division
761  // cross-talk channels are separate
762  int HO_htr_fi_eta1234_sipm[6][5][2][2] = {
763  { /*eta==1*/ /*eta==2*/ /*eta==3*/ /*eta==4*/ /*cross-talk*/
764  {{4,8},{6,4}}, {{4,4},{4,7}}, {{6,8},{6,7}}, {{5,8},{6,8}}, {{5,6},{-1,-1}} },//phm6==0
765  {
766  {{6,7},{5,6}}, {{6,6},{6,6}}, {{6,7},{5,7}}, {{5,7},{5,8}}, {{-1,-1},{4,8}} },//phm6==1
767  {
768  {{4,5},{5,6}}, {{5,5},{5,5}}, {{4,5},{4,6}}, {{4,6},{3,6}}, {{-1,-1},{3,8}} },//phm6==2
769  {
770  {{3,8},{8,5}}, {{8,8},{4,8}}, {{3,5},{4,5}}, {{3,6},{3,5}}, {{5,6},{-1,-1}} },//phm6==3
771  {
772  {{3,2},{8,3}}, {{3,3},{3,1}}, {{8,2},{8,1}}, {{7,2},{8,2}}, {{7,7},{-1,-1}} },//phm6==4
773  {
774  {{7,1},{7,7}}, {{8,7},{7,7}}, {{8,1},{7,1}}, {{7,1},{7,2}}, {{-1,-1},{3,2}} },//phm6==5
775  };
776 
777  // Pixel and letter code for HO.
778  // Ring 0 is separate and goes into entry 0, Rings +/- 1,2 are all the same and go to entry 1.
779  // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 4, pixel = 18, let_code = X
780  // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 5, pixel = 2, let_code = X
781  // Fiber Channel 0 1 2
782  int ipixelHO_loc[NRMFIBR][NFCH][2] = {{{12,12},{ 7, 7},{ 6, 3}}, //RM fiber 2
783  {{ 4, 4},{ 8, 8},{ 5, 1}}, //RM fiber 3
784  {{19,11},{18, 6},{17, 2}}, //RM fiber 4
785  {{ 2, 9},{ 1,13},{ 3, 5}}, //RM fiber 5
786  {{11,19},{16,18},{15,17}}, //RM fiber 6
787  {{13,15},{ 9,14},{14,16}}}; //RM fiber 7
788  //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
789  int ipixelHO_sipm[NRMFIBR][NFCH][2] = {{{12,12},{ 7, 7},{ 3, 3}}, //RM fibers 2
790  {{ 4, 4},{ 8, 8},{ 1, 1}}, //RM fibers 3
791  {{11,11},{ 6, 6},{ 2, 2}}, //RM fibers 4
792  {{ 9, 9},{13,13},{ 5, 5}}, //RM fibers 5
793  {{19,19},{18,18},{17,17}}, //RM fibers 6
794  {{15,15},{14,14},{16,16}}}; //RM fibers 7
795  if (mapIOV_ < 5)
796  memcpy( ipixelHO, ipixelHO_loc, sizeof(int)*NRMFIBR*NFCH*2 );
797  else
798  memcpy( ipixelHO, ipixelHO_sipm, sizeof(int)*NRMFIBR*NFCH*2 );
799 
800  // Fiber Channel 0 1 2
801  std::string letterHO_loc[NRMFIBR][NFCH][2] = {{{"E","E"},{"G","L"},{"F","S"}}, //RM fiber 2
802  {{"Q","M"},{"N","T"},{"P","F"}}, //RM fiber 3
803  {{"A","C"},{"X","J"},{"J","Q"}}, //RM fiber 4
804  {{"X","K"},{"R","R"},{"H","D"}}, //RM fiber 5
805  {{"D","A"},{"C","G"},{"B","N"}}, //RM fiber 6
806  {{"L","H"},{"M","P"},{"K","B"}}}; //RM fiber 7
807  //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
808  std::string letterHO_sipm[NRMFIBR][NFCH][2] = {{{"E","E"},{"G","L"},{"H","S"}}, //RM fibers 2
809  {{"Q","M"},{"N","T"},{"R","F"}}, //RM fibers 3
810  {{"D","C"},{"F","J"},{"X","Q"}}, //RM fibers 4
811  {{"M","K"},{"L","R"},{"P","D"}}, //RM fibers 5
812  {{"A","A"},{"X","G"},{"J","N"}}, //RM fibers 6
813  {{"B","H"},{"K","P"},{"C","B"}}}; //RM fibers 7
814 
815  for (int jj = 0; jj < NRMFIBR; jj++) {
816  for (int kk = 0; kk < NFCH; kk++) {
817  for (int ll = 0; ll < 2; ll++) {
818  if (mapIOV_ < 5)
819  letterHO[jj][kk][ll] = letterHO_loc[jj][kk][ll];
820  else
821  letterHO[jj][kk][ll] = letterHO_sipm[jj][kk][ll];
822  }
823  }
824  }
825 
826  /******************************************************************************************/
827  // Here is the section that deals with the miscabled HO RBXs.
828  // To modify the code between IOVs, just note that inverted corresponds to -infinity to end of 2008
829  // and otherwise, to 2009 to infinity.
830  // Except for some small but major caveats:
831  // HO2M04 (phi=16) was not able to be corrected, thus it is still inverted
832  // HO2M06 (phi=31) has not been active in 2009, and the cables have not been switched officially
833  // HO2P12 (phi=67) has not been active in 2009, and the cables have not been switched officially
834  // In the map, the inactive RBXs have been switched since the changes will be effected when the HO SiPMs
835  // are installed, also at that time, if it is possible, HO2M04 will be corrected as well.
836  // Following intervention in May 2009, the aforementioned changes have been implemented.
837  // All miscablings have been corrected
838 
839  // switched HO RM's need reversed eta values
840  if(mapIOV_==1) {
841  int rmspecialeta_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
842  { 14, 15, 14, 13, 12, 11 }, // ring +2 phi = 5, inverted
843  { 14, 15, 14, 13, 12, 11 }, // ring +2 phi = 67, inverted
844  { 10, 9, 8, 7, 6, 5 }, // ring -1 phi = 57, inverted
845  { 10, 9, 8, 7, 6, 5 }, // ring -1 phi = 65, inverted
846  { 14, 15, 14, 13, 12, 11 }, // ring -2 phi = 16, inverted
847  { 14, 15, 14, 13, 12, 11 } // ring -2 phi = 31, inverted
848  };
849 
850  std::string rmspeciallet_code_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
851  { "X", "B", "C", "D", "E", "F" }, // ring +2 phi = 5, inverted
852  { "X", "P", "Q", "R", "S", "T" }, // ring +2 phi = 67, inverted
853  { "G", "H", "J", "K", "L", "M" }, // ring -1 phi = 57, inverted
854  { "A", "B", "C", "D", "E", "F" }, // ring -1 phi = 65, inverted
855  { "X", "B", "C", "D", "E", "F" }, // ring -2 phi = 16, inverted
856  { "X", "P", "Q", "R", "S", "T" } // ring -2 phi = 31, inverted
857  };
858 
859  std::string rmspecialdet_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
860  { "HOX", "HO", "HO", "HO", "HO", "HO" }, // ring +2 phi = 5, inverted
861  { "HOX", "HO", "HO", "HO", "HO", "HO" }, // ring +2 phi = 67, inverted
862  { "HO", "HO", "HO", "HO", "HO", "HO" }, // ring -1 phi = 57, inverted
863  { "HO", "HO", "HO", "HO", "HO", "HO" }, // ring -1 phi = 65, inverted
864  { "HOX", "HO", "HO", "HO", "HO", "HO" }, // ring -2 phi = 16, inverted
865  { "HOX", "HO", "HO", "HO", "HO", "HO" } // ring -2 phi = 31, inverted
866  };
867 
868  memcpy( rmspecialeta, rmspecialeta_loc, sizeof(int)*6*6 );
869  // switched HO RM's need revised letter codes
870 
871  for (int jj = 0; jj < 6; jj++) {
872  for (int kk = 0; kk < 6; kk++) {
873  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];}}
874 
875  for (int jj = 0; jj < 6; jj++) {
876  for (int kk = 0; kk < 6; kk++) {
877  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];}}
878  }
879 
880  else if (mapIOV_==2) {
881  int rmspecialeta_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
882  { 11, 12, 13, 14, 15, 15 }, // ring +2 phi = 5
883  { 11, 12, 13, 14, 15, 15 }, // ring +2 phi = 67
884  { 5, 6, 7, 8, 9, 10 }, // ring -1 phi = 57
885  { 5, 6, 7, 8, 9, 10 }, // ring -1 phi = 65
886  { 14, 15, 14, 13, 12, 11 }, // ring -2 phi = 16, still inverted
887  { 11, 12, 13, 14, 15, 15 } // ring -2 phi = 31
888  };
889 
890  std::string rmspeciallet_code_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
891  { "F", "E", "D", "C", "B", "X" }, // ring +2 phi = 5
892  { "T", "S", "R", "Q", "P", "X" }, // ring +2 phi = 67
893  { "M", "L", "K", "J", "H", "G" }, // ring -1 phi = 57
894  { "F", "E", "D", "C", "B", "A" }, // ring -1 phi = 65
895  { "X", "B", "C", "D", "E", "F" }, // ring -2 phi = 16,still inverted
896  { "T", "S", "R", "Q", "P", "X" } // ring -2 phi = 31
897  };
898 
899  std::string rmspecialdet_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
900  { "HO", "HO", "HO", "HO", "HO", "HOX" }, // ring +2 phi = 5
901  { "HO", "HO", "HO", "HO", "HO", "HOX" }, // ring +2 phi = 67
902  { "HO", "HO", "HO", "HO", "HO", "HO" }, // ring -1 phi = 57
903  { "HO", "HO", "HO", "HO", "HO", "HO" }, // ring -1 phi = 65
904  { "HOX", "HO", "HO", "HO", "HO", "HO" }, // ring -2 phi = 16, still inverted
905  { "HO", "HO", "HO", "HO", "HO", "HOX" } // ring -2 phi = 31
906  };
907 
908  memcpy( rmspecialeta, rmspecialeta_loc, sizeof(int)*6*6 );
909  // switched HO RM's need revised letter codes
910 
911  for (int jj = 0; jj < 6; jj++) {
912  for (int kk = 0; kk < 6; kk++) {
913  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];}}
914 
915  for (int jj = 0; jj < 6; jj++) {
916  for (int kk = 0; kk < 6; kk++) {
917  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];}}
918  }
919 
920  else {
921  int rmspecialeta_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
922  { 11, 12, 13, 14, 15, 15 }, // ring +2 phi = 5
923  { 11, 12, 13, 14, 15, 15 }, // ring +2 phi = 67
924  { 5, 6, 7, 8, 9, 10 }, // ring -1 phi = 57
925  { 5, 6, 7, 8, 9, 10 }, // ring -1 phi = 65
926  { 11, 12, 13, 14, 15, 15 }, // ring -2 phi = 16
927  { 11, 12, 13, 14, 15, 15 } // ring -2 phi = 31
928  };
929 
930  std::string rmspeciallet_code_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
931  { "F", "E", "D", "C", "B", "X" }, // ring +2 phi = 5
932  { "T", "S", "R", "Q", "P", "X" }, // ring +2 phi = 67
933  { "M", "L", "K", "J", "H", "G" }, // ring -1 phi = 57
934  { "F", "E", "D", "C", "B", "A" }, // ring -1 phi = 65
935  { "F", "E", "D", "C", "B", "X" }, // ring -2 phi = 16
936  { "T", "S", "R", "Q", "P", "X" } // ring -2 phi = 31
937  };
938 
939  std::string rmspecialdet_loc[6][6] = { //there are 6 special cases, corresponding to 6 values of phi
940  { "HO", "HO", "HO", "HO", "HO", "HOX" }, // ring +2 phi = 5
941  { "HO", "HO", "HO", "HO", "HO", "HOX" }, // ring +2 phi = 67
942  { "HO", "HO", "HO", "HO", "HO", "HO" }, // ring -1 phi = 57
943  { "HO", "HO", "HO", "HO", "HO", "HO" }, // ring -1 phi = 65
944  { "HO", "HO", "HO", "HO", "HO", "HOX" }, // ring -2 phi = 16
945  { "HO", "HO", "HO", "HO", "HO", "HOX" } // ring -2 phi = 31
946  };
947 
948  memcpy( rmspecialeta, rmspecialeta_loc, sizeof(int)*6*6 );
949  // switched HO RM's need revised letter codes
950 
951  for (int jj = 0; jj < 6; jj++) {
952  for (int kk = 0; kk < 6; kk++) {
953  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];}}
954 
955  for (int jj = 0; jj < 6; jj++) {
956  for (int kk = 0; kk < 6; kk++) {
957  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];}}
958  }
959 
960  /******************************/
961 
962  char tempbuff[30]{0};
963 
964  //Stream variable
965  stringstream mystream;
966 
967  //Radical change: HO iterates over eta and phi rather than crate, HTR, etc.
968  for(isid = -1; isid < 2; isid+=2){
969  for (iph = 0; iph < NHOPHI; iph++){
970  for (iet = 0; iet < NHOETA; iet++){
971 
972  iphi = iph + 1;
973  ieta = iet + 1;
974  iside = isid;
975 
976  if (iphi >= 71 || iphi < 17) ic = 0;
977  else if (iphi >= 17 && iphi < 35) ic = 1;
978  else if (iphi >= 35 && iphi < 53) ic = 2;
979  else ic = 3;
980 
981  icrate=hocrate[ic];
982  idepth=4;
983  det = "HO";
984 
985  //fpga = top/bottom for Ring 0 depends on a pattern that repeats every 30 degrees (6 phi)
986  //Hence, phmod6 (not phi mod 6 because I don't want to separate 71 and 72, etc.)
987 
988  phmod6 = iph % 6;
989  //Bools associated with phmod6 to be used with htr_fi and the patch panel
990  phmod6e450 = (phmod6 == 4 || phmod6 == 5 || phmod6 == 0);
991  phmod6e123 = (phmod6 == 1 || phmod6 == 2 || phmod6 == 3);
992 
993  //Ring 0 (HTR type 0) is special
994  if (ieta <= 3 && (iside < 0 || phmod6 >= 4)) fpga = "bot";
995  else if (ieta <= 3 && iside > 0 && phmod6 < 4) fpga = "top";
996  //new HX HTR
997  else if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6)) fpga = "top";
998  else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13)) fpga = "bot";
999  //HTR types 0 and 1
1000  else if (ieta >= 10 && iside > 0) fpga = "top";
1001  else if (ieta < 10 && ieta >= 6 && iside > 0) fpga = "bot";
1002  //HTR types 2 and 3
1003  else if ((ieta == 5 && iside > 0) || ieta == 4) fpga = "top";
1004  else if ((ieta == 5 || ieta >= 10) && iside < 0) fpga = "bot";
1005  else if ((ieta < 10 && ieta >= 6) && iside < 0) fpga = "top";
1006  else edm::LogInfo( "HcalLogicalMapGenerator") <<"Bad fpga code"<<endl;
1007 
1008  //dphi
1009  if (ieta <= 20) idphi = 1;
1010  else idphi = -1000;
1011 
1012  //create values usable in arrays from side and fpga
1013  if (iside == 1) sidear = 1;
1014  else sidear = 0;
1015 
1016  phmod24 = iph % 24;
1017 
1018  //Again, x - 1 because the array starts at 0 while the variables start at 1
1019  irm = HO_RM_table[phmod24][iet][sidear];
1020 
1021  //x - 5 for the eta array for the same reason
1022  // the new stuff for HX
1023  if (ieta==16) irm_fi = HO_RM_fi_eta16;
1024  else if (ieta >= 5) irm_fi = HO_RM_fi_eta5to15[ieta - 5];
1025  else {
1026  if (mapIOV_ < 5) {
1027  if (ieta <= 3) irm_fi = HO_RM_fi_eta1to4[phmod24][0][sidear];
1028  else if (ieta == 4) irm_fi = HO_RM_fi_eta1to4[phmod24][1][sidear];
1029  else irm_fi = -1000;
1030  }
1031  else if (mapIOV_ >= 5) {
1032  irm_fi = HO_RM_fi_eta1to4_sipm[phmod24][ieta-1][sidear];
1033  }
1034  }
1035 
1036  //HTR fiber
1037 
1038  //
1039  if (ieta >= 5 && phmod6e450) ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5];
1040  else if (ieta >= 5 && phmod6e123) ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5] - 1;
1041  else if (ieta <= 4) {
1042  if (mapIOV_ < 5) {
1043  if (ieta == 4) ihtr_fi = HO_htr_fi_eta4[sidear][phmod6];
1044  else if (ieta <= 3) ihtr_fi = HO_htr_fi_eta123[sidear][phmod6];
1045  }
1046  else if (mapIOV_ >= 5) {
1047  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][ieta-1][(irm-1)/2][sidear];
1048  }
1049  }
1050  else ihtr_fi = -1000;
1051 
1052  //Fiber Channel
1053  //Eta >= 5 bools
1054  phi1458 = (iphi % 12 == 1 || iphi % 12 == 4 || iphi % 12 == 5 || iphi % 12 == 8);
1055  phi271011 = (iphi % 12 == 2 || iphi % 12 == 7 || iphi % 12 == 10 || iphi % 12 == 11);
1056 
1057  //Ring 0 bools
1058  phir0v1 = (iphi % 24 == 0 || iphi % 24 == 2 || iphi % 24 == 4 || iphi % 24 == 18 || iphi % 24 == 20 || iphi % 24 == 22);
1059  phir0v2 = (iphi % 24 == 1 || iphi % 24 == 3 || iphi % 24 == 17 || iphi % 24 == 19 || iphi % 24 == 21 || iphi % 24 == 23);
1060  //v3: phi 5 to 15 odd; v4: phi 6 to 16 even
1061  phir0v3 = (iphi % 24 == 5 || iphi % 24 == 7 || iphi % 24 == 9 || iphi % 24 == 11 || iphi % 24 == 13 || iphi % 24 == 15);
1062  phir0v4 = (iphi % 24 == 6 || iphi % 24 == 8 || iphi % 24 == 10 || iphi % 24 == 12 || iphi % 24 == 14 || iphi % 24 == 16);
1063 
1064  if (ieta >= 5){
1065  if (ieta % 2 == 0 && phi1458) ifi_ch = 0;
1066  else if (ieta % 2 == 0 && iphi % 3 == 0) ifi_ch = 1;
1067  else if (ieta % 2 == 0 && phi271011) ifi_ch = 2;
1068  else if (ieta % 2 == 1 && iphi % 3 == 0) ifi_ch = 0;
1069  else if (ieta % 2 == 1 && phi271011) ifi_ch = 1;
1070  else if (ieta % 2 == 1 && phi1458) ifi_ch = 2;
1071  }
1072  else {
1073  if (mapIOV_ < 5) {
1074  if (ieta == 4){
1075  if (iside == -1){
1076  if (phir0v1) ifi_ch = 0;
1077  else if (phir0v4) ifi_ch = 1;
1078  else if (iphi % 2 == 1) ifi_ch = 2;
1079  }
1080  else{
1081  if (phir0v3) ifi_ch = 0;
1082  else if (phir0v2) ifi_ch = 1;
1083  else if (iphi % 2 == 0) ifi_ch = 2;
1084  }
1085  }
1086  //eta = -3 and eta = +2
1087  else if ((ieta == 3 && iside == -1) || (ieta == 2 && iside == 1)){
1088  if (phir0v4) ifi_ch = 0;
1089  else if (phir0v3) ifi_ch = 1;
1090  else if (phir0v1 || phir0v2) ifi_ch = 2;
1091  }
1092  //eta = -2 and eta = +3
1093  else if ((ieta == 3 && iside == 1) || (ieta == 2 && iside == -1)){
1094  if (phir0v2) ifi_ch = 0;
1095  else if (phir0v1) ifi_ch = 1;
1096  else if (phir0v3 || phir0v4) ifi_ch = 2;
1097  }
1098  //ieta = 1
1099  else if (ieta == 1){
1100  if (phir0v1 || phir0v3) ifi_ch = 0;
1101  else if (phir0v2 || phir0v4) ifi_ch = 1;
1102  }
1103  }
1104  else {
1105  /*New code here for SiPM handling of rm fiber channel
1106  more challenging and requires some thought*/
1107  if (ieta == 4){
1108  if (iside == -1){
1109  if (phir0v1) ifi_ch = 0;
1110  else if (phir0v4) ifi_ch = 2;
1111  else if (iphi % 2 == 1) ifi_ch = 2;
1112  }
1113  else{
1114  if (phir0v3) ifi_ch = 0;
1115  else if (phir0v2) ifi_ch = 2;
1116  else if (iphi % 2 == 0) ifi_ch = 2;
1117  }
1118  }
1119  if (ieta == 2){
1120  if (iside == -1){
1121  if (iphi % 2 == 0) ifi_ch = 2;
1122  else if (iphi % 2 == 1) ifi_ch = 1;
1123  }
1124  else{
1125  if (iphi % 2 == 0) ifi_ch = 1;
1126  else if (iphi % 2 == 1) ifi_ch = 2;
1127  }
1128  }
1129  if (ieta == 3){
1130  if (iside == -1){
1131  if (iphi % 2 == 0) ifi_ch = 0;
1132  else if (iphi % 2 == 1) ifi_ch = 1;
1133  }
1134  else{
1135  if (iphi % 2 == 1) ifi_ch = 0;
1136  else if (iphi % 2 == 0) ifi_ch = 1;
1137  }
1138  }
1139  if (ieta == 1){
1140  if (iside == -1){
1141  if (phir0v1) ifi_ch = 0;
1142  else if (phir0v4) ifi_ch = 1;
1143  else if (iphi % 2 == 1) ifi_ch = 0;
1144  }
1145  else{
1146  if (phir0v3) ifi_ch = 0;
1147  else if (phir0v2) ifi_ch = 1;
1148  else if (iphi % 2 == 0) ifi_ch = 0;
1149  }
1150  }
1151  }
1152  }
1153 
1154  //Intentional integer truncation; iqie and iadc are the same across all subdetectors
1155  //(Although irm_fi for HF starts at 1 and for HO it starts at 2, so one can't just copy and paste)
1156  iqie = (irm_fi - 2) / 2 + 1;
1157 
1158  if (irm_fi % 2 == 0) iadc = ifi_ch;
1159  else iadc = NFCH + (ifi_ch + 1) % 3;
1160 
1161  //Pixel and Letter Code (Ring 0 is separate)
1162  if (ieta <= 4){
1163  ipixel = ipixelHO[irm_fi - 2][ifi_ch][0];
1164  letter = letterHO[irm_fi - 2][ifi_ch][0];
1165  }
1166  else{
1167  ipixel = ipixelHO[irm_fi - 2][ifi_ch][1];
1168  letter = letterHO[irm_fi - 2][ifi_ch][1];
1169  }
1170 
1171  //special treatment for new ring-0 SiPMs fpga
1172  int mytype = -1; //variable that allows grouping of channels
1173  if (ieta <= 4 && mapIOV_ >= 5) {
1174  if (ipixel==3 || ipixel==7 || ipixel==12 || ipixel==14 || ipixel==17 || ipixel==18) {
1175  mytype = 1;
1176  if (phmod6==1 || phmod6==3)
1177  fpga = "top";
1178  else
1179  fpga = "bot";
1180  }
1181  else if (ipixel==1 || ipixel==4 || ipixel==8 || ipixel==15 || ipixel==16 || ipixel==19) {
1182  mytype = 2;
1183  if (phmod6==0 || phmod6==2)
1184  fpga = "top";
1185  else
1186  fpga = "bot";
1187  }
1188  else if (ipixel==2 || ipixel==5 || ipixel==6 || ipixel==9 || ipixel==11 || ipixel==13) {
1189  mytype = 3;
1190  fpga = "top";
1191  }
1192  }
1193 
1194  if (fpga == "bot") itb = 1;//convention different than for the
1195  else itb = 0;//electronics id, modified in the
1196  //MapEntry code
1197 
1198  //Determine which of HTR in the set belongs here. It depends only on eta and side.
1199  // the new stuff for HX
1200  if (ieta <= 3 || (ieta >= 14 && iside == 1)) ih = 0;
1201  else if (ieta <= 13 && ieta >= 6 && iside == 1) ih = 1;
1202  else if (ieta <= 13 && ieta >= 6 && iside == -1) ih = 3;
1203  else ih = 2;
1204 
1206  // the htrs are grouped in chunks of ((ph+2) mod 18)/6
1207  //71,72,1,2,3,4
1208  // and indexed by the mytype variable previously defined
1209  int php2mod18 = (iph+2)%18;
1210  int php2mod18ov6 = php2mod18/6;
1211 
1212  //Each value of "is" covers 30 degrees (that is, 6 values of phi). To calculate which ones,
1213  //I use phi % 18. Crates start at phi = 71, 17, 35, 53
1214 
1215  if (iphi % 18 == 17 || iphi % 18 <= 4) is = 0;
1216  else if (iphi % 18 >= 5 && iphi % 18 <= 10) is = 1;
1217  else is = 2;
1218 
1219  if ( ieta == 16 && iside > 0 ) ihtr=21;
1220  else if (ieta > 4)
1221  ihtr=ihslotho[is][ih];
1222  else {
1223  //special treatment only for ring-0
1224  if (mapIOV_ < 5)
1225  ihtr=ihslotho[is][ih];
1226  else {
1227  if (mytype == 1 || mytype == 2)
1228  ih = 0;
1229  else
1230  ih = 2;
1231  ihtr=ihslotho[php2mod18ov6][ih];
1232  }
1233  }
1234 
1235  if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6)) ispigot = 12;
1236  else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13)) ispigot = 13;
1237  else ispigot=ihtr<9?(ihtr-2)*2+itb:(ihtr-13)*2+itb;
1238  idcc=ihtr<9?1:2;
1239  idcc_sl = idcc == 1 ?10:20;
1240 
1241  ifed=fedhonum[ic][idcc-1];
1242 
1243  //RBX and sector
1244 
1245  if (iside == -1) sidesign = 'M';
1246  else sidesign = 'P';
1247 
1248  if (ieta <= 4) ring = 0;
1249  else if (ieta >= 5 && ieta <= 10) ring = 1;
1250  else ring = 2;
1251 
1252  //Sector ranges from 1 to 12 depending on phi. Sector 1 goes 71,72,1,2,3,4 so I start at -2
1253  sector = 0;
1254  for (i = -2; i < iphi; i+=6){
1255  sector++;
1256  }
1257  if (sector > 12) sector = 1; //It rolls over for phi = 71,72
1258 
1259  isector = sector;
1260 
1261  //For rings 1 and 2, we only want even sectors for the rbx
1262  if (ring != 0 && sector % 2 != 0) sector++;
1263 
1264  if (ring == 0) snprintf (tempbuff, sizeof tempbuff, "%s%i%2.2d", det.c_str(), ring, sector);
1265  else snprintf (tempbuff, sizeof tempbuff, "%s%i%c%2.2d", det.c_str(), ring, sidesign, sector);
1266  mystream<<tempbuff;
1267  rbx = mystream.str();
1268  mystream.str("");
1269  if (ieta == 16) {
1270  det = "HOX";
1271  letter = "X";}
1272  else det = "HO";
1273 
1274  // the new htr_fi stuff for HX
1275  if (ieta==16 && isid<0) ihtr_fi = HO_htr_fi_450eta16M[irm - 1];
1276  else if (ieta==16 && isid>0) ihtr_fi = HO_htr_fi_450eta16P[irm - 1][sector/2-1];
1277 
1278  if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 7)) {
1279  icrate = 6;
1280  ifed = 729;
1281  }
1282  else if ((ieta > 15 && iside > 0) && (icrate == 6 || icrate == 13)) {
1283  icrate = 7;
1284  ifed = 727;
1285  }
1286 
1287  if ( ieta == 16 ) ieta = 15;
1288  // fixing the switched RM's
1289  if ( iside == 1 && ring == 2 ) {
1290  if ( iphi == 5 ) {
1291  ieta = rmspecialeta[0][iet - 10];
1292  letter = rmspeciallet_code[0][iet - 10];
1293  det = rmspecialdet[0][iet - 10];
1294  }
1295  else if ( iphi == 67 ) {
1296  ieta = rmspecialeta[1][iet - 10];
1297  letter = rmspeciallet_code[1][iet - 10];
1298  det = rmspecialdet[1][iet - 10];
1299  }
1300  }
1301  else if ( iside == -1) {
1302  if ( ring == 1 ) {
1303  if ( iphi == 57 ) {
1304  ieta = rmspecialeta[2][iet - 4];
1305  letter = rmspeciallet_code[2][iet - 4];
1306  det = rmspecialdet[2][iet - 4];
1307  }
1308  else if ( iphi == 65 ) {
1309  ieta = rmspecialeta[3][iet - 4];
1310  letter = rmspeciallet_code[3][iet - 4];
1311  det = rmspecialdet[3][iet - 4];
1312  }
1313  }
1314  else if ( ring == 2 ) {
1315  if ( iphi == 16 ) {
1316  ieta = rmspecialeta[4][iet - 10];
1317  letter = rmspeciallet_code[4][iet - 10];
1318  det = rmspecialdet[4][iet - 10];
1319  }
1320  else if ( iphi == 31 ) {
1321  ieta = rmspecialeta[5][iet - 10];
1322  letter = rmspeciallet_code[5][iet - 10];
1323  det = rmspecialdet[5][iet - 10];
1324  }
1325  }
1326  }
1327 
1328  HOHXLogicalMapEntry hoxlmapentry(
1329  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
1330  det, iside, ieta, iphi, idepth,
1331  idphi, isector, irm, irm_fi, ipixel, iqie, iadc,
1332  rbx, letter
1333  );
1334  HOHXEntries.push_back(hoxlmapentry);
1335  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,1,HOHXEntries.size()-1);
1336 
1337  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
1338  unsigned int denseId;
1339  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenOuter) {
1340  denseId=topo->detId2denseIdHO(hgdi);
1341  HoHash2Entry.at(denseId)=HOHXEntries.size();
1342  } else if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenCalibration) {
1343  denseId=topo->detId2denseIdCALIB(hgdi);
1344  HxCalibHash2Entry.at(denseId)=HOHXEntries.size();
1345  }
1346 
1347  if (ring==0){
1348  if (ipixel==1){
1349  ipixel = 2;
1350  iadc = 4;
1351  if (mapIOV_ < 5)
1352  ifi_ch = 0;
1353  else {
1354  irm_fi = 4;
1355  ifi_ch = 2;
1356  if (irm_fi % 2 == 0) iadc = ifi_ch;
1357  else iadc = NFCH + (ifi_ch + 1) % 3;
1358  iqie = (irm_fi - 2) / 2 + 1;
1359  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm-1)/2][sidear];
1360  itb = 0;
1361  fpga = "top";
1362  mytype = 3;
1363  ih = 2;
1364  ihtr=ihslotho[php2mod18ov6][ih];
1365  ispigot = ihtr<9?(ihtr-2)*2+itb:(ihtr-13)*2+itb;
1366  idcc=ihtr<9?1:2;
1367  idcc_sl = idcc == 1 ?10:20;
1368  ifed=fedhonum[ic][idcc-1];
1369  }
1370  letter = "X";
1371  det = "HOX";
1372  HOHXLogicalMapEntry hoxlmapentry(
1373  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
1374  det, iside, ieta, iphi, idepth,
1375  idphi, isector, irm, irm_fi, ipixel, iqie, iadc,
1376  rbx, letter
1377  );
1378  HOHXEntries.push_back(hoxlmapentry);
1379  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,1,HOHXEntries.size()-1);
1380 
1381  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
1382  unsigned int denseId;
1383  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenOuter) {
1384  denseId=topo->detId2denseIdHO(hgdi);
1385  HoHash2Entry.at(denseId)=HOHXEntries.size();
1386  } else if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenCalibration) {
1387  denseId=topo->detId2denseIdCALIB(hgdi);
1388  HxCalibHash2Entry.at(denseId)=HOHXEntries.size();
1389  }
1390  }
1391  else if (ipixel==17){
1392  ipixel = 18;
1393  iadc = 1;
1394  if (mapIOV_ < 5)
1395  ifi_ch = 1;
1396  else {
1397  irm_fi = 6;
1398  ifi_ch = 1;
1399  if (irm_fi % 2 == 0) iadc = ifi_ch;
1400  else iadc = NFCH + (ifi_ch + 1) % 3;
1401  iqie = (irm_fi - 2) / 2 + 1;
1402  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm-1)/2][sidear];
1403  if (phmod6==1 || phmod6==3) {
1404  itb = 0;
1405  fpga = "top";
1406  }
1407  else {
1408  itb = 1;
1409  fpga = "bot";
1410  }
1411  ispigot = ihtr<9?(ihtr-2)*2+itb:(ihtr-13)*2+itb;
1412  idcc=ihtr<9?1:2;
1413  idcc_sl = idcc == 1 ?10:20;
1414  ifed=fedhonum[ic][idcc-1];
1415  }
1416  letter = "X";
1417  det = "HOX";
1418  HOHXLogicalMapEntry hoxlmapentry(
1419  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
1420  det, iside, ieta, iphi, idepth,
1421  idphi, isector, irm, irm_fi, ipixel, iqie, iadc,
1422  rbx, letter
1423  );
1424  HOHXEntries.push_back(hoxlmapentry);
1425  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,1,HOHXEntries.size()-1);
1426 
1427  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
1428  unsigned int denseId;
1429  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenOuter) {
1430  denseId=topo->detId2denseIdHO(hgdi);
1431  HoHash2Entry.at(denseId)=HOHXEntries.size();
1432  } else if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenCalibration) {
1433  denseId=topo->detId2denseIdCALIB(hgdi);
1434  HxCalibHash2Entry.at(denseId)=HOHXEntries.size();
1435  }
1436  }
1437  }
1438  }
1439  }
1440  }
1441 }
1442 
1444  std::vector <CALIBLogicalMapEntry>& CALIBEntries,
1445  std::vector <uint32_t>& LinearIndex2Entry,
1446  std::vector <uint32_t>& HxCalibHash2Entry) {
1447 
1448  /******************************/
1449  /* CALIB crate numbering in order of FEDID*/
1450  int calibcrate_loc[NCALIBCR]={4,0,1,5,11,15,17,14,10,9,7,6,13};//HBHE,HF,HO
1451  memcpy( calibcrate, calibcrate_loc, sizeof(int)*NCALIBCR );
1452  /* CALIB FED numbering of DCCs */
1453  int fedcalibnum_loc[NCALIBCR][2]={{700,701},{702,703},{704,705},{706,707},{708,709},{710,711},{712,713},{714,715},{716,717},/*calib_hbhe 4,0,1,5,11,15,17,14,10*/
1454  {720,721},/*calib_hf 9*/
1455  {726,727},{728,729},{730,731}};//calib_ho 7,6,13
1456  memcpy( fedcalibnum, fedcalibnum_loc, sizeof(int)*NCALIBCR*2 );
1457  /* iphi (lower) starting index for each CALIB crate */
1458  int icalibphis_loc[NCALIBCR]={3,11,19,27,35,43,51,59,67,27,17,35,53};
1459  memcpy( icalibphis, icalibphis_loc, sizeof(int)*NCALIBCR );
1460  /* icalibsector_min minimum sector on each crate {0,1,4,5,10,11,14,15,17,9,7,6,13}*/
1461  int icalibsector_min_loc[NCALIBCR]={2,4,6,8,10,12,14,16,18,1,4,7,10};
1462  memcpy( icalibsector_min, icalibsector_min_loc, sizeof(int)*NCALIBCR );
1463  /* icalibsector_max maximum sector on each crate */
1464  int icalibsector_max_loc[NCALIBCR]={3,5,7,9,11,13,15,17,1,4,6,9,12};
1465  memcpy( icalibsector_max, icalibsector_max_loc, sizeof(int)*NCALIBCR );
1466  //detectors represented on each crate (0 for top, 1 for bot)
1467  std::string detIDCALIB_loc[NCALIBCR][NTOPBOT] = {{"HB","HE"},/*crate 4*/
1468  {"HB","HE"},/*crate 0*/
1469  {"HB","HE"},/*crate 1*/
1470  {"HB","HE"},/*crate 5*/
1471  {"HB","HE"},/*crate 11*/
1472  {"HB","HE"},/*crate 15*/
1473  {"HB","HE"},/*crate 17*/
1474  {"HB","HE"},/*crate 14*/
1475  {"HB","HE"},/*crate 10*/
1476  {"HF","HF"},/*crate 9*/
1477  {"HO","HO"},/*crate 7*/
1478  {"HO","HO"},/*crate 6*/
1479  {"HO","HO"}};/*crate 13*/
1480  for (int jj = 0; jj < NCALIBCR; jj++) {
1481  for (int kk = 0; kk < NTOPBOT; kk++) {
1482  detIDCALIB[jj][kk] = detIDCALIB_loc[jj][kk];
1483  }
1484  }
1485 
1486  int nfbr_max_loc[NCALIBCR][NTOPBOT] = {{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}};
1487  memcpy( nfbr_max, nfbr_max_loc, sizeof(int)*NCALIBCR*NTOPBOT );
1488  //HB only utilizes 4 htr_fibers HE all 8
1489  int calibHOinfo_loc[NHOCR][NTOPBOT][NFBR][2]={/*sector and ring of HO for the calib channel*/
1490  {{{4,0},{5,0},{6,0},{},{6,-2},{6,-1},{6,1},{6,2}},
1491  {{4,-2},{4,-1},{4,1},{4,2},{},{},{},{}}},/*crate 7*/
1492 
1493  {{{7,0},{8,0},{9,0},{},{8,-2},{8,-1},{8,1},{8,2}},
1494  {{1,0},{2,0},{3,0},{},{2,-2},{2,-1},{2,1},{2,2}}},/*crate 6*/
1495 
1496  {{{10,0},{11,0},{12,0},{},{10,-2},{10,-1},{10,1},{10,2}},
1497  {{12,-2},{12,-1},{12,1},{12,2},{},{},{},{}}}/*crate 13*/
1498  };
1499  memcpy( calibHOinfo, calibHOinfo_loc, sizeof(int)*NHOCR*NTOPBOT*NFBR*2 );
1500 
1501  /*********************************/
1502 
1503  char tempbuff[30]{0};
1504 
1505  //Stream variable
1506 
1507  stringstream mystream;
1508 
1509  ihtr=8; //calibration units are housed on htr slot 8
1510  idcc=1;
1511  idcc_sl=10;
1512  irm_fi = 1;// everything other than HE is on A
1513  det = "";
1514 
1515  /*****************************************************/
1516  /*HBHE calibration channels*/
1517  for(ic=0; ic<NHBHECR; ic++){
1518  icrate=calibcrate[ic];
1519  ifed=fedcalibnum[ic][idcc-1];
1520  /* top and bottom */
1521  for(itb=0; itb<NTOPBOT; itb++){
1522  /* 4 or 8 fibers used per HTR FPGA */
1523  for(ifb=0; ifb<nfbr_max[ic][itb]; ifb++){
1524  det = detIDCALIB[ic][itb];
1525  ihtr_fi=ifb+1;
1526  irm_fi = 1;// everything other than he is on A
1527  idphi=4;
1528  if (itb==1) if(ihtr_fi%2==0) irm_fi = 2; //all of the even fibers in HE are on B rather than A
1529  if (det=="HE"){
1530  ispigot=13;
1531  fpga="bot";
1532  if (ihtr_fi==1||ihtr_fi==2||ihtr_fi==5||ihtr_fi==6) {
1533  iwedge = icalibsector_min[ic];
1534  }
1535  else if (ihtr_fi==3||ihtr_fi==4||ihtr_fi==7||ihtr_fi==8) {
1536  iwedge = icalibsector_max[ic];
1537  }
1538  if (ihtr_fi<5) {
1539  sidesign = 'M';
1540  S_side = '1';
1541  ieta = -1;
1542  iside=-1;
1543  }
1544  else {
1545  sidesign = 'P';
1546  S_side = '1';
1547  ieta = 1;
1548  iside=1;
1549  }
1550  }
1551  else if (det=="HB"){
1552  ispigot=12;
1553  fpga="top";
1554  (ihtr_fi%2==1) ? iwedge = icalibsector_min[ic] : iwedge = icalibsector_max[ic];
1555  if (ihtr_fi<3) {
1556  sidesign = 'M';
1557  S_side = '1';
1558  ieta = -1;
1559  iside=-1;
1560  }
1561  else {
1562  sidesign = 'P';
1563  S_side = '1';
1564  ieta = 1;
1565  iside=1;
1566  }
1567  }
1568  iphi = ((iwedge*idphi) + 71 - idphi)%72;
1569  subdet = "CALIB_"+det;
1570  snprintf (tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
1571  mystream<<tempbuff;
1572  rbx = mystream.str();
1573  mystream.str("");
1574  /* three channels per fiber */
1575  for(ifc=0; ifc<NFCH; ifc++){
1576  ifi_ch=ifc;
1577  if (irm_fi==1){
1578  if (ifc==0) ich_type=0;
1579  else if (ifc==1) ich_type=1;
1580  else if (ifc==2) {
1581  if (det=="HB") ich_type=2;
1582  else if(det=="HE") ich_type=3;
1583  }
1584  }
1585  else if (irm_fi==2){
1586  if (ifc==0) ich_type=4;
1587  else if (ifc==1) ich_type=5;
1588  else if (ifc==2) ich_type=6;
1589  }
1590  CALIBLogicalMapEntry caliblmapentry(
1591  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
1592  det, ieta, iphi, ich_type,
1593  iside, idphi, rbx, iwedge, irm_fi,
1594  subdet
1595  );
1596  CALIBEntries.push_back(caliblmapentry);
1597  LinearIndex2Entry.at(caliblmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,2,CALIBEntries.size()-1);
1598 
1599  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
1600  const unsigned int hashedId=topo->detId2denseIdCALIB(hgdi);
1601  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenCalibration) HxCalibHash2Entry.at(hashedId)=CALIBEntries.size();
1602  }
1603  }
1604  }
1605  }
1606 
1607  /* only one CALIB HF crate */
1608  /* top and bottom */
1609  for(itb=0; itb<NTOPBOT; itb++){
1610  /* four CALIB HF fibers per HTR FPGA */
1611  for(ifb=0; ifb<4; ifb++){
1612  /* three channels per fiber */
1613  for(ifc=0; ifc<NFCH; ifc++){
1614  icrate=calibcrate[ic];
1615  det = "HF";
1616  ihtr_fi=ifb+1;
1617  ifi_ch=ifc;
1618  (ihtr_fi==1)?iphi=1:((ihtr_fi==2)?iphi=19:((ihtr_fi==3)?iphi=37:iphi=55));
1619  idphi=18;
1620  ifed=fedcalibnum[ic][idcc-1];
1621  (ifc==0)?ich_type=8:(ifc==1?ich_type=0:ich_type=1);
1622  //changed ch_type of fibre channel 0 from 2 to 8, as per HcalCalibDetId specification
1623  irm_fi = 1;
1624  //Wedge has steps of 3, HF(P/M)2,5,8,11
1625  //iwedge=ihtr_fi;
1626  iwedge=2+(ifb*3);
1627  if (itb==0){
1628  ispigot=12;
1629  fpga="top";
1630  sidesign='P';
1631  iside=1;
1632  ieta=1;
1633  }
1634  else {
1635  ispigot=13;
1636  fpga="bot";
1637  sidesign='M';
1638  iside=-1;
1639  ieta=-1;
1640  }
1641  subdet = "CALIB_"+det;
1642  snprintf (tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
1643  mystream<<tempbuff;
1644  rbx = mystream.str();
1645  mystream.str("");
1646  CALIBLogicalMapEntry caliblmapentry(
1647  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
1648  det, ieta, iphi, ich_type,
1649  iside, idphi, rbx, iwedge, irm_fi,
1650  subdet
1651  );
1652  CALIBEntries.push_back(caliblmapentry);
1653  LinearIndex2Entry.at(caliblmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,2,CALIBEntries.size()-1);
1654 
1655  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
1656  const unsigned int hashedId=topo->detId2denseIdCALIB(hgdi);
1657  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenCalibration) HxCalibHash2Entry.at(hashedId)=CALIBEntries.size();
1658 
1659  }
1660  }
1661  }
1662 
1663  /*HO calibration channels*/
1664  for(ic=ic+1 ; ic<NCALIBCR; ic++){
1665  icrate=calibcrate[ic];
1666  irm_fi = 1;// everything other than he is on A
1667  ifed=fedcalibnum[ic][idcc-1];
1668  /* top and bottom */
1669  for(itb=0; itb<NTOPBOT; itb++){
1670  det=detIDCALIB[ic][itb];
1671  /* 4 or 8 fibers used per HTR FPGA */
1672  for(ifb=0; ifb<nfbr_max[ic][itb]; ifb++){
1673  if (itb==1) {
1674  ispigot = 13;
1675  fpga = "bot";
1676  }
1677  else{
1678  ispigot = 12;
1679  fpga = "top";
1680  }
1681  ihtr_fi=ifb+1;
1682  iwedge=calibHOinfo[ic-10][itb][ifb][0];
1683  ieta=calibHOinfo[ic-10][itb][ifb][1];
1684  if (ieta<0) {
1685  iside=-1;
1686  sidesign='M';
1687  }
1688  else if (ieta>0){
1689  iside=1;
1690  sidesign='P';
1691  }
1692  else {
1693  iside=0;
1694  sidesign='0';
1695  }
1696  if (ieta==-2) S_side='2';
1697  else if (ieta==-1) S_side='1';
1698  else if (ieta==1) S_side='1';
1699  else if (ieta==2) S_side='2';
1700 
1701  subdet ="CALIB_"+det;
1702  if (ieta==0) snprintf (tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
1703  else snprintf (tempbuff, sizeof tempbuff, "%s%c%c%2.2i", det.c_str(), S_side, sidesign, iwedge);
1704  mystream<<tempbuff;
1705  rbx = mystream.str();
1706  mystream.str("");
1707  /* only two channels used in HO per fiber */
1708  //now new information suggests that the third channel is used for x-talk
1709  //but only in some of the rm's, seems to be dependent on whether nfbr_max
1710  //sector 10 on YB+2,1,0,-1, sector 12 on YB-2
1711  int NFCH_HO;
1712  //( nfbr_max[ic][itb] == 4 ) ? NFCH_HO = 2 : NFCH_HO = 3;
1713  ( ieta == -2 ) ? ( iwedge == 12 ? NFCH_HO = 3 : NFCH_HO = 2 ) : ( iwedge == 10) ? NFCH_HO = 3 : NFCH_HO = 2;
1714  for(ifc=0; ifc<NFCH_HO; ifc++){
1715  ifi_ch=ifc;
1716  (ifi_ch == 2) ? ich_type = 7 : ich_type = ifi_ch;
1717  (ieta==0) ? idphi = 6 : idphi = 12;
1718 
1719  (ieta==0) ? iphi=((iwedge*idphi)+71-idphi)%72 : iphi=(((iwedge/2)*idphi)+71-idphi)%72;
1720  //nothing on htr_fi=4 for the top
1721  //do {
1722  if (iside==0&&ifb==3) continue; // adjust logic since no longer inside loop
1723  CALIBLogicalMapEntry caliblmapentry(
1724  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
1725  det, ieta, iphi, ich_type,
1726  iside, idphi, rbx, iwedge, irm_fi,
1727  subdet
1728  );
1729  CALIBEntries.push_back(caliblmapentry);
1730  LinearIndex2Entry.at(caliblmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,2,CALIBEntries.size()-1);
1731 
1732  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
1733  const unsigned int hashedId=topo->detId2denseIdCALIB(hgdi);
1734  if (hgdi.genericSubdet()==HcalGenericDetId::HcalGenCalibration) HxCalibHash2Entry.at(hashedId)=CALIBEntries.size();
1735  //} while (ifb!=ifb);
1736  }
1737  }
1738  }
1739  }
1740 }
1741 
1742 void HcalLogicalMapGenerator::buildZDCMap(const HcalTopology* topo, std::vector <ZDCLogicalMapEntry>& ZDCEntries,
1743  std::vector <uint32_t>& LinearIndex2Entry,
1744  std::vector <uint32_t>& ZdcHash2Entry) {
1745  /******************************/
1746  /*ZDC channels*/
1747  //Stream variable
1748  stringstream mystream;
1749 
1750  ifed=722;
1751  iy=1;
1752  ihtr=8;
1753  icrate=12;
1754  idcc=1;
1755  idcc_sl=10;
1756  ispigot=12;
1757  /* side plus and minus */
1758  for(itb=0; itb<NTOPBOT; itb++){
1759  if (itb==0) {
1760  iside = 1;
1761  irm = 1;
1762  fpga = "top";
1763  }
1764  else {
1765  iside = -1;
1766  irm = 2;
1767  if (mapIOV_<4) {
1768  fpga = "top";
1769  ispigot = 12;}
1770  else {
1771  fpga = "bot";
1772  ispigot = 13;}
1773  }
1774  /*loop over ZDC cables*/
1775  for(icab=1; icab<NZDCCAB+1; icab++){
1776  if (icab < 4) {
1777  irm_fi = 1;
1778  iadc = icab - 1;
1779  ifi_ch = iadc;
1780  }
1781  else if (icab < 7) {
1782  irm_fi = 2;
1783  iadc = icab - 1;
1784  ifi_ch = iadc - 3;
1785  }
1786  else {
1787  irm_fi = 3;
1788  iadc = icab - 7;
1789  ifi_ch = iadc;
1790  }
1791  if (itb==0) {
1792  ihtr_fi = irm_fi;
1793  }
1794  else {
1795  if (mapIOV_<4) ihtr_fi = irm_fi + 3;
1796  else ihtr_fi = irm_fi;
1797  }
1798  if (icab < 6) {
1799  ix = icab;
1800  idepth = 1;
1801  idx = 1;
1802  det = "ZDC_EM";
1803  idet_ch = ix;
1804  iqie = 1;
1805  }
1806  else {
1807  ix = 1;
1808  idepth = icab - 4;
1809  idx = 5;
1810  det = "ZDC_HAD";
1811  idet_ch = icab - 5;
1812  if (icab==6) iqie = 1;
1813  else iqie = 2;
1814  }
1815  ZDCLogicalMapEntry zdclmapentry(
1816  ifi_ch, ihtr_fi, ispigot, ifed, icrate, ihtr, fpga,
1817  det, iside, idepth,
1818  ix, iy, idx, idet_ch, icab, irm, iqie,
1819  iadc, irm_fi
1820  );
1821  ZDCEntries.push_back(zdclmapentry);
1822  LinearIndex2Entry.at(zdclmapentry.getLinearIndex())=HcalLogicalMap::makeEntryNumber(true,3,ZDCEntries.size()-1);
1823  }
1824  }
1825 }
1826 
1827 
1828 /********************************************************/
1830  std::vector <HTLogicalMapEntry>& HTEntries,
1831  int iside, int ieta, int iphi, int idphi, int idepth, std::string det, int iwedge, int irm,
1832  int ipixel, int iqie, int iadc, int irm_fi, int ifi_ch, int icrate, int ihtr, std::string fpga,
1833  int ihtr_fi, int ispigot, int islb, std::string slbin, std::string slbin2,
1834  std::string slnam, int irctcra, int irctcar, int irctcon, std::string rctnam, int ifed
1835  )
1836 {
1837 
1838  string t_chDet,t_fpga;
1839  string t_slnam,t_rctnam,t_slbin,t_slbin2;
1840 
1841  int t_nDat=-1;
1842  int t_side,t_iEta,t_iPhi,t_jPhi,t_iDep,t_topbot;
1843  int t_wedge,t_crate,t_htr;
1844  // int t_rm,t_pixel,t_qie,t_adc,t_rm_fi,t_fi_ch,t_htr_fi;
1845  int t_spigo,t_slb,t_rctcra,t_rctcar,t_rctcon,t_fedid;
1846 
1847  //making global variables local for modification
1848  (fpga=="bot") ? t_topbot = 1 : t_topbot = 0;
1849  t_side = iside;
1850  t_iEta = ieta;
1851  t_iPhi = iphi;
1852  t_jPhi = idphi;
1853  t_iDep = idepth;
1854  t_chDet = det;
1855  t_wedge = iwedge;
1856  // t_rm = irm;
1857  // t_pixel = ipixel;
1858  // t_qie = iqie;
1859  // t_adc = iadc;
1860  // t_rm_fi = irm_fi;
1861  // t_fi_ch = ifi_ch;
1862  t_crate = icrate;
1863  t_htr = ihtr;
1864  t_fpga = fpga;
1865  // t_htr_fi = ihtr_fi;
1866  t_spigo = ispigot;
1867  t_slb = islb;
1868  t_slbin = slbin;
1869  t_slbin2 = slbin2;
1870  t_slnam = slnam;
1871  t_rctcra = irctcra;
1872  t_rctcar = irctcar;
1873  t_rctcon = irctcon;
1874  t_rctnam = rctnam;
1875  t_fedid = ifed;
1876 
1877  do {
1878  if(t_iDep!=1) break;
1879  if(t_chDet=="HE"&&t_iEta==29) break;
1880 
1881  if(t_chDet=="HF") {
1882  t_jPhi=4;//20 degree slices in HF
1883  if(t_iEta==30||t_iEta==31||t_iEta==33||
1884  t_iEta==34||t_iEta==36||t_iEta==37||
1885  t_iEta==39||t_iEta==40||t_iEta==41) break;
1886 
1887  else if(t_iEta==32)t_iEta=30;
1888  else if(t_iEta==35)t_iEta=31;
1889  else if(t_iEta==38)t_iEta=32;
1890 
1891  if(t_iPhi==3||t_iPhi==7||t_iPhi==11||t_iPhi==15||t_iPhi==19||
1892  t_iPhi==23||t_iPhi==27||t_iPhi==31||t_iPhi==35||t_iPhi==39||
1893  t_iPhi==43||t_iPhi==47||t_iPhi==51||t_iPhi==55||t_iPhi==59||
1894  t_iPhi==63||t_iPhi==67||t_iPhi==71) break;
1895  }
1896 
1897  if(t_side<0) t_iEta=-t_iEta;
1898  t_chDet="HT";
1899 
1900  if(t_slbin!="NA") {
1901  if(t_slbin2!="NA") t_jPhi=1;
1902  if(t_slbin=="A0"||t_slbin=="B0") t_nDat=0;
1903  else if(t_slbin=="A1"||t_slbin=="B1") t_nDat=1;
1904  else if(t_slbin=="C0"||t_slbin=="D0") t_nDat=2;
1905  else if(t_slbin=="C1"||t_slbin=="D1") t_nDat=3;
1906 
1907  HTLogicalMapEntry htlmapentry(
1908  t_iEta, t_iPhi,
1909  t_side, t_jPhi, t_iDep, t_chDet, t_wedge, t_crate, t_htr, t_topbot,
1910  t_spigo, t_slb, t_slbin, t_slbin2, t_nDat,
1911  t_slnam, t_rctcra, t_rctcar, t_rctcon, t_rctnam, t_fedid
1912  );
1913  HTEntries.push_back(htlmapentry);
1914  }
1915  if(t_slbin2!="NA") {
1916  if(t_slbin2=="A0"||t_slbin2=="B0") t_nDat=0;
1917  else if(t_slbin2=="A1"||t_slbin2=="B1") t_nDat=1;
1918  else if(t_slbin2=="C0"||t_slbin2=="D0") t_nDat=2;
1919  else if(t_slbin2=="C1"||t_slbin2=="D1") t_nDat=3;
1920  t_jPhi=1;//after splitting up these towers, each half should have dphi of 1
1921  t_iPhi+=1;
1922 
1923  HTLogicalMapEntry htlmapentry(
1924  t_iEta, t_iPhi,//changed from t_iPhi + 1 here to the spot above
1925  t_side, t_jPhi, t_iDep, t_chDet, t_wedge, t_crate, t_htr, t_topbot,
1926  t_spigo, t_slb, t_slbin, t_slbin2, t_nDat,
1927  t_slnam, t_rctcra, t_rctcar, t_rctcon, t_rctnam, t_fedid
1928  );
1929  HTEntries.push_back(htlmapentry);
1930  }
1931  } while(1!=1);
1932 }
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