diff --git a/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/L1TopoLUT.h b/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/L1TopoLUT.h index 598a5f69334e09d42caa4df26f616e92b3a829be..1601fa025054f6df2e8378790479c535ffc5c90b 100644 --- a/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/L1TopoLUT.h +++ b/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/L1TopoLUT.h @@ -20,14 +20,20 @@ namespace LVL1MUCTPIPHASE1 struct L1TopoCoordinates { - double eta; - double phi; - double eta_min; - double eta_max; - double phi_min; - double phi_max; - unsigned short ieta; - unsigned short iphi; + bool operator==(const L1TopoCoordinates& rhs) const + { + return (eta == rhs.eta && phi == rhs.phi && + eta_min == rhs.eta_min && phi_min == rhs.phi_min && + ieta == rhs.ieta && iphi == rhs.iphi); + } + double eta=0; + double phi=0; + double eta_min=0; + double eta_max=0; + double phi_min=0; + double phi_max=0; + unsigned short ieta=0; + unsigned short iphi=0; }; class L1TopoLUT @@ -44,16 +50,16 @@ namespace LVL1MUCTPIPHASE1 const unsigned short& sectorID, const unsigned short& roi) const; - std::set<std::string> getErrors() const {return m_errors;} + std::vector<std::string> getErrors() const {return m_errors;} protected: bool initializeLUT(const std::string& inFileName, const bool& isBarrel); - bool initializeJSON(const std::string& inFileName, const bool& side); + bool initializeJSON(const std::string& inFileName, bool side); bool initializeJSONForSubsystem(pt::ptree& root, const std::string& nodeName, - const bool& side, - const unsigned short& subsystem); + bool side, + unsigned short subsystem); struct L1TopoLUTKey { @@ -91,7 +97,7 @@ namespace LVL1MUCTPIPHASE1 }; std::unordered_map<L1TopoLUTKey, L1TopoCoordinates, L1TopoLUTKeyHasher> m_encoding; - std::set<std::string> m_errors; + std::vector<std::string> m_errors; }; } diff --git a/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/SimController.h b/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/SimController.h index 8c506de2cf7a381dbb71d914babf33d93ea6189c..826acfb90031185690935797f10ab21d5551ce74 100644 --- a/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/SimController.h +++ b/Trigger/TrigT1/TrigT1MuctpiPhase1/TrigT1MuctpiPhase1/SimController.h @@ -34,10 +34,10 @@ namespace LVL1MUCTPIPHASE1 { SimController(); ~SimController(); - void configureTopo(const std::string& barrelFileName, - const std::string& ecfFileName, - const std::string& side0LUTFileName, - const std::string& side1LUTFileName); + std::vector<std::string> configureTopo(const std::string& barrelFileName, + const std::string& ecfFileName, + const std::string& side0LUTFileName, + const std::string& side1LUTFileName); std::string processData(LVL1MUONIF::Lvl1MuCTPIInputPhase1* input, int bcid=0); void setConfiguration( const Configuration& conf ); diff --git a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/L1TopoLUT.cxx b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/L1TopoLUT.cxx index c7b4f41f6762187087a8949e0734f20d49ae7aa0..4a53599f9d76430dbedeede1379b545415b228aa 100644 --- a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/L1TopoLUT.cxx +++ b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/L1TopoLUT.cxx @@ -3,6 +3,8 @@ #include <boost/property_tree/json_parser.hpp> #include <fstream> +#include <map> +#include <iostream> namespace LVL1MUCTPIPHASE1 { @@ -23,14 +25,18 @@ namespace LVL1MUCTPIPHASE1 success = success && initializeLUT(ecfFileName, false); //read the json files - success = success && initializeJSON(side0LUTFileName, 0); - success = success && initializeJSON(side1LUTFileName, 1); + //(the input labels are swapped between A-side and C-side) + success = success && initializeJSON(side1LUTFileName, 0); + success = success && initializeJSON(side0LUTFileName, 1); return success; } bool L1TopoLUT::initializeLUT(const std::string& inFileName, const bool& isBarrel) { + //map between L1TopoLUTKey -> map between eta/phi -> index + std::unordered_map<L1TopoLUTKey, std::map<float, unsigned short>, L1TopoLUTKeyHasher> sector_eta_indices, sector_phi_indices; + std::ifstream inFile(inFileName.c_str()); if (!inFile) return false; while (!inFile.eof() && inFile.good()) @@ -63,11 +69,34 @@ namespace LVL1MUCTPIPHASE1 double eta = (eta_max+eta_min)/2.; double phi = (phi_max+phi_min)/2.; + L1TopoLUTKey key_no_roi = {side, subsystem, sectorID, 0}; + + //hold the eta and phi indices in memory + std::map<float, unsigned short>* eta_indices = §or_eta_indices[key_no_roi]; + unsigned short eta_index = 0; + auto eta_itr = eta_indices->find(float(eta)); + if (eta_itr != eta_indices->end()) eta_index = eta_itr->second; + else + { + eta_index = eta_indices->size(); + (*eta_indices)[float(eta)] = eta_index; + } + + std::map<float, unsigned short>* phi_indices = §or_phi_indices[key_no_roi]; + unsigned short phi_index = 0; + auto phi_itr = phi_indices->find(float(phi)); + if (phi_itr != phi_indices->end()) phi_index = phi_itr->second; + else + { + phi_index = phi_indices->size(); + (*phi_indices)[float(phi)] = phi_index; + } + L1TopoLUTKey key = {side, subsystem, sectorID, roi}; - L1TopoCoordinates value = {eta, phi, eta_min, eta_max, phi_min, phi_max, 0, 0}; + L1TopoCoordinates value = {eta, phi, eta_min, eta_max, phi_min, phi_max, eta_index, phi_index}; if (m_encoding.find(key) != m_encoding.end()) { - m_errors.insert("Duplicate key found in L1TopoLUT: "+key.info()); + m_errors.push_back("Duplicate key found in L1TopoLUT: "+key.info()); return false; } m_encoding[key] = value; @@ -76,7 +105,7 @@ namespace LVL1MUCTPIPHASE1 return true; } - bool L1TopoLUT::initializeJSON(const std::string& inFileName, const bool& side) + bool L1TopoLUT::initializeJSON(const std::string& inFileName, bool side) { // Create a root pt::ptree root; @@ -85,19 +114,18 @@ namespace LVL1MUCTPIPHASE1 pt::read_json(inFileName.c_str(), root); - // Supplement the L1TopoCoordinates with the eta/phi indices for each subsystem + // Supplement the L1TopoCoordinates with the eta/phi indices for the barrel. + // These are calculated on-the-fly for the endcap/forward. bool success = true; success = success && initializeJSONForSubsystem(root, "encode_lookup_barrel", side, 0); - success = success && initializeJSONForSubsystem(root, "encode_lookup_endcap", side, 1); - success = success && initializeJSONForSubsystem(root, "encode_lookup_forward", side, 2); return success; } bool L1TopoLUT::initializeJSONForSubsystem(pt::ptree& root, const std::string& nodeName, - const bool& side, - const unsigned short& subsystem) + bool side, + unsigned short subsystem) { for (pt::ptree::value_type& sectorID_elem : root.get_child(nodeName)) { @@ -109,16 +137,19 @@ namespace LVL1MUCTPIPHASE1 for (pt::ptree::value_type& code_elem : roi_elem.second) codes.push_back(code_elem.second.get_value<unsigned short>()); if (codes.size() != 2) { - m_errors.insert("Invalide eta/phi code size"); + m_errors.push_back("Invalide eta/phi code size"); return false; } L1TopoLUTKey key = {(unsigned short)(side), subsystem, sectorID, roi}; auto itr = m_encoding.find(key); if (itr == m_encoding.end()) { - m_errors.insert("Couldn't find L1TopoLUTKey when reading JSON files"); + std::stringstream err; + err << "Couldn't find L1TopoLUTKey when reading JSON files: Node = " << nodeName << ", side = " << side << ", subsystem = " << subsystem << ", sector = " << sectorID << ", roi = " << roi; + m_errors.push_back(err.str()); return false; } + itr->second.ieta = codes[0]; itr->second.iphi = codes[1]; } @@ -135,7 +166,7 @@ namespace LVL1MUCTPIPHASE1 auto itr = m_encoding.find(key); if (itr == m_encoding.end()) { - L1TopoCoordinates null = {0, 0, 0, 0, 0, 0, 0, 0}; + L1TopoCoordinates null; return null; } diff --git a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MUCTPI_AthTool.cxx b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MUCTPI_AthTool.cxx index d16c81d2cdf785ea4a23c0f61c99d49a861f09f4..1c4bd58c748a3220ebc8129c4ff5ef0bb1e3a2ed 100644 --- a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MUCTPI_AthTool.cxx +++ b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MUCTPI_AthTool.cxx @@ -135,14 +135,29 @@ namespace LVL1MUCTPIPHASE1 { } //initialize MSP ROI configuration + + const std::string barrelFileName = PathResolverFindCalibFile( m_barrelRoIFile ); const std::string ecfFileName = PathResolverFindCalibFile( m_ecfRoIFile ); const std::string side0LUTFileName = PathResolverFindCalibFile( m_side0LUTFile ); const std::string side1LUTFileName = PathResolverFindCalibFile( m_side1LUTFile ); - m_theMuctpi->configureTopo(barrelFileName, - ecfFileName, - side0LUTFileName, - side1LUTFileName); + ATH_MSG_INFO("Initializing L1Topo decoding with the following inputs"); + ATH_MSG_INFO(" Barrel file: " << barrelFileName); + ATH_MSG_INFO(" EC/Fwd file: " << ecfFileName); + ATH_MSG_INFO(" Side 0 LUT: " << side0LUTFileName); + ATH_MSG_INFO(" Side 1 LUT: " << side1LUTFileName); + std::vector<std::string> topo_errors = m_theMuctpi->configureTopo(barrelFileName, + ecfFileName, + side0LUTFileName, + side1LUTFileName); + if (topo_errors.size()) + { + std::stringstream err; + err << "Couldn't initialize L1Topo eta/phi encoding/decoding:\n"; + for (unsigned i=0;i<topo_errors.size();i++) err << topo_errors[i] << "\n"; + REPORT_ERROR( StatusCode::FAILURE ) << err.str(); + return StatusCode::FAILURE; + } // // Set up the overlap handling of the simulation: diff --git a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MuonSectorProcessor.cxx b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MuonSectorProcessor.cxx index ca4b7d104218dd085de8788456ed8dd27c59b56f..5483a734e7198648c4d808ae14bc4ecb374def7e 100644 --- a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MuonSectorProcessor.cxx +++ b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/MuonSectorProcessor.cxx @@ -411,7 +411,15 @@ namespace LVL1MUCTPIPHASE1 { int ptword = sectorData->pt(icand); if (ptword < 0) continue; - L1TopoCoordinates coord = m_l1topoLUT->getCoordinates(isub, isec, isys, roiID); + L1TopoCoordinates coord = m_l1topoLUT->getCoordinates(isub, isys, isec, roiID); + + //check for invalid decoding + if (coord == L1TopoCoordinates()) + { + std::stringstream err; + err << "Couldn't decode L1Topo coordinates: Side = " << isub << ", subsystem = " << isys << ", sector = " << isec << ", roi = " << roiID; + return err.str(); + } int ptValue = 0; auto enc = m_ptEncoding[isub].find(ptword); diff --git a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/SimController.cxx b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/SimController.cxx index 8ae0b6ab6e55436d1fcfcdab0290056bbec2fd2b..2d59c98552cff759bf64b60298decbd6cc3b3118 100644 --- a/Trigger/TrigT1/TrigT1MuctpiPhase1/src/SimController.cxx +++ b/Trigger/TrigT1/TrigT1MuctpiPhase1/src/SimController.cxx @@ -35,13 +35,16 @@ namespace LVL1MUCTPIPHASE1 { delete m_triggerProcessor; } - void SimController::configureTopo(const std::string& barrelFileName, - const std::string& ecfFileName, - const std::string& side0LUTFileName, - const std::string& side1LUTFileName) + std::vector<std::string> SimController::configureTopo(const std::string& barrelFileName, + const std::string& ecfFileName, + const std::string& side0LUTFileName, + const std::string& side1LUTFileName) { - m_l1topoLUT.initializeLUT(barrelFileName, ecfFileName, side0LUTFileName, side1LUTFileName); + std::vector<std::string> errors; + bool success = m_l1topoLUT.initializeLUT(barrelFileName, ecfFileName, side0LUTFileName, side1LUTFileName); + if (!success) errors = m_l1topoLUT.getErrors(); for (int i=0;i<(int)m_muonSectorProcessors.size();i++) m_muonSectorProcessors[i]->setL1TopoLUT(&m_l1topoLUT); + return errors; } // set Configuration