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