Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:31

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