CMS 3D CMS Logo

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