Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:07

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0003 #include "DataFormats/HcalDetId/interface/HcalOtherDetId.h"
0004 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0005 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0006 #include "CalibCalorimetry/HcalAlgos/interface/HcalLogicalMapGenerator.h"
0007 
0008 #include <string>
0009 #include <sstream>
0010 #include <cstdio>
0011 #include <iostream>
0012 #include <cstring>
0013 
0014 using namespace std;
0015 
0016 /***************************************/
0017 
0018 HcalLogicalMapGenerator::HcalLogicalMapGenerator() {
0019   //adc and qie table; qie is entry 0, adc is entry 1. Constant across HB, HE, HO
0020   //  int iadcquiHBHE[NRMFIBR][NFCH][2];
0021 
0022   for (i = 0; i < NRMFIBR; i++) {
0023     for (j = 0; j < NFCH; j++) {
0024       //Intentionally relying on integer truncation here
0025       iadcquiHBHE[i][j][0] = i / 2 + 1;
0026 
0027       if (i % 2 == 0)
0028         iadcquiHBHE[i][j][1] = j;
0029       else
0030         iadcquiHBHE[i][j][1] = NFCH + (j + 1) % 3;
0031     }
0032   }
0033 }
0034 
0035 HcalLogicalMapGenerator::~HcalLogicalMapGenerator() {}
0036 
0037 HcalLogicalMap HcalLogicalMapGenerator::createMap(const HcalTopology* topo, unsigned int mapIOV) {
0038   mapIOV_ = mapIOV;
0039 
0040   std::vector<HBHEHFLogicalMapEntry> HBHEHFEntries;
0041   std::vector<HOHXLogicalMapEntry> HOHXEntries;
0042   std::vector<CALIBLogicalMapEntry> CALIBEntries;
0043   std::vector<ZDCLogicalMapEntry> ZDCEntries;
0044   std::vector<HTLogicalMapEntry> HTEntries;
0045   std::vector<uint32_t> LinearIndex2Entry;
0046   std::vector<uint32_t> HbHash2Entry;
0047   std::vector<uint32_t> HeHash2Entry;
0048   std::vector<uint32_t> HfHash2Entry;
0049   std::vector<uint32_t> HtHash2Entry;
0050   std::vector<uint32_t> HoHash2Entry;
0051   std::vector<uint32_t> HxCalibHash2Entry;
0052   //std::vector <uint32_t> CalibHash2Entry;
0053   std::vector<uint32_t> ZdcHash2Entry;
0054 
0055   int HbHalf = 1296;
0056   int HeHalf = 1296;
0057   //if (h2mode_) HeHalf = 4032;
0058   int HoHalf = 1080;
0059   int HfHalf = 864;
0060   int HtHalf = 2088;
0061   int ZdcHalf = 11;
0062   int CalibFull = 216 + 425 + 8;
0063 
0064   uint32_t illegal_value = 0;
0065   for (int i = 0; i <= HcalElectronicsId::maxLinearIndex; i++)
0066     LinearIndex2Entry.push_back(illegal_value);
0067   HbHash2Entry.reserve(2 * HbHalf);
0068   for (int iHb = 0; iHb < 2 * HbHalf; iHb++)
0069     HbHash2Entry.push_back(illegal_value);
0070   HeHash2Entry.reserve(2 * HeHalf);
0071   for (int iHe = 0; iHe < 2 * HeHalf; iHe++)
0072     HeHash2Entry.push_back(illegal_value);
0073   HfHash2Entry.reserve(2 * HfHalf);
0074   for (int iHf = 0; iHf < 2 * HfHalf; iHf++)
0075     HfHash2Entry.push_back(illegal_value);
0076   HtHash2Entry.reserve(2 * HtHalf);
0077   for (int iHt = 0; iHt < 2 * HtHalf; iHt++)
0078     HtHash2Entry.push_back(illegal_value);
0079   HoHash2Entry.reserve(2 * HoHalf);
0080   for (int iHo = 0; iHo < 2 * HoHalf; iHo++)
0081     HoHash2Entry.push_back(illegal_value);
0082   HxCalibHash2Entry.reserve(CalibFull);
0083   for (int iHcalib = 0; iHcalib < CalibFull; iHcalib++)
0084     HxCalibHash2Entry.push_back(illegal_value);
0085   ZdcHash2Entry.reserve(2 * ZdcHalf);
0086   for (int iZdc = 0; iZdc < 2 * ZdcHalf; iZdc++)
0087     ZdcHash2Entry.push_back(illegal_value);
0088 
0089   buildHBEFTMap(
0090       topo, HBHEHFEntries, HTEntries, LinearIndex2Entry, HbHash2Entry, HeHash2Entry, HfHash2Entry, HtHash2Entry);
0091   buildHOXMap(topo, HOHXEntries, LinearIndex2Entry, HoHash2Entry, HxCalibHash2Entry);
0092   buildCALIBMap(topo, CALIBEntries, LinearIndex2Entry, HxCalibHash2Entry);
0093   buildZDCMap(topo, ZDCEntries, LinearIndex2Entry, ZdcHash2Entry);
0094 
0095   return HcalLogicalMap(topo,
0096                         HBHEHFEntries,
0097                         HOHXEntries,
0098                         CALIBEntries,
0099                         ZDCEntries,
0100                         HTEntries,
0101                         LinearIndex2Entry,
0102                         HbHash2Entry,
0103                         HeHash2Entry,
0104                         HfHash2Entry,
0105                         HtHash2Entry,
0106                         HoHash2Entry,
0107                         HxCalibHash2Entry,
0108                         /*CalibHash2Entry,*/ ZdcHash2Entry);
0109 }
0110 
0111 void HcalLogicalMapGenerator::buildHBEFTMap(const HcalTopology* topo,
0112                                             std::vector<HBHEHFLogicalMapEntry>& HBHEHFEntries,
0113                                             std::vector<HTLogicalMapEntry>& HTEntries,
0114                                             std::vector<uint32_t>& LinearIndex2Entry,
0115                                             std::vector<uint32_t>& HbHash2Entry,
0116                                             std::vector<uint32_t>& HeHash2Entry,
0117                                             std::vector<uint32_t>& HfHash2Entry,
0118                                             std::vector<uint32_t>& HtHash2Entry) {
0119   /******************************/
0120   /* HBHE crate numbering */
0121   int hbhecrate_loc[NHBHECR] = {0, 1, 4, 5, 10, 11, 14, 15, 17};
0122   memcpy(hbhecrate, hbhecrate_loc, sizeof(int) * NHBHECR);
0123   /* HBHE FED numbering of DCCs */
0124   int fedhbhenum_loc[NHBHECR][2] = {
0125       {702, 703}, {704, 705}, {700, 701}, {706, 707}, {716, 717}, {708, 709}, {714, 715}, {710, 711}, {712, 713}};
0126   memcpy(fedhbhenum, fedhbhenum_loc, sizeof(int) * NHBHECR * 2);
0127   /* HBHE/HF htr slot offsets for set of three htrs */
0128   int ihslot_loc[NHSETS] = {2, 5, 13, 16};
0129   memcpy(ihslot, ihslot_loc, sizeof(int) * NHSETS);
0130   /* iphi (lower) starting index for each HBHE crate */
0131   int ihbhephis_loc[NHBHECR] = {11, 19, 3, 27, 67, 35, 59, 43, 51};
0132   memcpy(ihbhephis, ihbhephis_loc, sizeof(int) * NHBHECR);
0133   /* ihbheetadepth - unique HBHE {eta,depth} assignments per fiber and fiber channel */
0134   int ihbheetadepth_loc[NHTRS][NTOPBOT][NFBR][NFCH][2] = {{{{{11, 1}, {7, 1}, {3, 1}}, /* htr 0 (HB) -bot(+top) */
0135                                                             {{5, 1}, {1, 1}, {9, 1}},
0136                                                             {{11, 1}, {7, 1}, {3, 1}},
0137                                                             {{5, 1}, {1, 1}, {9, 1}},
0138                                                             {{10, 1}, {6, 1}, {2, 1}},
0139                                                             {{8, 1}, {4, 1}, {12, 1}},
0140                                                             {{10, 1}, {6, 1}, {2, 1}},
0141                                                             {{8, 1}, {4, 1}, {12, 1}}},
0142                                                            {{{11, 1}, {7, 1}, {3, 1}}, /* htr 0 (HB) +bot(-top) */
0143                                                             {{5, 1}, {1, 1}, {9, 1}},
0144                                                             {{11, 1}, {7, 1}, {3, 1}},
0145                                                             {{5, 1}, {1, 1}, {9, 1}},
0146                                                             {{10, 1}, {6, 1}, {2, 1}},
0147                                                             {{8, 1}, {4, 1}, {12, 1}},
0148                                                             {{10, 1}, {6, 1}, {2, 1}},
0149                                                             {{8, 1}, {4, 1}, {12, 1}}}},
0150                                                           {{{{16, 2}, {15, 2}, {14, 1}}, /* htr 1 (HBHE) -bot(+top) */
0151                                                             {{15, 1}, {13, 1}, {16, 1}},
0152                                                             {{16, 2}, {15, 2}, {14, 1}},
0153                                                             {{15, 1}, {13, 1}, {16, 1}},
0154                                                             {{17, 1}, {16, 3}, {26, 1}},
0155                                                             {{18, 1}, {18, 2}, {26, 2}},
0156                                                             {{17, 1}, {16, 3}, {25, 1}},
0157                                                             {{18, 1}, {18, 2}, {25, 2}}},
0158                                                            {{{16, 2}, {15, 2}, {14, 1}}, /* htr 1 (HBHE) +bot(-top) */
0159                                                             {{15, 1}, {13, 1}, {16, 1}},
0160                                                             {{16, 2}, {15, 2}, {14, 1}},
0161                                                             {{15, 1}, {13, 1}, {16, 1}},
0162                                                             {{17, 1}, {16, 3}, {25, 1}},
0163                                                             {{18, 1}, {18, 2}, {25, 2}},
0164                                                             {{17, 1}, {16, 3}, {26, 1}},
0165                                                             {{18, 1}, {18, 2}, {26, 2}}}},
0166                                                           {{{{28, 1}, {28, 2}, {29, 1}}, /* htr 2 (HE) -bot(+top) */
0167                                                             {{28, 3}, {24, 2}, {24, 1}},
0168                                                             {{27, 1}, {27, 2}, {29, 2}},
0169                                                             {{27, 3}, {23, 2}, {23, 1}},
0170                                                             {{19, 2}, {20, 1}, {22, 2}},
0171                                                             {{19, 1}, {20, 2}, {22, 1}},
0172                                                             {{19, 2}, {20, 1}, {21, 2}},
0173                                                             {{19, 1}, {20, 2}, {21, 1}}},
0174                                                            {{{27, 1}, {27, 2}, {29, 2}}, /* htr 2 (HE) +bot(-top) */
0175                                                             {{27, 3}, {23, 2}, {23, 1}},
0176                                                             {{28, 1}, {28, 2}, {29, 1}},
0177                                                             {{28, 3}, {24, 2}, {24, 1}},
0178                                                             {{19, 2}, {20, 1}, {21, 2}},
0179                                                             {{19, 1}, {20, 2}, {21, 1}},
0180                                                             {{19, 2}, {20, 1}, {22, 2}},
0181                                                             {{19, 1}, {20, 2}, {22, 1}}}}};
0182   memcpy(ihbheetadepth, ihbheetadepth_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * NFCH * 2);
0183 
0184   //Aram's insert: I shall now define an array which contains the RM and the RM fiber for HB HE
0185   //and variables associated with this table
0186   int irm_rmfiHBHE_loc[NHTRS][NTOPBOT][NFBR][2] = {
0187       {{{6, 1}, {7, 1}, {6, 2}, {7, 2}, {4, 1}, {5, 1}, {4, 2}, {5, 2}},   // HTR 0 top
0188        {{6, 3}, {7, 3}, {6, 4}, {7, 4}, {4, 3}, {5, 3}, {4, 4}, {5, 4}}},  // HTR 0 bot
0189       {{{2, 1}, {3, 1}, {2, 2}, {3, 2}, {2, 1}, {3, 1}, {2, 2}, {3, 2}},   // HTR 1 top
0190        {{2, 3}, {3, 3}, {2, 4}, {3, 4}, {2, 3}, {3, 3}, {2, 4}, {3, 4}}},  // HTR 1 bot
0191       {{{4, 1}, {5, 1}, {4, 2}, {5, 2}, {6, 1}, {7, 1}, {6, 2}, {7, 2}},   // HTR 2 top
0192        {{4, 3}, {5, 3}, {4, 4}, {5, 4}, {6, 3}, {7, 3}, {6, 4}, {7, 4}}}   // HTR 2 bot
0193   };
0194   memcpy(irm_rmfiHBHE, irm_rmfiHBHE_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * 2);
0195   //Pixel tables as a function of rm, rm fiber and fiber channel
0196 
0197   int ipixelHB_loc[NRMFIBR][NFCH][NRMSLOT] = {
0198       //  fch = 0           fch = 1           fch = 2
0199       {{18, 17, 3, 2}, {13, 3, 17, 7}, {14, 1, 19, 6}},  //rmfiber = 2
0200       {{19, 2, 18, 1}, {15, 7, 13, 5}, {17, 19, 1, 3}},  //rmfiber = 3
0201       {{9, 4, 16, 11}, {5, 8, 12, 15}, {2, 13, 7, 18}},  //rmfiber = 4
0202       {{12, 11, 9, 8}, {7, 15, 5, 13}, {16, 6, 14, 4}},  //rmfiber = 5
0203       {{8, 5, 15, 12}, {4, 9, 11, 16}, {1, 14, 6, 19}},  //rmfiber = 6
0204       {{6, 16, 4, 14}, {3, 18, 2, 17}, {11, 12, 8, 9}}   //rmfiber = 7
0205   };
0206   memcpy(ipixelHB, ipixelHB_loc, sizeof(int) * NRMFIBR * NFCH * NRMSLOT);
0207 
0208   int ipixelHE_loc[NRMFIBR][NFCH][NRMSLOT] = {
0209       //  fch = 0           fch = 1           fch = 2
0210       {{12, 12, 12, 12}, {16, 7, 16, 7}, {7, 16, 7, 16}},  //rmfiber = 2
0211       {{11, 11, 11, 11}, {19, 3, 19, 3}, {3, 19, 3, 19}},  //rmfiber = 3
0212       {{15, 15, 6, 6}, {2, 18, 2, 18}, {6, 6, 15, 15}},    //rmfiber = 4
0213       {{5, 14, 5, 14}, {14, 5, 14, 5}, {18, 2, 18, 2}},    //rmfiber = 5
0214       {{17, 1, 17, 1}, {9, 9, 9, 9}, {1, 17, 1, 17}},      //rmfiber = 6
0215       {{13, 4, 13, 4}, {8, 8, 8, 8}, {4, 13, 4, 13}}       //rmfiber = 7
0216   };
0217   memcpy(ipixelHE, ipixelHE_loc, sizeof(int) * NRMFIBR * NFCH * NRMSLOT);
0218 
0219   //slb and rct tables
0220 
0221   //HB and HE
0222 
0223   const char* S_slbin_odd_loc[] = {"A1", "B0", "B1", "A0", "A1", "B0", "B1", "A0"};
0224   for (int gg = 0; gg < 8; gg++) {
0225     S_slbin_odd[gg] = S_slbin_odd_loc[gg];
0226   }
0227   const char* S_slbin_even_loc[] = {"C1", "D0", "D1", "C0", "C1", "D0", "D1", "C0"};
0228   for (int gg = 0; gg < 8; gg++) {
0229     S_slbin_even[gg] = S_slbin_even_loc[gg];
0230   }
0231   const char* rct_rackHBHE_loc[] = {"S2E01-RH",
0232                                     "S2E03-RH",
0233                                     "S2E05-RH",
0234                                     "S2E07-RH",
0235                                     "S2E09-RH",
0236                                     "S2E08-RL",
0237                                     "S2E06-RL",
0238                                     "S2E04-RL",
0239                                     "S2E02-RL",
0240                                     "S2E02-RH",
0241                                     "S2E04-RH",
0242                                     "S2E06-RH",
0243                                     "S2E08-RH",
0244                                     "S2E09-RL",
0245                                     "S2E07-RL",
0246                                     "S2E05-RL",
0247                                     "S2E03-RL",
0248                                     "S2E01-RL"};
0249   for (int gg = 0; gg < 18; gg++) {
0250     rct_rackHBHE[gg] = rct_rackHBHE_loc[gg];
0251   }
0252 
0253   int slb_table_loc[29] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,  // 1<=eta<=12
0254                            1, 1, 2, 2, 3, 3, 1, 1,              // 13<=eta<=20
0255                            2, 2, 3, 3, 4, 4, 4, 4, 4};          // 21<=eta<=29
0256   memcpy(slb_table, slb_table_loc, sizeof(int) * 29);
0257   /********************/
0258 
0259   char tempbuff[30]{0};
0260 
0261   //Stream variable
0262   stringstream mystream;
0263 
0264   /* all HBHE crates */
0265   for (ic = 0; ic < NHBHECR; ic++) {
0266     /* four sets of three htrs per crate */
0267     for (is = 0; is < NHSETS; is++) {
0268       /* three htrs per set */
0269       for (ih = 0; ih < NHTRS; ih++) {
0270         /* top and bottom */
0271         for (itb = 0; itb < NTOPBOT; itb++) {
0272           /* eight fibers per HTR FPGA */
0273           for (ifb = 0; ifb < NFBR; ifb++) {
0274             /* three channels per fiber */
0275             for (ifc = 0; ifc < NFCH; ifc++) {
0276               icrate = hbhecrate[ic];
0277               iside = is < NHSETS / 2 ? -1 : 1;
0278               ifwtb = (is / 2 + itb + 1) % 2;
0279               ieta = ihbheetadepth[ih][ifwtb][ifb][ifc][0];
0280               idepth = ihbheetadepth[ih][ifwtb][ifb][ifc][1];
0281               ihtr = ihslot[is] + ih;
0282               (ieta > 16 || idepth > 2) ? det = "HE" : det = "HB";
0283               (itb % 2) == 1 ? fpga = "bot" : fpga = "top";
0284               ihtr_fi = ifb + 1;
0285               ifi_ch = ifc;
0286               iphi = (ieta > 20) ? (ihbhephis[ic] + (is % 2) * 4 + itb * 2 - 1) % 72 + 1
0287                                  : (ihbhephis[ic] + (is % 2) * 4 + itb * 2 + (ifb / 2 + is / 2 + 1) % 2 - 1) % 72 + 1;
0288               ispigot = (is % 2) * 6 + ih * 2 + itb;
0289               idcc = is < NHSETS / 2 ? 1 : 2;
0290               idcc_sl = idcc == 1 ? 10 : 20;
0291               ifed = fedhbhenum[ic][idcc - 1];
0292               //Aram's insert: rm variables, rbx, wedge
0293               //Careful here: per Pawel's map, the rm fiber is the first entry an the rm itself is the second.
0294 
0295               //If iside == -1, switch top and bottom. Why?
0296               if (iside == -1) {
0297                 S_side = '-';
0298                 sidesign = 'M';
0299                 irm = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][1];
0300                 irm_fi = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][0];
0301 
0302                 //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
0303                 if (ieta >= 21 && (irm == 1 || irm == 3))
0304                   iwedge = (iphi + 1 + irm + 1) / 4;
0305                 else
0306                   iwedge = (iphi + irm + 1) / 4;
0307 
0308                 //Roll over the wedge
0309                 if (iwedge > 18)
0310                   iwedge -= 18;
0311               } else {
0312                 S_side = '+';
0313                 sidesign = 'P';
0314                 irm = irm_rmfiHBHE[ih][itb][ifb][1];
0315                 irm_fi = irm_rmfiHBHE[ih][itb][ifb][0];
0316 
0317                 //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
0318                 if (ieta >= 21 && (irm == 4 || irm == 2))
0319                   iwedge = (iphi + 1 - irm + 6) / 4;
0320                 else
0321                   iwedge = (iphi - irm + 6) / 4;
0322 
0323                 //Roll over the wedge
0324                 if (iwedge > 18)
0325                   iwedge -= 18;
0326               }
0327 
0328               snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
0329               mystream << tempbuff;
0330               rbx = mystream.str();
0331               mystream.str("");
0332 
0333               //Note that irm_fi ranges from 2 to 7 whereas arrays start at 0 so
0334               //I use irm_fi - 2. Likewise, irm goes from 1 to 4 so use irm - 1
0335 
0336               //Pixel is split by HB and HE
0337               if (ieta > 16 || idepth > 2)
0338                 ipixel = ipixelHE[irm_fi - 2][ifc][irm - 1];  //HE
0339               else
0340                 ipixel = ipixelHB[irm_fi - 2][ifc][irm - 1];  //HB
0341 
0342               iqie = iadcquiHBHE[irm_fi - 2][ifc][0];
0343               iadc = iadcquiHBHE[irm_fi - 2][ifc][1];
0344 
0345               phideg = iphi - 3;
0346               if (phideg < 0)
0347                 phideg = phideg + 72;
0348               phideg = (phideg / 4) * 20 + 10;
0349               irctcra = ((89 - phideg + 720) % 360) / 20;
0350               oddcard = irctcra % 2;
0351               irctcra /= 2;
0352               if (iside > 0)
0353                 irctcra = irctcra + 9;
0354 
0355               etaslb = ((ieta - 1) / 2) * 2 + 1;
0356               if (etaslb > 27)
0357                 etaslb = 27;
0358 
0359               snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
0360               mystream << tempbuff;
0361               slnam = mystream.str();
0362               mystream.str("");
0363 
0364               islb = slb_table[ieta - 1];
0365 
0366               // calculate RCT destination (that is, rctcon, rctcar and rctnam
0367               if (ieta <= 24) {  // these are the normal cards 0-5
0368                 irctcar = 2 * ((ieta - 1) / 8) + oddcard;
0369                 irctcon = 2 * (((ieta - 1) / 2) % 4);
0370               } else {  // these are on the special card 6 which folds back eta on the odd card half
0371                 irctcar = 6;
0372                 eta2 = ieta;
0373                 if (eta2 > 28)
0374                   eta2 = 28;
0375                 if (oddcard == 0)
0376                   eta3 = eta2;
0377                 else
0378                   eta3 = 57 - eta2;
0379                 irctcon = 2 * (((eta3 - 1) / 2) % 4);
0380               }
0381               irctcon = 11 * irctcon + 1;
0382 
0383               snprintf(tempbuff, sizeof tempbuff, "%s-%1d-HD%2.2d", rct_rackHBHE[irctcra], irctcar, irctcon);
0384               mystream << tempbuff;
0385               rctnam = mystream.str();
0386               mystream.str("");
0387 
0388               //Finally, the slbin
0389 
0390               phimod8 = iphi % 8;
0391 
0392               for (i = 0; i < 18; i++) {
0393                 if (iphi < i * 4 + 3) {
0394                   crazy = i % 2;
0395                   break;
0396                 }
0397               }
0398 
0399               int ietamod;  // determine if eta is "odd" or "even".
0400               if (ieta == 29)
0401                 ietamod = 0;
0402               else
0403                 ietamod = ieta % 2;
0404               if (ieta < 25) {  // use the regular table
0405                 if (ietamod == 1)
0406                   mystream << S_slbin_odd[phimod8];
0407                 else
0408                   mystream << S_slbin_even[phimod8];
0409               } else if (crazy == 0) {  // use the regular table
0410                 if (ietamod == 1)
0411                   mystream << S_slbin_odd[phimod8];
0412                 else
0413                   mystream << S_slbin_even[phimod8];
0414               } else {  // swap odd/even!!!
0415                 if (ietamod == 1)
0416                   mystream << S_slbin_even[phimod8];
0417                 else
0418                   mystream << S_slbin_odd[phimod8];
0419               }
0420 
0421               slbin = mystream.str();
0422               mystream.str("");
0423 
0424               if (ieta > 20) {
0425                 idphi = 2;
0426                 slbin2 = slbin;
0427                 slbin2[1] = '1';
0428               } else {
0429                 idphi = 1;
0430                 slbin2 = "NA";
0431               }
0432 
0433               HBHEHFLogicalMapEntry hbeflmapentry(ifi_ch,
0434                                                   ihtr_fi,
0435                                                   ispigot,
0436                                                   ifed,
0437                                                   icrate,
0438                                                   ihtr,
0439                                                   fpga,
0440                                                   det,
0441                                                   iside,
0442                                                   ieta,
0443                                                   iphi,
0444                                                   idepth,
0445                                                   idphi,
0446                                                   iwedge,
0447                                                   irm,
0448                                                   irm_fi,
0449                                                   ipixel,
0450                                                   iqie,
0451                                                   iadc,
0452                                                   islb,
0453                                                   irctcra,
0454                                                   irctcar,
0455                                                   irctcon,
0456                                                   rbx,
0457                                                   slbin,
0458                                                   slbin2,
0459                                                   slnam,
0460                                                   rctnam);
0461               HBHEHFEntries.push_back(hbeflmapentry);
0462               LinearIndex2Entry.at(hbeflmapentry.getLinearIndex()) =
0463                   HcalLogicalMap::makeEntryNumber(true, 0, HBHEHFEntries.size() - 1);
0464 
0465               const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
0466               unsigned int denseId;
0467               if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenBarrel) {
0468                 denseId = topo->detId2denseIdHB(hgdi);
0469                 HbHash2Entry.at(denseId) = HBHEHFEntries.size();
0470               }
0471               if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
0472                 denseId = topo->detId2denseIdHE(hgdi);
0473                 HeHash2Entry.at(denseId) = HBHEHFEntries.size();
0474               }
0475               if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenForward) {
0476                 denseId = topo->detId2denseIdHF(hgdi);
0477                 HfHash2Entry.at(denseId) = HBHEHFEntries.size();
0478               }
0479 
0480               ConstructTriggerTower(topo,
0481                                     HTEntries,
0482                                     iside,
0483                                     ieta,
0484                                     iphi,
0485                                     idphi,
0486                                     idepth,
0487                                     det,
0488                                     iwedge,
0489                                     irm,
0490                                     ipixel,
0491                                     iqie,
0492                                     iadc,
0493                                     irm_fi,
0494                                     ifi_ch,
0495                                     icrate,
0496                                     ihtr,
0497                                     fpga,
0498                                     ihtr_fi,
0499                                     ispigot,
0500                                     islb,
0501                                     slbin,
0502                                     slbin2,
0503                                     slnam,
0504                                     irctcra,
0505                                     irctcar,
0506                                     irctcon,
0507                                     rctnam,
0508                                     ifed);
0509             }
0510           }
0511         }
0512       }
0513     }
0514   }
0515 
0516   /********************/
0517   /* HF crate numbering */
0518   int hfcrate_loc[NHFCR] = {2, 9, 12};
0519   memcpy(hfcrate, hfcrate_loc, sizeof(int) * NHFCR);
0520   /* HF FED numbering of DCCs */
0521   int fedhfnum_loc[NHFCR][2] = {{718, 719}, {720, 721}, {722, 723}};
0522   memcpy(fedhfnum, fedhfnum_loc, sizeof(int) * NHFCR * 2);
0523   /* iphi (lower) starting index for each HF crate */
0524   int ihfphis_loc[NHFCR] = {3, 27, 51};
0525   memcpy(ihfphis, ihfphis_loc, sizeof(int) * NHFCR);
0526   /* ihfetadepth - unique HF {eta,depth} assignments per fiber and fiber channel */
0527   int ihfetadepth_loc[NTOPBOT][NFBR][NFCH][2] = {{{{33, 1}, {31, 1}, {29, 1}}, /* top */
0528                                                   {{32, 1}, {30, 1}, {34, 1}},
0529                                                   {{33, 2}, {31, 2}, {29, 2}},
0530                                                   {{32, 2}, {30, 2}, {34, 2}},
0531                                                   {{34, 2}, {32, 2}, {30, 2}},
0532                                                   {{31, 2}, {29, 2}, {33, 2}},
0533                                                   {{34, 1}, {32, 1}, {30, 1}},
0534                                                   {{31, 1}, {29, 1}, {33, 1}}},
0535                                                  {{{41, 1}, {37, 1}, {35, 1}}, /* bot */
0536                                                   {{38, 1}, {36, 1}, {39, 1}},
0537                                                   {{41, 2}, {37, 2}, {35, 2}},
0538                                                   {{38, 2}, {36, 2}, {39, 2}},
0539                                                   {{40, 2}, {38, 2}, {36, 2}},
0540                                                   {{37, 2}, {35, 2}, {39, 2}},
0541                                                   {{40, 1}, {38, 1}, {36, 1}},
0542                                                   {{37, 1}, {35, 1}, {39, 1}}}};
0543   memcpy(ihfetadepth, ihfetadepth_loc, sizeof(int) * NTOPBOT * NFBR * NFCH * 2);
0544 
0545   int irm_rmfiHF_loc[NHTRS][NTOPBOT][NFBR][2] = {
0546       {{{1, 2}, {2, 2}, {3, 2}, {4, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}},   // HTR 0 top
0547        {{5, 2}, {6, 2}, {7, 2}, {8, 2}, {5, 3}, {6, 3}, {7, 3}, {8, 3}}},  // HTR 0 bot
0548       {{{1, 1}, {2, 1}, {3, 1}, {4, 1}, {1, 2}, {2, 2}, {3, 2}, {4, 2}},   // HTR 1 top
0549        {{5, 1}, {6, 1}, {7, 1}, {8, 1}, {5, 2}, {6, 2}, {7, 2}, {8, 2}}},  // HTR 1 bot
0550       {{{1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 1}, {2, 1}, {3, 1}, {4, 1}},   // HTR 2 top
0551        {{5, 3}, {6, 3}, {7, 3}, {8, 3}, {5, 1}, {6, 1}, {7, 1}, {8, 1}}}   // HTR 2 bot
0552   };
0553   memcpy(irm_rmfiHF, irm_rmfiHF_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * 2);
0554 
0555   //HF
0556   const char* S_slbin_7_loc[] = {"A0", "A1", "B0", "B1"};
0557   for (int gg = 0; gg < 4; gg++) {
0558     S_slbin_7[gg] = S_slbin_7_loc[gg];
0559   }
0560   const char* S_slbin_3_loc[] = {"C0", "C1", "D0", "D1"};
0561   for (int gg = 0; gg < 4; gg++) {
0562     S_slbin_3[gg] = S_slbin_3_loc[gg];
0563   }
0564   const char* rct_rackHF_loc[] = {"S2E01-FH",
0565                                   "S2E03-FH",
0566                                   "S2E05-FH",
0567                                   "S2E07-FH",
0568                                   "S2E09-FH",
0569                                   "S2E08-FL",
0570                                   "S2E06-FL",
0571                                   "S2E04-FL",
0572                                   "S2E02-FL",
0573                                   "S2E02-FH",
0574                                   "S2E04-FH",
0575                                   "S2E06-FH",
0576                                   "S2E08-FH",
0577                                   "S2E09-FL",
0578                                   "S2E07-FL",
0579                                   "S2E05-FL",
0580                                   "S2E03-FL",
0581                                   "S2E01-FL"};
0582   for (int gg = 0; gg < 18; gg++) {
0583     rct_rackHF[gg] = rct_rackHF_loc[gg];
0584   }
0585 
0586   /***************/
0587 
0588   /* all HF crates */
0589   for (ic = 0; ic < NHFCR; ic++) {
0590     /* four sets of three htrs per crate */
0591     for (is = 0; is < NHSETS; is++) {
0592       /* three htrs per set */
0593       for (ih = 0; ih < NHTRS; ih++) {
0594         /* top and bottom */
0595         for (itb = 0; itb < NTOPBOT; itb++) {
0596           /* eight fibers per HTR FPGA */
0597           for (ifb = 0; ifb < NFBR; ifb++) {
0598             /* three channels per fiber */
0599             for (ifc = 0; ifc < NFCH; ifc++) {
0600               icrate = hfcrate[ic];
0601               iside = is < NHSETS / 2 ? -1 : 1;
0602               ieta = ihfetadepth[itb][ifb][ifc][0];
0603               idepth = ihfetadepth[itb][ifb][ifc][1];
0604               ihtr = ihslot[is] + ih;
0605               det = "HF";
0606               (itb % 2) == 1 ? fpga = "bot" : fpga = "top";
0607               ihtr_fi = ifb + 1;
0608               ifi_ch = ifc;
0609               iphi = (ieta > 39) ? (ihfphis[ic] + (is % 2) * 12 + ih * 4 - 1) % 72 + 1
0610                                  : (ihfphis[ic] + (is % 2) * 12 + ih * 4 + (ifb / 4) * 2 - 1) % 72 + 1;
0611               ispigot = (is % 2) * 6 + ih * 2 + itb;
0612               idcc = is < NHSETS / 2 ? 1 : 2;
0613               idcc_sl = idcc == 1 ? 10 : 20;
0614               ifed = fedhfnum[ic][idcc - 1];
0615 
0616               irm_fi = irm_rmfiHF[ih][itb][ifb][0];
0617 
0618               //Don't switch in the HF. Why?
0619               if (iside == -1) {
0620                 S_side = '-';
0621                 sidesign = 'M';
0622 
0623                 if (ieta < 40) {
0624                   if (iphi == 1)
0625                     iphi = 71;
0626                   else if (iphi == 71)
0627                     iphi = 1;
0628                   else if (iphi % 4 == 1)
0629                     iphi -= 2;
0630                   else if (iphi % 4 == 3)
0631                     iphi += 2;
0632                   else
0633                     edm::LogInfo("HcalLogicalMapGenerator") << "Even iphi in HFM" << endl;
0634                 }
0635               } else {
0636                 S_side = '+';
0637                 sidesign = 'P';
0638               }
0639 
0640               //RM and RBX number
0641               if ((iside == 1 && ieta == 40) || (iside == -1 && ieta == 41)) {
0642                 irm = ((iphi + 1) / 2) % 36 + 1;
0643                 hfphi = ((iphi + 1) / 6) % 12 + 1;
0644               } else {
0645                 irm = (iphi + 1) / 2;
0646                 hfphi = (iphi - 1) / 6 + 1;
0647               }
0648               irm = (irm - 1) % 3 + 1;
0649 
0650               //Wedge
0651               if (iphi >= 71)
0652                 iwedge = 1;
0653               else
0654                 iwedge = (iphi + 1) / 4 + 1;
0655 
0656               //RBX
0657               snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, hfphi);
0658               mystream << tempbuff;
0659               rbx = mystream.str();
0660               mystream.str("");
0661 
0662               //No pixel in HF, follow Fedor's convention
0663               ipixel = 0;
0664 
0665               //Integer truncation again consistent with Fedor's map.
0666               iqie = (irm_fi - 1) / 2 + 1;
0667 
0668               if (irm_fi % 2 != 0)
0669                 iadc = ifi_ch;
0670               else
0671                 iadc = NFCH + (ifi_ch + 1) % 3;
0672 
0673               //slb and rct variables
0674               //rctcrate
0675               phideg = iphi - 3;
0676               if (phideg < 0)
0677                 phideg = phideg + 72;
0678               phideg = (phideg / 4) * 20 + 10;
0679               irctcra = ((89 - phideg + 720) % 360) / 40;
0680               if (iside > 0)
0681                 irctcra = irctcra + 9;
0682 
0683               //rct card and rct connector appear to be dummy here -- again, I follow Fedor's convention
0684               irctcar = 99;
0685               irctcon = 0;
0686 
0687               etaslb = 29;
0688 
0689               snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
0690               mystream << tempbuff;
0691               slnam = mystream.str();
0692               mystream.str("");
0693 
0694               snprintf(tempbuff, sizeof tempbuff, "%s-JSC-HF_IN", rct_rackHF[irctcra]);
0695               mystream << tempbuff;
0696               rctnam = mystream.str();
0697               mystream.str("");
0698 
0699               islb = 6;
0700 
0701               int phibin = (iphi + 1) % 8;
0702               int etabin = (ieta - 29) / 3;
0703               if (etabin < 0)
0704                 etabin = 0;
0705               if (etabin > 3)
0706                 etabin = 3;
0707               if (phibin < 4)
0708                 mystream << S_slbin_7[etabin];
0709               else
0710                 mystream << S_slbin_3[etabin];
0711 
0712               slbin = mystream.str();
0713               mystream.str("");
0714 
0715               slbin2 = "NA";
0716 
0717               if (ieta < 40)
0718                 idphi = 2;
0719               else
0720                 idphi = 4;
0721 
0722               HBHEHFLogicalMapEntry hbeflmapentry(ifi_ch,
0723                                                   ihtr_fi,
0724                                                   ispigot,
0725                                                   ifed,
0726                                                   icrate,
0727                                                   ihtr,
0728                                                   fpga,
0729                                                   det,
0730                                                   iside,
0731                                                   ieta,
0732                                                   iphi,
0733                                                   idepth,
0734                                                   idphi,
0735                                                   iwedge,
0736                                                   irm,
0737                                                   irm_fi,
0738                                                   ipixel,
0739                                                   iqie,
0740                                                   iadc,
0741                                                   islb,
0742                                                   irctcra,
0743                                                   irctcar,
0744                                                   irctcon,
0745                                                   rbx,
0746                                                   slbin,
0747                                                   slbin2,
0748                                                   slnam,
0749                                                   rctnam);
0750               HBHEHFEntries.push_back(hbeflmapentry);
0751               LinearIndex2Entry.at(hbeflmapentry.getLinearIndex()) =
0752                   HcalLogicalMap::makeEntryNumber(true, 0, HBHEHFEntries.size() - 1);
0753 
0754               const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
0755               unsigned int denseId;
0756               if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenBarrel) {
0757                 denseId = topo->detId2denseIdHB(hgdi);
0758                 HbHash2Entry.at(denseId) = HBHEHFEntries.size();
0759               }
0760               if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
0761                 denseId = topo->detId2denseIdHE(hgdi);
0762                 HeHash2Entry.at(denseId) = HBHEHFEntries.size();
0763               }
0764               if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenForward) {
0765                 denseId = topo->detId2denseIdHF(hgdi);
0766                 HfHash2Entry.at(denseId) = HBHEHFEntries.size();
0767               }
0768 
0769               ConstructTriggerTower(topo,
0770                                     HTEntries,
0771                                     iside,
0772                                     ieta,
0773                                     iphi,
0774                                     idphi,
0775                                     idepth,
0776                                     det,
0777                                     iwedge,
0778                                     irm,
0779                                     ipixel,
0780                                     iqie,
0781                                     iadc,
0782                                     irm_fi,
0783                                     ifi_ch,
0784                                     icrate,
0785                                     ihtr,
0786                                     fpga,
0787                                     ihtr_fi,
0788                                     ispigot,
0789                                     islb,
0790                                     slbin,
0791                                     slbin2,
0792                                     slnam,
0793                                     irctcra,
0794                                     irctcar,
0795                                     irctcon,
0796                                     rctnam,
0797                                     ifed);
0798             }
0799           }
0800         }
0801       }
0802     }
0803   }
0804 }
0805 
0806 void HcalLogicalMapGenerator::buildHOXMap(const HcalTopology* topo,
0807                                           std::vector<HOHXLogicalMapEntry>& HOHXEntries,
0808                                           std::vector<uint32_t>& LinearIndex2Entry,
0809                                           std::vector<uint32_t>& HoHash2Entry,
0810                                           std::vector<uint32_t>& HxCalibHash2Entry) {
0811   /******************************/
0812   /* HO crate numbering */
0813   int hocrate_loc[NHOCR] = {3, 7, 6, 13};
0814   memcpy(hocrate, hocrate_loc, sizeof(int) * NHOCR);
0815   /* HO FED numbering of DCCs */
0816   int fedhonum_loc[NHOCR][2] = {{724, 725}, {726, 727}, {728, 729}, {730, 731}};
0817   memcpy(fedhonum, fedhonum_loc, sizeof(int) * NHOCR * 2);
0818   /* HO htr slot offsets for three sets of four htrs */
0819   int ihslotho_loc[NHSETSHO][NHTRSHO] = {{2, 3, 4, 5}, {6, 7, 13, 14}, {15, 16, 17, 18}};
0820   memcpy(ihslotho, ihslotho_loc, sizeof(int) * NHSETSHO * NHTRSHO);
0821   /* iphi (lower) starting index for each HO crate */
0822   int ihophis_loc[NHOCR] = {71, 17, 35, 53};
0823   memcpy(ihophis, ihophis_loc, sizeof(int) * NHOCR);
0824 
0825   //RM for the HO as a function of eta, phi and side as implemented in complete_ho_map.txt
0826   //There are only 24 phi columns because after that it begins to repeat. The relevant variable is phi mod 24.
0827   //HX as the 16th eta entry
0828   int HO_RM_table_loc[24][16][2] = {{{2, 2},
0829                                      {2, 2},
0830                                      {2, 2},
0831                                      {2, 2},
0832                                      {2, 2},
0833                                      {2, 2},
0834                                      {2, 2},
0835                                      {2, 2},
0836                                      {2, 2},
0837                                      {2, 2},
0838                                      {4, 2},
0839                                      {4, 2},
0840                                      {4, 2},
0841                                      {4, 2},
0842                                      {4, 2},
0843                                      {4, 2}},
0844                                     {{2, 2},
0845                                      {2, 2},
0846                                      {2, 2},
0847                                      {2, 2},
0848                                      {4, 4},
0849                                      {4, 4},
0850                                      {4, 4},
0851                                      {4, 4},
0852                                      {4, 4},
0853                                      {4, 4},
0854                                      {2, 4},
0855                                      {2, 4},
0856                                      {2, 4},
0857                                      {2, 4},
0858                                      {2, 4},
0859                                      {2, 4}},
0860                                     {{3, 3},
0861                                      {3, 3},
0862                                      {3, 3},
0863                                      {3, 3},
0864                                      {4, 4},
0865                                      {4, 4},
0866                                      {4, 4},
0867                                      {4, 4},
0868                                      {4, 4},
0869                                      {4, 4},
0870                                      {2, 4},
0871                                      {2, 4},
0872                                      {2, 4},
0873                                      {2, 4},
0874                                      {2, 4},
0875                                      {2, 4}},
0876                                     {{3, 3},
0877                                      {3, 3},
0878                                      {3, 3},
0879                                      {3, 3},
0880                                      {4, 4},
0881                                      {4, 4},
0882                                      {4, 4},
0883                                      {4, 4},
0884                                      {4, 4},
0885                                      {4, 4},
0886                                      {2, 4},
0887                                      {2, 4},
0888                                      {2, 4},
0889                                      {2, 4},
0890                                      {2, 4},
0891                                      {2, 4}},
0892                                     {{4, 4},
0893                                      {4, 4},
0894                                      {4, 4},
0895                                      {4, 4},
0896                                      {3, 3},
0897                                      {3, 3},
0898                                      {3, 3},
0899                                      {3, 3},
0900                                      {3, 3},
0901                                      {3, 3},
0902                                      {1, 3},
0903                                      {1, 3},
0904                                      {1, 3},
0905                                      {1, 3},
0906                                      {1, 3},
0907                                      {1, 3}},
0908                                     {{4, 4},
0909                                      {4, 4},
0910                                      {4, 4},
0911                                      {4, 4},
0912                                      {3, 3},
0913                                      {3, 3},
0914                                      {3, 3},
0915                                      {3, 3},
0916                                      {3, 3},
0917                                      {3, 3},
0918                                      {1, 3},
0919                                      {1, 3},
0920                                      {1, 3},
0921                                      {1, 3},
0922                                      {1, 3},
0923                                      {1, 3}},
0924                                     {{3, 3},
0925                                      {3, 3},
0926                                      {3, 3},
0927                                      {3, 3},
0928                                      {3, 3},
0929                                      {3, 3},
0930                                      {3, 3},
0931                                      {3, 3},
0932                                      {3, 3},
0933                                      {3, 3},
0934                                      {1, 3},
0935                                      {1, 3},
0936                                      {1, 3},
0937                                      {1, 3},
0938                                      {1, 3},
0939                                      {1, 3}},
0940                                     {{3, 3},
0941                                      {3, 3},
0942                                      {3, 3},
0943                                      {3, 3},
0944                                      {1, 1},
0945                                      {1, 1},
0946                                      {1, 1},
0947                                      {1, 1},
0948                                      {1, 1},
0949                                      {1, 1},
0950                                      {3, 1},
0951                                      {3, 1},
0952                                      {3, 1},
0953                                      {3, 1},
0954                                      {3, 1},
0955                                      {3, 1}},
0956                                     {{2, 2},
0957                                      {2, 2},
0958                                      {2, 2},
0959                                      {2, 2},
0960                                      {1, 1},
0961                                      {1, 1},
0962                                      {1, 1},
0963                                      {1, 1},
0964                                      {1, 1},
0965                                      {1, 1},
0966                                      {3, 1},
0967                                      {3, 1},
0968                                      {3, 1},
0969                                      {3, 1},
0970                                      {3, 1},
0971                                      {3, 1}},
0972                                     {{2, 2},
0973                                      {2, 2},
0974                                      {2, 2},
0975                                      {2, 2},
0976                                      {1, 1},
0977                                      {1, 1},
0978                                      {1, 1},
0979                                      {1, 1},
0980                                      {1, 1},
0981                                      {1, 1},
0982                                      {3, 1},
0983                                      {3, 1},
0984                                      {3, 1},
0985                                      {3, 1},
0986                                      {3, 1},
0987                                      {3, 1}},
0988                                     {{4, 4},
0989                                      {4, 4},
0990                                      {4, 4},
0991                                      {4, 4},
0992                                      {2, 2},
0993                                      {2, 2},
0994                                      {2, 2},
0995                                      {2, 2},
0996                                      {2, 2},
0997                                      {2, 2},
0998                                      {4, 2},
0999                                      {4, 2},
1000                                      {4, 2},
1001                                      {4, 2},
1002                                      {4, 2},
1003                                      {4, 2}},
1004                                     {{4, 4},
1005                                      {4, 4},
1006                                      {4, 4},
1007                                      {4, 4},
1008                                      {2, 2},
1009                                      {2, 2},
1010                                      {2, 2},
1011                                      {2, 2},
1012                                      {2, 2},
1013                                      {2, 2},
1014                                      {4, 2},
1015                                      {4, 2},
1016                                      {4, 2},
1017                                      {4, 2},
1018                                      {4, 2},
1019                                      {4, 2}},
1020                                     {{3, 3},
1021                                      {3, 3},
1022                                      {3, 3},
1023                                      {3, 3},
1024                                      {2, 2},
1025                                      {2, 2},
1026                                      {2, 2},
1027                                      {2, 2},
1028                                      {2, 2},
1029                                      {2, 2},
1030                                      {4, 2},
1031                                      {4, 2},
1032                                      {4, 2},
1033                                      {4, 2},
1034                                      {4, 2},
1035                                      {4, 2}},
1036                                     {{3, 3},
1037                                      {3, 3},
1038                                      {3, 3},
1039                                      {3, 3},
1040                                      {4, 4},
1041                                      {4, 4},
1042                                      {4, 4},
1043                                      {4, 4},
1044                                      {4, 4},
1045                                      {4, 4},
1046                                      {2, 4},
1047                                      {2, 4},
1048                                      {2, 4},
1049                                      {2, 4},
1050                                      {2, 4},
1051                                      {2, 4}},
1052                                     {{2, 2},
1053                                      {2, 2},
1054                                      {2, 2},
1055                                      {2, 2},
1056                                      {4, 4},
1057                                      {4, 4},
1058                                      {4, 4},
1059                                      {4, 4},
1060                                      {4, 4},
1061                                      {4, 4},
1062                                      {2, 4},
1063                                      {2, 4},
1064                                      {2, 4},
1065                                      {2, 4},
1066                                      {2, 4},
1067                                      {2, 4}},
1068                                     {{2, 2},
1069                                      {2, 2},
1070                                      {2, 2},
1071                                      {2, 2},
1072                                      {4, 4},
1073                                      {4, 4},
1074                                      {4, 4},
1075                                      {4, 4},
1076                                      {4, 4},
1077                                      {4, 4},
1078                                      {2, 4},
1079                                      {2, 4},
1080                                      {2, 4},
1081                                      {2, 4},
1082                                      {2, 4},
1083                                      {2, 4}},
1084                                     {{1, 1},
1085                                      {1, 1},
1086                                      {1, 1},
1087                                      {1, 1},
1088                                      {3, 3},
1089                                      {3, 3},
1090                                      {3, 3},
1091                                      {3, 3},
1092                                      {3, 3},
1093                                      {3, 3},
1094                                      {1, 3},
1095                                      {1, 3},
1096                                      {1, 3},
1097                                      {1, 3},
1098                                      {1, 3},
1099                                      {1, 3}},
1100                                     {{1, 1},
1101                                      {1, 1},
1102                                      {1, 1},
1103                                      {1, 1},
1104                                      {3, 3},
1105                                      {3, 3},
1106                                      {3, 3},
1107                                      {3, 3},
1108                                      {3, 3},
1109                                      {3, 3},
1110                                      {1, 3},
1111                                      {1, 3},
1112                                      {1, 3},
1113                                      {1, 3},
1114                                      {1, 3},
1115                                      {1, 3}},
1116                                     {{2, 2},
1117                                      {2, 2},
1118                                      {2, 2},
1119                                      {2, 2},
1120                                      {3, 3},
1121                                      {3, 3},
1122                                      {3, 3},
1123                                      {3, 3},
1124                                      {3, 3},
1125                                      {3, 3},
1126                                      {1, 3},
1127                                      {1, 3},
1128                                      {1, 3},
1129                                      {1, 3},
1130                                      {1, 3},
1131                                      {1, 3}},
1132                                     {{2, 2},
1133                                      {2, 2},
1134                                      {2, 2},
1135                                      {2, 2},
1136                                      {1, 1},
1137                                      {1, 1},
1138                                      {1, 1},
1139                                      {1, 1},
1140                                      {1, 1},
1141                                      {1, 1},
1142                                      {3, 1},
1143                                      {3, 1},
1144                                      {3, 1},
1145                                      {3, 1},
1146                                      {3, 1},
1147                                      {3, 1}},
1148                                     {{3, 3},
1149                                      {3, 3},
1150                                      {3, 3},
1151                                      {3, 3},
1152                                      {1, 1},
1153                                      {1, 1},
1154                                      {1, 1},
1155                                      {1, 1},
1156                                      {1, 1},
1157                                      {1, 1},
1158                                      {3, 1},
1159                                      {3, 1},
1160                                      {3, 1},
1161                                      {3, 1},
1162                                      {3, 1},
1163                                      {3, 1}},
1164                                     {{3, 3},
1165                                      {3, 3},
1166                                      {3, 3},
1167                                      {3, 3},
1168                                      {1, 1},
1169                                      {1, 1},
1170                                      {1, 1},
1171                                      {1, 1},
1172                                      {1, 1},
1173                                      {1, 1},
1174                                      {3, 1},
1175                                      {3, 1},
1176                                      {3, 1},
1177                                      {3, 1},
1178                                      {3, 1},
1179                                      {3, 1}},
1180                                     {{1, 1},
1181                                      {1, 1},
1182                                      {1, 1},
1183                                      {1, 1},
1184                                      {2, 2},
1185                                      {2, 2},
1186                                      {2, 2},
1187                                      {2, 2},
1188                                      {2, 2},
1189                                      {2, 2},
1190                                      {4, 2},
1191                                      {4, 2},
1192                                      {4, 2},
1193                                      {4, 2},
1194                                      {4, 2},
1195                                      {4, 2}},
1196                                     {{1, 1},
1197                                      {1, 1},
1198                                      {1, 1},
1199                                      {1, 1},
1200                                      {2, 2},
1201                                      {2, 2},
1202                                      {2, 2},
1203                                      {2, 2},
1204                                      {2, 2},
1205                                      {2, 2},
1206                                      {4, 2},
1207                                      {4, 2},
1208                                      {4, 2},
1209                                      {4, 2},
1210                                      {4, 2},
1211                                      {4, 2}}};
1212   memcpy(HO_RM_table, HO_RM_table_loc, sizeof(int) * 24 * 16 * 2);
1213 
1214   //For |eta| 5 to 15, rm_fi is a function of |eta| only while htr_fi is a function of side and |eta|
1215   int HO_RM_fi_eta5to15_loc[11] = {3, 2, 5, 4, 7, 6, 3, 2, 5, 4, 7};
1216   memcpy(HO_RM_fi_eta5to15, HO_RM_fi_eta5to15_loc, sizeof(int) * 11);
1217   //For eta=16 it is 6, declared in the header
1218   HO_RM_fi_eta16 = 6;
1219   //For eta in the YB0 region, rm_fi is dependent on side, 4 for -1, and 5 for +1
1220   //but the values won't be any different than when the regular loop is executed
1221   //int HO_RM_fi_etaYB0[2] = {4, 5}
1222 
1223   //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,
1224   //eta 4 is separate and thus gets its own box
1225   //threefold symmetry in iphi, repeats every three groups of 8 i.e., 1to8 == 25to32 == 49to56,
1226   //similarly for the other iphi groups
1227   //[iphi][ieta 1-3/4][side m/p]
1228   //Actually has more modular structure which is not repetitive cyclicly
1229   // groups of 4 in iphi repeat 1to4 == 17to20 == 21to24
1230   // groups of 4 in iphi repeat 5to8 == 9to12 == 13to16
1231   int HO_RM_fi_eta1to4_loc[24][2][2] = {
1232       //side = -1            side = 1
1233       {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{2, 6}, {5, 4}},
1234       {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}},  //Phi 1  to 8, Phi 25 to 32, Phi 49 to 56
1235       {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}},
1236       {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}},  //Phi 9  to 16, Phi 33 to 40, Phi 57 to 64
1237       {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}},
1238       {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}  //Phi 17 to 24, Phi 41 to 48, Phi 65 to 72
1239   };
1240   memcpy(HO_RM_fi_eta1to4, HO_RM_fi_eta1to4_loc, sizeof(int) * 24 * 2 * 2);
1241 
1242   /* new mapping with SiPMs in HO ring-0 */
1243   //The mapping is different for HO ring-0 with HPDs (above) or SiPMs (here)
1244   // as the SiPM mapping is not cyclic in the same way as before
1245   //[iphi][ieta][side m/p]
1246   //threefold symmetry in iphi, repeats every three lines i.e., 1to8 == 25to32 == 49to56,
1247   //similarly for the other iphi groups
1248   //(iphi-1)mod(24)
1249   //ieta4,rm_fi5,fi_ch1 5 -> 3:{minus:evenphi,plus:oddphi}
1250   //ieta4,rm_fi5,fi_ch2 5 -> 2:{minus:oddphi,plus:evenphi}
1251   int HO_RM_fi_eta1to4_sipm_loc[24][4][2] = {
1252       //side = -1            side = 1
1253       {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1254       {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},  //Phi 1   to  4
1255       {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1256       {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},  //Phi 5   to  8
1257       {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1258       {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},  //Phi 9   to 12
1259       {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1260       {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},  //Phi 13  to 16
1261       {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1262       {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},  //Phi 17 to 20
1263       {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1264       {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},  //Phi 21 to 24
1265   };
1266   memcpy(HO_RM_fi_eta1to4_sipm, HO_RM_fi_eta1to4_sipm_loc, sizeof(int) * 24 * 4 * 2);
1267 
1268   // htr_fi
1269   int HO_htr_fi_450eta5to15_loc[2][11] = {{2, 2, 4, 6, 8, 2, 4, 6, 8, 4, 6},   //iside = -1
1270                                           {2, 8, 6, 4, 2, 8, 6, 4, 2, 4, 2}};  //iside = +1
1271   memcpy(HO_htr_fi_450eta5to15, HO_htr_fi_450eta5to15_loc, sizeof(int) * 2 * 11);
1272   // for the minus side, htr_fi is determined by the RM, will have to shift up one since rm is
1273   //numbered 1-4 not 0-3
1274   int HO_htr_fi_450eta16M_loc[4] = {7, 7, 8, 8};  //iside = -1
1275   memcpy(HO_htr_fi_450eta16M, HO_htr_fi_450eta16M_loc, sizeof(int) * 4);
1276   //For the plus side, there is a new htr so all values can be used, but only 6 are used
1277   //Depend on phi, but also on rm and sector (2,4,6,8,10,12)
1278   int HO_htr_fi_450eta16P_loc[4][6] = {
1279       {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
1280   memcpy(HO_htr_fi_450eta16P, HO_htr_fi_450eta16P_loc, sizeof(int) * 4 * 6);
1281 
1282   //for |eta| <= 4, htr_fi is a function of side and phmod6
1283   int HO_htr_fi_eta4_loc[2][6] = {{6, 6, 8, 8, 7, 7},   //iside = -1
1284                                   {4, 4, 5, 5, 3, 3}};  //iside = +1
1285   if (mapIOV_ < 5)
1286     memcpy(HO_htr_fi_eta4, HO_htr_fi_eta4_loc, sizeof(int) * 2 * 6);
1287 
1288   int HO_htr_fi_eta123_loc[2][6] = {{6, 5, 4, 3, 8, 7},   //iside = -1
1289                                     {8, 7, 6, 5, 2, 1}};  //iside = +1
1290   if (mapIOV_ < 5)
1291     memcpy(HO_htr_fi_eta123, HO_htr_fi_eta123_loc, sizeof(int) * 2 * 6);
1292 
1293   //HO_htr_fi_123eta5to15[2][11] is unnecessary because
1294   // HO_htr_fi_123eta5to15[i][j] == int HO_htr_fi_450eta5to15[i][j] - 1
1295 
1296   //post SiPM card swap
1297   // htr_fi is a function of phmod6,eta,rm,side
1298   // rm is a function of phimod6: rm = 1,4 for phimod6 > 3, and 2,3 otherwise
1299   // to index the array, take rm/2 integer division
1300   // cross-talk channels are separate
1301   int HO_htr_fi_eta1234_sipm[6][5][2][2] = {
1302       {/*eta==1*/ /*eta==2*/ /*eta==3*/ /*eta==4*/ /*cross-talk*/
1303        {{4, 8}, {6, 4}},
1304        {{4, 4}, {4, 7}},
1305        {{6, 8}, {6, 7}},
1306        {{5, 8}, {6, 8}},
1307        {{5, 6}, {-1, -1}}},                                                                          //phm6==0
1308       {{{6, 7}, {5, 6}}, {{6, 6}, {6, 6}}, {{6, 7}, {5, 7}}, {{5, 7}, {5, 8}}, {{-1, -1}, {4, 8}}},  //phm6==1
1309       {{{4, 5}, {5, 6}}, {{5, 5}, {5, 5}}, {{4, 5}, {4, 6}}, {{4, 6}, {3, 6}}, {{-1, -1}, {3, 8}}},  //phm6==2
1310       {{{3, 8}, {8, 5}}, {{8, 8}, {4, 8}}, {{3, 5}, {4, 5}}, {{3, 6}, {3, 5}}, {{5, 6}, {-1, -1}}},  //phm6==3
1311       {////switches from rm 2/3 to rm 1/4
1312        {{3, 2}, {8, 3}},
1313        {{3, 3}, {3, 1}},
1314        {{8, 2}, {8, 1}},
1315        {{7, 2}, {8, 2}},
1316        {{7, 7}, {-1, -1}}},                                                                          //phm6==4
1317       {{{7, 1}, {7, 7}}, {{8, 7}, {7, 7}}, {{8, 1}, {7, 1}}, {{7, 1}, {7, 2}}, {{-1, -1}, {3, 2}}},  //phm6==5
1318   };
1319 
1320   // Pixel and letter code for HO.
1321   // Ring 0 is separate and goes into entry 0, Rings +/- 1,2 are all the same and go to entry 1.
1322   // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 4, pixel = 18, let_code = X
1323   // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 5, pixel = 2, let_code = X
1324   //                    Fiber Channel       0        1       2
1325   int ipixelHO_loc[NRMFIBR][NFCH][2] = {{{12, 12}, {7, 7}, {6, 3}},      //RM fiber 2
1326                                         {{4, 4}, {8, 8}, {5, 1}},        //RM fiber 3
1327                                         {{19, 11}, {18, 6}, {17, 2}},    //RM fiber 4
1328                                         {{2, 9}, {1, 13}, {3, 5}},       //RM fiber 5
1329                                         {{11, 19}, {16, 18}, {15, 17}},  //RM fiber 6
1330                                         {{13, 15}, {9, 14}, {14, 16}}};  //RM fiber 7
1331   //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
1332   int ipixelHO_sipm[NRMFIBR][NFCH][2] = {{{12, 12}, {7, 7}, {3, 3}},       //RM fibers 2
1333                                          {{4, 4}, {8, 8}, {1, 1}},         //RM fibers 3
1334                                          {{11, 11}, {6, 6}, {2, 2}},       //RM fibers 4
1335                                          {{9, 9}, {13, 13}, {5, 5}},       //RM fibers 5
1336                                          {{19, 19}, {18, 18}, {17, 17}},   //RM fibers 6
1337                                          {{15, 15}, {14, 14}, {16, 16}}};  //RM fibers 7
1338   if (mapIOV_ < 5)
1339     memcpy(ipixelHO, ipixelHO_loc, sizeof(int) * NRMFIBR * NFCH * 2);
1340   else
1341     memcpy(ipixelHO, ipixelHO_sipm, sizeof(int) * NRMFIBR * NFCH * 2);
1342 
1343   //                            Fiber Channel        0         1         2
1344   std::string letterHO_loc[NRMFIBR][NFCH][2] = {{{"E", "E"}, {"G", "L"}, {"F", "S"}},   //RM fiber 2
1345                                                 {{"Q", "M"}, {"N", "T"}, {"P", "F"}},   //RM fiber 3
1346                                                 {{"A", "C"}, {"X", "J"}, {"J", "Q"}},   //RM fiber 4
1347                                                 {{"X", "K"}, {"R", "R"}, {"H", "D"}},   //RM fiber 5
1348                                                 {{"D", "A"}, {"C", "G"}, {"B", "N"}},   //RM fiber 6
1349                                                 {{"L", "H"}, {"M", "P"}, {"K", "B"}}};  //RM fiber 7
1350   //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
1351   std::string letterHO_sipm[NRMFIBR][NFCH][2] = {{{"E", "E"}, {"G", "L"}, {"H", "S"}},   //RM fibers 2
1352                                                  {{"Q", "M"}, {"N", "T"}, {"R", "F"}},   //RM fibers 3
1353                                                  {{"D", "C"}, {"F", "J"}, {"X", "Q"}},   //RM fibers 4
1354                                                  {{"M", "K"}, {"L", "R"}, {"P", "D"}},   //RM fibers 5
1355                                                  {{"A", "A"}, {"X", "G"}, {"J", "N"}},   //RM fibers 6
1356                                                  {{"B", "H"}, {"K", "P"}, {"C", "B"}}};  //RM fibers 7
1357 
1358   for (int jj = 0; jj < NRMFIBR; jj++) {
1359     for (int kk = 0; kk < NFCH; kk++) {
1360       for (int ll = 0; ll < 2; ll++) {
1361         if (mapIOV_ < 5)
1362           letterHO[jj][kk][ll] = letterHO_loc[jj][kk][ll];
1363         else
1364           letterHO[jj][kk][ll] = letterHO_sipm[jj][kk][ll];
1365       }
1366     }
1367   }
1368 
1369   /******************************************************************************************/
1370   //  Here is the section that deals with the miscabled HO RBXs.
1371   //  To modify the code between IOVs, just note that inverted corresponds to -infinity to end of 2008
1372   //  and otherwise, to 2009 to infinity.
1373   //  Except for some small but major caveats:
1374   //    HO2M04 (phi=16) was not able to be corrected, thus it is still inverted
1375   //    HO2M06 (phi=31) has not been active in 2009, and the cables have not been switched officially
1376   //    HO2P12 (phi=67) has not been active in 2009, and the cables have not been switched officially
1377   //  In the map, the inactive RBXs have been switched since the changes will be effected when the HO SiPMs
1378   //  are installed, also at that time, if it is possible, HO2M04 will be corrected as well.
1379   // Following intervention in May 2009, the aforementioned changes have been implemented.
1380   // All miscablings have been corrected
1381 
1382   //              switched HO RM's need reversed eta values
1383   if (mapIOV_ == 1) {
1384     int rmspecialeta_loc[6][6] = {
1385         //there are 6 special cases, corresponding to 6 values of phi
1386         {14, 15, 14, 13, 12, 11},  // ring +2 phi = 5, inverted
1387         {14, 15, 14, 13, 12, 11},  // ring +2 phi = 67, inverted
1388         {10, 9, 8, 7, 6, 5},       // ring -1 phi = 57, inverted
1389         {10, 9, 8, 7, 6, 5},       // ring -1 phi = 65, inverted
1390         {14, 15, 14, 13, 12, 11},  // ring -2 phi = 16, inverted
1391         {14, 15, 14, 13, 12, 11}   // ring -2 phi = 31, inverted
1392     };
1393 
1394     std::string rmspeciallet_code_loc[6][6] = {
1395         //there are 6 special cases, corresponding to 6 values of phi
1396         {"X", "B", "C", "D", "E", "F"},  // ring +2 phi = 5, inverted
1397         {"X", "P", "Q", "R", "S", "T"},  // ring +2 phi = 67, inverted
1398         {"G", "H", "J", "K", "L", "M"},  // ring -1 phi = 57, inverted
1399         {"A", "B", "C", "D", "E", "F"},  // ring -1 phi = 65, inverted
1400         {"X", "B", "C", "D", "E", "F"},  // ring -2 phi = 16, inverted
1401         {"X", "P", "Q", "R", "S", "T"}   // ring -2 phi = 31, inverted
1402     };
1403 
1404     std::string rmspecialdet_loc[6][6] = {
1405         //there are 6 special cases, corresponding to 6 values of phi
1406         {"HOX", "HO", "HO", "HO", "HO", "HO"},  // ring +2 phi = 5, inverted
1407         {"HOX", "HO", "HO", "HO", "HO", "HO"},  // ring +2 phi = 67, inverted
1408         {"HO", "HO", "HO", "HO", "HO", "HO"},   // ring -1 phi = 57, inverted
1409         {"HO", "HO", "HO", "HO", "HO", "HO"},   // ring -1 phi = 65, inverted
1410         {"HOX", "HO", "HO", "HO", "HO", "HO"},  // ring -2 phi = 16, inverted
1411         {"HOX", "HO", "HO", "HO", "HO", "HO"}   // ring -2 phi = 31, inverted
1412     };
1413 
1414     memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1415     //              switched HO RM's need revised letter codes
1416 
1417     for (int jj = 0; jj < 6; jj++) {
1418       for (int kk = 0; kk < 6; kk++) {
1419         rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1420       }
1421     }
1422 
1423     for (int jj = 0; jj < 6; jj++) {
1424       for (int kk = 0; kk < 6; kk++) {
1425         rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1426       }
1427     }
1428   }
1429 
1430   else if (mapIOV_ == 2) {
1431     int rmspecialeta_loc[6][6] = {
1432         //there are 6 special cases, corresponding to 6 values of phi
1433         {11, 12, 13, 14, 15, 15},  // ring +2 phi = 5
1434         {11, 12, 13, 14, 15, 15},  // ring +2 phi = 67
1435         {5, 6, 7, 8, 9, 10},       // ring -1 phi = 57
1436         {5, 6, 7, 8, 9, 10},       // ring -1 phi = 65
1437         {14, 15, 14, 13, 12, 11},  // ring -2 phi = 16, still inverted
1438         {11, 12, 13, 14, 15, 15}   // ring -2 phi = 31
1439     };
1440 
1441     std::string rmspeciallet_code_loc[6][6] = {
1442         //there are 6 special cases, corresponding to 6 values of phi
1443         {"F", "E", "D", "C", "B", "X"},  // ring +2 phi = 5
1444         {"T", "S", "R", "Q", "P", "X"},  // ring +2 phi = 67
1445         {"M", "L", "K", "J", "H", "G"},  // ring -1 phi = 57
1446         {"F", "E", "D", "C", "B", "A"},  // ring -1 phi = 65
1447         {"X", "B", "C", "D", "E", "F"},  // ring -2 phi = 16,still  inverted
1448         {"T", "S", "R", "Q", "P", "X"}   // ring -2 phi = 31
1449     };
1450 
1451     std::string rmspecialdet_loc[6][6] = {
1452         //there are 6 special cases, corresponding to 6 values of phi
1453         {"HO", "HO", "HO", "HO", "HO", "HOX"},  // ring +2 phi = 5
1454         {"HO", "HO", "HO", "HO", "HO", "HOX"},  // ring +2 phi = 67
1455         {"HO", "HO", "HO", "HO", "HO", "HO"},   // ring -1 phi = 57
1456         {"HO", "HO", "HO", "HO", "HO", "HO"},   // ring -1 phi = 65
1457         {"HOX", "HO", "HO", "HO", "HO", "HO"},  // ring -2 phi = 16, still inverted
1458         {"HO", "HO", "HO", "HO", "HO", "HOX"}   // ring -2 phi = 31
1459     };
1460 
1461     memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1462     //              switched HO RM's need revised letter codes
1463 
1464     for (int jj = 0; jj < 6; jj++) {
1465       for (int kk = 0; kk < 6; kk++) {
1466         rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1467       }
1468     }
1469 
1470     for (int jj = 0; jj < 6; jj++) {
1471       for (int kk = 0; kk < 6; kk++) {
1472         rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1473       }
1474     }
1475   }
1476 
1477   else {
1478     int rmspecialeta_loc[6][6] = {
1479         //there are 6 special cases, corresponding to 6 values of phi
1480         {11, 12, 13, 14, 15, 15},  // ring +2 phi = 5
1481         {11, 12, 13, 14, 15, 15},  // ring +2 phi = 67
1482         {5, 6, 7, 8, 9, 10},       // ring -1 phi = 57
1483         {5, 6, 7, 8, 9, 10},       // ring -1 phi = 65
1484         {11, 12, 13, 14, 15, 15},  // ring -2 phi = 16
1485         {11, 12, 13, 14, 15, 15}   // ring -2 phi = 31
1486     };
1487 
1488     std::string rmspeciallet_code_loc[6][6] = {
1489         //there are 6 special cases, corresponding to 6 values of phi
1490         {"F", "E", "D", "C", "B", "X"},  // ring +2 phi = 5
1491         {"T", "S", "R", "Q", "P", "X"},  // ring +2 phi = 67
1492         {"M", "L", "K", "J", "H", "G"},  // ring -1 phi = 57
1493         {"F", "E", "D", "C", "B", "A"},  // ring -1 phi = 65
1494         {"F", "E", "D", "C", "B", "X"},  // ring -2 phi = 16
1495         {"T", "S", "R", "Q", "P", "X"}   // ring -2 phi = 31
1496     };
1497 
1498     std::string rmspecialdet_loc[6][6] = {
1499         //there are 6 special cases, corresponding to 6 values of phi
1500         {"HO", "HO", "HO", "HO", "HO", "HOX"},  // ring +2 phi = 5
1501         {"HO", "HO", "HO", "HO", "HO", "HOX"},  // ring +2 phi = 67
1502         {"HO", "HO", "HO", "HO", "HO", "HO"},   // ring -1 phi = 57
1503         {"HO", "HO", "HO", "HO", "HO", "HO"},   // ring -1 phi = 65
1504         {"HO", "HO", "HO", "HO", "HO", "HOX"},  // ring -2 phi = 16
1505         {"HO", "HO", "HO", "HO", "HO", "HOX"}   // ring -2 phi = 31
1506     };
1507 
1508     memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1509     //              switched HO RM's need revised letter codes
1510 
1511     for (int jj = 0; jj < 6; jj++) {
1512       for (int kk = 0; kk < 6; kk++) {
1513         rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1514       }
1515     }
1516 
1517     for (int jj = 0; jj < 6; jj++) {
1518       for (int kk = 0; kk < 6; kk++) {
1519         rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1520       }
1521     }
1522   }
1523 
1524   /******************************/
1525 
1526   char tempbuff[30]{0};
1527 
1528   //Stream variable
1529   stringstream mystream;
1530 
1531   //Radical change: HO iterates over eta and phi rather than crate, HTR, etc.
1532   for (isid = -1; isid < 2; isid += 2) {
1533     for (iph = 0; iph < NHOPHI; iph++) {
1534       for (iet = 0; iet < NHOETA; iet++) {
1535         iphi = iph + 1;
1536         ieta = iet + 1;
1537         iside = isid;
1538 
1539         if (iphi >= 71 || iphi < 17)
1540           ic = 0;
1541         else if (iphi >= 17 && iphi < 35)
1542           ic = 1;
1543         else if (iphi >= 35 && iphi < 53)
1544           ic = 2;
1545         else
1546           ic = 3;
1547 
1548         icrate = hocrate[ic];
1549         idepth = 4;
1550         det = "HO";
1551 
1552         //fpga = top/bottom for Ring 0 depends on a pattern that repeats every 30 degrees (6 phi)
1553         //Hence, phmod6 (not phi mod 6 because I don't want to separate 71 and 72, etc.)
1554 
1555         phmod6 = iph % 6;
1556         //Bools associated with phmod6 to be used with htr_fi and the patch panel
1557         phmod6e450 = (phmod6 == 4 || phmod6 == 5 || phmod6 == 0);
1558         phmod6e123 = (phmod6 == 1 || phmod6 == 2 || phmod6 == 3);
1559 
1560         //Ring 0 (HTR type 0) is special
1561         if (ieta <= 3 && (iside < 0 || phmod6 >= 4))
1562           fpga = "bot";
1563         else if (ieta <= 3 && iside > 0 && phmod6 < 4)
1564           fpga = "top";
1565         //new HX HTR
1566         else if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6))
1567           fpga = "top";
1568         else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13))
1569           fpga = "bot";
1570         //HTR types 0 and 1
1571         else if (ieta >= 10 && iside > 0)
1572           fpga = "top";
1573         else if (ieta < 10 && ieta >= 6 && iside > 0)
1574           fpga = "bot";
1575         //HTR types 2 and 3
1576         else if ((ieta == 5 && iside > 0) || ieta == 4)
1577           fpga = "top";
1578         else if ((ieta == 5 || ieta >= 10) && iside < 0)
1579           fpga = "bot";
1580         else if ((ieta < 10 && ieta >= 6) && iside < 0)
1581           fpga = "top";
1582         else
1583           edm::LogInfo("HcalLogicalMapGenerator") << "Bad fpga code" << endl;
1584 
1585         //dphi
1586         if (ieta <= 20)
1587           idphi = 1;
1588         else
1589           idphi = -1000;
1590 
1591         //create values usable in arrays from side and fpga
1592         if (iside == 1)
1593           sidear = 1;
1594         else
1595           sidear = 0;
1596 
1597         phmod24 = iph % 24;
1598 
1599         //Again, x - 1 because the array starts at 0 while the variables start at 1
1600         irm = HO_RM_table[phmod24][iet][sidear];
1601 
1602         //x - 5 for the eta array for the same reason
1603         //  the new stuff for HX
1604         if (ieta == 16)
1605           irm_fi = HO_RM_fi_eta16;
1606         else if (ieta >= 5)
1607           irm_fi = HO_RM_fi_eta5to15[ieta - 5];
1608         else {
1609           if (mapIOV_ < 5) {
1610             if (ieta <= 3)
1611               irm_fi = HO_RM_fi_eta1to4[phmod24][0][sidear];
1612             else if (ieta == 4)
1613               irm_fi = HO_RM_fi_eta1to4[phmod24][1][sidear];
1614             else
1615               irm_fi = -1000;
1616           } else if (mapIOV_ >= 5) {
1617             irm_fi = HO_RM_fi_eta1to4_sipm[phmod24][ieta - 1][sidear];
1618           }
1619         }
1620 
1621         //HTR fiber
1622 
1623         //
1624         if (ieta >= 5 && phmod6e450)
1625           ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5];
1626         else if (ieta >= 5 && phmod6e123)
1627           ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5] - 1;
1628         else if (ieta <= 4) {
1629           if (mapIOV_ < 5) {
1630             if (ieta == 4)
1631               ihtr_fi = HO_htr_fi_eta4[sidear][phmod6];
1632             else if (ieta <= 3)
1633               ihtr_fi = HO_htr_fi_eta123[sidear][phmod6];
1634           } else if (mapIOV_ >= 5) {
1635             ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][ieta - 1][(irm - 1) / 2][sidear];
1636           }
1637         } else
1638           ihtr_fi = -1000;
1639 
1640         //Fiber Channel
1641         //Eta >= 5 bools
1642         phi1458 = (iphi % 12 == 1 || iphi % 12 == 4 || iphi % 12 == 5 || iphi % 12 == 8);
1643         phi271011 = (iphi % 12 == 2 || iphi % 12 == 7 || iphi % 12 == 10 || iphi % 12 == 11);
1644 
1645         //Ring 0 bools
1646         phir0v1 = (iphi % 24 == 0 || iphi % 24 == 2 || iphi % 24 == 4 || iphi % 24 == 18 || iphi % 24 == 20 ||
1647                    iphi % 24 == 22);
1648         phir0v2 = (iphi % 24 == 1 || iphi % 24 == 3 || iphi % 24 == 17 || iphi % 24 == 19 || iphi % 24 == 21 ||
1649                    iphi % 24 == 23);
1650         //v3: phi 5 to 15 odd; v4: phi 6 to 16 even
1651         phir0v3 = (iphi % 24 == 5 || iphi % 24 == 7 || iphi % 24 == 9 || iphi % 24 == 11 || iphi % 24 == 13 ||
1652                    iphi % 24 == 15);
1653         phir0v4 = (iphi % 24 == 6 || iphi % 24 == 8 || iphi % 24 == 10 || iphi % 24 == 12 || iphi % 24 == 14 ||
1654                    iphi % 24 == 16);
1655 
1656         if (ieta >= 5) {
1657           if (ieta % 2 == 0 && phi1458)
1658             ifi_ch = 0;
1659           else if (ieta % 2 == 0 && iphi % 3 == 0)
1660             ifi_ch = 1;
1661           else if (ieta % 2 == 0 && phi271011)
1662             ifi_ch = 2;
1663           else if (ieta % 2 == 1 && iphi % 3 == 0)
1664             ifi_ch = 0;
1665           else if (ieta % 2 == 1 && phi271011)
1666             ifi_ch = 1;
1667           else if (ieta % 2 == 1 && phi1458)
1668             ifi_ch = 2;
1669         } else {
1670           if (mapIOV_ < 5) {
1671             if (ieta == 4) {
1672               if (iside == -1) {
1673                 if (phir0v1)
1674                   ifi_ch = 0;
1675                 else if (phir0v4)
1676                   ifi_ch = 1;
1677                 else if (iphi % 2 == 1)
1678                   ifi_ch = 2;
1679               } else {
1680                 if (phir0v3)
1681                   ifi_ch = 0;
1682                 else if (phir0v2)
1683                   ifi_ch = 1;
1684                 else if (iphi % 2 == 0)
1685                   ifi_ch = 2;
1686               }
1687             }
1688             //eta = -3 and eta = +2
1689             else if ((ieta == 3 && iside == -1) || (ieta == 2 && iside == 1)) {
1690               if (phir0v4)
1691                 ifi_ch = 0;
1692               else if (phir0v3)
1693                 ifi_ch = 1;
1694               else if (phir0v1 || phir0v2)
1695                 ifi_ch = 2;
1696             }
1697             //eta = -2 and eta = +3
1698             else if ((ieta == 3 && iside == 1) || (ieta == 2 && iside == -1)) {
1699               if (phir0v2)
1700                 ifi_ch = 0;
1701               else if (phir0v1)
1702                 ifi_ch = 1;
1703               else if (phir0v3 || phir0v4)
1704                 ifi_ch = 2;
1705             }
1706             //ieta = 1
1707             else if (ieta == 1) {
1708               if (phir0v1 || phir0v3)
1709                 ifi_ch = 0;
1710               else if (phir0v2 || phir0v4)
1711                 ifi_ch = 1;
1712             }
1713           } else {
1714             /*New code here for SiPM handling of rm fiber channel
1715           more challenging and requires some thought*/
1716             if (ieta == 4) {
1717               if (iside == -1) {
1718                 if (phir0v1)
1719                   ifi_ch = 0;
1720                 else if (phir0v4)
1721                   ifi_ch = 2;
1722                 else if (iphi % 2 == 1)
1723                   ifi_ch = 2;
1724               } else {
1725                 if (phir0v3)
1726                   ifi_ch = 0;
1727                 else if (phir0v2)
1728                   ifi_ch = 2;
1729                 else if (iphi % 2 == 0)
1730                   ifi_ch = 2;
1731               }
1732             }
1733             if (ieta == 2) {
1734               if (iside == -1) {
1735                 if (iphi % 2 == 0)
1736                   ifi_ch = 2;
1737                 else if (iphi % 2 == 1)
1738                   ifi_ch = 1;
1739               } else {
1740                 if (iphi % 2 == 0)
1741                   ifi_ch = 1;
1742                 else if (iphi % 2 == 1)
1743                   ifi_ch = 2;
1744               }
1745             }
1746             if (ieta == 3) {
1747               if (iside == -1) {
1748                 if (iphi % 2 == 0)
1749                   ifi_ch = 0;
1750                 else if (iphi % 2 == 1)
1751                   ifi_ch = 1;
1752               } else {
1753                 if (iphi % 2 == 1)
1754                   ifi_ch = 0;
1755                 else if (iphi % 2 == 0)
1756                   ifi_ch = 1;
1757               }
1758             }
1759             if (ieta == 1) {
1760               if (iside == -1) {
1761                 if (phir0v1)
1762                   ifi_ch = 0;
1763                 else if (phir0v4)
1764                   ifi_ch = 1;
1765                 else if (iphi % 2 == 1)
1766                   ifi_ch = 0;
1767               } else {
1768                 if (phir0v3)
1769                   ifi_ch = 0;
1770                 else if (phir0v2)
1771                   ifi_ch = 1;
1772                 else if (iphi % 2 == 0)
1773                   ifi_ch = 0;
1774               }
1775             }
1776           }
1777         }
1778 
1779         //Intentional integer truncation; iqie and iadc are the same across all subdetectors
1780         //(Although irm_fi for HF starts at 1 and for HO it starts at 2, so one can't just copy and paste)
1781         iqie = (irm_fi - 2) / 2 + 1;
1782 
1783         if (irm_fi % 2 == 0)
1784           iadc = ifi_ch;
1785         else
1786           iadc = NFCH + (ifi_ch + 1) % 3;
1787 
1788         //Pixel and Letter Code (Ring 0 is separate)
1789         if (ieta <= 4) {
1790           ipixel = ipixelHO[irm_fi - 2][ifi_ch][0];
1791           letter = letterHO[irm_fi - 2][ifi_ch][0];
1792         } else {
1793           ipixel = ipixelHO[irm_fi - 2][ifi_ch][1];
1794           letter = letterHO[irm_fi - 2][ifi_ch][1];
1795         }
1796 
1797         //special treatment for new ring-0 SiPMs fpga
1798         int mytype = -1;  //variable that allows grouping of channels
1799         if (ieta <= 4 && mapIOV_ >= 5) {
1800           if (ipixel == 3 || ipixel == 7 || ipixel == 12 || ipixel == 14 || ipixel == 17 || ipixel == 18) {
1801             mytype = 1;
1802             if (phmod6 == 1 || phmod6 == 3)
1803               fpga = "top";
1804             else
1805               fpga = "bot";
1806           } else if (ipixel == 1 || ipixel == 4 || ipixel == 8 || ipixel == 15 || ipixel == 16 || ipixel == 19) {
1807             mytype = 2;
1808             if (phmod6 == 0 || phmod6 == 2)
1809               fpga = "top";
1810             else
1811               fpga = "bot";
1812           } else if (ipixel == 2 || ipixel == 5 || ipixel == 6 || ipixel == 9 || ipixel == 11 || ipixel == 13) {
1813             mytype = 3;
1814             fpga = "top";
1815           }
1816         }
1817 
1818         if (fpga == "bot")
1819           itb = 1;  //convention different than for the
1820         else
1821           itb = 0;  //electronics id, modified in the
1822                     //MapEntry code
1823 
1824         //Determine which of HTR in the set belongs here. It depends only on eta and side.
1825         //  the new stuff for HX
1826         if (ieta <= 3 || (ieta >= 14 && iside == 1))
1827           ih = 0;
1828         else if (ieta <= 13 && ieta >= 6 && iside == 1)
1829           ih = 1;
1830         else if (ieta <= 13 && ieta >= 6 && iside == -1)
1831           ih = 3;
1832         else
1833           ih = 2;
1834 
1835         ////special treatment for new ring-0 SiPMs
1836         // the htrs are grouped in chunks of ((ph+2) mod 18)/6
1837         //71,72,1,2,3,4
1838         // and indexed by the mytype variable previously defined
1839         int php2mod18 = (iph + 2) % 18;
1840         int php2mod18ov6 = php2mod18 / 6;
1841 
1842         //Each value of "is" covers 30 degrees (that is, 6 values of phi). To calculate which ones,
1843         //I use phi % 18. Crates start at phi = 71, 17, 35, 53
1844 
1845         if (iphi % 18 == 17 || iphi % 18 <= 4)
1846           is = 0;
1847         else if (iphi % 18 >= 5 && iphi % 18 <= 10)
1848           is = 1;
1849         else
1850           is = 2;
1851 
1852         if (ieta == 16 && iside > 0)
1853           ihtr = 21;
1854         else if (ieta > 4)
1855           ihtr = ihslotho[is][ih];
1856         else {
1857           //special treatment only for ring-0
1858           if (mapIOV_ < 5)
1859             ihtr = ihslotho[is][ih];
1860           else {
1861             if (mytype == 1 || mytype == 2)
1862               ih = 0;
1863             else
1864               ih = 2;
1865             ihtr = ihslotho[php2mod18ov6][ih];
1866           }
1867         }
1868 
1869         if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6))
1870           ispigot = 12;
1871         else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13))
1872           ispigot = 13;
1873         else
1874           ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
1875         idcc = ihtr < 9 ? 1 : 2;
1876         idcc_sl = idcc == 1 ? 10 : 20;
1877 
1878         ifed = fedhonum[ic][idcc - 1];
1879 
1880         //RBX and sector
1881 
1882         if (iside == -1)
1883           sidesign = 'M';
1884         else
1885           sidesign = 'P';
1886 
1887         if (ieta <= 4)
1888           ring = 0;
1889         else if (ieta >= 5 && ieta <= 10)
1890           ring = 1;
1891         else
1892           ring = 2;
1893 
1894         //Sector ranges from 1 to 12 depending on phi. Sector 1 goes 71,72,1,2,3,4 so I start at -2
1895         sector = 0;
1896         for (i = -2; i < iphi; i += 6) {
1897           sector++;
1898         }
1899         if (sector > 12)
1900           sector = 1;  //It rolls over for phi = 71,72
1901 
1902         isector = sector;
1903 
1904         //For rings 1 and 2, we only want even sectors for the rbx
1905         if (ring != 0 && sector % 2 != 0)
1906           sector++;
1907 
1908         if (ring == 0)
1909           snprintf(tempbuff, sizeof tempbuff, "%s%i%2.2d", det.c_str(), ring, sector);
1910         else
1911           snprintf(tempbuff, sizeof tempbuff, "%s%i%c%2.2d", det.c_str(), ring, sidesign, sector);
1912         mystream << tempbuff;
1913         rbx = mystream.str();
1914         mystream.str("");
1915         if (ieta == 16) {
1916           det = "HOX";
1917           letter = "X";
1918         } else
1919           det = "HO";
1920 
1921         //  the new htr_fi stuff for HX
1922         if (ieta == 16 && isid < 0)
1923           ihtr_fi = HO_htr_fi_450eta16M[irm - 1];
1924         else if (ieta == 16 && isid > 0)
1925           ihtr_fi = HO_htr_fi_450eta16P[irm - 1][sector / 2 - 1];
1926 
1927         if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 7)) {
1928           icrate = 6;
1929           ifed = 729;
1930         } else if ((ieta > 15 && iside > 0) && (icrate == 6 || icrate == 13)) {
1931           icrate = 7;
1932           ifed = 727;
1933         }
1934 
1935         if (ieta == 16)
1936           ieta = 15;
1937         // fixing the switched RM's
1938         if (iside == 1 && ring == 2) {
1939           if (iphi == 5) {
1940             ieta = rmspecialeta[0][iet - 10];
1941             letter = rmspeciallet_code[0][iet - 10];
1942             det = rmspecialdet[0][iet - 10];
1943           } else if (iphi == 67) {
1944             ieta = rmspecialeta[1][iet - 10];
1945             letter = rmspeciallet_code[1][iet - 10];
1946             det = rmspecialdet[1][iet - 10];
1947           }
1948         } else if (iside == -1) {
1949           if (ring == 1) {
1950             if (iphi == 57) {
1951               ieta = rmspecialeta[2][iet - 4];
1952               letter = rmspeciallet_code[2][iet - 4];
1953               det = rmspecialdet[2][iet - 4];
1954             } else if (iphi == 65) {
1955               ieta = rmspecialeta[3][iet - 4];
1956               letter = rmspeciallet_code[3][iet - 4];
1957               det = rmspecialdet[3][iet - 4];
1958             }
1959           } else if (ring == 2) {
1960             if (iphi == 16) {
1961               ieta = rmspecialeta[4][iet - 10];
1962               letter = rmspeciallet_code[4][iet - 10];
1963               det = rmspecialdet[4][iet - 10];
1964             } else if (iphi == 31) {
1965               ieta = rmspecialeta[5][iet - 10];
1966               letter = rmspeciallet_code[5][iet - 10];
1967               det = rmspecialdet[5][iet - 10];
1968             }
1969           }
1970         }
1971 
1972         HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
1973                                          ihtr_fi,
1974                                          ispigot,
1975                                          ifed,
1976                                          icrate,
1977                                          ihtr,
1978                                          fpga,
1979                                          det,
1980                                          iside,
1981                                          ieta,
1982                                          iphi,
1983                                          idepth,
1984                                          idphi,
1985                                          isector,
1986                                          irm,
1987                                          irm_fi,
1988                                          ipixel,
1989                                          iqie,
1990                                          iadc,
1991                                          rbx,
1992                                          letter);
1993         HOHXEntries.push_back(hoxlmapentry);
1994         LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
1995             HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
1996 
1997         const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
1998         unsigned int denseId;
1999         if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2000           denseId = topo->detId2denseIdHO(hgdi);
2001           HoHash2Entry.at(denseId) = HOHXEntries.size();
2002         } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2003           denseId = topo->detId2denseIdCALIB(hgdi);
2004           HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2005         }
2006 
2007         if (ring == 0) {
2008           if (ipixel == 1) {
2009             ipixel = 2;
2010             iadc = 4;
2011             if (mapIOV_ < 5)
2012               ifi_ch = 0;
2013             else {
2014               irm_fi = 4;
2015               ifi_ch = 2;
2016               if (irm_fi % 2 == 0)
2017                 iadc = ifi_ch;
2018               else
2019                 iadc = NFCH + (ifi_ch + 1) % 3;
2020               iqie = (irm_fi - 2) / 2 + 1;
2021               ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm - 1) / 2][sidear];
2022               itb = 0;
2023               fpga = "top";
2024               //              mytype = 3;
2025               ih = 2;
2026               ihtr = ihslotho[php2mod18ov6][ih];
2027               ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
2028               idcc = ihtr < 9 ? 1 : 2;
2029               idcc_sl = idcc == 1 ? 10 : 20;
2030               ifed = fedhonum[ic][idcc - 1];
2031             }
2032             letter = "X";
2033             det = "HOX";
2034             HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
2035                                              ihtr_fi,
2036                                              ispigot,
2037                                              ifed,
2038                                              icrate,
2039                                              ihtr,
2040                                              fpga,
2041                                              det,
2042                                              iside,
2043                                              ieta,
2044                                              iphi,
2045                                              idepth,
2046                                              idphi,
2047                                              isector,
2048                                              irm,
2049                                              irm_fi,
2050                                              ipixel,
2051                                              iqie,
2052                                              iadc,
2053                                              rbx,
2054                                              letter);
2055             HOHXEntries.push_back(hoxlmapentry);
2056             LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
2057                 HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
2058 
2059             const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
2060             unsigned int denseId;
2061             if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2062               denseId = topo->detId2denseIdHO(hgdi);
2063               HoHash2Entry.at(denseId) = HOHXEntries.size();
2064             } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2065               denseId = topo->detId2denseIdCALIB(hgdi);
2066               HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2067             }
2068           } else if (ipixel == 17) {
2069             ipixel = 18;
2070             iadc = 1;
2071             if (mapIOV_ < 5)
2072               ifi_ch = 1;
2073             else {
2074               irm_fi = 6;
2075               ifi_ch = 1;
2076               if (irm_fi % 2 == 0)
2077                 iadc = ifi_ch;
2078               else
2079                 iadc = NFCH + (ifi_ch + 1) % 3;
2080               iqie = (irm_fi - 2) / 2 + 1;
2081               ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm - 1) / 2][sidear];
2082               if (phmod6 == 1 || phmod6 == 3) {
2083                 itb = 0;
2084                 fpga = "top";
2085               } else {
2086                 itb = 1;
2087                 fpga = "bot";
2088               }
2089               ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
2090               idcc = ihtr < 9 ? 1 : 2;
2091               idcc_sl = idcc == 1 ? 10 : 20;
2092               ifed = fedhonum[ic][idcc - 1];
2093             }
2094             letter = "X";
2095             det = "HOX";
2096             HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
2097                                              ihtr_fi,
2098                                              ispigot,
2099                                              ifed,
2100                                              icrate,
2101                                              ihtr,
2102                                              fpga,
2103                                              det,
2104                                              iside,
2105                                              ieta,
2106                                              iphi,
2107                                              idepth,
2108                                              idphi,
2109                                              isector,
2110                                              irm,
2111                                              irm_fi,
2112                                              ipixel,
2113                                              iqie,
2114                                              iadc,
2115                                              rbx,
2116                                              letter);
2117             HOHXEntries.push_back(hoxlmapentry);
2118             LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
2119                 HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
2120 
2121             const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
2122             unsigned int denseId;
2123             if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2124               denseId = topo->detId2denseIdHO(hgdi);
2125               HoHash2Entry.at(denseId) = HOHXEntries.size();
2126             } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2127               denseId = topo->detId2denseIdCALIB(hgdi);
2128               HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2129             }
2130           }
2131         }
2132       }
2133     }
2134   }
2135 }
2136 
2137 void HcalLogicalMapGenerator::buildCALIBMap(const HcalTopology* topo,
2138                                             std::vector<CALIBLogicalMapEntry>& CALIBEntries,
2139                                             std::vector<uint32_t>& LinearIndex2Entry,
2140                                             std::vector<uint32_t>& HxCalibHash2Entry) {
2141   /******************************/
2142   /* CALIB crate numbering in order of FEDID*/
2143   int calibcrate_loc[NCALIBCR] = {4, 0, 1, 5, 11, 15, 17, 14, 10, 9, 7, 6, 13};  //HBHE,HF,HO
2144   memcpy(calibcrate, calibcrate_loc, sizeof(int) * NCALIBCR);
2145   /* CALIB FED numbering of DCCs */
2146   int fedcalibnum_loc[NCALIBCR][2] = {{700, 701},
2147                                       {702, 703},
2148                                       {704, 705},
2149                                       {706, 707},
2150                                       {708, 709},
2151                                       {710, 711},
2152                                       {712, 713},
2153                                       {714, 715},
2154                                       {716, 717}, /*calib_hbhe 4,0,1,5,11,15,17,14,10*/
2155                                       {720, 721}, /*calib_hf 9*/
2156                                       {726, 727},
2157                                       {728, 729},
2158                                       {730, 731}};  //calib_ho 7,6,13
2159   memcpy(fedcalibnum, fedcalibnum_loc, sizeof(int) * NCALIBCR * 2);
2160   /* iphi (lower) starting index for each CALIB crate */
2161   int icalibphis_loc[NCALIBCR] = {3, 11, 19, 27, 35, 43, 51, 59, 67, 27, 17, 35, 53};
2162   memcpy(icalibphis, icalibphis_loc, sizeof(int) * NCALIBCR);
2163   /* icalibsector_min minimum sector on each crate {0,1,4,5,10,11,14,15,17,9,7,6,13}*/
2164   int icalibsector_min_loc[NCALIBCR] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 4, 7, 10};
2165   memcpy(icalibsector_min, icalibsector_min_loc, sizeof(int) * NCALIBCR);
2166   /* icalibsector_max maximum sector on each crate */
2167   int icalibsector_max_loc[NCALIBCR] = {3, 5, 7, 9, 11, 13, 15, 17, 1, 4, 6, 9, 12};
2168   memcpy(icalibsector_max, icalibsector_max_loc, sizeof(int) * NCALIBCR);
2169   //detectors represented on each crate (0 for top, 1 for bot)
2170   std::string detIDCALIB_loc[NCALIBCR][NTOPBOT] = {{"HB", "HE"},  /*crate 4*/
2171                                                    {"HB", "HE"},  /*crate 0*/
2172                                                    {"HB", "HE"},  /*crate 1*/
2173                                                    {"HB", "HE"},  /*crate 5*/
2174                                                    {"HB", "HE"},  /*crate 11*/
2175                                                    {"HB", "HE"},  /*crate 15*/
2176                                                    {"HB", "HE"},  /*crate 17*/
2177                                                    {"HB", "HE"},  /*crate 14*/
2178                                                    {"HB", "HE"},  /*crate 10*/
2179                                                    {"HF", "HF"},  /*crate 9*/
2180                                                    {"HO", "HO"},  /*crate 7*/
2181                                                    {"HO", "HO"},  /*crate 6*/
2182                                                    {"HO", "HO"}}; /*crate 13*/
2183   for (int jj = 0; jj < NCALIBCR; jj++) {
2184     for (int kk = 0; kk < NTOPBOT; kk++) {
2185       detIDCALIB[jj][kk] = detIDCALIB_loc[jj][kk];
2186     }
2187   }
2188 
2189   int nfbr_max_loc[NCALIBCR][NTOPBOT] = {
2190       {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}};
2191   memcpy(nfbr_max, nfbr_max_loc, sizeof(int) * NCALIBCR * NTOPBOT);
2192   //HB only utilizes 4 htr_fibers HE all 8
2193   int calibHOinfo_loc[NHOCR][NTOPBOT][NFBR][2] = {
2194       /*sector and ring of HO for the calib channel*/
2195       {{{4, 0}, {5, 0}, {6, 0}, {}, {6, -2}, {6, -1}, {6, 1}, {6, 2}},
2196        {{4, -2}, {4, -1}, {4, 1}, {4, 2}, {}, {}, {}, {}}}, /*crate 7*/
2197 
2198       {{{7, 0}, {8, 0}, {9, 0}, {}, {8, -2}, {8, -1}, {8, 1}, {8, 2}},
2199        {{1, 0}, {2, 0}, {3, 0}, {}, {2, -2}, {2, -1}, {2, 1}, {2, 2}}}, /*crate 6*/
2200 
2201       {{{10, 0}, {11, 0}, {12, 0}, {}, {10, -2}, {10, -1}, {10, 1}, {10, 2}},
2202        {{12, -2}, {12, -1}, {12, 1}, {12, 2}, {}, {}, {}, {}}} /*crate 13*/
2203   };
2204   memcpy(calibHOinfo, calibHOinfo_loc, sizeof(int) * NHOCR * NTOPBOT * NFBR * 2);
2205 
2206   /*********************************/
2207 
2208   char tempbuff[30]{0};
2209 
2210   //Stream variable
2211 
2212   stringstream mystream;
2213   /**/
2214   ihtr = 8;  //calibration units are housed on htr slot 8
2215   idcc = 1;
2216   idcc_sl = 10;
2217   irm_fi = 1;  // everything other than HE is on A
2218   det = "";
2219 
2220   /*****************************************************/
2221   /*HBHE calibration channels*/
2222   for (ic = 0; ic < NHBHECR; ic++) {
2223     icrate = calibcrate[ic];
2224     ifed = fedcalibnum[ic][idcc - 1];
2225     /* top and bottom */
2226     for (itb = 0; itb < NTOPBOT; itb++) {
2227       /* 4 or 8 fibers used per HTR FPGA */
2228       for (ifb = 0; ifb < nfbr_max[ic][itb]; ifb++) {
2229         det = detIDCALIB[ic][itb];
2230         ihtr_fi = ifb + 1;
2231         irm_fi = 1;  // everything other than he is on A
2232         idphi = 4;
2233         if (itb == 1)
2234           if (ihtr_fi % 2 == 0)
2235             irm_fi = 2;  //all of the even fibers in HE are on B rather than A
2236         if (det == "HE") {
2237           ispigot = 13;
2238           fpga = "bot";
2239           if (ihtr_fi == 1 || ihtr_fi == 2 || ihtr_fi == 5 || ihtr_fi == 6) {
2240             iwedge = icalibsector_min[ic];
2241           } else if (ihtr_fi == 3 || ihtr_fi == 4 || ihtr_fi == 7 || ihtr_fi == 8) {
2242             iwedge = icalibsector_max[ic];
2243           }
2244           if (ihtr_fi < 5) {
2245             sidesign = 'M';
2246             S_side = '1';
2247             ieta = -1;
2248             iside = -1;
2249           } else {
2250             sidesign = 'P';
2251             S_side = '1';
2252             ieta = 1;
2253             iside = 1;
2254           }
2255         } else if (det == "HB") {
2256           ispigot = 12;
2257           fpga = "top";
2258           (ihtr_fi % 2 == 1) ? iwedge = icalibsector_min[ic] : iwedge = icalibsector_max[ic];
2259           if (ihtr_fi < 3) {
2260             sidesign = 'M';
2261             S_side = '1';
2262             ieta = -1;
2263             iside = -1;
2264           } else {
2265             sidesign = 'P';
2266             S_side = '1';
2267             ieta = 1;
2268             iside = 1;
2269           }
2270         }
2271         iphi = ((iwedge * idphi) + 71 - idphi) % 72;
2272         subdet = "CALIB_" + det;
2273         snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2274         mystream << tempbuff;
2275         rbx = mystream.str();
2276         mystream.str("");
2277         /* three channels per fiber */
2278         for (ifc = 0; ifc < NFCH; ifc++) {
2279           ifi_ch = ifc;
2280           if (irm_fi == 1) {
2281             if (ifc == 0)
2282               ich_type = 0;
2283             else if (ifc == 1)
2284               ich_type = 1;
2285             else if (ifc == 2) {
2286               if (det == "HB")
2287                 ich_type = 2;
2288               else if (det == "HE")
2289                 ich_type = 3;
2290             }
2291           } else if (irm_fi == 2) {
2292             if (ifc == 0)
2293               ich_type = 4;
2294             else if (ifc == 1)
2295               ich_type = 5;
2296             else if (ifc == 2)
2297               ich_type = 6;
2298           }
2299           CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2300                                               ihtr_fi,
2301                                               ispigot,
2302                                               ifed,
2303                                               icrate,
2304                                               ihtr,
2305                                               fpga,
2306                                               det,
2307                                               ieta,
2308                                               iphi,
2309                                               ich_type,
2310                                               iside,
2311                                               idphi,
2312                                               rbx,
2313                                               iwedge,
2314                                               irm_fi,
2315                                               subdet);
2316           CALIBEntries.push_back(caliblmapentry);
2317           LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2318               HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2319 
2320           const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2321           const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2322           if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2323             HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2324         }
2325       }
2326     }
2327   }
2328 
2329   /* only one CALIB HF crate */
2330   /* top and bottom */
2331   for (itb = 0; itb < NTOPBOT; itb++) {
2332     /* four CALIB HF fibers per HTR FPGA */
2333     for (ifb = 0; ifb < 4; ifb++) {
2334       /* three channels per fiber */
2335       for (ifc = 0; ifc < NFCH; ifc++) {
2336         icrate = calibcrate[ic];
2337         det = "HF";
2338         ihtr_fi = ifb + 1;
2339         ifi_ch = ifc;
2340         (ihtr_fi == 1) ? iphi = 1 : ((ihtr_fi == 2) ? iphi = 19 : ((ihtr_fi == 3) ? iphi = 37 : iphi = 55));
2341         idphi = 18;
2342         ifed = fedcalibnum[ic][idcc - 1];
2343         (ifc == 0) ? ich_type = 8 : (ifc == 1 ? ich_type = 0 : ich_type = 1);
2344         //changed ch_type of fibre channel 0 from 2 to 8, as per HcalCalibDetId specification
2345         irm_fi = 1;
2346         //Wedge has steps of 3, HF(P/M)2,5,8,11
2347         //iwedge=ihtr_fi;
2348         iwedge = 2 + (ifb * 3);
2349         if (itb == 0) {
2350           ispigot = 12;
2351           fpga = "top";
2352           sidesign = 'P';
2353           iside = 1;
2354           ieta = 1;
2355         } else {
2356           ispigot = 13;
2357           fpga = "bot";
2358           sidesign = 'M';
2359           iside = -1;
2360           ieta = -1;
2361         }
2362         subdet = "CALIB_" + det;
2363         snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2364         mystream << tempbuff;
2365         rbx = mystream.str();
2366         mystream.str("");
2367         CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2368                                             ihtr_fi,
2369                                             ispigot,
2370                                             ifed,
2371                                             icrate,
2372                                             ihtr,
2373                                             fpga,
2374                                             det,
2375                                             ieta,
2376                                             iphi,
2377                                             ich_type,
2378                                             iside,
2379                                             idphi,
2380                                             rbx,
2381                                             iwedge,
2382                                             irm_fi,
2383                                             subdet);
2384         CALIBEntries.push_back(caliblmapentry);
2385         LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2386             HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2387 
2388         const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2389         const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2390         if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2391           HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2392       }
2393     }
2394   }
2395 
2396   /*HO calibration channels*/
2397   for (ic = ic + 1; ic < NCALIBCR; ic++) {
2398     icrate = calibcrate[ic];
2399     irm_fi = 1;  // everything other than he is on A
2400     ifed = fedcalibnum[ic][idcc - 1];
2401     /* top and bottom */
2402     for (itb = 0; itb < NTOPBOT; itb++) {
2403       det = detIDCALIB[ic][itb];
2404       /* 4 or 8 fibers used per HTR FPGA */
2405       for (ifb = 0; ifb < nfbr_max[ic][itb]; ifb++) {
2406         if (itb == 1) {
2407           ispigot = 13;
2408           fpga = "bot";
2409         } else {
2410           ispigot = 12;
2411           fpga = "top";
2412         }
2413         ihtr_fi = ifb + 1;
2414         iwedge = calibHOinfo[ic - 10][itb][ifb][0];
2415         ieta = calibHOinfo[ic - 10][itb][ifb][1];
2416         if (ieta < 0) {
2417           iside = -1;
2418           sidesign = 'M';
2419         } else if (ieta > 0) {
2420           iside = 1;
2421           sidesign = 'P';
2422         } else {
2423           iside = 0;
2424           sidesign = '0';
2425         }
2426         if (ieta == -2)
2427           S_side = '2';
2428         else if (ieta == -1)
2429           S_side = '1';
2430         else if (ieta == 1)
2431           S_side = '1';
2432         else if (ieta == 2)
2433           S_side = '2';
2434 
2435         subdet = "CALIB_" + det;
2436         if (ieta == 0)
2437           snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2438         else
2439           snprintf(tempbuff, sizeof tempbuff, "%s%c%c%2.2i", det.c_str(), S_side, sidesign, iwedge);
2440         mystream << tempbuff;
2441         rbx = mystream.str();
2442         mystream.str("");
2443         /* only two channels used in HO per fiber */
2444         //now new information suggests that the third channel is used for x-talk
2445         //but only in some of the rm's, seems to be dependent on whether nfbr_max
2446         //sector 10 on YB+2,1,0,-1, sector 12 on YB-2
2447         int NFCH_HO;
2448         //( nfbr_max[ic][itb] == 4 ) ? NFCH_HO = 2 : NFCH_HO = 3;
2449         (ieta == -2) ? (iwedge == 12 ? NFCH_HO = 3 : NFCH_HO = 2) : (iwedge == 10) ? NFCH_HO = 3 : NFCH_HO = 2;
2450         for (ifc = 0; ifc < NFCH_HO; ifc++) {
2451           ifi_ch = ifc;
2452           (ifi_ch == 2) ? ich_type = 7 : ich_type = ifi_ch;
2453           (ieta == 0) ? idphi = 6 : idphi = 12;
2454 
2455           (ieta == 0) ? iphi = ((iwedge * idphi) + 71 - idphi) % 72 : iphi = (((iwedge / 2) * idphi) + 71 - idphi) % 72;
2456           //nothing on htr_fi=4 for the top
2457           //do {
2458           if (iside == 0 && ifb == 3)
2459             continue;  // adjust logic since no longer inside loop
2460           CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2461                                               ihtr_fi,
2462                                               ispigot,
2463                                               ifed,
2464                                               icrate,
2465                                               ihtr,
2466                                               fpga,
2467                                               det,
2468                                               ieta,
2469                                               iphi,
2470                                               ich_type,
2471                                               iside,
2472                                               idphi,
2473                                               rbx,
2474                                               iwedge,
2475                                               irm_fi,
2476                                               subdet);
2477           CALIBEntries.push_back(caliblmapentry);
2478           LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2479               HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2480 
2481           const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2482           const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2483           if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2484             HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2485           //} while (ifb!=ifb);
2486         }
2487       }
2488     }
2489   }
2490 }
2491 
2492 void HcalLogicalMapGenerator::buildZDCMap(const HcalTopology* topo,
2493                                           std::vector<ZDCLogicalMapEntry>& ZDCEntries,
2494                                           std::vector<uint32_t>& LinearIndex2Entry,
2495                                           std::vector<uint32_t>& ZdcHash2Entry) {
2496   /******************************/
2497   /*ZDC channels*/
2498   //Stream variable
2499   stringstream mystream;
2500 
2501   ifed = 722;
2502   iy = 1;
2503   ihtr = 8;
2504   icrate = 12;
2505   idcc = 1;
2506   idcc_sl = 10;
2507   ispigot = 12;
2508   /* side plus and minus */
2509   for (itb = 0; itb < NTOPBOT; itb++) {
2510     if (itb == 0) {
2511       iside = 1;
2512       irm = 1;
2513       fpga = "top";
2514     } else {
2515       iside = -1;
2516       irm = 2;
2517       if (mapIOV_ < 4) {
2518         fpga = "top";
2519         ispigot = 12;
2520       } else {
2521         fpga = "bot";
2522         ispigot = 13;
2523       }
2524     }
2525     /*loop over ZDC cables*/
2526     for (icab = 1; icab < NZDCCAB + 1; icab++) {
2527       if (icab < 4) {
2528         irm_fi = 1;
2529         iadc = icab - 1;
2530         ifi_ch = iadc;
2531       } else if (icab < 7) {
2532         irm_fi = 2;
2533         iadc = icab - 1;
2534         ifi_ch = iadc - 3;
2535       } else {
2536         irm_fi = 3;
2537         iadc = icab - 7;
2538         ifi_ch = iadc;
2539       }
2540       if (itb == 0) {
2541         ihtr_fi = irm_fi;
2542       } else {
2543         if (mapIOV_ < 4)
2544           ihtr_fi = irm_fi + 3;
2545         else
2546           ihtr_fi = irm_fi;
2547       }
2548       if (icab < 6) {
2549         ix = icab;
2550         idepth = 1;
2551         idx = 1;
2552         det = "ZDC_EM";
2553         idet_ch = ix;
2554         iqie = 1;
2555       } else {
2556         ix = 1;
2557         idepth = icab - 4;
2558         idx = 5;
2559         det = "ZDC_HAD";
2560         idet_ch = icab - 5;
2561         if (icab == 6)
2562           iqie = 1;
2563         else
2564           iqie = 2;
2565       }
2566       ZDCLogicalMapEntry zdclmapentry(ifi_ch,
2567                                       ihtr_fi,
2568                                       ispigot,
2569                                       ifed,
2570                                       icrate,
2571                                       ihtr,
2572                                       fpga,
2573                                       det,
2574                                       iside,
2575                                       idepth,
2576                                       ix,
2577                                       iy,
2578                                       idx,
2579                                       idet_ch,
2580                                       icab,
2581                                       irm,
2582                                       iqie,
2583                                       iadc,
2584                                       irm_fi);
2585       ZDCEntries.push_back(zdclmapentry);
2586       LinearIndex2Entry.at(zdclmapentry.getLinearIndex()) =
2587           HcalLogicalMap::makeEntryNumber(true, 3, ZDCEntries.size() - 1);
2588     }
2589   }
2590 }
2591 
2592 /********************************************************/
2593 void HcalLogicalMapGenerator::ConstructTriggerTower(const HcalTopology* topo,
2594                                                     std::vector<HTLogicalMapEntry>& HTEntries,
2595                                                     int iside,
2596                                                     int ieta,
2597                                                     int iphi,
2598                                                     int idphi,
2599                                                     int idepth,
2600                                                     std::string det,
2601                                                     int iwedge,
2602                                                     int irm,
2603                                                     int ipixel,
2604                                                     int iqie,
2605                                                     int iadc,
2606                                                     int irm_fi,
2607                                                     int ifi_ch,
2608                                                     int icrate,
2609                                                     int ihtr,
2610                                                     std::string fpga,
2611                                                     int ihtr_fi,
2612                                                     int ispigot,
2613                                                     int islb,
2614                                                     std::string slbin,
2615                                                     std::string slbin2,
2616                                                     std::string slnam,
2617                                                     int irctcra,
2618                                                     int irctcar,
2619                                                     int irctcon,
2620                                                     std::string rctnam,
2621                                                     int ifed) {
2622   string t_chDet, t_fpga;
2623   string t_slnam, t_rctnam, t_slbin, t_slbin2;
2624 
2625   int t_nDat = -1;
2626   int t_side, t_iEta, t_iPhi, t_jPhi, t_iDep, t_topbot;
2627   int t_wedge, t_crate, t_htr;
2628   //  int t_rm,t_pixel,t_qie,t_adc,t_rm_fi,t_fi_ch,t_htr_fi;
2629   int t_spigo, t_slb, t_rctcra, t_rctcar, t_rctcon, t_fedid;
2630 
2631   //making global variables local for modification
2632   (fpga == "bot") ? t_topbot = 1 : t_topbot = 0;
2633   t_side = iside;
2634   t_iEta = ieta;
2635   t_iPhi = iphi;
2636   t_jPhi = idphi;
2637   t_iDep = idepth;
2638   t_chDet = det;
2639   t_wedge = iwedge;
2640   //  t_rm     = irm;
2641   //  t_pixel  = ipixel;
2642   //  t_qie    = iqie;
2643   //  t_adc    = iadc;
2644   //  t_rm_fi  = irm_fi;
2645   //  t_fi_ch  = ifi_ch;
2646   t_crate = icrate;
2647   t_htr = ihtr;
2648   t_fpga = fpga;
2649   //  t_htr_fi = ihtr_fi;
2650   t_spigo = ispigot;
2651   t_slb = islb;
2652   t_slbin = slbin;
2653   t_slbin2 = slbin2;
2654   t_slnam = slnam;
2655   t_rctcra = irctcra;
2656   t_rctcar = irctcar;
2657   t_rctcon = irctcon;
2658   t_rctnam = rctnam;
2659   t_fedid = ifed;
2660 
2661   do {
2662     if (t_iDep != 1)
2663       break;
2664     if (t_chDet == "HE" && t_iEta == 29)
2665       break;
2666 
2667     if (t_chDet == "HF") {
2668       t_jPhi = 4;  //20 degree slices in HF
2669       if (t_iEta == 30 || t_iEta == 31 || t_iEta == 33 || t_iEta == 34 || t_iEta == 36 || t_iEta == 37 ||
2670           t_iEta == 39 || t_iEta == 40 || t_iEta == 41)
2671         break;
2672 
2673       else if (t_iEta == 32)
2674         t_iEta = 30;
2675       else if (t_iEta == 35)
2676         t_iEta = 31;
2677       else if (t_iEta == 38)
2678         t_iEta = 32;
2679 
2680       if (t_iPhi == 3 || t_iPhi == 7 || t_iPhi == 11 || t_iPhi == 15 || t_iPhi == 19 || t_iPhi == 23 || t_iPhi == 27 ||
2681           t_iPhi == 31 || t_iPhi == 35 || t_iPhi == 39 || t_iPhi == 43 || t_iPhi == 47 || t_iPhi == 51 ||
2682           t_iPhi == 55 || t_iPhi == 59 || t_iPhi == 63 || t_iPhi == 67 || t_iPhi == 71)
2683         break;
2684     }
2685 
2686     if (t_side < 0)
2687       t_iEta = -t_iEta;
2688     t_chDet = "HT";
2689 
2690     if (t_slbin != "NA") {
2691       if (t_slbin2 != "NA")
2692         t_jPhi = 1;
2693       if (t_slbin == "A0" || t_slbin == "B0")
2694         t_nDat = 0;
2695       else if (t_slbin == "A1" || t_slbin == "B1")
2696         t_nDat = 1;
2697       else if (t_slbin == "C0" || t_slbin == "D0")
2698         t_nDat = 2;
2699       else if (t_slbin == "C1" || t_slbin == "D1")
2700         t_nDat = 3;
2701 
2702       HTLogicalMapEntry htlmapentry(t_iEta,
2703                                     t_iPhi,
2704                                     t_side,
2705                                     t_jPhi,
2706                                     t_iDep,
2707                                     t_chDet,
2708                                     t_wedge,
2709                                     t_crate,
2710                                     t_htr,
2711                                     t_topbot,
2712                                     t_spigo,
2713                                     t_slb,
2714                                     t_slbin,
2715                                     t_slbin2,
2716                                     t_nDat,
2717                                     t_slnam,
2718                                     t_rctcra,
2719                                     t_rctcar,
2720                                     t_rctcon,
2721                                     t_rctnam,
2722                                     t_fedid);
2723       HTEntries.push_back(htlmapentry);
2724     }
2725     if (t_slbin2 != "NA") {
2726       if (t_slbin2 == "A0" || t_slbin2 == "B0")
2727         t_nDat = 0;
2728       else if (t_slbin2 == "A1" || t_slbin2 == "B1")
2729         t_nDat = 1;
2730       else if (t_slbin2 == "C0" || t_slbin2 == "D0")
2731         t_nDat = 2;
2732       else if (t_slbin2 == "C1" || t_slbin2 == "D1")
2733         t_nDat = 3;
2734       t_jPhi = 1;  //after splitting up these towers, each half should have dphi of 1
2735       t_iPhi += 1;
2736 
2737       HTLogicalMapEntry htlmapentry(t_iEta,
2738                                     t_iPhi,  //changed from t_iPhi + 1 here to the spot above
2739                                     t_side,
2740                                     t_jPhi,
2741                                     t_iDep,
2742                                     t_chDet,
2743                                     t_wedge,
2744                                     t_crate,
2745                                     t_htr,
2746                                     t_topbot,
2747                                     t_spigo,
2748                                     t_slb,
2749                                     t_slbin,
2750                                     t_slbin2,
2751                                     t_nDat,
2752                                     t_slnam,
2753                                     t_rctcra,
2754                                     t_rctcar,
2755                                     t_rctcon,
2756                                     t_rctnam,
2757                                     t_fedid);
2758       HTEntries.push_back(htlmapentry);
2759     }
2760   } while (1 != 1);
2761 }