Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-25 03:22:24

0001 #include "L1Trigger/L1TMuonEndCap/interface/SectorProcessorLUT.h"
0002 
0003 #include <iostream>
0004 #include <fstream>
0005 
0006 #include "FWCore/ParameterSet/interface/FileInPath.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 SectorProcessorLUT::SectorProcessorLUT() : version_(0xFFFFFFFF) {}
0011 
0012 SectorProcessorLUT::~SectorProcessorLUT() {}
0013 
0014 void SectorProcessorLUT::read(bool pc_lut_data, int pc_lut_version) {
0015   if (version_ == pc_lut_version)
0016     return;
0017 
0018   edm::LogInfo("L1T") << "EMTF using pc_lut_ver: " << pc_lut_version << ", configured for "
0019                       << (pc_lut_data ? "data" : "MC");
0020 
0021   std::string coord_lut_dir = "";
0022   if (pc_lut_version == 0)
0023     coord_lut_dir = "ph_lut_v1";  // All year 2016
0024   else if (pc_lut_version == 1)
0025     coord_lut_dir = "ph_lut_v2";  // Beginning of 2017, improved alignment from ideal CMS geometry (MC)
0026   else if (pc_lut_version == 2 && pc_lut_data)
0027     coord_lut_dir = "ph_lut_v3_data";  // Update in September 2017 from ReReco alignment, data only
0028   else if (pc_lut_version == 3 && pc_lut_data)
0029     coord_lut_dir = "ph_lut_Run3_2022_data";  // Update in October 2022 from Run 3 2022 alignment, data only
0030   else if (pc_lut_version == 2)
0031     coord_lut_dir = "ph_lut_v2";  // MC still uses ideal CMS aligment
0032   else if (pc_lut_version == -1 && pc_lut_data)
0033     coord_lut_dir = "ph_lut_v3_data";  // September 2017 data LCT alignment, but use local CPPF LUTs for RPC
0034   else if (pc_lut_version == -1)
0035     coord_lut_dir = "ph_lut_v2";  // MC using ideal CMS LCT alignment, but use local CPPF LUTs for RPC
0036   else
0037     throw cms::Exception("L1TMuonEndCap")
0038         << "Trying to use EMTF pc_lut_version = " << pc_lut_version << ", does not exist!";
0039   // Will catch user trying to run with Global Tag settings on 2016 data, rather than fakeEmtfParams. - AWB 08.06.17
0040 
0041   std::string coord_lut_path = "L1Trigger/L1TMuon/data/emtf_luts/" + coord_lut_dir + "/";
0042 
0043   read_file(coord_lut_path + "ph_init_neighbor.txt", ph_init_neighbor_);
0044   read_file(coord_lut_path + "ph_disp_neighbor.txt", ph_disp_neighbor_);
0045   read_file(coord_lut_path + "th_init_neighbor.txt", th_init_neighbor_);
0046   read_file(coord_lut_path + "th_disp_neighbor.txt", th_disp_neighbor_);
0047   read_file(coord_lut_path + "th_lut_neighbor.txt", th_lut_neighbor_);
0048   read_file(coord_lut_path + "th_corr_lut_neighbor.txt", th_corr_lut_neighbor_);
0049 
0050   std::string cppf_coord_lut_path = "L1Trigger/L1TMuon/data/cppf/";  // Coordinate LUTs actually used by CPPF
0051   bool use_local_cppf_files = (pc_lut_version == -1);
0052   if (use_local_cppf_files) {  // More accurate coordinate transformation LUTs from Jia Fu
0053     cppf_coord_lut_path = "L1Trigger/L1TMuon/data/cppf_luts/angleScale_v1/";
0054   }
0055 
0056   read_cppf_file(cppf_coord_lut_path,
0057                  cppf_ph_lut_,
0058                  cppf_th_lut_,
0059                  use_local_cppf_files);  // cppf filenames are hardcoded in the function
0060 
0061   if (ph_init_neighbor_.size() != 2 * 6 * 61) {  // [endcap_2][sector_6][chamber_61]
0062     throw cms::Exception("L1TMuonEndCap") << "Expected ph_init_neighbor_ to get " << 2 * 6 * 61 << " values, "
0063                                           << "got " << ph_init_neighbor_.size() << " values.";
0064   }
0065 
0066   if (ph_disp_neighbor_.size() != 2 * 6 * 61) {  // [endcap_2][sector_6][chamber_61]
0067     throw cms::Exception("L1TMuonEndCap") << "Expected ph_disp_neighbor_ to get " << 2 * 6 * 61 << " values, "
0068                                           << "got " << ph_disp_neighbor_.size() << " values.";
0069   }
0070 
0071   if (th_init_neighbor_.size() != 2 * 6 * 61) {  // [endcap_2][sector_6][chamber_61]
0072     throw cms::Exception("L1TMuonEndCap") << "Expected th_init_neighbor_ to get " << 2 * 6 * 61 << " values, "
0073                                           << "got " << th_init_neighbor_.size() << " values.";
0074   }
0075 
0076   if (th_disp_neighbor_.size() != 2 * 6 * 61) {  // [endcap_2][sector_6][chamber_61]
0077     throw cms::Exception("L1TMuonEndCap") << "Expected th_disp_neighbor_ to get " << 2 * 6 * 61 << " values, "
0078                                           << "got " << th_disp_neighbor_.size() << " values.";
0079   }
0080 
0081   if (th_lut_neighbor_.size() != 2 * 6 * 61 * 128) {  // [endcap_2][sector_6][chamber_61][wire_128]
0082     throw cms::Exception("L1TMuonEndCap") << "Expected th_lut_neighbor_ to get " << 2 * 6 * 61 * 128 << " values, "
0083                                           << "got " << th_lut_neighbor_.size() << " values.";
0084   }
0085 
0086   if (th_corr_lut_neighbor_.size() != 2 * 6 * 7 * 128) {  // [endcap_2][sector_6][chamber_61][strip_wire_128]
0087     throw cms::Exception("L1TMuonEndCap") << "Expected th_corr_lut_neighbor_ to get " << 2 * 6 * 7 * 128 << " values, "
0088                                           << "got " << th_corr_lut_neighbor_.size() << " values.";
0089   }
0090 
0091   if (cppf_ph_lut_.size() !=
0092       2 * 6 * 6 * 6 * 3 *
0093           64) {  // [endcap_2][rpc_sector_6][rpc_station_ring_6][rpc_subsector_6][rpc_roll_3][rpc_halfstrip_64]
0094     throw cms::Exception("L1TMuonEndCap") << "Expected cppf_ph_lut_ to get " << 2 * 6 * 6 * 6 * 3 * 64 << " values, "
0095                                           << "got " << cppf_ph_lut_.size() << " values.";
0096   }
0097 
0098   if (cppf_th_lut_.size() !=
0099       2 * 6 * 6 * 6 * 3) {  // [endcap_2][rpc_sector_6][rpc_station_ring_6][rpc_subsector_6][rpc_roll_3]
0100     throw cms::Exception("L1TMuonEndCap") << "Expected cppf_th_lut_ to get " << 2 * 6 * 6 * 6 * 3 << " values, "
0101                                           << "got " << cppf_th_lut_.size() << " values.";
0102   }
0103 
0104   // clct pattern convertion array from CMSSW
0105   //{0.0, 0.0, -0.60,  0.60, -0.64,  0.64, -0.23,  0.23, -0.21,  0.21, 0.0}
0106   // 0    0    -5      +5    -5      +5    -2      +2    -2      +2    0
0107   ph_patt_corr_ = {0, 0, 5, 5, 5, 5, 2, 2, 2, 2, 0};
0108   if (ph_patt_corr_.size() != 11) {
0109     throw cms::Exception("L1TMuonEndCap") << "Expected ph_patt_corr_ to get " << 11 << " values, "
0110                                           << "got " << ph_patt_corr_.size() << " values.";
0111   }
0112 
0113   ph_patt_corr_sign_ = {0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0};
0114   if (ph_patt_corr_sign_.size() != 11) {
0115     throw cms::Exception("L1TMuonEndCap") << "Expected ph_patt_corr_sign_ to get " << 11 << " values, "
0116                                           << "got " << ph_patt_corr_sign_.size() << " values.";
0117   }
0118 
0119   ph_zone_offset_ = {39, 57, 76,  39, 58, 76, 41, 60,  79,  95, 114, 132, 95, 114, 133, 98, 116, 135,
0120                      38, 76, 113, 39, 58, 76, 95, 114, 132, 38, 76,  113, 39, 58,  76,  95, 114, 132,
0121                      38, 76, 113, 38, 57, 76, 95, 113, 132, 21, 21,  23,  1,  21,  1,   21, 1,   20};
0122   if (ph_zone_offset_.size() != 6 * 9) {
0123     throw cms::Exception("L1TMuonEndCap") << "Expected ph_zone_offset_ to get " << 6 * 9 << " values, "
0124                                           << "got " << ph_zone_offset_.size() << " values.";
0125   }
0126 
0127   // start phi of each chamber in reduced precision, for zone hits,
0128   // with negative offset to allow for possible chamber movement
0129   ph_init_hard_ = {39,  57,  76, 39,  58,  76, 41,  60,  79, 39, 57,  76,  21,  21, 23,  21,  95,  114, 132, 95,
0130                    114, 133, 98, 116, 135, 95, 114, 132, 0,  0,  0,   0,   38,  76, 113, 39,  58,  76,  95,  114,
0131                    132, 1,   21, 0,   0,   0,  0,   0,   38, 76, 113, 39,  58,  76, 95,  114, 132, 1,   21,  0,
0132                    0,   0,   0,  0,   38,  76, 113, 38,  57, 76, 95,  113, 132, 1,  20,  0,   0,   0,   0,   0};
0133   if (ph_init_hard_.size() != 5 * 16) {
0134     throw cms::Exception("L1TMuonEndCap") << "Expected ph_init_hard_ to get " << 5 * 16 << " values, "
0135                                           << "got " << ph_init_hard_.size() << " values.";
0136   }
0137 
0138   version_ = pc_lut_version;
0139   return;
0140 }
0141 
0142 uint32_t SectorProcessorLUT::get_ph_init(int fw_endcap, int fw_sector, int pc_lut_id) const {
0143   const uint32_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
0144   uint32_t entry = 0;
0145 
0146   if (index < ph_init_neighbor_.size()) {
0147     entry = ph_init_neighbor_.at(index);
0148   } else {
0149     edm::LogError("L1T") << "Could not retrieve entry from LUT. fw_endcap: " << fw_endcap
0150                          << ", fw_sector: " << fw_sector << ", pc_lut_id: " << pc_lut_id;
0151   }
0152   return entry;
0153 }
0154 
0155 uint32_t SectorProcessorLUT::get_ph_disp(int fw_endcap, int fw_sector, int pc_lut_id) const {
0156   const uint32_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
0157   uint32_t entry = 0;
0158 
0159   if (index < ph_disp_neighbor_.size()) {
0160     entry = ph_disp_neighbor_.at(index);
0161   } else {
0162     edm::LogError("L1T") << "Could not retrieve entry from LUT. fw_endcap: " << fw_endcap
0163                          << ", fw_sector: " << fw_sector << ", pc_lut_id: " << pc_lut_id;
0164   }
0165   return entry;
0166 }
0167 
0168 uint32_t SectorProcessorLUT::get_th_init(int fw_endcap, int fw_sector, int pc_lut_id) const {
0169   const uint32_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
0170   uint32_t entry = 0;
0171 
0172   if (index < th_init_neighbor_.size()) {
0173     entry = th_init_neighbor_.at(index);
0174   } else {
0175     edm::LogError("L1T") << "Could not retrieve entry from LUT. fw_endcap: " << fw_endcap
0176                          << ", fw_sector: " << fw_sector << ", pc_lut_id: " << pc_lut_id;
0177   }
0178   return entry;
0179 }
0180 
0181 uint32_t SectorProcessorLUT::get_th_disp(int fw_endcap, int fw_sector, int pc_lut_id) const {
0182   const uint32_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
0183   uint32_t entry = 0;
0184 
0185   if (index < th_disp_neighbor_.size()) {
0186     entry = th_disp_neighbor_.at(index);
0187   } else {
0188     edm::LogError("L1T") << "Could not retrieve entry from LUT. fw_endcap: " << fw_endcap
0189                          << ", fw_sector: " << fw_sector << ", pc_lut_id: " << pc_lut_id;
0190   }
0191   return entry;
0192 }
0193 
0194 uint32_t SectorProcessorLUT::get_th_lut(int fw_endcap, int fw_sector, int pc_lut_id, int pc_wire_id) const {
0195   int pc_lut_id2 = pc_lut_id;
0196 
0197   // Make ME1/1a the same as ME1/1b
0198   if ((9 <= pc_lut_id2 && pc_lut_id2 < 12) || (25 <= pc_lut_id2 && pc_lut_id2 < 28))
0199     pc_lut_id2 -= 9;
0200   // Make ME1/1a neighbor the same as ME1/1b
0201   if (pc_lut_id2 == 15)
0202     pc_lut_id2 -= 3;
0203 
0204   const uint32_t index = ((fw_endcap * 6 + fw_sector) * 61 + pc_lut_id2) * 128 + pc_wire_id;
0205   uint32_t entry = 0;
0206 
0207   if (index < th_lut_neighbor_.size()) {
0208     entry = th_lut_neighbor_.at(index);
0209   } else {
0210     edm::LogError("L1T") << "Could not retrieve entry from LUT. fw_endcap: " << fw_endcap
0211                          << ", fw_sector: " << fw_sector << ", pc_lut_id: " << pc_lut_id
0212                          << ", pc_wire_id: " << pc_wire_id;
0213   }
0214   return entry;
0215 }
0216 
0217 uint32_t SectorProcessorLUT::get_th_corr_lut(int fw_endcap, int fw_sector, int pc_lut_id, int pc_wire_strip_id) const {
0218   int pc_lut_id2 = pc_lut_id;
0219 
0220   // Make ME1/1a the same as ME1/1b
0221   if ((9 <= pc_lut_id2 && pc_lut_id2 < 12) || (25 <= pc_lut_id2 && pc_lut_id2 < 28))
0222     pc_lut_id2 -= 9;
0223   // Make ME1/1a neighbor the same as ME1/1b
0224   if (pc_lut_id2 == 15)
0225     pc_lut_id2 -= 3;
0226 
0227   if (pc_lut_id2 <= 3) {
0228     pc_lut_id2 -= 0;
0229   } else if (pc_lut_id2 == 12) {
0230     pc_lut_id2 -= 9;
0231   } else if (16 <= pc_lut_id2 && pc_lut_id2 < 19) {
0232     pc_lut_id2 -= 12;
0233   } else {
0234     edm::LogError("L1T") << "get_th_corr_lut(): out of range pc_lut_id: " << pc_lut_id;
0235   }
0236 
0237   const uint32_t index = ((fw_endcap * 6 + fw_sector) * 7 + pc_lut_id2) * 128 + pc_wire_strip_id;
0238   uint32_t entry = 0;
0239 
0240   if (index < th_corr_lut_neighbor_.size()) {
0241     entry = th_corr_lut_neighbor_.at(index);
0242   } else {
0243     edm::LogError("L1T") << "Could not retrieve entry from LUT. fw_endcap: " << fw_endcap
0244                          << ", fw_sector: " << fw_sector << ", pc_lut_id: " << pc_lut_id
0245                          << ", pc_wire_strip_id: " << pc_wire_strip_id;
0246   }
0247   return entry;
0248 }
0249 
0250 uint32_t SectorProcessorLUT::get_ph_patt_corr(int pattern) const {
0251   const uint32_t index = pattern;
0252   uint32_t entry = 0;
0253 
0254   if (index < ph_patt_corr_.size()) {
0255     entry = ph_patt_corr_.at(index);
0256   } else {
0257     edm::LogError("L1T") << "Could not retrieve entry from LUT. pattern: " << pattern;
0258   }
0259   return entry;
0260 }
0261 
0262 uint32_t SectorProcessorLUT::get_ph_patt_corr_sign(int pattern) const {
0263   const uint32_t index = pattern;
0264   uint32_t entry = 0;
0265 
0266   if (index < ph_patt_corr_sign_.size()) {
0267     entry = ph_patt_corr_sign_.at(index);
0268   } else {
0269     edm::LogError("L1T") << "Could not retrieve entry from LUT. pattern: " << pattern;
0270   }
0271   return entry;
0272 }
0273 
0274 uint32_t SectorProcessorLUT::get_ph_zone_offset(int pc_station, int pc_chamber) const {
0275   const uint32_t index = pc_station * 9 + pc_chamber;
0276   uint32_t entry = 0;
0277 
0278   if (index < ph_zone_offset_.size()) {
0279     entry = ph_zone_offset_.at(index);
0280   } else {
0281     edm::LogError("L1T") << "Could not retrieve entry from LUT. pc_station: " << pc_station
0282                          << ", pc_chamber: " << pc_chamber;
0283   }
0284   return entry;
0285 }
0286 
0287 uint32_t SectorProcessorLUT::get_ph_init_hard(int fw_station, int fw_cscid) const {
0288   const uint32_t index = fw_station * 16 + fw_cscid;
0289   uint32_t entry = 0;
0290 
0291   if (index < ph_init_hard_.size()) {
0292     entry = ph_init_hard_.at(index);
0293   } else {
0294     edm::LogError("L1T") << "Could not retrieve entry from LUT. fw_station: " << fw_station
0295                          << ", fw_cscid: " << fw_cscid;
0296   }
0297   return entry;
0298 }
0299 
0300 uint32_t SectorProcessorLUT::get_cppf_lut_id(
0301     int rpc_region, int rpc_sector, int rpc_station, int rpc_ring, int rpc_subsector, int rpc_roll) const {
0302   uint32_t iendcap = (rpc_region == -1) ? 1 : 0;
0303   uint32_t isector = (rpc_sector - 1);
0304   uint32_t istationring = (rpc_station >= 3) ? ((rpc_station - 3) * 2 + (rpc_ring - 2) + 2) : (rpc_station - 1);
0305   uint32_t isubsector = (rpc_subsector - 1);
0306   uint32_t iroll = (rpc_roll - 1);
0307   return ((((iendcap * 6 + isector) * 6 + istationring) * 6 + isubsector) * 3 + iroll);
0308 }
0309 
0310 uint32_t SectorProcessorLUT::get_cppf_ph_lut(int rpc_region,
0311                                              int rpc_sector,
0312                                              int rpc_station,
0313                                              int rpc_ring,
0314                                              int rpc_subsector,
0315                                              int rpc_roll,
0316                                              int halfstrip,
0317                                              bool is_neighbor) const {
0318   const uint32_t th_index = get_cppf_lut_id(rpc_region, rpc_sector, rpc_station, rpc_ring, rpc_subsector, rpc_roll);
0319   const uint32_t ph_index = (th_index * 64) + (halfstrip - 1);
0320   uint32_t ph = 0;
0321 
0322   if (ph_index < cppf_ph_lut_.size()) {
0323     ph = cppf_ph_lut_.at(ph_index);
0324   } else {
0325     edm::LogError("L1T") << "Could not retrieve entry from LUT. rpc_region: " << rpc_region
0326                          << ", rpc_sector: " << rpc_sector << ", rpc_station: " << rpc_station
0327                          << ", rpc_ring: " << rpc_ring << ", rpc_subsector: " << rpc_subsector
0328                          << ", rpc_roll: " << rpc_roll << ", halfstrip: " << halfstrip
0329                          << ", is_neighbor: " << is_neighbor;
0330   }
0331 
0332   if (!is_neighbor && rpc_subsector == 2)
0333     ph += 900;
0334   return ph;
0335 }
0336 
0337 uint32_t SectorProcessorLUT::get_cppf_th_lut(
0338     int rpc_region, int rpc_sector, int rpc_station, int rpc_ring, int rpc_subsector, int rpc_roll) const {
0339   const uint32_t th_index = get_cppf_lut_id(rpc_region, rpc_sector, rpc_station, rpc_ring, rpc_subsector, rpc_roll);
0340   uint32_t th = 0;
0341 
0342   if (th_index < cppf_th_lut_.size()) {
0343     th = cppf_th_lut_.at(th_index);
0344   } else {
0345     edm::LogError("L1T") << "Could not retrieve entry from LUT. rpc_region: " << rpc_region
0346                          << ", rpc_sector: " << rpc_sector << ", rpc_station: " << rpc_station
0347                          << ", rpc_ring: " << rpc_ring << ", rpc_subsector: " << rpc_subsector
0348                          << ", rpc_roll: " << rpc_roll;
0349   }
0350   return th;
0351 }
0352 
0353 void SectorProcessorLUT::read_file(const std::string& filename, std::vector<uint32_t>& vec) {
0354   vec.clear();
0355 
0356   std::ifstream infile;
0357   infile.open(edm::FileInPath(filename).fullPath().c_str());
0358 
0359   int buf;
0360   while (infile >> buf) {
0361     buf = (buf == -999) ? 0 : buf;
0362     vec.push_back(buf);
0363   }
0364   infile.close();
0365 }
0366 
0367 void SectorProcessorLUT::read_cppf_file(const std::string& filename,
0368                                         std::vector<uint32_t>& vec1,
0369                                         std::vector<uint32_t>& vec2,
0370                                         bool local) {
0371   auto get_rpc_region = [](uint32_t id) { return (static_cast<int>((id >> 0) & 0X3) + (-1)); };
0372   auto get_rpc_sector = [](uint32_t id) { return (static_cast<int>((id >> 7) & 0XF) + (1)); };
0373   auto get_rpc_ring = [](uint32_t id) { return (static_cast<int>((id >> 2) & 0X7) + (1)); };
0374   auto get_rpc_station = [](uint32_t id) { return (static_cast<int>((id >> 5) & 0X3) + (1)); };
0375   auto get_rpc_subsector = [](uint32_t id) { return (static_cast<int>((id >> 12) & 0X7) + (1)); };
0376   auto get_rpc_roll = [](uint32_t id) { return (static_cast<int>((id >> 15) & 0X7) + (0)); };
0377 
0378   std::vector<std::string> cppf_filenames = {
0379       "angleScale_RPC_CPPFp1.txt",
0380       "angleScale_RPC_CPPFp2.txt",
0381       "angleScale_RPC_CPPFp3.txt",
0382       "angleScale_RPC_CPPFp4.txt",
0383       "angleScale_RPC_CPPFn1.txt",
0384       "angleScale_RPC_CPPFn2.txt",
0385       "angleScale_RPC_CPPFn3.txt",
0386       "angleScale_RPC_CPPFn4.txt",
0387   };
0388 
0389   vec1.clear();
0390   vec2.clear();
0391   vec1.resize(2 * 6 * 6 * 6 * 3 * 64, 0);
0392   vec2.resize(2 * 6 * 6 * 6 * 3, 0);
0393 
0394   for (size_t i = 0; i < cppf_filenames.size(); ++i) {
0395     std::ifstream infile;
0396     infile.open(edm::FileInPath(filename + cppf_filenames.at(i)).fullPath().c_str());
0397 
0398     // std::cout << "\n\nOpening CPPF LUT file " << cppf_filenames.at(i) << std::endl;
0399 
0400     int buf1, buf2, buf3, buf4, buf5, buf6;
0401     // Special variables for transforming centrally-provided CPPF LUTs
0402     int buf1_prev = 0, buf2_prev = 0, halfstrip_prev = 0;  // Values from previous line in file
0403     int line_num = 0;                                      // Line number in file
0404     int count_dir = -1;                                    // Direction of half-strip counting: +1 is up, -1 is down
0405     int dStrip = 0;                                        // Offset for half-strip from full strip
0406     while ((infile >> buf1) && (infile >> buf2) && (infile >> buf3) && (infile >> buf4) && (infile >> buf5) &&
0407            (infile >> buf6)) {
0408       if ((line_num % 192) == 191)
0409         line_num += 1;  // Gap in central files vs. Jia Fu's files
0410       line_num += 1;
0411       // On roughly every-other line, files in L1Trigger/L1TMuon/data/cppf have 0 in the first three columns
0412       // Skips a "0 0 0" line once every 192 lines
0413       if ((line_num % 2) == 1) {
0414         buf1_prev = buf1;
0415         buf2_prev = buf2;
0416       }
0417 
0418       if (local && (buf1 == 0 || buf2 == 0)) {
0419         throw cms::Exception("L1TMuonEndCap") << "Expected non-0 values, got buf1 = " << buf1 << ", buf2 = " << buf2;
0420       }
0421       if (!local && (buf1_prev == 0 || buf2_prev == 0)) {
0422         throw cms::Exception("L1TMuonEndCap")
0423             << "Expected non-0 values, got buf1_prev = " << buf1_prev << ", buf2_prev = " << buf2_prev;
0424       }
0425 
0426       uint32_t id = (local ? buf1 : buf1_prev);
0427       int32_t rpc_region = get_rpc_region(id);
0428       int32_t rpc_sector = get_rpc_sector(id);
0429       int32_t rpc_station = get_rpc_station(id);
0430       int32_t rpc_ring = get_rpc_ring(id);
0431       int32_t rpc_subsector = get_rpc_subsector(id);
0432       int32_t rpc_roll = get_rpc_roll(id);
0433 
0434       // Offset into halfstrips from centrally-provided LUTs
0435       if (buf2_prev * 2 > halfstrip_prev + 8 ||
0436           buf2_prev * 2 < halfstrip_prev - 8) {  // Starting a new series of strips
0437         if (buf2_prev == 1)
0438           count_dir = +1;  // Starting from a low number, counting up
0439         else
0440           count_dir = -1;  // Starting from a high number, counting down
0441       }
0442       if (count_dir == -1)
0443         dStrip = (buf2_prev * 2 == halfstrip_prev ? 1 : 0);
0444       if (count_dir == +1)
0445         dStrip = (buf2_prev * 2 == halfstrip_prev + 2 ? 1 : 0);
0446       if (buf2_prev * 2 < halfstrip_prev - 8 && buf2_prev == 1)
0447         dStrip = 1;
0448 
0449       //uint32_t strip        = buf2;
0450       uint32_t halfstrip =
0451           (local ? buf2
0452                  : buf2_prev * 2 -
0453                        dStrip);  // I modified the local text files to use 'halfstrip' instead of 'strip' in column 2
0454       halfstrip_prev = halfstrip;
0455 
0456       uint32_t ph = buf5;
0457       uint32_t th = buf6;
0458 
0459       const uint32_t th_index = get_cppf_lut_id(rpc_region, rpc_sector, rpc_station, rpc_ring, rpc_subsector, rpc_roll);
0460       const uint32_t ph_index = (th_index * 64) + (halfstrip - 1);
0461 
0462       // std::cout << id << " " << rpc_region << " " << rpc_sector << " " << rpc_station << " " << rpc_ring << " "
0463       //    << rpc_subsector << " " << rpc_roll << " " << halfstrip << " " << th_index << " " << ph_index << std::endl;
0464 
0465       vec1.at(ph_index) = ph;
0466       if (halfstrip == 1)
0467         vec2.at(th_index) = th;
0468 
0469       // Fill gap in centrally-provided LUTs once every 192 lines
0470       if (!local && (line_num % 192) == 191)
0471         vec1.at(ph_index + 1) = ph;
0472 
0473     }  // End while ((infile >> buf1) && ... && (infile >> buf6))
0474     infile.close();
0475   }  // End loop over CPPF LUT files
0476 }